GeneralMethod.cs 316 KB

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