GeneralMethod.cs 348 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644
  1. using Aspose.Cells;
  2. using Aspose.Words;
  3. using Aspose.Words.Layout;
  4. using Aspose.Words.Saving;
  5. using Aspose.Words.Tables;
  6. using Microsoft.AspNetCore.SignalR;
  7. using Microsoft.Graph.Models;
  8. using Microsoft.International.Converters.PinYinConverter;
  9. using NodaTime;
  10. using OASystem.API.OAMethodLib.File;
  11. using OASystem.API.OAMethodLib.Hub.HubClients;
  12. using OASystem.API.OAMethodLib.Hub.Hubs;
  13. using OASystem.API.OAMethodLib.JuHeAPI;
  14. using OASystem.API.OAMethodLib.KiMiApi;
  15. using OASystem.API.OAMethodLib.SignalR.Hubs;
  16. using OASystem.Domain.AesEncryption;
  17. using OASystem.Domain.Dtos.Groups;
  18. using OASystem.Domain.Dtos.PersonnelModule;
  19. using OASystem.Domain.Entities.Customer;
  20. using OASystem.Domain.Entities.Financial;
  21. using OASystem.Domain.Entities.Groups;
  22. using OASystem.Domain.ViewModels.Financial;
  23. using OASystem.Domain.ViewModels.Groups;
  24. using OASystem.Domain.ViewModels.JuHeExchangeRate;
  25. using OASystem.Domain.ViewModels.PersonnelModule;
  26. using OASystem.Infrastructure.Repositories.CRM;
  27. using OASystem.Infrastructure.Repositories.Groups;
  28. using System.Data;
  29. using System.IdentityModel.Tokens.Jwt;
  30. using System.Security.Claims;
  31. namespace OASystem.API.OAMethodLib
  32. {
  33. public static class GeneralMethod
  34. {
  35. //团组信息
  36. private static readonly SqlSugarClient _sqlSugar = AutofacIocManager.Instance.GetService<SqlSugarClient>();
  37. private static readonly DelegationInfoRepository _dirRep = AutofacIocManager.Instance.GetService<DelegationInfoRepository>();
  38. private static readonly TeamRateRepository _teamRateRep = AutofacIocManager.Instance.GetService<TeamRateRepository>();
  39. private static readonly IJuHeApiService _juHeApi = AutofacIocManager.Instance.GetService<IJuHeApiService>();
  40. private static readonly SetDataRepository _setDataRep = AutofacIocManager.Instance.GetService<SetDataRepository>();
  41. private static readonly TableOperationRecordRepository _tableOperationRecordRep = AutofacIocManager.Instance.GetService<TableOperationRecordRepository>();
  42. private static readonly MessageRepository _messageRep = AutofacIocManager.Instance.GetService<MessageRepository>();
  43. private static readonly IHubContext<ChatHub, IChatClient> _hubContext = AutofacIocManager.Instance.GetService<IHubContext<ChatHub, IChatClient>>();
  44. private readonly static string[] weekdays = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  45. #region 团组操作-->团组归属部门
  46. /// <summary>
  47. /// 团组操作-->团组归属部门
  48. /// </summary>
  49. /// <returns></returns>
  50. public static async Task<List<GroupOpAffiliationBranchView>> GroupOpAffiliationBranchInit()
  51. {
  52. /*
  53. * 1.sq 和 gyy 等显示 市场部
  54. * 2.王鸽和主管及张总还有管理员号统一国交部
  55. * 2-1. 4 管理员 ,21 张海麟
  56. */
  57. //List<int> userIds = new List<int>() { 4, 21 };
  58. var userDepDatas = new List<GroupOpAffiliationBranchView>();
  59. //userDepDatas = _sqlSugar.Queryable<Sys_Users>()
  60. // .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  61. // .Where(u => u.IsDel == 0)
  62. // .Select((u, d) => new GroupOpAffiliationBranchView { value = userIds.Contains(u.Id) ? "国交部" : d.DepName, text = userIds.Contains(u.Id) ? "国交部" : d.DepName })
  63. // .ToList();
  64. //userDepDatas.Insert(0, new GroupOpAffiliationBranchView() { text = "公司", value = "公司" });
  65. userDepDatas.Insert(0, new GroupOpAffiliationBranchView() { text = "全部", value = "全部" });
  66. userDepDatas.Insert(1, new GroupOpAffiliationBranchView() { text = "国交部", value = "国交部" });
  67. userDepDatas.Insert(2, new GroupOpAffiliationBranchView() { text = "市场部", value = "市场部" });
  68. userDepDatas.Insert(3, new GroupOpAffiliationBranchView() { text = "策划部", value = "策划部" });
  69. return userDepDatas;
  70. }
  71. public class GroupOpAffiliationBranchView
  72. {
  73. public string value { get; set; }
  74. public string text { get; set; }
  75. }
  76. #endregion
  77. #region 员工注册默认添加基础页面
  78. /// <summary>
  79. /// 默认职位权限
  80. /// </summary>
  81. public static bool DefaultPostAuth(int depId, int postId, int userId, int createUserId)
  82. {
  83. if (depId < 1) return false;
  84. if (postId < 1) return false;
  85. if (userId < 1) return false;
  86. if (createUserId < 1) return false;
  87. List<DefaultPostPageAuthView> _defaultData = AppSettingsHelper.Get<DefaultPostPageAuthView>("DefaultPostPageData");
  88. if (_defaultData.Count < 1) return false;
  89. var postJobDatas = _dirRep._sqlSugar.Queryable<Sys_JobPost>().Where(it => it.IsDel == 0).ToList();
  90. List<int> pageData = new List<int>();
  91. //添加公司公共页面
  92. pageData.AddRange(_defaultData.Find(it => it.DepId == -1)?.PostPageAuths[0].PageIds ?? new List<int>());
  93. //添加部门页面
  94. var depPublicPageData = _defaultData.Find(it => it.DepId == depId);
  95. var jobPublicPageData = postJobDatas.Find(it => it.DepId == depId && it.Id == postId);
  96. if (depPublicPageData != null) //特殊部门
  97. {
  98. //公共页面
  99. pageData.AddRange(depPublicPageData.PostPageAuths.Find(it => it.PostId == -1)?.PageIds ?? new List<int>());
  100. if (depId == 7) //国交部特殊处理
  101. {
  102. List<string> postNames = new List<string>() { "主管", "经理" };
  103. //岗位页面
  104. if (jobPublicPageData != null)
  105. {
  106. if (postNames.Contains(jobPublicPageData.JobName))
  107. {
  108. pageData.AddRange(depPublicPageData.PostPageAuths.Find(it => it.PostId == 0)?.PageIds ?? new List<int>());
  109. }
  110. else
  111. {
  112. pageData.AddRange(depPublicPageData.PostPageAuths.Find(it => it.PostId == postId)?.PageIds ?? new List<int>());
  113. }
  114. }
  115. }
  116. #region 按照岗位默认分配页面 特殊处理 市场部-销售顾问
  117. var salesDefaultPages = new List<int>() {
  118. 27 , //团组操作
  119. 104, //接团客户名单
  120. 106, //倒推表
  121. 118, //出入境费用明细
  122. 168, //出入境国家三公费用标准
  123. 194, //出入境费用明细-草稿
  124. 196, //前期需求表单收集
  125. };
  126. var jobName = jobPublicPageData.JobName;
  127. if (!string.IsNullOrEmpty(jobName))
  128. {
  129. if (jobPublicPageData.JobName.Equals("销售顾问"))
  130. {
  131. pageData.AddRange(salesDefaultPages);
  132. pageData = pageData.Distinct().OrderBy(x => x).ToList();
  133. }
  134. }
  135. #endregion
  136. }
  137. else //通用部门
  138. {
  139. pageData.AddRange(_defaultData.Find(it => it.DepId == 0)?.PostPageAuths[0].PageIds ?? new List<int>());
  140. }
  141. if (pageData.Count > 0)
  142. {
  143. //页面操作权限数据(添加修改等...)
  144. var pageFunctionData = _dirRep._sqlSugar.Queryable<Sys_SystemMenuAndFunction>().Where(it => pageData.Contains(it.SmId) && it.IsDel == 0).ToList();
  145. var defaultPageData = pageFunctionData.Select(it => new Sys_UserAuthority()
  146. {
  147. UId = userId,
  148. SmId = it.SmId,
  149. FId = it.FId,
  150. CreateUserId = createUserId, //管理员
  151. CreateTime = DateTime.Now,
  152. IsDel = 0,
  153. IsTemp = 1
  154. }).ToList();
  155. if (defaultPageData.Count > 0)
  156. {
  157. //移除每个页面的审核权限,审核权限需要单独开启
  158. defaultPageData = defaultPageData.Where(it => it.FId != 12).ToList();
  159. //添加页面操作权限
  160. var s = _dirRep._sqlSugar.Fastest<Sys_UserAuthority>().PageSize(100000).BulkCopy(defaultPageData);
  161. if (s > 0)
  162. {
  163. return true;
  164. }
  165. }
  166. }
  167. return false;
  168. }
  169. #endregion
  170. #region 消息
  171. /// <summary>
  172. /// 消息 发布And 通知
  173. /// </summary>
  174. /// <param name="msgTypeEnum">
  175. /// 消息类型
  176. /// 1 公告通知
  177. /// 2 团组流程管控通知
  178. /// 3 团组业务操作通知
  179. /// 4 团组费用审核消息
  180. /// 5 团组签证进度通知
  181. /// 6 团组任务进度通知
  182. /// 7 日付申请通知
  183. /// </param>
  184. /// <param name="title">消息标题</param>
  185. /// <param name="content">消息内容</param>
  186. /// <param name="userIds"></param>
  187. /// <param name="diId">团组id</param>
  188. /// <param name="param">团组id</param>
  189. /// <returns></returns>
  190. public static async Task<bool> MessageIssueAndNotification(MessageTypeEnum msgTypeEnum, string title, string content, List<int> userIds, int diId = 0, string param = "")
  191. {
  192. MessageDto messageDto = new()
  193. {
  194. Type = msgTypeEnum,
  195. IssuerId = 4,//管理员
  196. DiId = diId,
  197. Title = title,
  198. Content = content,
  199. ReleaseTime = DateTime.Now,
  200. UIdList = userIds,
  201. Param = param
  202. };
  203. var status = await _messageRep.AddMsg(messageDto);//添加消息
  204. if (status)
  205. {
  206. //给在线在用户发送消息
  207. var connIds = UserStore.OnlineUser.Where(it => userIds.Contains(it.UserId)).Select(it => it.ConnectionId).ToList();
  208. var notificationTypeStr1 = GetMsgNotificationType(msgTypeEnum);
  209. var notificationTypeStr = JsonConvert.SerializeObject(
  210. new
  211. {
  212. UserIds = userIds,
  213. Msg = $"您有一条{notificationTypeStr1}相关的消息!"
  214. }
  215. );
  216. await _hubContext.Clients.Clients(connIds).ReceiveMessage($"您有一条{notificationTypeStr1}相关的消息!");
  217. return true;
  218. }
  219. return false;
  220. }
  221. /// <summary>
  222. /// 根据消息类型 获取 消息通知类型
  223. /// </summary>
  224. /// <returns></returns>
  225. public static string GetMsgNotificationType(MessageTypeEnum msgTypeEnum)
  226. {
  227. int notificationType = 0;
  228. string notificationStr = "";
  229. List<NotificationTypeView> notificationTypeViews = AppSettingsHelper.Get<NotificationTypeView>("MessageNotificationType");
  230. notificationType = notificationTypeViews.Where(it => it.MsgTypeIds.Contains((int)msgTypeEnum)).Select(it => it.TypeId).FirstOrDefault();
  231. if (notificationType == 1021) notificationStr = "操作";
  232. else if (notificationType == 1020) notificationStr = "任务";
  233. return notificationStr;
  234. }
  235. #endregion
  236. #region md5 加密
  237. /// <summary>
  238. /// MD5加密,和动网上的16/32位MD5加密结果相同,
  239. /// 使用的UTF8编码
  240. /// </summary>
  241. /// <param name="source">待加密字串</param>
  242. /// <param name="length">16或32值之一,其它则采用.net默认MD5加密算法</param>
  243. /// <returns>加密后的字串</returns>
  244. public static string Encrypt(string source, int length = 32)
  245. {
  246. if (string.IsNullOrWhiteSpace(source))
  247. return string.Empty;
  248. HashAlgorithm hashAlgorithm = CryptoConfig.CreateFromName("MD5") as HashAlgorithm;
  249. byte[] bytes = Encoding.UTF8.GetBytes(source);
  250. byte[] hashValue = hashAlgorithm.ComputeHash(bytes);
  251. StringBuilder sb = new StringBuilder();
  252. switch (length)
  253. {
  254. case 16://16位密文是32位密文的9到24位字符
  255. for (int i = 4; i < 12; i++)
  256. {
  257. sb.Append(hashValue[i].ToString("x2"));
  258. }
  259. break;
  260. case 32:
  261. for (int i = 0; i < 16; i++)
  262. {
  263. sb.Append(hashValue[i].ToString("x2"));
  264. }
  265. break;
  266. default:
  267. for (int i = 0; i < hashValue.Length; i++)
  268. {
  269. sb.Append(hashValue[i].ToString("x2"));
  270. }
  271. break;
  272. }
  273. return sb.ToString();
  274. }
  275. #endregion
  276. #region jwt
  277. /// <summary>
  278. /// 获取token
  279. /// </summary>
  280. /// <param name="_config"></param>
  281. /// <param name="Number"></param>
  282. /// <param name="uId"></param>
  283. /// <param name="uName"></param>
  284. /// <param name="exp"></param>
  285. /// <returns></returns>
  286. public static async Task<string> GetToken(IConfiguration _config, string Number, int uId, string uName, DateTime exp)
  287. {
  288. string userId = Guid.NewGuid().ToString().Replace("-", "");
  289. var claims = new[] {
  290. new Claim(ClaimTypes.NameIdentifier, uName),
  291. new Claim(ClaimTypes.NameIdentifier, uId.ToString()),
  292. new Claim(ClaimTypes.NameIdentifier, userId),
  293. new Claim("Number",Number)
  294. };
  295. var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["JwtSecurityKey"]));
  296. var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
  297. var token = new JwtSecurityToken(
  298. issuer: "OASystem.com",
  299. audience: "OASystem.com",
  300. claims: claims,
  301. expires: exp,
  302. signingCredentials: creds);
  303. var identity = new ClaimsIdentity(claims, "login");
  304. var principal = new ClaimsPrincipal(identity);
  305. // await _httpContext.SignInAsync (CookieAuthenticationDefaults.AuthenticationScheme, principal);
  306. return new JwtSecurityTokenHandler().WriteToken(token);
  307. }
  308. #endregion
  309. #region 数据类型转换
  310. /// <summary>
  311. /// object 转 Int
  312. /// </summary>
  313. /// <param name="obj"></param>
  314. /// <returns></returns>
  315. public static int GetInt(this object obj)
  316. {
  317. if (obj == null)
  318. return 0;
  319. var number = 0;
  320. var reslut = Int32.TryParse(obj.ToString(), out number);
  321. return number;
  322. }
  323. private static DateTime _dateStart = new DateTime(1970, 1, 1, 8, 0, 0);
  324. private static long _longTime = 621355968000000000;
  325. private static int _samllTime = 10000000;
  326. /// <summary>
  327. /// 时间戳 转 datetime
  328. /// </summary>
  329. /// <param name="timeStamp"></param>
  330. /// <returns></returns>
  331. public static DateTime GetTimeSpmpToDate(this object timeStamp)
  332. {
  333. if (timeStamp == null) return _dateStart;
  334. DateTime dateTime = new DateTime(_longTime + Convert.ToInt64(timeStamp) * _samllTime, DateTimeKind.Utc).ToLocalTime();
  335. return dateTime;
  336. }
  337. #endregion
  338. #region 用户页面操作功能 权限
  339. /// <summary>
  340. /// 用户页面操作功能(可使用)
  341. /// </summary>
  342. /// <param name="userId">用户Id</param>
  343. /// <param name="PageId">页面Id</param>
  344. /// <returns></returns>
  345. public static async Task<PageFunAuthViewBase> PostUserPageFuncDatas(int userId, int PageId)
  346. {
  347. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  348. List<UserPageFuncView> userPageFuncDatas = new List<UserPageFuncView>();
  349. string sql = string.Format(@"Select ua.UId As UserId, u.CnName As UserName, pa.ModuleId,pa.ModuleName,pa.PageId,pa.PageName,pa.PageIsEnable,
  350. pa.PagePhoneIsEnable,pa.FuncId,pa.FuncName,pa.FuncIsEnable
  351. From Sys_UserAuthority ua
  352. Left Join Sys_Users u On ua.UId = u.Id
  353. Left Join (
  354. Select sd.Id As ModuleId,sd.Name As ModuleName, smp.Id As PageId,smp.Name As PageName,smp.IsEnable As PageIsEnable,
  355. smp.phoneIsEnable As PagePhoneIsEnable,pfp.Id As FuncId,pfp.FunctionName As FuncName,pfp.IsEnable As FuncIsEnable
  356. From Sys_SystemMenuAndFunction smaf
  357. Left Join Sys_SystemMenuPermission smp On smaf.SmId = smp.Id
  358. Left Join Sys_SetData sd On sd.STid = 5 And smp.Mid = sd.Id
  359. Left Join Sys_PageFunctionPermission pfp On smaf.FId = pfp.Id
  360. Where smaf.IsDel = 0 And smp.IsDel = 0 And pfp.IsDel = 0 And sd.IsDel = 0 And smp.IsEnable = 1
  361. ) As pa On ua.SmId = pa.PageId And ua.FId = pa.FuncId
  362. Where ua.IsDel = 0 And ua.UId = {0} And pa.PageId = {1}
  363. Order By ModuleId,PageId,FuncId Asc", userId, PageId);
  364. userPageFuncDatas = await _dirRep._sqlSugar.SqlQueryable<UserPageFuncView>(sql).ToListAsync();
  365. if (userPageFuncDatas.Count <= 0)
  366. {
  367. return pageFunAuth;
  368. }
  369. UserPageFuncView userPageFunc = new UserPageFuncView();
  370. //查询 1
  371. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 1).FirstOrDefault();
  372. if (userPageFunc != null) pageFunAuth.CheckAuth = 1;
  373. //删除 2
  374. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 2).FirstOrDefault();
  375. if (userPageFunc != null) pageFunAuth.DeleteAuth = 1;
  376. //编辑 3
  377. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 3).FirstOrDefault();
  378. if (userPageFunc != null) pageFunAuth.EditAuth = 1;
  379. //下载 4
  380. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 4).FirstOrDefault();
  381. if (userPageFunc != null) pageFunAuth.FilesDownloadAuth = 1;
  382. //上传 5
  383. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 5).FirstOrDefault();
  384. if (userPageFunc != null) pageFunAuth.FilesUploadAuth = 1;
  385. //添加 11
  386. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 11).FirstOrDefault();
  387. if (userPageFunc != null) pageFunAuth.AddAuth = 1;
  388. //审核 12
  389. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 12).FirstOrDefault();
  390. if (userPageFunc != null) pageFunAuth.AuditAuth = 1;
  391. return pageFunAuth;
  392. }
  393. #endregion
  394. #region 业务模块 团组权限
  395. /// <summary>
  396. /// 业务模块 团组操作权限
  397. /// 验证 并返回可操作的团
  398. /// </summary>
  399. /// <param name="diId">团组Id</param>
  400. /// <param name="userId">用户Id</param>
  401. /// <param name="CTable">业务模块Id</param>
  402. /// <returns></returns>
  403. public static async Task<Result> PostGroupOperationAuth(int diId, int userId, int CTable)
  404. {
  405. Result _result = new Result { Code = -1, Msg = "No Operation Authorty!" };
  406. if (CTable < 1)
  407. {
  408. _result.Msg = "请填写正确的用户Id!";
  409. return _result;
  410. }
  411. var data = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(it => it.DIId == diId && it.UId == userId && it.CTId == CTable && it.IsDel == 0).First();
  412. if (data == null)
  413. {
  414. _result.Msg = "你没有本团下的该业务模块操作,请联系主管分配操作权限!";
  415. }
  416. else
  417. {
  418. _result.Code = 0;
  419. }
  420. return _result;
  421. }
  422. /// <summary>
  423. /// 业务模块 团组操作权限
  424. /// 返回可操作的团
  425. /// </summary>
  426. /// <param name="userId">用户Id</param>
  427. /// <param name="CTable">业务模块Id</param>
  428. /// <returns></returns>
  429. public static async Task<List<Web_ShareGroupInfoView>> PostOperationAuthReturnGroupInfosAsync(int userId, int CTable)
  430. {
  431. var shareGroupInfoViews = new List<Web_ShareGroupInfoView>();
  432. var taskData = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(it => it.UId == userId && it.CTId == CTable && it.IsDel == 0).ToList();
  433. if (taskData.Count < 1) return shareGroupInfoViews;
  434. var diIds = string.Join(",", taskData.Select(it => it.DIId).ToList());
  435. var sql = string.Format(@"Select Id,TeamName,TourCode,ClientName,VisitCountry,VisitStartDate,VisitEndDate,VisitDays,VisitPNumber
  436. From Grp_DelegationInfo Where Id In({0}) And IsDel = 0 Order By Id Desc", diIds);
  437. shareGroupInfoViews = await _dirRep._sqlSugar.SqlQueryable<Web_ShareGroupInfoView>(sql).ToListAsync();
  438. return shareGroupInfoViews;
  439. }
  440. #endregion
  441. #region 团组相关
  442. #region 费用录入 编辑、删除前验证
  443. /// <summary>
  444. /// 费用录入 编辑、删除 验证
  445. /// </summary>
  446. /// <param name="id">费用Id</param>
  447. /// <param name="feeType">
  448. /// 费用类型
  449. /// 85:机票
  450. /// 82:保险
  451. /// 81:商邀
  452. /// 80:签证
  453. /// 79:OP
  454. /// 76:酒店
  455. /// </param>
  456. /// <returns>
  457. /// (是否验证通过, 验证失败时的错误信息)
  458. /// 通过:true, null
  459. /// 失败:false, 错误信息
  460. /// </returns>
  461. public static async Task<(bool IsValid, string? ErrorMessage)> FeeOpValid(int id, int feeType)
  462. {
  463. // 查询费用记录
  464. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  465. .Where(x => x.IsDel == 0 && x.CId == id && x.CTable == feeType)
  466. .FirstAsync();
  467. // 记录不存在
  468. if (ccpInfo == null)
  469. return (false, "当前费用不存在,不可操作!");
  470. // 自动审核 费用类型为签证时不校验
  471. if (feeType != 80)
  472. {
  473. if (ccpInfo.IsAuditGM == 3)
  474. return (false, "当前费用已自动审核,不可操作!");
  475. }
  476. // 已审核
  477. if (ccpInfo.IsAuditGM == 1)
  478. return (false, "当前费用已审核,不可操作!");
  479. // 已付款
  480. if (ccpInfo.IsPay == 1)
  481. return (false, "当前费用已付款,不可操作!");
  482. // 验证通过
  483. return (true, null);
  484. }
  485. #endregion
  486. #region 建团按国家默认添加汇率 / 默认权限分配
  487. /// <summary>
  488. /// 团组汇率
  489. /// 建团时 添加基础汇率 CNY
  490. /// 按国家 添加 默认币种
  491. /// </summary>
  492. /// <param name="userId"></param>
  493. /// <param name="diId"></param>
  494. /// <returns></returns>
  495. public static async Task<Result> PostGroupRateAddInit(int userId, int diId)
  496. {
  497. Result result = new() { Code = -2 };
  498. if (userId < 1)
  499. {
  500. result.Msg = string.Format(@"请传入正确的userId");
  501. return result;
  502. }
  503. if (diId < 1)
  504. {
  505. result.Msg = string.Format(@"请传入正确的DiId");
  506. return result;
  507. }
  508. //美元(USD):1.0000|欧元(EUR):1.0000|墨西哥比索(MXN):1.0000
  509. string rateInit = string.Format(@"人民币(CNY):1.0000");
  510. //var gropInfo = _dirRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == diId).First();
  511. //if (gropInfo == null)
  512. //{
  513. // result.Msg = $@"未查询到团组信息!";
  514. // return result;
  515. //}
  516. var juheRateData = await _juHeApi.GetExchangeRateAsync();
  517. if (juheRateData.Error_code != 0)
  518. {
  519. result.Msg = juheRateData.Reason;
  520. return result;
  521. }
  522. List<ExchangeRateModel> exchangeRateModels = (List<ExchangeRateModel>)juheRateData.Result;
  523. if (exchangeRateModels.Count <= 0)
  524. {
  525. result.Msg = $@"未查询到聚合接口汇率信息!";
  526. return result;
  527. }
  528. if (exchangeRateModels.Count > 0)
  529. {
  530. var codes = _dirRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  531. for (int i = 0; i < exchangeRateModels.Count; i++)
  532. {
  533. string currencyName = exchangeRateModels[i].Name;
  534. string code = "";
  535. var currencyData = codes.Where(it => it.Remark == currencyName).FirstOrDefault();
  536. if (currencyData != null)
  537. {
  538. code = currencyData.Name;
  539. decimal currRate = 0.00M;
  540. string MSellPri = exchangeRateModels[i].MSellPri;
  541. if (!string.IsNullOrEmpty(MSellPri))
  542. {
  543. currRate = Convert.ToDecimal(MSellPri) / 100M;
  544. }
  545. rateInit += $@"|{currencyName}({code}):{currRate.ToString("#0.0000")}";
  546. }
  547. }
  548. }
  549. var cTableIds = _dirRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 16).ToList();
  550. if (cTableIds.Count < 1)
  551. {
  552. result.Msg = $@"未查询到操作模块信息!";
  553. return result;
  554. }
  555. List<Grp_TeamRate> grp_TeamRates = new List<Grp_TeamRate>();
  556. foreach (var item in cTableIds)
  557. {
  558. grp_TeamRates.Add(
  559. new Grp_TeamRate() { DiId = diId, CTable = item.Id, Remark = rateInit, CreateUserId = userId }
  560. );
  561. }
  562. if (grp_TeamRates.Count > 0)
  563. {
  564. var addId = _teamRateRep._sqlSugar.Insertable(grp_TeamRates).ExecuteCommand();
  565. if (addId < 1)
  566. {
  567. result.Msg = string.Format(@"添加失败!");
  568. return result;
  569. }
  570. }
  571. result.Code = 0;
  572. result.Msg = string.Format(@"操作成功!");
  573. return result;
  574. }
  575. /// <summary>
  576. /// 团组任务分配
  577. /// 建团时 默认按照岗位分配权限
  578. /// </summary>
  579. /// <param name="userId"></param>
  580. /// <param name="diId"></param>
  581. /// <param name="companyId"></param>
  582. /// <returns></returns>
  583. public static async Task<Result> PostGroupAuthAddInit(int userId, int diId, int companyId = 2)
  584. {
  585. Result result = new() { Code = -2 };
  586. if (userId < 0)
  587. {
  588. result.Msg = string.Format(@"请传入正确的userId");
  589. return result;
  590. }
  591. if (companyId < 0)
  592. {
  593. result.Msg = string.Format(@"请传入正确的companyId");
  594. return result;
  595. }
  596. if (diId < 0)
  597. {
  598. result.Msg = string.Format(@"请传入正确的DiId");
  599. return result;
  600. }
  601. var usersData = await _teamRateRep._sqlSugar.Queryable<Sys_Users>()
  602. .LeftJoin<Sys_Department>((su, sd) => su.DepId == sd.Id && sd.IsDel == 0)
  603. .LeftJoin<Sys_JobPost>((su, sd, sjp) => su.JobPostId == sjp.Id && sjp.IsDel == 0)
  604. .Where(su => su.IsDel == 0)
  605. .Select((su, sd, sjp) => new
  606. {
  607. su.DepId,
  608. sd.DepName,
  609. su.JobPostId,
  610. sjp.JobName,
  611. su.Id,
  612. su.CnName
  613. })
  614. .ToListAsync();
  615. /*
  616. * 76 酒店预订 --> 国交部门 酒店,主管 岗位
  617. * 77 行程 --> 国交部门 经理,主管 岗位
  618. * 79 车/导游地接 --> 国交部门 OP,主管 岗位
  619. * 80 签证 --> 国交部门 签证 岗位
  620. * 81 邀请/公务活动 --> 国交部门 商邀 岗位
  621. * 82 团组客户保险 --> 国交部 经理,主管 岗位
  622. * 85 机票预订 --> 国交部门 机票 岗位
  623. * 98 其他款项 --> 总经办部门 总经理 岗位/国交部门(ALL) 岗位/财务部门(ALL) 岗位/策划部门(ALL) 岗位/人事部门 采购 岗位
  624. * 1015 超支费用,69 收款退还 --> 财务部门(ALL)岗位
  625. * 1015 超支费用 --> 国交部(ALL)岗位
  626. * 1081 文档下载 --> 国交部门 酒店,主管 岗位
  627. */
  628. var groupsTaskAssignments = new List<Grp_GroupsTaskAssignment>();
  629. // 76 酒店预订 --> 国交部门(7) 酒店(25)、主管(22) 岗位
  630. groupsTaskAssignments.AddRange(
  631. usersData
  632. .Where(it => it.DepId == 7 && (it.JobPostId == 25 || it.JobPostId == 22))
  633. .Select(it => new Grp_GroupsTaskAssignment()
  634. {
  635. DIId = diId,
  636. CTId = 76,
  637. UId = it.Id,
  638. CreateUserId = userId
  639. }).ToList()
  640. );
  641. // 77 行程 --> 国交部门(7) 经理(32),主管(22) 岗位
  642. groupsTaskAssignments.AddRange(
  643. usersData
  644. .Where(it => it.DepId == 7 && (it.JobPostId == 22 || it.JobPostId == 32))
  645. .Select(it => new Grp_GroupsTaskAssignment()
  646. {
  647. DIId = diId,
  648. CTId = 77,
  649. UId = it.Id,
  650. CreateUserId = userId
  651. }).ToList()
  652. );
  653. //79 车/导游地接 --> 国交部门(7) OP(28)、主管(22) 岗位
  654. //groupsTaskAssignments.AddRange(
  655. // usersData.Where(it => it.DepId == 7 && (it.JobPostId == 22 || it.JobPostId == 28))
  656. // .Select(it => new Grp_GroupsTaskAssignment()
  657. // {
  658. // DIId = diId,
  659. // CTId = 79,
  660. // UId = it.Id,
  661. // CreateUserId = userId
  662. // }).ToList()
  663. //);
  664. //81 邀请/公务活动 --> 国交部门(7) 商邀(27) 岗位
  665. //groupsTaskAssignments.AddRange(
  666. // usersData.Where(it => it.DepId == 7 && it.JobPostId == 27)
  667. // .Select(it => new Grp_GroupsTaskAssignment()
  668. // {
  669. // DIId = diId,
  670. // CTId = 81,
  671. // UId = it.Id,
  672. // CreateUserId = userId
  673. // }).ToList()
  674. //);
  675. //2024年8月26日16点27分 “邀请公务活动分配给王鸽(UserID:149)”
  676. //groupsTaskAssignments.Add(
  677. // new Grp_GroupsTaskAssignment()
  678. // {
  679. // DIId = diId,
  680. // CTId = 81,
  681. // UId = 149,
  682. // CreateUserId = userId
  683. // }
  684. //);
  685. //80 签证 --> 国交部门(7) 签证(26) 岗位
  686. groupsTaskAssignments.AddRange(
  687. usersData
  688. .Where(it => it.DepId == 7 && it.JobPostId == 26)
  689. .Select(it => new Grp_GroupsTaskAssignment()
  690. {
  691. DIId = diId,
  692. CTId = 80,
  693. UId = it.Id,
  694. CreateUserId = userId
  695. }).ToList()
  696. );
  697. //82 团组客户保险 --> 国交部(7) 经理(32),主管(22) 岗位
  698. //2024-06-25 默认将保险权限分配给签证岗。 签证(26) 岗位
  699. List<int> insurancePositions = new List<int>() { 32, 22, 26 };
  700. groupsTaskAssignments.AddRange(
  701. usersData
  702. .Where(it => it.DepId == 7 && insurancePositions.Contains(it.JobPostId))
  703. .Select(it => new Grp_GroupsTaskAssignment()
  704. {
  705. DIId = diId,
  706. CTId = 82,
  707. UId = it.Id,
  708. CreateUserId = userId
  709. }).ToList()
  710. );
  711. //85 机票预订 --> 国交部门(7) 机票(24),商邀主管(22),OP主管(23) 岗位
  712. groupsTaskAssignments.AddRange(
  713. usersData
  714. .Where(it => it.DepId == 7 && (it.JobPostId == 22 || it.JobPostId == 24 || it.JobPostId == 23))
  715. .Select(it => new Grp_GroupsTaskAssignment()
  716. {
  717. DIId = diId,
  718. CTId = 85,
  719. UId = it.Id,
  720. CreateUserId = userId
  721. }).ToList()
  722. );
  723. //98 其他款项 --> 总经办部门(1) 总经理(1) 岗位/国交部门(7)(ALL) 岗位/财务部门(3)(ALL) 岗位/策划部门(5)(ALL) 岗位/人事部门(4) 采购(74) 岗位
  724. var depIds = new List<int>() { 7, 3, 5 };
  725. var jobIds = new List<int>() { 1, 74 };
  726. groupsTaskAssignments.AddRange(
  727. usersData
  728. .Where(it => depIds.Contains(it.DepId) || jobIds.Contains(it.JobPostId))
  729. .Select(it => new Grp_GroupsTaskAssignment()
  730. {
  731. DIId = diId,
  732. CTId = 98,
  733. UId = it.Id,
  734. CreateUserId = userId
  735. }).ToList()
  736. );
  737. //2024年8月26日16点27分 “其他款项分配给王鸽(UserID:149)”
  738. groupsTaskAssignments.Add(new Grp_GroupsTaskAssignment()
  739. {
  740. DIId = diId,
  741. CTId = 98,
  742. UId = 149,
  743. CreateUserId = userId
  744. });
  745. //1015 超支费用,285 收款退还 --> 财务部门(ALL)岗位
  746. groupsTaskAssignments.AddRange(
  747. usersData
  748. .Where(it => it.DepId == 3)
  749. .Select(it => new Grp_GroupsTaskAssignment()
  750. {
  751. DIId = diId,
  752. CTId = 1015,
  753. UId = it.Id,
  754. CreateUserId = userId
  755. }).ToList()
  756. );
  757. groupsTaskAssignments.AddRange(
  758. usersData
  759. .Where(it => it.DepId == 3)
  760. .Select(it => new Grp_GroupsTaskAssignment()
  761. {
  762. DIId = diId,
  763. CTId = 285,
  764. UId = it.Id,
  765. CreateUserId = userId
  766. }).ToList()
  767. );
  768. //1015 超支费用 --> 国交部(ALL)岗位
  769. groupsTaskAssignments.AddRange(
  770. usersData
  771. .Where(it => it.DepId == 7)
  772. .Select(it => new Grp_GroupsTaskAssignment()
  773. {
  774. DIId = diId,
  775. CTId = 1015,
  776. UId = it.Id,
  777. CreateUserId = userId
  778. }).ToList()
  779. );
  780. if (groupsTaskAssignments.Count > 0)
  781. {
  782. var addId = await _teamRateRep._sqlSugar.Insertable(groupsTaskAssignments).ExecuteCommandAsync();
  783. }
  784. result.Code = 0;
  785. result.Msg = string.Format(@"操作成功!");
  786. return result;
  787. }
  788. #endregion
  789. #region 员工是否是市场部人员
  790. /// <summary>
  791. /// 验证市场部客户人员
  792. /// </summary>
  793. /// <param name="userId"></param>
  794. /// <returns></returns>
  795. public static async Task<bool> IsMarketingStaff(int userId)
  796. {
  797. var userInfos = await _dirRep._sqlSugar
  798. .Queryable<Sys_Users>()
  799. .InnerJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  800. .Where((u, d) => u.IsDel == 0 && u.Id == userId && d.DepName.Contains("市场部"))
  801. .ToListAsync();
  802. if (userInfos.Count > 0) return true;
  803. return false;
  804. }
  805. #endregion
  806. #region 三公费用相关
  807. /// <summary>
  808. /// 保存操作前汇率
  809. /// </summary>
  810. /// <param name="currUserId"></param>
  811. /// <param name="diId"></param>
  812. /// <param name="linkModule"></param>
  813. /// <returns></returns>
  814. public static async Task<bool> RateRecordSave(int currUserId, int diId, string linkModule)
  815. {
  816. //var selectData = await _enterExitCostRep._sqlSugar.Queryable<Sys_ExchangeRateRecord>()
  817. // .Where(x => Convert.ToDateTime(x.RateDateTime).ToString("yyyy-MM-dd").Equals(DateTime.Now.ToString("yyyy-MM-dd")))
  818. // .FirstAsync();
  819. //if (selectData != null) return false;
  820. var _currencyRate = await _juHeApi.PostItemRateAsync(Array.Empty<string>());
  821. string rateInfoStr = string.Empty;
  822. var oaCurrencyData = await _sqlSugar.Queryable<Sys_SetData>()
  823. .Where(x => x.IsDel == 0 && x.STid == 66)
  824. .ToListAsync();
  825. //只记录 五种币种 汇率
  826. var currencyCodes = new List<string>() {
  827. "USD",
  828. "EUR",
  829. "JPY",
  830. "GBP",
  831. "HKD"
  832. };
  833. foreach (var rate in _currencyRate)
  834. {
  835. var oaCurrncy = oaCurrencyData.Find(x => x.Remark.Equals(rate.Name));
  836. if (oaCurrncy == null) continue;
  837. if (!currencyCodes.Contains(oaCurrncy.Name)) continue;
  838. //美元(USD):7.5|
  839. string rateStr = rate.FSellPri ?? "0.00";
  840. rateInfoStr += $"{rate.Name}({oaCurrncy.Name}):{rateStr}|";
  841. }
  842. if (string.IsNullOrEmpty(rateInfoStr)) return false;
  843. var add = await _sqlSugar
  844. .Insertable<Sys_ExchangeRateRecord>(new Sys_ExchangeRateRecord()
  845. {
  846. DiId = diId,
  847. LinkModule = linkModule,
  848. RateDateTime = DateTime.Now,
  849. RateInfo = rateInfoStr,
  850. CreateUserId = currUserId,
  851. IsDel = 0
  852. })
  853. .ExecuteCommandAsync();
  854. return add > 0;
  855. }
  856. /// <summary>
  857. /// 三公费用导入收款账单数据
  858. /// </summary>
  859. /// <param name="groupId"></param>
  860. /// <returns></returns>
  861. public static async Task<List<Fin_ForeignReceivables>> ReceivablesImportFeeAsync(int groupId)
  862. {
  863. var data = new List<Fin_ForeignReceivables>();
  864. var enterExitCosts = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == groupId).FirstAsync();
  865. var dayAndCosts = await _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == groupId).ToListAsync();
  866. var dayOtherCosts = await _sqlSugar.Queryable<Grp_DayOtherPrice>().Where(x => x.IsDel == 0 && x.Diid == groupId).ToListAsync(); //其他款项
  867. if (enterExitCosts == null) return data;
  868. //数据源
  869. var stayData = dayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  870. var mealData = dayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  871. var miscellaneousData = dayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  872. var trainData = dayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  873. //筛选 陪同人员 = 1
  874. var groupClientList = await _sqlSugar.Queryable<Grp_TourClientList>()
  875. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id)
  876. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id)
  877. .LeftJoin<Sys_SetData>((tcl, dc, cc, sd) => tcl.ShippingSpaceTypeId == sd.Id)
  878. .Where(tcl => tcl.IsDel == 0 &&
  879. tcl.DiId == groupId &&
  880. tcl.IsAccompany == 1
  881. )
  882. .Select((tcl, dc, cc, sd) => new
  883. {
  884. DiId = tcl.DiId,
  885. CompanyId = cc.Id,
  886. CompanyName = cc.CompanyFullName,
  887. ClienId = dc.Id,
  888. ClientName = dc.FirstName + dc.LastName,
  889. SpaceId = tcl.ShippingSpaceTypeId,
  890. SpaceName = sd.Name
  891. })
  892. .ToListAsync();
  893. if (!groupClientList.Any()) return data;
  894. decimal domesticFeeTotal = 0.00M, //境内费用
  895. economyClassFeeTotal = 0.00M, //经济舱费用
  896. businessClassFeeTotal = 0.00M, //公务舱费用
  897. firstClassFeeTotal = 0.00M, //头等舱费用
  898. stayFeeTotal = 0.00M, //住宿费
  899. mealsFeeTotal = 0.00M, //餐食费
  900. miscellaneousFeeTotal = 0.00M, //公杂费
  901. trainFeeTotal = 0.00M, //培训费
  902. otherPriceTotal = 0.00M; //其他款项
  903. //境内费用(其他费用)
  904. if (enterExitCosts.ChoiceOne == 1) domesticFeeTotal = enterExitCosts.InsidePay;
  905. //住宿费
  906. if (enterExitCosts.ChoiceThree == 1) stayFeeTotal = stayData.Sum(x => x.SubTotal);
  907. //伙食费
  908. if (enterExitCosts.ChoiceFour == 1) mealsFeeTotal = mealData.Sum(x => x.SubTotal);
  909. //公杂费
  910. if (enterExitCosts.ChoiceFive == 1) miscellaneousFeeTotal = miscellaneousData.Sum(x => x.SubTotal);
  911. //培训费
  912. if (enterExitCosts.ChoiceSix == 1) trainFeeTotal = trainData.Sum(x => x.SubTotal);
  913. //其他款项
  914. if (enterExitCosts.OtherExpenses_Checked == 1) otherPriceTotal = dayOtherCosts.Sum(x => x.SubTotal);
  915. decimal otherFeeTotal = domesticFeeTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + trainFeeTotal + otherPriceTotal;
  916. //国际旅费合计
  917. //经济舱
  918. if (enterExitCosts.SumJJC == 1) economyClassFeeTotal = enterExitCosts.OutsideJJPay + otherFeeTotal;
  919. //公务舱
  920. if (enterExitCosts.SumGWC == 1) businessClassFeeTotal = enterExitCosts.OutsideGWPay + otherFeeTotal;
  921. //头等舱
  922. if (enterExitCosts.SumTDC == 1) firstClassFeeTotal = enterExitCosts.OutsideTDPay + otherFeeTotal;
  923. var groupClientListGroup = groupClientList.GroupBy(x => x.CompanyId);
  924. foreach (var item in groupClientListGroup)
  925. {
  926. var companyName = AesEncryptionHelper.Decrypt(item.FirstOrDefault().CompanyName);
  927. var airTicketGroup = item.GroupBy(x => x.SpaceId);
  928. foreach (var airTicket in airTicketGroup)
  929. {
  930. int quantity = airTicket.Count();
  931. if (quantity > 0)
  932. {
  933. var price = 0.00M;
  934. var spaceName = airTicket.FirstOrDefault()?.SpaceName ?? string.Empty;
  935. if (spaceName.Equals("经济舱")) price = economyClassFeeTotal;
  936. else if (spaceName.Equals("公务舱")) price = businessClassFeeTotal;
  937. else if (spaceName.Equals("头等舱")) price = firstClassFeeTotal;
  938. if (price > 0)
  939. {
  940. decimal itemTotal = price * quantity;
  941. data.Add(new Fin_ForeignReceivables()
  942. {
  943. Id = 0,
  944. CreateTime = DateTime.Now,
  945. Diid = groupId,
  946. PriceName = $"{companyName}-{spaceName}",
  947. Price = price,
  948. Count = quantity,
  949. Unit = "人",
  950. ItemSumPrice = itemTotal,
  951. Currency = 836,
  952. Rate = 1.0000M,
  953. AddingWay = 2,
  954. Remark = "由出入境费用导入费用",
  955. });
  956. }
  957. }
  958. }
  959. }
  960. return data;
  961. }
  962. #endregion
  963. #region 根据团ID获取各板块实际操作人
  964. /// <summary>
  965. /// 获取 团组模块操作人
  966. /// </summary>
  967. /// <param name="groupId"></param>
  968. /// <returns></returns>
  969. public static List<GroupOperationUserView> GetGroupModuleOperators(int groupId)
  970. {
  971. var modoule = new GroupOperationUserView();
  972. var view = modoule.GetOperationUsersInit();
  973. if (groupId < 1) return view;
  974. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>()
  975. .Where(it => it.IsDel == 0 && it.Id == groupId)
  976. .First();
  977. if (groupInfo == null) return view;
  978. var authUsers = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>()
  979. .LeftJoin<Sys_Users>((x, u) => x.UId == u.Id)
  980. .Where((x, u) => x.DIId == groupId && x.IsDel == 0)
  981. .Select((x, u) => new
  982. {
  983. GroupId = x.DIId,
  984. CType = x.CTId,
  985. UserId = u.Id,
  986. UserName = u.CnName
  987. }).Distinct().ToList();
  988. //获取团组下的操作人
  989. //车/导游地接
  990. var opUers = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  991. .InnerJoin<Grp_CreditCardPayment>((x, y) => x.Id == y.CId && y.CTable == 79)
  992. .LeftJoin<Sys_Users>((x, y, u) => x.CreateUserId == u.Id)
  993. .Where((x, y, u) => x.DiId == groupId && x.IsDel == 0)
  994. .Select((x, y, u) => new GroupOperationUserInfo
  995. {
  996. UserId = u.Id,
  997. UserName = u.CnName
  998. }).Distinct().ToList();
  999. view.Where(it => it.CTableId == 79).FirstOrDefault().OperationUsers = opUers.Distinct().ToList();
  1000. //签证
  1001. var visaUsers = _sqlSugar.Queryable<Grp_VisaInfo>()
  1002. .InnerJoin<Grp_CreditCardPayment>((x, y) => x.Id == y.CId && y.CTable == 80)
  1003. .LeftJoin<Sys_Users>((x, y, u) => x.CreateUserId == u.Id)
  1004. .Where((x, y, u) => x.DIId == groupId && x.IsDel == 0)
  1005. .Select((x, y, u) => new GroupOperationUserInfo
  1006. {
  1007. UserId = u.Id,
  1008. UserName = u.CnName
  1009. }).Distinct().ToList();
  1010. view.Where(it => it.CTableId == 80).FirstOrDefault().OperationUsers = visaUsers.Distinct().ToList();
  1011. //保险
  1012. var insUsers = _sqlSugar.Queryable<Grp_Customers>()
  1013. .InnerJoin<Grp_CreditCardPayment>((x, y) => x.Id == y.CId && y.CTable == 82)
  1014. .LeftJoin<Sys_Users>((x, y, u) => x.CreateUserId == u.Id)
  1015. .Where((x, y, u) => x.DiId == groupId && x.IsDel == 0)
  1016. .Select((x, y, u) => new GroupOperationUserInfo
  1017. {
  1018. UserId = u.Id,
  1019. UserName = u.CnName
  1020. }).Distinct().ToList();
  1021. view.Where(it => it.CTableId == 82).FirstOrDefault().OperationUsers = insUsers.Distinct().ToList();
  1022. //邀请/公务活动
  1023. var ioaUsers = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>()
  1024. .InnerJoin<Grp_CreditCardPayment>((x, y) => x.Id == y.CId && y.CTable == 81)
  1025. .LeftJoin<Sys_Users>((x, y, u) => x.CreateUserId == u.Id)
  1026. .Where((x, y, u) => x.DiId == groupId && x.IsDel == 0)
  1027. .Select((x, y, u) => new GroupOperationUserInfo
  1028. {
  1029. UserId = u.Id,
  1030. UserName = u.CnName
  1031. }).Distinct().ToList();
  1032. if (!ioaUsers.Any())
  1033. {
  1034. ioaUsers = _sqlSugar.Queryable<Res_OfficialActivities>()
  1035. .LeftJoin<Sys_Users>((x, y) => x.CreateUserId == y.Id)
  1036. .Where((x, y) => x.DiId == groupId && x.IsDel == 0)
  1037. .Select((x, y) => new GroupOperationUserInfo
  1038. {
  1039. UserId = y.Id,
  1040. UserName = y.CnName
  1041. }).Distinct().ToList();
  1042. }
  1043. ////公务资料信息
  1044. //var ioaUsers1 = _sqlSugar.Queryable< Res_OfficialActivities >()
  1045. // .LeftJoin<Sys_Users>((x,y) => x.CreateUserId == y.Id)
  1046. // .Where((x,y) => x.DiId == groupId && x.IsDel == 0)
  1047. // .Select((x, y) => new GroupOperationUserInfo
  1048. // {
  1049. // UserId = y.Id,
  1050. // UserName = y.CnName
  1051. // }).Distinct().ToList();
  1052. //if (!ioaUsers.Any())
  1053. //{
  1054. // ioaUsers.AddRange(ioaUsers1);
  1055. //}
  1056. view.Where(it => it.CTableId == 81).FirstOrDefault().OperationUsers = ioaUsers.Distinct().ToList();
  1057. //其他款项 98
  1058. var otherUsers = _sqlSugar.Queryable<Grp_DecreasePayments>()
  1059. .InnerJoin<Grp_CreditCardPayment>((x, y) => x.Id == y.CId && y.CTable == 98)
  1060. .LeftJoin<Sys_Users>((x, y, u) => x.CreateUserId == u.Id)
  1061. .Where((x, y, u) => x.DiId == groupId && x.IsDel == 0)
  1062. .Select((x, y, u) => new GroupOperationUserInfo
  1063. {
  1064. UserId = u.Id,
  1065. UserName = u.CnName
  1066. }).Distinct().ToList();
  1067. view.Where(it => it.CTableId == 98).FirstOrDefault().OperationUsers = otherUsers.Distinct().ToList();
  1068. //添加分配人员
  1069. // 79 车/导游地接
  1070. // 80 签证
  1071. // 81 邀请/公务活动
  1072. var setdataids = new List<int>() { 79, 81, 80 };
  1073. //职位Id
  1074. // 27 商邀
  1075. // 28 OP
  1076. // 22 王鸽(主管)
  1077. // 26 签证
  1078. var jobSetdataids = new List<int>() { 22, 27, 28, 26 };
  1079. var q = _sqlSugar.Queryable<Grp_GroupsTaskAssignment, Sys_Users>(
  1080. (ccta, su) => new JoinQueryInfos(
  1081. JoinType.Left, ccta.UId == su.Id && su.IsDel == 0))
  1082. .Where((ccta, su) =>
  1083. ccta.IsDel == 0 &&
  1084. ccta.DIId == groupId &&
  1085. jobSetdataids.Contains(su.JobPostId) &&
  1086. setdataids.Contains(ccta.CTId))
  1087. .Select((ccta, su) => new
  1088. {
  1089. userid = su.Id,
  1090. su.JobPostId,
  1091. ccta.CTId,
  1092. ccta.DIId,
  1093. su.CnName,
  1094. });
  1095. var qtb = q.ToDataTable();
  1096. foreach (var groupModule in view)
  1097. {
  1098. if (setdataids.Contains(groupModule.CTableId) && !groupModule.OperationUsers.Any())
  1099. {
  1100. var qtbUsers = qtb.AsEnumerable().
  1101. Where(x => x.Field<int>("CTId") == groupModule.CTableId).
  1102. Select(x => x.Field<int>("userid")).ToList();
  1103. //王鸽、王思雨、朱琳
  1104. groupModule.OperationUsers = qtbUsers.Select(x => new GeneralMethod.GroupOperationUserInfo()
  1105. {
  1106. UserId = x,
  1107. UserName = qtb.AsEnumerable().FirstOrDefault(y => y.Field<int>("userid") == x)?.Field<string>("CnName") ?? ""
  1108. }).ToList();
  1109. }
  1110. }
  1111. return view;
  1112. }
  1113. public class GroupOperationUserView
  1114. {
  1115. public int CTableId { get; set; }
  1116. public string CTableName { get; set; }
  1117. public List<GroupOperationUserInfo> OperationUsers { get; set; }
  1118. public GroupOperationUserView() { }
  1119. /// <summary>
  1120. /// 默认模块List
  1121. /// </summary>
  1122. /// <returns></returns>
  1123. public List<GroupOperationUserView> GetOperationUsersInit()
  1124. {
  1125. var modules = new List<GroupOperationUserView>() {
  1126. new(){ CTableId = 76,CTableName = "酒店预订",
  1127. OperationUsers=new List<GroupOperationUserInfo>(){ new() {UserId = 226,UserName = "宋夏雨" } } },
  1128. new(){ CTableId = 79,CTableName = "车/导游地接" },
  1129. new(){ CTableId = 80,CTableName = "签证" },
  1130. new(){ CTableId = 82,CTableName = "团组客户保险" },
  1131. new(){ CTableId = 81,CTableName = "邀请/公务活动" },
  1132. new(){ CTableId = 85,CTableName = "机票预订",
  1133. OperationUsers=new List<GroupOperationUserInfo>(){ new() {UserId = 385, UserName = "雍婷玉" } } },
  1134. new(){ CTableId = 98,CTableName = "其他款项" },
  1135. };
  1136. return modules;
  1137. }
  1138. }
  1139. public class GroupOperationUserInfo
  1140. {
  1141. public int UserId { get; set; }
  1142. public string UserName { get; set; }
  1143. }
  1144. #endregion
  1145. #region 公务 AI
  1146. #region 提示词构建
  1147. /// <summary>
  1148. /// 构建行业匹配提示词(含预筛选逻辑)
  1149. /// <param name="entryInfo">【必填】基础配置信息</param>
  1150. /// <param name="localData">【数据源】来自 SqlSugar 查询的本地候选数据集,需包含 Region 和 NameCn 字段</param>
  1151. /// <returns>返回经过结构化处理的 Markdown 格式 Prompt 字符串</returns>
  1152. /// </summary>
  1153. public static string BuildIndustryPrompt(EntryInfo entryInfo, IEnumerable<InvitationAIInfo> localData)
  1154. {
  1155. // 业务逻辑预处理:仅保留目标国家数据,大幅节省 Token 成本
  1156. var filteredData = localData
  1157. .Where(x => entryInfo.TargetCountry.Contains(x.Region))
  1158. .Select(x => new { x.Region, x.NameCn }) // 仅提取 AI 需要的字段
  1159. .Distinct()
  1160. .ToList();
  1161. // 序列化数据
  1162. var industryStandard = IndustryTree.Build().Select(x => x.NameCn).ToList();
  1163. string industryStandardStr = string.Join("、", industryStandard);
  1164. string countriesStr = string.Join(", ", entryInfo.TargetCountry);
  1165. string jsonData = JsonConvert.SerializeObject(filteredData);
  1166. string sourceUnit = entryInfo.OriginUnit ?? "未知单位";
  1167. string sourceIndustry = string.Join(", ", entryInfo.Industries);
  1168. // 将提示词模板定义为常量,方便维护和查阅
  1169. string promptTemplate = @"
  1170. # Role
  1171. 你是一位精通全球产业结构与大数据清洗的【智能匹配专家】。
  1172. # Standard Industry Categories (Dynamic)
  1173. 请将目标单位严格归类为以下指定的行业类别:
  1174. {0}
  1175. *注意:若无法完全匹配,请归类至语义最接近的一项。*
  1176. # Situation (Dynamic Input)
  1177. - **出访单位**:{1}
  1178. - **其所属行业**:{2}
  1179. - **目标出访国家**:{3}
  1180. # Task
  1181. 分析【本地待匹配数据集】,执行以下逻辑:
  1182. 1. **实体一致性 (Critical)**:返回结果中的 TargetUnitName 必须与输入数据集中的 NameCn 完全一致,严禁修改。
  1183. 2. **语义归类**:分析业务关键词,并映射至上述标准行业分类。
  1184. 3. **关联度计算**:计算与出访单位的业务契合度 (ConfidenceScore: 0.0-1.0)。
  1185. # Rules
  1186. - **输出格式**:仅返回纯 JSON 数组,严禁任何解释性文字。
  1187. - **命名规范**:JSON 键名严格使用 PascalCase。
  1188. # Data Source (JSON Array)
  1189. {4}
  1190. # Output Format (Required JSON)
  1191. [
  1192. {{
  1193. ""SourceUnitName"": ""{1}"",
  1194. ""TargetUnitName"": ""必须与输入数据原样一致"",
  1195. ""TargetCountry"": ""所在国家"",
  1196. ""MatchedIndustry"": ""必须匹配标准行业分类中的原词"",
  1197. ""ConfidenceScore"": 0.00,
  1198. ""MatchReason"": ""匹配理由""
  1199. }}
  1200. ]
  1201. ";
  1202. // 填充模板并返回
  1203. return string.Format(
  1204. promptTemplate,
  1205. industryStandardStr, // {0}
  1206. sourceUnit, // {1}
  1207. sourceIndustry, // {2}
  1208. countriesStr, // {3}
  1209. jsonData // {4}
  1210. );
  1211. }
  1212. #region 国家配额计算(根据 行业、规模)
  1213. public class TaskCoverageReport
  1214. {
  1215. public bool IsValid { get; set; }
  1216. public List<string> MissingRegions { get; set; } = new();
  1217. public List<string> MissingIndustries { get; set; } = new();
  1218. public List<string> MissingScales { get; set; } = new();
  1219. public string Summary =>
  1220. $"Valid={IsValid}, " +
  1221. $"MissingRegions={string.Join(",", MissingRegions)}, " +
  1222. $"MissingIndustries={string.Join(",", MissingIndustries)}, " +
  1223. $"MissingScales={string.Join(",", MissingScales)}";
  1224. }
  1225. public static class CountryToRegionMapper
  1226. {
  1227. /// <summary>
  1228. /// 直接返回中文国家名作为 Region
  1229. /// </summary>
  1230. public static string GetRegion(string country)
  1231. {
  1232. if (string.IsNullOrWhiteSpace(country))
  1233. return "Other";
  1234. return country;
  1235. }
  1236. }
  1237. public record IndustryNode(
  1238. string Code,
  1239. string NameCn,
  1240. string NameEn,
  1241. double Weight = 1.0, // 1.0 代表主行业
  1242. List<IndustryNode>? Children = null
  1243. );
  1244. /// <summary>
  1245. /// 行业结构
  1246. /// </summary>
  1247. public static class IndustryTree
  1248. {
  1249. public static List<IndustryNode> Build() => new()
  1250. {
  1251. // 1. 工业与制造业
  1252. new("IND_MANU", "工业与制造业领域", "Industry & Manufacturing", 1.0,
  1253. Children: new()
  1254. {
  1255. new("MANU_MACH", "机械制造", "Machinery Manufacturing", 0.9),
  1256. new("MANU_AUTO", "汽车制造", "Automotive Manufacturing", 0.9,
  1257. Children: new()
  1258. {
  1259. new("AUTO_NEV", "新能源汽车", "New Energy Vehicles", 0.9),
  1260. new("AUTO_AD", "自动驾驶", "Autonomous Driving", 0.85),
  1261. new("AUTO_PARTS", "汽车零部件", "Auto Parts", 0.7)
  1262. }),
  1263. new("MANU_SMART", "智能制造", "Smart Manufacturing", 0.85)
  1264. }),
  1265. // 2. 能源与资源
  1266. new("ENERGY_RES", "能源与资源领域", "Energy & Resources", 1.0,
  1267. Children: new()
  1268. {
  1269. new("ENERGY_NE", "新能源", "New Energy", 0.9),
  1270. new("ENERGY_STORAGE", "储能技术", "Energy Storage", 0.85),
  1271. new("ENERGY_GRID", "智慧电网", "Smart Grid", 0.8)
  1272. }),
  1273. // 3. 交通运输与物流
  1274. new("TRANS_LOG", "交通运输与物流领域", "Transportation & Logistics", 1.0,
  1275. Children: new()
  1276. {
  1277. new("LOG_SMART", "智慧物流", "Smart Logistics", 0.9),
  1278. new("TRANS_PORT", "港口自动化", "Port Automation", 0.85),
  1279. new("LOG_COLD", "冷链物流", "Cold Chain Logistics", 0.8)
  1280. }),
  1281. // 4. 城乡建设与规划
  1282. new("URBAN_RURAL", "城乡建设与规划领域", "Urban & Rural Construction", 1.0,
  1283. Children: new()
  1284. {
  1285. new("URBAN_SMART", "智慧城市", "Smart City", 0.9),
  1286. new("URBAN_GREEN", "绿色建筑", "Green Building", 0.85),
  1287. new("URBAN_UPDATE", "城市更新", "Urban Renewal", 0.8)
  1288. }),
  1289. // 5. 生态环境与水务
  1290. new("ECO_ENV", "生态环境与水务领域", "Ecology & Water Affairs", 1.0,
  1291. Children: new()
  1292. {
  1293. new("ENV_WATER", "水处理", "Water Treatment", 0.9),
  1294. new("ENV_SOLID", "固废处理", "Solid Waste Treatment", 0.85),
  1295. new("ENV_MONITOR", "环境监测", "Environmental Monitoring", 0.8)
  1296. }),
  1297. // 6. 农业与食品
  1298. new("AGRI_FOOD", "农业与食品领域", "Agriculture & Food", 1.0,
  1299. Children: new()
  1300. {
  1301. new("AGRI_SMART", "智慧农业", "Smart Agriculture", 0.9),
  1302. new("FOOD_PROC", "农产品加工", "Food Processing", 0.85),
  1303. new("AGRI_SEED", "种业技术", "Seed Technology", 0.8)
  1304. }),
  1305. // 7. 金融与商贸
  1306. new("FIN_TRADE", "金融与商贸领域", "Finance & Commerce", 1.0,
  1307. Children: new()
  1308. {
  1309. new("FIN_TECH", "金融科技", "FinTech", 0.9),
  1310. new("TRADE_E", "跨境电商", "Cross-border E-commerce", 0.85),
  1311. new("FIN_SUPPLY", "供应链金融", "Supply Chain Finance", 0.8)
  1312. }),
  1313. // 8. 医药健康与康养
  1314. new("MED_HEALTH", "医药健康与康养领域", "Medicine & Health", 1.0,
  1315. Children: new()
  1316. {
  1317. new("MED_BIO", "生物医药", "Biopharma", 0.9),
  1318. new("MED_DEVICE", "医疗器械", "Medical Devices", 0.85),
  1319. new("HEALTH_CARE", "康复养老", "Rehabilitation & Elderly Care", 0.8)
  1320. }),
  1321. // 9. 文化旅游与体育
  1322. new("CULT_TOUR", "文化旅游与体育领域", "Culture, Tourism & Sports", 1.0,
  1323. Children: new()
  1324. {
  1325. new("TOUR_DIGITAL", "数字文旅", "Digital Culture & Tourism", 0.9),
  1326. new("SPORT_EVENT", "体育赛事运营", "Sports Event Management", 0.85),
  1327. new("CULT_CREATIVE", "文创设计", "Cultural Creativity", 0.8)
  1328. }),
  1329. // 10. 信息科技与数字经济
  1330. new("IT_DIGITAL", "信息科技与数字经济领域", "IT & Digital Economy", 1.0,
  1331. Children: new()
  1332. {
  1333. new("IT_SOFT", "软件", "Software", 1.0,
  1334. Children: new()
  1335. {
  1336. new("SOFT_SAAS", "SaaS", "SaaS", 0.9),
  1337. new("IT_AI", "AI", "Artificial Intelligence", 0.9),
  1338. new("IT_BIGDATA", "大数据", "Big Data", 0.85),
  1339. new("IT_CLOUD", "云计算", "Cloud Computing", 0.6)
  1340. }),
  1341. new("IT_IOT", "工业互联网", "Industrial Internet", 0.85)
  1342. }),
  1343. // 11. 教育与科技
  1344. new("EDU_TECH", "教育与科技领域", "Education & Technology", 1.0,
  1345. Children: new()
  1346. {
  1347. new("EDU_ONLINE", "在线教育", "Online Education", 0.9),
  1348. new("EDU_VOC", "职业教育", "Vocational Education", 0.85),
  1349. new("EDU_INFO", "教育信息化", "Education Informatization", 0.8)
  1350. }),
  1351. // 12. 社会服务与公共管理
  1352. new("SOC_SERVICE", "社会服务与公共管理领域", "Social Services", 1.0,
  1353. Children: new()
  1354. {
  1355. new("GOV_SMART", "智慧政务", "Smart Government", 0.9),
  1356. new("COMMUNITY", "社区治理", "Community Governance", 0.85),
  1357. new("NGO", "公益慈善", "Charity & NGO", 0.7)
  1358. }),
  1359. // 13. 其他重点领域
  1360. new("OTHER_KEY", "其他重点领域", "Other Key Fields", 1.0,
  1361. Children: new()
  1362. {
  1363. new("EMERGENCY", "应急管理", "Emergency Management", 0.9),
  1364. new("GEO_SURVEY", "地质勘察", "Geological Survey", 0.85),
  1365. new("IP_SERVICE", "知识产权服务", "IP Services", 0.8)
  1366. })
  1367. };
  1368. }
  1369. public static class IndustryExpander
  1370. {
  1371. public static List<string> Expand(
  1372. List<string> baseIndustries,
  1373. List<IndustryNode> tree)
  1374. {
  1375. var result = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
  1376. foreach (var baseIndName in baseIndustries)
  1377. {
  1378. var node = tree.FirstOrDefault(n =>
  1379. n.NameCn.Equals(baseIndName, StringComparison.OrdinalIgnoreCase));
  1380. if (node == null) continue;
  1381. // 添加主行业
  1382. result.Add(node.NameCn);
  1383. // 递归添加子行业(按权重降序)
  1384. if (node.Children != null)
  1385. {
  1386. AddChildrenRecursive(node.Children, result);
  1387. }
  1388. }
  1389. return result.ToList();
  1390. }
  1391. private static void AddChildrenRecursive(
  1392. List<IndustryNode> nodes,
  1393. HashSet<string> result)
  1394. {
  1395. foreach (var child in nodes.OrderByDescending(n => n.Weight))
  1396. {
  1397. result.Add(child.NameCn);
  1398. if (child.Children != null)
  1399. {
  1400. AddChildrenRecursive(child.Children, result);
  1401. }
  1402. }
  1403. }
  1404. }
  1405. public static class QuotaScheduler
  1406. {
  1407. /// <summary>
  1408. /// 国家配额计算(根据 行业、规模)
  1409. /// </summary>
  1410. /// <param name="countryTasks"></param>
  1411. /// <param name="industries"></param>
  1412. /// <param name="scales"></param>
  1413. /// <returns></returns>
  1414. public static List<AITaskItem> GenerateTasks(
  1415. List<CountryAIPormptInfo> countryTasks,
  1416. List<string> industries,
  1417. List<string> scales)
  1418. {
  1419. if (!countryTasks.Any() || !industries.Any() || !scales.Any())
  1420. return new List<AITaskItem>();
  1421. var rnd = new Random();
  1422. // 1. 行业延伸
  1423. var expandedIndustries = IndustryExpander.Expand(
  1424. industries,
  1425. IndustryTree.Build()
  1426. );
  1427. // 2. Country -> Region (中文)
  1428. var regionGroups = countryTasks
  1429. .Select(ct => new
  1430. {
  1431. Region = CountryToRegionMapper.GetRegion(ct.Country),
  1432. ct.Count
  1433. })
  1434. .GroupBy(x => x.Region)
  1435. .ToList();
  1436. int totalRequested = regionGroups.Sum(g => g.Sum(x => x.Count));
  1437. var tasks = new List<AITaskItem>();
  1438. int totalTaskCount = countryTasks.Sum(x => x.Count);
  1439. // 3. 按权重生成(Region 30%)
  1440. foreach (var group in regionGroups)
  1441. {
  1442. double weight = (double)group.Sum(x => x.Count) / totalRequested;
  1443. int quota = (int)Math.Round(weight * totalTaskCount * 0.3);
  1444. for (int i = 0; i < quota; i++)
  1445. {
  1446. tasks.Add(new AITaskItem
  1447. {
  1448. Region = group.Key, // 中文国家名
  1449. Industry = expandedIndustries[rnd.Next(expandedIndustries.Count)],
  1450. Scale = scales[rnd.Next(scales.Count)]
  1451. });
  1452. }
  1453. }
  1454. return tasks
  1455. .OrderBy(_ => rnd.Next())
  1456. .ToList();
  1457. }
  1458. }
  1459. #endregion
  1460. /// <summary>
  1461. /// 混元提示词构建(高度定制化,适配商邀资料场景)
  1462. /// </summary>
  1463. /// <param name="tasks">包含国家及 Count 数量的任务列表</param>
  1464. /// <param name="countryTasks"></param>
  1465. /// <param name="entryInfo">包含规则基础信息</param>
  1466. /// <returns>最终构建的 System Prompt 字符串</returns>
  1467. public static string BuildHunyuanPrompt(List<CountryAIPormptInfo> tasks, List<AITaskItem> countryTasks, EntryInfo entryInfo)
  1468. {
  1469. // 行业信息,用于提示词硬约束
  1470. string industryEnum = string.Join("、", IndustryTree.Build().Select(x => x.NameCn).ToList());
  1471. var businessConstraints = new StringBuilder();
  1472. if (entryInfo.Industries.Any()) businessConstraints.AppendLine($" - 行业信息: {string.Join("、", entryInfo.Industries)}");
  1473. if (entryInfo.ScaleTypes.Any()) businessConstraints.AppendLine($" - 单位规模: {string.Join("、", entryInfo.ScaleTypes)}");
  1474. if (entryInfo.IsBackground) businessConstraints.AppendLine($" - 单位是否包含华人背景: 是");
  1475. if (!string.IsNullOrEmpty(entryInfo.OrgLevel) && !entryInfo.OrgLevel.Equals("全部")) businessConstraints.AppendLine($" - 公司层级: {entryInfo.OrgLevel}");
  1476. if (!string.IsNullOrEmpty(entryInfo.OtherConstraints)) businessConstraints.AppendLine($" - 其他规则: {entryInfo.OtherConstraints}");
  1477. if (businessConstraints == null || businessConstraints.Length == 0) businessConstraints.AppendLine("无");
  1478. return $@"
  1479. # [SYSTEM_ROLE]
  1480. 你是精通全球实时经贸情报的【顶级商务咨询顾问】。
  1481. 你具备资深 .NET 6 架构思维,输出 JSON 必须 100% 兼容强类型反序列化。遵循“无存证不输出、官网优先溯源、AB管道证伪、零虚构熔断”的最高数据纯度准则。
  1482. # [CONTEXT_ANALYSIS]
  1483. • 当前核查基准时间 (CurrentDate): {DateTime.Now:yyyy-MM-dd} (锁定动态年份为绝对时空锚点)
  1484. • 发起单位 (OriginUnit): {entryInfo.OriginUnit}
  1485. • 业务硬性约束 (BusinessConstraints): {businessConstraints}
  1486. • 核心驱动配置 (CountryTasks): {JsonConvert.SerializeObject(countryTasks)}
  1487. • 任务配额分配 (Tasks): {JsonConvert.SerializeObject(tasks)}
  1488. # [REALITY_CHECK_RULES - 严禁虚构与存证审计标准]
  1489. ## 1. 企业存在性“三位一体”核验 (Anti-Hallucination)
  1490. - **核心原则**:严禁推测、编造、组合不存在的企业名称。必须严格按照 `CountryTasks` 定义的区域执行检索。
  1491. - **验证链条**:
  1492. 1. **官网验证**:SiteUrl 必须真实可访问,且内容与企业业务高度吻合。
  1493. 2. **管道 A (官方公示)**:必须在目标国工商注册局、证监会或经商处有备案。
  1494. 3. **管道 B (公正存证)**:必须在 LinkedIn (官方认证页)、Bloomberg 或 Crunchbase 有实时动态。
  1495. - **熔断判定**:若以上三项均无法交叉证实企业真实存在性,该条目必须立即废弃。
  1496. ## 2. 软 404 与“FoundPage”假死内容熔断
  1497. - **实质内容审计**:即便 URL 响应 200,若页面包含以下特征,必须判定为**死链**并熔断:
  1498. - **特征词**:`404 Not Found`, `Page Not Found`, `Oops`, `Seite nicht gefunden`, `foundpage`, `链接不存在`.
  1499. - **主站熔断**:若 `SiteUrl` 触碰报错特征,该企业条目整体作废;若仅 `PostUrl` 触碰,则动态字段返回 `[]`。
  1500. ## 3. 信息溯源:官网优先与 AB 管道补位
  1501. - **首要来源**:新闻 (PostUrl)、联系人 (Contact) 与邮件 (Email) 必须优先从企业官网提取。
  1502. - **补位机制**:仅当官网无法获取联系信息时,允许从 AB 管道(管道B认证页)提取 {DateTime.Now.AddYears(-3).Year}-{DateTime.Now.Year} 年间的实时活跃数据。
  1503. ## 4. 属地物理地址强校验 (GEO_ADDRESS_STRICTNESS)
  1504. - **物理属地锁定原则**:企业必须是在目标国家**实际运营、注册并拥有实体办公场所**的主体,严禁接受虚拟办公室、共享注册地址或仅用于税务/法律注册的空壳地址。
  1505. - **地址真实性审计流程**:
  1506. 1. **地理一致性校验**:`Address` 字段必须位于 `CountryTasks` 指定的国家境内,且与官网“Contact / Imprint / About Us”页面披露的实体地址完全一致。
  1507. 2. **地图实体验证(AB 管道)**:必须通过 Google Maps / OpenStreetMap 等权威地理服务验证该地址对应真实建筑,且建筑内确实挂有该企业标识(或街景证据)。
  1508. 3. **虚拟地址熔断**:若地址被识别为虚拟办公、信箱服务(P.O. Box)或商业中心,该条目**整条作废**。
  1509. - **输出规范**:`Address` 必须返回**可直接复制粘贴到 Google Maps、百度地图、Apple 地图等主流地图服务中进行搜索和导航的完整物理地址**。格式要求:街道地址 + 城市 + 州/省 + 邮政编码 + 国家。地址中必须包含可被地图服务准确识别的**邮政编码**。
  1510. # [BUSINESS_CONSTRAINTS_SCHEMA]
  1511. - **零虚构原则**:绝对禁止编造任何不存在的企业、人名、链接或动态。
  1512. - **行业约束**:Industry 必须严格锁定在业务定义的范围内,严禁跨类延伸。
  1513. - **规模匹配**:Scale 必须严格匹配“单位规模”集合定义。
  1514. - **英文命名清洗规则 (NAMING_CONVENTION_EN_CLEAN)**:在 `NameEn` 字段中,**严禁出现任何法律实体后缀标识**。包括但不限于:`PTY LTD`, `LTD`, `LIMITED`, `LLC`, `INC`, `CORP`, `PLC`, `GMBH`, `AG`, `SAS`, `SARL`, `BV`, `NV` 等。`NameEn` 应仅保留企业**核心品牌名或商号 (Trading Name)**,确保与官网首页主 Title 保持一致。若清洗后 `NameEn` 为空或仅剩通用词,该条目视为**无效命名并整体废弃**。
  1515. # [QUOTA_SCHEDULING - 动态再分配算法]
  1516. - **名额平移**:若 `CountryTasks` 指定的某国家因“官网失效/无法证伪”导致有效条目不足,允许实际输出数 < 理论配额。
  1517. - **禁止凑数**:名额自动向质量更高、官网更活跃的国家转移,严禁为了填满 JSON 而降低审计标准。
  1518. # [THOUGHT_PROCESS_LOGIC]
  1519. 1. 解析 `CountryTasks` 与 `BusinessConstraints` -> 2. 执行 {DateTime.Now.Year} 实时检索 -> 3. **执行存在性三位一体核验(证伪熔断)** -> 4. **扫描官网内容(识别并过滤软404)** -> 5. **属地物理地址强校验** -> 6. **英文命名清洗** -> 7. **以官网为核心、AB管道为备份提取字段** -> 8. 生成纯净 JSON。
  1520. # [STRICT_DATA_CONTRACT]
  1521. 属性命名遵循 PascalCase,禁止新增字段:
  1522. [
  1523. {{
  1524. ""Region"": ""string"",
  1525. ""Industry"": ""string"",
  1526. ""Scale"": ""string"",
  1527. ""NameCn"": ""string"",
  1528. ""NameEn"": ""string"",
  1529. ""Address"": ""string"",
  1530. ""Scope"": ""string"",
  1531. ""Contact"": ""string"",
  1532. ""Phone"": ""string"",
  1533. ""Email"": ""string"",
  1534. ""SiteUrl"": ""string"",
  1535. ""PostUrl"": [ {{ ""Date"": ""yyyy-MM-dd"", ""Description"": ""string"", ""Url"": ""string"" }} ],
  1536. ""RecLevel"": ""Core|Backup"",
  1537. ""IntgAdvice"": ""string""
  1538. }}
  1539. ]
  1540. # [HUNYUAN_OUTPUT_GUARDRAILS]
  1541. 你是一个严格的 JSON 生成器。
  1542. 1. 最高禁令:绝对禁止编造任何不存在的企业、人名、链接或动态。
  1543. 2. 输出洁癖:不输出 Markdown 标记、不输出任何解释文字或思考过程。
  1544. 3. 边界控制:首字符 [,末字符 ]。结果为空输出 []。
  1545. # [EXECUTION]
  1546. 立即执行:以动态年份为锚点,执行严苛的企业真实性审计与软 404 熔断逻辑,严禁虚构任何信息,按契约输出纯净 JSON。
  1547. ";
  1548. }
  1549. #endregion
  1550. #region 基础数据 整合
  1551. /// <summary>
  1552. /// 商邀AI invName 整合
  1553. /// </summary>
  1554. /// <returns></returns>
  1555. public static async Task<List<InvitationAIInvNameView>> InvitationAIInvName()
  1556. {
  1557. // 预定义 UnionAll 查询
  1558. var query1 = _sqlSugar.Queryable<Grp_DelegationInfo>()
  1559. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.TeamName))
  1560. .Select(x => new InvitationAIInvNameView { Id = x.Id, Name = x.TeamName, Source = 1, SortTime = x.VisitDate });
  1561. var query2 = _sqlSugar.Queryable<Res_InvitationAI>()
  1562. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.InvName))
  1563. .Select(x => new InvitationAIInvNameView { Id = x.Id, Name = x.InvName, Source = 2, SortTime = x.CreateTime });
  1564. var unionQuery = _sqlSugar.UnionAll(query1, query2);
  1565. // 先进行去重逻辑处理
  1566. var distinctQuery = _sqlSugar.Queryable(unionQuery)
  1567. .PartitionBy(it => it.Name)
  1568. .OrderByDescending(it => it.SortTime)
  1569. .Select(it => it);
  1570. // 将去重后的结果包装,再进行全局
  1571. return await _sqlSugar.Queryable(distinctQuery)
  1572. .OrderByDescending(it => it.Source)
  1573. .OrderByDescending(it => it.SortTime)
  1574. .ToListAsync();
  1575. }
  1576. /// <summary>
  1577. /// 商邀AI-无团组 invName 整合
  1578. /// </summary>
  1579. /// <returns></returns>
  1580. public static async Task<List<InvitationAIInvNameView>> InvitationAI_NoGroupInvName()
  1581. {
  1582. return await _sqlSugar.Queryable<Res_InvitationAI_NoGroup>()
  1583. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.InvName))
  1584. .Select(x => new InvitationAIInvNameView { Id = x.Id, Name = x.InvName, Source = 2, SortTime = x.CreateTime })
  1585. .OrderByDescending(it => it.Source)
  1586. .OrderByDescending(it => it.SortTime)
  1587. .ToListAsync();
  1588. }
  1589. /// <summary>
  1590. /// 商邀AI ClientName 处理
  1591. /// </summary>
  1592. /// <returns></returns>
  1593. public static async Task<List<string>> InvitationAIClientName()
  1594. {
  1595. var rawEncryptedDatas = await _sqlSugar.Queryable<Crm_NewClientData>()
  1596. .Where(x => x.IsDel == 0 && x.Client != null)
  1597. .Select(x => x.Client)
  1598. .ToListAsync();
  1599. // 解密 -> 去空格 -> 排除横杠 -> 去重
  1600. var unitNames = rawEncryptedDatas
  1601. .Select(encryptedItem =>
  1602. {
  1603. try
  1604. {
  1605. return AesEncryptionHelper.Decrypt(encryptedItem);
  1606. }
  1607. catch
  1608. {
  1609. return null; // 异常解密处理
  1610. }
  1611. })
  1612. .Where(decrypted => !string.IsNullOrWhiteSpace(decrypted)) // 排除空或纯空格
  1613. .Select(decrypted => decrypted.Replace(" ", "")) // 去除所有内部空格
  1614. .Where(cleaned => !cleaned.Contains("-")) // 此时过滤解密后的 "-" 才有效
  1615. .Distinct() // 最终去重
  1616. .ToList();
  1617. return unitNames;
  1618. }
  1619. /// <summary>
  1620. /// 商邀AI CountryName 处理
  1621. /// </summary>
  1622. /// <returns></returns>
  1623. public static async Task<List<string>> InvitationAICountryName()
  1624. {
  1625. return await _sqlSugar.Queryable<Sys_Countries>()
  1626. .Where(x => x.IsDel == 0)
  1627. .Select(x => x.Name_CN)
  1628. .Distinct()
  1629. .ToListAsync();
  1630. }
  1631. #endregion
  1632. #endregion
  1633. #region op地接资料 AI
  1634. #region 提示词构建
  1635. /// <summary>
  1636. /// 混元提示词构建(国外地接公司 · AI 自动采集专用 · 完整最终版)
  1637. /// </summary>
  1638. /// <param name="tasks">国家 & 数量配额</param>
  1639. /// <param name="entryInfo">业务约束</param>
  1640. /// <returns>System Prompt</returns>
  1641. public static string OpLocalBuildHunyuanPrompt(
  1642. List<CountryAIPormptInfo> tasks,
  1643. EntryInfo entryInfo)
  1644. {
  1645. #region 1. 业务约束拼接
  1646. var businessConstraints = new StringBuilder();
  1647. if (entryInfo.ScaleTypes?.Any() == true)
  1648. businessConstraints.AppendLine($" - 单位规模: {string.Join("、", entryInfo.ScaleTypes)}");
  1649. if (entryInfo.IsBackground)
  1650. businessConstraints.AppendLine(" - 是否包含华人背景: 是");
  1651. if (!string.IsNullOrEmpty(entryInfo.OrgLevel) && entryInfo.OrgLevel != "全部")
  1652. businessConstraints.AppendLine($" - 公司层级: {entryInfo.OrgLevel}");
  1653. if (!string.IsNullOrEmpty(entryInfo.OtherConstraints))
  1654. businessConstraints.AppendLine($" - 其他规则: {entryInfo.OtherConstraints}");
  1655. if (businessConstraints.Length == 0)
  1656. businessConstraints.AppendLine("无");
  1657. #endregion
  1658. #region 2. Prompt 主体
  1659. return $@"
  1660. # [SYSTEM_ROLE]
  1661. 你是全球旅游与地接行业的【顶级情报采集系统】。
  1662. 你具备 .NET 6 强类型架构思维,输出 JSON 必须 100% 可直接反序列化。
  1663. 你信奉唯一铁律:**无官网不收录、无许可不采信、无存证不输出**。
  1664. # [CONTEXT_ANALYSIS]
  1665. • 基准时间: {DateTime.Now:yyyy-MM-dd}
  1666. • 业务约束:
  1667. {businessConstraints}
  1668. # [COUNTRY_QUOTA_MATRIX - 动态国家配额]
  1669. 以下为国家及其对应的**最大获取数量**(严格锁定):
  1670. {string.Join("\n", tasks.Select(t => $"- {t.Country}: {t.Count} 家"))}
  1671. 🚨 配额规则:
  1672. - 每个国家 **不得超过** 指定数量
  1673. - 若无法满足数量要求,**允许少于配额**
  1674. - 严禁跨国家凑数
  1675. - 严禁编造企业填补空缺
  1676. # [COUNTRY_SCOPE_LOCK - 国家白名单]
  1677. 允许采集的国家列表(严格锁定):
  1678. {string.Join("、", tasks.Select(t => t.Country))}
  1679. 🚨 最高禁令:
  1680. - 严禁采集上述国家以外的任何地接公司
  1681. - 严禁通过翻译、联想、扩展国家名称
  1682. # [CORE_COLLECTION_RULES - 自动采集五锁机制]
  1683. ## 🔒 锁 1:企业存在性(Anti-Hallucination)
  1684. - 严禁编造、推测或拼接地接公司名称
  1685. - 必须同时满足:
  1686. 1. 官网可访问(SiteUrl)
  1687. 2. 当地旅游许可可查证
  1688. 3. Google Maps 存在实体办公地址
  1689. ## 🔒 锁 2:官网真实性(Soft-404 熔断)
  1690. - 若 SiteUrl 命中以下特征 → 整条作废:
  1691. - 404 / Not Found / Oops
  1692. - Seite nicht gefunden
  1693. - foundpage / 链接不存在
  1694. ## 🔒 锁 3:属地物理地址(GEO_LOCK)
  1695. - 禁止虚拟办公室 / 信箱 / 注册代理地址
  1696. - 地址必须:
  1697. - 位于指定国家境内
  1698. - 与官网 Contact / Imprint 页面一致
  1699. - Google Maps / Apple Maps 可精确定位
  1700. - 输出格式:街道 + 城市 + 州/省 + 邮编 + 国家
  1701. ## 🔒 锁 4:车队与资源真实性(FLEET_REALITY_LOCK)
  1702. - 必须同时包含:
  1703. - 数量(如:15辆)
  1704. - 品牌 + 车型(如:奔驰商务)
  1705. - 座位数(如:7座)
  1706. - 推荐格式:
  1707. > 15辆奔驰商务(7座)
  1708. - 模糊描述 → FleetInfo 返回空
  1709. ## 🔒 锁 5:Email 校验与复制规则(VALIDATE_THEN_COPY)
  1710. ### ✅ 校验流程
  1711. AI 必须按顺序执行:
  1712. 1. 格式合法(xxx@domain.com)
  1713. 2. 域名可解析
  1714. 3. MX 记录存在(逻辑判断)
  1715. 4. 邮箱域名 ≈ 官网域名(关键)
  1716. ### ✅ 复制规则
  1717. - **仅当 1+2+3+4 全部通过**
  1718. → 才写入 `Email`
  1719. - 否则:
  1720. - `Email` 返回空
  1721. - 原始邮箱写入 `EmailInfo.Address`
  1722. ### 🚨 严禁
  1723. - 将未通过校验的邮箱写入 Email
  1724. - 为了“有数据”强行复制
  1725. # [OUTPUT_SCHEMA - STRICT]
  1726. 属性命名 PascalCase,禁止新增字段:
  1727. [
  1728. {{
  1729. ""Region"": ""string"",
  1730. ""Industry"": ""旅游与地接"",
  1731. ""Scale"": ""string"",
  1732. ""NameCn"": ""string"",
  1733. ""NameEn"": ""string"",
  1734. ""Address"": ""string"",
  1735. ""Scope"": ""string"",
  1736. ""Contact"": ""string"",
  1737. ""Phone"": ""string"",
  1738. ""Email"": ""string"",
  1739. ""SiteUrl"": ""string"",
  1740. ""PostUrl"": [
  1741. {{ ""Date"": ""yyyy-MM-dd"", ""Description"": ""string"", ""Url"": ""string"" }}
  1742. ],
  1743. ""RecLevel"": ""Core|Backup"",
  1744. ""IntgAdvice"": ""string"",
  1745. ""RiskNote"": ""string"",
  1746. ""License"": {{
  1747. ""LicenseNo"": ""string"",
  1748. ""LocalLicense"": ""string"",
  1749. ""DotNumber"": ""string"",
  1750. ""AssociationMember"": ""string"",
  1751. ""LiabilityInsurance"": ""string""
  1752. }},
  1753. ""Resource"": {{
  1754. ""BusinessScope"": ""string"",
  1755. ""FleetInfo"": ""string"",
  1756. ""GuideInfo"": ""string"",
  1757. ""DirectContract"": ""string"",
  1758. ""IsDirectSupplier"": true
  1759. }}
  1760. }}
  1761. ]
  1762. # [OUTPUT_GUARDRAILS]
  1763. - 仅输出 JSON
  1764. - 不输出 Markdown
  1765. - 不输出解释、不输出思考过程
  1766. - 首字符 `[`,末字符 `]`
  1767. - 无结果时输出 `[]`
  1768. # [EXECUTE_NOW]
  1769. 以 {DateTime.Now:yyyy-MM-dd} 为时间锚点,
  1770. 仅在以下国家范围内执行全自动采集:
  1771. {string.Join("、", tasks.Select(t => t.Country))}
  1772. 并严格遵守各国配额限制,
  1773. 执行五锁机制,输出纯净 JSON。
  1774. ";
  1775. #endregion
  1776. }
  1777. public class AICreateEmailTask
  1778. {
  1779. public string Country { get; set; }
  1780. public string City { get; set; }
  1781. public int PersonCount { get; set; }
  1782. public string DateRange { get; set; }
  1783. public List<LocalAgencyInfo> Agencies { get; set; }
  1784. public EntryInfo EntryInfo { get; set; }
  1785. }
  1786. /// <summary>
  1787. /// 混元提示词构建(多公司 / 多国家 / 多城市)
  1788. /// </summary>
  1789. public static string BuildBatchCreateEmailPrompt(
  1790. AICreateEmailTask task)
  1791. {
  1792. var agenciesJson = JsonConvert.SerializeObject(
  1793. task.Agencies.Select(a => new
  1794. {
  1795. a.NameCn,
  1796. a.NameEn,
  1797. a.Region,
  1798. //a.City,
  1799. a.Contact,
  1800. a.Email,
  1801. a.SiteUrl,
  1802. a.Scope,
  1803. a.Resource?.FleetInfo
  1804. }));
  1805. return $@"
  1806. # [SYSTEM_ROLE]
  1807. 你是国际地接与商务考察的【用车与报价专家】。
  1808. 你具备 .NET 强类型架构思维,输出 JSON 必须 100% 可直接反序列化。
  1809. # [CONTEXT]
  1810. • 当前时间: {DateTime.Now:yyyy-MM-dd}
  1811. • 发起单位: {task.EntryInfo.OriginUnit}
  1812. • 出访人数: {task.PersonCount}
  1813. • 出访日期: {task.DateRange}
  1814. # [TASK]
  1815. 请针对以下每家地接公司,分别生成一封**首次报价请求邮件**:
  1816. {agenciesJson}
  1817. # [RULES - 每家公司独立处理]
  1818. 1. 每家公司:
  1819. - 国家 = Company.Region
  1820. - 城市 = Company.City
  1821. - 车型必须基于 Company.FleetInfo
  1822. 2. 禁止编造车型
  1823. 3. 若 FleetInfo 无法匹配人数:
  1824. - 请在邮件中说明
  1825. - 请对方推荐替代方案
  1826. 4. 邮件语言:
  1827. - 默认:英文
  1828. - Region = 日本 → 追加日文
  1829. - Region = 韩国 → 追加韩文
  1830. # [OUTPUT_SCHEMA - STRICT]
  1831. 请返回 JSON 数组,每项对应一家公司:
  1832. [
  1833. {{
  1834. ""Guid"": """",
  1835. ""NameCn"": ""string"",
  1836. ""Scope"": ""string"",
  1837. ""Subject"": ""string"",
  1838. ""Content"": ""string(纯文本,\n 表示换行)""
  1839. }}
  1840. ]
  1841. # [OUTPUT_GUARDRAILS]
  1842. - 仅输出 JSON
  1843. - 不输出 Markdown
  1844. - 不输出解释
  1845. - 首字符 [,末字符 ]
  1846. # [EXECUTE_NOW]
  1847. 基于上述公司列表,
  1848. 为每家公司生成一封高回复率的首次报价请求邮件,
  1849. 并以 AICreateEmailInfo 格式返回纯净 JSON。
  1850. ";
  1851. }
  1852. #endregion
  1853. #region 基础数据
  1854. /// <summary>
  1855. /// op地接资料AI 团组名称整理
  1856. /// </summary>
  1857. /// <returns></returns>
  1858. public static async Task<List<InvitationAIInvNameView>> OpLocalServiceAINames()
  1859. {
  1860. // 预定义 UnionAll 查询
  1861. var query1 = _sqlSugar.Queryable<Grp_DelegationInfo>()
  1862. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.TeamName))
  1863. .Select(x => new InvitationAIInvNameView { Id = x.Id, Name = x.TeamName, Source = 1, SortTime = x.VisitDate });
  1864. var unionQuery = _sqlSugar.UnionAll(query1);
  1865. // 先进行去重逻辑处理
  1866. var distinctQuery = _sqlSugar.Queryable(unionQuery)
  1867. .PartitionBy(it => it.Name)
  1868. .OrderByDescending(it => it.SortTime)
  1869. .Select(it => it);
  1870. // 将去重后的结果包装,再进行全局
  1871. return await _sqlSugar.Queryable(distinctQuery)
  1872. .OrderByDescending(it => it.Source)
  1873. .OrderByDescending(it => it.SortTime)
  1874. .ToListAsync();
  1875. }
  1876. #endregion
  1877. #endregion
  1878. #endregion
  1879. #region 团组汇率
  1880. /// <summary>
  1881. /// 团组汇率
  1882. /// 获取板块 币种 及 汇率
  1883. /// 76 酒店预订 77 行程 79 车/导游地接
  1884. /// 80 签证 82 团组客户保险 85 机票预订
  1885. /// 98 其他款项 285 收款退还
  1886. /// </summary>
  1887. /// <param name="teamRateModels"></param>
  1888. /// <param name="cTable"></param>
  1889. /// <param name="currencyCodes"></param>
  1890. /// <returns>
  1891. /// string
  1892. /// eg: CNY 1.0000
  1893. /// </returns>
  1894. public static async Task<string> PostGroupRateByCTableAndCurrency(List<TeamRateModelView> teamRateModels, int cTable, List<string> currencyCodes)
  1895. {
  1896. string str = "";
  1897. List<string> currencyRates = new List<string>();
  1898. TeamRateModelView hotelRateData = teamRateModels.Where(it => it.CTableId == cTable).FirstOrDefault();
  1899. if (hotelRateData != null)
  1900. {
  1901. var hotelRates = hotelRateData.TeamRates;
  1902. foreach (var item in currencyCodes)
  1903. {
  1904. if (!string.IsNullOrEmpty(item))
  1905. {
  1906. var hotelRateInfo = hotelRates.Where(it => it.CurrencyCode.Equals(item)).FirstOrDefault();
  1907. if (hotelRateInfo != null)
  1908. {
  1909. string str1 = string.Format("{0} {1}\r\n", hotelRateInfo.CurrencyCode, hotelRateInfo.Rate.ToString("#0.0000"));
  1910. currencyRates.Add(str1);
  1911. }
  1912. }
  1913. }
  1914. if (currencyRates != null || currencyRates.Count > 0)
  1915. {
  1916. currencyRates = currencyRates.Distinct().ToList();
  1917. foreach (var item in currencyRates)
  1918. {
  1919. str += item;
  1920. }
  1921. }
  1922. }
  1923. return str;
  1924. }
  1925. /// <summary>
  1926. /// 团组汇率 币种 Item (来源:团组汇率)
  1927. /// 根据 团组Id And 业务类型(CTable)Id
  1928. /// api处理CTable = 285,默认返回CNY
  1929. /// </summary>
  1930. /// <param name="portType"></param>
  1931. /// <param name="diId"></param>
  1932. /// <param name="cTable"></param>
  1933. /// <returns></returns>
  1934. public static async Task<TeamRateModelGeneralView> PostGroupTeamRateByDiIdAndCTableId(int portType, int diId, int cTable)
  1935. {
  1936. TeamRateModelGeneralView _view = new TeamRateModelGeneralView();
  1937. _view = await _teamRateRep.PostGroupTeamRateByDiIdAndCTableId(portType, diId, cTable);
  1938. return _view;
  1939. }
  1940. /// <summary>
  1941. /// 汇率备注拆分
  1942. /// (美元(USD):7.2370|日元(JPY):0.0499|欧元(EUR):8.3000|英镑(GBP):9.1996|港币(HKD):0.9291)
  1943. /// </summary>
  1944. /// <param name="rateRemark"></param>
  1945. /// <returns></returns>
  1946. public static async Task<List<TeamRateDescAddCurrencyIdView>> SplitExchangeRate(this string rateRemark)
  1947. {
  1948. List<TeamRateDescAddCurrencyIdView> _view = new List<TeamRateDescAddCurrencyIdView>();
  1949. List<SetDataInfoView> currencyDatas = new List<SetDataInfoView>();
  1950. #region 获取所有币种
  1951. string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0", 66);
  1952. var DBdata = _setDataRep.GetListBySqlWithNolock(sql);
  1953. if (DBdata == null || DBdata.Count == 0)
  1954. {
  1955. return _view;
  1956. }
  1957. currencyDatas = DBdata.Select(x => new SetDataInfoView
  1958. {
  1959. Name = x.Name,
  1960. Id = x.Id,
  1961. Remark = x.Remark,
  1962. }).ToList();
  1963. #endregion
  1964. #region 拆分remark里的汇率
  1965. if (string.IsNullOrEmpty(rateRemark))
  1966. {
  1967. return _view;
  1968. }
  1969. if (rateRemark.Contains("|"))
  1970. {
  1971. string[] currencyArr = rateRemark.Split("|");
  1972. foreach (string currency in currencyArr)
  1973. {
  1974. string[] currency1 = currency.Split(":");
  1975. string[] currency2 = currency1[0].Split("(");
  1976. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  1977. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  1978. {
  1979. CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
  1980. CurrencyCode = currencyCode,
  1981. CurrencyName = currency2[0],
  1982. Rate = decimal.Parse(currency1[1]),
  1983. };
  1984. _view.Add(rateDescView);
  1985. }
  1986. }
  1987. else
  1988. {
  1989. try
  1990. {
  1991. string[] currency1 = rateRemark.Split(":");
  1992. string[] currency2 = currency1[0].Split("(");
  1993. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  1994. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  1995. {
  1996. CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
  1997. CurrencyCode = currencyCode,
  1998. CurrencyName = currency2[0],
  1999. Rate = decimal.Parse(currency1[1]),
  2000. };
  2001. _view.Add(rateDescView);
  2002. }
  2003. catch (Exception)
  2004. {
  2005. return _view;
  2006. }
  2007. }
  2008. #endregion
  2009. return _view;
  2010. }
  2011. #endregion
  2012. #region 汉字转换拼音
  2013. private static Dictionary<int, List<string>> GetTotalPingYinDictionary(string text)
  2014. {
  2015. var chs = text.ToCharArray();
  2016. //记录每个汉字的全拼
  2017. Dictionary<int, List<string>> totalPingYinList = new Dictionary<int, List<string>>();
  2018. for (int i = 0; i < chs.Length; i++)
  2019. {
  2020. var pinyinList = new List<string>();
  2021. //是否是有效的汉字
  2022. if (ChineseChar.IsValidChar(chs[i]))
  2023. {
  2024. ChineseChar cc = new ChineseChar(chs[i]);
  2025. pinyinList = cc.Pinyins.Where(p => !string.IsNullOrWhiteSpace(p)).ToList();
  2026. }
  2027. else
  2028. {
  2029. pinyinList.Add(chs[i].ToString());
  2030. }
  2031. //去除声调,转小写
  2032. pinyinList = pinyinList.ConvertAll(p => Regex.Replace(p, @"\d", "").ToLower());
  2033. //去重
  2034. pinyinList = pinyinList.Where(p => !string.IsNullOrWhiteSpace(p)).Distinct().ToList();
  2035. if (pinyinList.Any())
  2036. {
  2037. totalPingYinList[i] = pinyinList;
  2038. }
  2039. }
  2040. return totalPingYinList;
  2041. }
  2042. /// <summary>
  2043. /// 获取汉语拼音全拼
  2044. /// </summary>
  2045. /// <param name="text">The string.</param>
  2046. /// <returns></returns>
  2047. public static List<string> GetTotalPingYin(this string text)
  2048. {
  2049. var result = new List<string>();
  2050. foreach (var pys in GetTotalPingYinDictionary(text))
  2051. {
  2052. var items = pys.Value;
  2053. if (result.Count <= 0)
  2054. {
  2055. result = items;
  2056. }
  2057. else
  2058. {
  2059. //全拼循环匹配
  2060. var newTotalPingYinList = new List<string>();
  2061. foreach (var totalPingYin in result)
  2062. {
  2063. newTotalPingYinList.AddRange(items.Select(item => totalPingYin + item));
  2064. }
  2065. newTotalPingYinList = newTotalPingYinList.Distinct().ToList();
  2066. result = newTotalPingYinList;
  2067. }
  2068. }
  2069. return result;
  2070. }
  2071. /// <summary>
  2072. /// 获取中文第一个拼音
  2073. /// </summary>
  2074. /// <param name="text"></param>
  2075. /// <param name="isUp"></param>
  2076. /// <returns></returns>
  2077. public static string GetTotalPingYinFirst(this string text, bool isUp = true)
  2078. {
  2079. var returnstr = string.Empty;
  2080. var enResult = text.GetTotalPingYin();
  2081. if (enResult.Count == 0)
  2082. {
  2083. returnstr = text;
  2084. }
  2085. else if (isUp)
  2086. {
  2087. returnstr = enResult[0].ToUpper();
  2088. }
  2089. else
  2090. {
  2091. returnstr = enResult[0].ToLower();
  2092. }
  2093. return returnstr;
  2094. }
  2095. /// <summary>
  2096. /// 获取汉语拼音首字母
  2097. /// </summary>
  2098. /// <param name="text"></param>
  2099. /// <returns></returns>
  2100. public static List<string> GetFirstPingYin(this string text)
  2101. {
  2102. var result = new List<string>();
  2103. foreach (var pys in GetTotalPingYinDictionary(text))
  2104. {
  2105. var items = pys.Value;
  2106. if (result.Count <= 0)
  2107. {
  2108. result = items.ConvertAll(p => p.Substring(0, 1)).Distinct().ToList();
  2109. }
  2110. else
  2111. {
  2112. //首字母循环匹配
  2113. var newFirstPingYinList = new List<string>();
  2114. foreach (var firstPingYin in result)
  2115. {
  2116. newFirstPingYinList.AddRange(items.Select(item => firstPingYin + item.Substring(0, 1)));
  2117. }
  2118. newFirstPingYinList = newFirstPingYinList.Distinct().ToList();
  2119. result = newFirstPingYinList;
  2120. }
  2121. }
  2122. return result;
  2123. }
  2124. #endregion
  2125. #region 新客户资料表 操作记录
  2126. /// <summary>
  2127. /// 新客户资料表
  2128. /// 操作记录添加
  2129. /// </summary>
  2130. /// <param name="portType"></param>
  2131. /// <param name="operationEnum"></param>
  2132. /// <param name="userId"></param>
  2133. /// <param name="dataId"></param>
  2134. /// <param name="remark"></param>
  2135. /// <returns></returns>
  2136. public static async Task<bool> NewClientOperationRecord(int portType, OperationEnum operationEnum, int userId, int dataId, string remark)
  2137. {
  2138. Crm_TableOperationRecord _TableOperationRecord = new Crm_TableOperationRecord()
  2139. {
  2140. TableName = "Crm_NewClientData",
  2141. PortType = portType,
  2142. OperationItem = operationEnum,
  2143. DataId = dataId,
  2144. CreateUserId = userId,
  2145. CreateTime = DateTime.Now,
  2146. Remark = remark
  2147. };
  2148. bool add = await _tableOperationRecordRep._Add(_TableOperationRecord);
  2149. if (add) return false;
  2150. return false;
  2151. }
  2152. #endregion
  2153. #region 金额转大写
  2154. /// <summary>
  2155. /// 金额转换为大写数字
  2156. /// <para>1、支持的最大数字:999999999999.99(玖仟玖佰玖拾玖亿玖仟玖佰玖拾玖万玖仟玖佰玖拾玖元玖角玖分)</para>
  2157. /// <para>2、小数点后最多支持两位</para>
  2158. /// </summary>
  2159. /// <param name="num">数值</param>
  2160. /// <returns></returns>
  2161. public static string ConvertCNYUpper(this decimal num)
  2162. {
  2163. if (num == 0)
  2164. {
  2165. return "零元";
  2166. }
  2167. // 解决327000000转换后缺少单位万的问题
  2168. return ConvertToChinese(num);
  2169. }
  2170. #region 实例
  2171. /// <summary>
  2172. /// 要转换的数字
  2173. /// </summary>
  2174. private static decimal j;
  2175. /// <summary>
  2176. ///
  2177. /// </summary>
  2178. private static string[] NumChineseCharacter = new string[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
  2179. /// <summary>
  2180. /// 判断输入的数字是否大于double类型
  2181. /// </summary>
  2182. private static bool IsNumber
  2183. {
  2184. get
  2185. {
  2186. if (j > decimal.MaxValue || j <= 0)
  2187. return false;
  2188. else
  2189. return true;
  2190. }
  2191. }
  2192. /// <summary>
  2193. /// 数字转换成大写汉字主函数
  2194. /// </summary>
  2195. /// <returns>返回转换后的大写汉字</returns>
  2196. public static string ConvertToChinese(decimal m)
  2197. {
  2198. j = m;
  2199. string bb = "";
  2200. if (IsNumber)
  2201. {
  2202. string str = j.ToString();
  2203. string[] Num = str.Split('.');
  2204. if (Num.Length == 1)
  2205. {
  2206. bb = NumberString(Num[0]) + "元整";
  2207. bb = bb.Replace("零零", "零");
  2208. }
  2209. else
  2210. {
  2211. bb = NumberString(Num[0]) + "元";
  2212. bb += FloatString(Num[1]);
  2213. bb = bb.Replace("零零", "零");
  2214. }
  2215. }
  2216. else
  2217. {
  2218. throw new FormatException("你输入的数字格式不正确或不是数字!");
  2219. }
  2220. return bb;
  2221. }
  2222. /// <summary>
  2223. /// 小数位转换只支持两位的小数
  2224. /// </summary>
  2225. /// <param name="Num">转换的小数</param>
  2226. /// <returns>小数转换成汉字</returns>
  2227. private static string FloatString(string Num)
  2228. {
  2229. string cc = "";
  2230. if (Num.Length > 2)
  2231. {
  2232. throw new FormatException("小数位数过多.");
  2233. }
  2234. else
  2235. {
  2236. string bb = ConvertString(Num);
  2237. int len = bb.IndexOf("零");
  2238. if (len != 0)
  2239. {
  2240. bb = bb.Replace("零", "");
  2241. if (bb.Length == 1)
  2242. {
  2243. cc = bb.Substring(0, 1) + "角";
  2244. }
  2245. else
  2246. {
  2247. cc = bb.Substring(0, 1) + "角";
  2248. cc += bb.Substring(1, 1) + "分";
  2249. }
  2250. }
  2251. else
  2252. cc = bb + "分";
  2253. }
  2254. return cc;
  2255. }
  2256. /// <summary>
  2257. /// 判断数字位数以进行拆分转换
  2258. /// </summary>
  2259. /// <param name="Num">要进行拆分的数字</param>
  2260. /// <returns>转换成的汉字</returns>
  2261. private static string NumberString(string Num)
  2262. {
  2263. string bb = "";
  2264. if (Num.Length <= 4)
  2265. {
  2266. bb = Convert4(Num);
  2267. }
  2268. else if (Num.Length > 4 && Num.Length <= 8)
  2269. {
  2270. bb = Convert4(Num.Substring(0, Num.Length - 4)) + "万";
  2271. bb += Convert4(Num.Substring(Num.Length - 4, 4));
  2272. }
  2273. else if (Num.Length > 8 && Num.Length <= 12)
  2274. {
  2275. bb = Convert4(Num.Substring(0, Num.Length - 8)) + "亿";
  2276. if (Convert4(Num.Substring(Num.Length - 8, 4)) == "")
  2277. if (Convert4(Num.Substring(Num.Length - 4, 4)) != "")
  2278. bb += "零";
  2279. else
  2280. bb += "";
  2281. else
  2282. bb += Convert4(Num.Substring(Num.Length - 8, 4)) + "万";
  2283. bb += Convert4(Num.Substring(Num.Length - 4, 4));
  2284. }
  2285. else
  2286. {
  2287. throw new Exception("整数部分最多支持12位");
  2288. }
  2289. return bb;
  2290. }
  2291. /// <summary>
  2292. /// 四位数字的转换
  2293. /// </summary>
  2294. /// <param name="Num">准备转换的四位数字</param>
  2295. /// <returns>转换以后的汉字</returns>
  2296. private static string Convert4(string Num)
  2297. {
  2298. string bb = "";
  2299. if (Num.Length == 1)
  2300. {
  2301. bb = ConvertString(Num);
  2302. }
  2303. else if (Num.Length == 2)
  2304. {
  2305. bb = ConvertString(Num);
  2306. bb = Convert2(bb);
  2307. }
  2308. else if (Num.Length == 3)
  2309. {
  2310. bb = ConvertString(Num);
  2311. bb = Convert3(bb);
  2312. }
  2313. else
  2314. {
  2315. bb = ConvertString(Num);
  2316. string cc = "";
  2317. string len = bb.Substring(0, 4);
  2318. if (len != "零零零零")
  2319. {
  2320. len = bb.Substring(0, 3);
  2321. if (len != "零零零")
  2322. {
  2323. bb = bb.Replace("零零零", "");
  2324. if (bb.Length == 1)
  2325. {
  2326. bb = bb.Substring(0, 1) + "仟";
  2327. }
  2328. else
  2329. {
  2330. if (bb.Substring(0, 1) != "零" && bb.Substring(0, 2) != "零")
  2331. cc = bb.Substring(0, 1) + "仟";
  2332. else
  2333. cc = bb.Substring(0, 1);
  2334. bb = cc + Convert3(bb.Substring(1, 3));
  2335. }
  2336. }
  2337. else
  2338. {
  2339. bb = bb.Replace("零零零", "零");
  2340. }
  2341. }
  2342. else
  2343. {
  2344. bb = bb.Replace("零零零零", "");
  2345. }
  2346. }
  2347. return bb;
  2348. }
  2349. /// <summary>
  2350. /// 将数字转换成汉字
  2351. /// </summary>
  2352. /// <param name="Num">需要转换的数字</param>
  2353. /// <returns>转换后的汉字</returns>
  2354. private static string ConvertString(string Num)
  2355. {
  2356. string bb = "";
  2357. for (int i = 0; i < Num.Length; i++)
  2358. {
  2359. bb += NumChineseCharacter[int.Parse(Num.Substring(i, 1))];
  2360. }
  2361. return bb;
  2362. }
  2363. /// <summary>
  2364. /// 两位数字的转换
  2365. /// </summary>
  2366. /// <param name="Num">两位数字</param>
  2367. /// <returns>转换后的汉字</returns>
  2368. private static string Convert2(string Num)
  2369. {
  2370. string bb = ""; string cc = "";
  2371. string len = Num.Substring(0, 1);
  2372. if (len != "零")
  2373. {
  2374. bb = Num.Replace("零", "");
  2375. if (bb.Length == 1)
  2376. {
  2377. cc = bb.Substring(0, 1) + "拾";
  2378. }
  2379. else
  2380. {
  2381. cc = bb.Substring(0, 1) + "拾";
  2382. cc += bb.Substring(1, 1);
  2383. }
  2384. }
  2385. else
  2386. cc = Num;
  2387. return cc;
  2388. }
  2389. /// <summary>
  2390. /// 三位数字的转换
  2391. /// </summary>
  2392. /// <param name="Num">三位数字</param>
  2393. /// <returns>转换后的汉字</returns>
  2394. private static string Convert3(string Num)
  2395. {
  2396. string bb = ""; string cc = "";
  2397. string len = Num.Substring(0, 2);
  2398. if (len != "零零")
  2399. {
  2400. bb = Num.Replace("零零", "");
  2401. if (bb.Length == 1)
  2402. {
  2403. bb = bb.Substring(0, 1) + "佰";
  2404. }
  2405. else
  2406. {
  2407. if (bb.Substring(0, 1) != "零")
  2408. cc = bb.Substring(0, 1) + "佰";
  2409. else
  2410. cc = bb.Substring(0, 1);
  2411. bb = cc + Convert2(bb.Substring(1, 2));
  2412. }
  2413. }
  2414. else
  2415. {
  2416. bb = Num.Replace("零零", "零");
  2417. }
  2418. return bb;
  2419. }
  2420. #endregion
  2421. #endregion
  2422. #region 数字验证
  2423. /// <summary>
  2424. /// 验证数字字符串
  2425. /// </summary>
  2426. /// <param name="numStr"></param>
  2427. /// <returns></returns>
  2428. public static bool IsNumeric(this string numStr)
  2429. {
  2430. bool isNumeric = Regex.IsMatch(numStr, @"^\d+$");
  2431. if (isNumeric)
  2432. {
  2433. return true;
  2434. }
  2435. return false;
  2436. }
  2437. #endregion
  2438. #region 日期 格式转换
  2439. /// <summary>
  2440. /// 验证日期字符串
  2441. /// </summary>
  2442. /// <param name="str"></param>
  2443. /// <returns></returns>
  2444. public static string ConvertToDatetime(this string str)
  2445. {
  2446. if (!string.IsNullOrEmpty(str))
  2447. {
  2448. DateTime currentDate = Convert.ToDateTime(str);
  2449. return $"{currentDate.Year}年{currentDate.Month}月{currentDate.Day}日";
  2450. }
  2451. return "";
  2452. }
  2453. #endregion
  2454. #region 月份/季度
  2455. /// <summary>
  2456. /// 获取月份对应的起始天数
  2457. /// </summary>
  2458. /// <param name="year"></param>
  2459. /// <returns></returns>
  2460. public static List<MonthInfo> GetMonthInfos(int year)
  2461. {
  2462. List<MonthInfo> months = new List<MonthInfo>();
  2463. if (year > 1)
  2464. {
  2465. for (int i = 1; i < 13; i++)
  2466. {
  2467. months.Add(new MonthInfo()
  2468. {
  2469. Month = i,
  2470. Days = new DaysInfo() { BeginDays = 1, EndDays = DateTime.DaysInMonth(year, i) }
  2471. });
  2472. }
  2473. }
  2474. return months;
  2475. }
  2476. /// <summary>
  2477. /// 获取季度对应的起始天数
  2478. /// </summary>
  2479. /// <param name="year"></param>
  2480. /// <returns></returns>
  2481. public static List<MonthInfo> GetQuarter(int year)
  2482. {
  2483. List<MonthInfo> months = new List<MonthInfo>();
  2484. months.Add(new MonthInfo() { Month = 1, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //1.1 - 3.31
  2485. months.Add(new MonthInfo() { Month = 2, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //4.1 - 6.30
  2486. months.Add(new MonthInfo() { Month = 3, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //7.1 - 9.31
  2487. months.Add(new MonthInfo() { Month = 4, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //10.1 - 12.31
  2488. return months;
  2489. }
  2490. public class MonthInfo
  2491. {
  2492. public int Month { get; set; }
  2493. public DaysInfo Days { get; set; }
  2494. }
  2495. public class DaysInfo
  2496. {
  2497. public int BeginDays { get; set; }
  2498. public int EndDays { get; set; }
  2499. }
  2500. #endregion
  2501. #region op行程单,黑屏幕代码
  2502. public static string GetCountryStandingTime(int diId)
  2503. {
  2504. DataTable datas = GetTableByBlackCode(diId);
  2505. string countryStr = "[黑屏代码未录入].";
  2506. if (datas.Rows.Count > 0)
  2507. {
  2508. var airDatas = from row in datas.AsEnumerable()
  2509. select new
  2510. {
  2511. Three = row.Field<string>("Three"),
  2512. Day = row.Field<string>("Day"),
  2513. ArrivedDate = row.Field<string>("ArrivedDate"),
  2514. };
  2515. //三字码信息
  2516. List<Res_ThreeCode> listcode = _dirRep._sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.IsDel == 0).ToList();
  2517. //string countryStr = "";
  2518. int index = 0;
  2519. List<string> cityCodes = new List<string>();
  2520. //去掉开始和结束城市
  2521. foreach (var row in airDatas)
  2522. {
  2523. if (!string.IsNullOrEmpty(row.Three))
  2524. {
  2525. if (index == 0) cityCodes.Add(row.Three.Substring(3, 3)); //到达国家
  2526. else if (airDatas.Count() - 1 == index) cityCodes.Add(row.Three.Substring(0, 3)); //到达国家
  2527. else cityCodes.Add(row.Three.Substring(0, 3)); //到达国家
  2528. }
  2529. index++;
  2530. }
  2531. cityCodes = cityCodes.Distinct().ToList();
  2532. if (cityCodes.Count > 0) countryStr = "";
  2533. foreach (var item in cityCodes)
  2534. {
  2535. var airData = airDatas.Where(it => it.Three.Contains(item)).ToList();
  2536. string country = listcode.Find(it => it.Three.Equals(item))?.Country ?? "Unknown";
  2537. if (country.Equals("中国"))
  2538. {
  2539. country = listcode.Find(it => it.Three.Equals(item))?.City ?? "Unknown";
  2540. }
  2541. //int days = 0;
  2542. if (airData.Count == 2)
  2543. {
  2544. DateTime arr_dt = Convert.ToDateTime(airData[0].ArrivedDate); //抵达时间
  2545. DateTime dep_dt = Convert.ToDateTime(airData[1].Day); //离开时间
  2546. //days = (dep_dt - arr_dt).Days;
  2547. //countryStr += $@"{country}停留{days}日、";
  2548. countryStr += $@"{country}停留 日、";
  2549. }
  2550. }
  2551. if (countryStr.Length > 0) countryStr = countryStr.Substring(0, countryStr.Length - 1);
  2552. }
  2553. return countryStr;
  2554. }
  2555. /// <summary>
  2556. ///根据机票黑屏代码整理DataTable
  2557. /// </summary>
  2558. /// <param name="diid"></param>
  2559. /// <returns></returns>
  2560. public static DataTable GetTableByBlackCode1(int diid)
  2561. {
  2562. //黑屏代码信息
  2563. List<Air_TicketBlackCode> listcode = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.DiId == diid && x.IsDel == 0).ToList();
  2564. //测试数据为序号,航班号,起飞日期,三字码,起飞时刻,到达时刻,出发航站楼,到达航站楼,机型,飞行时间
  2565. //1.3U8391 TU17NOV CTUCAI 0220 0715 T1 T2 330 10H55M
  2566. DataTable dt = new DataTable();
  2567. dt.Columns.Add("Fliagtcode", typeof(string)); //航班号
  2568. dt.Columns.Add("Date", typeof(string));//起飞日期
  2569. dt.Columns.Add("Three", typeof(string));//三字码
  2570. dt.Columns.Add("StartTime", typeof(string));//起飞时刻
  2571. dt.Columns.Add("EndTime", typeof(string));//到达时刻
  2572. dt.Columns.Add("StartBuilding", typeof(string));//出发航站楼
  2573. dt.Columns.Add("EndBuilding", typeof(string));//到达航站楼
  2574. dt.Columns.Add("AirModel", typeof(string)); //机型
  2575. dt.Columns.Add("FlightTime", typeof(string));//飞行时间
  2576. dt.Columns.Add("Day", typeof(string));//整理的起飞日期;作为排序依据
  2577. dt.Columns.Add("ArrivedDate", typeof(string));//整理的到达日期
  2578. dt.Columns.Add("Error", typeof(string));//整理的到达日期
  2579. dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  2580. //判断是否录入黑屏代码
  2581. if (listcode.Count == 0 || listcode == null)
  2582. {
  2583. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "黑屏代码未录入!", null);
  2584. }
  2585. else
  2586. {
  2587. //读取单段黑屏代码
  2588. for (int i = 0; i < listcode.Count; i++)
  2589. {
  2590. //去除序号
  2591. string[] CodeList = Regex.Split(listcode[i].BlackCode, "\\d+\\.", RegexOptions.IgnoreCase);
  2592. //去除多余空格,方法一Linq扩展方法
  2593. CodeList = CodeList.Where(str => str != "").ToArray();
  2594. CodeList = CodeList.Where(str => str != " ").ToArray();
  2595. //年
  2596. int year = Convert.ToInt32(DateTime.Now.Year.ToString());
  2597. //读取单条黑屏代码
  2598. for (int j = 0; j < CodeList.Length; j++)
  2599. {
  2600. //去除多余空格,方法二使用Split()方法进行分割,分割有一个选项是RemoveEmptyEntries
  2601. CodeList[j] = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty).TrimStart().TrimEnd();
  2602. string[] Info = CodeList[j].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  2603. //string[] Info = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty)
  2604. // .TrimStart().TrimEnd().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  2605. //去除多余空格
  2606. Info = Info.Where(str => str != "").ToArray();
  2607. Info = Info.Where(str => str != " ").ToArray();
  2608. //判断黑屏代码是否正确拆分; 理应拆成9段
  2609. if (Info.Length < 9)
  2610. {
  2611. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "本团组第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误,请联系机票同事核对", null);
  2612. }
  2613. else
  2614. {
  2615. try
  2616. {
  2617. //月
  2618. int month = Convert.ToInt32(GetLonger(Info[1].Substring(4, 3)));
  2619. //日
  2620. int day = Convert.ToInt32(Info[1].Substring(2, 2));
  2621. #region 逐一比较月份,判断是否翻年;逐一比较三字码顶真,判断是否跑错机场
  2622. if (j > 0)
  2623. {
  2624. string[] Temp = CodeList[j - 1].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty)
  2625. .TrimStart().TrimEnd().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  2626. Temp = Temp.Where(str => str != "").ToArray();
  2627. Temp = Temp.Where(str => str != " ").ToArray();
  2628. int monthTemp = Convert.ToInt32(GetLonger(Temp[1].Substring(4, 3)));
  2629. // 如果相邻月份之差小于0,则证明次一条年份需+1
  2630. if (month - monthTemp < 0)
  2631. {
  2632. year = year + 1;
  2633. }
  2634. //如果相邻代码三字码不顶真,提醒
  2635. string FootThree = Temp[2].Substring(3, 3);
  2636. string HeadThree = Info[2].Substring(0, 3);
  2637. if (FootThree != HeadThree)
  2638. {
  2639. //DelegationInfoService s = new DelegationInfoService();
  2640. //UsersService us = new UsersService();
  2641. //GroupsTaskAssignmentService gts = new GroupsTaskAssignmentService();
  2642. //77 行程
  2643. List<Grp_GroupsTaskAssignment> list2 = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(x => x.CTId == 77 && x.DIId == diid && x.IsDel == 0).ToList();
  2644. foreach (var temp in list2)
  2645. {
  2646. //if (temp.UId != 21)
  2647. //SendAndReturn(us.GetUsersByID(temp.UId).Email,
  2648. // "黑屏代码提醒",
  2649. // s.GetDelegationInfoByID(diid).TeamName + "的机票黑屏代码中,相邻航段的三字码不连续,请查看!");
  2650. }
  2651. //85 机票预订
  2652. List<Grp_GroupsTaskAssignment> list6 = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(x => x.CTId == 85 && x.DIId == diid && x.IsDel == 0).ToList();
  2653. foreach (var temp in list6)
  2654. {
  2655. //if (temp.UId != 21)
  2656. //SendAndReturn(us.GetUsersByID(temp.UId).Email,
  2657. // "黑屏代码提醒",
  2658. // s.GetDelegationInfoByID(diid).TeamName + "的机票黑屏代码中,相邻航段的三字码不连续,请查看!");
  2659. }
  2660. }
  2661. }
  2662. #endregion
  2663. #region 判断到达日期是否需要加1
  2664. if (Info[4].Contains("+"))
  2665. {
  2666. //日期+1
  2667. day = day + 1;
  2668. //判断是否进入下一月
  2669. if (day > Convert.ToInt32(GetDaysByMonth(Info[1].Substring(4, 3), year)))
  2670. {
  2671. day = day - Convert.ToInt32(GetDaysByMonth(Info[1].Substring(4, 3), year));
  2672. month = month + 1;
  2673. //判断是否进入下一年
  2674. if (month > 12)
  2675. {
  2676. month = month - 12;
  2677. year = year + 1;
  2678. }
  2679. }
  2680. //月份整理格式
  2681. string monthTemp = month.ToString();
  2682. if (month < 10)
  2683. {
  2684. monthTemp = "0" + monthTemp;
  2685. }
  2686. //日期整理格式
  2687. string daytemp = day.ToString();
  2688. if (day < 10)
  2689. {
  2690. daytemp = "0" + daytemp;
  2691. }
  2692. string temp = Info[4].Split('+')[0];
  2693. //添加起飞数据
  2694. dt.Rows.Add(Info[0],
  2695. Info[1],
  2696. Info[2],
  2697. Info[3],
  2698. temp,
  2699. Info[5],
  2700. Info[6],
  2701. Info[7],
  2702. Info[8],
  2703. year + "-" + GetLonger(Info[1].Substring(4, 3)) + "-" + Info[1].Substring(2, 2),
  2704. year + "-" + monthTemp + "-" + daytemp,
  2705. "",
  2706. "0");
  2707. //加1天,添加到达数据
  2708. dt.Rows.Add(Info[0],
  2709. Info[1].Replace(Info[1].Substring(2, 2), daytemp),
  2710. Info[2],
  2711. Info[3],
  2712. temp,
  2713. Info[5],
  2714. Info[6],
  2715. Info[7],
  2716. Info[8],
  2717. year + "-" + monthTemp + "-" + daytemp,
  2718. year + "-" + monthTemp + "-" + daytemp,
  2719. "",
  2720. "1");
  2721. }
  2722. else
  2723. {
  2724. //月份整理格式
  2725. string monthTemp = month.ToString();
  2726. if (month < 10)
  2727. {
  2728. monthTemp = "0" + monthTemp;
  2729. }
  2730. //日期整理格式
  2731. string daytemp = day.ToString();
  2732. if (day < 10)
  2733. {
  2734. daytemp = "0" + daytemp;
  2735. }
  2736. dt.Rows.Add(Info[0],
  2737. Info[1],
  2738. Info[2],
  2739. Info[3],
  2740. Info[4],
  2741. Info[5],
  2742. Info[6],
  2743. Info[7],
  2744. Info[8],
  2745. year + "-" + monthTemp + "-" + daytemp,
  2746. year + "-" + monthTemp + "-" + daytemp,
  2747. "",
  2748. "0");
  2749. }
  2750. #endregion
  2751. }
  2752. catch (Exception ex)
  2753. {
  2754. string exstr = ex.Message.ToString();
  2755. }
  2756. }
  2757. }
  2758. //排序
  2759. dt.DefaultView.Sort = "Day asc";
  2760. dt = dt.DefaultView.ToTable();
  2761. }
  2762. }
  2763. return dt;
  2764. }
  2765. private readonly static string[] excludeArr = new string[] { "[中转]", "[转机]", "[国内]" };
  2766. /// <summary>
  2767. ///根据机票黑屏代码整理DataTable
  2768. /// </summary>
  2769. /// <param name="diid"></param>
  2770. /// <returns></returns>
  2771. public static DataTable GetTableByBlackCode(int diid)
  2772. {
  2773. //黑屏代码信息
  2774. List<Air_TicketBlackCode> listcode = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.DiId == diid && x.IsDel == 0).ToList();
  2775. //测试数据为序号,航班号,起飞日期,三字码,起飞时刻,到达时刻,出发航站楼,到达航站楼,机型,飞行时间
  2776. //1.3U8391 TU17NOV CTUCAI 0220 0715 T1 T2 330 10H55M
  2777. DataTable dt = new DataTable();
  2778. dt.Columns.Add("Fliagtcode", typeof(string)); //航班号
  2779. dt.Columns.Add("Date", typeof(string));//起飞日期
  2780. dt.Columns.Add("Three", typeof(string));//三字码
  2781. dt.Columns.Add("StartTime", typeof(string));//起飞时刻
  2782. dt.Columns.Add("EndTime", typeof(string));//到达时刻
  2783. dt.Columns.Add("StartBuilding", typeof(string));//出发航站楼
  2784. dt.Columns.Add("EndBuilding", typeof(string));//到达航站楼
  2785. dt.Columns.Add("AirModel", typeof(string)); //机型
  2786. dt.Columns.Add("FlightTime", typeof(string));//飞行时间
  2787. dt.Columns.Add("Day", typeof(string));//整理的起飞日期;作为排序依据
  2788. dt.Columns.Add("ArrivedDate", typeof(string));//整理的到达日期
  2789. dt.Columns.Add("Error", typeof(string));//整理的到达日期
  2790. dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  2791. //添加转机标识
  2792. dt.Columns.Add("isTransitShipment", typeof(bool));
  2793. //判断是否录入黑屏代码
  2794. if (listcode.Count == 0 || listcode == null)
  2795. {
  2796. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "黑屏代码未录入!", null, false);
  2797. }
  2798. else
  2799. {
  2800. //读取单段黑屏代码
  2801. for (int i = 0; i < listcode.Count; i++)
  2802. {
  2803. //去除序号
  2804. string[] CodeList = Regex.Split(listcode[i].BlackCode, "\\d+\\.", RegexOptions.IgnoreCase);
  2805. //去除多余空格,方法一Linq扩展方法
  2806. CodeList = CodeList.Where(str => !string.IsNullOrWhiteSpace(str)).ToArray();
  2807. //读取单条黑屏代码
  2808. for (int j = 0; j < CodeList.Length; j++)
  2809. {
  2810. //去除多余空格,方法二使用Split()方法进行分割,分割有一个选项是RemoveEmptyEntries
  2811. CodeList[j] = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty).TrimStart().TrimEnd();
  2812. string[] Info = CodeList[j].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  2813. //去除多余空格
  2814. Info = Info.Where(str => !string.IsNullOrWhiteSpace(str)).ToArray();
  2815. //判断黑屏代码是否正确拆分; 理应拆成9段
  2816. if (Info.TakeWhile((x) =>
  2817. {
  2818. return !excludeArr.Contains(x);
  2819. }).Count() != 9)
  2820. {
  2821. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "本团组第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误,请联系机票同事核对", null, false);
  2822. //MessageBoxEx.Show("第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误, 请联系机票同事核对");
  2823. return dt;
  2824. }
  2825. else
  2826. {
  2827. try
  2828. {
  2829. var monthEn = Info[1].Substring(4, 3);
  2830. //月
  2831. int month = Convert.ToInt32(GetLonger(monthEn));
  2832. //日
  2833. int day = Convert.ToInt32(Info[1].Substring(2, 2));
  2834. var time = new DateTime(DateTime.Now.Year, month, day); //
  2835. var isExist = Info.Contains("[中转]");
  2836. //dt.Columns.Add("Fliagtcode", typeof(string)); //航班号
  2837. //dt.Columns.Add("Date", typeof(string));//起飞日期
  2838. //dt.Columns.Add("Three", typeof(string));//三字码
  2839. //dt.Columns.Add("StartTime", typeof(string));//起飞时刻
  2840. //dt.Columns.Add("EndTime", typeof(string));//到达时刻
  2841. //dt.Columns.Add("StartBuilding", typeof(string));//出发航站楼
  2842. //dt.Columns.Add("EndBuilding", typeof(string));//到达航站楼
  2843. //dt.Columns.Add("AirModel", typeof(string)); //机型
  2844. //dt.Columns.Add("FlightTime", typeof(string));//飞行时间
  2845. //dt.Columns.Add("Day", typeof(string));//整理的起飞日期;作为排序依据
  2846. //dt.Columns.Add("ArrivedDate", typeof(string));//整理的到达日期
  2847. //dt.Columns.Add("Error", typeof(string));//整理的到达日期
  2848. //dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  2849. dt.Rows.Add(Info[0],
  2850. Info[1],
  2851. Info[2],
  2852. Info[3],
  2853. Info[4],
  2854. Info[5],
  2855. Info[6],
  2856. Info[7],
  2857. Info[8],
  2858. time.ToString("yyyy-MM-dd"),
  2859. time.ToString("yyyy-MM-dd"),
  2860. "",
  2861. "0",
  2862. isExist
  2863. );
  2864. }
  2865. catch (Exception ex)
  2866. {
  2867. string exstr = ex.Message.ToString();
  2868. }
  2869. }
  2870. }
  2871. //排序
  2872. dt.DefaultView.Sort = "Day asc";
  2873. dt = dt.DefaultView.ToTable();
  2874. }
  2875. }
  2876. return dt;
  2877. }
  2878. /// <summary>
  2879. ///根据黑屏代码整理DataTable
  2880. /// </summary>
  2881. /// <param name="blackCode"></param>
  2882. /// <returns></returns>
  2883. public static DataTable GetTableByBlackCodeBySingle(Air_TicketBlackCode blackCode)
  2884. {
  2885. DataTable dt = new DataTable();
  2886. dt.Columns.Add("Fliagtcode", typeof(string)); //航班号
  2887. dt.Columns.Add("Date", typeof(string));//起飞日期
  2888. dt.Columns.Add("Three", typeof(string));//三字码
  2889. dt.Columns.Add("StartTime", typeof(string));//起飞时刻
  2890. dt.Columns.Add("EndTime", typeof(string));//到达时刻
  2891. dt.Columns.Add("StartBuilding", typeof(string));//出发航站楼
  2892. dt.Columns.Add("EndBuilding", typeof(string));//到达航站楼
  2893. dt.Columns.Add("AirModel", typeof(string)); //机型
  2894. dt.Columns.Add("FlightTime", typeof(string));//飞行时间
  2895. dt.Columns.Add("Day", typeof(string));//整理的起飞日期;作为排序依据
  2896. dt.Columns.Add("ArrivedDate", typeof(string));//整理的到达日期
  2897. dt.Columns.Add("Error", typeof(string));//整理的到达日期
  2898. dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  2899. //添加转机标识
  2900. dt.Columns.Add("isTransitShipment", typeof(bool));
  2901. //添加国内段标识
  2902. dt.Columns.Add("isDomesticSection", typeof(bool));
  2903. //判断是否录入黑屏代码
  2904. if (blackCode == null)
  2905. {
  2906. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "黑屏代码未录入!", null, false, false);
  2907. }
  2908. else
  2909. {
  2910. var listcode = new List<Air_TicketBlackCode> { blackCode };
  2911. //读取单段黑屏代码
  2912. for (int i = 0; i < listcode.Count; i++)
  2913. {
  2914. //去除序号
  2915. string[] CodeList = Regex.Split(listcode[i].BlackCode, "\\d+\\.", RegexOptions.IgnoreCase);
  2916. //去除多余空格,方法一Linq扩展方法
  2917. CodeList = CodeList.Where(str => !string.IsNullOrWhiteSpace(str)).ToArray();
  2918. //读取单条黑屏代码
  2919. for (int j = 0; j < CodeList.Length; j++)
  2920. {
  2921. //去除多余空格,方法二使用Split()方法进行分割,分割有一个选项是RemoveEmptyEntries
  2922. CodeList[j] = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty).TrimStart().TrimEnd();
  2923. string[] Info = CodeList[j].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  2924. //去除多余空格
  2925. Info = Info.Where(str => !string.IsNullOrWhiteSpace(str)).ToArray();
  2926. //判断黑屏代码是否正确拆分; 理应拆成9段
  2927. if (Info.TakeWhile((x) =>
  2928. {
  2929. return !excludeArr.Contains(x);
  2930. }).Count() != 9)
  2931. {
  2932. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "本团组第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误,请联系机票同事核对", null, false, false);
  2933. //MessageBoxEx.Show("第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误, 请联系机票同事核对");
  2934. return dt;
  2935. }
  2936. else
  2937. {
  2938. try
  2939. {
  2940. var monthEn = Info[1].Substring(4, 3);
  2941. //月
  2942. int month = Convert.ToInt32(GetLonger(monthEn));
  2943. //日
  2944. int day = Convert.ToInt32(Info[1].Substring(2, 2));
  2945. var time = new DateTime(DateTime.Now.Year, month, day); //
  2946. var isExist = Info.Contains("[中转]");
  2947. if (!isExist)
  2948. {
  2949. isExist = Info.Contains("[转机]");
  2950. }
  2951. var isDomesticSection = Info.Contains("[国内]");
  2952. if (isDomesticSection)
  2953. {
  2954. continue;
  2955. }
  2956. dt.Rows.Add(Info[0],
  2957. Info[1],
  2958. Info[2],
  2959. Info[3],
  2960. Info[4],
  2961. Info[5],
  2962. Info[6],
  2963. Info[7],
  2964. Info[8],
  2965. time.ToString("yyyy-MM-dd"),
  2966. time.ToString("yyyy-MM-dd"),
  2967. "",
  2968. ExtractNumberAfterPlus(Info[4]),
  2969. isExist,
  2970. isDomesticSection
  2971. );
  2972. }
  2973. catch (Exception ex)
  2974. {
  2975. string exstr = ex.Message.ToString();
  2976. }
  2977. }
  2978. }
  2979. //排序
  2980. dt.DefaultView.Sort = "Day asc";
  2981. dt = dt.DefaultView.ToTable();
  2982. }
  2983. }
  2984. return dt;
  2985. }
  2986. private static int ExtractNumberAfterPlus(string input)
  2987. {
  2988. int value = 0;
  2989. if (string.IsNullOrEmpty(input))
  2990. {
  2991. return value;
  2992. }
  2993. string pattern = @"\+\d+"; // 匹配“+”及其后的数字
  2994. System.Text.RegularExpressions.Match match = Regex.Match(input, pattern);
  2995. if (match.Success)
  2996. {
  2997. int.TryParse(match.Value.Substring(1), out value); // 去掉“+”符号,只保留数字部分
  2998. }
  2999. return value;
  3000. }
  3001. /// <summary>
  3002. /// 根据星期,月份的缩写,转换成数字或者全称
  3003. /// 根据币种中文名称返回币种代码
  3004. /// 根据数字返回机型型号【2、3开头的就是空客,比如空客320,7开头的就是波音,比如波音777】
  3005. /// 20210903贾文滔
  3006. /// </summary>
  3007. /// <param name="temp"></param>
  3008. /// <returns></returns>
  3009. public static string GetLonger(string temp)
  3010. {
  3011. string str = "";
  3012. switch (temp.ToUpper())
  3013. {
  3014. case "美元":
  3015. str = "USD";
  3016. break;
  3017. case "日元":
  3018. str = "JPY";
  3019. break;
  3020. case "英镑":
  3021. str = "GBP";
  3022. break;
  3023. case "欧元":
  3024. str = "EUR";
  3025. break;
  3026. case "港币":
  3027. str = "HKD";
  3028. break;
  3029. case "MO":
  3030. str = "星期一";
  3031. break;
  3032. case "TU":
  3033. str = "星期二";
  3034. break;
  3035. case "WE":
  3036. str = "星期三";
  3037. break;
  3038. case "TH":
  3039. str = "星期四";
  3040. break;
  3041. case "FR":
  3042. str = "星期五";
  3043. break;
  3044. case "SA":
  3045. str = "星期六";
  3046. break;
  3047. case "SU":
  3048. str = "星期天";
  3049. break;
  3050. case "JAN":
  3051. str = "01";
  3052. break;
  3053. case "FEB":
  3054. str = "02";
  3055. break;
  3056. case "MAR":
  3057. str = "03";
  3058. break;
  3059. case "APR":
  3060. str = "04";
  3061. break;
  3062. case "MAY":
  3063. str = "05";
  3064. break;
  3065. case "JUN":
  3066. str = "06";
  3067. break;
  3068. case "JUL":
  3069. str = "07";
  3070. break;
  3071. case "AUG":
  3072. str = "08";
  3073. break;
  3074. case "SEP":
  3075. str = "09";
  3076. break;
  3077. case "OCT":
  3078. str = "10";
  3079. break;
  3080. case "NOV":
  3081. str = "11";
  3082. break;
  3083. case "DEC":
  3084. str = "12";
  3085. break;
  3086. case "MONDAY":
  3087. str = "星期一";
  3088. break;
  3089. case "TUESDAY":
  3090. str = "星期二";
  3091. break;
  3092. case "WEDNESDAY":
  3093. str = "星期三";
  3094. break;
  3095. case "THURSDAY":
  3096. str = "星期四";
  3097. break;
  3098. case "FRIDAY":
  3099. str = "星期五";
  3100. break;
  3101. case "SATURDAY":
  3102. str = "星期六";
  3103. break;
  3104. case "SUNDAY":
  3105. str = "星期日";
  3106. break;
  3107. case "01":
  3108. str = "JAN";
  3109. break;
  3110. case "02":
  3111. str = "FEB";
  3112. break;
  3113. case "03":
  3114. str = "MAR";
  3115. break;
  3116. case "04":
  3117. str = "APR";
  3118. break;
  3119. case "05":
  3120. str = "MAY";
  3121. break;
  3122. case "06":
  3123. str = "JUN";
  3124. break;
  3125. case "07":
  3126. str = "JUL";
  3127. break;
  3128. case "08":
  3129. str = "AUG";
  3130. break;
  3131. case "09":
  3132. str = "SEP";
  3133. break;
  3134. case "10":
  3135. str = "OCT";
  3136. break;
  3137. case "11":
  3138. str = "NOV";
  3139. break;
  3140. case "12":
  3141. str = "DEC";
  3142. break;
  3143. case "2":
  3144. str = "空客A";
  3145. break;
  3146. case "3":
  3147. str = "空客A";
  3148. break;
  3149. case "7":
  3150. str = "波音";
  3151. break;
  3152. }
  3153. return str;
  3154. }
  3155. /// <summary>
  3156. /// 根据月份返回天数
  3157. /// </summary>
  3158. /// <param name="Month"></param>
  3159. /// <param name="year"></param>
  3160. /// <returns></returns>
  3161. public static string GetDaysByMonth(string Month, int year)
  3162. {
  3163. string str = "";
  3164. //判断是否是闰年
  3165. if (DateTime.IsLeapYear(year) == false)
  3166. {
  3167. switch (Month.ToUpper())
  3168. {
  3169. case "JAN":
  3170. str = "31";
  3171. break;
  3172. case "FEB":
  3173. str = "28";
  3174. break;
  3175. case "MAR":
  3176. str = "31";
  3177. break;
  3178. case "APR":
  3179. str = "30";
  3180. break;
  3181. case "MAY":
  3182. str = "31";
  3183. break;
  3184. case "JUN":
  3185. str = "30";
  3186. break;
  3187. case "JUL":
  3188. str = "31";
  3189. break;
  3190. case "AUG":
  3191. str = "31";
  3192. break;
  3193. case "SEP":
  3194. str = "30";
  3195. break;
  3196. case "OCT":
  3197. str = "31";
  3198. break;
  3199. case "NOV":
  3200. str = "30";
  3201. break;
  3202. case "DEC":
  3203. str = "31";
  3204. break;
  3205. case "01":
  3206. str = "31";
  3207. break;
  3208. case "02":
  3209. str = "28";
  3210. break;
  3211. case "03":
  3212. str = "31";
  3213. break;
  3214. case "04":
  3215. str = "30";
  3216. break;
  3217. case "05":
  3218. str = "31";
  3219. break;
  3220. case "06":
  3221. str = "30";
  3222. break;
  3223. case "07":
  3224. str = "31";
  3225. break;
  3226. case "08":
  3227. str = "31";
  3228. break;
  3229. case "09":
  3230. str = "30";
  3231. break;
  3232. case "10":
  3233. str = "31";
  3234. break;
  3235. case "11":
  3236. str = "30";
  3237. break;
  3238. case "12":
  3239. str = "31";
  3240. break;
  3241. }
  3242. }
  3243. else
  3244. {
  3245. switch (Month.ToUpper())
  3246. {
  3247. case "JAN":
  3248. str = "31";
  3249. break;
  3250. case "FEB":
  3251. str = "29";
  3252. break;
  3253. case "MAR":
  3254. str = "31";
  3255. break;
  3256. case "APR":
  3257. str = "30";
  3258. break;
  3259. case "MAY":
  3260. str = "31";
  3261. break;
  3262. case "JUN":
  3263. str = "30";
  3264. break;
  3265. case "JUL":
  3266. str = "31";
  3267. break;
  3268. case "AUG":
  3269. str = "31";
  3270. break;
  3271. case "SEP":
  3272. str = "30";
  3273. break;
  3274. case "OCT":
  3275. str = "31";
  3276. break;
  3277. case "NOV":
  3278. str = "30";
  3279. break;
  3280. case "DEC":
  3281. str = "31";
  3282. break;
  3283. case "01":
  3284. str = "31";
  3285. break;
  3286. case "02":
  3287. str = "29";
  3288. break;
  3289. case "03":
  3290. str = "31";
  3291. break;
  3292. case "04":
  3293. str = "30";
  3294. break;
  3295. case "05":
  3296. str = "31";
  3297. break;
  3298. case "06":
  3299. str = "30";
  3300. break;
  3301. case "07":
  3302. str = "31";
  3303. break;
  3304. case "08":
  3305. str = "31";
  3306. break;
  3307. case "09":
  3308. str = "30";
  3309. break;
  3310. case "10":
  3311. str = "31";
  3312. break;
  3313. case "11":
  3314. str = "30";
  3315. break;
  3316. case "12":
  3317. str = "31";
  3318. break;
  3319. }
  3320. }
  3321. return str;
  3322. }
  3323. /// <summary>
  3324. /// op行程单 团组 城市路径
  3325. /// </summary>
  3326. /// <param name="diid">团组Id</param>
  3327. /// <param name="separator">分隔符</param>
  3328. /// <returns></returns>
  3329. public static string GetGroupCityLine(int diid, string separator)
  3330. {
  3331. string city = string.Empty;
  3332. var blackCode = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && x.DiId == diid).ToList();
  3333. if (blackCode.Count > 0)
  3334. {
  3335. var black = blackCode.First();
  3336. black.BlackCode = black.BlackCode == null ? "" : black.BlackCode;
  3337. var blackSp = Regex.Split(black.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  3338. if (blackSp.Length > 0)
  3339. {
  3340. try
  3341. {
  3342. var cityArrCode = new List<string>(20);
  3343. foreach (var item in blackSp)
  3344. {
  3345. var itemSp = item.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  3346. var IndexSelect = itemSp[2];
  3347. var cityArrCodeLength = cityArrCode.Count - 1;
  3348. var startCity = IndexSelect.Substring(0, 3);
  3349. if (cityArrCodeLength > 0)
  3350. {
  3351. var arrEndCity = cityArrCode[cityArrCodeLength];
  3352. if (arrEndCity != startCity)
  3353. {
  3354. cityArrCode.Add(startCity.ToUpper());
  3355. }
  3356. }
  3357. else
  3358. {
  3359. cityArrCode.Add(startCity.ToUpper());
  3360. }
  3361. var endCity = IndexSelect.Substring(3, 3);
  3362. cityArrCode.Add(endCity.ToUpper());
  3363. }
  3364. var cityThree = string.Empty;
  3365. cityArrCode.ForEach(x => cityThree += "'" + x + "',");
  3366. cityThree = cityThree.TrimEnd(',');
  3367. if (string.IsNullOrWhiteSpace(cityThree))
  3368. {
  3369. throw new Exception("error");
  3370. }
  3371. string sql = $"SELECT * FROM Res_ThreeCode rtc WHERE UPPER(rtc.Three) in ({cityThree}) ";
  3372. var cityArr = _dirRep._sqlSugar.SqlQueryable<Res_ThreeCode>(sql).ToList();
  3373. foreach (var item in cityArrCode)
  3374. {
  3375. var find = cityArr.Find(x => x.Three.ToUpper() == item.ToUpper());
  3376. if (find != null)
  3377. {
  3378. city += find.City + separator;
  3379. }
  3380. else
  3381. {
  3382. city += item + "[三字码未收录]" + separator;
  3383. }
  3384. }
  3385. city = city.TrimEnd(char.Parse(separator));
  3386. }
  3387. catch (Exception e)
  3388. {
  3389. city = "[黑屏代码格式不正确!]";
  3390. }
  3391. }
  3392. }
  3393. else city = "[未录入黑屏代码]";
  3394. return city;
  3395. }
  3396. /// <summary>
  3397. /// op行程单 团组 城市路径
  3398. /// </summary>
  3399. /// <param name="black">黑屏代码实例</param>
  3400. /// <param name="separator">分隔符</param>
  3401. /// <returns></returns>
  3402. public static string GetGroupCityLine(Air_TicketBlackCode black, string separator)
  3403. {
  3404. string city = string.Empty;
  3405. if (black != null)
  3406. {
  3407. black.BlackCode = black.BlackCode == null ? "" : black.BlackCode;
  3408. var blackSp = Regex.Split(black.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  3409. if (blackSp.Length > 0)
  3410. {
  3411. try
  3412. {
  3413. var cityArrCode = new List<string>(20);
  3414. foreach (var item in blackSp)
  3415. {
  3416. var itemSp = item.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  3417. var IndexSelect = itemSp[2];
  3418. var cityArrCodeLength = cityArrCode.Count - 1;
  3419. var startCity = IndexSelect.Substring(0, 3);
  3420. if (cityArrCodeLength > 0)
  3421. {
  3422. var arrEndCity = cityArrCode[cityArrCodeLength];
  3423. if (arrEndCity != startCity)
  3424. {
  3425. cityArrCode.Add(startCity.ToUpper());
  3426. }
  3427. }
  3428. else
  3429. {
  3430. cityArrCode.Add(startCity.ToUpper());
  3431. }
  3432. var endCity = IndexSelect.Substring(3, 3);
  3433. cityArrCode.Add(endCity.ToUpper());
  3434. }
  3435. var cityThree = string.Empty;
  3436. cityArrCode.ForEach(x => cityThree += "'" + x + "',");
  3437. cityThree = cityThree.TrimEnd(',');
  3438. if (string.IsNullOrWhiteSpace(cityThree))
  3439. {
  3440. throw new Exception("error");
  3441. }
  3442. string sql = $"SELECT * FROM Res_ThreeCode rtc WHERE UPPER(rtc.Three) in ({cityThree}) ";
  3443. var cityArr = _dirRep._sqlSugar.SqlQueryable<Res_ThreeCode>(sql).ToList();
  3444. foreach (var item in cityArrCode)
  3445. {
  3446. var find = cityArr.Find(x => x.Three.ToUpper() == item.ToUpper());
  3447. if (find != null)
  3448. {
  3449. city += find.City + separator;
  3450. }
  3451. else
  3452. {
  3453. city += item + "[三字码未收录]" + separator;
  3454. }
  3455. }
  3456. city = city.TrimEnd(char.Parse(separator));
  3457. }
  3458. catch (Exception e)
  3459. {
  3460. city = "[黑屏代码格式不正确!]";
  3461. }
  3462. }
  3463. }
  3464. else city = "[黑屏代码有误!]";
  3465. return city;
  3466. }
  3467. /// <summary>
  3468. /// op行程单 团组 城市路径
  3469. /// </summary>
  3470. /// <param name="diids">团组Id</param>
  3471. /// <param name="separator">分隔符</param>
  3472. /// <returns></returns>
  3473. public static Dictionary<int, string> GetGroupCityLineItem(List<int> diids, string separator)
  3474. {
  3475. Dictionary<int, string> dicCitys = new Dictionary<int, string>();
  3476. var cityCodes = _dirRep._sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList();
  3477. var blackCodes = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && diids.Contains(x.DiId)).ToList();
  3478. foreach (var diid in diids)
  3479. {
  3480. string city = string.Empty;
  3481. var blackCode = blackCodes.Where(it => it.DiId == diid).ToList();
  3482. if (blackCode.Count > 0)
  3483. {
  3484. var black = blackCode.First();
  3485. black.BlackCode = black.BlackCode == null ? "" : black.BlackCode;
  3486. var blackSp = Regex.Split(black.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  3487. if (blackSp.Length > 0)
  3488. {
  3489. try
  3490. {
  3491. var cityArrCode = new List<string>(20);
  3492. foreach (var item in blackSp)
  3493. {
  3494. var itemSp = item.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  3495. var IndexSelect = itemSp[2];
  3496. var cityArrCodeLength = cityArrCode.Count - 1;
  3497. var startCity = IndexSelect.Substring(0, 3);
  3498. if (cityArrCodeLength > 0)
  3499. {
  3500. var arrEndCity = cityArrCode[cityArrCodeLength];
  3501. if (arrEndCity != startCity)
  3502. {
  3503. cityArrCode.Add(startCity.ToUpper());
  3504. }
  3505. }
  3506. else
  3507. {
  3508. cityArrCode.Add(startCity.ToUpper());
  3509. }
  3510. var endCity = IndexSelect.Substring(3, 3);
  3511. cityArrCode.Add(endCity.ToUpper());
  3512. }
  3513. var cityThree = string.Empty;
  3514. cityArrCode.ForEach(x => cityThree += "'" + x + "',");
  3515. cityThree = cityThree.TrimEnd(',');
  3516. if (string.IsNullOrWhiteSpace(cityThree))
  3517. {
  3518. throw new Exception("error");
  3519. }
  3520. var cityArr = cityCodes.Where(it => cityThree.Contains(it.Three.ToUpper())).ToList();
  3521. foreach (var item in cityArrCode)
  3522. {
  3523. var find = cityArr.Find(x => x.Three.ToUpper() == item.ToUpper());
  3524. if (find != null)
  3525. {
  3526. city += find.City + separator;
  3527. }
  3528. else
  3529. {
  3530. city += item + "[三字码未收录]" + separator;
  3531. }
  3532. }
  3533. city = city.TrimEnd(char.Parse(separator));
  3534. }
  3535. catch (Exception e)
  3536. {
  3537. city = "[黑屏代码格式不正确!]";
  3538. }
  3539. }
  3540. }
  3541. else city = "[未录入黑屏代码]";
  3542. dicCitys.Add(diid, city);
  3543. }
  3544. return dicCitys;
  3545. }
  3546. /// <summary>
  3547. /// op行程单相关团组信息 含途径城市
  3548. /// </summary>
  3549. /// <returns></returns>
  3550. public static async Task<List<MateOpGroupPageListView>> MateOpGroupPageListRedis()
  3551. {
  3552. List<MateOpGroupPageListView> _views = new List<MateOpGroupPageListView>();
  3553. string viewStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("MateOpGroupPageList");//string 取
  3554. if (!string.IsNullOrEmpty(viewStr))
  3555. {
  3556. _views = JsonConvert.DeserializeObject<List<MateOpGroupPageListView>>(viewStr);
  3557. }
  3558. else
  3559. {
  3560. string sql = string.Format($@"Select Row_Number,Id,SalesQuoteNo,TourCode,TeamTypeId, TeamType,
  3561. TeamLevId,TeamLev,TeamName,ClientName,ClientUnit,
  3562. VisitDate,VisitDays,VisitPNumber,JietuanOperatorId,
  3563. JietuanOperator,IsSure,CreateTime,VisitCountry
  3564. From (
  3565. Select row_number() over(order by gdi.CreateTime Desc) as Row_Number,
  3566. gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,
  3567. ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,
  3568. VisitDate,VisitDays,VisitPNumber,JietuanOperator JietuanOperatorId,
  3569. su.CnName JietuanOperator,IsSure,gdi.CreateTime,gdi.VisitCountry
  3570. From Grp_DelegationInfo gdi
  3571. Left Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  3572. Left Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  3573. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  3574. Where gdi.IsDel = 0
  3575. ) temp");
  3576. _views = _dirRep._sqlSugar.SqlQueryable<MateOpGroupPageListView>(sql).ToList();
  3577. #region 处理所属部门
  3578. /*
  3579. * 1.sq 和 gyy 等显示 市场部
  3580. * 2.王鸽和主管及张总还有管理员号统一国交部
  3581. * 2-1. 4 管理员 ,21 张海麟
  3582. */
  3583. List<int> userIds = _views.Select(it => it.JietuanOperatorId).ToList();
  3584. List<int> userIds1 = new List<int>() { 4, 21 };
  3585. var UserDepDatas = _dirRep._sqlSugar.Queryable<Sys_Users>()
  3586. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  3587. .Where(u => u.IsDel == 0 && userIds.Contains(u.Id))
  3588. .Select((u, d) => new { UserId = u.Id, DepName = userIds1.Contains(u.Id) ? "国交部" : d.DepName })
  3589. .ToList();
  3590. #endregion
  3591. _views.ForEach(it =>
  3592. {
  3593. it.RouteCity = GetGroupCityLine(it.Id, @"/");
  3594. it.Department = UserDepDatas.Find(it1 => it.JietuanOperatorId == it1.UserId)?.DepName ?? "Unknown";
  3595. });
  3596. TimeSpan ts = DateTime.Now.AddHours(2).TimeOfDay;
  3597. await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>("MateOpGroupPageList", JsonConvert.SerializeObject(_views), ts);//string 存
  3598. }
  3599. return _views;
  3600. }
  3601. /// <summary>
  3602. /// 获取黑屏代码日期列表
  3603. /// </summary>
  3604. /// <param name="dt"></param>
  3605. /// <returns></returns>
  3606. public static List<string> GetTimeListByDataTable(DataTable dt)
  3607. {
  3608. DateTime datestart = Convert.ToDateTime(dt.Rows[0]["Day"].ToString());
  3609. DateTime dateend = Convert.ToDateTime(dt.Rows[dt.Rows.Count - 1]["ArrivedDate"].ToString());
  3610. List<string> timeList = new List<string>();
  3611. while (datestart <= dateend)
  3612. {
  3613. timeList.Add(datestart.ToString("yyyy-MM-dd"));
  3614. datestart = datestart.AddDays(1);
  3615. }
  3616. return timeList;
  3617. }
  3618. const decimal conversion = 1.61M;
  3619. /// <summary>
  3620. /// 简要行程
  3621. /// </summary>
  3622. /// <param name="diid"></param>
  3623. /// <returns></returns>
  3624. public static Result GetBriefStroke(int diid)
  3625. {
  3626. DataTable resultTable = GetTableByBlackCode(diid);
  3627. if (resultTable == null)
  3628. {
  3629. return new Result { Code = -1, Msg = "黑屏代码有误或黑屏代码未录入" };
  3630. }
  3631. if (resultTable.Rows.Count == 0 || string.IsNullOrWhiteSpace(resultTable.Rows[0][1].ToString()))
  3632. {
  3633. string msg = string.Empty;
  3634. if (resultTable.Rows.Count > 0)
  3635. {
  3636. msg = resultTable.Rows[0]["Error"].ToString();
  3637. }
  3638. return new Result { Code = -1, Msg = $"黑屏代码有误;{msg}" };
  3639. }
  3640. var timeArr = GetTimeListByDataTable(resultTable);
  3641. var threeCodes = _dirRep._sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList(); //三字码
  3642. var airCompanys = _dirRep._sqlSugar.Queryable<Res_AirCompany>().Where(it => it.IsDel == 0).ToList(); //航司公司
  3643. var obDatas = _dirRep._sqlSugar.Queryable<Res_OfficialActivities>().Where(it => it.IsDel == 0 && it.DiId == diid).ToList(); //公务信息
  3644. var NewListTravel = new List<Grp_TravelList>();
  3645. var index = 0;
  3646. var stopCity = string.Empty;
  3647. foreach (var item in timeArr)
  3648. {
  3649. string trip = string.Empty;
  3650. string weekDay = string.Empty;
  3651. DateTime time = DateTime.Now;
  3652. if (DateTime.TryParse(item, out time))
  3653. {
  3654. weekDay = weekdays[(int)time.DayOfWeek];
  3655. }
  3656. else
  3657. {
  3658. weekDay = "日期格式不正确!";
  3659. }
  3660. var empty = "【未收入该三字码!请机票同事录入】";
  3661. var tabSelect = resultTable.Select(string.Format("Day = '{0}'", item));
  3662. var isMoreTraffic = false;
  3663. if (tabSelect.Length > 0)
  3664. {
  3665. isMoreTraffic = true;
  3666. var takeOffTime = DateTime.Parse(item);
  3667. var fallToTime = DateTime.Parse(item);
  3668. Res_ThreeCode start_Object = null;
  3669. Res_ThreeCode end_Object = null;
  3670. //bool isTrade = false;
  3671. //air 处理
  3672. foreach (var tabRow in tabSelect)
  3673. {
  3674. takeOffTime = DateTime.Parse(item);
  3675. fallToTime = DateTime.Parse(item);
  3676. var takeOff = tabRow["StartTime"].ToString();
  3677. var fallTo = tabRow["EndTime"].ToString();
  3678. takeOffTime = takeOffTime.AddHours(int.Parse(takeOff.Substring(0, 2)));
  3679. takeOffTime = takeOffTime.AddMinutes(int.Parse(takeOff.Substring(2, 2)));
  3680. fallToTime = fallToTime.AddHours(int.Parse(fallTo.Substring(0, 2)));
  3681. fallToTime = fallToTime.AddMinutes(int.Parse(fallTo.Substring(2, 2)));
  3682. var threeCode = tabRow["Three"].ToString();
  3683. var start = threeCode.Substring(0, 3);
  3684. var end = threeCode.Substring(3, 3);
  3685. stopCity = end;
  3686. start_Object = threeCodes.Find(x => x.Three.ToUpper() == start.ToUpper());
  3687. end_Object = threeCodes.Find(x => x.Three.ToUpper() == end.ToUpper());
  3688. if (start_Object == null)
  3689. {
  3690. start_Object = new Res_ThreeCode()
  3691. {
  3692. AirPort = empty,
  3693. AirPort_En = empty,
  3694. City = empty,
  3695. Country = empty,
  3696. Four = empty,
  3697. Three = empty,
  3698. };
  3699. }
  3700. if (end_Object == null)
  3701. {
  3702. end_Object = new Res_ThreeCode()
  3703. {
  3704. AirPort = empty,
  3705. AirPort_En = empty,
  3706. City = empty,
  3707. Country = empty,
  3708. Four = empty,
  3709. Three = empty,
  3710. };
  3711. }
  3712. //航班号
  3713. string flightcode = tabRow["Fliagtcode"].ToString();
  3714. trip += $"{takeOffTime.ToString("HH:mm")}—{fallToTime.ToString("HH:mm")} {start_Object.City}—{end_Object.City} 航班号:{flightcode}\r\n";
  3715. }
  3716. //var airArrive = fallToTime; //航班落地时间
  3717. time = fallToTime.AddHours(1.5); //出机场一个半小时
  3718. string Time = string.Empty;
  3719. string Distance = string.Empty;
  3720. int GetGoogleResult = 0;
  3721. int GetDistResult = 0;
  3722. JObject Result = null;
  3723. try
  3724. {
  3725. Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace(" ", "").Trim();
  3726. Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString().Replace(" ", "").Trim();
  3727. if (Time.Contains("hours"))
  3728. {
  3729. Time = Time.Replace("hours", "小时");
  3730. }
  3731. if (Time.Contains("hour"))
  3732. {
  3733. Time = Time.Replace("hour", "小时");
  3734. }
  3735. Time = Time.Replace("mins", "分钟");
  3736. if (Distance.Contains("mi"))
  3737. {
  3738. var distSp = Regex.Split(Distance, "mi");
  3739. if (distSp.Length > 0)
  3740. {
  3741. Distance = (decimal.Parse(distSp[0]) * conversion).ToString("#0.00") + " 公里";
  3742. }
  3743. }
  3744. if (Distance.Contains("km"))
  3745. {
  3746. Distance = Distance.Replace("km", "公里");
  3747. }
  3748. if (Time.Contains("小时"))
  3749. {
  3750. var xs = Regex.Split(Time, "小时");
  3751. var xsValue = int.Parse(xs[0]);
  3752. var fz = Regex.Split(xs[1], "分钟");
  3753. var fzValue = int.Parse(fz[0]);
  3754. GetGoogleResult = xsValue * 60;
  3755. GetGoogleResult += fzValue;
  3756. }
  3757. else if (Time.Contains("分钟"))
  3758. {
  3759. GetGoogleResult = int.Parse(Regex.Split(Time, "分钟")[0]);
  3760. }
  3761. if (Distance.Contains("公里"))
  3762. {
  3763. GetDistResult = (int)decimal.Parse(Regex.Split(Distance, "公里")[0]);
  3764. }
  3765. if (GetGoogleResult > 0 && GetGoogleResult % 5 != 0)
  3766. {
  3767. while (GetGoogleResult % 5 != 0)
  3768. {
  3769. GetGoogleResult++;
  3770. }
  3771. }
  3772. if (GetDistResult % 5 != 0 && GetDistResult > 0)
  3773. {
  3774. while (GetDistResult % 5 != 0)
  3775. {
  3776. GetDistResult++;
  3777. }
  3778. }
  3779. int H = (GetGoogleResult / 60);
  3780. int m = (GetGoogleResult % 60);
  3781. string TimeStr = string.Empty;
  3782. if (H != 0)
  3783. {
  3784. if (H < 10)
  3785. {
  3786. TimeStr += "0" + H + "小时";
  3787. }
  3788. else
  3789. {
  3790. TimeStr += H + "小时";
  3791. }
  3792. }
  3793. if (m < 10)
  3794. {
  3795. TimeStr += "0" + m + "分钟";
  3796. }
  3797. else
  3798. {
  3799. TimeStr += m + "分钟";
  3800. }
  3801. Time = TimeStr;
  3802. Distance = GetDistResult.ToString() + "公里";
  3803. }
  3804. catch (Exception ex)
  3805. {
  3806. Time = "未知!";
  3807. Distance = "未知!";
  3808. }
  3809. //trip += $"{time.ToString("HH:mm")} 搭乘专车前往市区({end_Object.AirPort} - {end_Object.City}市区 路程{Distance},耗时{Time})";
  3810. //trip += $"{time.ToString("HH:mm")} 搭乘专车前往市区({end_Object.AirPort} - {end_Object.City}市区)";
  3811. time = time.AddMinutes(GetGoogleResult); //到达市区时间
  3812. string tripDate = Convert.ToDateTime(item).ToString("M月d日");
  3813. if (index == timeArr.Count - 1)
  3814. {
  3815. NewListTravel.Add(new Grp_TravelList
  3816. {
  3817. CreateTime = DateTime.Now,
  3818. CreateUserId = 0,
  3819. Diid = diid,
  3820. Date = tripDate,
  3821. Trip = trip,
  3822. WeekDay = weekDay,
  3823. Days = index + 1,
  3824. Traffic_First = "飞机",
  3825. Traffic_Second = "汽车",
  3826. Diffgroup = 1,
  3827. Issel = 1,
  3828. IsDel = 0,
  3829. });
  3830. continue;
  3831. }
  3832. if (time.Day != fallToTime.Day) //超出一天
  3833. {
  3834. NewListTravel.Add(new Grp_TravelList
  3835. {
  3836. CreateTime = DateTime.Now,
  3837. CreateUserId = 0,
  3838. Diid = diid,
  3839. Date = tripDate,
  3840. Trip = trip,
  3841. WeekDay = weekDay,
  3842. Days = index + 1,
  3843. Traffic_First = "飞机",
  3844. Traffic_Second = "汽车",
  3845. Diffgroup = 1,
  3846. Issel = 1,
  3847. IsDel = 0,
  3848. });
  3849. continue;
  3850. }
  3851. var obInfo = obDatas.Find(it => Convert.ToDateTime(it.Date).ToString("M月d日").Equals(tripDate));
  3852. string obtime = "";
  3853. string obcontent = "";
  3854. if (obInfo != null)
  3855. {
  3856. obtime = obInfo.Time;
  3857. obcontent = $"拜访{obInfo.Client ?? "公务出访单位未录入"}{obInfo.Job ?? "公务出访联系人职务未录入"}{obInfo.Contact ?? "公务出访联系人职务未录入"}";
  3858. }
  3859. bool obTime_bool = DateTime.TryParse(obtime, out DateTime obTimeDt);
  3860. if (time.Hour < 9) // && (airArrive < new DateTime(airArrive.Year,airArrive.Month,airArrive.Day,6, 30, 0))
  3861. {
  3862. if (obTime_bool)
  3863. {
  3864. if (obTimeDt.Hour < 9)
  3865. {
  3866. trip += $"{obTimeDt.ToString("HH:mm")}—10:30 {obcontent};\r\n";
  3867. }
  3868. }
  3869. else
  3870. {
  3871. trip += "09:00—10:30 公务活动;\r\n";
  3872. }
  3873. }
  3874. else if (time.Hour < 10)
  3875. {
  3876. if (obTime_bool)
  3877. {
  3878. if (obTimeDt.Hour < 10)
  3879. {
  3880. trip += $"{obTimeDt.ToString("HH:mm")}—12:00 {obcontent};\r\n";
  3881. }
  3882. }
  3883. else
  3884. {
  3885. trip += "10:30—12:00 公务活动;\r\n";
  3886. }
  3887. }
  3888. if (time.Hour < 13)
  3889. {
  3890. //trip += $"\r\n{time.ToString("HH:mm")} 午餐于当地餐厅;";
  3891. }
  3892. if (time < new DateTime(time.Year, time.Month, time.Day, 14, 30, 0))
  3893. {
  3894. if (obTime_bool)
  3895. {
  3896. if (obTimeDt < new DateTime(time.Year, time.Month, time.Day, 14, 30, 0))
  3897. {
  3898. trip += $"{obTimeDt.ToString("HH:mm")}—16:00 {obcontent};\r\n";
  3899. }
  3900. }
  3901. else
  3902. {
  3903. trip += "14:00—16:00 公务活动;\r\n";
  3904. }
  3905. }
  3906. else if (time.Hour < 16)
  3907. {
  3908. if (obTime_bool)
  3909. {
  3910. if (obTimeDt.Hour < 16)
  3911. {
  3912. trip += $"{obTimeDt.ToString("HH:mm")}—17:30 {obcontent};\r\n";
  3913. }
  3914. }
  3915. else
  3916. {
  3917. trip += "16:00—17:30 公务活动;\r\n";
  3918. }
  3919. }
  3920. //if (time.Hour < 18)
  3921. //{
  3922. // trip += $"\r\n18:00 晚餐于当地餐厅;";
  3923. //}
  3924. //time = time.AddHours(1);
  3925. //trip += $"\r\n{time.ToString("HH:mm")} 搭乘专车前往酒店,抵达后办理入住;";
  3926. }
  3927. else
  3928. {
  3929. var end_Object = threeCodes.Find(x => x.Three.ToUpper() == stopCity.ToUpper());
  3930. if (end_Object == null)
  3931. {
  3932. end_Object = new Res_ThreeCode()
  3933. {
  3934. AirPort = empty,
  3935. AirPort_En = empty,
  3936. City = empty,
  3937. Country = empty,
  3938. Four = empty,
  3939. Three = empty,
  3940. };
  3941. }
  3942. //trip += $"{end_Object.City}\r\n";
  3943. // trip += @"08:00 早餐于酒店;
  3944. //09:00—10:30 公务活动;
  3945. //12:00 午餐于当地餐厅;
  3946. //14:00—16:00 公务活动;
  3947. //18:00 晚餐于当地餐厅;
  3948. //19:00 入住酒店休息;";
  3949. trip += "09:00—10:30 公务活动;\r\n14:00—16:00 公务活动;\r\n";
  3950. }
  3951. string[] traffic = new string[] { "飞机", "汽车" };
  3952. if (!isMoreTraffic)
  3953. {
  3954. traffic = new string[] { "汽车", "" };
  3955. }
  3956. NewListTravel.Add(new Grp_TravelList
  3957. {
  3958. CreateTime = DateTime.Now,
  3959. CreateUserId = 0,
  3960. Diid = diid,
  3961. Date = Convert.ToDateTime(item).ToString("M月d日"),
  3962. Trip = trip,
  3963. WeekDay = weekDay,
  3964. Days = index + 1,
  3965. Traffic_First = traffic[0],
  3966. Traffic_Second = traffic[1],
  3967. Diffgroup = 1,
  3968. Issel = 1,
  3969. IsDel = 0,
  3970. });
  3971. index++;
  3972. }
  3973. return new Result() { Code = 0, Msg = "获取成功!", Data = NewListTravel };
  3974. }
  3975. /// <summary>
  3976. /// 根据日期获取星期
  3977. /// </summary>
  3978. /// <param name="dtStr"></param>
  3979. /// <returns></returns>
  3980. public static string GetWeek(this string dtStr)
  3981. {
  3982. string week = "";
  3983. bool isDt = DateTime.TryParse(dtStr, out DateTime dt);
  3984. if (isDt)
  3985. {
  3986. week = weekdays[(int)dt.DayOfWeek];
  3987. }
  3988. return week;
  3989. }
  3990. #endregion
  3991. #region 计算国家城市当时时间
  3992. /// <summary>
  3993. /// 中文城市名称映射
  3994. /// </summary>
  3995. private static readonly Dictionary<string, string> _timeZoneCityMappings = new Dictionary<string, string>
  3996. {
  3997. {"Africa/Abidjan","非洲/阿比让"} ,
  3998. {"Africa/Accra","非洲/阿克拉"} ,
  3999. {"Africa/Addis_Ababa","非洲/亚的斯亚贝巴"} ,
  4000. {"Africa/Algiers","非洲/阿尔及尔"} ,
  4001. {"Africa/Asmara","非洲/阿斯马拉"} ,
  4002. {"Africa/Asmera","非洲/阿斯梅拉"} ,
  4003. {"Africa/Bamako","非洲/巴马科"} ,
  4004. {"Africa/Bangui","非洲/班吉"} ,
  4005. {"Africa/Banjul","非洲/班珠尔"} ,
  4006. {"Africa/Bissau","非洲/比绍"} ,
  4007. {"Africa/Blantyre","非洲/布兰太尔"} ,
  4008. {"Africa/Brazzaville","非洲/布拉柴维尔"} ,
  4009. {"Africa/Bujumbura","非洲/布琼布拉"} ,
  4010. {"Africa/Cairo","非洲/开罗"} ,
  4011. {"Africa/Casablanca","非洲/卡萨布兰卡"} ,
  4012. {"Africa/Ceuta","非洲/休达"} ,
  4013. {"Africa/Conakry","非洲/科纳克里"} ,
  4014. {"Africa/Dakar","非洲/达喀尔"} ,
  4015. {"Africa/Dar_es_Salaam","非洲/达累斯萨拉姆"} ,
  4016. {"Africa/Djibouti","非洲/吉布提"} ,
  4017. {"Africa/Douala","非洲/杜阿拉"} ,
  4018. {"Africa/El_Aaiun","非洲/阿尤恩"} ,
  4019. {"Africa/Freetown","非洲/弗里敦"} ,
  4020. {"Africa/Gaborone","非洲/哈博罗内"} ,
  4021. {"Africa/Harare","非洲/哈拉雷"} ,
  4022. {"Africa/Johannesburg","非洲/约翰内斯堡"} ,
  4023. {"Africa/Juba","非洲/朱巴"} ,
  4024. {"Africa/Kampala","非洲/坎帕拉"} ,
  4025. {"Africa/Khartoum","非洲/喀土穆"} ,
  4026. {"Africa/Kigali","非洲/基加利"} ,
  4027. {"Africa/Kinshasa","非洲/金沙萨"} ,
  4028. {"Africa/Lagos","非洲/拉各斯"} ,
  4029. {"Africa/Libreville","非洲/利伯维尔"} ,
  4030. {"Africa/Lome","非洲/洛美"} ,
  4031. {"Africa/Luanda","非洲/罗安达"} ,
  4032. {"Africa/Lubumbashi","非洲/卢本巴希"} ,
  4033. {"Africa/Lusaka","非洲/卢萨卡"} ,
  4034. {"Africa/Malabo","非洲/马拉博"} ,
  4035. {"Africa/Maputo","非洲/马普托"} ,
  4036. {"Africa/Maseru","非洲/马塞卢"} ,
  4037. {"Africa/Mbabane","非洲/姆巴巴内"} ,
  4038. {"Africa/Mogadishu","非洲/摩加迪沙"} ,
  4039. {"Africa/Monrovia","非洲/蒙罗维亚"} ,
  4040. {"Africa/Nairobi","非洲/内罗毕"} ,
  4041. {"Africa/Ndjamena","非洲/恩贾梅纳"} ,
  4042. {"Africa/Niamey","非洲/尼亚美"} ,
  4043. {"Africa/Nouakchott","非洲/努瓦克肖特"} ,
  4044. {"Africa/Ouagadougou","非洲/瓦加杜古"} ,
  4045. {"Africa/Porto-Novo","非洲/波多诺伏"} ,
  4046. {"Africa/Sao_Tome","非洲/圣多美"} ,
  4047. {"Africa/Timbuktu","非洲/廷巴克图"} ,
  4048. {"Africa/Tripoli","非洲/的黎波里"} ,
  4049. {"Africa/Tunis","非洲/突尼斯"} ,
  4050. {"Africa/Windhoek","非洲/温得和克"} ,
  4051. {"America/Adak","美洲/埃达克"} ,
  4052. {"America/Anchorage","美洲/安克雷奇"} ,
  4053. {"America/Anguilla","美洲/安圭拉"} ,
  4054. {"America/Antigua","美洲/安提瓜岛"} ,
  4055. {"America/Araguaina","美洲/阿拉瓜纳"} ,
  4056. {"America/Argentina/Buenos_Aires","美洲/阿根廷/布宜诺斯艾利斯"} ,
  4057. {"America/Argentina/Catamarca","美洲/阿根廷/卡塔马卡"} ,
  4058. {"America/Argentina/ComodRivadavia","美洲/阿根廷/科莫德里瓦达维亚"} ,
  4059. {"America/Argentina/Cordoba","美洲/阿根廷/科尔多瓦"} ,
  4060. {"America/Argentina/Jujuy","美洲/阿根廷/胡胡伊省"} ,
  4061. {"America/Argentina/La_Rioja","美洲/阿根廷/拉里奥哈"} ,
  4062. {"America/Argentina/Mendoza","美洲/阿根廷/门多萨"} ,
  4063. {"America/Argentina/Rio_Gallegos","美洲/阿根廷/里奥加耶戈斯"} ,
  4064. {"America/Argentina/Salta","美洲/阿根廷/萨尔塔"} ,
  4065. {"America/Argentina/San_Juan","美洲/阿根廷/San_Juan"} ,
  4066. {"America/Argentina/San_Luis","美洲/阿根廷/圣路易斯"} ,
  4067. {"America/Argentina/Tucuman","美洲/阿根廷/图库曼"} ,
  4068. {"America/Argentina/Ushuaia","美洲/阿根廷/乌斯怀亚"} ,
  4069. {"America/Aruba","美洲/阿鲁巴岛"} ,
  4070. {"America/Asuncion","美洲/亚松森"} ,
  4071. {"America/Atikokan","美洲/阿蒂科坎"} ,
  4072. {"America/Atka","美洲/阿特卡"} ,
  4073. {"America/Bahia","美洲/巴伊亚"} ,
  4074. {"America/Bahia_Banderas","美洲/巴伊亚_班德拉斯"} ,
  4075. {"America/Barbados","美洲/巴巴多斯"} ,
  4076. {"America/Belem","美洲/贝伦"} ,
  4077. {"America/Belize","美洲/伯利兹"} ,
  4078. {"America/Blanc-Sablon","America/Blanc-Sablon"} ,
  4079. {"America/Boa_Vista","美洲/博阿维斯塔"} ,
  4080. {"America/Bogota","美洲/波哥大"} ,
  4081. {"America/Boise","美洲/博伊西"} ,
  4082. {"America/Buenos_Aires","美洲/布宜诺斯艾利斯"} ,
  4083. {"America/Cambridge_Bay","美洲/剑桥湾"} ,
  4084. {"America/Campo_Grande","美洲/大坎普"} ,
  4085. {"America/Cancun","美洲/坎昆"} ,
  4086. {"America/Caracas","美洲/加拉加斯"} ,
  4087. {"America/Catamarca","美洲/卡塔马卡"} ,
  4088. {"America/Cayenne","美洲/卡宴"} ,
  4089. {"America/Cayman","美洲/开曼"} ,
  4090. {"America/Chicago","美洲/芝加哥"} ,
  4091. {"America/Chihuahua","美洲/奇瓦瓦州"} ,
  4092. {"America/Ciudad_Juarez","美洲/华雷斯城"} ,
  4093. {"America/Coral_Harbour","美洲/珊瑚港"} ,
  4094. {"America/Cordoba","美洲/科尔多瓦"} ,
  4095. {"America/Costa_Rica","美洲/哥斯达黎加"} ,
  4096. {"America/Creston","美洲/克雷斯顿"} ,
  4097. {"America/Cuiaba","美洲/库艾巴"} ,
  4098. {"America/Curacao","美洲/库拉索岛"} ,
  4099. {"America/Danmarkshavn","美洲/丹麦港"} ,
  4100. {"America/Dawson","美洲/道森"} ,
  4101. {"America/Dawson_Creek","美洲/道森克里克"} ,
  4102. {"America/Denver","美洲/丹佛"} ,
  4103. {"America/Detroit","美洲/底特律"} ,
  4104. {"America/Dominica","美洲/多米尼克"} ,
  4105. {"America/Edmonton","美洲/埃德蒙顿"} ,
  4106. {"America/Eirunepe","美洲/埃鲁内佩"} ,
  4107. {"America/El_Salvador","美洲/萨尔瓦多"} ,
  4108. {"America/Ensenada","美洲/恩塞纳达"} ,
  4109. {"America/Fort_Nelson","美洲/纳尔逊堡"} ,
  4110. {"America/Fort_Wayne","美洲/韦恩堡"} ,
  4111. {"America/Fortaleza","美洲/福塔莱萨"} ,
  4112. {"America/Glace_Bay","America/Glace_Bay"} ,
  4113. {"America/Godthab","美洲/戈德哈布"} ,
  4114. {"America/Goose_Bay","America/Goose_Bay"} ,
  4115. {"America/Grand_Turk","美洲/大特克岛"} ,
  4116. {"America/Grenada","美洲/格林纳达"} ,
  4117. {"America/Guadeloupe","美洲/瓜德罗普岛"} ,
  4118. {"America/Guatemala","美洲/危地马拉"} ,
  4119. {"America/Guayaquil","美洲/瓜亚基尔"} ,
  4120. {"America/Guyana","美洲/圭亚那"} ,
  4121. {"America/Halifax","美洲/哈利法克斯"} ,
  4122. {"America/Havana","美洲/哈瓦那"} ,
  4123. {"America/Hermosillo","美洲/埃莫西约"} ,
  4124. {"America/Indiana/Indianapolis","美洲/印第安纳州/印第安纳波利斯"} ,
  4125. {"America/Indiana/Knox","美洲/印第安纳州/诺克斯"} ,
  4126. {"America/Indiana/Marengo","美洲/印第安纳州/马伦戈"} ,
  4127. {"America/Indiana/Petersburg","美洲/印第安纳州/彼得斯堡"} ,
  4128. {"America/Indiana/Tell_City","美洲/印第安纳州/Tell_City"} ,
  4129. {"America/Indiana/Vevay","美洲/印第安纳州/沃韦"} ,
  4130. {"America/Indiana/Vincennes","美洲/印第安纳州/文森斯"} ,
  4131. {"America/Indiana/Winamac","美洲/印第安纳州/威纳马克"} ,
  4132. {"America/Indianapolis","美洲/印第安纳波利斯"} ,
  4133. {"America/Inuvik","美洲/伊努维克人"} ,
  4134. {"America/Iqaluit","美洲/伊魁特"} ,
  4135. {"America/Jamaica","美洲/牙买加"} ,
  4136. {"America/Jujuy","美洲/胡胡伊省"} ,
  4137. {"America/Juneau","美洲/朱诺"} ,
  4138. {"America/Kentucky/Louisville","美洲/肯塔基州/路易斯维尔"} ,
  4139. {"America/Kentucky/Monticello","美洲/肯塔基州/蒙蒂塞洛"} ,
  4140. {"America/Knox_IN","美洲/Knox_IN"} ,
  4141. {"America/Kralendijk","美洲/克拉伦代克"} ,
  4142. {"America/La_Paz","美洲/拉巴斯"} ,
  4143. {"America/Lima","美洲/利马"} ,
  4144. {"America/Los_Angeles","美洲/洛杉矶"} ,
  4145. {"America/Louisville","美洲/路易斯维尔"} ,
  4146. {"America/Lower_Princes","美洲/下王子郡"} ,
  4147. {"America/Maceio","美洲/马塞约"} ,
  4148. {"America/Managua","美洲/马那瓜"} ,
  4149. {"America/Manaus","美洲/马瑙斯"} ,
  4150. {"America/Marigot","美洲/马里戈特"} ,
  4151. {"America/Martinique","美洲/马提尼克岛"} ,
  4152. {"America/Matamoros","美洲/马塔莫罗斯"} ,
  4153. {"America/Mazatlan","美洲/马萨特兰"} ,
  4154. {"America/Mendoza","美洲/门多萨"} ,
  4155. {"America/Menominee","美国/梅诺米尼"} ,
  4156. {"America/Merida","美洲/梅里达"} ,
  4157. {"America/Metlakatla","美洲/梅特拉卡特拉"} ,
  4158. {"America/Mexico_City","美洲/墨西哥_城市"} ,
  4159. {"America/Miquelon","美洲/密克隆群岛"} ,
  4160. {"America/Moncton","美洲/蒙克顿"} ,
  4161. {"America/Monterrey","美洲/蒙特雷"} ,
  4162. {"America/Montevideo","美洲/蒙得维的亚"} ,
  4163. {"America/Montreal","美洲/蒙特利尔"} ,
  4164. {"America/Montserrat","美洲/蒙特塞拉特"} ,
  4165. {"America/Nassau","美洲/拿骚"} ,
  4166. {"America/New_York","美洲/纽约"} ,
  4167. {"America/Nipigon","美洲/尼皮贡"} ,
  4168. {"America/Nome","美国/名称"} ,
  4169. {"America/Noronha","美国/某地"} ,
  4170. {"America/North_Dakota/Beulah","美洲/北达科他州/比尤拉"} ,
  4171. {"America/North_Dakota/Center","美洲/北达科他州/中部"} ,
  4172. {"America/North_Dakota/New_Salem","美洲/北达科他州/新塞勒姆"} ,
  4173. {"America/Nuuk","美洲/努克"} ,
  4174. {"America/Ojinaga","美洲/奥吉纳加"} ,
  4175. {"America/Panama","美洲/巴拿马"} ,
  4176. {"America/Pangnirtung","美洲/庞纳通"} ,
  4177. {"America/Paramaribo","美洲/帕拉马里博"} ,
  4178. {"America/Phoenix","美洲/菲尼克斯"} ,
  4179. {"America/Port-au-Prince","美洲/太子港"} ,
  4180. {"America/Port_of_Spain","美洲/西班牙港"} ,
  4181. {"America/Porto_Acre","美洲/阿卡港"} ,
  4182. {"America/Porto_Velho","美洲/旧波尔图"} ,
  4183. {"America/Puerto_Rico","美洲/波多黎各"} ,
  4184. {"America/Punta_Arenas","美洲/蓬塔阿雷纳斯"} ,
  4185. {"America/Rainy_River","美洲/雷尼河"} ,
  4186. {"America/Rankin_Inlet","兰金因莱特"} ,
  4187. {"America/Recife","美洲/累西腓"} ,
  4188. {"America/Regina","美洲/里贾纳"} ,
  4189. {"America/Resolute","美国/坚决"} ,
  4190. {"America/Rio_Branco","美洲/里奥布兰科"} ,
  4191. {"America/Rosario","美洲/罗萨里奥"} ,
  4192. {"America/Santa_Isabel","美洲/圣伊莎贝尔"} ,
  4193. {"America/Santarem","美洲/圣塔伦"} ,
  4194. {"America/Santiago","美洲/圣地亚哥"} ,
  4195. {"America/Santo_Domingo","美洲/圣多明各"} ,
  4196. {"America/Sao_Paulo","美洲/圣保罗"} ,
  4197. {"America/Scoresbysund","美洲/斯科斯比松"} ,
  4198. {"America/Shiprock","美洲/希普洛克"} ,
  4199. {"America/Sitka","美洲/锡特卡"} ,
  4200. {"America/St_Barthelemy","美洲/圣巴泰勒米"} ,
  4201. {"America/St_Johns","美洲/圣约翰斯"} ,
  4202. {"America/St_Kitts","美洲/圣基茨"} ,
  4203. {"America/St_Lucia","美洲/圣卢西亚"} ,
  4204. {"America/St_Thomas","美洲/圣托马斯"} ,
  4205. {"America/St_Vincent","美洲/圣文森特"} ,
  4206. {"America/Swift_Current","America/Swift_Current"} ,
  4207. {"America/Tegucigalpa","美洲/特古西加尔巴"} ,
  4208. {"America/Thule","美洲/图勒"} ,
  4209. {"America/Thunder_Bay","美洲/雷湾"} ,
  4210. {"America/Tijuana","美洲/蒂华纳"} ,
  4211. {"America/Toronto","美洲/多伦多"} ,
  4212. {"America/Tortola","美洲/托尔托拉岛"} ,
  4213. {"America/Vancouver","美洲/温哥华"} ,
  4214. {"America/Virgin","美国/维珍"} ,
  4215. {"America/Whitehorse","美洲/怀特霍斯"} ,
  4216. {"America/Winnipeg","美洲/温尼伯"} ,
  4217. {"America/Yakutat","美洲/雅库塔特"} ,
  4218. {"America/Yellowknife","美洲/黄刀镇"} ,
  4219. {"Antarctica/Casey","南极洲/凯西"} ,
  4220. {"Antarctica/Davis","南极洲/戴维斯"} ,
  4221. {"Antarctica/DumontDUrville","南极洲/杜蒙杜维尔"} ,
  4222. {"Antarctica/Macquarie","南极洲/麦格理"} ,
  4223. {"Antarctica/Mawson","南极洲/莫森"} ,
  4224. {"Antarctica/McMurdo","南极洲/麦克默多"} ,
  4225. {"Antarctica/Palmer","南极洲/帕尔默"} ,
  4226. {"Antarctica/Rothera","南极洲/罗塞拉岛"} ,
  4227. {"Antarctica/South_Pole","南极洲/南极点"} ,
  4228. {"Antarctica/Syowa","南极洲/昭和"} ,
  4229. {"Antarctica/Troll","南极洲/巨魔"} ,
  4230. {"Antarctica/Vostok","南极洲/东方"} ,
  4231. {"Arctic/Longyearbyen","北极/朗伊尔城"} ,
  4232. {"Asia/Aden","亚洲/亚丁"} ,
  4233. {"Asia/Almaty","亚洲/阿拉木图"} ,
  4234. {"Asia/Amman","亚洲/安曼"} ,
  4235. {"Asia/Anadyr","亚洲/阿纳德尔"} ,
  4236. {"Asia/Aqtau","亚洲/阿克套"} ,
  4237. {"Asia/Aqtobe","亚洲/阿克托比"} ,
  4238. {"Asia/Ashgabat","亚洲/阿什哈巴德"} ,
  4239. {"Asia/Ashkhabad","亚洲/阿什哈巴德"} ,
  4240. {"Asia/Atyrau","亚洲/阿特劳"} ,
  4241. {"Asia/Baghdad","亚洲/巴格达"} ,
  4242. {"Asia/Bahrain","亚洲/巴林"} ,
  4243. {"Asia/Baku","亚洲/巴库"} ,
  4244. {"Asia/Bangkok","亚洲/曼谷"} ,
  4245. {"Asia/Barnaul","亚洲/巴尔瑙尔"} ,
  4246. {"Asia/Beirut","亚洲/贝鲁特"} ,
  4247. {"Asia/Bishkek","亚洲/比什凯克"} ,
  4248. {"Asia/Brunei","亚洲/文莱"} ,
  4249. {"Asia/Calcutta","亚洲/加尔各答"} ,
  4250. {"Asia/Chita","亚洲/赤塔"} ,
  4251. {"Asia/Choibalsan","亚洲/乔巴山"} ,
  4252. {"Asia/Chongqing","亚洲/重庆"} ,
  4253. {"Asia/Chungking","亚洲/重庆"} ,
  4254. {"Asia/Colombo","亚洲/科伦坡"} ,
  4255. {"Asia/Dacca","亚洲/达卡"} ,
  4256. {"Asia/Damascus","亚洲/大马士革"} ,
  4257. {"Asia/Dhaka","亚洲/达卡"} ,
  4258. {"Asia/Dili","亚洲/帝力"} ,
  4259. {"Asia/Dubai","亚洲/迪拜"} ,
  4260. {"Asia/Dushanbe","亚洲/杜尚别"} ,
  4261. {"Asia/Famagusta","亚洲/法马古斯塔"} ,
  4262. {"Asia/Gaza","亚洲/加沙"} ,
  4263. {"Asia/Harbin","亚洲/哈尔滨"} ,
  4264. {"Asia/Hebron","亚洲/希伯伦"} ,
  4265. {"Asia/Ho_Chi_Minh","亚洲/胡志明市"} ,
  4266. {"Asia/Hong_Kong","亚洲/香港"} ,
  4267. {"Asia/Hovd","亚洲/霍布德"} ,
  4268. {"Asia/Irkutsk","亚洲/伊尔库茨克"} ,
  4269. {"Asia/Istanbul","亚洲/伊斯坦布尔"} ,
  4270. {"Asia/Jakarta","亚洲/雅加达"} ,
  4271. {"Asia/Jayapura","亚洲/查亚普拉"} ,
  4272. {"Asia/Jerusalem","亚洲/耶路撒冷"} ,
  4273. {"Asia/Kabul","亚洲/喀布尔"} ,
  4274. {"Asia/Kamchatka","亚洲/堪察加半岛"} ,
  4275. {"Asia/Karachi","亚洲/卡拉奇"} ,
  4276. {"Asia/Kashgar","亚洲/喀什"} ,
  4277. {"Asia/Kathmandu","亚洲/加德满都"} ,
  4278. {"Asia/Katmandu","亚洲/加德满都"} ,
  4279. {"Asia/Khandyga","亚洲/坎迪加"} ,
  4280. {"Asia/Kolkata","亚洲/加尔各答"} ,
  4281. {"Asia/Krasnoyarsk","亚洲/克拉斯诺亚尔斯克"} ,
  4282. {"Asia/Kuala_Lumpur","亚洲/吉隆坡_吉隆坡"} ,
  4283. {"Asia/Kuching","亚洲/古晋"} ,
  4284. {"Asia/Kuwait","亚洲/科威特"} ,
  4285. {"Asia/Macao","亚洲/澳门"} ,
  4286. {"Asia/Macau","亚洲/澳门"} ,
  4287. {"Asia/Magadan","亚洲/马加丹"} ,
  4288. {"Asia/Makassar","亚洲/望加锡"} ,
  4289. {"Asia/Manila","亚洲/马尼拉"} ,
  4290. {"Asia/Muscat","亚洲/马斯喀特"} ,
  4291. {"Asia/Nicosia","亚洲/尼科西亚"} ,
  4292. {"Asia/Novokuznetsk","亚洲/新库兹涅茨克"} ,
  4293. {"Asia/Novosibirsk","亚洲/新西伯利亚"} ,
  4294. {"Asia/Omsk","亚洲/鄂木斯克"} ,
  4295. {"Asia/Oral","亚洲/口头"} ,
  4296. {"Asia/Phnom_Penh","亚洲/金边"} ,
  4297. {"Asia/Pontianak","亚洲/笨珍"} ,
  4298. {"Asia/Pyongyang","亚洲/平壤"} ,
  4299. {"Asia/Qatar","亚洲/卡塔尔"} ,
  4300. {"Asia/Qostanay","亚洲/库斯塔奈"} ,
  4301. {"Asia/Qyzylorda","亚洲/克孜勒奥尔达"} ,
  4302. {"Asia/Rangoon","亚洲/仰光"} ,
  4303. {"Asia/Riyadh","亚洲/利雅得"} ,
  4304. {"Asia/Saigon","亚洲/西贡"} ,
  4305. {"Asia/Sakhalin","亚洲/萨哈林岛"} ,
  4306. {"Asia/Samarkand","亚洲/撒马尔罕"} ,
  4307. {"Asia/Seoul","亚洲/首尔"} ,
  4308. {"Asia/Shanghai","亚洲/上海"} ,
  4309. {"Asia/Singapore","亚洲/新加坡"} ,
  4310. {"Asia/Srednekolymsk","亚洲/中科雷姆斯克"} ,
  4311. {"Asia/Taipei","亚洲/台北"} ,
  4312. {"Asia/Tashkent","亚洲/塔什干"} ,
  4313. {"Asia/Tbilisi","亚洲/第比利斯"} ,
  4314. {"Asia/Tehran","亚洲/德黑兰"} ,
  4315. {"Asia/Tel_Aviv","亚洲/特拉维夫"} ,
  4316. {"Asia/Thimbu","亚洲/廷布"} ,
  4317. {"Asia/Thimphu","亚洲/廷布"} ,
  4318. {"Asia/Tokyo","亚洲/东京"} ,
  4319. {"Asia/Tomsk","亚洲/托木斯克"} ,
  4320. {"Asia/Ujung_Pandang","亚洲/乌戎_潘当"} ,
  4321. {"Asia/Ulaanbaatar","亚洲/乌兰巴托"} ,
  4322. {"Asia/Ulan_Bator","亚洲/乌兰巴托"} ,
  4323. {"Asia/Urumqi","亚洲/乌鲁木齐"} ,
  4324. {"Asia/Ust-Nera","亚洲/乌斯季-内拉"} ,
  4325. {"Asia/Vientiane","亚洲/万象"} ,
  4326. {"Asia/Vladivostok","亚洲/符拉迪沃斯托克"} ,
  4327. {"Asia/Yakutsk","亚洲/雅库茨克"} ,
  4328. {"Asia/Yangon","亚洲/仰光"} ,
  4329. {"Asia/Yekaterinburg","亚洲/叶卡捷琳堡"} ,
  4330. {"Asia/Yerevan","亚洲/埃里温"} ,
  4331. {"Atlantic/Azores","大西洋/亚速尔群岛"} ,
  4332. {"Atlantic/Bermuda","大西洋/百慕大"} ,
  4333. {"Atlantic/Canary","大西洋/加那利"} ,
  4334. {"Atlantic/Cape_Verde","大西洋/佛得角"} ,
  4335. {"Atlantic/Faeroe","大西洋/法罗"} ,
  4336. {"Atlantic/Faroe","大西洋/法罗"} ,
  4337. {"Atlantic/Jan_Mayen","大西洋/扬马延"} ,
  4338. {"Atlantic/Madeira","大西洋/马德拉"} ,
  4339. {"Atlantic/Reykjavik","大西洋/雷克雅未克"} ,
  4340. {"Atlantic/South_Georgia","大西洋/南乔治亚州"} ,
  4341. {"Atlantic/St_Helena","大西洋/圣赫勒拿岛"} ,
  4342. {"Atlantic/Stanley","大西洋/斯坦利"} ,
  4343. {"Australia/ACT","澳大利亚/澳大利亚首都地区"} ,
  4344. {"Australia/Adelaide","澳大利亚/阿德莱德"} ,
  4345. {"Australia/Brisbane","澳大利亚/布里斯班"} ,
  4346. {"Australia/Broken_Hill","澳大利亚/布罗肯希尔"} ,
  4347. {"Australia/Canberra","澳大利亚/堪培拉"} ,
  4348. {"Australia/Currie","澳大利亚/柯里"} ,
  4349. {"Australia/Darwin","澳大利亚/达尔文"} ,
  4350. {"Australia/Eucla","澳大利亚/尤克拉拉"} ,
  4351. {"Australia/Hobart","澳大利亚/霍巴特"} ,
  4352. {"Australia/LHI","澳大利亚/LHI"} ,
  4353. {"Australia/Lindeman","澳大利亚/林德曼"} ,
  4354. {"Australia/Lord_Howe","澳大利亚/豪勋爵"} ,
  4355. {"Australia/Melbourne","澳大利亚/墨尔本"} ,
  4356. {"Australia/NSW","澳大利亚/新南威尔士州"} ,
  4357. {"Australia/North","澳大利亚/北部"} ,
  4358. {"Australia/Perth","澳大利亚/珀斯"} ,
  4359. {"Australia/Queensland","澳大利亚/昆士兰"} ,
  4360. {"Australia/South","澳大利亚/南部"} ,
  4361. {"Australia/Sydney","澳大利亚/悉尼"} ,
  4362. {"Australia/Tasmania","澳大利亚/塔斯马尼亚"} ,
  4363. {"Australia/Victoria","澳大利亚/维多利亚"} ,
  4364. {"Australia/West","澳大利亚/西部"} ,
  4365. {"Australia/Yancowinna","澳大利亚/扬科温纳"} ,
  4366. {"Brazil/Acre","巴西/阿卡"} ,
  4367. {"Brazil/DeNoronha","巴西/迪诺罗尼亚群岛"} ,
  4368. {"Brazil/East","巴西/东部"} ,
  4369. {"Brazil/West","巴西/西部"} ,
  4370. {"CET","CET"} ,
  4371. {"CST6CDT","CST6CDT"} ,
  4372. {"Canada/Atlantic","加拿大/大西洋"} ,
  4373. {"Canada/Central","加拿大/中部"} ,
  4374. {"Canada/Eastern","加拿大/东部"} ,
  4375. {"Canada/Mountain","加拿大/山区"} ,
  4376. {"Canada/Newfoundland","加拿大/纽芬兰"} ,
  4377. {"Canada/Pacific","加拿大/太平洋地区"} ,
  4378. {"Canada/Saskatchewan","加拿大/萨斯喀彻温省"} ,
  4379. {"Canada/Yukon","加拿大/育空地区"} ,
  4380. {"Chile/Continental","智利/大陆航空"} ,
  4381. {"Chile/EasterIsland","智利/复活节岛"} ,
  4382. {"Cuba","古巴"} ,
  4383. {"EET","欧洲东部时间"} ,
  4384. {"EST","东部时间"} ,
  4385. {"EST5EDT","EST5EDT"} ,
  4386. {"Egypt","埃及"} ,
  4387. {"Eire","爱尔兰"} ,
  4388. {"Etc/GMT","Etc/GMT"} ,
  4389. {"Etc/GMT+0","Etc/GMT+0"} ,
  4390. {"Etc/GMT+1","Etc/GMT+1"} ,
  4391. {"Etc/GMT+10","Etc/GMT+10"} ,
  4392. {"Etc/GMT+11","Etc/GMT+11"} ,
  4393. {"Etc/GMT+12","Etc/GMT+12"} ,
  4394. {"Etc/GMT+2","Etc/GMT+2"} ,
  4395. {"Etc/GMT+3","Etc/GMT+3"} ,
  4396. {"Etc/GMT+4","Etc/GMT+4"} ,
  4397. {"Etc/GMT+5","Etc/GMT+5"} ,
  4398. {"Etc/GMT+6","Etc/GMT+6"} ,
  4399. {"Etc/GMT+7","Etc/GMT+7"} ,
  4400. {"Etc/GMT+8","Etc/GMT+8"} ,
  4401. {"Etc/GMT+9","Etc/GMT+9"} ,
  4402. {"Etc/GMT-0","Etc/GMT-0"} ,
  4403. {"Etc/GMT-1","Etc/GMT-1"} ,
  4404. {"Etc/GMT-10","Etc/GMT-10"} ,
  4405. {"Etc/GMT-11","Etc/GMT-11"} ,
  4406. {"Etc/GMT-12","Etc/GMT-12"} ,
  4407. {"Etc/GMT-13","Etc/GMT-13"} ,
  4408. {"Etc/GMT-14","Etc/GMT-14"} ,
  4409. {"Etc/GMT-2","Etc/GMT-2"} ,
  4410. {"Etc/GMT-3","Etc/GMT-3"} ,
  4411. {"Etc/GMT-4","Etc/GMT-4"} ,
  4412. {"Etc/GMT-5","Etc/GMT-5"} ,
  4413. {"Etc/GMT-6","Etc/GMT-6"} ,
  4414. {"Etc/GMT-7","Etc/GMT-7"} ,
  4415. {"Etc/GMT-8","Etc/GMT-8"} ,
  4416. {"Etc/GMT-9","Etc/GMT-9"} ,
  4417. {"Etc/GMT0","Etc/GMT0"} ,
  4418. {"Etc/Greenwich","Etc/格林威治"} ,
  4419. {"Etc/UCT","Etc/UCT"} ,
  4420. {"Etc/UTC","Etc/UTC"} ,
  4421. {"Etc/Universal","Etc/通用"} ,
  4422. {"Etc/Zulu","Etc/祖鲁语"} ,
  4423. {"Europe/Amsterdam","欧洲/阿姆斯特丹"} ,
  4424. {"Europe/Andorra","欧洲/安道尔"} ,
  4425. {"Europe/Astrakhan","欧洲/阿斯特拉罕"} ,
  4426. {"Europe/Athens","欧洲/雅典"} ,
  4427. {"Europe/Belfast","欧洲/贝尔法斯特"} ,
  4428. {"Europe/Belgrade","欧洲/贝尔格莱德"} ,
  4429. {"Europe/Berlin","欧洲/柏林"} ,
  4430. {"Europe/Bratislava","欧洲/布拉迪斯拉发"} ,
  4431. {"Europe/Brussels","欧洲/布鲁塞尔"} ,
  4432. {"Europe/Bucharest","欧洲/布加勒斯特"} ,
  4433. {"Europe/Budapest","欧洲/布达佩斯"} ,
  4434. {"Europe/Busingen","欧洲/布辛根"} ,
  4435. {"Europe/Chisinau","欧洲/基希讷乌"} ,
  4436. {"Europe/Copenhagen","欧洲/哥本哈根"} ,
  4437. {"Europe/Dublin","欧洲/都柏林"} ,
  4438. {"Europe/Gibraltar","欧洲/直布罗陀"} ,
  4439. {"Europe/Guernsey","欧洲/根西岛"} ,
  4440. {"Europe/Helsinki","欧洲/赫尔辛基"} ,
  4441. {"Europe/Isle_of_Man","欧洲/马恩岛"} ,
  4442. {"Europe/Istanbul","欧洲/伊斯坦布尔"} ,
  4443. {"Europe/Jersey","欧洲/泽西岛"} ,
  4444. {"Europe/Kaliningrad","欧洲/加里宁格勒"} ,
  4445. {"Europe/Kiev","欧洲/基辅"} ,
  4446. {"Europe/Kirov","欧洲/基洛夫"} ,
  4447. {"Europe/Kyiv","欧洲/基辅"} ,
  4448. {"Europe/Lisbon","欧洲/里斯本"} ,
  4449. {"Europe/Ljubljana","欧洲/卢布尔雅那"} ,
  4450. {"Europe/London","欧洲/伦敦"} ,
  4451. {"Europe/Luxembourg","欧洲/卢森堡"} ,
  4452. {"Europe/Madrid","欧洲/马德里"} ,
  4453. {"Europe/Malta","欧洲/马耳他"} ,
  4454. {"Europe/Mariehamn","欧洲/玛丽港"} ,
  4455. {"Europe/Minsk","欧洲/明斯克"} ,
  4456. {"Europe/Monaco","欧洲/摩纳哥"} ,
  4457. {"Europe/Moscow","欧洲/莫斯科"} ,
  4458. {"Europe/Nicosia","欧洲/尼科西亚"} ,
  4459. {"Europe/Oslo","欧洲/奥斯陆"} ,
  4460. {"Europe/Paris","欧洲/巴黎"} ,
  4461. {"Europe/Podgorica","欧洲/波德戈里察"} ,
  4462. {"Europe/Prague","欧洲/布拉格"} ,
  4463. {"Europe/Riga","欧洲/里加"} ,
  4464. {"Europe/Rome","欧洲/罗马"} ,
  4465. {"Europe/Samara","欧洲/萨马拉"} ,
  4466. {"Europe/San_Marino","欧洲/圣马力诺"} ,
  4467. {"Europe/Sarajevo","欧洲/萨拉热窝"} ,
  4468. {"Europe/Saratov","欧洲/萨拉托夫"} ,
  4469. {"Europe/Simferopol","欧洲/辛菲罗波尔"} ,
  4470. {"Europe/Skopje","欧洲/斯科普里"} ,
  4471. {"Europe/Sofia","欧洲/索非亚"} ,
  4472. {"Europe/Stockholm","欧洲/斯德哥尔摩"} ,
  4473. {"Europe/Tallinn","欧洲/塔林"} ,
  4474. {"Europe/Tirane","欧洲/地拉那"} ,
  4475. {"Europe/Tiraspol","欧洲/蒂拉斯波尔"} ,
  4476. {"Europe/Ulyanovsk","欧洲/乌里扬诺夫斯克"} ,
  4477. {"Europe/Uzhgorod","欧洲/乌日哥罗德"} ,
  4478. {"Europe/Vaduz","欧洲/瓦杜兹"} ,
  4479. {"Europe/Vatican","欧洲/梵蒂冈"} ,
  4480. {"Europe/Vienna","欧洲/维也纳"} ,
  4481. {"Europe/Vilnius","欧洲/维尔纽斯"} ,
  4482. {"Europe/Volgograd","欧洲/伏尔加格勒"} ,
  4483. {"Europe/Warsaw","欧洲/华沙"} ,
  4484. {"Europe/Zagreb","欧洲/萨格勒布"} ,
  4485. {"Europe/Zaporozhye","欧洲/扎波罗热"} ,
  4486. {"Europe/Zurich","欧洲/苏黎世"} ,
  4487. {"GB","国标"} ,
  4488. {"GB-Eire","英国-爱尔兰"} ,
  4489. {"GMT","格林威治标准时间"} ,
  4490. {"GMT+0","格林威治标准时间+0"} ,
  4491. {"GMT-0","GMT-0"} ,
  4492. {"GMT0","格林威治标准时间0"} ,
  4493. {"Greenwich","格林威治"} ,
  4494. {"HST","高温试验"} ,
  4495. {"Hongkong","香港"} ,
  4496. {"Iceland","冰岛"} ,
  4497. {"Indian/Antananarivo","印度/塔那那利佛"} ,
  4498. {"Indian/Chagos","印第安人/查戈斯人"} ,
  4499. {"Indian/Christmas","印度/圣诞节"} ,
  4500. {"Indian/Cocos","印度/科科斯"} ,
  4501. {"Indian/Comoro","印度/科摩罗"} ,
  4502. {"Indian/Kerguelen","印度/凯尔盖朗"} ,
  4503. {"Indian/Mahe","印度/马埃岛"} ,
  4504. {"Indian/Maldives","印度/马尔代夫"} ,
  4505. {"Indian/Mauritius","印度/毛里求斯"} ,
  4506. {"Indian/Mayotte","印度/马约特岛"} ,
  4507. {"Indian/Reunion","印度/留尼汪岛"} ,
  4508. {"Iran","伊朗"} ,
  4509. {"Israel","以色列"} ,
  4510. {"Jamaica","牙买加"} ,
  4511. {"Japan","日本"} ,
  4512. {"Kwajalein","夸贾林环礁"} ,
  4513. {"Libya","利比亚"} ,
  4514. {"MET","梅特"} ,
  4515. {"MST","MST"} ,
  4516. {"MST7MDT","MST7MDT"} ,
  4517. {"Mexico/BajaNorte","墨西哥/北下巴"} ,
  4518. {"Mexico/BajaSur","墨西哥/巴哈苏尔"} ,
  4519. {"Mexico/General","墨西哥/一般"} ,
  4520. {"NZ","新西兰"} ,
  4521. {"NZ-CHAT","新西兰聊天室"} ,
  4522. {"Navajo","纳瓦霍语"} ,
  4523. {"PRC","中国"} ,
  4524. {"PST8PDT","PST8PDT"} ,
  4525. {"Pacific/Apia","太平洋/阿皮亚"} ,
  4526. {"Pacific/Auckland","太平洋/奥克兰"} ,
  4527. {"Pacific/Bougainville","太平洋/布干维尔岛"} ,
  4528. {"Pacific/Chatham","太平洋/查塔姆"} ,
  4529. {"Pacific/Chuuk","太平洋/楚克"} ,
  4530. {"Pacific/Easter","太平洋/复活节"} ,
  4531. {"Pacific/Efate","太平洋/埃法特"} ,
  4532. {"Pacific/Enderbury","太平洋/恩德伯里"} ,
  4533. {"Pacific/Fakaofo","太平洋/法考福"} ,
  4534. {"Pacific/Fiji","太平洋/斐济"} ,
  4535. {"Pacific/Funafuti","太平洋/富纳富提"} ,
  4536. {"Pacific/Galapagos","太平洋/加拉帕戈斯群岛"} ,
  4537. {"Pacific/Gambier","太平洋/甘比尔"} ,
  4538. {"Pacific/Guadalcanal","太平洋/瓜达尔卡纳尔岛"} ,
  4539. {"Pacific/Guam","太平洋/关岛"} ,
  4540. {"Pacific/Honolulu","太平洋/檀香山"} ,
  4541. {"Pacific/Johnston","太平洋/约翰斯顿"} ,
  4542. {"Pacific/Kanton","太平洋/关东"} ,
  4543. {"Pacific/Kiritimati","太平洋/基里蒂马蒂"} ,
  4544. {"Pacific/Kosrae","太平洋/科斯雷"} ,
  4545. {"Pacific/Kwajalein","太平洋/夸贾林环礁"} ,
  4546. {"Pacific/Majuro","太平洋/马朱罗"} ,
  4547. {"Pacific/Marquesas","太平洋/马克萨斯"} ,
  4548. {"Pacific/Midway","太平洋/中途岛"} ,
  4549. {"Pacific/Nauru","太平洋/瑙鲁"} ,
  4550. {"Pacific/Niue","太平洋/纽埃"} ,
  4551. {"Pacific/Norfolk","太平洋/诺福克"} ,
  4552. {"Pacific/Noumea","太平洋/努美阿"} ,
  4553. {"Pacific/Pago_Pago","太平洋/帕果"} ,
  4554. {"Pacific/Palau","太平洋/帕劳"} ,
  4555. {"Pacific/Pitcairn","太平洋/皮特凯恩"} ,
  4556. {"Pacific/Pohnpei","太平洋/波纳佩"} ,
  4557. {"Pacific/Ponape","太平洋/波纳佩"} ,
  4558. {"Pacific/Port_Moresby","太平洋/莫尔兹比港"} ,
  4559. {"Pacific/Rarotonga","太平洋/拉罗汤加"} ,
  4560. {"Pacific/Saipan","太平洋/塞班岛"} ,
  4561. {"Pacific/Samoa","太平洋/萨摩亚"} ,
  4562. {"Pacific/Tahiti","太平洋/大溪地"} ,
  4563. {"Pacific/Tarawa","太平洋/塔拉瓦"} ,
  4564. {"Pacific/Tongatapu","太平洋/汤加塔布岛"} ,
  4565. {"Pacific/Truk","太平洋/特鲁克"} ,
  4566. {"Pacific/Wake","太平洋/威克"} ,
  4567. {"Pacific/Wallis","太平洋/沃利斯"} ,
  4568. {"Pacific/Yap","太平洋/雅浦岛"} ,
  4569. {"Poland","波兰"} ,
  4570. {"Portugal","葡萄牙"} ,
  4571. {"ROC","ROC"} ,
  4572. {"ROK","韩国"} ,
  4573. {"Singapore","新加坡"} ,
  4574. {"Turkey","Turkey"} ,
  4575. {"UCT","世界标准时间"} ,
  4576. {"US/Alaska","美国/阿拉斯加"} ,
  4577. {"US/Aleutian","美国/阿留申群岛"} ,
  4578. {"US/Arizona","美国/亚利桑那州"} ,
  4579. {"US/Central","美国/中部"} ,
  4580. {"US/East-Indiana","美国/东印第安纳州"} ,
  4581. {"US/Eastern","美国/东部"} ,
  4582. {"US/Hawaii","美国/夏威夷"} ,
  4583. {"US/Indiana-Starke","美国/印第安纳州斯塔克"} ,
  4584. {"US/Michigan","美国/密歇根州"} ,
  4585. {"US/Mountain","美国/山地"} ,
  4586. {"US/Pacific","美国/太平洋地区"} ,
  4587. {"US/Samoa","美国/萨摩亚"} ,
  4588. {"UTC","世界标准时间"} ,
  4589. {"Universal","Universal"} ,
  4590. {"W-SU","W-SU"} ,
  4591. {"WET","WET"} ,
  4592. {"Zulu","Zulu"}
  4593. };
  4594. /// <summary>
  4595. /// 获取国家或城市当地时间
  4596. /// </summary>
  4597. /// <param name="country"></param>
  4598. /// <param name="city"></param>
  4599. /// <returns></returns>
  4600. public static DateTime? GetCountryOrCityCurrentDateTime(string country, string city)
  4601. {
  4602. DateTime? currDt = null;
  4603. var currTimezones = _timeZoneCityMappings.Where(x => x.Value.Contains(city)).ToList();
  4604. if (!currTimezones.Any())
  4605. {
  4606. currTimezones = _timeZoneCityMappings.Where(x => x.Value.Contains(country)).ToList();
  4607. }
  4608. ;
  4609. string timeZoneId = string.Empty;
  4610. if (currTimezones.Count > 1)
  4611. {
  4612. currTimezones = currTimezones.Where(x => x.Value.Contains(country)).ToList();
  4613. timeZoneId = currTimezones.FirstOrDefault().Key ?? string.Empty;
  4614. }
  4615. else timeZoneId = currTimezones.FirstOrDefault().Key ?? string.Empty;
  4616. if (string.IsNullOrEmpty(timeZoneId)) return currDt;
  4617. // Step 1: 获取当前 UTC 时间
  4618. Instant now = SystemClock.Instance.GetCurrentInstant();
  4619. // Step 2: 加载目标时区(以 "Asia/Shanghai" 为例)
  4620. var timeZone = DateTimeZoneProviders.Tzdb[timeZoneId];
  4621. if (timeZone == null) return currDt;
  4622. // Step 3: 将 UTC 时间转换为目标时区的本地时间
  4623. currDt = now.InZone(timeZone).ToDateTimeUnspecified();
  4624. return currDt;
  4625. }
  4626. #endregion
  4627. #region aspose
  4628. /// <summary>
  4629. /// aspose word 设置页脚
  4630. /// </summary>
  4631. /// <param name="builder"></param>
  4632. /// <param name="footerLabel">页脚内容</param>
  4633. /// <param name="font">字体名称</param>
  4634. /// <param name="fontSize"><字体大小/param>
  4635. public static void AsposeWordSetFooter(DocumentBuilder builder, string footerLabel, string font, int fontSize)
  4636. {
  4637. Aspose.Words.Section currentSection = builder.CurrentSection;
  4638. var pageSetup = currentSection.PageSetup;
  4639. pageSetup.DifferentFirstPageHeaderFooter = true;
  4640. //第一页页脚
  4641. builder.MoveToHeaderFooter(HeaderFooterType.FooterFirst);
  4642. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  4643. builder.Font.Name = font;
  4644. builder.Font.Bold = true;
  4645. builder.Font.Size = fontSize;
  4646. builder.Write(footerLabel);
  4647. //非第一页页脚
  4648. builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
  4649. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  4650. builder.Font.Name = font;
  4651. builder.Font.Bold = true;
  4652. builder.Font.Size = fontSize;
  4653. builder.Write(footerLabel);
  4654. }
  4655. #endregion
  4656. #region 出入境费用
  4657. #region 汇率
  4658. /// <summary>
  4659. /// 三公费用实时汇率调差
  4660. /// </summary>
  4661. private readonly static decimal _xchgRateAdj = 0.00M;
  4662. /// <summary>
  4663. /// 三公费用实时汇率上浮比例
  4664. /// </summary>
  4665. private readonly static decimal _fxRateRise = 1.0350M;
  4666. #region 城市区间费用详情
  4667. /// <summary>
  4668. /// 城市区间费用详情 使用的币种及汇率
  4669. /// </summary>
  4670. /// <param name="groupId"></param>
  4671. /// <returns></returns>
  4672. public static async Task<List<CurrencyInfo>> EnterExitCostOVFeeUsedCurrencyAsync(int groupId = 0)
  4673. {
  4674. var infos = new List<CurrencyInfo>();
  4675. bool isUsedGroup = false;
  4676. var countryies = new List<string>();
  4677. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  4678. if (groupInfo != null)
  4679. {
  4680. countryies = _dirRep.GroupSplitCountry(groupInfo.VisitCountry);
  4681. if (countryies.Any())
  4682. {
  4683. isUsedGroup = true;
  4684. }
  4685. }
  4686. infos = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  4687. .LeftJoin<Sys_SetData>((ov, sd) => ov.Currency == sd.Id)
  4688. .Where((ov, sd) => ov.IsDel == 0)
  4689. .WhereIF(isUsedGroup, (ov, sd) => countryies.Contains(ov.CountryName))
  4690. .Select((ov, sd) => new CurrencyInfo()
  4691. {
  4692. CurrencyCode = sd.Name.ToUpper(),
  4693. CurrencyName = sd.Remark
  4694. })
  4695. .Distinct()
  4696. .ToListAsync();
  4697. //出入境费用存储的币种及汇率
  4698. var eexCurrencyInfos = new List<CurrencyInfo>();
  4699. if (infos.Any())
  4700. {
  4701. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).FirstAsync();
  4702. if (eecInfo != null)
  4703. {
  4704. eexCurrencyInfos = CommonFun.GetCurrencyChinaToList(eecInfo.CurrencyRemark);
  4705. }
  4706. }
  4707. //合并已使用币种及汇率
  4708. infos.ForEach(x =>
  4709. {
  4710. x.Rate = x.Rate == 0.00M ? 1.0000M : x.Rate;
  4711. var eexCurrencyInfo = eexCurrencyInfos.Where(y => y.CurrencyCode == x.CurrencyCode).FirstOrDefault();
  4712. if (eexCurrencyInfo != null)
  4713. {
  4714. x.Rate = eexCurrencyInfo.Rate;
  4715. }
  4716. });
  4717. //未存储费用集合
  4718. var unSaveCurrInfos = infos.Where(x => !eexCurrencyInfos.Any(y => y.CurrencyCode == x.CurrencyCode)).ToList();
  4719. if (unSaveCurrInfos.Any())
  4720. {
  4721. var currencyRate = await _juHeApi.PostItemRateAsync(unSaveCurrInfos.Select(it => it.CurrencyCode!).ToArray());
  4722. if (currencyRate.Count > 0)
  4723. {
  4724. foreach (var item in infos)
  4725. {
  4726. var rateInfo = currencyRate.Where(it => it.Name.Equals(item.CurrencyName)).FirstOrDefault();
  4727. if (rateInfo != null)
  4728. {
  4729. decimal rate1 = Convert.ToDecimal(rateInfo.FSellPri) / 100.00M;
  4730. rate1 *= _fxRateRise;
  4731. item.Rate = rate1.TruncDecimals(4) + _xchgRateAdj;
  4732. }
  4733. }
  4734. }
  4735. }
  4736. return infos;
  4737. }
  4738. /// <summary>
  4739. /// 城市区间-草稿费用详情 使用的币种及汇率
  4740. /// </summary>
  4741. /// <param name="draftId"></param>
  4742. /// <returns></returns>
  4743. public static async Task<List<CurrencyInfo>> EnterExitCostDrafOVFeeUsedCurrencyAsync(int draftId = 0)
  4744. {
  4745. var infos = new List<CurrencyInfo>();
  4746. bool isUsedDraft = false;
  4747. var countryies = new List<string>();
  4748. var drafInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == draftId).FirstAsync();
  4749. if (drafInfo != null)
  4750. {
  4751. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  4752. .Where(x => x.IsDel == 0 && x.ParentId == draftId)
  4753. .Select(x => x.NationalTravelFeeId)
  4754. .Distinct()
  4755. .ToListAsync();
  4756. var countries = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  4757. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  4758. .Select(x => x.Country)
  4759. .Distinct()
  4760. .ToListAsync();
  4761. if (countryies.Any())
  4762. {
  4763. isUsedDraft = true;
  4764. }
  4765. }
  4766. infos = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  4767. .LeftJoin<Sys_SetData>((ov, sd) => ov.Currency == sd.Id)
  4768. .Where((ov, sd) => ov.IsDel == 0)
  4769. .WhereIF(isUsedDraft, (ov, sd) => countryies.Contains(ov.CountryName))
  4770. .Select((ov, sd) => new CurrencyInfo()
  4771. {
  4772. CurrencyCode = sd.Name.ToUpper(),
  4773. CurrencyName = sd.Remark
  4774. })
  4775. .Distinct()
  4776. .ToListAsync();
  4777. //出入境费用存储的币种及汇率
  4778. var eexCurrencyInfos = new List<CurrencyInfo>();
  4779. if (infos.Any())
  4780. {
  4781. if (drafInfo != null)
  4782. {
  4783. eexCurrencyInfos = CommonFun.GetCurrencyChinaToList(drafInfo.CurrencyRemark);
  4784. }
  4785. }
  4786. //合并已使用币种及汇率
  4787. infos.ForEach(x =>
  4788. {
  4789. if (x.CurrencyCode.Equals("CNY")) x.Rate = 1.0000M;
  4790. var eexCurrencyInfo = eexCurrencyInfos.Where(y => y.CurrencyCode == x.CurrencyCode).FirstOrDefault();
  4791. if (eexCurrencyInfo != null)
  4792. {
  4793. x.Rate = eexCurrencyInfo.Rate;
  4794. }
  4795. });
  4796. //未存储费用集合
  4797. var unSaveCurrInfos = infos.Where(x => !eexCurrencyInfos.Any(y => y.CurrencyCode == x.CurrencyCode)).ToList();
  4798. if (unSaveCurrInfos.Any())
  4799. {
  4800. var currencyRate = await _juHeApi.PostItemRateAsync(unSaveCurrInfos.Select(it => it.CurrencyCode!).ToArray());
  4801. if (currencyRate.Count > 0)
  4802. {
  4803. foreach (var item in infos)
  4804. {
  4805. var rateInfo = currencyRate.Where(it => it.Name.Equals(item.CurrencyName)).FirstOrDefault();
  4806. if (rateInfo != null)
  4807. {
  4808. decimal rate1 = Convert.ToDecimal(rateInfo.FSellPri) / 100.00M;
  4809. rate1 *= _fxRateRise;
  4810. item.Rate = rate1.TruncDecimals(4) + _xchgRateAdj;
  4811. }
  4812. }
  4813. }
  4814. }
  4815. return infos;
  4816. }
  4817. #endregion
  4818. /// <summary>
  4819. /// 出入境费用 初始化汇率
  4820. /// </summary>
  4821. /// <returns></returns>
  4822. public static async Task<List<CurrencyInfo>> EnterExitCostInitRate()
  4823. {
  4824. //默认币种显示
  4825. var currencyInfos = new List<CurrencyInfo>()
  4826. {
  4827. new(){ CurrencyCode="USD",CurrencyName = "美元",Rate = 7.5000M },
  4828. new(){ CurrencyCode="EUR",CurrencyName = "欧元",Rate = 8.0000M },
  4829. new(){ CurrencyCode="GBP",CurrencyName = "英镑",Rate = 9.5000M },
  4830. new(){ CurrencyCode="JPY",CurrencyName = "日元",Rate = 0.0500M },
  4831. new(){ CurrencyCode="HKD",CurrencyName = "港币",Rate = 0.9500M },
  4832. };
  4833. var currencyRate = await _juHeApi.PostItemRateAsync(currencyInfos.Select(it => it.CurrencyCode!).ToArray());
  4834. if (currencyRate.Count > 0)
  4835. {
  4836. foreach (var item in currencyInfos)
  4837. {
  4838. var rateInfo = currencyRate.Where(it => it.Name.Equals(item.CurrencyName)).FirstOrDefault();
  4839. if (rateInfo != null)
  4840. {
  4841. decimal rate1 = Convert.ToDecimal(rateInfo.FSellPri) / 100.00M;
  4842. rate1 *= _fxRateRise;
  4843. item.Rate = rate1.TruncDecimals(4) + _xchgRateAdj;
  4844. }
  4845. }
  4846. }
  4847. return currencyInfos;
  4848. }
  4849. /// <summary>
  4850. /// 出入境费用 实时汇率
  4851. /// </summary>
  4852. /// <returns></returns>
  4853. public static async Task<List<dynamic>> EnterExitCostLiveRate()
  4854. {
  4855. List<dynamic> reteInfos = new List<dynamic>();
  4856. //默认币种显示
  4857. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>()
  4858. {
  4859. new(){ CurrencyCode="USD",CurrencyName = "美元",Rate = 7.5000M },
  4860. new(){ CurrencyCode="EUR",CurrencyName = "欧元",Rate = 8.0000M },
  4861. new(){ CurrencyCode="GBP",CurrencyName = "英镑",Rate = 9.5000M },
  4862. new(){ CurrencyCode="JPY",CurrencyName = "日元",Rate = 0.0500M },
  4863. new(){ CurrencyCode="HKD",CurrencyName = "港币",Rate = 0.9500M }
  4864. };
  4865. var currencyRate = await _juHeApi.PostItemRateAsync(currencyInfos.Select(it => it.CurrencyCode!).ToArray());
  4866. if (currencyRate.Count > 0)
  4867. {
  4868. foreach (var item in currencyInfos)
  4869. {
  4870. var rateInfo = currencyRate.Where(it => it.Name.Equals(item.CurrencyName)).FirstOrDefault();
  4871. if (rateInfo != null)
  4872. {
  4873. item.Rate = Convert.ToDecimal((Convert.ToDecimal(rateInfo.FSellPri == null ? 0.00M : rateInfo.FSellPri) / 100.00M).ToString("#0.0000"));
  4874. decimal rate1 = item.Rate * _fxRateRise + _xchgRateAdj;
  4875. reteInfos.Add(new
  4876. {
  4877. currCode = item.CurrencyCode,
  4878. currName = item.CurrencyName,
  4879. rate = rate1.TruncDecimals(4),
  4880. lastUpdateDt = rateInfo.Date + " " + rateInfo.Time
  4881. });
  4882. }
  4883. }
  4884. }
  4885. return reteInfos;
  4886. }
  4887. /// <summary>
  4888. /// 出入境费用 汇率验证
  4889. /// </summary>
  4890. /// <param name="groupId"></param>
  4891. /// <param name="checkCurrencys">已使用币种</param>
  4892. /// <returns></returns>
  4893. public static async Task<(bool, string, List<CurrencyInfo>)> EnterExitCostCheckRate(int groupId, List<CurrencyInfo> checkCurrencys)
  4894. {
  4895. if (checkCurrencys == null || checkCurrencys.Count < 1) return (false, string.Empty, new List<CurrencyInfo>());
  4896. var info = await _sqlSugar.Queryable<Grp_EnterExitCost>().FirstAsync(x => x.IsDel == 0 && x.DiId == groupId);
  4897. if (info == null) return (false, string.Empty, new List<CurrencyInfo>());
  4898. List<CurrencyInfo> liveRates;
  4899. var cacheRateInfo = await _sqlSugar.Queryable<Sys_ExchangeRateRecord>()
  4900. .OrderByDescending(x => x.CreateTime)
  4901. .FirstAsync(x => x.IsDel == 0 && x.DiId == info.Id);
  4902. if (cacheRateInfo == null)
  4903. {
  4904. var _currencyRate = await _juHeApi.PostItemRateAsync(Array.Empty<string>());
  4905. if (_currencyRate.Count < 1) return (false, "获取汇率失败,请稍后再试!", new List<CurrencyInfo>());
  4906. liveRates = _currencyRate.Select(it => new CurrencyInfo
  4907. {
  4908. CurrencyCode = it.Name,
  4909. CurrencyName = it.Name,
  4910. Rate = Convert.ToDecimal((Convert.ToDecimal(it.FSellPri == null ? 0.00M : it.FSellPri) / 100.00M).ToString("#0.0000"))
  4911. }).ToList();
  4912. }
  4913. else
  4914. {
  4915. liveRates = CommonFun.GetCurrencyChinaToList(cacheRateInfo.RateInfo);
  4916. foreach (var x in liveRates)
  4917. x.Rate = (x.Rate / 100.00M).TruncDecimals(4);
  4918. }
  4919. var cacheRateInfos = CommonFun.GetCurrencyChinaToList(info.CurrencyRemark);
  4920. var isSendMsg = true;
  4921. var msgContent = new StringBuilder();
  4922. //去掉费用未使用得币种
  4923. if (checkCurrencys != null && checkCurrencys.Count > 0)
  4924. {
  4925. cacheRateInfos = cacheRateInfos.Where(x => checkCurrencys.Select(x1 => x1.CurrencyName).ToList().Contains(x.CurrencyName)).ToList();
  4926. }
  4927. if (cacheRateInfos.Any())
  4928. {
  4929. decimal rowthRate = _fxRateRise;
  4930. foreach (var cacheRate in cacheRateInfos)
  4931. {
  4932. var liveRate = liveRates.Find(x => x.CurrencyName.Equals(cacheRate.CurrencyName));
  4933. if (liveRate == null) continue;
  4934. var currRate = (rowthRate * liveRate.Rate).TruncDecimals(4) + _xchgRateAdj;
  4935. //if (cacheRate.Rate != currRate)
  4936. //{
  4937. // isSendMsg = true;
  4938. //>团组归属:<font color='info'>{groupName}</font>
  4939. msgContent.AppendLine($">- {cacheRate.CurrencyName}汇率(页面保存):{cacheRate.Rate:#0.0000} / 实时汇率(接口保存,已上浮1.0350):{currRate:#0.0000}【原接口输出汇率为:{liveRate.Rate:#0.0000}】");
  4940. //}
  4941. }
  4942. return (isSendMsg, msgContent.ToString(), liveRates);
  4943. }
  4944. return (false, string.Empty, new List<CurrencyInfo>());
  4945. }
  4946. #endregion
  4947. #region 三公费用明细 文件下载
  4948. /// <summary>
  4949. /// 获取三公费用标准city
  4950. /// </summary>
  4951. /// <param name="placeData"></param>
  4952. /// <param name="nationalTravelFeeId"></param>
  4953. /// <returns></returns>
  4954. private static string GetEnterExitCostExportCity(List<Grp_NationalTravelFee> placeData, int nationalTravelFeeId)
  4955. {
  4956. string _city = string.Empty;
  4957. if (placeData.Count < 1) return _city;
  4958. var data = placeData.Find(it => it.Id == nationalTravelFeeId);
  4959. if (data == null) return _city;
  4960. string country = data.Country;
  4961. string city = data.City;
  4962. if (city.Contains("其他城市") || city.Contains("所有城市")) _city = $"{country}-{city}";
  4963. else _city = city;
  4964. return _city;
  4965. }
  4966. /// <summary>
  4967. /// 三公费用明细 文件下载
  4968. /// </summary>
  4969. /// <param name="dto"></param>
  4970. /// <param name="fileFormat"></param>
  4971. /// <returns></returns>
  4972. public static async Task<JsonView> EnterExitCostDownload(EnterExitCostDownloadDto dto, string fileFormat = "pdf")
  4973. {
  4974. var _view = new JsonView() { Code = StatusCodes.Status204NoContent };
  4975. if (dto.DiId < 1)
  4976. {
  4977. _view.Msg = "请传入有效的DiId参数;";
  4978. return _view;
  4979. }
  4980. if (dto.ExportType < 1)
  4981. {
  4982. _view.Msg = MsgTips.Port;
  4983. return _view;
  4984. }
  4985. if (dto.SubTypeId < 1)
  4986. {
  4987. _view.Msg = @"请传入有效的SubTypeId参数;
  4988. 1 明细表 --> 1005(默认明细表) 1006(因公出国(境)经费测算明细表) 1007(四川省商务厅出国经费财政先行审核表)
  4989. 2 表格 --> 1008(派员单位出(境)任务和预算审批意见表) 1009(省级单位出(境)经费报销单)
  4990. 3 团组成员名单 1 团组成员名单";
  4991. return _view;
  4992. }
  4993. try
  4994. {
  4995. var enterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  4996. var dayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).ToList();
  4997. if (enterExitCosts == null)
  4998. {
  4999. _view.Msg = @"该团组未填写出入境费用;";
  5000. return _view;
  5001. }
  5002. //数据源
  5003. List<Grp_DayAndCost> dac1 = dayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  5004. List<Grp_DayAndCost> dac2 = dayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  5005. List<Grp_DayAndCost> dac3 = dayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  5006. List<Grp_DayAndCost> dac4 = dayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  5007. var _CurrDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  5008. var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == dto.DiId).First();
  5009. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  5010. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  5011. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  5012. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
  5013. .Select((tcl, dc, cc) => new
  5014. {
  5015. Name = dc.LastName + dc.FirstName,
  5016. Sex = dc.Sex,
  5017. Birthday = dc.BirthDay,
  5018. Company = cc.CompanyFullName,
  5019. Job = dc.Job
  5020. })
  5021. .ToList();
  5022. var blackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  5023. var threeCodes = _sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList();
  5024. var placeData = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  5025. var rateDatas = await enterExitCosts.CurrencyRemark.SplitExchangeRate();
  5026. _DelegationInfo.VisitCountry = _DelegationInfo?.VisitCountry?.Replace("|", "、") ?? "";
  5027. if (dto.ExportType == 1) //明细表
  5028. {
  5029. if (dto.SubTypeId == 1005) //1005(默认明细表)
  5030. {
  5031. if (!fileFormat.Equals("pdf")) fileFormat = "docx";
  5032. //获取模板
  5033. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/出入境费用表模板.docx");
  5034. //载入模板
  5035. Document doc = new Document(tempPath);
  5036. DocumentBuilder builder = new DocumentBuilder(doc);
  5037. //利用键值对存放数据
  5038. Dictionary<string, string> dic = new Dictionary<string, string>();
  5039. decimal stayFeeTotal = dayAndCosts.Where(it => it.Type == 1).Sum(it => it.SubTotal); // 住宿费
  5040. decimal mealsFeeTotal = dayAndCosts.Where(it => it.Type == 2).Sum(it => it.SubTotal); // 伙食费费
  5041. decimal miscellaneousFeeTotal = dayAndCosts.Where(it => it.Type == 3).Sum(it => it.SubTotal); // 公杂费
  5042. decimal tainFeeTotal = dayAndCosts.Where(it => it.Type == 4).Sum(it => it.SubTotal); // 培训费
  5043. decimal insidePayTotal = enterExitCosts.InsidePay;
  5044. string row1_1 = "";
  5045. if (enterExitCosts.Visa > 0)
  5046. {
  5047. //insidePayTotal += enterExitCosts.Visa;
  5048. row1_1 = $"签证费: {enterExitCosts.Visa:#0.00} 人民币/人";
  5049. //if (!string.IsNullOrEmpty(enterExitCosts.VisaRemark))
  5050. //{
  5051. // row1_1 += $"\t签证费用描述: {enterExitCosts.VisaRemark}";
  5052. //}
  5053. }
  5054. string row1_2 = "";
  5055. if (enterExitCosts.YiMiao > 0)
  5056. {
  5057. //insidePayTotal += enterExitCosts.YiMiao;
  5058. row1_2 += $"疫苗费:{enterExitCosts.YiMiao:#0.00} 人民币/人";
  5059. }
  5060. if (enterExitCosts.HeSuan > 0)
  5061. {
  5062. //insidePayTotal += enterExitCosts.HeSuan;
  5063. row1_2 += $"核酸检测费:{enterExitCosts.HeSuan:#0.00} 人民币/人";
  5064. }
  5065. if (enterExitCosts.Service > 0)
  5066. {
  5067. //insidePayTotal += enterExitCosts.Service;
  5068. row1_2 += $"服务费:{enterExitCosts.Service:#0.00} 人民币/人";
  5069. }
  5070. string row1_3 = "";
  5071. if (enterExitCosts.Safe > 0)
  5072. {
  5073. //insidePayTotal += enterExitCosts.Safe;
  5074. row1_3 += $"保险费:{enterExitCosts.Safe:#0.00} 人民币/人";
  5075. }
  5076. if (enterExitCosts.Ticket > 0)
  5077. {
  5078. //insidePayTotal += enterExitCosts.Ticket;
  5079. row1_3 += $"参展门票:{enterExitCosts.Ticket:#0.00} 人民币/人";
  5080. }
  5081. string row1 = "";
  5082. if (!string.IsNullOrEmpty(row1_1)) row1 += $"{row1_1}\r\n";
  5083. if (!string.IsNullOrEmpty(row1_2)) row1 += $"{row1_2}\r\n";
  5084. if (!string.IsNullOrEmpty(row1_3)) row1 += $"{row1_3}";
  5085. dic.Add("InsidePay", insidePayTotal.ToString("#0.00"));
  5086. dic.Add("Row1Str", row1);
  5087. dic.Add("OutsideJJ", enterExitCosts.OutsideJJPay.ToString("#0.00"));
  5088. dic.Add("OutsaideGW", enterExitCosts.OutsideGWPay.ToString("#0.00"));
  5089. dic.Add("AirJJ", enterExitCosts.AirJJ.ToString("#0.00"));
  5090. dic.Add("AirGW", enterExitCosts.AirGW.ToString("#0.00"));
  5091. var cityTrafficLable = new StringBuilder()
  5092. .AppendFormat($"经济舱费用:{enterExitCosts.CityTranffic:#0.00} 元/人、")
  5093. .AppendFormat($"公务舱费用:{enterExitCosts.CityTranffic1:#0.00} 元/人、")
  5094. .AppendFormat($"头等舱费用:{enterExitCosts.CityTranffic2:#0.00}")
  5095. .ToString();
  5096. dic.Add("CityTranffic", cityTrafficLable);
  5097. dic.Add("SubZS", stayFeeTotal.ToString("#0.00"));
  5098. dic.Add("SubHS", mealsFeeTotal.ToString("#0.00"));
  5099. string miscellaneousFeeTotalStr = miscellaneousFeeTotal.ToString("#0.00");
  5100. dic.Add("SubGZF", miscellaneousFeeTotalStr);
  5101. //dic.Add("SubPX", tainFeeTotal.ToString("#0.00"));
  5102. decimal subJJC = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + enterExitCosts.OutsideJJPay;
  5103. decimal subGWC = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + enterExitCosts.OutsideGWPay;
  5104. dic.Add("SubJJC", subJJC.ToString("#0.00"));
  5105. dic.Add("SubGWC", subGWC.ToString("#0.00"));
  5106. #region 填充word模板书签内容
  5107. foreach (var key in dic.Keys)
  5108. {
  5109. builder.MoveToBookmark(key);
  5110. builder.Write(dic[key]);
  5111. }
  5112. #endregion
  5113. #region 填充word表格内容
  5114. ////获读取指定表格方法二
  5115. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  5116. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  5117. for (int i = 0; i < dac1.Count; i++)
  5118. {
  5119. Grp_DayAndCost dac = dac1[i];
  5120. if (dac == null) continue;
  5121. builder.MoveToCell(0, i, 0, 0);
  5122. builder.Write("第" + dac.Days.ToString() + "晚:");
  5123. builder.MoveToCell(0, i, 1, 0);
  5124. //builder.Write(placeData.Find(it => it.Id == dac.NationalTravelFeeId)?.Country ?? "Unknown");
  5125. //builder.Write(dac.Place == null ? "" : dac.Place);
  5126. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  5127. builder.MoveToCell(0, i, 2, 0);
  5128. builder.Write("费用标准:");
  5129. string curr = "";
  5130. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  5131. if (currData != null)
  5132. {
  5133. curr = currData.Name;
  5134. }
  5135. builder.MoveToCell(0, i, 3, 0);
  5136. builder.Write(dac.Cost.ToString("#0.00") + curr);
  5137. builder.MoveToCell(0, i, 4, 0);
  5138. builder.Write("费用小计:");
  5139. builder.MoveToCell(0, i, 5, 0);
  5140. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  5141. }
  5142. //删除多余行
  5143. while (table1.Rows.Count > dac1.Count)
  5144. {
  5145. table1.Rows.RemoveAt(dac1.Count);
  5146. }
  5147. Aspose.Words.Tables.Table table2 = allTables[1] as Aspose.Words.Tables.Table;
  5148. for (int i = 0; i < dac2.Count; i++)
  5149. {
  5150. Grp_DayAndCost dac = dac2[i];
  5151. if (dac == null) continue;
  5152. builder.MoveToCell(1, i, 0, 0);
  5153. builder.Write("第" + dac.Days.ToString() + "天:");
  5154. builder.MoveToCell(1, i, 1, 0);
  5155. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  5156. builder.MoveToCell(1, i, 2, 0);
  5157. builder.Write("费用标准:");
  5158. string curr = "";
  5159. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  5160. if (currData != null)
  5161. {
  5162. curr = currData.Name;
  5163. }
  5164. builder.MoveToCell(1, i, 3, 0);
  5165. builder.Write(dac.Cost.ToString("#0.00") + curr);
  5166. builder.MoveToCell(1, i, 4, 0);
  5167. builder.Write("费用小计:");
  5168. builder.MoveToCell(1, i, 5, 0);
  5169. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  5170. }
  5171. //删除多余行
  5172. while (table2.Rows.Count > dac2.Count)
  5173. {
  5174. table2.Rows.RemoveAt(dac2.Count);
  5175. }
  5176. Aspose.Words.Tables.Table table3 = allTables[2] as Aspose.Words.Tables.Table;
  5177. for (int i = 0; i < dac3.Count; i++)
  5178. {
  5179. Grp_DayAndCost dac = dac3[i];
  5180. if (dac == null) continue;
  5181. builder.MoveToCell(2, i, 0, 0);
  5182. builder.Write("第" + dac.Days.ToString() + "天:");
  5183. builder.MoveToCell(2, i, 1, 0);
  5184. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  5185. builder.MoveToCell(2, i, 2, 0);
  5186. builder.Write("费用标准:");
  5187. string curr = "";
  5188. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  5189. if (currData != null)
  5190. {
  5191. curr = currData.Name;
  5192. }
  5193. builder.MoveToCell(2, i, 3, 0);
  5194. builder.Write(dac.Cost.ToString("#0.00") + curr);
  5195. builder.MoveToCell(2, i, 4, 0);
  5196. builder.Write("费用小计:");
  5197. builder.MoveToCell(2, i, 5, 0);
  5198. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  5199. }
  5200. //删除多余行
  5201. while (table3.Rows.Count > dac3.Count)
  5202. {
  5203. table3.Rows.RemoveAt(dac3.Count);
  5204. }
  5205. #endregion
  5206. //文件名
  5207. //string strFileName = $"{_DelegationInfo.TeamName}出入境费用{Guid.NewGuid().ToString()}.{fileFormat}";
  5208. //string strFileName = $"{_DelegationInfo.TeamName}-出入境费用{Guid.NewGuid().ToString()}.{fileFormat}";
  5209. string strFileName = $"{_DelegationInfo.TeamName}{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.{fileFormat}";
  5210. AsposeHelper.removewatermark_v2180();
  5211. //doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  5212. var saveFormat = Aspose.Words.SaveFormat.Docx;
  5213. if (fileFormat.Equals("pdf"))
  5214. {
  5215. //doc.LayoutOptions.IsShowComments = false;
  5216. doc.LayoutOptions.IsShowHiddenText = false;
  5217. doc.LayoutOptions.IsShowParagraphMarks = false;
  5218. doc.LayoutOptions.RevisionOptions.DeletedTextEffect = RevisionTextEffect.None;
  5219. doc.AcceptAllRevisions();
  5220. Aspose.Words.Saving.PdfSaveOptions options = new Aspose.Words.Saving.PdfSaveOptions();
  5221. options.Compliance = PdfCompliance.PdfA1a;
  5222. options.CreateNoteHyperlinks = true;
  5223. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName, options);
  5224. //_view.Data = new { Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName };
  5225. _view.Data = new { Url = strFileName };
  5226. _view.Msg = "成功";
  5227. return _view;
  5228. }
  5229. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName, saveFormat);
  5230. _view.Data = new { Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName };
  5231. _view.Msg = "成功";
  5232. return _view;
  5233. }
  5234. else if (dto.SubTypeId == 1006)//1006(因公出国(境)经费测算明细表)
  5235. {
  5236. //获取模板
  5237. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/因公出国(境)经费测算明细表.docx");
  5238. //载入模板
  5239. Document doc = new Document(tempPath);
  5240. DocumentBuilder builder = new DocumentBuilder(doc);
  5241. Dictionary<string, string> dic = new Dictionary<string, string>();
  5242. if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  5243. {
  5244. List<string> list = new List<string>();
  5245. try
  5246. {
  5247. var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  5248. foreach (var item in spilitArr)
  5249. {
  5250. var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  5251. var depCode = spDotandEmpty[2].Substring(0, 3);
  5252. var arrCode = spDotandEmpty[2].Substring(3, 3);
  5253. string depName = threeCodes.Find(it => it.Three.Equals(depCode)).City,
  5254. arrName = threeCodes.Find(it => it.Three.Equals(arrCode)).City;
  5255. list.Add(depName);
  5256. list.Add(arrName);
  5257. }
  5258. list = list.Distinct().ToList();
  5259. dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  5260. }
  5261. catch (Exception)
  5262. {
  5263. dic.Add("ReturnCode", "行程录入不正确!");
  5264. }
  5265. }
  5266. else
  5267. {
  5268. dic.Add("ReturnCode", "未录入行程!");
  5269. }
  5270. dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  5271. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  5272. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  5273. if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  5274. {
  5275. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  5276. dic.Add("Day", sp.Days.ToString());
  5277. }
  5278. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  5279. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  5280. //var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  5281. //dic.Add("Names", Names);
  5282. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  5283. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  5284. decimal dac1totalPrice = 0.00M;
  5285. int accommodationStartIndex = 6, foodandotherStartIndex = 22;
  5286. foreach (var dac in dac1)
  5287. {
  5288. if (dac.SubTotal == 0.00M)
  5289. {
  5290. continue;
  5291. }
  5292. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  5293. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  5294. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  5295. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  5296. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  5297. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  5298. builder.Write(currency);//币种
  5299. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  5300. builder.Write(dac.Cost.ToString("#0.00"));//标准
  5301. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  5302. builder.Write("");//人数
  5303. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  5304. builder.Write("");//天数
  5305. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  5306. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  5307. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  5308. decimal rate = 0.00M;
  5309. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  5310. builder.Write(rate.ToString("#0.0000"));//汇率
  5311. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  5312. decimal rbmPrice = dac.SubTotal;
  5313. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  5314. accommodationStartIndex++;
  5315. dac1totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  5316. }
  5317. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  5318. for (int i = 21; i > (dac1.Count == 0 ? 1 : dac1.Count) + 6; i--)
  5319. {
  5320. table1.Rows.RemoveAt(i - 1);
  5321. foodandotherStartIndex--;
  5322. }
  5323. if (dac2.Count == dac3.Count)//国家 币种 金额
  5324. {
  5325. for (int i = 0; i < dac2.Count; i++)
  5326. {
  5327. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  5328. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  5329. }
  5330. }
  5331. decimal dac2totalPrice = 0.00M;
  5332. foreach (var dac in dac2)
  5333. {
  5334. if (dac.SubTotal == 0)
  5335. {
  5336. continue;
  5337. }
  5338. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  5339. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  5340. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  5341. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  5342. builder.Write(currency);//币种
  5343. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  5344. builder.Write(dac.Cost.ToString("#0.00"));//标准
  5345. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  5346. builder.Write("");//人数
  5347. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  5348. builder.Write("");//天数
  5349. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  5350. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  5351. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  5352. decimal rate = 0.00M;
  5353. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  5354. builder.Write(rate.ToString("#0.0000"));//汇率
  5355. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  5356. decimal rbmPrice = dac.SubTotal;
  5357. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  5358. foodandotherStartIndex++;
  5359. dac2totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  5360. }
  5361. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  5362. for (int i = foodandotherStartIndex + (15 - dac2.Count); i > (dac2.Count == 0 ? 1 : 0) + foodandotherStartIndex; i--)
  5363. {
  5364. table1.Rows.RemoveAt(i - 1);
  5365. }
  5366. //dic.Add("CityTranffic", enterExitCosts.CityTranffic.ToString("#0.00"));
  5367. string otherFeeStr = "";
  5368. if (enterExitCosts.Visa > 0) otherFeeStr += $"签证费: {enterExitCosts.Visa.ToString("#0.00")} 元,";
  5369. if (enterExitCosts.Safe > 0) otherFeeStr += $"保险费: {enterExitCosts.Safe.ToString("#0.00")} 元,";
  5370. if (enterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费: {enterExitCosts.Ticket.ToString("#0.00")} 元,";
  5371. if (otherFeeStr.Length > 0)
  5372. {
  5373. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  5374. otherFeeStr = $"({otherFeeStr})";
  5375. dic.Add("OtherFeeStr", otherFeeStr);
  5376. }
  5377. //总计
  5378. decimal allPrice = dac1totalPrice + dac2totalPrice + enterExitCosts.Visa + enterExitCosts.Safe + enterExitCosts.Ticket;
  5379. //国际旅费
  5380. string outsideJJ = "";
  5381. string allPriceJJ = "";
  5382. if (enterExitCosts.SumJJC == 1)
  5383. {
  5384. outsideJJ = string.Format(@"经济舱:{0} 元/人", enterExitCosts.AirJJ.ToString("#0.00"));
  5385. allPriceJJ = string.Format(@"经济舱:{0} 元/人", (allPrice + enterExitCosts.OutsideJJPay).ToString("#0.00"));
  5386. }
  5387. string outsideGW = "";
  5388. string allPriceGW = "";
  5389. if (enterExitCosts.SumGWC == 1)
  5390. {
  5391. outsideGW = string.Format(@"公务舱:{0} 元/人", enterExitCosts.AirGW.ToString("#0.00"));
  5392. allPriceGW = string.Format(@"公务舱:{0} 元/人", (allPrice + enterExitCosts.OutsideGWPay).ToString("#0.00"));
  5393. }
  5394. if (enterExitCosts.SumJJC == 1 || enterExitCosts.SumGWC == 1)
  5395. {
  5396. string InTravelPriceStr = string.Format(@" ({0} {1})", outsideJJ, outsideGW);
  5397. dic.Add("InTravelPrice", InTravelPriceStr);
  5398. string FinalSumPriceStr = string.Format(@" ({0} {1})", allPriceJJ, allPriceGW);
  5399. dic.Add("FinalSumPrice", FinalSumPriceStr);
  5400. }
  5401. //dic.Add("VisaPay", enterExitCosts.Visa.ToString("#0.00"));
  5402. //dic.Add("SafePay", enterExitCosts.Safe.ToString("#0.00"));
  5403. //dic.Add("YiMiao", enterExitCosts.YiMiao.ToString("#0.00"));
  5404. foreach (var key in dic.Keys)
  5405. {
  5406. builder.MoveToBookmark(key);
  5407. builder.Write(dic[key]);
  5408. }
  5409. //模板文件名
  5410. string strFileName = $"{_DelegationInfo.TeamName}因公出国(境)经费测算明细表.docx";
  5411. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  5412. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  5413. _view.Data = new { Url = url };
  5414. _view.Msg = "成功";
  5415. return _view;
  5416. }
  5417. else if (dto.SubTypeId == 1007) //1007(四川省商务厅出国经费财政先行审核表)
  5418. {
  5419. //获取模板
  5420. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/四川省商务厅出国经费财政先行审核表.xls");
  5421. //载入模板
  5422. WorkbookDesigner designer = new WorkbookDesigner();
  5423. designer.Workbook = new Aspose.Cells.Workbook(tempPath);
  5424. Dictionary<string, string> dic = new Dictionary<string, string>();
  5425. if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  5426. {
  5427. List<string> list = new List<string>();
  5428. try
  5429. {
  5430. var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  5431. foreach (var item in spilitArr)
  5432. {
  5433. var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  5434. var depCode = spDotandEmpty[2].Substring(0, 3);
  5435. var arrCode = spDotandEmpty[2].Substring(3, 3);
  5436. string depName = threeCodes.Find(it => it.Three.Equals(depCode))?.City ?? "Unknwon",
  5437. arrName = threeCodes.Find(it => it.Three.Equals(arrCode))?.City ?? "Unknown";
  5438. list.Add(depName);
  5439. list.Add(arrName);
  5440. }
  5441. list = list.Distinct().ToList();
  5442. dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  5443. }
  5444. catch (Exception)
  5445. {
  5446. dic.Add("ReturnCode", "行程录入不正确!");
  5447. }
  5448. }
  5449. else
  5450. {
  5451. dic.Add("ReturnCode", "未录入行程!");
  5452. }
  5453. dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  5454. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  5455. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  5456. if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  5457. {
  5458. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  5459. dic.Add("Day", sp.Days.ToString());
  5460. }
  5461. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  5462. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  5463. var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  5464. designer.SetDataSource("ClientUnit", _DelegationInfo.ClientUnit);
  5465. designer.SetDataSource("VisitCountry", _DelegationInfo.VisitCountry);
  5466. designer.SetDataSource("Group", _DelegationInfo.TeamName);
  5467. designer.SetDataSource("ClientUnitTitle", _DelegationInfo.TeamName);
  5468. designer.SetDataSource("Name", Names);
  5469. designer.SetDataSource("VisitStartDate", dic["VisitStartDate"] + "-" + dic["VisitEndDate"]);
  5470. designer.SetDataSource("Day", dic["Day"] + "天");
  5471. designer.SetDataSource("ReturnCode", dic["ReturnCode"]);
  5472. designer.SetDataSource("ReturnCodeAir", dic["ReturnCodeAir"]);
  5473. int startIndex = 10;
  5474. const int startIndexcopy = 10;
  5475. if (dac2.Count == dac3.Count)//国家 币种 金额
  5476. {
  5477. for (int i = 0; i < dac2.Count; i++)
  5478. {
  5479. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  5480. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  5481. }
  5482. }
  5483. DataTable dtdac1 = new DataTable();
  5484. List<string> place = new List<string>();
  5485. dtdac1.Columns.AddRange(new DataColumn[] {
  5486. new DataColumn(){ ColumnName = "city"},
  5487. new DataColumn(){ ColumnName = "curr"},
  5488. new DataColumn(){ ColumnName = "criterion"},
  5489. new DataColumn(){ ColumnName = "number",DataType = typeof(int)},
  5490. new DataColumn(){ ColumnName = "day",DataType = typeof(int)},
  5491. new DataColumn(){ ColumnName = "cost", DataType = typeof(decimal)},
  5492. new DataColumn(){ ColumnName = "rate", DataType = typeof(decimal) },
  5493. new DataColumn(){ ColumnName = "costRMB", DataType = typeof(decimal) },
  5494. });
  5495. DataTable dtdac2 = new DataTable();
  5496. dtdac2.Columns.AddRange(new DataColumn[] {
  5497. new DataColumn(){ ColumnName = "city"},
  5498. new DataColumn(){ ColumnName = "curr"},
  5499. new DataColumn(){ ColumnName = "criterion"},
  5500. new DataColumn(){ ColumnName = "number",DataType = typeof(int)},
  5501. new DataColumn(){ ColumnName = "day",DataType = typeof(int)},
  5502. new DataColumn(){ ColumnName = "cost", DataType = typeof(decimal)},
  5503. new DataColumn(){ ColumnName = "rate", DataType = typeof(decimal) },
  5504. new DataColumn(){ ColumnName = "costRMB",DataType = typeof(decimal)},
  5505. });
  5506. dtdac1.TableName = "tb1";
  5507. dtdac2.TableName = "tb2";
  5508. decimal dac1totalPrice = 0.00M, dac2totalPrice = 0.00M;
  5509. foreach (var item in dac1)
  5510. {
  5511. item.Place = GetEnterExitCostExportCity(placeData, item.NationalTravelFeeId);
  5512. if (place.Contains(item.Place))
  5513. {
  5514. continue;
  5515. }
  5516. DataRow row = dtdac1.NewRow();
  5517. row["city"] = item.Place;
  5518. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  5519. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  5520. row["curr"] = currency;
  5521. row["rate"] = rate.ToString("#0.0000");
  5522. row["criterion"] = item.Cost.ToString("#0.00");
  5523. row["number"] = 1;
  5524. row["day"] = dac1.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  5525. //row["costRMB"] = rbmPrice;
  5526. dtdac1.Rows.Add(row);
  5527. place.Add(item.Place);
  5528. }
  5529. place = new List<string>();
  5530. foreach (var item in dac2)
  5531. {
  5532. item.Place = GetEnterExitCostExportCity(placeData, item.NationalTravelFeeId);
  5533. if (place.Contains(item.Place))
  5534. {
  5535. continue;
  5536. }
  5537. DataRow row = dtdac2.NewRow();
  5538. row["city"] = item.Place;
  5539. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  5540. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  5541. row["curr"] = currency;
  5542. row["rate"] = rate.ToString("#0.0000");
  5543. row["criterion"] = item.Cost.ToString("#0.00");
  5544. row["number"] = 1;
  5545. row["day"] = dac2.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  5546. //row["cost"] = item.SubTotal;
  5547. //row["costRMB"] = rbmPrice;
  5548. dtdac2.Rows.Add(row);
  5549. place.Add(item.Place);
  5550. //dac2totalPrice += rbmPrice;
  5551. }
  5552. dac1totalPrice = dac1.Sum(it => it.SubTotal);
  5553. dac2totalPrice = dac2.Sum(it => it.SubTotal);
  5554. designer.SetDataSource("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  5555. designer.SetDataSource("dac2totalPrice", dac2totalPrice);
  5556. //designer.SetDataSource("cityTranffic", @$"其中:国外城市间机票费: {enterExitCosts.CityTranffic.ToString("#0.00")} 元");
  5557. //designer.SetDataSource("sumCityTranffic", @$"{enterExitCosts.CityTranffic.ToString("#0.00")} ");
  5558. string cell4Str = $" 4.国际旅费:经济舱:{enterExitCosts.AirJJ.ToString("#0.00")} 元/人,公务舱:{enterExitCosts.AirGW.ToString("#0.00")} 元/人";
  5559. string cellStr = $" 5.其他费用(";
  5560. if (enterExitCosts.Visa > 0) cellStr += $"签证费:{enterExitCosts.Visa.ToString("#0.00")}元,";
  5561. if (enterExitCosts.YiMiao > 0) cellStr += $"疫苗费:{enterExitCosts.YiMiao.ToString("#0.00")}元,";
  5562. if (enterExitCosts.HeSuan > 0) cellStr += $"核酸费:{enterExitCosts.HeSuan.ToString("#0.00")}元,";
  5563. if (enterExitCosts.Safe > 0) cellStr += $"保险费:{enterExitCosts.Safe.ToString("#0.00")}元,";
  5564. if (enterExitCosts.Ticket > 0) cellStr += $"参展门票费:{enterExitCosts.Ticket.ToString("#0.00")}元,";
  5565. if (enterExitCosts.Service > 0) cellStr += $"服务费:{enterExitCosts.Service.ToString("#0.00")}元,";
  5566. if (cellStr.Length > 8)
  5567. {
  5568. cellStr = cellStr.Substring(0, cellStr.Length - 1);
  5569. }
  5570. cellStr += ")";
  5571. decimal otherFee = enterExitCosts.Visa + enterExitCosts.YiMiao + enterExitCosts.HeSuan + enterExitCosts.Safe + enterExitCosts.Ticket + enterExitCosts.Service;
  5572. decimal s = dac1totalPrice + dac2totalPrice + enterExitCosts.OutsideJJPay + enterExitCosts.OutsideGWPay + otherFee;
  5573. decimal pxFee = dac4.Sum(it => it.Cost);
  5574. decimal glvFee = enterExitCosts.OutsideJJPay + enterExitCosts.OutsideGWPay;
  5575. string celllastStr1 = "";
  5576. if (dac1totalPrice > 0) celllastStr1 += $"住宿费 {dac1totalPrice.ToString("#0.00")} 元";
  5577. if (dac2totalPrice > 0) celllastStr1 += $",伙食费和公杂费 {dac2totalPrice.ToString("#0.00")} 元";
  5578. if (pxFee > 0) celllastStr1 += $",培训费 {pxFee.ToString("#0.00")} 元";
  5579. celllastStr1 += $",国际旅费 元";
  5580. if (otherFee > 0) celllastStr1 += $",其他费用 {otherFee.ToString("#0.00")} 元";
  5581. string celllastStr = $" 经审核,{celllastStr1},本次出国经费预算合计为 元。其中:市本级安排 。";
  5582. designer.SetDataSource("cell4Str", cell4Str);
  5583. designer.SetDataSource("cellStr", cellStr);
  5584. designer.SetDataSource("cellSum", (enterExitCosts.Visa + enterExitCosts.Safe).ToString("#0.00"));
  5585. designer.SetDataSource("cellSum4", (enterExitCosts.OutsideJJPay + enterExitCosts.OutsideGWPay).ToString("#0.00"));
  5586. designer.SetDataSource("celllastStr", celllastStr);
  5587. Aspose.Cells.Workbook wb = designer.Workbook;
  5588. var sheet = wb.Worksheets[0];
  5589. //绑定datatable数据集
  5590. designer.SetDataSource(dtdac1);
  5591. designer.SetDataSource(dtdac2);
  5592. designer.Process();
  5593. var rowStart = dtdac1.Rows.Count;
  5594. while (rowStart > 0)
  5595. {
  5596. sheet.Cells[startIndex, 8].Formula = $"=G{startIndex + 1} * H{startIndex + 1}";
  5597. sheet.Cells[startIndex, 6].Formula = $"=E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  5598. startIndex++;
  5599. rowStart--;
  5600. }
  5601. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + 1}: I{startIndex})";
  5602. startIndex += 1; //总计行
  5603. rowStart = dtdac2.Rows.Count;
  5604. while (rowStart > 0)
  5605. {
  5606. sheet.Cells[startIndex, 8].Formula = $"= G{startIndex + 1} * H{startIndex + 1}";
  5607. sheet.Cells[startIndex, 6].Formula = $"= E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  5608. startIndex++;
  5609. rowStart--;
  5610. }
  5611. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + dtdac1.Rows.Count + 2}: I{startIndex})";
  5612. wb.CalculateFormula(true);
  5613. //模板文件名
  5614. string strFileName = $"{_DelegationInfo.TeamName}-四川省商务厅出国经费财政先行审核表{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls"; ;//$".xls";
  5615. designer.Workbook.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  5616. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  5617. _view.Data = new { Url = url };
  5618. _view.Msg = "成功";
  5619. return _view;
  5620. }
  5621. else if (dto.SubTypeId == 1066) //成都市因公临时出国任务和预算审批意见表(外专培训团专用)
  5622. {
  5623. //获取模板
  5624. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/成都市因公临时出国任务和预算审批意见表.docx");
  5625. //载入模板
  5626. Document doc = new Document(tempPath);
  5627. DocumentBuilder builder = new DocumentBuilder(doc);
  5628. Dictionary<string, string> dic = new Dictionary<string, string>();
  5629. dic.Add("GroupName", _DelegationInfo.TeamName);
  5630. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  5631. string missionLeader = ""; //团负责人默认接团客户名单第一个人
  5632. string missionLeaderJob = "";//负责人job
  5633. //int groupNumber = 0; //团人数
  5634. if (DeleClientList.Count > 0)
  5635. {
  5636. missionLeader = DeleClientList[0]?.Name ?? "";
  5637. missionLeaderJob = DeleClientList[0]?.Job ?? "";
  5638. }
  5639. dic.Add("MissionLeader", missionLeader); //团负责人
  5640. dic.Add("MissionLeaderJob", missionLeaderJob); //团负责人job
  5641. dic.Add("GroupNumber", _DelegationInfo.VisitPNumber.ToString()); //团人数
  5642. #region MyRegion
  5643. //if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  5644. //{
  5645. // List<string> list = new List<string>();
  5646. // try
  5647. // {
  5648. // var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  5649. // foreach (var item in spilitArr)
  5650. // {
  5651. // var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  5652. // var depCode = spDotandEmpty[2].Substring(0, 3);
  5653. // var arrCode = spDotandEmpty[2].Substring(3, 3);
  5654. // string depName = threeCodes.Find(it => it.Three.Equals(depCode)).City,
  5655. // arrName = threeCodes.Find(it => it.Three.Equals(arrCode)).City;
  5656. // list.Add(depName);
  5657. // list.Add(arrName);
  5658. // }
  5659. // list = list.Distinct().ToList();
  5660. // dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  5661. // }
  5662. // catch (Exception)
  5663. // {
  5664. // dic.Add("ReturnCode", "行程录入不正确!");
  5665. // }
  5666. //}
  5667. //else
  5668. //{
  5669. // dic.Add("ReturnCode", "未录入行程!");
  5670. //}
  5671. List<string> countrys = _dirRep.GroupSplitCountry(_DelegationInfo.VisitCountry);
  5672. dic.Add("ReturnCode", string.Join("、", countrys));
  5673. #endregion
  5674. //dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  5675. //dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  5676. //dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  5677. //if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  5678. //{
  5679. // TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  5680. // dic.Add("Day", sp.Days.ToString());
  5681. //}
  5682. dic.Add("Day", _DelegationInfo.VisitDays.ToString());
  5683. dic.Add("CultivateDay", dac4.Count.ToString()); //培训天数
  5684. // dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  5685. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  5686. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  5687. //培训人员名单
  5688. int cultivateRowIndex = 7;
  5689. foreach (var item in DeleClientList)
  5690. {
  5691. builder.MoveToCell(0, cultivateRowIndex, 0, 0);
  5692. builder.Write(item.Name);
  5693. builder.MoveToCell(0, cultivateRowIndex, 1, 0);
  5694. builder.Write(item.Sex == 0 ? "男" : item.Sex == 1 ? "女" : "");
  5695. builder.MoveToCell(0, cultivateRowIndex, 2, 0);
  5696. string birthDay = "";
  5697. if (item.Birthday != null)
  5698. {
  5699. DateTime dt = Convert.ToDateTime(item.Birthday);
  5700. birthDay = $"{dt.Year}.{dt.Month}";
  5701. }
  5702. builder.Write(birthDay);
  5703. builder.MoveToCell(0, cultivateRowIndex, 3, 0);
  5704. builder.Write(item.Company);
  5705. builder.MoveToCell(0, cultivateRowIndex, 4, 0);
  5706. builder.Write(item.Job);
  5707. cultivateRowIndex++;
  5708. }
  5709. //删除多余行
  5710. //cultivateRowIndex -= 2;
  5711. int delRows = 10 + 7 - cultivateRowIndex;
  5712. if (delRows > 0)
  5713. {
  5714. for (int i = 0; i < delRows; i++)
  5715. {
  5716. table1.Rows.RemoveAt(cultivateRowIndex);
  5717. //cultivateRowIndex++;
  5718. }
  5719. }
  5720. decimal hotelFeeTotal = dac1.Sum(it => it.SubTotal);//住宿费
  5721. dic.Add("HotelFeeTotal", hotelFeeTotal.ToString("#0.00"));
  5722. decimal mealsFeeTotal = dac2.Sum(it => it.SubTotal);//伙食费
  5723. dic.Add("MealsFeeTotal", mealsFeeTotal.ToString("#0.00"));
  5724. decimal miscellaneousFeeTotal = dac3.Sum(it => it.SubTotal);//公杂费
  5725. dic.Add("MiscellaneousFeeTotal", miscellaneousFeeTotal.ToString("#0.00"));
  5726. decimal trainingFeeTotal = dac4.Sum(it => it.SubTotal);//培训费
  5727. dic.Add("TrainingFeeTotal", trainingFeeTotal.ToString("#0.00"));
  5728. decimal cityTranfficFeeToatal = 0.00M;
  5729. //decimal cityTranfficFeeToatal = enterExitCosts.CityTranffic; //城市区间交通费
  5730. //dic.Add("CityTranfficFeeToatal", cityTranfficFeeToatal.ToString("#0.00"));//
  5731. //其他费用
  5732. decimal otherFeeTotal = enterExitCosts.Visa + enterExitCosts.Safe + enterExitCosts.Ticket + enterExitCosts.YiMiao + enterExitCosts.HeSuan + enterExitCosts.Service;
  5733. dic.Add("OtherFeeTotal", otherFeeTotal.ToString("#0.00"));
  5734. //其他费用合计
  5735. decimal _otherFeeTotal = hotelFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + trainingFeeTotal + cityTranfficFeeToatal + otherFeeTotal;
  5736. decimal _jjcFeeToatal = enterExitCosts.AirJJ + _otherFeeTotal; //经济舱
  5737. decimal _gwcFeeToatal = enterExitCosts.AirGW + _otherFeeTotal; //公务舱
  5738. //公务舱合计
  5739. //国际旅费
  5740. //string outsideJJ = "";
  5741. //string allPriceJJ = "";
  5742. if (enterExitCosts.SumJJC == 1 && enterExitCosts.SumGWC == 0)
  5743. {
  5744. dic.Add("AirFeeTotal", enterExitCosts.AirJJ.ToString("#0.00"));
  5745. dic.Add("FeeTotal", _jjcFeeToatal.ToString("#0.00"));
  5746. }
  5747. if (enterExitCosts.SumGWC == 1 && enterExitCosts.SumJJC == 0)
  5748. {
  5749. dic.Add("AirFeeTotal", enterExitCosts.AirGW.ToString("#0.00"));
  5750. dic.Add("FeeTotal", _gwcFeeToatal.ToString("#0.00"));
  5751. }
  5752. if (enterExitCosts.SumJJC == 1 && enterExitCosts.SumGWC == 1)
  5753. {
  5754. string airFeeTotalStr = string.Format(@$"经济舱:{enterExitCosts.AirJJ.ToString("#0.00")} 公务舱:{enterExitCosts.AirGW.ToString("#0.00")}");
  5755. dic.Add("AirFeeTotal", airFeeTotalStr);
  5756. string feeTotalStr = string.Format(@$"经济舱:{_jjcFeeToatal.ToString("#0.00")} 公务舱:{_gwcFeeToatal.ToString("#0.00")}");
  5757. dic.Add("FeeTotal", feeTotalStr);
  5758. }
  5759. foreach (var key in dic.Keys)
  5760. {
  5761. builder.MoveToBookmark(key);
  5762. builder.Write(dic[key]);
  5763. }
  5764. //模板文件名
  5765. string strFileName = $"{_DelegationInfo.TeamName}-成都市因公临时出国任务和预算审批意见表(外专培训团专用).docx";
  5766. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  5767. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  5768. _view.Data = new { Url = url };
  5769. _view.Msg = "成功";
  5770. return _view;
  5771. }
  5772. }
  5773. else if (dto.ExportType == 2) //表格
  5774. {
  5775. //利用键值对存放数据
  5776. Dictionary<string, string> dic = new Dictionary<string, string>();
  5777. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  5778. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  5779. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  5780. dic.Add("Day", sp.Days.ToString());
  5781. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  5782. if (dto.SubTypeId == 1008) //1008(派员单位出(境)任务和预算审批意见表)
  5783. {
  5784. //获取模板
  5785. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/派员单位出(境)任务和预算审批意见表.docx");
  5786. //载入模板
  5787. Document doc = new Document(tempPath);
  5788. DocumentBuilder builder = new DocumentBuilder(doc);
  5789. dic.Add("TeamName", _DelegationInfo.TeamName);
  5790. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  5791. //dic.Add("TellPhone", _DelegationInfo.TellPhone);
  5792. string missionLeaderName = "",
  5793. missionLeaderJob = "";
  5794. if (DeleClientList.Count > 0)
  5795. {
  5796. missionLeaderName = DeleClientList[0].Name;
  5797. missionLeaderJob = DeleClientList[0].Job;
  5798. }
  5799. dic.Add("MissionLeaderName", missionLeaderName);
  5800. dic.Add("MissionLeaderJob", missionLeaderJob);
  5801. dic.Add("VisitPNumber", _DelegationInfo.VisitPNumber.ToString());
  5802. dic.Add("VisitPurpose", _DelegationInfo.VisitPurpose);
  5803. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  5804. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  5805. int rowCount = 10;//总人数行
  5806. int startRowIndex = 7; //起始行
  5807. for (int i = 0; i < DeleClientList.Count; i++)
  5808. {
  5809. builder.MoveToCell(0, startRowIndex, 0, 0);
  5810. builder.Write(DeleClientList[i].Name); //出国人员姓名
  5811. builder.MoveToCell(0, startRowIndex, 1, 0);
  5812. string sex = DeleClientList[i].Sex == 0 ? "男" : DeleClientList[i].Sex == 1 ? "女" : "";
  5813. builder.Write(sex);//性别
  5814. builder.MoveToCell(0, startRowIndex, 2, 0);
  5815. builder.Write(Convert.ToDateTime(DeleClientList[i].Birthday).ToString("yyyy年MM月dd日"));//出生年月
  5816. builder.MoveToCell(0, startRowIndex, 3, 0);
  5817. builder.Write(DeleClientList[i].Company);//工作单位
  5818. builder.MoveToCell(0, startRowIndex, 4, 0);
  5819. builder.Write(DeleClientList[i].Job);//职务及级别
  5820. builder.MoveToCell(0, startRowIndex, 5, 0);
  5821. builder.Write("");//人员属性
  5822. builder.MoveToCell(0, startRowIndex, 6, 0);
  5823. builder.Write("");//上次出国时间
  5824. startRowIndex++;
  5825. }
  5826. int nullRow = rowCount - DeleClientList.Count;//空行
  5827. for (int i = 0; i < nullRow; i++)
  5828. {
  5829. table1.Rows.Remove(table1.Rows[startRowIndex]);
  5830. }
  5831. foreach (var key in dic.Keys)
  5832. {
  5833. builder.MoveToBookmark(key);
  5834. builder.Write(dic[key]);
  5835. }
  5836. //模板文件名
  5837. string strFileName = $"派员单位出(境)任务和预算审批意见表.docx";
  5838. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  5839. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  5840. _view.Data = new { Url = url };
  5841. _view.Msg = "成功";
  5842. return _view;
  5843. }
  5844. else if (dto.SubTypeId == 1009)//1009(省级单位出(境)经费报销单)
  5845. {
  5846. //获取模板
  5847. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/省级单位出(境)经费报销单.docx");
  5848. //载入模板
  5849. Document doc = new Document(tempPath);
  5850. DocumentBuilder builder = new DocumentBuilder(doc);
  5851. dic.Add("GroupClient", _DelegationInfo.ClientUnit);
  5852. var Names = string.Join("、", DeleClientList.Select(x => x.Name)).TrimEnd('、');
  5853. dic.Add("Names", Names);
  5854. int accommodationRows = 12, foodandotherRows = 12;
  5855. var Dac1currCn = dac1.GroupBy(x => x.Currency).Select(x => x.Key).ToList();
  5856. var Dac2currCn = dac2.GroupBy(x => x.Currency).Select(x => x.Key).ToList();
  5857. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  5858. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  5859. int accommodationStartIndex = 6;
  5860. decimal dac1totalPrice = 0.00M;
  5861. foreach (var dac in dac1)
  5862. {
  5863. if (dac.SubTotal == 0)
  5864. {
  5865. continue;
  5866. }
  5867. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  5868. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  5869. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  5870. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));//城市
  5871. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  5872. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknwon";
  5873. builder.Write(currency);//币种
  5874. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  5875. builder.Write(dac.Cost.ToString("#0.00"));//标准
  5876. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  5877. builder.Write("");//人数
  5878. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  5879. builder.Write("");//天数
  5880. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  5881. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  5882. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  5883. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  5884. builder.Write(rate.ToString("#0.0000"));//汇率
  5885. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  5886. decimal rbmPrice = rate * dac.SubTotal;
  5887. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  5888. accommodationStartIndex++;
  5889. dac1totalPrice += rbmPrice;
  5890. }
  5891. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  5892. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  5893. builder.Write("小计");
  5894. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  5895. builder.Write(dac1totalPrice.ToString("#0.00"));
  5896. accommodationStartIndex++;
  5897. int nullRow = accommodationRows - dac1.Count;
  5898. //删除空行
  5899. //if (nullRow > 0)
  5900. //{
  5901. // int rowIndex = accommodationStartIndex;
  5902. // for (int i = 0; i < nullRow; i++)
  5903. // {
  5904. // Row row = table1.Rows[rowIndex];
  5905. // row.Remove();
  5906. // rowIndex++;
  5907. // }
  5908. //}
  5909. if (dac2.Count == dac3.Count)//国家 币种 金额
  5910. {
  5911. for (int i = 0; i < dac2.Count; i++)
  5912. {
  5913. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  5914. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  5915. }
  5916. }
  5917. int foodandotherStartIndex = 19;//
  5918. decimal dac2totalPrice = 0.00M;
  5919. foreach (var dac in dac2)
  5920. {
  5921. if (dac.SubTotal == 0)
  5922. {
  5923. continue;
  5924. }
  5925. //foodandotherStartIndex = 12;
  5926. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  5927. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));//城市
  5928. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  5929. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknwon";
  5930. builder.Write(currency);//币种
  5931. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  5932. builder.Write(dac.Cost.ToString("#0.00"));//标准
  5933. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  5934. builder.Write("");//人数
  5935. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  5936. builder.Write("");//天数
  5937. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  5938. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  5939. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  5940. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  5941. builder.Write(rate.ToString("#0.0000"));//汇率
  5942. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  5943. decimal rbmPrice = rate * dac.SubTotal;
  5944. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  5945. foodandotherStartIndex++;
  5946. dac2totalPrice += rbmPrice;
  5947. }
  5948. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  5949. //删除空行
  5950. if (dac2.Count < foodandotherRows)
  5951. {
  5952. //int nullRow = accommodationRows - dac2.Count;
  5953. //while (table2.Rows.Count > dac2.Count)
  5954. //{
  5955. // table2.Rows.RemoveAt(dac2.Count);
  5956. //}
  5957. }
  5958. //dic.Add("CityTranffic", enterExitCosts.CityTranffic.ToString("#0.00"));
  5959. string otherFeeStr = "";
  5960. if (enterExitCosts.Visa > 0) otherFeeStr += $"签证费: {enterExitCosts.Visa.ToString("#0.00")} 元,";
  5961. if (enterExitCosts.Safe > 0) otherFeeStr += $"保险费: {enterExitCosts.Safe.ToString("#0.00")} 元,";
  5962. if (enterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费: {enterExitCosts.Ticket.ToString("#0.00")} 元,";
  5963. if (otherFeeStr.Length > 0)
  5964. {
  5965. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  5966. otherFeeStr = $"({otherFeeStr})";
  5967. dic.Add("OtherFeeStr", otherFeeStr);
  5968. }
  5969. foreach (var key in dic.Keys)
  5970. {
  5971. builder.MoveToBookmark(key);
  5972. builder.Write(dic[key]);
  5973. }
  5974. //模板文件名
  5975. string strFileName = $"省级单位出(境)经费报销单.docx";
  5976. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  5977. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  5978. _view.Data = new { Url = url };
  5979. _view.Msg = "成功";
  5980. return _view;
  5981. }
  5982. }
  5983. else if (dto.ExportType == 3)
  5984. {
  5985. if (dto.SubTypeId == 1) //团组成员名单
  5986. {
  5987. if (DeleClientList.Count < 1)
  5988. {
  5989. _view.Msg = "团组成员暂未录入!!!";
  5990. return _view;
  5991. }
  5992. //获取模板
  5993. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/dwon_团组人员列表模板.doc");
  5994. //载入模板
  5995. Document doc = new Document(tempPath);
  5996. DocumentBuilder builder = new DocumentBuilder(doc);
  5997. //获取word里所有表格
  5998. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  5999. //获取所填表格的序数
  6000. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  6001. var rowStart = tableOne.Rows[0]; //获取第1行
  6002. //循环赋值
  6003. for (int i = 0; i < DeleClientList.Count; i++)
  6004. {
  6005. builder.MoveToCell(0, i + 1, 0, 0);
  6006. builder.Write(DeleClientList[i].Name);
  6007. builder.MoveToCell(0, i + 1, 1, 0);
  6008. string sex = DeleClientList[i].Sex == 0 ? "男" : DeleClientList[i].Sex == 1 ? "女" : "";
  6009. builder.Write(sex);
  6010. builder.MoveToCell(0, i + 1, 2, 0);
  6011. builder.Write(Convert.ToDateTime(DeleClientList[i].Birthday).ToString("yyyy年MM月dd日"));
  6012. builder.MoveToCell(0, i + 1, 3, 0);
  6013. builder.Write(DeleClientList[i].Company);
  6014. builder.MoveToCell(0, i + 1, 4, 0);
  6015. builder.Write(DeleClientList[i].Job);
  6016. }
  6017. //删除多余行
  6018. while (tableOne.Rows.Count > DeleClientList.Count + 1)
  6019. {
  6020. tableOne.Rows.RemoveAt(DeleClientList.Count + 1);
  6021. }
  6022. string strFileName = $"{_DelegationInfo.TeamName}组团人员名单({DateTime.Now.ToString("yyyyMMddHHmmss")}).doc";
  6023. //C:/Server/File/OA2023/Office/Word/EnterExitCost/File/
  6024. //C:\Server\File\OA2023\Office\Word\EnterExitCost\File\
  6025. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  6026. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  6027. _view.Data = new { Url = url };
  6028. _view.Msg = "成功";
  6029. return _view;
  6030. }
  6031. }
  6032. }
  6033. catch (Exception ex)
  6034. {
  6035. _view.Code = StatusCodes.Status500InternalServerError;
  6036. _view.Msg = ex.Message;
  6037. return _view;
  6038. }
  6039. return _view;
  6040. }
  6041. #endregion
  6042. #region 机票费用提示
  6043. /// <summary>
  6044. /// 三公机票费用提示
  6045. /// </summary>
  6046. /// <param name="diId"></param>
  6047. /// <returns></returns>
  6048. public static async Task<EntryAndExitTipsView[]> EntryAndExitTips(int diId)
  6049. {
  6050. if (diId < 1) return Array.Empty<EntryAndExitTipsView>();
  6051. var airFees = await _sqlSugar.Queryable<Air_TicketBlackCode>().Where(a => a.IsDel == 0 && a.DiId == diId).ToListAsync();
  6052. if (airFees.Any())
  6053. {
  6054. var result = new List<EntryAndExitTipsView>();
  6055. foreach (var x in airFees)
  6056. {
  6057. string tripDesc = "";
  6058. if (!string.IsNullOrEmpty(x.BlackCode))
  6059. {
  6060. var redisKeyName = string.Format("AirTripDesc_{0}_{1}", x.DiId, x.Id);
  6061. tripDesc = await KIMIAirTripCodeRec(redisKeyName, x.BlackCode);
  6062. }
  6063. result.Add(new EntryAndExitTipsView
  6064. {
  6065. jjcCurrentRate = x.ECPrice,
  6066. gwcCurrentRate = x.BCPrice,
  6067. tdcCurrentRate = x.FCPrice,
  6068. remark = $"经济舱全价:{x.ECPrice.ToString("#0.00")} 元/人 公务舱全价:{x.BCPrice.ToString("#0.00")} 元/人 头等舱全价:{x.FCPrice.ToString("#0.00")} 元/人",
  6069. TripDesc = tripDesc
  6070. });
  6071. }
  6072. return result.OrderByDescending(x => x.jjcCurrentRate + x.gwcCurrentRate + x.tdcCurrentRate).ToArray();
  6073. }
  6074. return Array.Empty<EntryAndExitTipsView>();
  6075. }
  6076. /// <summary>
  6077. /// 机票行程代码识别
  6078. /// </summary>
  6079. /// <param name="redisKeyName">redis缓存名称(名称定义格式:AirTripDesc_Diid_Id)</param>
  6080. /// <param name="msg"></param>
  6081. /// <returns></returns>
  6082. public static async Task<string> KIMIAirTripCodeRec(string redisKeyName, string msg)
  6083. {
  6084. string result = string.Empty;
  6085. if (!string.IsNullOrEmpty(redisKeyName))
  6086. {
  6087. result = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>(redisKeyName);//string 取
  6088. if (!string.IsNullOrEmpty(result)) return result;
  6089. }
  6090. if (string.IsNullOrEmpty(msg)) return result;
  6091. KiMiApiClient KiMiApi = new KiMiApiClient();
  6092. var kimiMsgs = new List<SeedMessages>() {
  6093. new SeedMessages { Role = KimiRole.system, Content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一切涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。" },
  6094. new SeedMessages { Role = KimiRole.user, Content = "请将提供的三字码行程信息翻译成中文,每条信息独立一行,并在次日到达的时间后加上“+1”以表示次日。日期(星期)格式请按照“04月14日(星期一)”标注。航站楼信息请按照“T1”、“T2”、“ ”等格式标注。只输出正文数据,不要除正文数据外的任何文字以及符号。格式示例如下:\r\n1. CA445 05月17日(星期六) 成都天府 T1 - 米兰马尔彭萨 T1 01:50 06:55" },
  6095. new SeedMessages { Role = KimiRole.user, Content = msg }
  6096. };
  6097. var kimiApiResult = await KiMiApi.SeedMessage(kimiMsgs);
  6098. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  6099. result = kimiApiResult_JObject["content"].ToString();
  6100. if (!string.IsNullOrEmpty(result))
  6101. {
  6102. TimeSpan expiry = TimeSpan.FromMinutes(5); // 5分钟
  6103. await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>(redisKeyName, result, expiry);//string 存
  6104. }
  6105. return result;
  6106. }
  6107. #endregion
  6108. #endregion
  6109. #region Excel导出服务
  6110. #region 类
  6111. public class FileExportSettings
  6112. {
  6113. public string ExportBasePath { get; set; } = "wwwroot/exports";
  6114. public string DownloadBaseUrl { get; set; } = "/exports";
  6115. public int RetentionDays { get; set; } = 7;
  6116. public int MaxFileSizeMB { get; set; } = 50;
  6117. public string ExcelTemplatesPath { get; set; } = "Templates/Excel";
  6118. }
  6119. public class ExportResult
  6120. {
  6121. public bool Success { get; set; }
  6122. public string FilePath { get; set; }
  6123. public string DownloadUrl { get; set; }
  6124. public string FileName { get; set; }
  6125. public long FileSize { get; set; }
  6126. public string MimeType { get; set; } = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  6127. public string ErrorMessage { get; set; }
  6128. public DateTime GeneratedAt { get; set; } = DateTime.Now;
  6129. }
  6130. public class ExportRequest
  6131. {
  6132. public IEnumerable<object> Data { get; set; }
  6133. public string FileName { get; set; }
  6134. public string SheetName { get; set; } = "Sheet1";
  6135. public string TemplateType { get; set; } = "default";
  6136. public Dictionary<string, string> CustomHeaders { get; set; }
  6137. }
  6138. public class ExportResponse
  6139. {
  6140. public string FilePath { get; set; }
  6141. public string DownloadUrl { get; set; }
  6142. public string FileName { get; set; }
  6143. public long FileSize { get; set; }
  6144. public DateTime GeneratedAt { get; set; }
  6145. public string Message { get; set; }
  6146. }
  6147. #endregion
  6148. public static async Task<ExportResult> ExportToExcel<T>(IEnumerable<T> data, string fileName, string sheetName = "Sheet1", string templateType = "default")
  6149. {
  6150. try
  6151. {
  6152. byte[] excelBytes = templateType.ToLower() switch
  6153. {
  6154. "styled" => GenerateStyledExcel(data, sheetName),
  6155. "with_formulas" => GenerateExcelWithFormulas(data, sheetName),
  6156. //"with_charts" => GenerateExcelWithCharts(data, sheetName),
  6157. _ => GenerateDefaultExcel(data, sheetName)
  6158. };
  6159. var filePath = await SaveFileAsync(excelBytes, fileName, "excel");
  6160. var downloadUrl = $"wwwroot/exports/{filePath}";
  6161. return new ExportResult
  6162. {
  6163. Success = true,
  6164. FilePath = filePath,
  6165. DownloadUrl = downloadUrl,
  6166. FileName = Path.GetFileName(filePath),
  6167. FileSize = excelBytes.Length,
  6168. MimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
  6169. };
  6170. }
  6171. catch (Exception ex)
  6172. {
  6173. return new ExportResult
  6174. {
  6175. Success = false,
  6176. ErrorMessage = ex.Message
  6177. };
  6178. }
  6179. }
  6180. private static byte[] GenerateDefaultExcel<T>(IEnumerable<T> data, string sheetName)
  6181. {
  6182. using var workbook = new Aspose.Cells.Workbook();
  6183. var worksheet = workbook.Worksheets[0];
  6184. worksheet.Name = sheetName;
  6185. if (data != null && data.Any())
  6186. {
  6187. FillWorksheetWithData(worksheet, data, 0);
  6188. worksheet.AutoFitColumns();
  6189. }
  6190. return SaveWorkbookToBytes(workbook);
  6191. }
  6192. private static byte[] GenerateStyledExcel<T>(IEnumerable<T> data, string sheetName)
  6193. {
  6194. using var workbook = new Aspose.Cells.Workbook();
  6195. var worksheet = workbook.Worksheets[0];
  6196. worksheet.Name = sheetName;
  6197. if (data != null && data.Any())
  6198. {
  6199. FillWorksheetWithData(worksheet, data, 0);
  6200. // 设置样式
  6201. var headerStyle = workbook.CreateStyle();
  6202. headerStyle.Pattern = BackgroundType.Solid;
  6203. headerStyle.ForegroundColor = System.Drawing.Color.LightGray;
  6204. headerStyle.Font.IsBold = true;
  6205. headerStyle.HorizontalAlignment = TextAlignmentType.Center;
  6206. var properties = typeof(T).GetProperties();
  6207. Aspose.Cells.Range headerRange = worksheet.Cells.CreateRange(0, 0, 1, properties.Length);
  6208. headerRange.ApplyStyle(headerStyle, new StyleFlag { All = true });
  6209. worksheet.AutoFitColumns();
  6210. }
  6211. return SaveWorkbookToBytes(workbook);
  6212. }
  6213. private static byte[] GenerateExcelWithFormulas<T>(IEnumerable<T> data, string sheetName)
  6214. {
  6215. using var workbook = new Aspose.Cells.Workbook();
  6216. var worksheet = workbook.Worksheets[0];
  6217. worksheet.Name = sheetName;
  6218. if (data != null && data.Any())
  6219. {
  6220. FillWorksheetWithData(worksheet, data, 0);
  6221. // 添加公式(例如:求和公式)
  6222. var properties = typeof(T).GetProperties();
  6223. int lastRow = data.Count() + 1;
  6224. for (int i = 0; i < properties.Length; i++)
  6225. {
  6226. if (IsNumericType(properties[i].PropertyType))
  6227. {
  6228. worksheet.Cells[lastRow, i].Formula = $"=SUM({worksheet.Cells[1, i].Name}:{worksheet.Cells[lastRow - 1, i].Name})";
  6229. }
  6230. }
  6231. worksheet.AutoFitColumns();
  6232. }
  6233. return SaveWorkbookToBytes(workbook);
  6234. }
  6235. private static void FillWorksheetWithData<T>(Worksheet worksheet, IEnumerable<T> data, int startRow)
  6236. {
  6237. var properties = typeof(T).GetProperties();
  6238. // 设置表头
  6239. for (int i = 0; i < properties.Length; i++)
  6240. {
  6241. worksheet.Cells[startRow, i].PutValue(properties[i].Name);
  6242. }
  6243. // 填充数据
  6244. int rowIndex = startRow + 1;
  6245. foreach (var item in data)
  6246. {
  6247. for (int colIndex = 0; colIndex < properties.Length; colIndex++)
  6248. {
  6249. var value = properties[colIndex].GetValue(item);
  6250. worksheet.Cells[rowIndex, colIndex].PutValue(value);
  6251. }
  6252. rowIndex++;
  6253. }
  6254. }
  6255. private static int FindDataStartRow(Worksheet worksheet)
  6256. {
  6257. // 在实际项目中,可以根据模板中的特定标记来定位数据起始行
  6258. // 例如查找 "{{DATA_START}}" 这样的标记
  6259. for (int row = 0; row < 50; row++)
  6260. {
  6261. for (int col = 0; col < 10; col++)
  6262. {
  6263. var value = worksheet.Cells[row, col].StringValue;
  6264. if (value == "{{DATA_START}}")
  6265. {
  6266. worksheet.Cells[row, col].PutValue(""); // 清空标记
  6267. return row + 1;
  6268. }
  6269. }
  6270. }
  6271. return 1; // 默认从第2行开始
  6272. }
  6273. private static byte[] SaveWorkbookToBytes(Aspose.Cells.Workbook workbook)
  6274. {
  6275. using var stream = new MemoryStream();
  6276. workbook.Save(stream, Aspose.Cells.SaveFormat.Xlsx);
  6277. return stream.ToArray();
  6278. }
  6279. private static bool IsNumericType(Type type)
  6280. {
  6281. return Type.GetTypeCode(type) switch
  6282. {
  6283. TypeCode.Byte or TypeCode.SByte or TypeCode.UInt16 or TypeCode.UInt32 or
  6284. TypeCode.UInt64 or TypeCode.Int16 or TypeCode.Int32 or TypeCode.Int64 or
  6285. TypeCode.Decimal or TypeCode.Double or TypeCode.Single => true,
  6286. _ => false
  6287. };
  6288. }
  6289. public static async Task<string> SaveFileAsync(byte[] fileData, string fileName, string subFolder = "")
  6290. {
  6291. try
  6292. {
  6293. var basePath = "wwwroot/exports/exports";
  6294. var folderPath = Path.Combine(basePath, subFolder);
  6295. Directory.CreateDirectory(folderPath);
  6296. var uniqueFileName = $"{Path.GetFileNameWithoutExtension(fileName)}_{Guid.NewGuid():N}{Path.GetExtension(fileName)}.xlsx";
  6297. var filePath = Path.Combine(folderPath, uniqueFileName);
  6298. await System.IO.File.WriteAllBytesAsync(filePath, fileData);
  6299. var relativePath = Path.Combine(basePath, subFolder, uniqueFileName).Replace("\\", "/");
  6300. return relativePath;
  6301. }
  6302. catch (Exception ex)
  6303. {
  6304. throw;
  6305. }
  6306. }
  6307. #endregion
  6308. #region 动态构架word表格
  6309. /// <summary>
  6310. /// 设置表格样式
  6311. /// </summary>
  6312. /// <param name="builder"></param>
  6313. public static void SetupDocumentStyles(DocumentBuilder builder)
  6314. {
  6315. builder.Font.Name = "微软雅黑";
  6316. builder.Font.Size = 10;
  6317. builder.ParagraphFormat.SpaceAfter = 0;
  6318. }
  6319. /// <summary>
  6320. /// 添加标题
  6321. /// </summary>
  6322. /// <param name="builder"></param>
  6323. /// <param name="title"></param>
  6324. public static void AddTitle(DocumentBuilder builder, string title)
  6325. {
  6326. // 主标题
  6327. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  6328. builder.Font.Size = 16;
  6329. builder.Font.Bold = true;
  6330. builder.Font.Color = System.Drawing.Color.DarkBlue;
  6331. builder.Writeln(title);
  6332. // 空行
  6333. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  6334. builder.Font.Size = 10;
  6335. builder.Font.Bold = false;
  6336. builder.Font.Color = System.Drawing.Color.Black;
  6337. builder.Writeln();
  6338. }
  6339. /// <summary>
  6340. /// 生成酒机票表格信息
  6341. /// </summary>
  6342. /// <param name="builder"></param>
  6343. /// <param name="airInfos"></param>
  6344. /// <param name="footerText"></param>
  6345. public static void AddAirInfoSections(DocumentBuilder builder, List<Grp_AirTicketReservations> airInfos, string? footerText)
  6346. {
  6347. if (airInfos == null || !airInfos.Any())
  6348. {
  6349. builder.Writeln("暂无机票航班信息。");
  6350. return;
  6351. }
  6352. int airCount = 0;
  6353. const int maxAirPerPage = 3; // 每页最多显示3个酒店,确保有足够空间
  6354. for (int i = 0; i < airInfos.Count; i++)
  6355. {
  6356. var info = airInfos[i];
  6357. // 检查是否需要分页
  6358. if (airCount > 0 && airCount > maxAirPerPage)
  6359. {
  6360. builder.InsertBreak(BreakType.PageBreak);
  6361. airCount = 0;
  6362. }
  6363. airCount++;
  6364. // 为每个酒店创建详细信息表格
  6365. CreateAirDetailTable(builder, info);
  6366. // 酒店之间添加间距,但不是最后一个
  6367. if (i < airInfos.Count() - 1)
  6368. {
  6369. AddSpacingBetweenHotels(builder);
  6370. }
  6371. // 检查是否达到每页最大酒店数量
  6372. if (airCount >= maxAirPerPage && (i < airInfos.Count - 1 || i < airInfos.Count() - 1))
  6373. {
  6374. builder.InsertBreak(BreakType.PageBreak);
  6375. airCount = 0;
  6376. }
  6377. }
  6378. if (!string.IsNullOrEmpty(footerText))
  6379. {
  6380. AddFooter(builder, footerText);
  6381. }
  6382. }
  6383. /// <summary>
  6384. /// 生成酒店表格信息
  6385. /// </summary>
  6386. /// <param name="builder"></param>
  6387. /// <param name="hotelInfos"></param>
  6388. /// <param name="footerText"></param>
  6389. public static void AddHotelInfoSections(DocumentBuilder builder, List<Grp_HotelReservations> hotelInfos, string? footerText)
  6390. {
  6391. if (hotelInfos == null || !hotelInfos.Any())
  6392. {
  6393. builder.Writeln("暂无酒店信息");
  6394. return;
  6395. }
  6396. int hotelCount = 0;
  6397. const int maxHotelsPerPage = 3; // 每页最多显示3个酒店,确保有足够空间
  6398. for (int i = 0; i < hotelInfos.Count; i++)
  6399. {
  6400. var info = hotelInfos[i];
  6401. // 检查是否需要分页
  6402. if (hotelCount > 0 && hotelCount > maxHotelsPerPage)
  6403. {
  6404. builder.InsertBreak(BreakType.PageBreak);
  6405. hotelCount = 0;
  6406. }
  6407. hotelCount++;
  6408. AddCityHeader(builder, info.City);
  6409. // 为每个酒店创建详细信息表格
  6410. CreateHotelDetailTable(builder, info);
  6411. // 酒店之间添加间距,但不是最后一个
  6412. if (i < hotelInfos.Count() - 1)
  6413. {
  6414. AddSpacingBetweenHotels(builder);
  6415. }
  6416. // 检查是否达到每页最大酒店数量
  6417. if (hotelCount >= maxHotelsPerPage && (i < hotelInfos.Count - 1 || i < hotelInfos.Count() - 1))
  6418. {
  6419. builder.InsertBreak(BreakType.PageBreak);
  6420. hotelCount = 0;
  6421. }
  6422. }
  6423. if (!string.IsNullOrEmpty(footerText))
  6424. {
  6425. AddFooter(builder, footerText);
  6426. }
  6427. }
  6428. private static void AddSpacingBetweenHotels(DocumentBuilder builder)
  6429. {
  6430. builder.Writeln();
  6431. builder.InsertBreak(BreakType.LineBreak);
  6432. }
  6433. private static void AddCityHeader(DocumentBuilder builder, string cityName)
  6434. {
  6435. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  6436. builder.Font.Size = 14;
  6437. builder.Font.Bold = true;
  6438. builder.Font.Color = System.Drawing.Color.DarkGreen;
  6439. builder.Writeln($"城市:{cityName}");
  6440. builder.Font.Size = 10;
  6441. builder.Font.Bold = false;
  6442. builder.Font.Color = System.Drawing.Color.Black;
  6443. }
  6444. private static void CreateHotelDetailTable(DocumentBuilder builder, Grp_HotelReservations hotel)
  6445. {
  6446. // 设置表格不允许跨页断行,确保整个表格在一页上
  6447. Table table = builder.StartTable();
  6448. //table.AllowBreakAcrossPages = false; // 关键设置:不允许表格跨页
  6449. // 设置表格样式
  6450. ApplyTableStyle(table);
  6451. // 添加酒店基本信息行
  6452. AddTableRow(builder, "酒店名称", hotel.HotelName ?? "-", true);
  6453. AddTableRow(builder, "联系电话", hotel.HotelTel ?? "-");
  6454. AddTableRow(builder, "酒店地址", hotel.HotelAddress ?? "-");
  6455. AddTableRow(builder, "确认号码", hotel.DetermineNo ?? "-");
  6456. AddTableRow(builder, "入住日期", hotel.CheckInDate);
  6457. AddTableRow(builder, "离店日期", hotel.CheckOutDate);
  6458. AddTableRow(builder, "房间信息", hotel.RoomExplanation ?? "-");
  6459. builder.EndTable();
  6460. }
  6461. private static void CreateAirDetailTable(DocumentBuilder builder, Grp_AirTicketReservations air)
  6462. {
  6463. // 设置表格不允许跨页断行,确保整个表格在一页上
  6464. Table table = builder.StartTable();
  6465. //table.AllowBreakAcrossPages = false; // 关键设置:不允许表格跨页
  6466. // 设置表格样式
  6467. ApplyTableStyle(table);
  6468. // 添加酒店基本信息行
  6469. AddTableRow(builder, "城市(A-B)", air.FlightsCity ?? "-", true);
  6470. AddTableRow(builder, "航班日期", air.FlightsDate + " " + air.FlightsTime ?? "-");
  6471. AddTableRow(builder, "机票票号", air.TicketNumber ?? "-");
  6472. AddTableRow(builder, "航班简述", air.FlightsCode ?? "-");
  6473. AddTableRow(builder, "航班描述", air.FlightsDescription);
  6474. builder.EndTable();
  6475. }
  6476. private static void AddTableRow(DocumentBuilder builder, string title, string value, bool isHeaderRow = false)
  6477. {
  6478. // 左边单元格 - 标题
  6479. builder.InsertCell();
  6480. //builder.CellFormat.BackColor = isHeaderRow ? System.Drawing.Color.LightBlue : System.Drawing.Color.LightGray;
  6481. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  6482. builder.CellFormat.Width = 60;
  6483. builder.Font.Bold = true;
  6484. builder.Font.Size = isHeaderRow ? 12 : 10;
  6485. builder.Font.Color = isHeaderRow ? System.Drawing.Color.DarkBlue : System.Drawing.Color.Black;
  6486. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  6487. builder.Write(title);
  6488. // 右边单元格 - 值
  6489. builder.InsertCell();
  6490. //builder.CellFormat.BackColor = System.Drawing.Color.White;
  6491. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  6492. builder.CellFormat.Width = 200;
  6493. builder.Font.Bold = isHeaderRow;
  6494. builder.Font.Size = isHeaderRow ? 12 : 10;
  6495. builder.Font.Color = System.Drawing.Color.Black;
  6496. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  6497. builder.Write(value);
  6498. builder.EndRow();
  6499. // 重置单元格格式(除了宽度)
  6500. //builder.CellFormat.BackColor = System.Drawing.Color.White;
  6501. builder.Font.Bold = false;
  6502. builder.Font.Size = 10;
  6503. builder.Font.Color = System.Drawing.Color.Black;
  6504. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  6505. }
  6506. private static void ApplyTableStyle(Table table)
  6507. {
  6508. try
  6509. {
  6510. // 设置表格边框
  6511. table.SetBorders(LineStyle.Single, 1.0, System.Drawing.Color.Gray);
  6512. // 设置表格属性
  6513. table.LeftPadding = 5;
  6514. table.RightPadding = 5;
  6515. table.TopPadding = 3;
  6516. table.BottomPadding = 3;
  6517. table.Alignment = TableAlignment.Left;
  6518. table.AllowAutoFit = false;
  6519. //table.AllowBreakAcrossPages = true;
  6520. // 设置表格宽度
  6521. table.PreferredWidth = PreferredWidth.FromPoints(400);
  6522. // 设置列宽
  6523. if (table.FirstRow != null && table.FirstRow.Cells.Count == 2)
  6524. {
  6525. table.FirstRow.Cells[0].CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);
  6526. table.FirstRow.Cells[1].CellFormat.PreferredWidth = PreferredWidth.FromPercent(80);
  6527. }
  6528. }
  6529. catch (Exception ex)
  6530. {
  6531. //_logger.LogWarning(ex, "设置表格样式时发生错误");
  6532. }
  6533. }
  6534. private static void AddFooter(DocumentBuilder builder, string footerText)
  6535. {
  6536. builder.InsertBreak(BreakType.ParagraphBreak);
  6537. builder.Writeln();
  6538. builder.Writeln();
  6539. // 添加分隔线
  6540. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  6541. builder.Font.Size = 8;
  6542. builder.Font.Color = System.Drawing.Color.LightGray;
  6543. //builder.Writeln("────────────────────────────────────");
  6544. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;
  6545. builder.Font.Size = 9;
  6546. builder.Font.Italic = true;
  6547. builder.Font.Color = System.Drawing.Color.Gray;
  6548. builder.Writeln(footerText);
  6549. builder.Writeln($"文档生成时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
  6550. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  6551. builder.Font.Size = 10;
  6552. builder.Font.Italic = false;
  6553. builder.Font.Color = System.Drawing.Color.Black;
  6554. }
  6555. #endregion
  6556. #region 动态参数字符串格式化
  6557. /// <summary>
  6558. /// 动态参数字符串格式化
  6559. /// </summary>
  6560. /// <param name="dto">字符串格式化参数DTO</param>
  6561. /// <returns>格式化结果View</returns>
  6562. public static Task<StringFormatView> StringFormatAsync(StringFormatDto dto)
  6563. {
  6564. // 参数验证
  6565. if (string.IsNullOrWhiteSpace(dto?.FormatTemplate))
  6566. {
  6567. return Task.FromResult(new StringFormatView
  6568. {
  6569. Success = false,
  6570. Message = "格式化模板不能为空!"
  6571. });
  6572. }
  6573. if (dto.Parameters == null)
  6574. {
  6575. dto.Parameters = new List<string>();
  6576. }
  6577. try
  6578. {
  6579. // 计算需要的占位符数量
  6580. var placeholderCount = CountPlaceholders(dto.FormatTemplate);
  6581. // 验证参数数量是否匹配
  6582. if (dto.Parameters.Count != placeholderCount)
  6583. {
  6584. return Task.FromResult(new StringFormatView
  6585. {
  6586. Success = false,
  6587. Message = $"参数数量不匹配!模板需要 {placeholderCount} 个参数,但提供了 {dto.Parameters.Count} 个参数。"
  6588. });
  6589. }
  6590. var parameters = dto.Parameters.Cast<object>().ToArray();
  6591. // 格式化字符串
  6592. string formattedResult = string.Format(dto.FormatTemplate, parameters);
  6593. var result = new StringFormatView
  6594. {
  6595. Success = true,
  6596. Message = "操作成功!",
  6597. OriginalTemplate = dto.FormatTemplate,
  6598. FormattedResult = formattedResult,
  6599. Parameters = dto.Parameters,
  6600. ParameterCount = dto.Parameters.Count
  6601. };
  6602. return Task.FromResult(result);
  6603. }
  6604. catch (FormatException ex)
  6605. {
  6606. return Task.FromResult(new StringFormatView
  6607. {
  6608. Success = false,
  6609. Message = $"格式化错误:{ex.Message}"
  6610. });
  6611. }
  6612. catch (Exception ex)
  6613. {
  6614. return Task.FromResult(new StringFormatView
  6615. {
  6616. Success = false,
  6617. Message = $"处理失败:{ex.Message}"
  6618. });
  6619. }
  6620. }
  6621. /// <summary>
  6622. /// 计算模板字符串中的占位符数量
  6623. /// </summary>
  6624. private static int CountPlaceholders(string template)
  6625. {
  6626. if (string.IsNullOrWhiteSpace(template))
  6627. return 0;
  6628. int maxIndex = -1;
  6629. int index = 0;
  6630. while (index < template.Length)
  6631. {
  6632. if (template[index] == '{')
  6633. {
  6634. int endIndex = template.IndexOf('}', index);
  6635. if (endIndex > index)
  6636. {
  6637. string placeholder = template.Substring(index + 1, endIndex - index - 1);
  6638. if (int.TryParse(placeholder, out int placeholderIndex))
  6639. {
  6640. maxIndex = Math.Max(maxIndex, placeholderIndex);
  6641. }
  6642. index = endIndex + 1;
  6643. }
  6644. else
  6645. {
  6646. index++;
  6647. }
  6648. }
  6649. else
  6650. {
  6651. index++;
  6652. }
  6653. }
  6654. return maxIndex + 1; // 返回最大索引+1(因为索引从0开始)
  6655. }
  6656. #endregion
  6657. /// <summary>
  6658. /// AI对话结果中提取JSON
  6659. /// </summary>
  6660. /// <param name="input"></param>
  6661. /// <returns></returns>
  6662. public static string ExtractJson(string input)
  6663. {
  6664. // 1) 优先匹配 Markdown 代码块: ```json ... ``` 或 ``` ... ```
  6665. var m = Regex.Match(
  6666. input,
  6667. @"```(?:json)?\s*([\s\S]*?)\s*```",
  6668. RegexOptions.IgnoreCase);
  6669. if (m.Success)
  6670. return m.Groups[1].Value.Trim();
  6671. // 2) 兜底:从文本中截取第一个 JSON 数组/对象
  6672. int arrStart = input.IndexOf('[');
  6673. int arrEnd = input.LastIndexOf(']');
  6674. if (arrStart >= 0 && arrEnd > arrStart)
  6675. return input.Substring(arrStart, arrEnd - arrStart + 1).Trim();
  6676. int objStart = input.IndexOf('{');
  6677. int objEnd = input.LastIndexOf('}');
  6678. if (objStart >= 0 && objEnd > objStart)
  6679. return input.Substring(objStart, objEnd - objStart + 1).Trim();
  6680. // 3) 实在提取不到,按原文返回,让反序列化抛错
  6681. return input.Trim();
  6682. }
  6683. }
  6684. }