GeneralMethod.cs 317 KB

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