GeneralMethod.cs 349 KB

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