GroupsController.cs 1.8 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861
  1. using Aspose.Cells;
  2. using Aspose.Words;
  3. using Aspose.Words.Drawing;
  4. using Aspose.Words.Tables;
  5. using DiffMatchPatch;
  6. using Dm.util;
  7. using Humanizer;
  8. using iTextSharp.text.pdf;
  9. using iTextSharp.xmp.impl.xpath;
  10. using Microsoft.AspNetCore.Routing.Template;
  11. using Microsoft.AspNetCore.SignalR;
  12. using NPOI.OpenXmlFormats.Wordprocessing;
  13. using NPOI.SS.Formula.Functions;
  14. using NPOI.SS.UserModel;
  15. using NPOI.SS.Util;
  16. using NPOI.XSSF.UserModel;
  17. using OASystem.API.Middlewares;
  18. using OASystem.API.OAMethodLib;
  19. using OASystem.API.OAMethodLib.APNs;
  20. using OASystem.API.OAMethodLib.DeepSeekAPI;
  21. using OASystem.API.OAMethodLib.File;
  22. using OASystem.API.OAMethodLib.GenericSearch;
  23. using OASystem.API.OAMethodLib.Hub.HubClients;
  24. using OASystem.API.OAMethodLib.Hub.Hubs;
  25. using OASystem.API.OAMethodLib.JuHeAPI;
  26. using OASystem.API.OAMethodLib.KiMiApi;
  27. using OASystem.API.OAMethodLib.QiYeWeChatAPI.AppNotice;
  28. using OASystem.Domain.AesEncryption;
  29. using OASystem.Domain.Attributes;
  30. using OASystem.Domain.Dtos.CRM;
  31. using OASystem.Domain.Dtos.FileDto;
  32. using OASystem.Domain.Dtos.Financial;
  33. using OASystem.Domain.Dtos.Groups;
  34. using OASystem.Domain.Entities.Customer;
  35. using OASystem.Domain.Entities.Financial;
  36. using OASystem.Domain.Entities.Groups;
  37. using OASystem.Domain.ViewModels.Financial;
  38. using OASystem.Domain.ViewModels.Groups;
  39. using OASystem.Domain.ViewModels.JuHeExchangeRate;
  40. using OASystem.Domain.ViewModels.OCR;
  41. using OASystem.Domain.ViewModels.QiYeWeChat;
  42. using OASystem.Domain.ViewModels.Statistics;
  43. using OASystem.Infrastructure.Logging;
  44. using OASystem.Infrastructure.Repositories.CRM;
  45. using OASystem.Infrastructure.Repositories.Financial;
  46. using OASystem.Infrastructure.Repositories.Groups;
  47. using Quartz.Util;
  48. using SqlSugar.Extensions;
  49. using System.Collections;
  50. using System.ComponentModel.DataAnnotations;
  51. using System.Data;
  52. using System.Diagnostics;
  53. using System.Globalization;
  54. using System.IO.Compression;
  55. using System.Linq.Expressions;
  56. using System.Text.Json;
  57. using System.Web;
  58. using static OASystem.API.OAMethodLib.JWTHelper;
  59. using static OASystem.Infrastructure.Repositories.Groups.AirTicketResRepository;
  60. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  61. using Bookmark = Aspose.Words.Bookmark;
  62. using Cell = Aspose.Words.Tables.Cell;
  63. using Table = Aspose.Words.Tables.Table;
  64. using OASystem.Domain.Dtos.PersonnelModule;
  65. using OASystem.API.OAMethodLib.DoubaoAPI;
  66. namespace OASystem.API.Controllers
  67. {
  68. /// <summary>
  69. /// 团组相关
  70. /// </summary>
  71. //[Authorize]
  72. [Route("api/[controller]/[action]")]
  73. public class GroupsController : ControllerBase
  74. {
  75. private readonly ILogger<GroupsController> _logger;
  76. private readonly ITextFileLogger _eec_textLogger;
  77. private readonly IGroupTextFileLogger _groupTextLogger;
  78. private readonly GrpScheduleRepository _grpScheduleRep;
  79. private readonly IMapper _mapper;
  80. private readonly DelegationInfoRepository _groupRepository;
  81. private readonly TaskAssignmentRepository _taskAssignmentRep;
  82. private readonly AirTicketResRepository _airTicketResRep;
  83. private readonly DecreasePaymentsRepository _decreasePaymentsRep;
  84. private readonly InvitationOfficialActivitiesRepository _InvitationOfficialActivitiesRep;
  85. private readonly DelegationEnDataRepository _delegationEnDataRep;
  86. private readonly DelegationVisaRepository _delegationVisaRep;
  87. private readonly VisaPriceRepository _visaPriceRep;
  88. private readonly CarTouristGuideGroundRepository _carTouristGuideGroundRep;
  89. private readonly HotelPriceRepository _hotelPriceRep;
  90. private readonly CustomersRepository _customersRep;
  91. private readonly MessageRepository _message;
  92. private readonly SqlSugarClient _sqlSugar;
  93. private readonly TourClientListRepository _tourClientListRep;
  94. private readonly TeamRateRepository _teamRateRep;
  95. #region 成本相关
  96. private readonly CheckBoxsRepository _checkBoxs;
  97. private readonly GroupCostRepository _GroupCostRepository;
  98. private readonly CostTypeHotelNumberRepository _CostTypeHotelNumberRepository;
  99. private readonly GroupCostParameterRepository _GroupCostParameterRepository;
  100. #endregion
  101. private readonly IDoubaoService _doubaoService;
  102. private readonly SetDataRepository _setDataRep;
  103. private string url;
  104. private string path;
  105. private readonly EnterExitCostRepository _enterExitCostRep;
  106. private readonly IHubContext<ChatHub, IChatClient> _hubContext;
  107. private readonly UsersRepository _usersRep;
  108. private readonly IJuHeApiService _juHeApi;
  109. private readonly InvertedListRepository _invertedListRep;
  110. private readonly VisaFeeInfoRepository _visaFeeInfoRep;
  111. private readonly TicketBlackCodeRepository _ticketBlackCodeRep;
  112. private readonly ThreeCodeRepository _threeCodeRepository;
  113. private readonly HotelInquiryRepository _hotelInquiryRep;
  114. private readonly FeeAuditRepository _feeAuditRep;
  115. private readonly VisaCommissionRepository _visaCommissionRep;
  116. private readonly ForeignReceivablesRepository _ffrRep; //对外收款账单仓库
  117. private readonly OpinionaireRepository _opinionaireRep; //对外收款账单仓库
  118. private readonly List<CurrencyInfo> _currencyInit;
  119. private readonly List<int> _portTypeData;
  120. private readonly TableOperationRecordRepository _tableorRep;
  121. private readonly EnterExitCostDraftRepository _enterExitCostDraftRep;
  122. private readonly RestaurantRepository _restaurantRep;
  123. private readonly EnterExitCostQuoteRepository _enterExitCostQuoteRep;
  124. private readonly GroupOrderPreInfoRepository _grpOrderPreInfoRep;
  125. private readonly VisaProcessRepository _visaProcessRep;
  126. private readonly ProcessOverviewRepository _processOverviewRep;
  127. private readonly IDeepSeekService _deepSeekService;
  128. private readonly DynamicSearchService<Grp_DelegationInfo> _groupSearchService;
  129. /// <summary>
  130. /// 接送机默认报价系数
  131. /// </summary>
  132. public const decimal Def_AirportTransferCoeff = 2.50M;
  133. /// <summary>
  134. /// 接送机默认服务次数
  135. /// </summary>
  136. public const int Def_ServiceCount = 1;
  137. /// <summary>
  138. /// 火车默认报价系数
  139. /// </summary>
  140. public const decimal Def_TrainCoeff = 2.50M;
  141. /// <summary>
  142. /// 拉扯默认报价系数
  143. /// </summary>
  144. public const decimal Def_PullCartCoeff = 2.50M;
  145. /// <summary>
  146. /// 城市机票默认报价系数
  147. /// </summary>
  148. public const decimal Def_CityFlightCoeff = 2.50M;
  149. /// <summary>
  150. /// 初始化岗位对应负责的数据类型
  151. ///
  152. /// 岗位ID
  153. /// 24 机票、25 酒店、26 签证、27 商邀、28 OP
  154. ///
  155. /// 费用类型ID
  156. /// 76 酒店预订、79 车/导游地接、80 签证、81 邀请/公务活动、82 团组客户保险、85 机票预订、98 其他款项
  157. /// </summary>
  158. private readonly Dictionary<int, List<int>> _dataInit = new() {
  159. { 24, new List<int> { 85 } }, // 机票 -> 机票预订
  160. { 25, new List<int> { 76 } }, // 酒店 -> 酒店预订
  161. { 26, new List<int> { 80, 82 } }, // 签证 -> 签证, 团组客户保险
  162. { 27, new List<int> { 81 } }, // 地接 -> 邀请/公务活动
  163. { 28, new List<int> { 79 } } // 商邀 -> 车/导游地接
  164. };
  165. /// <summary>
  166. /// 构造函数
  167. /// </summary>
  168. /// <param name="logger"></param>
  169. /// <param name="eec_textLogger"></param>
  170. /// <param name="groupTextLogger"></param>
  171. /// <param name="mapper"></param>
  172. /// <param name="hubContext"></param>
  173. /// <param name="sqlSugar"></param>
  174. /// <param name="grpScheduleRep"></param>
  175. /// <param name="groupRepository"></param>
  176. /// <param name="taskAssignmentRep"></param>
  177. /// <param name="airTicketResRep"></param>
  178. /// <param name="decreasePaymentsRep"></param>
  179. /// <param name="InvitationOfficialActivitiesRep"></param>
  180. /// <param name="delegationEnDataRep"></param>
  181. /// <param name="enterExitCostRep"></param>
  182. /// <param name="delegationVisaRep"></param>
  183. /// <param name="message"></param>
  184. /// <param name="visaPriceRep"></param>
  185. /// <param name="carTouristGuideGroundRep"></param>
  186. /// <param name="checkBoxs"></param>
  187. /// <param name="GroupCostRepository"></param>
  188. /// <param name="CostTypeHotelNumberRepository"></param>
  189. /// <param name="GroupCostParameterRepository"></param>
  190. /// <param name="hotelPriceRep"></param>
  191. /// <param name="customersRep"></param>
  192. /// <param name="setDataRep"></param>
  193. /// <param name="tourClientListRep"></param>
  194. /// <param name="teamRateRep"></param>
  195. /// <param name="usersRep"></param>
  196. /// <param name="juHeApi"></param>
  197. /// <param name="invertedListRep"></param>
  198. /// <param name="visaFeeInfoRep"></param>
  199. /// <param name="ticketBlackCodeRep"></param>
  200. /// <param name="hotelInquiryRep"></param>
  201. /// <param name="threeCodeRepository"></param>
  202. /// <param name="feeAuditRep"></param>
  203. /// <param name="visaCommissionRep"></param>
  204. /// <param name="ffrRep"></param>
  205. /// <param name="opinionaireRep"></param>
  206. /// <param name="tableorRep"></param>
  207. /// <param name="enterExitCostDraftRep"></param>
  208. /// <param name="restaurantRep"></param>
  209. /// <param name="enterExitCostQuoteRep"></param>
  210. /// <param name="grpOrderPreInfoRep"></param>
  211. /// <param name="visaProcessRep"></param>
  212. /// <param name="processOverviewRep"></param>
  213. /// <param name="groupSearchService"></param>
  214. /// <param name="deepSeekService"></param>
  215. public GroupsController(
  216. ILogger<GroupsController> logger,
  217. ITextFileLogger eec_textLogger,
  218. IGroupTextFileLogger groupTextLogger,
  219. IMapper mapper,
  220. IHubContext<ChatHub, IChatClient> hubContext,
  221. SqlSugarClient sqlSugar,
  222. GrpScheduleRepository grpScheduleRep,
  223. DelegationInfoRepository groupRepository,
  224. TaskAssignmentRepository taskAssignmentRep,
  225. AirTicketResRepository airTicketResRep,
  226. DecreasePaymentsRepository decreasePaymentsRep,
  227. InvitationOfficialActivitiesRepository InvitationOfficialActivitiesRep,
  228. DelegationEnDataRepository delegationEnDataRep,
  229. EnterExitCostRepository enterExitCostRep,
  230. DelegationVisaRepository delegationVisaRep,
  231. MessageRepository message,
  232. VisaPriceRepository visaPriceRep,
  233. CarTouristGuideGroundRepository carTouristGuideGroundRep,
  234. CheckBoxsRepository checkBoxs,
  235. GroupCostRepository GroupCostRepository,
  236. CostTypeHotelNumberRepository CostTypeHotelNumberRepository,
  237. GroupCostParameterRepository GroupCostParameterRepository,
  238. HotelPriceRepository hotelPriceRep,
  239. CustomersRepository customersRep,
  240. SetDataRepository setDataRep,
  241. TourClientListRepository tourClientListRep,
  242. TeamRateRepository teamRateRep,
  243. UsersRepository usersRep,
  244. IJuHeApiService juHeApi,
  245. InvertedListRepository invertedListRep,
  246. VisaFeeInfoRepository visaFeeInfoRep,
  247. TicketBlackCodeRepository ticketBlackCodeRep,
  248. HotelInquiryRepository hotelInquiryRep,
  249. ThreeCodeRepository threeCodeRepository,
  250. FeeAuditRepository feeAuditRep,
  251. VisaCommissionRepository visaCommissionRep,
  252. ForeignReceivablesRepository ffrRep,
  253. OpinionaireRepository opinionaireRep,
  254. TableOperationRecordRepository tableorRep,
  255. EnterExitCostDraftRepository enterExitCostDraftRep,
  256. RestaurantRepository restaurantRep,
  257. EnterExitCostQuoteRepository enterExitCostQuoteRep,
  258. GroupOrderPreInfoRepository grpOrderPreInfoRep,
  259. VisaProcessRepository visaProcessRep,
  260. ProcessOverviewRepository processOverviewRep,
  261. DynamicSearchService<Grp_DelegationInfo> groupSearchService,
  262. IDeepSeekService deepSeekService,
  263. IDoubaoService doubaoService
  264. )
  265. {
  266. _logger = logger;
  267. _eec_textLogger = eec_textLogger;
  268. _groupTextLogger = groupTextLogger;
  269. _mapper = mapper;
  270. _grpScheduleRep = grpScheduleRep;
  271. _groupRepository = groupRepository;
  272. _taskAssignmentRep = taskAssignmentRep;
  273. _airTicketResRep = airTicketResRep;
  274. _sqlSugar = sqlSugar;
  275. url = AppSettingsHelper.Get("ExcelBaseUrl");
  276. path = AppSettingsHelper.Get("ExcelBasePath");
  277. if (!System.IO.Directory.Exists(path))
  278. {
  279. System.IO.Directory.CreateDirectory(path);//不存在就创建文件夹
  280. }
  281. _decreasePaymentsRep = decreasePaymentsRep;
  282. _InvitationOfficialActivitiesRep = InvitationOfficialActivitiesRep;
  283. _delegationEnDataRep = delegationEnDataRep;
  284. _enterExitCostRep = enterExitCostRep;
  285. _delegationVisaRep = delegationVisaRep;
  286. _message = message;
  287. _visaPriceRep = visaPriceRep;
  288. _carTouristGuideGroundRep = carTouristGuideGroundRep;
  289. _checkBoxs = checkBoxs;
  290. _GroupCostRepository = GroupCostRepository;
  291. _CostTypeHotelNumberRepository = CostTypeHotelNumberRepository;
  292. _GroupCostParameterRepository = GroupCostParameterRepository;
  293. _hotelPriceRep = hotelPriceRep;
  294. _customersRep = customersRep;
  295. _setDataRep = setDataRep;
  296. _tourClientListRep = tourClientListRep;
  297. _teamRateRep = teamRateRep;
  298. _hubContext = hubContext;
  299. _usersRep = usersRep;
  300. _juHeApi = juHeApi;
  301. _invertedListRep = invertedListRep;
  302. _visaFeeInfoRep = visaFeeInfoRep;
  303. _ticketBlackCodeRep = ticketBlackCodeRep;
  304. _hotelInquiryRep = hotelInquiryRep;
  305. _threeCodeRepository = threeCodeRepository;
  306. _feeAuditRep = feeAuditRep;
  307. _visaCommissionRep = visaCommissionRep;
  308. _ffrRep = ffrRep;
  309. _opinionaireRep = opinionaireRep;
  310. _currencyInit = new List<CurrencyInfo>()
  311. {
  312. new(){ CurrencyCode="USD",CurrencyName = "美元",Rate = 7.5000M },
  313. new(){ CurrencyCode="EUR",CurrencyName = "欧元",Rate = 8.0000M },
  314. new(){ CurrencyCode="GBP",CurrencyName = "英镑",Rate = 9.5000M },
  315. new(){ CurrencyCode="JPY",CurrencyName = "日元",Rate = 0.0500M },
  316. new(){ CurrencyCode="HKD",CurrencyName = "港币",Rate = 0.9500M },
  317. };
  318. _portTypeData = new List<int>() { 2, 3 };
  319. _tableorRep = tableorRep;
  320. _enterExitCostDraftRep = enterExitCostDraftRep;
  321. _restaurantRep = restaurantRep;
  322. _enterExitCostQuoteRep = enterExitCostQuoteRep;
  323. _grpOrderPreInfoRep = grpOrderPreInfoRep;
  324. _visaProcessRep = visaProcessRep;
  325. _processOverviewRep = processOverviewRep;
  326. _groupSearchService = groupSearchService;
  327. _deepSeekService = deepSeekService;
  328. _doubaoService = doubaoService;
  329. }
  330. #region 页面加载弹窗信息
  331. /// <summary>
  332. /// 提示用户录入团组费用信息
  333. /// 根据用户ID获取分配权限内团组名称
  334. /// </summary>
  335. /// <param name="currUserId">用户Id</param>
  336. /// <param name="daysAgo">往前推的天数</param>
  337. /// <returns></returns>
  338. [HttpGet]
  339. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  340. public async Task<IActionResult> GetGroupNamesByUserId(int currUserId, int daysAgo = 5)
  341. {
  342. var stopwatch = Stopwatch.StartNew();
  343. var userInfo = await _sqlSugar.Queryable<Sys_Users>()
  344. .Where(x => x.Id == currUserId && x.IsDel == 0)
  345. .Select(x => new { x.Id, x.JobPostId, x.CnName })
  346. .FirstAsync();
  347. if (userInfo == null)
  348. {
  349. return Ok(JsonView(false, "用户不存在或已被禁用!"));
  350. }
  351. var jobId = userInfo.JobPostId;
  352. var feeTypeIds = new List<int>() { };
  353. if (_dataInit.TryGetValue(jobId, out var values))
  354. {
  355. feeTypeIds = values;
  356. }
  357. /*
  358. * 获取今天时间往前推5天查询团组c表里有没有费用
  359. */
  360. var today_startDate = DateTime.Now.Date.AddDays(-daysAgo);
  361. //var today_endDate = DateTime.Now.Date.AddDays(-daysAgo).AddDays(1).AddSeconds(-1);
  362. var today_endDate = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
  363. var groupNames = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  364. .Where(di => di.IsDel == 0)
  365. .Where(di => di.VisitDate >= today_startDate && di.VisitDate <= today_endDate)
  366. // 存在任务分配记录
  367. .Where(di => SqlFunc.Subqueryable<Grp_GroupsTaskAssignment>()
  368. .Where(gta => gta.DIId == di.Id && gta.IsDel == 0 && feeTypeIds.Contains(gta.CTId))
  369. .Any())
  370. // 不存在费用记录
  371. .Where(di => !SqlFunc.Subqueryable<Grp_CreditCardPayment>()
  372. .Where(ccp => ccp.DIId == di.Id && ccp.IsDel == 0 && feeTypeIds.Contains(ccp.CTable))
  373. .Any())
  374. // 新增条件:不在确认记录表中(排除已确认的团组)
  375. .Where(di => !SqlFunc.Subqueryable<Grp_FeeEntryAcknowledge>()
  376. .Where(ack => ack.GroupId == di.Id && ack.IsDel == 0 && ack.UserId == currUserId)
  377. .Where(ack => feeTypeIds.Contains(ack.FeeTypeId))
  378. .Where(ack => ack.IsAcknowledged == AcknowledgeStatusEnum.Acknowledged) // 只排除已确认的记录
  379. .Any())
  380. .Select(di => new
  381. {
  382. di.Id,
  383. di.TeamName,
  384. di.VisitDate
  385. })
  386. .OrderBy(di => di.VisitDate)
  387. .ToListAsync();
  388. stopwatch.Stop();
  389. return Ok(JsonView(true, $"操作成功!【耗时:{stopwatch.ElapsedMilliseconds}ms】", new
  390. {
  391. isTips = groupNames.Any(),
  392. groupNames = groupNames.Select(x => new { x.Id, GroupName = x.TeamName, x.VisitDate }).ToList()
  393. }));
  394. }
  395. /// <summary>
  396. /// 提示用户录入团组费用信息
  397. /// 已知晓确认操作记录(添加) 批量
  398. /// </summary>
  399. /// <param name="dto">请求体</param>
  400. /// <returns></returns>
  401. [HttpPost]
  402. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  403. public async Task<IActionResult> FeeEntryAcknowledgeCrate(FeeEntryAcknowledgeCrateDto dto)
  404. {
  405. // 1. 参数验证
  406. if (dto?.GroupIds == null || !dto.GroupIds.Any())
  407. return Ok(JsonView(false, "请选择需要确认的团组!"));
  408. if (dto.GroupIds.Count > 100)
  409. return Ok(JsonView(false, "一次性确认团组数量不能超过100个!"));
  410. if (dto.CurrUserId <= 0)
  411. return Ok(JsonView(false, "用户ID无效!"));
  412. // 2. 验证用户存在性
  413. var userInfo = await _sqlSugar.Queryable<Sys_Users>()
  414. .Where(x => x.Id == dto.CurrUserId && x.IsDel == 0)
  415. .Select(x => new { x.Id, x.JobPostId, x.CnName })
  416. .FirstAsync();
  417. if (userInfo == null)
  418. return Ok(JsonView(false, "用户不存在或已被禁用!"));
  419. // 3. 获取费用类型
  420. if (!_dataInit.TryGetValue(userInfo.JobPostId, out var feeTypeIds) || feeTypeIds?.Count == 0)
  421. return Ok(JsonView(false, "当前用户岗位无对应的费用类型配置!"));
  422. // 4. 验证团组存在性
  423. var validGroupIds = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  424. .Where(x => dto.GroupIds.Contains(x.Id) && x.IsDel == 0)
  425. .Select(x => x.Id)
  426. .ToListAsync();
  427. if (!validGroupIds.Any())
  428. return Ok(JsonView(false, "未找到有效的团组信息!"));
  429. // 5. 检查团组费用表中是否存在对应费用类型的数据
  430. var existingFeeRecords = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  431. .Where(x => validGroupIds.Contains(x.DIId) && x.IsDel == 0)
  432. .Where(x => feeTypeIds.Contains(x.CTable))
  433. .Select(x => new { GroupId = x.DIId, FeeTypeId = x.CTable })
  434. .ToListAsync();
  435. if (existingFeeRecords.Count > 0)
  436. {
  437. // 找出有问题的团组和费用类型
  438. var problematicGroups = existingFeeRecords
  439. .GroupBy(x => x.GroupId)
  440. .Select(g => new
  441. {
  442. GroupId = g.Key,
  443. FeeTypeIds = string.Join(",", g.Select(x => x.FeeTypeId).Distinct())
  444. })
  445. .ToList();
  446. var errorMessage = $"以下团组的费用表中已存在费用数据,不可添加确认记录:";
  447. foreach (var group in problematicGroups)
  448. {
  449. errorMessage += $"\n团组 {group.GroupId} - 费用类型ID: [{group.FeeTypeIds}]";
  450. }
  451. return Ok(JsonView(false, errorMessage));
  452. }
  453. // 6. 检查是否已存在确认记录(避免重复确认)
  454. var existingAcknowledgeRecords = await _sqlSugar.Queryable<Grp_FeeEntryAcknowledge>()
  455. .Where(x => x.UserId == dto.CurrUserId && x.IsDel == 0)
  456. .Where(x => validGroupIds.Contains(x.GroupId))
  457. .Where(x => feeTypeIds.Contains(x.FeeTypeId))
  458. .Select(x => new { x.GroupId, x.FeeTypeId })
  459. .ToListAsync();
  460. // 7. 准备插入数据(过滤已存在的记录)
  461. var recordsToInsert = new List<Grp_FeeEntryAcknowledge>();
  462. foreach (var groupId in validGroupIds)
  463. {
  464. foreach (var feeTypeId in feeTypeIds)
  465. {
  466. // 检查是否已存在相同记录
  467. var exists = existingAcknowledgeRecords.Any(x => x.GroupId == groupId && x.FeeTypeId == feeTypeId);
  468. if (!exists)
  469. {
  470. recordsToInsert.Add(new Grp_FeeEntryAcknowledge()
  471. {
  472. GroupId = groupId,
  473. UserId = dto.CurrUserId,
  474. JobPostId = userInfo.JobPostId,
  475. FeeTypeId = feeTypeId,
  476. IsAcknowledged = Domain.Enums.AcknowledgeStatusEnum.Acknowledged,
  477. AcknowledgeTime = DateTime.Now,
  478. AcknowledgeType = Domain.Enums.AcknowledgeTypeEnum.WebConfirm,
  479. CreateUserId = 4, // 系统创建
  480. CreateTime = DateTime.Now
  481. });
  482. }
  483. }
  484. }
  485. if (!recordsToInsert.Any())
  486. return Ok(JsonView(true, "所选团组已确认,无需重复操作!"));
  487. // 8. 批量插入数据
  488. var successCount = await _sqlSugar.Insertable(recordsToInsert).ExecuteCommandAsync();
  489. if (successCount <= 0)
  490. return Ok(JsonView(false, "操作失败,未能保存确认记录!"));
  491. // 9. 记录操作日志
  492. _logger.LogInformation("用户 {UserName}(ID:{UserId}) 批量确认了 {GroupCount} 个团组的费用类型,共添加 {RecordCount} 条确认记录",
  493. userInfo.CnName, dto.CurrUserId, validGroupIds.Count, successCount);
  494. // 10. 操作成功 返回成功视图
  495. var result = await GetGroupNamesByUserId(dto.CurrUserId, dto.DaysAgo);
  496. if (result is OkObjectResult okObjectResult)
  497. {
  498. return Ok(okObjectResult.Value);
  499. }
  500. //return Ok(result);
  501. return Ok(JsonView(true, $"操作成功!共为 {validGroupIds.Count} 个团组添加了 {successCount} 条确认记录"));
  502. }
  503. /// <summary>
  504. /// 提示用户录入团组费用信息
  505. /// 已知晓确认操作记录(添加) 单个
  506. /// </summary>
  507. /// <param name="dto">请求体</param>
  508. /// <returns></returns>
  509. [HttpPost]
  510. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  511. public async Task<IActionResult> FeeEntryAcknowledgeSingleCreate(FeeEntryAcknowledgeSingleDto dto)
  512. {
  513. // 1. 参数验证
  514. if (dto.GroupId <= 0)
  515. return Ok(JsonView(false, "请选择有效的团组ID!"));
  516. if (dto.CurrUserId <= 0)
  517. return Ok(JsonView(false, "用户ID无效!"));
  518. // 2. 验证用户存在性
  519. var userInfo = await _sqlSugar.Queryable<Sys_Users>()
  520. .Where(x => x.Id == dto.CurrUserId && x.IsDel == 0)
  521. .Select(x => new { x.Id, x.JobPostId, x.CnName })
  522. .FirstAsync();
  523. if (userInfo == null)
  524. return Ok(JsonView(false, "用户不存在或已被禁用!"));
  525. // 3. 获取费用类型
  526. if (!_dataInit.TryGetValue(userInfo.JobPostId, out var feeTypeIds) || feeTypeIds?.Count == 0)
  527. return Ok(JsonView(false, "当前用户岗位无对应的费用类型配置!"));
  528. // 4. 验证团组存在性
  529. var groupExists = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  530. .AnyAsync(x => x.Id == dto.GroupId && x.IsDel == 0);
  531. if (!groupExists)
  532. return Ok(JsonView(false, "未找到有效的团组信息!"));
  533. // 5. 检查团组费用表中是否存在对应费用类型的数据
  534. var existingFeeRecords = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  535. .Where(x => x.DIId == dto.GroupId && x.IsDel == 0)
  536. .Where(x => feeTypeIds.Contains(x.CTable))
  537. .Select(x => new { x.CTable })
  538. .ToListAsync();
  539. if (existingFeeRecords.Count > 0)
  540. {
  541. var existingFeeTypeNames = existingFeeRecords.Select(x => x.CTable).Distinct().ToList();
  542. return Ok(JsonView(false, $"团组费用表中已存在费用类型ID [{string.Join(",", existingFeeTypeNames)}] 的数据,不可添加确认无费用记录!"));
  543. }
  544. // 6. 检查已存在的确认记录
  545. var existingAcknowledgeRecords = await _sqlSugar.Queryable<Grp_FeeEntryAcknowledge>()
  546. .Where(x => x.UserId == dto.CurrUserId && x.IsDel == 0)
  547. .Where(x => x.GroupId == dto.GroupId)
  548. .Where(x => feeTypeIds.Contains(x.FeeTypeId))
  549. .Select(x => new { x.FeeTypeId })
  550. .ToListAsync();
  551. var existingAcknowledgeFeeTypeIds = existingAcknowledgeRecords.Select(x => x.FeeTypeId).ToHashSet();
  552. // 7. 准备插入数据(过滤已存在的记录)
  553. var recordsToInsert = feeTypeIds
  554. .Where(feeTypeId => !existingAcknowledgeFeeTypeIds.Contains(feeTypeId))
  555. .Select(feeTypeId => new Grp_FeeEntryAcknowledge
  556. {
  557. GroupId = dto.GroupId,
  558. UserId = dto.CurrUserId,
  559. JobPostId = userInfo.JobPostId,
  560. FeeTypeId = feeTypeId,
  561. IsAcknowledged = Domain.Enums.AcknowledgeStatusEnum.Acknowledged,
  562. AcknowledgeTime = DateTime.Now,
  563. AcknowledgeType = Domain.Enums.AcknowledgeTypeEnum.WebConfirm,
  564. CreateUserId = 4, // 系统创建
  565. CreateTime = DateTime.Now
  566. })
  567. .ToList();
  568. if (recordsToInsert.Count == 0)
  569. return Ok(JsonView(true, "所选团组已确认,无需重复操作!"));
  570. // 8. 批量插入数据
  571. var successCount = await _sqlSugar.Insertable(recordsToInsert).ExecuteCommandAsync();
  572. if (successCount <= 0)
  573. return Ok(JsonView(false, "操作失败,未能保存确认记录!"));
  574. // 9. 记录操作日志(可选)
  575. _logger.LogInformation("用户 {UserName}(ID:{UserId}) 确认了团组 {GroupId} 的费用类型",
  576. userInfo.CnName, dto.CurrUserId, dto.GroupId);
  577. return Ok(JsonView(true, $"操作成功!"));
  578. }
  579. #endregion
  580. #region 流程管控
  581. /// <summary>
  582. /// 获取团组流程管控信息
  583. /// </summary>
  584. /// <param name="_jsonDto">查询参数</param>
  585. /// <returns></returns>
  586. [HttpPost]
  587. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  588. public async Task<IActionResult> PostSearchGrpSchedule(JsonDtoBase _jsonDto)
  589. {
  590. if (string.IsNullOrEmpty(_jsonDto.Paras))
  591. {
  592. return Ok(JsonView(false, "参数为空"));
  593. }
  594. Grp_ScheduleDto _ScheduleDto = JsonConvert.DeserializeObject<Grp_ScheduleDto>(_jsonDto.Paras);
  595. if (_ScheduleDto != null)
  596. {
  597. if (_ScheduleDto.SearchType == 2)//获取列表
  598. {
  599. List<Grp_ScheduleView> _grpScheduleViewList = await _grpScheduleRep.GetViewList_GrpSchedule(_ScheduleDto);
  600. return Ok(JsonView(_grpScheduleViewList));
  601. }
  602. else//获取对象
  603. {
  604. Grp_ScheduleCombinView _grpScheduleView = await _grpScheduleRep.GetView_GrpSchedule(_ScheduleDto);
  605. if (_grpScheduleView != null)
  606. {
  607. return Ok(JsonView(_grpScheduleView));
  608. }
  609. }
  610. }
  611. else
  612. {
  613. return Ok(JsonView(false, "参数反序列化失败"));
  614. }
  615. return Ok(JsonView(false, "暂无数据!"));
  616. }
  617. /// <summary>
  618. /// 修改团组流程管控详细表数据
  619. /// </summary>
  620. /// <param name="dto"></param>
  621. /// <returns></returns>
  622. [HttpPost]
  623. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  624. public async Task<IActionResult> PostUpdateGrpScheduleDetail(Grp_ScheduleDetailUpdDto dto)
  625. {
  626. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  627. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_ScheduleDetailInfo>()
  628. .SetColumns(it => it.Duty == _detail.Duty)
  629. .SetColumns(it => it.ExpectBeginDt == _detail.ExpectBeginDt)
  630. .SetColumns(it => it.ExpectEndDt == _detail.ExpectEndDt)
  631. .SetColumns(it => it.JobContent == _detail.JobContent)
  632. .SetColumns(it => it.Remark == _detail.Remark)
  633. .SetColumns(it => it.StepStatus == _detail.StepStatus)
  634. .Where(s => s.Id == dto.Id)
  635. //.UpdateColumns(s => new { s.Duty, s.ExpectBeginDt, s.ExpectEndDt, s.JobContent, s.Remark, s.StepStatus })
  636. .ExecuteCommandAsync();
  637. if (result > 0)
  638. {
  639. return Ok(JsonView(true, "保存成功!"));
  640. }
  641. return Ok(JsonView(false, "保存失败!"));
  642. }
  643. /// <summary>
  644. /// 删除团组流程管控详细表数据,删除人Id请放在Duty
  645. /// </summary>
  646. /// <param name="dto"></param>
  647. /// <returns></returns>
  648. [HttpPost]
  649. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  650. public async Task<ActionResult> PostDeleteGrpScheduleDetail(Grp_ScheduleDetailUpdDto dto)
  651. {
  652. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  653. _detail.IsDel = 1;
  654. _detail.DeleteUserId = dto.Duty;
  655. _detail.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  656. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_ScheduleDetailInfo>()
  657. .SetColumns(it => it.IsDel == _detail.IsDel)
  658. .SetColumns(it => it.DeleteUserId == _detail.DeleteUserId)
  659. .SetColumns(it => it.DeleteTime == _detail.DeleteTime)
  660. .Where(it => it.Id == dto.Id)
  661. //.UpdateColumns(s => new { s.IsDel, s.DeleteUserId, s.DeleteTime })
  662. //.WhereColumns(s => s.Id == dto.Id)
  663. .ExecuteCommandAsync();
  664. if (result > 0)
  665. {
  666. return Ok(JsonView(true, "删除成功!"));
  667. }
  668. return Ok(JsonView(false, "删除失败!"));
  669. }
  670. /// <summary>
  671. /// 增加团组流程管控详细表数据
  672. /// </summary>
  673. /// <param name="dto"></param>
  674. /// <returns></returns>
  675. [HttpPost]
  676. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  677. public async Task<ActionResult> PostInsertGrpScheduleDetail(Grp_ScheduleDetailInsertDto dto)
  678. {
  679. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  680. if (DateTime.Now < _detail.ExpectBeginDt)
  681. {
  682. _detail.StepStatus = 0;
  683. }
  684. else
  685. {//若大于设置时间,不考虑设置的预计结束日期,统一视为进行中
  686. _detail.StepStatus = 1;
  687. }
  688. var result = await _grpScheduleRep._sqlSugar.Insertable(_detail).ExecuteReturnIdentityAsync();
  689. if (result > 0)
  690. {
  691. Grp_ScheduleDetailView _result = await _grpScheduleRep.GetInsertBackData(result);
  692. return Ok(JsonView(true, "添加成功!", _result));
  693. }
  694. return Ok(JsonView(false, "添加失败!"));
  695. }
  696. #endregion
  697. #region 团组前期信息
  698. /// <summary>
  699. /// 团组前期信息H5-URL(员工对应地址)
  700. /// </summary>
  701. /// <param name="name">用户名称</param>
  702. /// <returns></returns>
  703. [HttpGet]
  704. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  705. public async Task<IActionResult> GroupOrderPreInfoH5URLList([FromQuery] string name)
  706. {
  707. var userURLs = await _sqlSugar.Queryable<Sys_Users>()
  708. .Where(x => x.IsDel == 0)
  709. .WhereIF(!string.IsNullOrEmpty(name), x => x.CnName.Contains(name))
  710. .OrderBy(x => x.Id)
  711. .Select(x => new
  712. {
  713. name = x.CnName,
  714. url = $"http://oa.pan-american-intl.com:4399/#/MarketplacePick?userid={x.Id}",
  715. })
  716. .ToListAsync();
  717. return Ok(JsonView(true, "操作成功!", userURLs, userURLs.Count));
  718. }
  719. /// <summary>
  720. /// 团组前期信息 List
  721. /// </summary>
  722. /// <returns></returns>
  723. [HttpPost]
  724. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  725. public async Task<IActionResult> GroupOrderPreInfoList(GroupOrderPreInfoListDto dto)
  726. {
  727. var search = dto.Search;
  728. int[] nameTempIds = new int[] { 1, 12, 28 },
  729. countryTempIds = new int[] { 2, 13, 29 },
  730. daysTempIds = new int[] { 4, 15, 31 },
  731. ppNumTempIds = new int[] { 6 };
  732. var list = await _sqlSugar.Queryable<Grp_OrderPreInfo>()
  733. .LeftJoin<Sys_Users>((opi, u) => opi.CreateUserId == u.Id)
  734. .Where((opi, u) => opi.IsDel == 0)
  735. .OrderByDescending((opi, u) => opi.CreateTime)
  736. .Select((opi, u) => new GroupOrderPreInfoListView()
  737. {
  738. Id = opi.Id,
  739. Name = opi.Name,
  740. UnitName = SqlFunc.Subqueryable<Grp_OrderPreItem>().Where(x => x.ParentId == opi.Id && nameTempIds.Contains(x.FormTempId)).Select(x => x.Value),
  741. VisitCountryVal = SqlFunc.Subqueryable<Grp_OrderPreItem>().Where(x => x.ParentId == opi.Id && countryTempIds.Contains(x.FormTempId)).Select(x => x.Value),
  742. VisitDays = SqlFunc.Subqueryable<Grp_OrderPreItem>().Where(x => x.ParentId == opi.Id && daysTempIds.Contains(x.FormTempId)).Select(x => x.Value),
  743. VisiPpNum = SqlFunc.Subqueryable<Grp_OrderPreItem>().Where(x => x.ParentId == opi.Id && ppNumTempIds.Contains(x.FormTempId)).Select(x => x.Value),
  744. Operator = u.CnName,
  745. OperationTime = opi.CreateTime
  746. })
  747. //.WhereIF(!string.IsNullOrEmpty(search), x => x.Name.Contains(search) || x.UnitName.Contains(search) || x.VisitCountrys.Contains(search))
  748. //.ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  749. .ToListAsync();
  750. var listPageData = list.WhereIF(!string.IsNullOrEmpty(search), x => x.Name.Contains(search) || x.UnitName.Contains(search) || x.VisitCountrys.Contains(search)).ToList();
  751. int total = list.Count;
  752. int totalPageCount = (int)Math.Ceiling(list.Count / (double)dto.PageSize);
  753. var listPageData1 = listPageData
  754. .Skip((dto.PageIndex - 1) * dto.PageSize)
  755. .Take(dto.PageSize)
  756. .ToList();
  757. var infoIds = listPageData1.Select(x => x.Id).ToList();
  758. var typeDatas = await _sqlSugar.Queryable<Sys_SetData>()
  759. .Where(x => x.IsDel == 0 && x.STid == 109)
  760. .ToArrayAsync();
  761. var items = await _sqlSugar.Queryable<Grp_OrderPreItem>()
  762. .LeftJoin<Sys_FormTemp>((opi, ft) => opi.FormTempId == ft.Id)
  763. .Where((opi, ft) => opi.IsDel == 0 && infoIds.Contains(opi.ParentId))
  764. .Select((opi, ft) => new { opi.ParentId, opi.FormTempId, ft.TempId })
  765. .ToListAsync();
  766. foreach (var item in listPageData1)
  767. {
  768. var typeDatas1 = typeDatas.Select(x => new
  769. {
  770. x.Id,
  771. x.Name,
  772. IsNull = !items.Any(x1 => item.Id == x1.ParentId && x.Id == x1.TempId)
  773. }).ToArray();
  774. item.VersionDetails = typeDatas1;
  775. }
  776. return Ok(JsonView(listPageData1, listPageData1.Count));
  777. }
  778. /// <summary>
  779. /// 团组前期信息 Init
  780. /// </summary>
  781. /// <returns></returns>
  782. [HttpGet("{userId}")]
  783. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  784. public async Task<IActionResult> GroupOrderPreInfo(int userId)
  785. {
  786. return Ok(await _grpOrderPreInfoRep.DataInit(userId));
  787. }
  788. /// <summary>
  789. /// 国家数据源
  790. /// </summary>
  791. /// <param name="pageIndex">当前页码</param>
  792. /// <param name="pageSize">每页条数</param>
  793. /// <param name="search">查询条件</param>
  794. /// <returns></returns>
  795. [HttpGet]
  796. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  797. public async Task<IActionResult> CountryInit([FromQuery] int pageIndex, [FromQuery] int pageSize, [FromQuery] string search)
  798. {
  799. var countrys = await _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x => x.IsDel == 0).Select(x => x.Country).Distinct().ToListAsync();
  800. if (pageIndex == 0 && pageSize == 0)
  801. {
  802. //所有数据
  803. return Ok(JsonView(countrys, countrys.Count));
  804. }
  805. //分页
  806. int skip = (pageIndex - 1) * pageSize;
  807. int take = pageSize;
  808. if (!string.IsNullOrEmpty(search))
  809. {
  810. IEnumerable<char> charSequence = search.Select(c => c);
  811. var pageResult1 = countrys.Where(x => charSequence.All(x1 => x.Contains(x1))).ToList();
  812. var pageData = pageResult1.Skip(skip).Take(take).ToList();
  813. return Ok(JsonView(pageData, pageResult1.Count));
  814. }
  815. var pageResult2 = countrys.Skip(skip).Take(take).ToList();
  816. return Ok(JsonView(pageResult2, countrys.Count));
  817. }
  818. /// <summary>
  819. /// 城市数据源
  820. /// </summary>
  821. /// <param name="countryLabel">国家名称 多个使用英文逗号隔开</param>
  822. /// <param name="pageIndex">当前页码</param>
  823. /// <param name="pageSize">每页条数</param>
  824. /// <param name="search">查询条件</param>
  825. /// <returns></returns>
  826. [HttpGet("{countryLabel}")]
  827. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  828. public async Task<IActionResult> CityByCountry(
  829. string countryLabel,
  830. [FromQuery] int pageIndex,
  831. [FromQuery] int pageSize,
  832. [FromQuery] string search)
  833. {
  834. countryLabel = HttpUtility.UrlDecode(countryLabel);
  835. var countryList = countryLabel.Split(',', StringSplitOptions.RemoveEmptyEntries).ToArray();
  836. var citys = Array.Empty<string?>();
  837. if (countryList.Any())
  838. {
  839. var cityDatas = await _sqlSugar
  840. .Queryable<Grp_NationalTravelFee>()
  841. .Where(x => x.IsDel == 0 && countryList.Contains(x.Country) && !string.IsNullOrEmpty(x.City))
  842. .ToArrayAsync();
  843. foreach (var item in cityDatas)
  844. {
  845. if (item.City.Contains("城市"))
  846. {
  847. item.City = item.Country + "-所有城市";
  848. }
  849. }
  850. var cityDatas1 = cityDatas.OrderBy(x => x.Country);
  851. citys = cityDatas1.Select(x => x.City).Distinct().ToArray();
  852. }
  853. if (pageIndex == 0 && pageSize == 0)
  854. {
  855. //所有数据
  856. return Ok(JsonView(citys, citys?.Length ?? 0));
  857. }
  858. //分页
  859. int skip = (pageIndex - 1) * pageSize;
  860. int take = pageSize;
  861. if (!string.IsNullOrEmpty(search))
  862. {
  863. IEnumerable<char> charSequence = search.Select(c => c);
  864. var pageResult1 = citys.Where(x => charSequence.All(x1 => x.Contains(x1))).ToList();
  865. var pageData = pageResult1.Skip(skip).Take(take).ToList();
  866. return Ok(JsonView(pageData, pageResult1.Count));
  867. }
  868. var pageResult2 = citys.Skip(skip).Take(take).ToList();
  869. return Ok(JsonView(pageResult2, citys?.Length ?? 0));
  870. }
  871. /// <summary>
  872. /// 团组前期信息 Info
  873. /// </summary>
  874. /// <param name="dto">Id</param>
  875. /// <returns></returns>
  876. [HttpGet("{Id}/{TempId}")]
  877. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  878. public async Task<IActionResult> GroupOrderPreInfo([FromRoute] GroupOrderPreInfoDto dto)
  879. {
  880. return Ok(await _grpOrderPreInfoRep.InfoAsync(dto.Id, dto.TempId));
  881. }
  882. /// <summary>
  883. /// 团组前期信息 移动端 Info
  884. /// </summary>
  885. /// <param name="dto">Id</param>
  886. /// <returns></returns>
  887. [HttpGet("{Id}/{TempId}")]
  888. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  889. public async Task<IActionResult> GroupOrderPreMobileInfo([FromRoute] GroupOrderPreInfoDto dto)
  890. {
  891. return Ok(await _grpOrderPreInfoRep.MobileInfoAsync(dto.Id, dto.TempId));
  892. }
  893. /// <summary>
  894. /// 团组前期信息 Save
  895. /// </summary>
  896. /// <param name="dto">Id</param>
  897. /// <returns></returns>
  898. [HttpPost]
  899. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  900. public async Task<IActionResult> GroupOrderPreInfoSave(GroupOrderPreInfoOpDto dto)
  901. {
  902. return Ok(await _grpOrderPreInfoRep.OpAsync(dto));
  903. }
  904. /// <summary>
  905. /// 团组前期信息 Del
  906. /// </summary>
  907. /// <param name="dto">Id</param>
  908. /// <returns></returns>
  909. [HttpPost]
  910. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  911. public async Task<IActionResult> GroupOrderPreInfoDel(GroupOrderPreInfoDelDto dto)
  912. {
  913. return Ok(await _grpOrderPreInfoRep.DelAsync(dto));
  914. }
  915. /// <summary>
  916. /// 团组前期信息 文件下载
  917. /// </summary>
  918. /// <param name="dto">Id</param>
  919. /// <returns></returns>
  920. [HttpGet("{Id}/{TempId}")]
  921. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  922. public async Task<IActionResult> GroupOrderPreInfoFileDownload([FromRoute] GroupOrderPreInfoDto dto)
  923. {
  924. int id = dto.Id, tempId = dto.TempId;
  925. var view = await _grpOrderPreInfoRep.InfoAsync(id, tempId);
  926. var data = view.Data as GrpOrderPreInfoView;
  927. #region Excel
  928. var tempPath = AppSettingsHelper.Get("ExcelTempPath");
  929. var servicePath = AppSettingsHelper.Get("GrpFileBaseUrl");
  930. var savePath = AppSettingsHelper.Get("ExcelBasePath") + "GroupOrderPreInfo/";
  931. var ftpPath = AppSettingsHelper.Get("ExcelFtpPath") + "GroupOrderPreInfo/";
  932. var fileNamePrefix = string.Empty;
  933. if (tempId == 1405)
  934. {
  935. tempPath += $"前期需客户提供信息_无商邀版Temp.xlsx";
  936. fileNamePrefix = $"{data.Name}_无商邀版";
  937. }
  938. else if (tempId == 1406)
  939. {
  940. tempPath += $"前期需客户提供信息_有商邀版Temp.xlsx";
  941. fileNamePrefix = $"{data.Name}_有商邀版";
  942. }
  943. else
  944. {
  945. //tempId == 1404 默认下载
  946. tempPath += $"前期需客户提供信息_单接送机Temp.xlsx";
  947. fileNamePrefix = $"{data.Name}_单接送机";
  948. }
  949. foreach (var item in data.Items)
  950. {
  951. var obj = item.NewValue;
  952. if (obj == null) item.OriginVal = "";
  953. else if (obj.Equals("有") || obj.Equals("无"))
  954. {
  955. item.OriginVal = obj.ToString();
  956. }
  957. else if (obj is object[] objArray)
  958. {
  959. string[] stringArray = Array.ConvertAll(objArray, item => item?.ToString() ?? string.Empty);
  960. item.OriginVal = string.Join("、", stringArray);
  961. }
  962. else if (obj is string[] stringArray)
  963. {
  964. item.OriginVal = string.Join("、", stringArray);
  965. }
  966. else if (obj.Equals("-"))
  967. {
  968. item.OriginVal = "";
  969. }
  970. }
  971. var fileName = $"{fileNamePrefix}{CommonFun.GUID}.xlsx";
  972. fileName = CommonFun.ValidFileName(fileName);
  973. //载入模板
  974. var designer = new WorkbookDesigner
  975. {
  976. Workbook = new Workbook(tempPath)
  977. };
  978. if (tempId == 1406)
  979. {
  980. var view1 = data.Items.Where(x => x.Index < 11).ToArray();
  981. var view2 = data.Items.Where(x => x.Index > 10).ToArray();
  982. for (int i = 1; i <= view2.Length; i++)
  983. {
  984. view2[i - 1].Index = i;
  985. }
  986. designer.SetDataSource("View1", view1);
  987. designer.SetDataSource("View2", view2);
  988. }
  989. else
  990. {
  991. designer.SetDataSource("View", data.Items);
  992. }
  993. designer.Process();
  994. if (!Directory.Exists(savePath))
  995. {
  996. Directory.CreateDirectory(savePath);
  997. }
  998. string serverPath = $"{savePath}{fileName}";
  999. designer.Workbook.Save(serverPath);
  1000. string rst = $"{servicePath}{ftpPath}{fileName}";
  1001. #endregion
  1002. return Ok(JsonView(new { url = rst }));
  1003. }
  1004. #endregion
  1005. #region 团组基本信息
  1006. /// <summary>
  1007. /// 接团信息列表
  1008. /// </summary>
  1009. /// <param name="dto">团组列表请求dto</param>
  1010. /// <returns></returns>
  1011. [HttpPost]
  1012. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1013. public async Task<IActionResult> GetGroupList(GroupListDto dto)
  1014. {
  1015. var groupData = await _groupRepository.GetGroupList(dto);
  1016. if (groupData.Code != 0)
  1017. {
  1018. return Ok(JsonView(false, groupData.Msg));
  1019. }
  1020. return Ok(JsonView(groupData.Data));
  1021. }
  1022. /// <summary>
  1023. /// 分页查询团组列表
  1024. /// </summary>
  1025. /// <param name="dto"></param>
  1026. /// <returns></returns>
  1027. [HttpPost]
  1028. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1029. public async Task<IActionResult> QueryGroupListOffset(QueryGroupListOffsetDto dto)
  1030. {
  1031. var watch = new Stopwatch();
  1032. watch.Start();
  1033. RefAsync<int> total = 0;
  1034. var countyDatas = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  1035. .Where((di) => di.IsDel == 0 && !string.IsNullOrWhiteSpace(di.TeamName))
  1036. .WhereIF(!string.IsNullOrEmpty(dto.Search), (di) => di.TeamName.Contains(dto.Search))
  1037. .OrderBy((di) => new { id = SqlFunc.Desc(di.Id) })
  1038. .Select((di) => new { id = di.Id, name = di.TeamName, di.ClientName, di.VisitPNumber, di.VisitCountry, di.VisitDays, di.VisitStartDate, di.VisitEndDate, di.TourCode })
  1039. .Distinct()
  1040. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  1041. watch.Stop();
  1042. return Ok(JsonView(true, $"{MsgTips.Succeed},耗时 {watch.ElapsedMilliseconds} ms", countyDatas, total));
  1043. }
  1044. /// <summary>
  1045. /// 接团信息列表 Page Init
  1046. /// </summary>
  1047. /// <returns></returns>
  1048. [HttpPost]
  1049. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1050. public async Task<IActionResult> PostGroupPageListInit()
  1051. {
  1052. var depDatas = await GeneralMethod.GroupOpAffiliationBranchInit();
  1053. var rankDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 56).Select(x => new { x.Id, x.Name }).ToListAsync();
  1054. rankDatas.Insert(0, new { Id = 0, Name = "全部" });
  1055. var _view = new
  1056. {
  1057. depData = depDatas,
  1058. rankData = rankDatas
  1059. };
  1060. return Ok(JsonView(true, "查询成功!", _view));
  1061. }
  1062. /// <summary>
  1063. /// 接团信息列表 关键字输入提示
  1064. /// </summary>
  1065. /// <param name="keyword">关键字</param>
  1066. /// <returns></returns>
  1067. [HttpGet]
  1068. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1069. public async Task<IActionResult> GroupItemNativeKeywordSearch(string keyword)
  1070. {
  1071. var jw = JsonView(true, "暂无数据");
  1072. if (string.IsNullOrEmpty(keyword)) return Ok(jw);
  1073. var expression = Expressionable
  1074. .Create<Grp_DelegationInfo>()
  1075. .And(x => x.IsDel == 0);
  1076. string field = "TeamName,ClientUnit,ClientName";
  1077. var groupData = _sqlSugar.Queryable<Grp_DelegationInfo>()
  1078. .Where(expression.ToExpression())
  1079. .Select(field)
  1080. .ToList();
  1081. var keywordArray = keyword.ToCharArray();
  1082. var matches = groupData
  1083. .Where(fullString => !string.IsNullOrWhiteSpace(fullString.TeamName) &&
  1084. keywordArray.All(keyword => fullString.TeamName.Contains(keyword)))
  1085. .Select(x => new
  1086. {
  1087. x.TeamName,
  1088. x.ClientUnit,
  1089. x.ClientName
  1090. })
  1091. .DistinctBy(x => x.TeamName)
  1092. .ToList();
  1093. if (matches.Any())
  1094. {
  1095. jw.Code = StatusCodes.Status200OK;
  1096. jw.Msg = "搜索成功";
  1097. jw.Data = matches;
  1098. jw.Count = matches.Count;
  1099. }
  1100. return Ok(jw);
  1101. }
  1102. /// <summary>
  1103. /// 接团信息列表 关键字输入提示(智能版)
  1104. /// </summary>
  1105. /// <param name="keyword">关键字</param>
  1106. /// <returns></returns>
  1107. [HttpGet]
  1108. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1109. public async Task<IActionResult> GroupItemKeywordSearch(string keyword)
  1110. {
  1111. try
  1112. {
  1113. // 验证请求参数
  1114. if (string.IsNullOrEmpty(keyword))
  1115. {
  1116. return Ok(JsonView(true, $"暂无数据!"));
  1117. }
  1118. var searchRequest = new DynamicSearchRequest
  1119. {
  1120. Keyword = keyword,
  1121. RequireAllSingleChars = true,
  1122. PageIndex = 1,
  1123. PageSize = 999999,
  1124. FieldWeights = new Dictionary<string, int>
  1125. {
  1126. { "TeamName", 10 }
  1127. },
  1128. Filters = new List<SearchFilter>()
  1129. {
  1130. new(){Field = "IsDel",Operator="eq",Value="0" }
  1131. },
  1132. OrderBy = "VisitDate",
  1133. ReturnFields = new List<string>() { "TeamName", "ClientUnit", "ClientName" }
  1134. };
  1135. // 验证字段配置
  1136. var validation = _groupSearchService.ValidateFieldConfig(
  1137. searchRequest.FieldWeights,
  1138. searchRequest.ReturnFields);
  1139. if (!validation.IsValid)
  1140. {
  1141. return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
  1142. }
  1143. var result = await _groupSearchService.SearchAsync(searchRequest);
  1144. if (result.Success)
  1145. {
  1146. var data = new List<dynamic>();
  1147. foreach (var item in result.Items)
  1148. {
  1149. data.Add(new
  1150. {
  1151. item.Data.TeamName,
  1152. item.Data.ClientUnit,
  1153. item.Data.ClientName,
  1154. //item.Data.VisitDate
  1155. });
  1156. }
  1157. return Ok(JsonView(true, result.Message, data, data.Count));
  1158. }
  1159. return Ok(JsonView(true, result.Message));
  1160. }
  1161. catch (Exception ex)
  1162. {
  1163. return Ok(JsonView(true, $"搜索服务暂时不可用!"));
  1164. }
  1165. }
  1166. /// <summary>
  1167. /// 接团信息列表 Page
  1168. /// </summary>
  1169. /// <param name="dto">团组列表请求dto</param>
  1170. /// <returns></returns>
  1171. [HttpPost]
  1172. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1173. public async Task<IActionResult> PostGroupPageList(GroupPageListDto dto)
  1174. {
  1175. // 创建Stopwatch实例
  1176. var stopwatch = new Stopwatch();
  1177. stopwatch.Start();
  1178. #region 参数验证
  1179. if (dto.UserId < 1)
  1180. return Ok(JsonView(false, "员工Id为空"));
  1181. if (dto.PageId < 1)
  1182. return Ok(JsonView(false, "页面Id为空"));
  1183. #region 页面操作权限验证
  1184. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1185. if (pageFunAuthView.CheckAuth == 0)
  1186. return Ok(JsonView(false, "您没有查看权限"));
  1187. #endregion
  1188. #endregion
  1189. //if (dto.PortType != 1 && dto.PortType != 2) // web/Android
  1190. // return Ok(JsonView(false, "不支持的端口类型"));
  1191. // 构建查询条件
  1192. var sqlWhereBuilder = new StringBuilder(" WHERE gdi.IsDel = 0");
  1193. var parameters = new List<SugarParameter>();
  1194. // 完成状态筛选
  1195. if (dto.IsSure == 0 || dto.IsSure == 1)
  1196. {
  1197. sqlWhereBuilder.Append(" AND gdi.IsSure = @IsSure");
  1198. parameters.Add(new SugarParameter("@IsSure", dto.IsSure));
  1199. }
  1200. // 搜索条件
  1201. if (!string.IsNullOrWhiteSpace(dto.SearchCriteria))
  1202. {
  1203. var searchParam = $"%{dto.SearchCriteria.Trim()}%";
  1204. sqlWhereBuilder.Append(@"
  1205. AND (ssd.Name LIKE @SearchCriteria
  1206. OR gdi.TeamName LIKE @SearchCriteria
  1207. OR gdi.ClientName LIKE @SearchCriteria
  1208. OR su.CnName LIKE @SearchCriteria)");
  1209. parameters.Add(new SugarParameter("@SearchCriteria", searchParam));
  1210. }
  1211. // 等级筛选
  1212. if (int.TryParse(dto.Rank, out int rankId) && rankId > 0)
  1213. {
  1214. sqlWhereBuilder.Append(" AND gdi.TeamLevSId = @RankId");
  1215. parameters.Add(new SugarParameter("@RankId", rankId));
  1216. }
  1217. // 部门筛选
  1218. var departmentWhere = string.Empty;
  1219. if (!string.IsNullOrWhiteSpace(dto.Department) && !dto.Department.Equals("全部"))
  1220. {
  1221. departmentWhere = " WHERE Department = @Department";
  1222. parameters.Add(new SugarParameter("@Department", dto.Department));
  1223. }
  1224. // 构建SQL查询
  1225. string sql = $@"
  1226. SELECT Row_Number, Id, SalesQuoteNo, TourCode, TeamTypeId, TeamType, Department,
  1227. TeamLevId, TeamLev, TeamName, ClientName, ClientUnit,
  1228. VisitDate, VisitDays, VisitPNumber, JietuanOperatorId,
  1229. JietuanOperator, IsSure, CreateTime, IsBid, Step,
  1230. CONVERT(VARCHAR(19), StepOperationTime, 20) AS StepOperationTime
  1231. FROM (
  1232. SELECT ROW_NUMBER() OVER(ORDER BY gdi.VisitStartDate DESC) AS Row_Number,
  1233. CASE
  1234. WHEN gdi.JietuanOperator IN (4, 21) THEN '国交部'
  1235. ELSE (SELECT DepName FROM OA2023DB.dbo.Sys_Department WHERE Id = su.DepId)
  1236. END AS 'Department',
  1237. gdi.Id, SalesQuoteNo, TourCode, ssd.Id AS TeamTypeId, ssd.Name AS TeamType, gdi.Step,
  1238. ssd1.Id AS TeamLevId, ssd1.Name AS TeamLev, TeamName, ClientName, ClientUnit,
  1239. VisitDate, VisitDays, VisitPNumber, JietuanOperator AS JietuanOperatorId,
  1240. su.CnName AS JietuanOperator, IsSure, gdi.CreateTime, gdi.IsBid,StepOperationTime
  1241. FROM Grp_DelegationInfo gdi
  1242. LEFT JOIN Sys_SetData ssd ON gdi.TeamDid = ssd.Id
  1243. LEFT JOIN Sys_SetData ssd1 ON gdi.TeamLevSId = ssd1.Id
  1244. LEFT JOIN Sys_Users su ON gdi.JietuanOperator = su.Id
  1245. {sqlWhereBuilder}
  1246. ) temp {departmentWhere}";
  1247. // 执行分页查询
  1248. RefAsync<int> total = 0;
  1249. var delegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql)
  1250. .AddParameters(parameters)
  1251. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  1252. if (!delegationList.Any())
  1253. {
  1254. var emptyView = new
  1255. {
  1256. PageFuncAuth = pageFunAuthView,
  1257. Data = delegationList
  1258. };
  1259. return Ok(JsonView(true, "查询成功,暂无数据", emptyView, total));
  1260. }
  1261. // 批量处理团组模块实际操作人和背景颜色设置
  1262. await ProcessDelegationListData(delegationList);
  1263. var resultView = new
  1264. {
  1265. PageFuncAuth = pageFunAuthView,
  1266. Data = delegationList
  1267. };
  1268. stopwatch.Stop();
  1269. return Ok(JsonView(true, $"查询成功!耗时:{stopwatch.Elapsed.TotalSeconds:F3}s", resultView, total));
  1270. }
  1271. /// <summary>
  1272. /// 批量处理团组数据
  1273. /// </summary>
  1274. private async Task ProcessDelegationListData(List<DelegationListView> delegationList)
  1275. {
  1276. var groupIds = delegationList.Select(x => x.Id).ToList();
  1277. // 批量查询信用卡支付记录
  1278. var creditCardPayments = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  1279. .Where(y => groupIds.Contains(y.DIId) && y.IsDel == 0)
  1280. .Select(y => y.DIId)
  1281. .Distinct()
  1282. .ToListAsync();
  1283. // 批量查询费用确认记录
  1284. var feeAcknowledgements = await _sqlSugar.Queryable<Grp_FeeEntryAcknowledge>()
  1285. .Where(y => groupIds.Contains(y.GroupId) && y.IsDel == 0)
  1286. .Where(y => y.IsAcknowledged == AcknowledgeStatusEnum.Acknowledged)
  1287. .Select(y => y.GroupId)
  1288. .Distinct()
  1289. .ToListAsync();
  1290. var creditCardPaymentSet = creditCardPayments.ToHashSet();
  1291. var feeAcknowledgementSet = feeAcknowledgements.ToHashSet();
  1292. // 并行处理每个团组
  1293. var tasks = delegationList.Select(async x =>
  1294. {
  1295. // 处理团组模块实际操作人
  1296. var operators = GeneralMethod.GetGroupModuleOperators(x.Id);
  1297. var operatorNames = new StringBuilder();
  1298. if (operators.Any())
  1299. {
  1300. foreach (var operatorInfo in operators)
  1301. {
  1302. string label = operatorInfo.OperationUsers.Any()
  1303. ? string.Join('、', operatorInfo.OperationUsers.Select(u => u.UserName))
  1304. : "暂未指定";
  1305. operatorNames.AppendLine($"{operatorInfo.CTableName}:{label}");
  1306. operatorNames.AppendLine();
  1307. }
  1308. }
  1309. x.OperatorLabel = operatorNames.ToString().TrimEnd('\n', '\r');
  1310. // 设置背景颜色为红色
  1311. // C表没数据并且没点提醒确认按钮(无成本费用按钮)的团组该行显示红色
  1312. bool hasCreditCardPayment = creditCardPaymentSet.Contains(x.Id);
  1313. bool hasFeeAcknowledgement = feeAcknowledgementSet.Contains(x.Id);
  1314. x.UseRedBackground = !hasCreditCardPayment && !hasFeeAcknowledgement;
  1315. });
  1316. await Task.WhenAll(tasks);
  1317. }
  1318. /// <summary>
  1319. /// 团组列表
  1320. /// </summary>
  1321. /// <returns></returns>
  1322. [HttpPost]
  1323. public async Task<IActionResult> GetGroupListByWhere(GroupListByWhere dto)
  1324. {
  1325. #region 参数验证
  1326. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  1327. if (dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  1328. #region 页面操作权限验证
  1329. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1330. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  1331. #endregion
  1332. #endregion
  1333. if (dto.PortType != 1 && dto.PortType != 2)
  1334. {
  1335. return Ok(JsonView(false, "查询失败!"));
  1336. }
  1337. string orderbyStr = "order by gdi.CreateTime Desc";
  1338. string sqlWhere = string.Empty;
  1339. if (dto.IsSure == 0) //未完成
  1340. {
  1341. sqlWhere += string.Format(@" And IsSure = 0");
  1342. }
  1343. else if (dto.IsSure == 1) //已完成
  1344. {
  1345. sqlWhere += string.Format(@" And IsSure = 1");
  1346. }
  1347. //团组类型
  1348. if (dto.TeamDid > 0)
  1349. {
  1350. sqlWhere += string.Format(@"And TeamDid = {0} ", dto.TeamDid);
  1351. }
  1352. //团组名称
  1353. if (!string.IsNullOrEmpty(dto.TeamName))
  1354. {
  1355. sqlWhere += string.Format(@"And TeamName Like '%{0}%'", dto.TeamName);
  1356. }
  1357. //客户名称
  1358. if (!string.IsNullOrEmpty(dto.ClientName))
  1359. {
  1360. sqlWhere += string.Format(@"And ClientName Like '%{0}%'", dto.ClientName);
  1361. }
  1362. //客户单位
  1363. if (!string.IsNullOrEmpty(dto.ClientUnit))
  1364. {
  1365. sqlWhere += string.Format(@"And ClientUnit Like '%{0}%'", dto.ClientUnit);
  1366. }
  1367. //出访时间
  1368. if (!string.IsNullOrEmpty(dto.visitDataTime))
  1369. {
  1370. sqlWhere += string.Format(@"And VisitDate >= '{0}'", dto.visitDataTime);
  1371. orderbyStr = "order by gdi.VisitDate";
  1372. }
  1373. string sql = string.Format(@"Select Row_Number,Id,SalesQuoteNo,TourCode,TeamTypeId, TeamType,
  1374. TeamLevId,TeamLev,TeamName,ClientName,ClientUnit,
  1375. VisitDate,VisitDays,VisitPNumber,JietuanOperatorId,
  1376. JietuanOperator,IsSure,CreateTime
  1377. From (
  1378. Select row_number() over({0}) as Row_Number,
  1379. gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,
  1380. ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,
  1381. VisitDate,VisitDays,VisitPNumber,JietuanOperator JietuanOperatorId,
  1382. su.CnName JietuanOperator,IsSure,gdi.CreateTime
  1383. From Grp_DelegationInfo gdi
  1384. Left Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  1385. Left Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  1386. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  1387. Where gdi.IsDel = 0 {1}
  1388. ) temp ", orderbyStr, sqlWhere);
  1389. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  1390. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);//ToPageAsync
  1391. #region 处理所属部门
  1392. /*
  1393. * 1.sq 和 gyy 等显示 市场部
  1394. * 2.王鸽和主管及张总还有管理员号统一国交部
  1395. * 2-1. 4 管理员 ,21 张海麟
  1396. */
  1397. var userIds = _DelegationList.Select(it => it.JietuanOperatorId).ToList();
  1398. var userIds1 = new List<int>() { 4, 21 };
  1399. var UserDepDatas = _sqlSugar.Queryable<Sys_Users>()
  1400. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  1401. .Where(u => u.IsDel == 0 && userIds.Contains(u.Id))
  1402. .Select((u, d) => new { UserId = u.Id, DepName = userIds1.Contains(u.Id) ? "国交部" : d.DepName })
  1403. .ToList();
  1404. foreach (var item in _DelegationList)
  1405. {
  1406. item.Department = UserDepDatas.Find(it => item.JietuanOperatorId == it.UserId)?.DepName ?? "Unknown";
  1407. }
  1408. #endregion
  1409. var _view = new
  1410. {
  1411. PageFuncAuth = pageFunAuthView,
  1412. Data = _DelegationList
  1413. };
  1414. return Ok(JsonView(true, $"查询成功!", _view, total));
  1415. }
  1416. /// <summary>
  1417. /// 接团信息详情
  1418. /// </summary>
  1419. /// <param name="dto">团组info请求dto</param>
  1420. /// <returns></returns>
  1421. [HttpPost]
  1422. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1423. public async Task<IActionResult> GetGroupInfo(GroupInfoDto dto)
  1424. {
  1425. var groupData = await _groupRepository.GetGroupInfo(dto);
  1426. if (groupData.Code != 0)
  1427. {
  1428. return Ok(JsonView(false, groupData.Msg));
  1429. }
  1430. return Ok(JsonView(groupData.Data));
  1431. }
  1432. /// <summary>
  1433. /// 接团信息 编辑添加
  1434. /// 基础信息数据源
  1435. /// </summary>
  1436. /// <param name="dto"></param>
  1437. /// <returns></returns>
  1438. [HttpPost]
  1439. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1440. public async Task<IActionResult> GroupEditBasicSource(GroupListDto dto)
  1441. {
  1442. var groupData = await _groupRepository.GroupEditBasicSource(dto);
  1443. if (groupData.Code != 0)
  1444. {
  1445. return Ok(JsonView(false, groupData.Msg));
  1446. }
  1447. return Ok(JsonView(groupData.Data));
  1448. }
  1449. /// <summary>
  1450. /// 成本修改团组信息
  1451. /// </summary>
  1452. /// <param name="dto"></param>
  1453. /// <returns></returns>
  1454. [HttpPost]
  1455. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1456. public async Task<IActionResult> GroupCostEditGroupInfo(GroupCostEditGroupInfoDto dto)
  1457. {
  1458. var jw = JsonView(false, "操作失败");
  1459. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  1460. if (di == null)
  1461. {
  1462. jw.Msg = "参数有误!";
  1463. return Ok(jw);
  1464. }
  1465. #region 添加出访起止时间
  1466. var startTime = new DateTime();
  1467. var endTime = new DateTime();
  1468. if (DateTime.TryParse(dto.VisitDate, out startTime))
  1469. {
  1470. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  1471. }
  1472. else
  1473. {
  1474. jw.Msg = "参数有误!";
  1475. return Ok(jw);
  1476. }
  1477. #endregion
  1478. #region 验证出访时间是否有变化 有变化则重新生成倒推表
  1479. if (!startTime.ToString("yyyy-MM-dd").Equals(di.VisitDate.ToString("yyyy-MM-dd")))
  1480. {
  1481. var msg = "团组成本模块修改出访时间,删除倒推表重新生成";
  1482. var softDel = await _sqlSugar.Updateable<Grp_InvertedList>()
  1483. .SetColumns(x => x.IsDel == 1)
  1484. .SetColumns(x => x.DeleteUserId == 4)
  1485. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  1486. .SetColumns(x => x.Remark == msg)
  1487. .Where(x => x.DiId == dto.Diid)
  1488. .ExecuteCommandAsync();
  1489. //默认创建倒推表
  1490. await _invertedListRep.Create(4, dto.Diid, msg);
  1491. }
  1492. #endregion
  1493. di.VisitDate = startTime;
  1494. di.VisitPNumber = dto.VisitPNumber;
  1495. di.VisitDays = dto.VisitDays;
  1496. di.VisitStartDate = startTime;
  1497. di.VisitEndDate = endTime;
  1498. var count = _sqlSugar.Updateable(di)
  1499. .UpdateColumns(x => new { x.VisitDate, x.VisitPNumber, x.VisitDays, x.VisitStartDate, x.VisitEndDate })
  1500. .ExecuteCommand();
  1501. return Ok(count > 0 ? JsonView(true, "操作成功") : jw);
  1502. }
  1503. /// <summary>
  1504. /// 接团信息 编辑添加
  1505. /// 省份-城市 基础信息数据源
  1506. /// </summary>
  1507. /// <param name="dto"></param>
  1508. /// <returns></returns>
  1509. [HttpPost]
  1510. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1511. public async Task<IActionResult> GroupProvCityBasicSource(GroupProvCityBasicSourceDto dto)
  1512. {
  1513. int pageIndex = dto.PageIndex, pageSize = dto.PageSize;
  1514. string search = dto.Search;
  1515. var data = await _groupRepository.CityBasicSource();
  1516. int total = data.Length;
  1517. data = data.WhereIF(!string.IsNullOrEmpty(search), x => x.Name.Contains(search))
  1518. .Skip((pageIndex - 1) * pageSize)
  1519. .Take(pageSize)
  1520. .ToArray();
  1521. return Ok(JsonView(data, total));
  1522. }
  1523. /// <summary>
  1524. /// 接团信息 操作(增改)
  1525. /// </summary>
  1526. /// <param name="dto"></param>
  1527. /// <returns></returns>
  1528. [HttpPost]
  1529. [ApiLog("Grp_DelegationInfo", OperationEnum.Edit)]
  1530. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1531. public async Task<IActionResult> GroupOperation(GroupOperationDto dto)
  1532. {
  1533. // 创建 Stopwatch 实例
  1534. Stopwatch stopwatch = Stopwatch.StartNew();
  1535. decimal ffrPrice = 0.00M;
  1536. DateTime? visitDt = null;
  1537. if (dto.Status == 2)
  1538. {
  1539. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.Id && x.IsDel == 0);
  1540. if (groupInfo != null)
  1541. {
  1542. ffrPrice = groupInfo.PaymentMoney;
  1543. visitDt = groupInfo.VisitDate.AddDays(-groupInfo.PayDay);
  1544. #region 验证出访时间是否有变化 有变化则重新生成倒推表
  1545. if (DateTime.TryParse(dto.VisitDate, out DateTime startTime))
  1546. {
  1547. if (!startTime.ToString("yyyy-MM-dd").Equals(groupInfo.VisitDate.ToString("yyyy-MM-dd")))
  1548. {
  1549. var msg = "团组信息模块修改出访时间,删除倒推表重新生成";
  1550. var softDel = await _sqlSugar.Updateable<Grp_InvertedList>()
  1551. .SetColumns(x => x.IsDel == 1)
  1552. .SetColumns(x => x.DeleteUserId == 4)
  1553. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  1554. .SetColumns(x => x.Remark == msg)
  1555. .Where(x => x.DiId == dto.Id)
  1556. .ExecuteCommandAsync();
  1557. //默认创建倒推表
  1558. await _invertedListRep.Create(dto.UserId, dto.Id, msg);
  1559. }
  1560. }
  1561. #endregion
  1562. }
  1563. }
  1564. var groupData = await _groupRepository.GroupOperation(dto);
  1565. if (groupData.Code != 0)
  1566. {
  1567. return Ok(JsonView(false, groupData.Msg));
  1568. }
  1569. int diId = 0;
  1570. try
  1571. {
  1572. //添加时 默认加入团组汇率
  1573. if (dto.Status == 1) //添加
  1574. {
  1575. diId = groupData.Data;
  1576. //添加默认币种
  1577. await GeneralMethod.PostGroupRateAddInit(dto.UserId, diId);
  1578. //默认分配权限
  1579. await GeneralMethod.PostGroupAuthAddInit(dto.UserId, diId);
  1580. //消息提示 王鸽 主管号 2024-10-21 新增LZ UID
  1581. var _managerIds = new List<int>() { 22, 32, 21 };
  1582. var userIds = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && _managerIds.Contains(it.JobPostId)).Select(it => it.Id).ToList();
  1583. if (userIds.Count > 0)
  1584. {
  1585. userIds.Add(208);
  1586. //创建团组管控
  1587. GroupStepForDelegation.CreateWorkStep(diId);
  1588. //发送消息
  1589. string groupName = dto.TeamName;
  1590. string createGroupUser = string.Empty;
  1591. var userInfo = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.Id == dto.UserId).First();
  1592. if (userInfo != null) createGroupUser = userInfo.CnName;
  1593. string title = $"系统通知";
  1594. string content = $"团组[{groupName}(创建人:{createGroupUser})]创建成功,请前往页面进行下一步操作!";
  1595. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  1596. }
  1597. //默认创建倒推表
  1598. await _invertedListRep.Create(dto.UserId, diId);
  1599. //默认创建签证流程
  1600. await _visaProcessRep.Create(dto.UserId, diId);
  1601. //默认创建团组流程总览信息
  1602. await _processOverviewRep.ProcessInitAsync(diId, dto.UserId);
  1603. }
  1604. else if (dto.Status == 2)
  1605. {
  1606. diId = dto.Id;
  1607. }
  1608. #region 签证人员团组时间通知
  1609. #region 计算出访起止时间
  1610. var startTime = new DateTime();
  1611. var endTime = new DateTime();
  1612. if (DateTime.TryParse(dto.VisitDate, out startTime))
  1613. {
  1614. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  1615. }
  1616. #endregion
  1617. #endregion
  1618. #region 团组操作默认添加/修改收款账单
  1619. if (dto.PayDay > 0 && dto.PaymentMoney > 0)
  1620. {
  1621. var ffrInfo = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  1622. .Where(x => x.IsDel == 0 &&
  1623. x.Diid == diId &&
  1624. x.Remark.Equals("预付款")
  1625. )
  1626. .WhereIF(ffrPrice > 0, x => x.ItemSumPrice == ffrPrice)
  1627. .WhereIF(visitDt != null, x => x.CreateTime == visitDt)
  1628. .FirstAsync();
  1629. ffrInfo = new Fin_ForeignReceivables()
  1630. {
  1631. Diid = diId,
  1632. PriceName = dto.ClientUnit,
  1633. Price = dto.PaymentMoney,
  1634. Count = 1,
  1635. Unit = $"元",
  1636. ItemSumPrice = dto.PaymentMoney,
  1637. Rate = 1.0000M,
  1638. Currency = 836,
  1639. AddingWay = 0,
  1640. CreateUserId = dto.UserId,
  1641. CreateTime = Convert.ToDateTime(dto.VisitDate).AddDays(-dto.PayDay),
  1642. Remark = $"预付款"
  1643. };
  1644. if (ffrInfo == null) //Add
  1645. {
  1646. await _sqlSugar.Insertable(ffrInfo).ExecuteCommandAsync();
  1647. }
  1648. else //修改
  1649. {
  1650. await _sqlSugar.Updateable(ffrInfo)
  1651. .UpdateColumns(x => new
  1652. {
  1653. x.PriceName,
  1654. x.Price,
  1655. x.ItemSumPrice,
  1656. x.CreateTime,
  1657. x.CreateUserId
  1658. })
  1659. .WhereColumns(x => x.Id)
  1660. .ExecuteCommandAsync();
  1661. }
  1662. }
  1663. #endregion
  1664. if (diId > 0)
  1665. {
  1666. await AppNoticeLibrary.SendUserMsg_GroupTimeInfo_ToVisaUser(diId, startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"));
  1667. }
  1668. // 停止计时
  1669. stopwatch.Stop();
  1670. return Ok(JsonView(true, $"操作成功!{stopwatch.ElapsedMilliseconds}ms", diId));
  1671. }
  1672. catch (Exception ex)
  1673. {
  1674. // 停止计时
  1675. stopwatch.Stop();
  1676. Logs("[response]" + JsonConvert.SerializeObject(dto));
  1677. Logs(ex.Message);
  1678. //return Ok(JsonView(false, $"{ex.Message}[{stopwatch.ElapsedMilliseconds}ms]"));
  1679. }
  1680. // 停止计时
  1681. stopwatch.Stop();
  1682. return Ok(JsonView(true, $"操作成功!{stopwatch.ElapsedMilliseconds}ms", diId));
  1683. }
  1684. /// <summary>
  1685. /// 团组聚合API测试接口
  1686. /// </summary>
  1687. /// <param name="userId"></param>
  1688. /// <param name="groupId"></param>
  1689. /// <returns></returns>
  1690. [HttpPost]
  1691. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1692. public async Task<IActionResult> GroupJuHeAPITest(int userId, int groupId)
  1693. {
  1694. //添加默认币种
  1695. var currencyData = await GeneralMethod.PostGroupRateAddInit(userId, groupId);
  1696. return Ok(JsonView(true, $"操作成功!", currencyData.Data));
  1697. }
  1698. /// <summary>
  1699. /// 接团流程操作(增改)
  1700. /// 安卓端使用 建团时添加客户名单
  1701. /// </summary>
  1702. /// <param name="dto"></param>
  1703. /// <returns></returns>
  1704. [HttpPost]
  1705. [ApiLog("Grp_DelegationInfo", OperationEnum.Edit)]
  1706. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1707. public async Task<IActionResult> GroupProcessOperation(GroupProcessOperationDto dto)
  1708. {
  1709. #region 参数验证
  1710. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  1711. #region 页面操作权限验证
  1712. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, 104);
  1713. //if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "客户名单您没有添加权限!"));
  1714. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, 27);
  1715. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "团组操作您没有添加权限!"));
  1716. #endregion
  1717. #endregion
  1718. try
  1719. {
  1720. //_sqlSugar.BeginTran();
  1721. decimal ffrPrice = 0.00M;
  1722. DateTime? visitDt = null;
  1723. if (dto.Status == 2)
  1724. {
  1725. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.Id && x.IsDel == 0);
  1726. if (groupInfo != null)
  1727. {
  1728. ffrPrice = groupInfo.PaymentMoney;
  1729. visitDt = groupInfo.VisitDate.AddDays(-groupInfo.PayDay);
  1730. }
  1731. }
  1732. var _dto = new GroupOperationDto();
  1733. _dto = _mapper.Map<GroupProcessOperationDto, GroupOperationDto>(dto);
  1734. var groupData = await _groupRepository.GroupOperation(_dto);
  1735. if (groupData.Code != 0)
  1736. {
  1737. return Ok(JsonView(false, "团组操作添加失败!" + groupData.Msg));
  1738. }
  1739. int diId = 0;
  1740. //添加时 默认加入团组汇率
  1741. if (dto.Status == 1) //添加
  1742. {
  1743. diId = groupData.Data;
  1744. //添加默认币种
  1745. await GeneralMethod.PostGroupRateAddInit(dto.UserId, diId);
  1746. //默认分配权限
  1747. await GeneralMethod.PostGroupAuthAddInit(dto.UserId, diId);
  1748. //消息提示 王鸽 主管号 2024-10-21 新增LZ UID
  1749. var _managerIds = new List<int>() { 21, 22, 32 };
  1750. var userIds = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && _managerIds.Contains(it.JobPostId)).Select(it => it.Id).ToList();
  1751. if (userIds.Count > 0)
  1752. {
  1753. userIds.Add(208);
  1754. //创建团组管控
  1755. GroupStepForDelegation.CreateWorkStep(diId);
  1756. //发送消息
  1757. string groupName = dto.TeamName;
  1758. string createGroupUser = string.Empty;
  1759. var userInfo = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.Id == dto.UserId).First();
  1760. if (userInfo != null) createGroupUser = userInfo.CnName;
  1761. string title = $"系统通知";
  1762. string content = $"团组[{groupName}(创建人:{createGroupUser})]创建成功,请前往页面进行下一步操作!";
  1763. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  1764. }
  1765. #region 应用推送
  1766. try
  1767. {
  1768. await AppNoticeLibrary.SendChatMsg_GroupStatus_Create(diId, QiyeWeChatEnum.CompanyCRMChat);
  1769. Sys_Users users = _airTicketResRep.Query<Sys_Users>(s => s.Id == dto.UserId).First();
  1770. Sys_Department department = _airTicketResRep.Query<Sys_Department>(s => s.Id == users.DepId).First();
  1771. if (department.Id == 6 && !string.IsNullOrEmpty(users.QiyeChatUserId))
  1772. {
  1773. var userList = new List<string>() { users.QiyeChatUserId };
  1774. await AppNoticeLibrary.SendUserMsg_GroupStatus_Create(diId, userList);
  1775. }
  1776. }
  1777. catch (Exception ex)
  1778. {
  1779. }
  1780. #endregion
  1781. //默认创建倒推表
  1782. await _invertedListRep.Create(dto.UserId, diId);
  1783. //默认创建签证流程
  1784. await _visaProcessRep.Create(dto.UserId, diId);
  1785. //默认创建团组流程总览信息
  1786. await _processOverviewRep.ProcessInitAsync(diId, dto.UserId);
  1787. }
  1788. if (dto.Status == 2)
  1789. {
  1790. diId = dto.Id;
  1791. if (diId == 0)
  1792. {
  1793. //_sqlSugar.RollbackTran();
  1794. return Ok(JsonView(false, "修改失败! 未添加团组id" + groupData.Msg));
  1795. }
  1796. }
  1797. var viewData = await _tourClientListRep.OperMultiple(dto.TourClientListInfos, diId, dto.UserId);
  1798. if (viewData.Code != 0)
  1799. {
  1800. //_sqlSugar.RollbackTran();
  1801. return Ok(JsonView(false, "客户名单添加失败!" + viewData.Msg));
  1802. }
  1803. #region 团组操作默认添加/修改收款账单
  1804. if (dto.PayDay > 0 && dto.PaymentMoney > 0)
  1805. {
  1806. var ffrInfo = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  1807. .Where(x => x.IsDel == 0 &&
  1808. x.Diid == diId &&
  1809. x.Remark.Equals("预付款")
  1810. )
  1811. .WhereIF(ffrPrice > 0, x => x.ItemSumPrice == ffrPrice)
  1812. .WhereIF(visitDt != null, x => x.CreateTime == visitDt)
  1813. .FirstAsync();
  1814. ffrInfo = new Fin_ForeignReceivables()
  1815. {
  1816. Diid = diId,
  1817. PriceName = dto.ClientUnit,
  1818. Price = dto.PaymentMoney,
  1819. Count = 1,
  1820. Unit = $"元",
  1821. ItemSumPrice = dto.PaymentMoney,
  1822. Rate = 1.0000M,
  1823. Currency = 836,
  1824. AddingWay = 0,
  1825. CreateUserId = dto.UserId,
  1826. CreateTime = Convert.ToDateTime(dto.VisitDate).AddDays(-dto.PayDay),
  1827. Remark = $"预付款"
  1828. };
  1829. if (ffrInfo == null) //Add
  1830. {
  1831. await _sqlSugar.Insertable(ffrInfo).ExecuteCommandAsync();
  1832. }
  1833. else //修改
  1834. {
  1835. await _sqlSugar.Updateable<Fin_ForeignReceivables>(ffrInfo)
  1836. .UpdateColumns(x => new
  1837. {
  1838. x.PriceName,
  1839. x.Price,
  1840. x.ItemSumPrice,
  1841. x.CreateTime,
  1842. x.CreateUserId
  1843. })
  1844. .WhereColumns(x => x.Id)
  1845. .ExecuteCommandAsync();
  1846. }
  1847. }
  1848. #endregion
  1849. #region 签证人员团组时间通知
  1850. #region 计算出访起止时间
  1851. var startTime = new DateTime();
  1852. var endTime = new DateTime();
  1853. if (DateTime.TryParse(dto.VisitDate, out startTime))
  1854. {
  1855. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  1856. }
  1857. #endregion
  1858. if (diId > 0)
  1859. {
  1860. await AppNoticeLibrary.SendUserMsg_GroupTimeInfo_ToVisaUser(diId, startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"));
  1861. }
  1862. #endregion
  1863. //_sqlSugar.CommitTran();
  1864. return Ok(JsonView(true, "添加成功"));
  1865. }
  1866. catch (Exception ex)
  1867. {
  1868. _sqlSugar.RollbackTran();
  1869. return Ok(JsonView(false, ex.Message));
  1870. }
  1871. }
  1872. /// <summary>
  1873. /// 接团流程操作(增改)
  1874. /// 安卓端使用 建团时添加客户名单
  1875. /// </summary>
  1876. /// <param name="dto"></param>
  1877. /// <returns></returns>
  1878. [HttpPost]
  1879. [ApiLog("Grp_DelegationInfo", OperationEnum.Edit)]
  1880. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1881. public async Task<IActionResult> GroupProcessOperation1(GroupProcessOperationDto dto)
  1882. {
  1883. #region 参数验证
  1884. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  1885. #region 页面操作权限验证
  1886. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, 104);
  1887. //if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "客户名单您没有添加权限!"));
  1888. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, 27);
  1889. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "团组操作您没有添加权限!"));
  1890. #endregion
  1891. #endregion
  1892. _sqlSugar.BeginTran();
  1893. decimal ffrPrice = 0.00M;
  1894. DateTime? visitDt = null;
  1895. if (dto.Status == 2)
  1896. {
  1897. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.Id && x.IsDel == 0);
  1898. if (groupInfo != null)
  1899. {
  1900. ffrPrice = groupInfo.PaymentMoney;
  1901. visitDt = groupInfo.VisitDate.AddDays(-groupInfo.PayDay);
  1902. }
  1903. }
  1904. var _dto = new GroupOperationDto();
  1905. _dto = _mapper.Map<GroupProcessOperationDto, GroupOperationDto>(dto);
  1906. var groupData = await _groupRepository.GroupOperation(_dto);
  1907. if (groupData.Code != 0)
  1908. {
  1909. _sqlSugar.RollbackTran();
  1910. return Ok(JsonView(false, "团组操作添加失败!" + groupData.Msg));
  1911. }
  1912. try
  1913. {
  1914. int diId = 0;
  1915. //添加时 默认加入团组汇率
  1916. if (dto.Status == 1) //添加
  1917. {
  1918. diId = groupData.Data;
  1919. //添加默认币种
  1920. await GeneralMethod.PostGroupRateAddInit(dto.UserId, diId);
  1921. //默认分配权限
  1922. await GeneralMethod.PostGroupAuthAddInit(dto.UserId, diId);
  1923. //消息提示 王鸽 主管号 2024-10-21 新增LZ UID
  1924. var _managerIds = new List<int>() { 21, 22, 32 };
  1925. var userIds = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && _managerIds.Contains(it.JobPostId)).Select(it => it.Id).ToList();
  1926. if (userIds.Count > 0)
  1927. {
  1928. userIds.Add(208);
  1929. //创建团组管控
  1930. GroupStepForDelegation.CreateWorkStep(diId);
  1931. //发送消息
  1932. string groupName = dto.TeamName;
  1933. string createGroupUser = string.Empty;
  1934. var userInfo = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.Id == dto.UserId).First();
  1935. if (userInfo != null) createGroupUser = userInfo.CnName;
  1936. string title = $"系统通知";
  1937. string content = $"团组[{groupName}(创建人:{createGroupUser})]创建成功,请前往页面进行下一步操作!";
  1938. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  1939. }
  1940. #region 应用推送
  1941. try
  1942. {
  1943. await AppNoticeLibrary.SendChatMsg_GroupStatus_Create(diId, QiyeWeChatEnum.CompanyCRMChat);
  1944. Sys_Users users = _airTicketResRep.Query<Sys_Users>(s => s.Id == dto.UserId).First();
  1945. Sys_Department department = _airTicketResRep.Query<Sys_Department>(s => s.Id == users.DepId).First();
  1946. if (department.Id == 6 && !string.IsNullOrEmpty(users.QiyeChatUserId))
  1947. {
  1948. var userList = new List<string>() { users.QiyeChatUserId };
  1949. await AppNoticeLibrary.SendUserMsg_GroupStatus_Create(diId, userList);
  1950. }
  1951. }
  1952. catch (Exception ex)
  1953. {
  1954. _sqlSugar.CommitTran();
  1955. return Ok(JsonView(true, "操作成功! 应用推送异常:" + groupData.Msg));
  1956. }
  1957. #endregion
  1958. //默认创建倒推表
  1959. await _invertedListRep.Create(dto.UserId, diId);
  1960. }
  1961. else if (dto.Status == 2)
  1962. {
  1963. diId = dto.Id;
  1964. if (diId == 0)
  1965. {
  1966. _sqlSugar.RollbackTran();
  1967. return Ok(JsonView(false, "操作失败! 未添加团组id" + groupData.Msg));
  1968. }
  1969. }
  1970. var viewData = await _tourClientListRep.OperMultiple(dto.TourClientListInfos, diId, dto.UserId);
  1971. if (viewData.Code != 0)
  1972. {
  1973. _sqlSugar.RollbackTran();
  1974. return Ok(JsonView(false, "客户名单添加失败!" + viewData.Msg));
  1975. }
  1976. #region 团组操作默认添加/修改收款账单
  1977. if (dto.PayDay > 0 && dto.PaymentMoney > 0)
  1978. {
  1979. var ffrInfo = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  1980. .Where(x => x.IsDel == 0 &&
  1981. x.Diid == diId &&
  1982. x.Remark.Equals("预付款")
  1983. )
  1984. .WhereIF(ffrPrice > 0, x => x.ItemSumPrice == ffrPrice)
  1985. .WhereIF(visitDt != null, x => x.CreateTime == visitDt)
  1986. .FirstAsync();
  1987. ffrInfo = new Fin_ForeignReceivables()
  1988. {
  1989. Diid = diId,
  1990. PriceName = dto.ClientUnit,
  1991. Price = dto.PaymentMoney,
  1992. Count = 1,
  1993. Unit = $"元",
  1994. ItemSumPrice = dto.PaymentMoney,
  1995. Rate = 1.0000M,
  1996. Currency = 836,
  1997. AddingWay = 0,
  1998. CreateUserId = dto.UserId,
  1999. CreateTime = Convert.ToDateTime(dto.VisitDate).AddDays(-dto.PayDay),
  2000. Remark = $"预付款"
  2001. };
  2002. if (ffrInfo == null) //Add
  2003. {
  2004. await _sqlSugar.Insertable(ffrInfo).ExecuteCommandAsync();
  2005. }
  2006. else //修改
  2007. {
  2008. await _sqlSugar.Updateable<Fin_ForeignReceivables>(ffrInfo)
  2009. .UpdateColumns(x => new
  2010. {
  2011. x.PriceName,
  2012. x.Price,
  2013. x.ItemSumPrice,
  2014. x.CreateTime,
  2015. x.CreateUserId
  2016. })
  2017. .WhereColumns(x => x.Id)
  2018. .ExecuteCommandAsync();
  2019. }
  2020. }
  2021. #endregion
  2022. #region 签证人员团组时间通知
  2023. #region 计算出访起止时间
  2024. var startTime = new DateTime();
  2025. var endTime = new DateTime();
  2026. if (DateTime.TryParse(dto.VisitDate, out startTime))
  2027. {
  2028. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  2029. }
  2030. #endregion
  2031. if (diId > 0)
  2032. {
  2033. await AppNoticeLibrary.SendUserMsg_GroupTimeInfo_ToVisaUser(diId, startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"));
  2034. }
  2035. #endregion
  2036. _sqlSugar.CommitTran();
  2037. return Ok(JsonView(true));
  2038. }
  2039. catch (Exception ex)
  2040. {
  2041. _sqlSugar.RollbackTran();
  2042. return Ok(JsonView(false, ex.Message));
  2043. }
  2044. }
  2045. /// <summary>
  2046. /// 接团信息 操作(删除)
  2047. /// </summary>
  2048. /// <param name="dto"></param>
  2049. /// <returns></returns>
  2050. [HttpPost]
  2051. [ApiLog("Grp_DelegationInfo", OperationEnum.Del)]
  2052. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2053. public async Task<IActionResult> GroupDel(GroupDelDto dto)
  2054. {
  2055. var diId = dto.Id;
  2056. if (diId < 1) return Ok(JsonView(false, MsgTips.Id));
  2057. #region 删除 验证
  2058. /*
  2059. * 1、收款账单数据:0 条
  2060. * 2、收款退还数据:0 条
  2061. * 3、机票费用数据:0 条
  2062. * 4、签证费用数据:0 条
  2063. * 5、保险费用数据:0 条
  2064. * 6、酒店费用数据:0 条
  2065. * 7、公务出访数据:1 条
  2066. * 8、邀请公务活动费用数据:1 条
  2067. * 9、OP费用数据:5 条
  2068. * 10、其他费用数据:0 条
  2069. * 11、团组日付报销费用数据:0 条
  2070. *
  2071. * 温馨提示:该团组已产生费用,不允许删除;如需删除,请先删除对应版块费用,谢谢!
  2072. */
  2073. //收款账单
  2074. int frCount = _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(x => x.IsDel == 0 && x.Diid == diId).Count();
  2075. //收款退还
  2076. int fraomCount = _sqlSugar.Queryable<Fin_PaymentRefundAndOtherMoney>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2077. //机票费用
  2078. int arCount = _sqlSugar.Queryable<Grp_AirTicketReservations>().Where(x => x.IsDel == 0 && x.DIId == diId).Count();
  2079. //签证费用
  2080. int viCount = _sqlSugar.Queryable<Grp_VisaInfo>().Where(x => x.IsDel == 0 && x.DIId == diId).Count();
  2081. //保险费用
  2082. int cCount = _sqlSugar.Queryable<Grp_Customers>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2083. //酒店费用
  2084. int hrCount = _sqlSugar.Queryable<Grp_HotelReservations>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2085. //公务出访
  2086. int oaCount = _sqlSugar.Queryable<Res_OfficialActivities>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2087. //邀请公务活动费用
  2088. int ioaCount = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2089. //OP费用
  2090. int ctggrCount = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2091. //其他费用
  2092. int dpCount = _sqlSugar.Queryable<Grp_DecreasePayments>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2093. //团组日付报销费用
  2094. int dfpCount = _sqlSugar.Queryable<Fin_DailyFeePayment>().Where(x => x.IsDel == 0 && x.GroupId == diId).Count();
  2095. var feeCount = frCount + fraomCount + arCount + viCount + cCount + hrCount + oaCount + ioaCount + ctggrCount + dpCount + dfpCount;
  2096. if (feeCount > 0)
  2097. {
  2098. var delMsgTips = new StringBuilder();
  2099. delMsgTips.AppendLine($"1、收款账单数据:{frCount} 条");
  2100. delMsgTips.AppendLine($"2、收款退换数据:{fraomCount} 条");
  2101. delMsgTips.AppendLine($"3、机票费用数据:{arCount} 条");
  2102. delMsgTips.AppendLine($"4、签证费用数据:{viCount} 条");
  2103. delMsgTips.AppendLine($"5、保险费用数据:{cCount} 条");
  2104. delMsgTips.AppendLine($"6、酒店费用数据:{hrCount} 条");
  2105. delMsgTips.AppendLine($"7、公务出访数据:{oaCount} 条");
  2106. delMsgTips.AppendLine($"8、邀请公务活动费用数据:{ioaCount} 条");
  2107. delMsgTips.AppendLine($"9、OP费用数据:{ctggrCount} 条");
  2108. delMsgTips.AppendLine($"10、其他费用数据:{dpCount} 条");
  2109. delMsgTips.AppendLine($"11、团组日付报销费用数据:{dfpCount} 条");
  2110. delMsgTips.AppendLine($"");
  2111. delMsgTips.AppendLine($"温馨提示:该团组已产生费用,不允许删除;如需删除,请先删除对应版块费用,谢谢!");
  2112. return Ok(JsonView(false, delMsgTips.ToString()));
  2113. }
  2114. #endregion
  2115. var groupData = await _groupRepository.GroupDel(dto);
  2116. if (groupData.Code != 0)
  2117. {
  2118. return Ok(JsonView(false, groupData.Msg));
  2119. }
  2120. return Ok(JsonView(true));
  2121. }
  2122. /// <summary>
  2123. /// 获取团组销售报价号
  2124. /// 团组添加时 使用
  2125. /// </summary>
  2126. /// <returns></returns>
  2127. [HttpPost]
  2128. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2129. public async Task<IActionResult> GetGroupSalesQuoteNo()
  2130. {
  2131. var groupData = await _groupRepository.GetGroupSalesQuoteNo();
  2132. if (groupData.Code != 0)
  2133. {
  2134. return Ok(JsonView(false, groupData.Msg));
  2135. }
  2136. object salesQuoteNo = new
  2137. {
  2138. SalesQuoteNo = groupData.Data
  2139. };
  2140. return Ok(JsonView(salesQuoteNo));
  2141. }
  2142. /// <summary>
  2143. /// 设置确认出团
  2144. /// </summary>
  2145. /// <param name="dto"></param>
  2146. /// <returns></returns>
  2147. [HttpPost]
  2148. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2149. public async Task<IActionResult> SetConfirmationGroup(ConfirmationGroupDto dto)
  2150. {
  2151. var groupData = await _groupRepository.ConfirmationGroup(dto);
  2152. if (groupData.Code != 0)
  2153. {
  2154. return Ok(JsonView(false, groupData.Msg));
  2155. }
  2156. var groupInfo = _groupRepository.Query(s => s.Id == dto.GroupId).First();
  2157. #region OA消息推送
  2158. try
  2159. {
  2160. string groupName = groupInfo.TeamName;
  2161. var userIds = _airTicketResRep.Query<Sys_Users>(s => s.DepId == 7 && s.IsDel == 0).Select(x => x.Id).ToList();
  2162. string title = $"系统通知";
  2163. string content = $"团组[{groupName}]已确认出团!";
  2164. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, dto.GroupId);
  2165. }
  2166. catch (Exception ex)
  2167. {
  2168. }
  2169. #endregion
  2170. #region 应用推送
  2171. try
  2172. {
  2173. await AppNoticeLibrary.SendChatMsg_GroupStatus_Create(dto.GroupId, QiyeWeChatEnum.CompanyCRMChat);
  2174. Sys_Users users = _airTicketResRep.Query<Sys_Users>(s => s.Id == groupInfo.JietuanOperator).First();
  2175. Sys_Department department = _airTicketResRep.Query<Sys_Department>(s => s.Id == users.DepId).First();
  2176. if (department.Id == 6 && !string.IsNullOrEmpty(users.QiyeChatUserId))
  2177. {
  2178. var userList = new List<string>() { users.QiyeChatUserId };
  2179. await AppNoticeLibrary.SendUserMsg_GroupStatus_Create(dto.GroupId, userList);
  2180. }
  2181. }
  2182. catch (Exception ex)
  2183. {
  2184. }
  2185. #endregion
  2186. GroupStepForDelegation.CreateWorkStep(dto.GroupId); //创建管控流程
  2187. return Ok(JsonView(true, "操作成功!", groupData.Data));
  2188. }
  2189. /// <summary>
  2190. /// 获取团组名称data And 签证国别Data
  2191. /// </summary>
  2192. /// <param name="dto"></param>
  2193. /// <returns></returns>
  2194. [HttpPost]
  2195. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2196. public async Task<IActionResult> GetGroupNameAndVisaNationality(GroupNameDto dto)
  2197. {
  2198. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  2199. Where TeamName != '' And IsDel = 0
  2200. Order By VisitDate Desc");
  2201. var groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  2202. var data = new
  2203. {
  2204. groupNameData = groupNameList,
  2205. visaNationalityData = _visaTypeInit.ToList()
  2206. };
  2207. return Ok(JsonView(data));
  2208. }
  2209. /// <summary>
  2210. /// 根据CTable类型返回对应的团组名称及简单数据(APP端)
  2211. /// </summary>
  2212. /// <returns></returns>
  2213. [HttpPost]
  2214. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2215. public async Task<IActionResult> PostGroupNameAndEasy(DecreasePaymentsDto dto)
  2216. {
  2217. try
  2218. {
  2219. Result groupData = await _decreasePaymentsRep.PostGroupNameAndEasy(dto);
  2220. if (groupData.Code != 0)
  2221. {
  2222. return Ok(JsonView(false, groupData.Msg));
  2223. }
  2224. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  2225. }
  2226. catch (Exception ex)
  2227. {
  2228. return Ok(JsonView(false, ex.Message));
  2229. throw;
  2230. }
  2231. }
  2232. /// <summary>
  2233. /// 团组清单 Excel
  2234. /// </summary>
  2235. /// <param name="beginDt">开始时间 EG:“2024-01-01”</param>
  2236. /// <param name="endDt">结束时间 EG;“2024-12-31”</param>
  2237. /// <returns></returns>
  2238. [HttpGet]
  2239. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2240. public async Task<IActionResult> GroupListFile([FromQuery] string beginDt, [FromQuery] string endDt)
  2241. {
  2242. bool beginBool = DateTime.TryParse($"{beginDt} 00:00:00", out DateTime _beginDt),
  2243. endBool = DateTime.TryParse($"{endDt} 23:59:59", out DateTime _endDt);
  2244. if (!beginBool && !endBool)
  2245. {
  2246. return Ok(JsonView(false, "开始或结束时间不正确!"));
  2247. }
  2248. string sql = string.Format(@"
  2249. SELECT
  2250. ROW_NUMBER,
  2251. Id,
  2252. SalesQuoteNo,
  2253. TourCode,
  2254. TeamTypeId,
  2255. TeamType,
  2256. TeamLevId,
  2257. TeamLev,
  2258. TeamName,
  2259. ClientName,
  2260. ClientUnit,
  2261. VisitDate,
  2262. VisitDays,
  2263. VisitPNumber,
  2264. JietuanOperatorId,
  2265. JietuanOperator,
  2266. IsSure,
  2267. CreateUserName,
  2268. IsBid
  2269. FROM
  2270. (
  2271. SELECT
  2272. ROW_NUMBER() OVER(
  2273. ORDER BY
  2274. gdi.VisitDate Desc
  2275. ) AS ROW_NUMBER,
  2276. gdi.Id,
  2277. SalesQuoteNo,
  2278. TourCode,
  2279. ssd.Id TeamTypeId,
  2280. ssd.Name TeamType,
  2281. ssd1.Id TeamLevId,
  2282. ssd1.Name TeamLev,
  2283. TeamName,
  2284. ClientName,
  2285. ClientUnit,
  2286. VisitDate,
  2287. VisitDays,
  2288. VisitPNumber,
  2289. JietuanOperator JietuanOperatorId,
  2290. su.CnName JietuanOperator,
  2291. IsSure,
  2292. gdi.CreateTime,
  2293. su1.CnName As CreateUserName,
  2294. gdi.IsBid
  2295. FROM
  2296. Grp_DelegationInfo gdi
  2297. LEFT JOIN Sys_SetData ssd ON gdi.TeamDid = ssd.Id
  2298. LEFT JOIN Sys_SetData ssd1 ON gdi.TeamLevSId = ssd1.Id
  2299. LEFT JOIN Sys_Users su ON gdi.JietuanOperator = su.Id
  2300. LEFT JOIN Sys_Users su1 ON gdi.CreateUserId = su1.Id
  2301. WHERE
  2302. gdi.IsDel = 0
  2303. AND gdi.IsBid = 0
  2304. AND gdi.VisitDate BETWEEN '{0}' AND '{1}'
  2305. ) temp", _beginDt.ToString("yyyy-MM-dd HH:mm:ss"), _endDt.ToString("yyyy-MM-dd HH:mm:ss"));
  2306. var groupList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
  2307. #region 处理所属部门
  2308. /*
  2309. * 1.sq 和 gyy 等显示 市场部
  2310. * 2.王鸽和主管及张总还有管理员号统一国交部
  2311. * 2-1. 4 管理员 ,21 张海麟
  2312. */
  2313. var userIds = groupList.Select(it => it.JietuanOperatorId).ToList();
  2314. var userIds1 = new List<int>() { 4, 21 };
  2315. var userDepDatas = await _sqlSugar.Queryable<Sys_Users>()
  2316. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  2317. .Where(u => u.IsDel == 0 && userIds.Contains(u.Id))
  2318. .Select((u, d) => new { UserId = u.Id, DepName = userIds1.Contains(u.Id) ? "国交部" : d.DepName })
  2319. .ToListAsync();
  2320. var droupIds = groupList.Select(it => it.Id).ToList();
  2321. var deleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  2322. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  2323. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  2324. .Where((tcl, dc, cc) => tcl.IsDel == 0 && droupIds.Contains(tcl.DiId))
  2325. .Select((tcl, dc, cc) => new ClientInfoInfo_Group
  2326. {
  2327. DiId = tcl.DiId,
  2328. LastName = dc.LastName,
  2329. FirstName = dc.FirstName,
  2330. Sex = dc.Sex,
  2331. Birthday = dc.BirthDay,
  2332. Company = cc.CompanyFullName,
  2333. Job = dc.Job,
  2334. CreateTime = tcl.CreateTime,
  2335. })
  2336. .ToList();
  2337. foreach (var item in groupList)
  2338. {
  2339. item.Department = userDepDatas.Find(it => item.JietuanOperatorId == it.UserId)?.DepName ?? "Unknown";
  2340. string groupFirstName = "";
  2341. var currDatas = deleClientList.Where(x => x.DiId == item.Id).ToList();
  2342. if (currDatas.Any())
  2343. {
  2344. groupFirstName = AesEncryptionHelper.Decrypt(currDatas[0].LastName) + AesEncryptionHelper.Decrypt(currDatas[0].FirstName);
  2345. }
  2346. item.GroupFirst = groupFirstName;
  2347. }
  2348. #endregion
  2349. #region Excel
  2350. var tempPath = AppSettingsHelper.Get("ExcelTempPath");
  2351. var servicePath = AppSettingsHelper.Get("GrpFileBaseUrl");
  2352. var savePath = AppSettingsHelper.Get("GrpListFileBasePath");
  2353. var ftpPath = AppSettingsHelper.Get("GrpListFileFtpPath");
  2354. var fileName = $"团组清单({beginDt}~{endDt}){DateTime.Now:yyyyMMddHHmmss}.xlsx";
  2355. //载入模板
  2356. var designer = new WorkbookDesigner
  2357. {
  2358. Workbook = new Workbook($"{tempPath}团组清单模板.xlsx")
  2359. };
  2360. designer.SetDataSource("Titel", $"团组清单({beginDt}~{endDt})");
  2361. DataTable dt = CommonFun.GetDataTableFromIList<DelegationListView>(groupList); ;
  2362. dt.TableName = "GroupList";
  2363. designer.SetDataSource(dt);
  2364. designer.Process();
  2365. if (!Directory.Exists(savePath))
  2366. {
  2367. Directory.CreateDirectory(savePath);
  2368. }
  2369. string serverPath = $"{savePath}{fileName}";
  2370. designer.Workbook.Save(serverPath);
  2371. string rst = $"{servicePath}{ftpPath}{fileName}";
  2372. #endregion
  2373. return Ok(JsonView(true, "操作成功!", rst));
  2374. }
  2375. /// <summary>
  2376. /// 团组合同下载(1.付款80% 2.付全款)
  2377. /// </summary>
  2378. /// <param name="dto"></param>
  2379. /// <returns></returns>
  2380. /// <exception cref="Exception"></exception>
  2381. [HttpPost]
  2382. public async Task<IActionResult> DownGroupContractFile(DownGroupContractFileDto dto)
  2383. {
  2384. var jw = JsonView(false);
  2385. var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  2386. .FirstAsync(x => x.Id == dto.GroupId && x.IsDel == 0);
  2387. if (di == null)
  2388. {
  2389. jw.Msg = "团组Id有误!";
  2390. return Ok(jw);
  2391. }
  2392. #region 权限校验
  2393. var allDownFile = new List<int>() { 21 };
  2394. try
  2395. {
  2396. var setting = _sqlSugar.Queryable<Sys_SetData>()
  2397. .First(x => x.Id == 1418 && x.IsDel == 0);
  2398. allDownFile.AddRange(JsonConvert.DeserializeObject<List<int>>(setting.Remark));
  2399. }
  2400. catch (Exception)
  2401. { }
  2402. var guojiaoDownFile = new List<int>() { 330, 383 };
  2403. var shichangDownFile = new List<int>() { 95 };
  2404. if (allDownFile.Contains(dto.UserId))
  2405. {
  2406. }
  2407. else if (guojiaoDownFile.Contains(dto.UserId))
  2408. {
  2409. var guojiaobuDi = new List<int>() { 4, 21 };
  2410. var departmentStr = _sqlSugar.Queryable<Sys_Department>()
  2411. .LeftJoin<Sys_Users>((d, u) => d.Id == u.DepId && u.IsDel == 0)
  2412. .Where((d, u) => u.Id == di.JietuanOperator)
  2413. .Select((d, u) => d.DepName)
  2414. .First();
  2415. if (!guojiaobuDi.Contains(di.JietuanOperator) && departmentStr != "策划部" && departmentStr != "国交部")
  2416. {
  2417. jw.Msg = "暂无下载权限!";
  2418. return Ok(jw);
  2419. }
  2420. }
  2421. else if (shichangDownFile.Contains(dto.UserId))
  2422. {
  2423. var dic = new Dictionary<int, int[]>()
  2424. {
  2425. { 95, new int []{ 95 , 337 , 302, 350, 355, 357, 353 , 359 , 361, 368, 364, 366, 369} }
  2426. };
  2427. try
  2428. {
  2429. var sqSetting = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == 1417);
  2430. if (sqSetting != null)
  2431. {
  2432. Dictionary<int, int[]> result = JsonConvert.DeserializeObject<Dictionary<int, int[]>>(sqSetting.Remark);
  2433. foreach (var item in result.Keys)
  2434. {
  2435. if (dic.ContainsKey(item))
  2436. {
  2437. int[] dilatation = new int[dic[item].Length + result[item].Length];
  2438. Array.Copy(dic[item], dilatation, dic[item].Length);
  2439. Array.Copy(result[item], 0, dilatation, dic[item].Length, result[item].Length);
  2440. dic[item] = dilatation;
  2441. }
  2442. else
  2443. {
  2444. dic.Add(item, result[item]);
  2445. }
  2446. }
  2447. }
  2448. if (!dic[95].Contains(di.CreateUserId))
  2449. {
  2450. jw.Msg = "暂无下载权限!";
  2451. return Ok(jw);
  2452. }
  2453. }
  2454. catch (Exception)
  2455. { }
  2456. }
  2457. else if (dto.UserId == di.CreateUserId)
  2458. {
  2459. }
  2460. else
  2461. {
  2462. jw.Msg = "暂无下载权限!";
  2463. return Ok(jw);
  2464. }
  2465. #endregion
  2466. var blackCodeList = await _sqlSugar.Queryable<Air_TicketBlackCode>()
  2467. .Where(x => x.DiId == dto.GroupId && x.IsDel == 0)
  2468. .ToListAsync();
  2469. if (!blackCodeList.Any())
  2470. {
  2471. jw.Msg = "该团无机票行程代码!";
  2472. return Ok(jw);
  2473. }
  2474. var groupEnterExitCost = await _sqlSugar.Queryable<Grp_EnterExitCost>()
  2475. .FirstAsync(x => x.DiId == dto.GroupId && x.IsDel == 0);
  2476. if (groupEnterExitCost == null)
  2477. {
  2478. jw.Msg = "暂无三公费用信息!";
  2479. return Ok(jw);
  2480. }
  2481. var rateList = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(groupEnterExitCost.CurrencyRemark);
  2482. rateList ??= new List<CurrencyInfo>();
  2483. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == di.Id).ToList();
  2484. var dac5 = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  2485. .LeftJoin<Sys_SetData>((x, a) => a.IsDel == 0 && a.Id == x.SetDataId)
  2486. .LeftJoin<Sys_SetData>((x, a, b) => b.IsDel == 0 && b.Id == x.Currency)
  2487. .Where((x, a, b) => x.IsDel == 0 && x.Diid == di.Id)
  2488. .Select((x, a, b) => new
  2489. {
  2490. x.Index,
  2491. itemName = a.Name,
  2492. CurrencyStr = b.Name,
  2493. x.Cost,
  2494. x.SubTotal,
  2495. x.Remark
  2496. })
  2497. .OrderBy((x) => x.Index)
  2498. .ToList();
  2499. decimal stayFeeTotal = groupEnterExitCost.ChoiceThree == 1 ? _DayAndCosts.Where(it => it.Type == 1).Sum(it => it.SubTotal) : 0.00M; // 住宿费
  2500. decimal mealsFeeTotal = groupEnterExitCost.ChoiceFour == 1 ? _DayAndCosts.Where(it => it.Type == 2).Sum(it => it.SubTotal) : 0.00M; // 伙食费费
  2501. decimal miscellaneousFeeTotal = groupEnterExitCost.ChoiceFive == 1 ? _DayAndCosts.Where(it => it.Type == 3).Sum(it => it.SubTotal) : 0.00M; // 公杂费
  2502. decimal tainFeeTotal = groupEnterExitCost.ChoiceSix == 1 ? _DayAndCosts.Where(it => it.Type == 4).Sum(it => it.SubTotal) : 0.00M; // 培训费
  2503. decimal otherPriceTotal = groupEnterExitCost.OtherExpenses_Checked == 1 ? dac5.Sum(x => x.SubTotal) : 0.00M; //其他费用
  2504. decimal insidePayTotal = groupEnterExitCost.ChoiceOne == 1 ? groupEnterExitCost.InsidePay : 0.00M;
  2505. decimal otherFeeTotal = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + otherPriceTotal;
  2506. decimal subJJC = 0.00M,
  2507. subGWC = 0.00M,
  2508. subTDC = 0.00M;
  2509. //经济舱
  2510. if (groupEnterExitCost.SumJJC == 1)
  2511. {
  2512. subJJC = otherFeeTotal + groupEnterExitCost.OutsideJJPay;
  2513. }
  2514. //公务舱
  2515. if (groupEnterExitCost.SumGWC == 1)
  2516. {
  2517. subGWC = otherFeeTotal + groupEnterExitCost.OutsideGWPay;
  2518. }
  2519. //头等舱
  2520. if (groupEnterExitCost.SumTDC == 1)
  2521. {
  2522. subTDC = otherFeeTotal + groupEnterExitCost.OutsideTDPay;
  2523. }
  2524. var groupClints = await _sqlSugar.Queryable<Grp_TourClientList>()
  2525. .LeftJoin<Sys_SetData>((x, s) => s.Id == x.ShippingSpaceTypeId && s.IsDel == 0)
  2526. .LeftJoin<Crm_DeleClient>((x, s, dc) => x.ClientId == dc.Id && dc.IsDel == 0)
  2527. .LeftJoin<Crm_CustomerCompany>((x, s, dc, cc) => dc.CrmCompanyId == cc.Id && cc.IsDel == 0)
  2528. .Where((x, s, dc, cc) => x.DiId == dto.GroupId && x.IsDel == 0)
  2529. .Select((x, s, dc, cc) => new GroupClints
  2530. {
  2531. Id = x.Id,
  2532. Name = s.Name,
  2533. IsAccompany = x.IsAccompany,
  2534. CompanyFullName = cc.CompanyFullName
  2535. })
  2536. .ToListAsync();
  2537. groupClints.ForEach(x => x.CompanyFullName = AesEncryptionHelper.Decrypt(x.CompanyFullName));
  2538. //获取舱位人数
  2539. var cabinCount = groupClints.Where(x => x.IsAccompany != 2 && !x.CompanyFullName.Contains("泛美国际"))
  2540. .GroupBy(x => x.Name)
  2541. .Select(x => new { Cabin = x.Key, Count = x.Count() })
  2542. .ToList();
  2543. string cityPath = string.Empty;
  2544. string startCity = string.Empty;
  2545. string endCity = string.Empty;
  2546. foreach (var item in blackCodeList)
  2547. {
  2548. string city = GeneralMethod.GetGroupCityLine(item, "-");
  2549. cityPath += city + "\r\n";
  2550. if (item.Equals(blackCodeList.First()))
  2551. {
  2552. var sp = city.Split('-');
  2553. startCity = sp[0];
  2554. endCity = sp[^1];
  2555. }
  2556. }
  2557. di.VisitCountry = Regex.Replace(di.VisitCountry, @"[|-]", "、");
  2558. var bookMarkDic = new Dictionary<string, string>
  2559. {
  2560. { "ClientUnit", di.ClientUnit },
  2561. { "VisitCountry", di.VisitCountry },
  2562. { "VisitDate", di.VisitDate.ToString("yyyy年MM月dd日") },
  2563. { "VisitPNumber", di.VisitPNumber.ToString() },
  2564. { "CityPath", cityPath },
  2565. { "StartCity", startCity },
  2566. { "EndCity", endCity },
  2567. { "StayDays", $"{di.VisitDays}天{di.VisitDays - 1}晚" }
  2568. };
  2569. Document doc = null;
  2570. var percentage = 0.8M;
  2571. var fileNameadd = "预付";
  2572. if (dto.FileType == 1)
  2573. {
  2574. doc = new Document($"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Template/团组合同bookmarkFormat.doc");
  2575. }
  2576. else if (dto.FileType == 2)
  2577. {
  2578. doc = new Document($"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Template/团组合同全款无表格.doc");
  2579. percentage = 1;
  2580. fileNameadd = "全款";
  2581. }
  2582. else
  2583. {
  2584. throw new Exception("FileType有误!");
  2585. }
  2586. var builder = new DocumentBuilder(doc);
  2587. decimal totalPrice = 0.00M;
  2588. Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true);
  2589. if (firstTable != null)
  2590. {
  2591. // 遍历表格的行和单元格
  2592. foreach (Aspose.Words.Tables.Row row in firstTable.Rows)
  2593. {
  2594. for (int i = 0; i < row.Cells.Count; i++)
  2595. {
  2596. var cell = row.Cells[i];
  2597. // 读取单元格内容
  2598. string cellTextFirst = row.Cells[0].FirstParagraph.ToString(Aspose.Words.SaveFormat.Text).Trim();
  2599. if (cellTextFirst.Contains("舱位"))
  2600. {
  2601. break;
  2602. }
  2603. if (cellTextFirst == "经济舱" || cellTextFirst == "公务舱")
  2604. {
  2605. if (i == 2)
  2606. {
  2607. if (cellTextFirst == "经济舱")
  2608. {
  2609. // 设置单元格内容
  2610. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2611. cell.FirstParagraph.AppendChild(new Run(doc, subJJC.ToString())); // 添加
  2612. }
  2613. else
  2614. {
  2615. // 设置单元格内容
  2616. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2617. cell.FirstParagraph.AppendChild(new Run(doc, subGWC.ToString())); // 添加
  2618. }
  2619. }
  2620. if (i == 3)
  2621. {
  2622. var count = cabinCount.Find(x => x.Cabin == cellTextFirst)?.Count;
  2623. if (count != null)
  2624. {
  2625. // 设置单元格内容
  2626. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2627. cell.FirstParagraph.AppendChild(new Run(doc, count.ToString())); // 添加
  2628. }
  2629. }
  2630. if (i == 4)
  2631. {
  2632. var rowPrice = 0.00M;
  2633. var count = cabinCount.Find(x => x.Cabin == cellTextFirst)?.Count;
  2634. count ??= 0;
  2635. if (cellTextFirst == "经济舱")
  2636. {
  2637. rowPrice = subJJC * (int)count;
  2638. }
  2639. else
  2640. {
  2641. rowPrice = subGWC * (int)count;
  2642. }
  2643. totalPrice += rowPrice;
  2644. // 设置单元格内容
  2645. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2646. cell.FirstParagraph.AppendChild(new Run(doc, rowPrice.ToString())); // 添加
  2647. }
  2648. }
  2649. }
  2650. }
  2651. }
  2652. bookMarkDic.Add("TotalPrice", (totalPrice).ToString("#0.00"));
  2653. bookMarkDic.Add("TotalPrice1", (totalPrice * percentage).ToString("#0.00"));
  2654. bookMarkDic.Add("TotalPriceChinese", decimal.Parse((totalPrice * percentage).ToString("#0.00")).ConvertCNYUpper());
  2655. //--合同表格部分
  2656. bookMarkDic.Add("TimeNowDate", DateTime.Now.ToString("yyyy年MM月dd日"));
  2657. bookMarkDic.Add("ClientUnit1", di.ClientUnit);
  2658. bookMarkDic.Add("VisitCountry1", di.VisitCountry);
  2659. bookMarkDic.Add("DayCount", di.VisitDays.ToString());
  2660. bookMarkDic.Add("VisitingArea", di.VisitDate.ToString("yyyy年MM月dd日") + "-" + di.VisitEndDate.ToString("yyyy年MM月dd日"));
  2661. bookMarkDic.Add("CityPath1", cityPath);
  2662. bookMarkDic.Add("CityPath2", cityPath);
  2663. Table contractTable = (Table)doc.GetChild(NodeType.Table, 1, true);
  2664. if (contractTable != null)
  2665. {
  2666. //数据源
  2667. var _DayAndCostsAndCity = _sqlSugar.Queryable<Grp_DayAndCost>()
  2668. .LeftJoin<Grp_NationalTravelFee>((it, y) => it.NationalTravelFeeId == y.Id && y.IsDel == 0)
  2669. .LeftJoin<Sys_SetData>((it, y, s) => s.IsDel == 0 && s.Id == it.Currency)
  2670. .Where((it, y, s) => it.IsDel == 0 && it.DiId == di.Id)
  2671. .Select((it, y, s) => new
  2672. {
  2673. it.Cost,
  2674. it.SubTotal,
  2675. it.Type,
  2676. y.Id,
  2677. y.City,
  2678. s.Name,
  2679. CurrencyCodeCn = s.Remark
  2680. })
  2681. .ToList()
  2682. .Select(x => new
  2683. {
  2684. CurrencyCode = x.Name,
  2685. CityId = x.Id,
  2686. x.City,
  2687. di.VisitPNumber,
  2688. x.Type,
  2689. x.Cost,
  2690. x.SubTotal,
  2691. rateList.Find(y => y.CurrencyCode == x.Name)?.Rate,
  2692. x.CurrencyCodeCn,
  2693. });
  2694. var dac1 = _DayAndCostsAndCity.Where(it => it.Type == 1).GroupBy(x => x.CityId).ToList(); //住宿费
  2695. var dac2 = _DayAndCostsAndCity.Where(it => it.Type == 2).GroupBy(x => x.CityId).ToList(); //伙食费
  2696. var dac3 = _DayAndCostsAndCity.Where(it => it.Type == 3).GroupBy(x => x.CityId).ToList(); //公杂费
  2697. var dac4 = _DayAndCostsAndCity.Where(it => it.Type == 4).GroupBy(x => x.CityId).ToList(); //培训费
  2698. var tableSettings = new List<tableSetting>()
  2699. {
  2700. new(){ Index = 1 , Property = "City"},
  2701. new(){ Index = 2 , Property = "CurrencyCodeCn"},
  2702. new(){ Index = 3 , Property = "Cost"},
  2703. new(){ Index = 4 , Property = "VisitPNumber"},
  2704. //new tableSetting{ Index = 5 , Property = ""},
  2705. //new tableSetting{ Index = 6 , Property = ""},
  2706. new(){ Index = 7 , Property = "Rate"},
  2707. //new tableSetting{ Index = 8 , Property = ""},
  2708. };
  2709. //1.住宿费
  2710. int cloneRow = 8;
  2711. int startDayPrice = 8; //写入index
  2712. decimal ZSPriceSum = 0.00M, HSPriceSum = 0.00M, GZPriceSum = 0.00M;
  2713. foreach (var dac in dac1)
  2714. {
  2715. var first = dac.First();
  2716. var dayCount = dac.Count();
  2717. Aspose.Words.Tables.Row row = contractTable.Rows[startDayPrice];
  2718. for (int i = 1; i < row.Cells.Count; i++)
  2719. {
  2720. var cell = row.Cells[i];
  2721. var findProperty = tableSettings.Find(x => x.Index == i);
  2722. if (findProperty != null)
  2723. {
  2724. string value = first.GetType().GetProperty(findProperty.Property).GetValue(first).ToString();
  2725. // 设置单元格内容
  2726. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2727. cell.FirstParagraph.AppendChild(new Run(doc, value)); // 添加
  2728. }
  2729. else
  2730. {
  2731. switch (i)
  2732. {
  2733. case 5:
  2734. cell.FirstParagraph.Runs.Clear();
  2735. cell.FirstParagraph.AppendChild(new Run(doc, dayCount.ToString()));
  2736. break;
  2737. case 6:
  2738. var xiaoji = dayCount * first.VisitPNumber * first.Cost;
  2739. cell.FirstParagraph.Runs.Clear();
  2740. cell.FirstParagraph.AppendChild(new Run(doc, xiaoji.ToString("F2")));
  2741. break;
  2742. case 8:
  2743. var xiaojiRMB = dayCount * first.VisitPNumber * first.SubTotal;
  2744. cell.FirstParagraph.Runs.Clear();
  2745. cell.FirstParagraph.AppendChild(new Run(doc, xiaojiRMB.ToString("F2")));
  2746. ZSPriceSum += xiaojiRMB;
  2747. break;
  2748. default:
  2749. break;
  2750. }
  2751. }
  2752. }
  2753. startDayPrice++;
  2754. if (!dac1.Last().Equals(dac))
  2755. {
  2756. Aspose.Words.Tables.Row newRow = (Aspose.Words.Tables.Row)contractTable.Rows[cloneRow].Clone(true);
  2757. // 将克隆的行追加到原行后面
  2758. contractTable.Rows.Insert(startDayPrice, newRow);
  2759. }
  2760. else
  2761. {
  2762. cloneRow += dac1.Count + 1;
  2763. startDayPrice = cloneRow;
  2764. }
  2765. }
  2766. //2.伙食费
  2767. foreach (var dac in dac2)
  2768. {
  2769. var first = dac.First();
  2770. var dayCount = dac.Count();
  2771. Aspose.Words.Tables.Row row = contractTable.Rows[startDayPrice];
  2772. for (int i = 1; i < row.Cells.Count; i++)
  2773. {
  2774. var cell = row.Cells[i];
  2775. var findProperty = tableSettings.Find(x => x.Index == i);
  2776. if (findProperty != null)
  2777. {
  2778. string value = first.GetType().GetProperty(findProperty.Property).GetValue(first).ToString();
  2779. // 设置单元格内容
  2780. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2781. cell.FirstParagraph.AppendChild(new Run(doc, value)); // 添加
  2782. }
  2783. else
  2784. {
  2785. switch (i)
  2786. {
  2787. case 5:
  2788. cell.FirstParagraph.Runs.Clear();
  2789. cell.FirstParagraph.AppendChild(new Run(doc, dayCount.ToString()));
  2790. break;
  2791. case 6:
  2792. var xiaoji = dayCount * first.VisitPNumber * first.Cost;
  2793. cell.FirstParagraph.Runs.Clear();
  2794. cell.FirstParagraph.AppendChild(new Run(doc, xiaoji.ToString("F2")));
  2795. break;
  2796. case 8:
  2797. var xiaojiRMB = dayCount * first.VisitPNumber * first.SubTotal;
  2798. cell.FirstParagraph.Runs.Clear();
  2799. cell.FirstParagraph.AppendChild(new Run(doc, xiaojiRMB.ToString("F2")));
  2800. HSPriceSum += xiaojiRMB;
  2801. break;
  2802. default:
  2803. break;
  2804. }
  2805. }
  2806. }
  2807. startDayPrice++;
  2808. if (!dac2.Last().Equals(dac))
  2809. {
  2810. Aspose.Words.Tables.Row newRow = (Aspose.Words.Tables.Row)contractTable.Rows[cloneRow].Clone(true);
  2811. // 将克隆的行追加到原行后面
  2812. contractTable.Rows.Insert(startDayPrice, newRow);
  2813. }
  2814. else
  2815. {
  2816. cloneRow += dac2.Count + 1;
  2817. startDayPrice = cloneRow;
  2818. }
  2819. }
  2820. //3.公杂费
  2821. foreach (var dac in dac3)
  2822. {
  2823. var first = dac.First();
  2824. var dayCount = dac.Count();
  2825. Aspose.Words.Tables.Row row = contractTable.Rows[startDayPrice];
  2826. for (int i = 1; i < row.Cells.Count; i++)
  2827. {
  2828. var cell = row.Cells[i];
  2829. var findProperty = tableSettings.Find(x => x.Index == i);
  2830. if (findProperty != null)
  2831. {
  2832. string value = first.GetType().GetProperty(findProperty.Property).GetValue(first).ToString();
  2833. // 设置单元格内容
  2834. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2835. cell.FirstParagraph.AppendChild(new Run(doc, value)); // 添加
  2836. }
  2837. else
  2838. {
  2839. switch (i)
  2840. {
  2841. case 5:
  2842. cell.FirstParagraph.Runs.Clear();
  2843. cell.FirstParagraph.AppendChild(new Run(doc, dayCount.ToString()));
  2844. break;
  2845. case 6:
  2846. var xiaoji = dayCount * first.VisitPNumber * first.Cost;
  2847. cell.FirstParagraph.Runs.Clear();
  2848. cell.FirstParagraph.AppendChild(new Run(doc, xiaoji.ToString("F2")));
  2849. break;
  2850. case 8:
  2851. var xiaojiRMB = dayCount * first.VisitPNumber * first.SubTotal;
  2852. cell.FirstParagraph.Runs.Clear();
  2853. cell.FirstParagraph.AppendChild(new Run(doc, xiaojiRMB.ToString("F2")));
  2854. GZPriceSum += xiaojiRMB;
  2855. break;
  2856. default:
  2857. break;
  2858. }
  2859. }
  2860. }
  2861. startDayPrice++;
  2862. if (!dac3.Last().Equals(dac))
  2863. {
  2864. Aspose.Words.Tables.Row newRow = (Aspose.Words.Tables.Row)contractTable.Rows[cloneRow].Clone(true);
  2865. // 将克隆的行追加到原行后面
  2866. contractTable.Rows.Insert(startDayPrice, newRow);
  2867. }
  2868. else
  2869. {
  2870. cloneRow += dac3.Count + 1;
  2871. startDayPrice = cloneRow;
  2872. }
  2873. }
  2874. //合并单元格
  2875. for (int i = 8; i < contractTable.Rows.Count - 1; i++)
  2876. {
  2877. var currentRow = contractTable.Rows[i];
  2878. var nextRow = contractTable.Rows[i + 1];
  2879. // 获取当前行和下一行的第一个单元格
  2880. Cell currentCell = currentRow.Cells[0];
  2881. Cell nextCell = nextRow.Cells[0];
  2882. // 检查单元格内容是否一致(去除尾部的换行符)
  2883. string currentText = currentCell.GetText().Trim();
  2884. string nextText = nextCell.GetText().Trim();
  2885. if (currentText == nextText)
  2886. {
  2887. // 如果当前单元格已经被合并,找到合并的起始单元格
  2888. if (currentCell.CellFormat.VerticalMerge == CellMerge.Previous)
  2889. {
  2890. // 找到合并的起始单元格
  2891. int mergeStartIndex = FindMergeStartRowIndex(contractTable, i);
  2892. // 将下一行的单元格设置为合并的后续单元格
  2893. nextCell.CellFormat.VerticalMerge = CellMerge.Previous;
  2894. }
  2895. else
  2896. {
  2897. // 如果当前单元格是合并的起始单元格
  2898. currentCell.CellFormat.VerticalMerge = CellMerge.First;
  2899. // 将下一行的单元格设置为合并的后续单元格
  2900. nextCell.CellFormat.VerticalMerge = CellMerge.Previous;
  2901. }
  2902. }
  2903. else
  2904. {
  2905. // 如果内容不一致,重置当前单元格的合并属性
  2906. if (currentCell.CellFormat.VerticalMerge == CellMerge.Previous)
  2907. {
  2908. // 如果当前单元格是合并的后续单元格,找到合并的起始单元格并重置
  2909. int mergeStartIndex = FindMergeStartRowIndex(contractTable, i);
  2910. contractTable.Rows[mergeStartIndex].Cells[0].CellFormat.VerticalMerge = CellMerge.First;
  2911. }
  2912. else
  2913. {
  2914. currentCell.CellFormat.VerticalMerge = CellMerge.None;
  2915. }
  2916. }
  2917. }
  2918. bookMarkDic.Add("ZSPriceSum", ZSPriceSum.ToString("F2"));
  2919. bookMarkDic.Add("HSPriceSum", HSPriceSum.ToString("F2"));
  2920. bookMarkDic.Add("GZPriceSum", GZPriceSum.ToString("F2"));
  2921. }
  2922. foreach (var bookmarkName in bookMarkDic.Keys)
  2923. {
  2924. Bookmark bookmark = doc.Range.Bookmarks[bookmarkName];
  2925. if (bookmark != null)
  2926. {
  2927. if (bookmarkName == "ClientUnit")
  2928. {
  2929. // 移动到书签位置
  2930. builder.MoveTo(bookmark.BookmarkStart);
  2931. // 设置字体样式为下划线
  2932. builder.Font.Underline = Aspose.Words.Underline.Single;
  2933. // 插入书签值
  2934. builder.Write(bookMarkDic[bookmarkName]);
  2935. // 清除字体格式,避免影响后续文本
  2936. builder.Font.ClearFormatting();
  2937. }
  2938. else
  2939. {
  2940. builder.MoveToBookmark(bookmarkName);
  2941. builder.Write(bookMarkDic[bookmarkName]);
  2942. }
  2943. }
  2944. }
  2945. string savePaht = $"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Export/{di.TeamName}_{fileNameadd}版本合同文件.doc";
  2946. doc.Save(savePaht);
  2947. jw.Msg = "生成成功!";
  2948. jw.Code = 200;
  2949. jw.Data = new { Url = AppSettingsHelper.Get("WordBaseUrl") + savePaht.Replace(AppSettingsHelper.Get("WordBasePath"), AppSettingsHelper.Get("WordFtpPath")) };
  2950. return Ok(jw);
  2951. }
  2952. static int FindMergeStartRowIndex(Table table, int rowIndex)
  2953. {
  2954. int index = rowIndex;
  2955. while (index > 0 && table.Rows[index].Cells[0].CellFormat.VerticalMerge == CellMerge.Previous)
  2956. {
  2957. index--;
  2958. }
  2959. return index;
  2960. }
  2961. /// <summary>
  2962. /// 报批完成企微通知
  2963. /// </summary>
  2964. /// <param name="dto"></param>
  2965. /// <returns></returns>
  2966. [HttpPost]
  2967. public async Task<IActionResult> EnterpriseWeChatNotificationAsyncBaoPi(EnterpriseWeChatNotificationAsyncBaoPiDto dto)
  2968. {
  2969. int currUserId = dto.currUserId;
  2970. int diid = dto.diid;
  2971. var jw = JsonView(true);
  2972. var users = new List<string>();
  2973. var ssd = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == 1460);
  2974. //时间格式验证
  2975. if (!DateTime.TryParse(dto.stepOperationTime, out DateTime dt))
  2976. {
  2977. return Ok(JsonView(false, "请传入有效的时间格式!(例如:2026-01-06 15:45:02)"));
  2978. }
  2979. try
  2980. {
  2981. users = JsonConvert.DeserializeObject<List<string>>(ssd.Remark);
  2982. var groupModuleOperators = GeneralMethod.GetGroupModuleOperators(dto.diid);
  2983. //添加分配人员
  2984. // 79 车/导游地接
  2985. // 80 签证
  2986. // 81 邀请/公务活动
  2987. var setdataids = new List<int>() { 79, 81 };
  2988. foreach (var groupModule in groupModuleOperators)
  2989. {
  2990. if (setdataids.Contains(groupModule.CTableId))
  2991. {
  2992. users.AddRange(groupModule.OperationUsers.Select(x => x.UserId.ToString()));
  2993. }
  2994. }
  2995. var res = await AppNoticeLibrary.SendUserMsg_BaoPi_ToUser(users, diid);
  2996. //消息通知成功 更改团组step、记录日志
  2997. if (res)
  2998. {
  2999. var groupStep = 0; //0-新建 1-企微消息通知
  3000. //更改团组step
  3001. var updStatus = await _sqlSugar.Updateable<Grp_DelegationInfo>()
  3002. .SetColumns(x => new Grp_DelegationInfo()
  3003. {
  3004. Step = 2,
  3005. StepOperationTime = dt
  3006. })
  3007. .Where(x => x.Id == diid && x.IsDel == 0)
  3008. .ExecuteCommandAsync();
  3009. if (updStatus > 0) groupStep = 2;
  3010. string groupStepLabel = groupStep switch
  3011. {
  3012. 1 => "新建",
  3013. 2 => "企微消息通知(报批)",
  3014. _ => "未设置"
  3015. };
  3016. //记录日志
  3017. var teamName = _sqlSugar.Queryable<Grp_DelegationInfo>()
  3018. .Where(x => x.Id == diid && x.IsDel == 0)
  3019. .Select(x => x.TeamName)
  3020. .First() ?? "-";
  3021. var operationName = _sqlSugar.Queryable<Sys_Users>()
  3022. .Where(x => x.Id == currUserId && x.IsDel == 0)
  3023. .Select(x => x.CnName)
  3024. .First() ?? "-";
  3025. _groupTextLogger.LogInformation("团组:【{teamName}({groupId})】 操作人:【{operationName}】 操作时间:【{operationTime}】{logContent}", teamName, diid, operationName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), groupStepLabel);
  3026. //设置 签证流程初始值
  3027. await _visaProcessRep.UpdateBatchTop4Step(dto.diid, dto.currUserId);
  3028. }
  3029. }
  3030. catch (Exception ex)
  3031. {
  3032. return Ok(JsonView(false, ex.Message));
  3033. }
  3034. return Ok(jw);
  3035. }
  3036. #endregion
  3037. #region 团组&签证
  3038. #region 团组&签证 New
  3039. /// <summary>
  3040. /// 团组&签证 New
  3041. /// DeepSeek API:测试API连通性
  3042. /// </summary>
  3043. /// <param name="file">请求dto</param>
  3044. /// <returns></returns>
  3045. [HttpPost]
  3046. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3047. public async Task<IActionResult> TestDeepSeekApiConnectivityAsync()
  3048. {
  3049. return Ok(JsonView(await _deepSeekService.TestApiConnectivityAsync()));
  3050. }
  3051. /// <summary>
  3052. /// 团组&签证 New
  3053. /// DeepSeek API:检查可用端点
  3054. /// </summary>
  3055. /// <param name="file">请求dto</param>
  3056. /// <returns></returns>
  3057. [HttpPost]
  3058. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3059. public async Task<IActionResult> DiscoverAvailableEndpointsAsync()
  3060. {
  3061. return Ok(JsonView(await _deepSeekService.DiscoverAvailableEndpointsAsync()));
  3062. }
  3063. /// <summary>
  3064. /// 团组&签证 New
  3065. /// 上传签证文件(客户填写签证文件),新增或更新 签证信息
  3066. /// </summary>
  3067. /// <param name="visaFile">文件</param>
  3068. /// </param>
  3069. /// <returns></returns>
  3070. [HttpPost]
  3071. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3072. public async Task<IActionResult> VisaFileUploadAndUpdate(IFormFile visaFile)
  3073. {
  3074. //文件验证
  3075. if (visaFile.Length < 1) return Ok(JsonView(false, "请选择文件!"));
  3076. //var visaFiles = new VisaUploadFileTypeView();
  3077. //var filetypes = VisaUploadFileTypeView.GetVisaUploadFileTypeViewItemInit();
  3078. //if (!filetypes.Any(x => x.FileId == fileTypeId)) return Ok(JsonView(false, "请选择文件类型!"));
  3079. //服务器存储文件
  3080. var fileServerPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Uploads";
  3081. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(fileServerPath);
  3082. var filePath = Path.Combine(fileServerPath, visaFile.FileName);
  3083. using (var stream = new FileStream(filePath, FileMode.Create))
  3084. {
  3085. await visaFile.CopyToAsync(stream);
  3086. }
  3087. //日志记录-上传文件
  3088. _logger.LogInformation("【签证上传文件操作信息】签证文件存储成功!路径:{fileServerPath} 文件名称:{fileName}", fileServerPath, visaFile.FileName);
  3089. #region kimi API
  3090. //kimi AI 识别文档返回json结果
  3091. var KiMiApi = new KiMiApiClient();
  3092. var files = new List<IFormFile>() { visaFile };
  3093. var seedConter = await KiMiApi.UploadFilesAsync(files);
  3094. if (seedConter.Count == 0) return Ok(JsonView(false, "Kimi AI 文件上传结果为空!"));
  3095. var seedMessage = string.Format(@"你是领事馆电子材料审核员,只关注 Word 里的表格,正文、页眉页脚、水印、批注全部忽略。
  3096. 个人信息:
  3097. - 姓名:请提取文档中的“姓名”。
  3098. - 拼音名:请提取文档中的“拼音名”或“英文名”。
  3099. - 曾用名:请提取文档中的“曾用名”或“别名”。
  3100. - 性别:请提取文档中的“性别”。
  3101. - 出生日期:请提取文档中的“出生日期”。
  3102. - 出生地省:请提取文档中的“出生地省”或“出生地省份”。
  3103. - 出生地市:请提取文档中的“出生地市”或“出生地城市”。
  3104. - 国籍:请提取文档中的“国籍”或“现国籍”。
  3105. - 身份证号码:请提取文档中的“身份证号码”。
  3106. - 婚姻状况:请提取文档中的“婚姻状况”。
  3107. - 离婚原因:请提取文档中的“离婚原因”。
  3108. 家庭信息:
  3109. - 家庭成员:请提取文档中所有家庭成员信息,以列表形式返回,每个条目包含以下信息:
  3110. - 关系
  3111. - 姓名
  3112. - 出生日期
  3113. - 婚姻状况
  3114. - 现国籍
  3115. - 出生国
  3116. - 现居住国
  3117. - 现职务
  3118. - 家庭地址:请提取文档中的“家庭地址”或“现住址”。
  3119. - 家庭电话:请提取文档中的“家庭电话”。
  3120. - 移动电话:请提取文档中的“移动电话”或“手机”。
  3121. - 电子邮箱:请提取文档中的“电子邮箱”或“电子邮件”。
  3122. 工作信息:
  3123. - 工作经历:请提取文档中所有工作经历,以列表形式返回,每个条目包含以下信息:
  3124. - 单位名称
  3125. - 单位地址
  3126. - 职务
  3127. - 入职时间
  3128. - 离职时间
  3129. - 上级领导姓名(如适用)
  3130. - 工作单位名称:请提取文档中的“工作单位名称”或“现单位名称”。
  3131. - 工作单位地址:请提取文档中的“工作单位地址”或“单位地址”。
  3132. - 工作单位电话:请提取文档中的“工作单位电话”或“单位电话”。
  3133. - 职位:请提取文档中的“职位”或“目前职位”。
  3134. - 月薪:请提取文档中的“月薪”或“月收入”。
  3135. 教育经历:
  3136. - 教育经历:请提取文档中所有教育经历,以列表形式返回,每个条目包含以下信息:
  3137. - 学校名称
  3138. - 学校地址
  3139. - 学位
  3140. - 专业
  3141. - 入学时间
  3142. - 毕业时间
  3143. 签证与旅行记录:
  3144. - 拒签记录:请提取文档中所有拒签记录,以列表形式返回,每个条目包含以下信息:
  3145. - 国家
  3146. - 拒签日期:请提取文档中的“拒签日期”或“申请日期”。
  3147. - 地点:请提取文档中的“地点”或“拒签地点”。
  3148. - 签证申请类别
  3149. - 拒签原因
  3150. - 旅行历史:请提取文档中所有旅行历史,以列表形式返回,每个条目包含以下信息:
  3151. - 国家
  3152. - 到达日期
  3153. - 离开日期
  3154. - 签证类型(如适用)
  3155. - 服役历史:请提取文档中所有服役历史,以列表形式返回,每个条目包含以下信息:
  3156. - 军种
  3157. - 军衔
  3158. - 服役时间范围(开始日期至结束日期)
  3159. - 去过的国家:请提取文档中所有去过的国家及访问日期范围,以列表形式返回,每个条目包含以下信息:
  3160. - 国家名称
  3161. - 访问日期范围
  3162. - 申根签证记录:请提取文档中所有申根签证记录,以列表形式返回,每个条目包含以下信息:
  3163. - 签证类型
  3164. - 签发日期
  3165. - 有效期
  3166. 其他信息:
  3167. - 社交账号:请提取文档中提到的所有社交账号信息,以列表形式返回,每个条目包含以下信息:
  3168. - 平台名称
  3169. - 账号名称
  3170. - 邀请人信息:请提取文档中的“邀请人信息”,以列表形式返回,每个条目包含以下信息:
  3171. - 邀请人姓名
  3172. - 邀请人地址
  3173. - 邀请人联系方式
  3174. - 旅行目的:请提取文档中的“旅行目的”或“赴美目的”。
  3175. - 旅费支付方:请提取文档中的“旅费支付方”或“费用谁付”。
  3176. - 是否持有因公护照:请提取文档中的“是否持有因公护照”。
  3177. - 因公护照类型:请提取文档中的“因公护照类型”。
  3178. - 因公护照号码:请提取文档中的“因公护照号码”。
  3179. - 因公护照有效期:请提取文档中的“因公护照有效期”。
  3180. - 是否申请过该国签证:请提取文档中的“是否申请过该国签证”。
  3181. - 是否有亲属在目标国家:请提取文档中的“是否有亲属在目标国家”。
  3182. - 亲属、朋友及联系人信息:
  3183. - 请提取文档中所有在目标国家的亲属、朋友及联系人信息,以列表形式返回。
  3184. - 每个条目包含以下信息:
  3185. - 类型(亲属/朋友/联系人)
  3186. - 姓名
  3187. - 关系(如适用,如亲属关系)
  3188. - 出生日期
  3189. - 地址
  3190. - 联系方式
  3191. - 是否居住在现国籍以外的国家:请提取文档中的“是否居住在现国籍以外的国家”。
  3192. - 居留证编号:请提取文档中的“居留证编号”。
  3193. - 居留证有效期:请提取文档中的“居留证有效期”。
  3194. - 是否有指纹记录:请提取文档中的“是否有指纹记录”。
  3195. - 指纹记录日期:请提取文档中的“指纹记录日期”。
  3196. - 是否有美国驾照:请提取文档中的“是否有美国驾照”。
  3197. - 美国驾照号码:请提取文档中的“美国驾照号码”。
  3198. - 美国驾照签发地:请提取文档中的“美国驾照签发地”。
  3199. - 是否有美国社会安全号:请提取文档中的“是否有美国社会安全号”。
  3200. - 美国社会安全号:请提取文档中的“美国社会安全号”。
  3201. - 是否是其他国家的永久居民:请提取文档中的“是否是其他国家的永久居民”。
  3202. - 是否曾抵达过美国:请提取文档中的“是否曾抵达过美国”。
  3203. - 抵达美国时间:请提取文档中的“抵达美国时间”。
  3204. - 在美停留时间:请提取文档中的“在美停留时间”。
  3205. - 是否曾被美国拒签:请提取文档中的“是否曾被美国拒签”。
  3206. - 美国拒签日期:请提取文档中的“美国拒签日期”。
  3207. - 美国拒签原因:请提取文档中的“美国拒签原因”。
  3208. - 代办人姓名:请提取文档中的“代办人姓名”。
  3209. - 代办人手机号码:请提取文档中的“代办人手机号码”。
  3210. - 代办人现居住地址:请提取文档中的“代办人现居住地址”。
  3211. 把表格里的每个可填字段转换成“标题:值”的键值对,值用原文,不翻译。
  3212. 注:日期格式:YYYY-MM-DD、值为空时空字符串
  3213. 只返回json结果,不需要其他内容,json内容去掉换行。");
  3214. var messages = new List<SeedMessages>
  3215. {
  3216. new() { Role = KimiRole.system, Content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长识别文件为Json格式的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一切涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。" },
  3217. new() { Role = KimiRole.user, Content = seedMessage }
  3218. };
  3219. messages.InsertRange(1, seedConter);
  3220. string jsonString = "";
  3221. dynamic jsonData = null;
  3222. bool isJson = false;
  3223. while (!isJson)
  3224. {
  3225. var kimiApiResult = await KiMiApi.SeedMessage(messages);
  3226. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  3227. var newJsonString = kimiApiResult_JObject["content"].ToString();
  3228. string startStr = "```json", endStr = "```";
  3229. // 判断并清除开头部分
  3230. if (newJsonString.StartsWith(startStr))
  3231. {
  3232. newJsonString = newJsonString.Replace(startStr, "");
  3233. }
  3234. // 判断并清除结尾部分
  3235. if (newJsonString.EndsWith(endStr))
  3236. {
  3237. newJsonString = newJsonString.Replace(endStr, "");
  3238. }
  3239. jsonString += newJsonString;
  3240. //验证json格式是否正确
  3241. try
  3242. {
  3243. jsonData = JsonDocument.Parse(jsonString);
  3244. isJson = true; // 如果解析成功,则是json格式
  3245. }
  3246. catch (Exception)
  3247. {
  3248. messages.Add(new() { Role = KimiRole.user, Content = "请接着续写未完成的json格式内容。" });
  3249. }
  3250. }
  3251. if (jsonData == null)
  3252. {
  3253. return Ok(JsonView(false, "kimi识别json转换失败。"));
  3254. }
  3255. var info = new Crm_DeleClient();
  3256. var company = new Crm_CustomerCompany();
  3257. var certs = new List<Crm_CustomerCert>();
  3258. var familys = new List<Crm_VisaCustomerFamily>();
  3259. var schools = new List<Crm_VisaCustomerSchool>();
  3260. var works = new List<Crm_VisaCustomerCompany>();
  3261. var refusalRecords = new List<VisaRefusalRecord>(); // 拒签记录
  3262. var travelHistories = new List<TravelHistory>(); // 出行历史
  3263. var militaries = new List<MilitaryInfo>(); // 军事信息
  3264. var countryVisiteds = new List<CountryVisited>(); // 已出访的国家
  3265. var schengenVisaRecords = new List<SchengenVisaRecord>(); // 申根签证记录
  3266. var socialAccounts = new List<SocialAccount>(); // 社交账号
  3267. var personInfos = new List<PersonInfo>(); // 亲属朋友信息
  3268. try
  3269. {
  3270. using (JsonDocument document = JsonDocument.Parse(jsonString))
  3271. {
  3272. JsonElement root = document.RootElement;
  3273. if (root.ValueKind == JsonValueKind.Object)
  3274. {
  3275. if (root.TryGetProperty("个人信息", out JsonElement userInfo))
  3276. {
  3277. if (TryGetNonEmptyStringProperty(userInfo, "姓名", out string name))
  3278. {
  3279. info.LastName = name.Substring(0, 1);
  3280. info.FirstName = name.Substring(1, name.Length - 1);
  3281. }
  3282. if (TryGetNonEmptyStringProperty(userInfo, "曾用名", out string oldName))
  3283. info.OldName = oldName;
  3284. if (TryGetNonEmptyStringProperty(userInfo, "拼音名", out string pinyin))
  3285. info.Pinyin = pinyin;
  3286. if (TryGetNonEmptyStringProperty(userInfo, "性别", out string gender))
  3287. info.Sex = gender switch
  3288. {
  3289. "男" => 0,
  3290. "女" => 1,
  3291. _ => -1
  3292. };
  3293. if (TryGetNonEmptyDateTimeProperty(userInfo, "出生日期", out DateTime? birthDay))
  3294. info.BirthDay = birthDay;
  3295. if (TryGetNonEmptyStringProperty(userInfo, "出生地省", out string birthProvince))
  3296. info.BirthProvince = birthProvince;
  3297. if (TryGetNonEmptyStringProperty(userInfo, "出生地市", out string birthCity))
  3298. info.BirthCity = birthCity;
  3299. if (TryGetNonEmptyStringProperty(userInfo, "国籍", out string nationality))
  3300. { }
  3301. if (TryGetNonEmptyStringProperty(userInfo, "身份证号码", out string idNo))
  3302. certs.Add(new() { PassportType = 74, CertNo = idNo, Country = nationality });
  3303. if (TryGetNonEmptyStringProperty(userInfo, "婚姻状况", out string marital_status))
  3304. info.Marriage = marital_status switch
  3305. {
  3306. "未婚" => 1,
  3307. "已婚" => 2,
  3308. "离异" => 3,
  3309. "丧偶" => 4,
  3310. _ => 0
  3311. };
  3312. if (TryGetNonEmptyStringProperty(userInfo, "离婚原因", out string DivorceRsn))
  3313. info.DivorceRsn = DivorceRsn;
  3314. }
  3315. if (root.TryGetProperty("家庭信息", out JsonElement familyInfo))
  3316. {
  3317. if (TryGetNonEmptyStringProperty(familyInfo, "家庭地址", out string address))
  3318. info.Address = address;
  3319. if (TryGetNonEmptyStringProperty(familyInfo, "家庭电话", out string tel))
  3320. info.Tel = tel;
  3321. if (TryGetNonEmptyStringProperty(familyInfo, "移动电话", out string phone))
  3322. info.Phone = phone;
  3323. if (TryGetNonEmptyStringProperty(familyInfo, "电子邮箱", out string email))
  3324. info.Email = email;
  3325. if (familyInfo.TryGetProperty("家庭成员", out JsonElement family_members))
  3326. {
  3327. foreach (JsonElement family_member in family_members.EnumerateArray())
  3328. {
  3329. var familyInfo1 = new Crm_VisaCustomerFamily();
  3330. if (TryGetNonEmptyStringProperty(family_member, "关系", out string gx))
  3331. familyInfo1.Appellation = gx;
  3332. if (TryGetNonEmptyStringProperty(family_member, "姓名", out string family_name))
  3333. familyInfo1.Name = family_name;
  3334. if (TryGetNonEmptyDateTimeProperty(family_member, "出生日期", out DateTime? family_date_of_birth))
  3335. familyInfo1.BirthDay = family_date_of_birth;
  3336. if (TryGetNonEmptyStringProperty(family_member, "婚姻状况", out string marital_status))
  3337. familyInfo1.MaritalStatus = marital_status;
  3338. if (TryGetNonEmptyStringProperty(family_member, "现国籍", out string currentNationality))
  3339. familyInfo1.CurrentNationality = currentNationality;
  3340. if (TryGetNonEmptyStringProperty(family_member, "出生国", out string countryOfBirth))
  3341. familyInfo1.CountryOfBirth = countryOfBirth;
  3342. if (TryGetNonEmptyStringProperty(family_member, "现居住国", out string currentResidenceCountry))
  3343. familyInfo1.CurrentResidenceCountry = currentResidenceCountry;
  3344. if (TryGetNonEmptyStringProperty(family_member, "现职务", out string currentOccupation))
  3345. familyInfo1.CurrentOccupation = currentOccupation;
  3346. familys.Add(familyInfo1);
  3347. }
  3348. }
  3349. }
  3350. if (root.TryGetProperty("工作信息", out JsonElement workInfo))
  3351. {
  3352. if (TryGetNonEmptyStringProperty(workInfo, "工作单位名称", out string workName))
  3353. company.CompanyFullName = workName;
  3354. if (TryGetNonEmptyStringProperty(workInfo, "工作单位电话", out string workPhone))
  3355. info.ClientPhone = workPhone;
  3356. if (TryGetNonEmptyStringProperty(workInfo, "工作单位地址", out string address))
  3357. company.Address = address;
  3358. if (TryGetNonEmptyStringProperty(workInfo, "职位", out string job))
  3359. info.Job = job;
  3360. if (TryGetNonEmptyStringProperty(workInfo, "月薪", out string wage))
  3361. info.Wage = wage;
  3362. if (workInfo.TryGetProperty("工作经历", out JsonElement workExp))
  3363. {
  3364. foreach (JsonElement work in workExp.EnumerateArray())
  3365. {
  3366. var workInfo1 = new Crm_VisaCustomerCompany();
  3367. if (TryGetNonEmptyStringProperty(work, "单位名称", out string unit_name))
  3368. workInfo1.Company = unit_name;
  3369. if (TryGetNonEmptyStringProperty(work, "单位地址", out string unit_address))
  3370. workInfo1.CompanyAddress = unit_address;
  3371. if (TryGetNonEmptyStringProperty(work, "职务", out string work_position))
  3372. workInfo1.Job = work_position;
  3373. if (TryGetNonEmptyStringProperty(work, "上级领导姓名", out string superior_leader_name))
  3374. workInfo1.LeaderName = superior_leader_name;
  3375. if (TryGetNonEmptyDateTimeProperty(work, "入职时间", out DateTime? start_date))
  3376. workInfo1.WorkStart = start_date;
  3377. if (TryGetNonEmptyDateTimeProperty(work, "离职时间", out DateTime? end_date))
  3378. workInfo1.WorkEnd = end_date;
  3379. workInfo1.WorkState = "";
  3380. works.Add(workInfo1);
  3381. }
  3382. }
  3383. }
  3384. if (root.TryGetProperty("教育经历", out JsonElement eduInfo))
  3385. {
  3386. if (eduInfo.TryGetProperty("教育经历", out JsonElement educations))
  3387. {
  3388. foreach (JsonElement edu in educations.EnumerateArray())
  3389. {
  3390. var schoolInfo = new Crm_VisaCustomerSchool();
  3391. if (TryGetNonEmptyStringProperty(edu, "学校名称", out string school_name))
  3392. schoolInfo.School = school_name;
  3393. if (TryGetNonEmptyStringProperty(edu, "学校地址", out string school_address))
  3394. schoolInfo.Address = school_address;
  3395. if (TryGetNonEmptyStringProperty(edu, "专业", out string degree))
  3396. schoolInfo.Subject = degree;
  3397. if (TryGetNonEmptyStringProperty(edu, "学位", out string major))
  3398. schoolInfo.Education = major;
  3399. if (TryGetNonEmptyDateTimeProperty(edu, "入学时间", out DateTime? enrollment_date))
  3400. schoolInfo.StudyStart = enrollment_date;
  3401. if (TryGetNonEmptyDateTimeProperty(edu, "毕业时间", out DateTime? graduation_date))
  3402. schoolInfo.StudyEnd = graduation_date;
  3403. schools.Add(schoolInfo);
  3404. }
  3405. }
  3406. }
  3407. if (root.TryGetProperty("签证与旅行记录", out JsonElement visaTravelRecs))
  3408. {
  3409. if (visaTravelRecs.TryGetProperty("拒签记录", out JsonElement rejectRecs))
  3410. {
  3411. foreach (JsonElement rejectRec in rejectRecs.EnumerateArray())
  3412. {
  3413. var visaRefusalRecordInfo = new VisaRefusalRecord();
  3414. if (TryGetNonEmptyStringProperty(rejectRec, "国家", out string country))
  3415. visaRefusalRecordInfo.Country = country;
  3416. if (TryGetNonEmptyDateTimeProperty(rejectRec, "拒签日期", out DateTime? refusal_date))
  3417. visaRefusalRecordInfo.Date = refusal_date;
  3418. if (TryGetNonEmptyStringProperty(rejectRec, "申请签证类别", out string visaType))
  3419. visaRefusalRecordInfo.VisaType = visaType;
  3420. if (TryGetNonEmptyStringProperty(rejectRec, "地点", out string address))
  3421. visaRefusalRecordInfo.Address = address;
  3422. if (TryGetNonEmptyStringProperty(rejectRec, "拒签原因", out string refusal_reason))
  3423. visaRefusalRecordInfo.Reason = refusal_reason;
  3424. refusalRecords.Add(visaRefusalRecordInfo);
  3425. }
  3426. info.RefusalRecords = refusalRecords;
  3427. }
  3428. if (visaTravelRecs.TryGetProperty("旅行历史", out JsonElement travelHist))
  3429. {
  3430. foreach (JsonElement travel in travelHist.EnumerateArray())
  3431. {
  3432. var travelHistoryInfo = new TravelHistory();
  3433. if (TryGetNonEmptyStringProperty(travel, "国家", out string country))
  3434. travelHistoryInfo.Country = country;
  3435. if (TryGetNonEmptyDateTimeProperty(travel, "到达日期", out DateTime? arrival_date))
  3436. travelHistoryInfo.ArrivalDate = arrival_date;
  3437. if (TryGetNonEmptyDateTimeProperty(travel, "离开日期", out DateTime? departure_date))
  3438. travelHistoryInfo.DepartureDate = departure_date;
  3439. if (TryGetNonEmptyStringProperty(travel, "visa_type", out string visa_type))
  3440. travelHistoryInfo.VisaType = visa_type;
  3441. travelHistories.Add(travelHistoryInfo);
  3442. }
  3443. info.TravelHistories = travelHistories;
  3444. }
  3445. if (visaTravelRecs.TryGetProperty("服役历史", out JsonElement militaryHist))
  3446. {
  3447. foreach (JsonElement military in militaryHist.EnumerateArray())
  3448. {
  3449. var militaryInfo = new MilitaryInfo();
  3450. if (TryGetNonEmptyStringProperty(military, "军种", out string military_branch))
  3451. militaryInfo.MilBranch = military_branch;
  3452. if (TryGetNonEmptyStringProperty(military, "军衔", out string military_rank))
  3453. militaryInfo.MilRank = military_rank;
  3454. if (TryGetNonEmptyStringProperty(military, "服役时间范围", out string service_duration))
  3455. militaryInfo.ServeDuration = service_duration;
  3456. militaries.Add(militaryInfo);
  3457. }
  3458. info.Militaries = militaries;
  3459. }
  3460. if (visaTravelRecs.TryGetProperty("去过的国家", out JsonElement visitedCountries))
  3461. {
  3462. foreach (JsonElement country in visitedCountries.EnumerateArray())
  3463. {
  3464. var countryVisitedInfo = new CountryVisited();
  3465. if (TryGetNonEmptyStringProperty(country, "国家名称", out string visit_country))
  3466. countryVisitedInfo.Country = visit_country;
  3467. if (TryGetNonEmptyStringProperty(country, "访问日期范围", out string visit_date_range))
  3468. countryVisitedInfo.VisitDate = visit_date_range;
  3469. countryVisiteds.Add(countryVisitedInfo);
  3470. }
  3471. info.CountryVisiteds = countryVisiteds;
  3472. }
  3473. if (visaTravelRecs.TryGetProperty("申根签证记录", out JsonElement schengenVisaRecs))
  3474. {
  3475. foreach (JsonElement schengenVisaRec in schengenVisaRecs.EnumerateArray())
  3476. {
  3477. var schengenVisaRecInfo = new SchengenVisaRecord();
  3478. if (TryGetNonEmptyStringProperty(schengenVisaRec, "签证类型", out string visaType))
  3479. schengenVisaRecInfo.VisaType = visaType;
  3480. if (TryGetNonEmptyDateTimeProperty(schengenVisaRec, "签发日期", out DateTime? issueDate))
  3481. schengenVisaRecInfo.IssueDate = issueDate;
  3482. if (TryGetNonEmptyDateTimeProperty(schengenVisaRec, "有效期", out DateTime? expiryDate))
  3483. schengenVisaRecInfo.ExpiryDate = expiryDate;
  3484. schengenVisaRecords.Add(schengenVisaRecInfo);
  3485. }
  3486. info.SchengenVisaRecords = schengenVisaRecords;
  3487. }
  3488. }
  3489. if (root.TryGetProperty("其他信息", out JsonElement otherInfo))
  3490. {
  3491. if (otherInfo.TryGetProperty("社交账号", out JsonElement socialAccountss))
  3492. {
  3493. foreach (JsonElement socialAccount in socialAccountss.EnumerateArray())
  3494. {
  3495. var socialAccount1 = new SocialAccount();
  3496. if (TryGetNonEmptyStringProperty(socialAccount, "平台名称", out string platform))
  3497. socialAccount1.Platform = platform;
  3498. if (TryGetNonEmptyStringProperty(socialAccount, "账号名称", out string account))
  3499. socialAccount1.Account = account;
  3500. socialAccounts.Add(socialAccount1);
  3501. }
  3502. info.SocialAccounts = socialAccounts;
  3503. }
  3504. if (TryGetNonEmptyStringProperty(otherInfo, "旅行目的", out string usaPurpose))
  3505. info.USAPurpose = usaPurpose;
  3506. if (TryGetNonEmptyStringProperty(otherInfo, "旅费支付方", out string payer))
  3507. info.CostBearers = payer;
  3508. if (TryGetNonEmptyStringProperty(otherInfo, "是否持有因公护照", out string isUSAVia))
  3509. info.IsUSAVia = isUSAVia switch
  3510. {
  3511. "是" => 1,
  3512. _ => 0
  3513. };
  3514. if (TryGetNonEmptyDateTimeProperty(otherInfo, "因公护照有效期", out DateTime? GetUSAVisaDate))
  3515. info.GetUSAVisaDate = GetUSAVisaDate;
  3516. if (TryGetNonEmptyStringProperty(otherInfo, "因公护照类型", out string USAVisaCate))
  3517. info.USAVisaCate = USAVisaCate;
  3518. if (TryGetNonEmptyStringProperty(otherInfo, "因公护照号码", out string USAVisaCode))
  3519. info.USAVisaCode = USAVisaCode;
  3520. if (otherInfo.TryGetProperty("亲属、朋友及联系人信息", out JsonElement personInfos1))
  3521. {
  3522. foreach (JsonElement personInfo in personInfos1.EnumerateArray())
  3523. {
  3524. var personInfo1 = new PersonInfo();
  3525. if (TryGetNonEmptyStringProperty(personInfo, "类型", out string type))
  3526. personInfo1.Type = type;
  3527. if (TryGetNonEmptyStringProperty(personInfo, "姓名", out string name))
  3528. personInfo1.Name = name;
  3529. if (TryGetNonEmptyDateTimeProperty(personInfo, "出生日期", out DateTime? birthDay))
  3530. personInfo1.BirthDay = birthDay;
  3531. if (TryGetNonEmptyStringProperty(personInfo, "地址", out string address))
  3532. personInfo1.Address = address;
  3533. if (TryGetNonEmptyStringProperty(personInfo, "联系方式", out string contactInfo))
  3534. personInfo1.ContactInfo = contactInfo;
  3535. personInfos.Add(personInfo1);
  3536. }
  3537. info.PersonInfos = personInfos;
  3538. }
  3539. if (TryGetNonEmptyStringProperty(otherInfo, "是否有指纹记录", out string IsFinger))
  3540. info.IsFinger = IsFinger switch
  3541. {
  3542. "是" => 1,
  3543. _ => 0
  3544. };
  3545. if (TryGetNonEmptyDateTimeProperty(otherInfo, "指纹记录日期", out DateTime? FingerDate))
  3546. info.FingerDate = FingerDate;
  3547. if (TryGetNonEmptyStringProperty(otherInfo, "美国驾照号码", out string USA_DLNo))
  3548. info.USA_DLNo = USA_DLNo;
  3549. if (TryGetNonEmptyStringProperty(otherInfo, "指纹记录日期", out string USA_DLPlace))
  3550. info.USA_DLPlace = USA_DLPlace;
  3551. if (TryGetNonEmptyStringProperty(otherInfo, "美国社会安全号", out string USA_SSNOrITIN))
  3552. info.USA_SSNOrITIN = USA_SSNOrITIN;
  3553. if (TryGetNonEmptyStringProperty(otherInfo, "是否是其他国家的永久居民", out string Resident))
  3554. info.Resident = Resident;
  3555. if (TryGetNonEmptyStringProperty(otherInfo, "抵达美国时间", out string USAHadArrival‌))
  3556. info.USAHadArrival‌ = USAHadArrival‌;
  3557. if (TryGetNonEmptyStringProperty(otherInfo, "在美停留时间", out string USAHadDays‌))
  3558. info.USAHadDays‌ = USAHadDays‌;
  3559. if (TryGetNonEmptyStringProperty(otherInfo, "代办人姓名", out string TableOpName))
  3560. info.TableOpName = TableOpName;
  3561. if (TryGetNonEmptyStringProperty(otherInfo, "代办人手机号码", out string TableOpTel))
  3562. info.TableOpTel = TableOpTel;
  3563. if (TryGetNonEmptyStringProperty(otherInfo, "代办人现居住地址", out string TableOpAddress))
  3564. { }
  3565. }
  3566. }
  3567. }
  3568. }
  3569. catch (Exception ex)
  3570. {
  3571. return Ok(JsonView(false, "信息提取失败:" + ex.Message));
  3572. }
  3573. #region 数据提交
  3574. _sqlSugar.BeginTran();
  3575. try
  3576. {
  3577. var infos = await _sqlSugar.Queryable<Crm_DeleClient>().Where(x => x.IsDel == 0).Select(x => new { x.Id, x.FirstName, x.LastName, x.Phone }).ToListAsync();
  3578. var infoDecrypts = new List<dynamic>();
  3579. foreach (var item in infos)
  3580. {
  3581. infoDecrypts.Add(new
  3582. {
  3583. Id = item.Id,
  3584. FirstName = AesEncryptionHelper.Decrypt(item.FirstName),
  3585. LastName = AesEncryptionHelper.Decrypt(item.LastName),
  3586. Phone = AesEncryptionHelper.Decrypt(item.Phone),
  3587. });
  3588. }
  3589. var infoVaild = infoDecrypts.Where(x =>
  3590. info.FirstName.Equals(x.FirstName) &&
  3591. info.LastName.Equals(x.LastName) &&
  3592. info.Phone.Equals(x.Phone))
  3593. .FirstOrDefault();
  3594. var compnayInfos = await _sqlSugar.Queryable<Crm_CustomerCompany>()
  3595. .Where(x => x.IsDel == 0)
  3596. .ToListAsync();
  3597. foreach (var company1 in compnayInfos)
  3598. {
  3599. company1.CompanyFullName = AesEncryptionHelper.Decrypt(company1.CompanyFullName);
  3600. }
  3601. var compnayInfo = compnayInfos.FirstOrDefault(x => x.CompanyFullName == company.CompanyFullName);
  3602. if (compnayInfo == null)
  3603. {
  3604. company.CompanyFullName = AesEncryptionHelper.Encrypt(company.CompanyFullName);
  3605. compnayInfo = await _sqlSugar.Insertable(company).ExecuteReturnEntityAsync();
  3606. if (compnayInfo == null)
  3607. {
  3608. _sqlSugar.RollbackTran();
  3609. return Ok(JsonView(false, "公司信息添加失败!"));
  3610. }
  3611. }
  3612. if (infoVaild == null) //添加
  3613. {
  3614. info.CrmCompanyId = compnayInfo.Id;
  3615. EncryptionProcessor.EncryptProperties(info);
  3616. var insertId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  3617. if (insertId < 1)
  3618. {
  3619. _sqlSugar.RollbackTran();
  3620. return Ok(JsonView(false, "信息添加失败!"));
  3621. }
  3622. if (familys.Any())
  3623. {
  3624. foreach (var family in familys)
  3625. {
  3626. family.DcId = insertId;
  3627. }
  3628. var familyInsert = await _sqlSugar.Insertable(familys).ExecuteCommandAsync();
  3629. if (familyInsert < 1)
  3630. {
  3631. _sqlSugar.RollbackTran();
  3632. return Ok(JsonView(false, "家庭信息添加失败!"));
  3633. }
  3634. }
  3635. if (schools.Any())
  3636. {
  3637. foreach (var school in schools)
  3638. {
  3639. school.DcId = insertId;
  3640. }
  3641. var schoolInsert = await _sqlSugar.Insertable(schools).ExecuteCommandAsync();
  3642. if (schoolInsert < 1)
  3643. {
  3644. _sqlSugar.RollbackTran();
  3645. return Ok(JsonView(false, "学校信息添加失败!"));
  3646. }
  3647. }
  3648. if (works.Any())
  3649. {
  3650. foreach (var work in works)
  3651. {
  3652. work.DcId = insertId;
  3653. }
  3654. var workInsert = await _sqlSugar.Insertable(works).ExecuteCommandAsync();
  3655. if (workInsert < 1)
  3656. {
  3657. _sqlSugar.RollbackTran();
  3658. return Ok(JsonView(false, "工作信息添加失败!"));
  3659. }
  3660. }
  3661. }
  3662. //修改
  3663. else
  3664. {
  3665. int id = infoVaild?.Id ?? 0;
  3666. var updInfo = await _sqlSugar.Queryable<Crm_DeleClient>().FirstAsync(x => x.Id == id);
  3667. EncryptionProcessor.DecryptProperties(updInfo);
  3668. foreach (var prop in info.GetType().GetProperties())
  3669. {
  3670. var currentVal = prop.GetValue(updInfo);
  3671. var newValue = prop.GetValue(info);
  3672. // 检查当前值是否为 null 或空字符串
  3673. if (currentVal == null || (currentVal is string && string.IsNullOrEmpty((string)currentVal)))
  3674. {
  3675. // 如果新值不为 null 或空字符串,则更新
  3676. if (newValue != null && !(newValue is string && string.IsNullOrEmpty((string)newValue)))
  3677. {
  3678. prop.SetValue(updInfo, newValue);
  3679. }
  3680. }
  3681. }
  3682. EncryptionProcessor.EncryptProperties(updInfo);
  3683. var upd = await _sqlSugar.Updateable(updInfo).ExecuteCommandAsync();
  3684. if (upd < 1)
  3685. {
  3686. _sqlSugar.RollbackTran();
  3687. return Ok(JsonView(false, "个人信息更新失败!"));
  3688. }
  3689. int parentId = updInfo.Id;
  3690. if (familys.Any())
  3691. {
  3692. await _sqlSugar.Updateable<Crm_VisaCustomerFamily>()
  3693. .SetColumns(x => x.IsDel == 0)
  3694. .SetColumns(x => x.DeleteUserId == 4)
  3695. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  3696. .Where(x => x.DcId == parentId)
  3697. .ExecuteCommandAsync();
  3698. foreach (var family in familys)
  3699. {
  3700. family.DcId = parentId;
  3701. }
  3702. var familyInsert = await _sqlSugar.Insertable(familys).ExecuteCommandAsync();
  3703. if (familyInsert < 1)
  3704. {
  3705. _sqlSugar.RollbackTran();
  3706. return Ok(JsonView(false, "家庭信息添加失败!"));
  3707. }
  3708. }
  3709. if (schools.Any())
  3710. {
  3711. await _sqlSugar.Updateable<Crm_VisaCustomerSchool>()
  3712. .SetColumns(x => x.IsDel == 0)
  3713. .SetColumns(x => x.DeleteUserId == 4)
  3714. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  3715. .Where(x => x.DcId == parentId)
  3716. .ExecuteCommandAsync();
  3717. foreach (var school in schools)
  3718. {
  3719. school.DcId = parentId;
  3720. }
  3721. var schoolInsert = await _sqlSugar.Insertable(schools).ExecuteCommandAsync();
  3722. if (schoolInsert < 1)
  3723. {
  3724. _sqlSugar.RollbackTran();
  3725. return Ok(JsonView(false, "学校信息添加失败!"));
  3726. }
  3727. }
  3728. if (works.Any())
  3729. {
  3730. await _sqlSugar.Updateable<Crm_VisaCustomerCompany>()
  3731. .SetColumns(x => x.IsDel == 0)
  3732. .SetColumns(x => x.DeleteUserId == 4)
  3733. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  3734. .Where(x => x.DcId == parentId)
  3735. .ExecuteCommandAsync();
  3736. foreach (var work in works)
  3737. {
  3738. work.DcId = parentId;
  3739. }
  3740. var workInsert = await _sqlSugar.Insertable(works).ExecuteCommandAsync();
  3741. if (workInsert < 1)
  3742. {
  3743. _sqlSugar.RollbackTran();
  3744. return Ok(JsonView(false, "工作信息添加失败!"));
  3745. }
  3746. }
  3747. }
  3748. _sqlSugar.CommitTran();
  3749. return Ok(JsonView(true, "操作成功"));
  3750. }
  3751. catch (Exception ex)
  3752. {
  3753. _sqlSugar.RollbackTran();
  3754. return Ok(JsonView(false, ex.Message));
  3755. }
  3756. #endregion
  3757. #endregion
  3758. }
  3759. private static bool TryGetNonEmptyStringProperty(JsonElement root, string propertyName, out string value)
  3760. {
  3761. value = null;
  3762. if (root.TryGetProperty(propertyName, out JsonElement propertyElement))
  3763. {
  3764. string stringValue = propertyElement.GetString();
  3765. if (stringValue != null && stringValue != "null" && stringValue != "")
  3766. {
  3767. value = stringValue;
  3768. return true;
  3769. }
  3770. }
  3771. return false;
  3772. }
  3773. private static bool TryGetNonEmptyDateTimeProperty(JsonElement root, string propertyName, out DateTime? value)
  3774. {
  3775. value = null; // 初始化为null
  3776. if (root.TryGetProperty(propertyName, out JsonElement propertyElement))
  3777. {
  3778. string stringValue = propertyElement.GetString();
  3779. if (stringValue != null && stringValue != "null" && stringValue != "")
  3780. {
  3781. if (DateTime.TryParse(stringValue, out DateTime parsedValue))
  3782. {
  3783. value = parsedValue; // 将解析结果赋值给value
  3784. return true;
  3785. }
  3786. }
  3787. }
  3788. return false;
  3789. }
  3790. #region 扩展处理
  3791. // 从 Expression<Func<T,object>> 里取出属性名
  3792. static string GetPropName<T>(Expression<Func<T, object>> expr)
  3793. {
  3794. if (expr.Body is UnaryExpression ue) expr = Expression.Lambda<Func<T, object>>(ue.Operand, expr.Parameters);
  3795. return ((MemberExpression)expr.Body).Member.Name;
  3796. }
  3797. /// <summary>
  3798. /// 5.1.4.193 可用:存在更新(非NULL非空串),不存在插入,返回主键ID
  3799. /// </summary>
  3800. public int UpsertReturnId<T>(T entity, Expression<Func<T, object>> whereExpr) where T : class, new()
  3801. {
  3802. // 1. 空字符串→NULL,让后续忽略
  3803. foreach (var pi in typeof(T).GetProperties())
  3804. if (pi.PropertyType == typeof(string) &&
  3805. pi.GetValue(entity) is string s &&
  3806. string.IsNullOrWhiteSpace(s))
  3807. pi.SetValue(entity, null);
  3808. // 2. 从表达式里拿属性名
  3809. string propName = GetPropName(whereExpr);
  3810. var propValue = typeof(T).GetProperty(propName)?.GetValue(entity);
  3811. // 3. 判断存在
  3812. bool exists = _sqlSugar.Queryable<T>().Where(propName, propValue).Any();
  3813. // 4. 执行 Upsert
  3814. if (exists)
  3815. {
  3816. _sqlSugar.Updateable(entity)
  3817. .WhereColumns(propName) // 指定条件列
  3818. .IgnoreColumns(ignoreAllNullColumns: true) // 忽略 NULL
  3819. .ExecuteCommand();
  3820. }
  3821. else
  3822. {
  3823. _sqlSugar.Insertable(entity).ExecuteReturnIdentity();
  3824. }
  3825. // 5. 返回主键值(自增/雪花已回填)
  3826. var idProp = typeof(T).GetProperties()
  3827. .First(p => p.GetCustomAttributes<SugarColumn>()
  3828. .Any(a => a.IsPrimaryKey));
  3829. return (int)idProp.GetValue(entity)!;
  3830. }
  3831. /// <summary>
  3832. /// 地址喊邮编 相关处理
  3833. /// </summary>
  3834. public static (string address, string zipCode) SplitAddressZip(string? s)
  3835. {
  3836. if (string.IsNullOrWhiteSpace(s))
  3837. return ("", "");
  3838. ReadOnlySpan<char> src = s.AsSpan();
  3839. int i = src.IndexOf("邮编".AsSpan());
  3840. if (i < 0) // 没有“邮编”字样
  3841. return (src.Trim().ToString(), "");
  3842. ReadOnlySpan<char> addr = src[..i].TrimEnd();
  3843. ReadOnlySpan<char> zip = src[(i + 3)..].Trim(); // 跳过“邮编:”
  3844. // 可能只有“邮编:”而没有数字
  3845. return (addr.IsEmpty ? "" : addr.ToString(),
  3846. zip.IsEmpty ? "" : zip.ToString());
  3847. }
  3848. /// <summary>
  3849. /// 驾照相 关处理
  3850. /// </summary>
  3851. /// <param name="raw"></param>
  3852. /// <returns></returns>
  3853. public static (bool hasLicense, string number, string place) LicenseParser(string? raw)
  3854. {
  3855. if (string.IsNullOrWhiteSpace(raw))
  3856. return (false, "", "");
  3857. // 1. 是否持有
  3858. bool has = raw.StartsWith("是", System.StringComparison.OrdinalIgnoreCase) ||
  3859. raw.StartsWith("Y", System.StringComparison.OrdinalIgnoreCase);
  3860. // 2. 去掉前缀,按空格切
  3861. ReadOnlySpan<char> s = raw.AsSpan();
  3862. int colon = s.IndexOf(':');
  3863. ReadOnlySpan<char> after = colon < 0 ? s : s[(colon + 1)..];
  3864. after = after.Trim();
  3865. int space = after.IndexOf(' ');
  3866. ReadOnlySpan<char> num = space < 0 ? after : after[..space];
  3867. ReadOnlySpan<char> st = space < 0 ? ReadOnlySpan<char>.Empty : after[(space + 1)..];
  3868. return (has, num.ToString().Trim(), st.ToString().Trim());
  3869. }
  3870. /// <summary>
  3871. /// 美国社会安全号或者纳税ID号 相关处理
  3872. /// </summary>
  3873. /// <param name="raw"></param>
  3874. /// <returns></returns>
  3875. public static (bool hasSsnItin, string number) SsnItinParser(string? raw)
  3876. {
  3877. if (string.IsNullOrWhiteSpace(raw))
  3878. return (false, "");
  3879. ReadOnlySpan<char> s = raw.AsSpan();
  3880. // 1. 是否持有
  3881. bool has = s.StartsWith("是", System.StringComparison.Ordinal) ||
  3882. s.StartsWith("Y", System.StringComparison.OrdinalIgnoreCase);
  3883. // 2. 取号码(去掉前缀和空格)
  3884. int colon = s.IndexOf(':');
  3885. ReadOnlySpan<char> num = colon < 0
  3886. ? ReadOnlySpan<char>.Empty
  3887. : s[(colon + 1)..].Trim();
  3888. return (has, num.ToString());
  3889. }
  3890. /// <summary>
  3891. /// 取消开始的“是:”或者“是”或者“ :”
  3892. /// </summary>
  3893. /// <param name="raw"></param>
  3894. /// <returns></returns>
  3895. public static string CleanPrefix(string? raw)
  3896. {
  3897. if (string.IsNullOrWhiteSpace(raw)) return "";
  3898. // 跳过第一个“是”或“Y”
  3899. ReadOnlySpan<char> s = raw.AsSpan();
  3900. int start = 0;
  3901. if (s.StartsWith("是") || s.StartsWith("Y", StringComparison.OrdinalIgnoreCase))
  3902. start = 1;
  3903. // 跳过连续 : 或空格
  3904. while (start < s.Length && (s[start] == ':' || s[start] == ' '))
  3905. start++;
  3906. return s[start..].Trim().ToString();
  3907. }
  3908. /// <summary>
  3909. /// 婚姻起止时间处理
  3910. /// </summary>
  3911. /// <param name="raw"></param>
  3912. /// <returns></returns>
  3913. public static (DateTime? fromDate, DateTime? toDate) WeddingParser(string? raw)
  3914. {
  3915. if (string.IsNullOrWhiteSpace(raw)) return (null, null);
  3916. Regex _clean = new(@"[\s~至]+", RegexOptions.Compiled);
  3917. // 1. 把所有“空格~至”统一成 '-'
  3918. string normalized = _clean.Replace(raw, "-");
  3919. // 2. 切两段
  3920. string[] parts = normalized.Split('-', StringSplitOptions.RemoveEmptyEntries);
  3921. if (parts.Length != 2) return (null, null);
  3922. // 3. 解析
  3923. bool ff = DateTime.TryParse(parts[0].Trim(), out var from);
  3924. bool tf = DateTime.TryParse(parts[1].Trim(), out var to);
  3925. return (tf ? from : null, tf ? to : null);
  3926. }
  3927. /// <summary>
  3928. /// 出行日期和天数处理
  3929. /// </summary>
  3930. /// <param name="raw"></param>
  3931. /// <returns></returns>
  3932. public static (DateTime? travelDate, int? days) TravelParser(string? raw)
  3933. {
  3934. if (string.IsNullOrWhiteSpace(raw)) return (null, null);
  3935. // 切成两段:第一段日期,第二段天数
  3936. Regex sep = new(@"[^0-9./-]+", RegexOptions.Compiled);
  3937. string[] parts = sep.Split(raw.Trim());
  3938. if (parts.Length < 2) return (null, null);
  3939. bool okDate = DateTime.TryParse(parts[0], out DateTime date);
  3940. bool okDays = int.TryParse(parts[1], out int days) && days > 0;
  3941. return (okDate ? date : null, okDays ? days : null);
  3942. }
  3943. /// <summary>
  3944. /// 是否曾抵达过美国
  3945. /// </summary>
  3946. /// <param name="raw"></param>
  3947. /// <returns></returns>
  3948. public static (bool hasTravel, string date, string days) TravelHadFlagParser(string? raw)
  3949. {
  3950. if (string.IsNullOrWhiteSpace(raw)) return (false, string.Empty, string.Empty);
  3951. Regex sep = new(@"[^0-9./-]+", RegexOptions.Compiled);
  3952. // 1. 是否持有
  3953. bool has = raw.AsSpan().TrimStart().StartsWith("是") ||
  3954. raw.AsSpan().TrimStart().StartsWith("Y", StringComparison.OrdinalIgnoreCase);
  3955. // 2. 用非数字分隔符切成三段:第一段空,第二段日期,第三段天数
  3956. string[] parts = sep.Split(raw.Trim());
  3957. if (parts.Length < 3) return (has, string.Empty, string.Empty);
  3958. return (has, parts[1], parts[2]);
  3959. }
  3960. /// <summary>
  3961. /// 是否有被美国拒发签证的经历
  3962. /// </summary>
  3963. /// <param name="raw"></param>
  3964. /// <returns></returns>
  3965. public static (bool wasDenied, DateTime? date, string place, string visaType) VisaDenialParser(string? raw)
  3966. {
  3967. if (string.IsNullOrWhiteSpace(raw)) return (false, null, "", "");
  3968. bool denied = raw.AsSpan().TrimStart().StartsWith("有") ||
  3969. raw.AsSpan().TrimStart().StartsWith("Y", StringComparison.OrdinalIgnoreCase);
  3970. var parts = Regex.Split(raw.Trim(), @"[^0-9A-Za-z-]+");
  3971. if (parts.Length < 4) return (denied, null, "", "");
  3972. DateTime.TryParse(parts[1], out var dt); // ← 这里改为 DateTime
  3973. return (denied, dt, parts[2], parts[3]);
  3974. }
  3975. /// <summary>
  3976. /// 在美直系、旁系 处理
  3977. /// </summary>
  3978. /// <param name="raw"></param>
  3979. /// <returns></returns>
  3980. public static (bool flag, string name, string rel, string stat) FourFieldParser(string? raw)
  3981. {
  3982. if (string.IsNullOrWhiteSpace(raw)) return (false, "", "", "");
  3983. var parts = raw.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
  3984. if (parts.Length < 4) return (false, "", "", "");
  3985. bool flag = parts[0] is "有" or "是" or "Y" or "Yes";
  3986. string name = parts[1];
  3987. string rel = parts[2];
  3988. string stat = parts[3];
  3989. return (flag, name, rel, stat);
  3990. }
  3991. /// <summary>
  3992. /// 服役时间处理
  3993. /// </summary>
  3994. /// <param name="raw"></param>
  3995. /// <returns></returns>
  3996. public static (bool hasService, string branch, string rank, string specialty, (DateTime? start, DateTime? end) period) MilitaryParser(string? raw)
  3997. {
  3998. const string fmt = "yyyy年MM月dd日";
  3999. if (string.IsNullOrWhiteSpace(raw))
  4000. return (false, "", "", "", (null, null));
  4001. var parts = raw.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
  4002. if (parts.Length < 5) return (false, "", "", "", (null, null));
  4003. bool has = parts[0] is "是" or "Y" or "Yes";
  4004. string branch = parts[1];
  4005. string rank = parts[2];
  4006. string specialty = parts[3];
  4007. // 拼回时间字符串
  4008. string periodRaw = string.Join(" ", parts[4..]);
  4009. var span = periodRaw.AsSpan();
  4010. int zhi = span.IndexOf("至");
  4011. if (zhi < 0) return (has, branch, rank, specialty, (null, null));
  4012. var startStr = span.Slice(0, zhi).Trim();
  4013. var endStr = span.Slice(zhi + 1).Trim();
  4014. bool okStart = DateTime.TryParseExact(startStr.ToString(), fmt, null, DateTimeStyles.None, out var start);
  4015. bool okEnd = DateTime.TryParseExact(endStr.ToString(), fmt, null, DateTimeStyles.None, out var end);
  4016. return (has, branch, rank, specialty, (okStart ? start : null, okEnd ? end : null));
  4017. }
  4018. /// <summary>
  4019. /// 申请人父母信息
  4020. /// </summary>
  4021. /// <param name="raw"></param>
  4022. /// <returns></returns>
  4023. public static (string fatherName, DateTime? fatherDob, string motherName, DateTime? motherDob) ParentParser(string? raw)
  4024. {
  4025. const string fmt = "yyyy年MM月dd日";
  4026. if (string.IsNullOrWhiteSpace(raw)) return ("", null, "", null);
  4027. // 按空格切,去掉空元素
  4028. var parts = raw.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
  4029. if (parts.Length < 4) return ("", null, "", null);
  4030. // 父亲
  4031. string fName = parts[0];
  4032. DateTime.TryParseExact(parts[1], fmt, null, DateTimeStyles.None, out var fDob);
  4033. // 母亲
  4034. string mName = parts[2];
  4035. DateTime.TryParseExact(parts[3], fmt, null, DateTimeStyles.None, out var mDob);
  4036. return (fName, fDob, mName, mDob);
  4037. }
  4038. public class VisaDetailsView
  4039. {
  4040. /// <summary>
  4041. /// 客户资料表
  4042. /// </summary>
  4043. public Crm_DeleClient ClientInfo { get; set; }
  4044. /// <summary>
  4045. /// 客户家庭表
  4046. /// </summary>
  4047. public List<Crm_VisaCustomerFamily> ClientFamilys { get; set; }
  4048. /// <summary>
  4049. /// 客户公司表
  4050. /// </summary>
  4051. public Crm_CustomerCompany ClientCompany { get; set; }
  4052. /// <summary>
  4053. /// 客户证件表
  4054. /// </summary>
  4055. public List<Crm_CustomerCert> ClientCerts { get; set; }
  4056. /// <summary>
  4057. /// 客户学历表
  4058. /// </summary>
  4059. public List<Crm_VisaCustomerSchool> ClientSchools { get; set; }
  4060. }
  4061. private int GetSuccessCount(List<FileUploadResult> results)
  4062. {
  4063. var count = 0;
  4064. foreach (var result in results)
  4065. {
  4066. if (result.Success) count++;
  4067. }
  4068. return count;
  4069. }
  4070. #endregion
  4071. #region 文件下载
  4072. /// <summary>
  4073. /// 签证下载类型初始化
  4074. /// </summary>
  4075. private readonly static Dictionary<int, string> _visaTypeInit = new()
  4076. {
  4077. { 1, "美国" },
  4078. { 2, "日本" },
  4079. { 3, "韩国" },
  4080. { 4, "瑞典" },
  4081. { 5, "波兰" },
  4082. //{ 6, "加拿大" },
  4083. { 7, "克罗地亚" },
  4084. { 8, "西班牙" },
  4085. };
  4086. /// <summary>
  4087. /// 申根国
  4088. /// </summary>
  4089. private readonly static string[] _shenGenGuos = new string[] { "奥地利", "比利时", "丹麦", "芬兰", "法国", "德国", "冰岛", "意大利", "希腊", "卢森堡", "荷兰", "挪威", "葡萄牙", "西班牙",
  4090. "瑞典", "匈牙利", "捷克", "斯洛伐克", "斯洛文尼亚","波兰","爱沙尼亚","拉脱维亚","立陶宛","马耳他","瑞士","列支敦士登" };
  4091. /// <summary>
  4092. /// 欧盟国家
  4093. /// </summary>
  4094. private readonly static string[] _eucountries = new string[] { "奥地利", "比利时", "丹麦", "芬兰", "法国", "德国", "意大利", "希腊", "卢森堡", "荷兰", "葡萄牙", "西班牙","爱尔兰","罗马尼亚",
  4095. "保加利亚","匈牙利", "捷克", "斯洛伐克", "斯洛文尼亚","波兰","爱沙尼亚","拉脱维亚","立陶宛","马耳他","瑞士","列支敦士登" };
  4096. /// <summary>
  4097. /// 欧洲国家
  4098. /// </summary>
  4099. private readonly static string[] _aBC = new string[] { "英国", "爱尔兰" };
  4100. /// <summary>
  4101. /// 团组&签证 New
  4102. /// 签证文申请表下载 批量
  4103. /// </summary>
  4104. /// <param name="groupId"></param>
  4105. /// <param name="fileTypeId"></param>
  4106. /// <param name="language">
  4107. /// 下载语言:1-中文,2-英文
  4108. /// </param>
  4109. /// <returns></returns>
  4110. [HttpGet]
  4111. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  4112. public async Task<IActionResult> VisaFileDownload1(int groupId, int fileTypeId, int language = 1)
  4113. {
  4114. if (!_visaTypeInit.TryGetValue(fileTypeId, out _))
  4115. {
  4116. return Ok(JsonView(false, "请选择正确的文件类型!"));
  4117. }
  4118. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0 && x.Id == groupId).First();
  4119. if (groupInfo == null)
  4120. {
  4121. return Ok(JsonView(false, "团组信息不存在!"));
  4122. }
  4123. string group_unique_name = $"{groupInfo.TeamName}_{Guid.NewGuid().ToString("N").Substring(0, 10)}";
  4124. //访问路径
  4125. var serverPath = $"http://132.232.92.186:24/Office/Word/VisaClientData/Downloads/{group_unique_name}/";
  4126. //模板存储位置
  4127. var tempPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Template/";
  4128. //服务器存储文件位置
  4129. var fileServerPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Downloads/{group_unique_name}/";
  4130. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(fileServerPath);
  4131. //文件生成路径
  4132. string url = string.Empty;
  4133. //基础数据
  4134. //团组客户名单
  4135. var groupClients = await _sqlSugar.Queryable<Grp_TourClientList>()
  4136. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  4137. .Select(x => x.ClientId)
  4138. .ToListAsync();
  4139. if (groupClients.Count < 1)
  4140. {
  4141. return Ok(JsonView(false, "该团组下暂无团组名单!"));
  4142. }
  4143. //团组客户详细信息
  4144. var groupCustInfos = _sqlSugar.Queryable<Crm_DeleClient>().Where(x => x.IsDel == 0 && groupClients.Contains(x.Id)).ToList();
  4145. //家庭成员资料
  4146. var familyInfos = _sqlSugar.Queryable<Crm_VisaCustomerFamily>().Where(x => x.IsDel == 0 && groupClients.Contains(x.DcId)).ToList();
  4147. //公司资料
  4148. var companyInfo‌‌s = _sqlSugar.Queryable<Crm_VisaCustomerCompany>().Where(x => x.IsDel == 0 && groupClients.Contains(x.DcId)).ToList();
  4149. //学校资料
  4150. var schoolInfos = _sqlSugar.Queryable<Crm_VisaCustomerSchool>().Where(x => x.IsDel == 0 && groupClients.Contains(x.DcId)).ToList();
  4151. /* 证件类型
  4152. *
  4153. * 773 身份证
  4154. * 774 护照
  4155. * 775 学生证
  4156. * 776 军人证
  4157. * 777 回乡证
  4158. * 778 台胞证
  4159. * 779 港澳通行证
  4160. * 780 国际海员证
  4161. * 781 外国人永久居留证
  4162. * 782 旅行证
  4163. * 783 台湾通行证
  4164. * 784 港澳台居住证
  4165. * 785 其他
  4166. */
  4167. //证件资料
  4168. var certInfos = _sqlSugar.Queryable<Crm_CustomerCert>().Where(x => x.IsDel == 0 && groupClients.Contains(x.DcId)).ToList();
  4169. var applyDate = DateTime.Now.ToString("yyyy-MM-dd");
  4170. var filePaths = new List<string>();
  4171. var visaTypeName = string.Empty;
  4172. var currTempPath = string.Empty;
  4173. switch (fileTypeId)
  4174. {
  4175. case 1: // 美国
  4176. visaTypeName = $"美国签证申请表";
  4177. currTempPath = $"{tempPath}{visaTypeName}.doc";
  4178. var usaSavePath = $"{fileServerPath}{visaTypeName}/";
  4179. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(usaSavePath);
  4180. foreach (var custInfo in groupCustInfos)
  4181. {
  4182. //解密
  4183. EncryptionProcessor.DecryptProperties(custInfo);
  4184. Dictionary<string, string> dics = new();
  4185. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  4186. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  4187. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  4188. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4189. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4190. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4191. #region 美国签证模板书签值处理
  4192. dics.Add("LastNameEn", custInfo?.LastName ?? "");//名拼音
  4193. dics.Add("FirstNameEn", custInfo?.FirstName ?? "");//姓拼音
  4194. dics.Add("LastName", custInfo?.LastName ?? "");//名
  4195. dics.Add("FirstName", custInfo?.FirstName ?? "");//姓
  4196. dics.Add("OldNameEn", custInfo?.OldName ?? "");//曾用姓名拼音
  4197. dics.Add("OldName", custInfo?.FirstName ?? "");//曾用姓名
  4198. //未设置、未婚、已婚、离异、丧偶
  4199. var marriage = custInfo.Marriage switch
  4200. {
  4201. 0 => "未设置",
  4202. 1 => "未婚",
  4203. 2 => "已婚",
  4204. 3 => "离异",
  4205. 4 => "丧偶",
  4206. _ => "未知"
  4207. };
  4208. dics.Add("Marriage", marriage);//婚姻状况
  4209. dics.Add("Phone", custInfo?.Phone ?? "");//家庭电话
  4210. dics.Add("BirthCity", custInfo?.BirthCity ?? "");//出生城市
  4211. dics.Add("BirthProvince", custInfo?.BirthProvince ?? "");//出生省份
  4212. string m_idCard = idInfo?.CertNo ?? "";
  4213. string m_birthday = string.Empty;
  4214. if (!string.IsNullOrEmpty(m_idCard))
  4215. {
  4216. string m_year = m_idCard.Substring(6, 4);
  4217. string m_month = m_idCard.Substring(10, 2);
  4218. string m_day = m_idCard.Substring(12, 2);
  4219. m_birthday = m_year + "." + m_month + "." + m_day;
  4220. }
  4221. dics.Add("BirthDay", m_birthday);//出生日期
  4222. dics.Add("Tel", custInfo?.Tel ?? "");//移动电话
  4223. dics.Add("Email", custInfo?.Email ?? "");//电子信箱
  4224. dics.Add("IdCard", m_idCard);//身份证号码
  4225. dics.Add("Address", custInfo?.Address ?? "");//现居家庭地址
  4226. dics.Add("PostCodes", custInfo?.PostCodes ?? "");//邮编
  4227. dics.Add("Client", clinetInfo?.Company ?? "");//单位名称
  4228. dics.Add("ClientAddress", clinetInfo?.CompanyAddress ?? "");//单位地址
  4229. dics.Add("ClientPostCodes", custInfo?.PostCodes ?? "");//单位邮编
  4230. dics.Add("Job", custInfo?.Job ?? "");//职务
  4231. dics.Add("WorkDate", custInfo?.WorkDate ?? "");//入职时间
  4232. dics.Add("Wage", custInfo?.Wage ?? "");//月薪
  4233. dics.Add("ClientPhone", custInfo?.ClientPhone ?? "");//单位电话
  4234. dics.Add("ClientFax", custInfo?.ClientFax ?? "");//单位传真
  4235. dics.Add("ClientEmail", custInfo?.ClientEmail ?? "");//单位邮箱
  4236. dics.Add("ClientLeader", custInfo?.ClientLeader ?? "");//单位主管姓名
  4237. dics.Add("ClientLeaderJob", custInfo?.ClientLeaderJob ?? "");//单位主管职务
  4238. dics.Add("WorkState", custInfo?.WorkState ?? "");//工作内容简单介绍
  4239. dics.Add("IsGetSchengen", custInfo?.IsGetSchengen == 0 ? "否" : "是");//是否有获批的申根签证
  4240. dics.Add("StartTime", custInfo?.StartTime.ToString("yyyy-MM-dd") ?? "");//申根签证有效期开始
  4241. dics.Add("EndTime", custInfo?.EndTime.ToString("yyyy-MM-dd") ?? "");//申根签证有效期结束
  4242. dics.Add("IsFinger", custInfo.IsFinger == 0 ? "否" : "是");//申根签证是否有指纹记录
  4243. dics.Add("FingerDate", custInfo?.FingerDate?.ToString("yyyy-MM-dd") ?? "");//申根签指纹采集时间
  4244. dics.Add("TableOpName", custInfo?.TableOpName ?? "");//填表经办人
  4245. dics.Add("TableOpTel", custInfo?.TableOpTel ?? "");//填表经办人联系电话
  4246. dics.Add("TableDate", custInfo?.TableDate.ToString("yyyy-MM-dd") ?? "");//填表日期
  4247. dics.Add("Party", custInfo?.Party ?? "");//所属党派或宗教
  4248. dics.Add("Nationality", custInfo?.Nationality ?? "");//国籍
  4249. var sex = custInfo.Sex switch
  4250. {
  4251. 0 => "男",
  4252. 1 => "女",
  4253. _ => "未知"
  4254. };
  4255. dics.Add("Sex", sex);//性别
  4256. dics.Add("WeddingDate", custInfo?.WeddingDate?.ToString("yyyy-MM-dd") ?? "");//结婚日期
  4257. dics.Add("DivorceDate", custInfo?.DivorceDate?.ToString("yyyy-MM-dd") ?? "");//离婚日期
  4258. dics.Add("MateName", custInfo?.MateName ?? "");//配偶姓名
  4259. dics.Add("MateBirthDay", custInfo?.MateBirthDay.ToString("yyyy-MM-dd") ?? "");//配偶出生日期
  4260. dics.Add("MateBirthCity", custInfo?.MateBirthCity ?? "");//配偶出生城市
  4261. dics.Add("MateBirthCountry", custInfo?.MateBirthCountry ?? "");//配偶出生省份
  4262. dics.Add("MateAddress", custInfo?.MateAddress ?? "");//配偶住址
  4263. dics.Add("MateClient", custInfo?.MateClient ?? "");//配偶工作单位名称
  4264. dics.Add("MateClientAddress", custInfo?.MateClientAddress ?? "");//配偶工作单位地址
  4265. dics.Add("MateJob", custInfo?.MateJob ?? "");//配偶职务
  4266. dics.Add("VisitCountry", custInfo?.VisitCountry ?? "");//因公出访的国家
  4267. dics.Add("Paper", custInfo?.Paper ?? "");//发表的期刊、论文
  4268. dics.Add("Papent", custInfo?.Papent ?? "");//专利
  4269. dics.Add("PhD", custInfo?.PhD ?? "");//博士论文
  4270. dics.Add("IsVisitUC", custInfo?.IsVisitUC == 0 ? "否" : "是" ?? "");//是否因公去过美国/加拿大
  4271. dics.Add("USADate", custInfo?.USADate?.ToString("yyyy-MM-dd") ?? "");//美国抵达日期
  4272. dics.Add("USADays", custInfo?.USADays.ToString() ?? "");//美国停留天数
  4273. dics.Add("CanDate", custInfo?.CanDate.ToString("yyyy-MM-dd") ?? "");//加拿大抵达日期
  4274. dics.Add("CanDays", custInfo?.CanDays.ToString() ?? "");//加拿大停留天数
  4275. dics.Add("IsUSAVia", custInfo?.IsUSAVia == 0 ? "否" : "是" ?? "");//是否获得过因公美国签证
  4276. dics.Add("GetUSAVisaDate", custInfo?.GetUSAVisaDate?.ToString("yyyy-MM-dd") ?? "");//因公美国签证时间
  4277. dics.Add("GetUPPlace", custInfo?.GetUPPlace ?? "");//因公美国签证地点
  4278. dics.Add("USAVisaCate", custInfo?.USAVisaCate ?? "");//因公美国签证种类
  4279. dics.Add("USAVisaCode", custInfo?.USAVisaCode ?? "");//因公美国签证编码
  4280. dics.Add("USAFinger", custInfo?.USAFinger == 0 ? "否" : "是" ?? "");//是否在使馆留过十指的指纹
  4281. dics.Add("IsRejected", custInfo?.IsRejected == 0 ? "否" : "是" ?? "");//是否被拒
  4282. dics.Add("RejectedDate", custInfo?.RejectedDate?.ToString("yyyy-MM-dd") ?? "");//被拒时间
  4283. dics.Add("RejectedPlace", custInfo?.RejectedPlace ?? "");//被拒地点
  4284. dics.Add("RejectedVisa", custInfo?.RejectedVisa ?? "");//被拒签证种类
  4285. dics.Add("IsRevoke", custInfo?.IsRevoke == 0 ? "否" : "是" ?? "");//美国签证是否被吊销
  4286. dics.Add("IsLose", custInfo?.IsLose == 0 ? "否" : "是" ?? "");//护照是否丢失
  4287. dics.Add("LoseDate", custInfo?.LoseDate.ToString("yyyy-MM-dd") ?? "");//丢失的护照时间
  4288. dics.Add("LoseCode", custInfo?.LoseCode ?? "");//丢失的护照号码
  4289. dics.Add("IsUSAVisa", custInfo?.IsUSAVisa == 0 ? "否" : "是" ?? "");//丢失的护照是否有美国签证
  4290. dics.Add("MateUSA", custInfo?.MateUSA == 0 ? "否" : "是" ?? "");//夫/妻是否已在美国
  4291. dics.Add("MateIden", custInfo?.MateIden ?? "");//夫/妻身份
  4292. dics.Add("WHUSA", custInfo?.WHUSA == 0 ? "否" : "是" ?? "");//未婚夫/妻是否已在美国
  4293. dics.Add("WHIden", custInfo?.WHIden ?? "");//未婚夫/妻身份
  4294. dics.Add("ParentUSA", custInfo?.ParentUSA == 0 ? "否" : "是" ?? "");//父/母是否已在美国
  4295. dics.Add("ParentIden", custInfo?.ParentIden ?? "");//父/母身份
  4296. dics.Add("ChildUSA", custInfo?.ChildUSA == 0 ? "否" : "是" ?? "");//儿子/女儿是否已在美国
  4297. dics.Add("ChildIden", custInfo?.ChildIden ?? "");//儿子/女儿身份
  4298. dics.Add("BroUSA", custInfo?.BroUSA == 0 ? "否" : "是" ?? "");//兄弟/姐妹是否已在美国
  4299. dics.Add("BroIden", custInfo?.BroIden ?? "");//兄弟/姐妹身份
  4300. dics.Add("Social", custInfo?.Social ?? "");//所属/捐助/工作过的职业协会、社会团体和慈善机构
  4301. dics.Add("IsArmy", custInfo?.IsArmy == 0 ? "否" : "是" ?? "");//是否参军
  4302. dics.Add("ArmyState", custInfo?.ArmyState ?? "");//参军详情
  4303. dics.Add("ApplyDate", applyDate);//申请日期
  4304. //公司信息书签
  4305. if (currCompanyInfos.Count > 0)
  4306. {
  4307. for (int i = 0; i < currCompanyInfos.Count; i++)
  4308. {
  4309. var compnayInfo = currCompanyInfos[i];
  4310. if (!string.IsNullOrEmpty(compnayInfo.Company))
  4311. {
  4312. dics.Add("Company", compnayInfo?.Company ?? "");//公司名称
  4313. dics.Add("CompanyAddress", compnayInfo?.CompanyAddress ?? "");//公司地址
  4314. dics.Add("CompanyPhone", compnayInfo?.Phone ?? "");//公司电话
  4315. dics.Add("CompanyJob", compnayInfo?.Job ?? "");//职务
  4316. dics.Add("CompanyLeaderName", compnayInfo?.LeaderName ?? "");//主管名字
  4317. dics.Add("CompanyWorkStart", compnayInfo?.WorkStart?.ToString("yyyy-MM-dd") ?? "");//雇佣起始年月日
  4318. dics.Add("CompanyWorkEnd", compnayInfo?.WorkEnd?.ToString("yyyy-MM-dd") ?? "");//雇佣结束年月日
  4319. dics.Add("CompanyWorkState", compnayInfo?.WorkState ?? "");//工作职责及内容简述
  4320. }
  4321. else break;
  4322. }
  4323. }
  4324. //学校信息书签
  4325. if (currSchoolInfos.Count > 0)
  4326. {
  4327. for (int i = 0; i < currSchoolInfos.Count; i++)
  4328. {
  4329. var schoolInfo = currSchoolInfos[i];
  4330. if (!string.IsNullOrEmpty(schoolInfo.School))
  4331. {
  4332. dics.Add("School", schoolInfo?.School ?? "");//学校名称和学历
  4333. dics.Add("SchoolAddress", schoolInfo?.Address ?? "");//学校地址
  4334. dics.Add("SchoolTeacher", schoolInfo?.Teacher ?? "");//指导老师
  4335. dics.Add("SchoolSubject", schoolInfo?.Subject ?? "");//所学课程或专业名称
  4336. dics.Add("SchoolStudyStart", schoolInfo?.StudyStart?.ToString("yyyy-MM-dd") ?? "");//就读起始日
  4337. dics.Add("SchoolStudyEnd", schoolInfo?.StudyEnd?.ToString("yyyy-MM-dd") ?? "");//就读结束日
  4338. }
  4339. else break;
  4340. }
  4341. }
  4342. //家人信息书签
  4343. if (currFamilyInfos.Count > 0)
  4344. {
  4345. for (int i = 0; i < currFamilyInfos.Count; i++)
  4346. {
  4347. var familyInfo = currFamilyInfos[i];
  4348. if (!string.IsNullOrEmpty(familyInfo.Appellation))
  4349. {
  4350. dics.Add("FamilyAppellation", familyInfo?.Appellation ?? "");//家庭成员称谓
  4351. dics.Add("FamilyName", familyInfo?.Name ?? "");//家庭成员姓名
  4352. dics.Add("FamilyBirthDay", familyInfo?.BirthDay?.ToString("yyyy-MM-dd") ?? "");//家庭成员出生日期
  4353. dics.Add("FamilyBirthPlace", familyInfo?.BirthPlace ?? "");// 家庭成员出生地
  4354. dics.Add("FamilyPolitics", familyInfo?.Politics ?? "");//家庭成员政治面貌
  4355. dics.Add("FamilyClient", familyInfo?.Client ?? "");//家庭成员工作单位
  4356. dics.Add("FamilyAddress", familyInfo?.Address ?? "");// 家庭地址
  4357. dics.Add("IsEu", familyInfo?.IsEu == 0 ? "No" : "Yes" ?? "");// 欧盟公民
  4358. dics.Add("FamilyNameSnd", familyInfo?.NameSnd ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员姓名
  4359. dics.Add("FamilyBirthDaySnd", familyInfo?.BirthDaySnd.ToString("yyyy-MM-dd") ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员生日
  4360. dics.Add("FamilyNationality", familyInfo?.Nationality ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员国籍
  4361. dics.Add("FamilyIDCard", familyInfo?.IDCard ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员旅行证件编号或身份证号码
  4362. dics.Add("FamilyReletionship", familyInfo?.Reletionship ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员与申请人的关系
  4363. dics.Add("IsUSA", familyInfo?.IsUSA == 1 ? "是" : "否" ?? "");// 家庭成员是否在美国
  4364. }
  4365. else break;
  4366. }
  4367. }
  4368. #endregion
  4369. #region 生成文件
  4370. try
  4371. {
  4372. _logger.LogInformation("模板位置:{currTempPath}", currTempPath);
  4373. Document doc = new(currTempPath);
  4374. Aspose.Words.DocumentBuilder builder = new(doc);
  4375. string strTemp = "";
  4376. //循环键值对
  4377. foreach (var key in dics.Keys)
  4378. {
  4379. //将光标移入书签的位置
  4380. builder.MoveToBookmark(key);
  4381. //判断书签值是否为空
  4382. if (!string.IsNullOrEmpty(dics[key]))
  4383. {
  4384. strTemp = dics[key];
  4385. }
  4386. else strTemp = "";
  4387. //填充书签
  4388. builder.Write(strTemp.Replace("\\N", "\n"));
  4389. }
  4390. var custName = custInfo.LastName + custInfo.FirstName;
  4391. string fileName = $"{custName}_{visaTypeName}.doc";
  4392. var currFilePath = $"{usaSavePath}{fileName}";
  4393. doc.Save(currFilePath);
  4394. filePaths.Add(currFilePath);
  4395. }
  4396. catch (Exception ex)
  4397. {
  4398. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  4399. }
  4400. #endregion
  4401. }
  4402. break;
  4403. case 2: // 日本
  4404. visaTypeName = $"新办日本申请表";
  4405. currTempPath = $"{tempPath}/{visaTypeName}.pdf";
  4406. var jpnSavePath = $"{fileServerPath}/{visaTypeName}/";
  4407. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(jpnSavePath);
  4408. foreach (var custInfo in groupCustInfos)
  4409. {
  4410. EncryptionProcessor.DecryptProperties(custInfo);
  4411. Dictionary<string, string> dics = new();
  4412. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  4413. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  4414. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  4415. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4416. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4417. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4418. #region 生成文件
  4419. PdfReader reader = null;
  4420. FileStream templateStream = null;
  4421. FileStream outputStream = null;
  4422. PdfStamper stamper = null;
  4423. try
  4424. {
  4425. string outputPath = $"{jpnSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  4426. //读取模板文件
  4427. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  4428. reader = new PdfReader(templateStream);
  4429. //创建输出文件
  4430. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  4431. stamper = new PdfStamper(reader, outputStream);
  4432. AcroFields formFields = stamper.AcroFields;
  4433. #region 设置文本值
  4434. SetFieldValue(formFields, "surname_en", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? ""); // 姓 英文
  4435. SetFieldValue(formFields, "name_en", CommonFun.ConvertToPinyin(custInfo?.FirstName?.Trim() ?? "")?.ToLower() ?? ""); // 名 英文
  4436. SetFieldValue(formFields, "surname_cn", custInfo?.LastName ?? ""); // 姓 中文
  4437. SetFieldValue(formFields, "name_cn", custInfo?.FirstName ?? ""); // 名 中文
  4438. if (!string.IsNullOrEmpty(custInfo.OldName))
  4439. {
  4440. SetFieldValue(formFields, "formername_en", CommonFun.ConvertToPinyin(custInfo?.OldName?.Trim() ?? "")?.ToLower() ?? ""); // 出生时姓氏
  4441. SetFieldValue(formFields, "formername_cn", custInfo.OldName); // 出生时姓氏
  4442. }
  4443. else
  4444. {
  4445. SetFieldValue(formFields, "formername_cn", custInfo.OldName); // 出生时姓氏
  4446. }
  4447. // 出生日期(日-月-年)
  4448. string idCard = idInfo?.CertNo?.Trim() ?? "";
  4449. string birthday = string.Empty;
  4450. if (!string.IsNullOrEmpty(idCard))
  4451. {
  4452. string year = idCard.Substring(6, 4);
  4453. string month = idCard.Substring(10, 2);
  4454. string day = idCard.Substring(12, 2);
  4455. birthday = day + "-" + month + "-" + year;
  4456. }
  4457. SetFieldValue(formFields, "birthday", birthday);
  4458. string currentNationality = custInfo.BirthProvince + custInfo.BirthCity;
  4459. SetFieldValue(formFields, "birthplace", currentNationality); // 出生地
  4460. SetFieldValue(formFields, "nationality", "中国"); // 出生国
  4461. SetFieldValue(formFields, "previous_nationality", "中国"); // 现国籍
  4462. SetFieldValue(formFields, "IdNo", idCard); // 身份证号码
  4463. #region 性别处理
  4464. //清除性别
  4465. SetFieldValue(formFields, "sex_man", "Off"); // 性别 - 男
  4466. SetFieldValue(formFields, "sex_woman", "Off"); // 性别 - 女
  4467. //设置性别
  4468. if (custInfo.Sex == 0) //男
  4469. {
  4470. SetFieldValue(formFields, "sex_man", "Yes"); // 性别 - 男
  4471. }
  4472. else if (custInfo.Sex == 1) //女
  4473. {
  4474. SetFieldValue(formFields, "sex_woman", "Yes"); // 性别 - 女
  4475. }
  4476. #endregion
  4477. #region 婚姻状况处理
  4478. //清除婚姻状况
  4479. SetFieldValue(formFields, "marriage_single", "Off"); // 婚姻状况 - 未婚
  4480. SetFieldValue(formFields, "marriage_married", "Off"); // 婚姻状况 - 已婚
  4481. SetFieldValue(formFields, "marriage_divorce", "Off"); // 婚姻状况 - 离婚
  4482. SetFieldValue(formFields, "marriage_widowedw", "Off"); // 婚姻状况 - 丧偶
  4483. //设置婚姻状况
  4484. switch (custInfo.Marriage)
  4485. {
  4486. case 1: // 未婚
  4487. SetFieldValue(formFields, "marriage_single", "Yes");
  4488. break;
  4489. case 2: // 已婚
  4490. SetFieldValue(formFields, "marriage_married", "Yes");
  4491. break;
  4492. case 3: // 离异
  4493. SetFieldValue(formFields, "marriage_divorce", "Yes");
  4494. break;
  4495. case 4: // 离异
  4496. SetFieldValue(formFields, "marriage_widowedw", "Yes");
  4497. break;
  4498. }
  4499. #endregion
  4500. #region 护照(旅行证件类型)
  4501. //清除值
  4502. SetFieldValue(formFields, "passport_diplomacy", "Off"); // 旅行证件类型 - 外交护照
  4503. SetFieldValue(formFields, "passport_official", "Off"); // 旅行证件类型 - 公务护照
  4504. SetFieldValue(formFields, "passport_ordinary", "Off"); // 旅行证件类型 - 普通护照
  4505. SetFieldValue(formFields, "passport_other", "Off"); // 旅行证件类型 - 其它
  4506. //设置值
  4507. if (passportInfo != null)
  4508. {
  4509. // 签证类型
  4510. var visatypeInfo = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == passportInfo.PassportType);
  4511. if (visatypeInfo != null)
  4512. {
  4513. string visaName = visatypeInfo?.Name ?? "-";
  4514. if (visaName.contains("外交")) SetFieldValue(formFields, "passport_diplomacy", "Yes"); // 旅行证件类型 - 外交护照
  4515. else if (visaName.contains("公务")) SetFieldValue(formFields, "passport_official", "Yes"); // 旅行证件类型 - 公务护照
  4516. else if (visaName.contains("普通")) SetFieldValue(formFields, "passport_ordinary", "Yes"); // 旅行证件类型 - 普通护照
  4517. else if (visaName.contains("其它")) SetFieldValue(formFields, "passport_other", "Yes"); // 旅行证件类型 - 其它
  4518. else SetFieldValue(formFields, "passport_ordinary", "Yes"); // 旅行证件类型 - 普通护照
  4519. }
  4520. SetFieldValue(formFields, "passport_no", passportInfo.CertNo); // 签证编号
  4521. SetFieldValue(formFields, "passport_issuplice", passportInfo.Country + passportInfo.Area); // 签发 国、地区
  4522. SetFieldValue(formFields, "passport_issuauthority", ""); // 签发机关
  4523. SetFieldValue(formFields, "passport_issudate", passportInfo.IssueDt?.ToString("yyyy-MM-dd") ?? ""); // 签发日期
  4524. SetFieldValue(formFields, "passport_validdate", passportInfo.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); // 有效期至
  4525. }
  4526. #endregion
  4527. SetFieldValue(formFields, "certification_number", ""); // 再留资格认证证书编号
  4528. SetFieldValue(formFields, "residentialstatus_purposetojapan", groupInfo?.VisitPurpose ?? ""); // 居住身份、赴日目的
  4529. // 签证国家下的城市
  4530. string city = "";
  4531. string county = "";
  4532. #region 入境信息
  4533. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  4534. if (atbc != null)
  4535. {
  4536. string startTime = string.Empty; // 开始停留时间
  4537. string endTime = string.Empty; // 离开时间
  4538. string three = string.Empty; // 航司
  4539. string threeCode = string.Empty; // 入境口岸
  4540. for (int i = 0; i < atbc.Rows.Count; i++)
  4541. {
  4542. if (i == 0) //得到抵达日期
  4543. {
  4544. three = atbc.Rows[i]["Fliagtcode"].ToString();
  4545. startTime = atbc.Rows[i]["Day"].ToString();
  4546. threeCode = atbc.Rows[i]["Three"].ToString();
  4547. continue;
  4548. }
  4549. if (i == 1)
  4550. endTime = atbc.Rows[i]["Day"].ToString();
  4551. }
  4552. dics.Add("japandate_stay", startTime); // 预计逗留日期 起
  4553. dics.Add("japandate_end", endTime); // 预计逗留日期 止
  4554. dics.Add("japanduring", startTime); // 预计逗留期间
  4555. if (!string.IsNullOrEmpty(three))
  4556. {
  4557. //查询航司名称
  4558. var threeCodeTwo = three.Substring(0, 2);
  4559. var ac = _sqlSugar.Queryable<Res_AirCompany>().Where(x => x.ShortCode == threeCodeTwo).First();
  4560. if (ac != null)
  4561. {
  4562. dics.Add("shiporairlinename", $"{ac?.EnName ?? ""} {three}"); // 航司名称
  4563. }
  4564. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  4565. if (tc != null)
  4566. {
  4567. county = tc.Country;
  4568. city = tc.City;
  4569. dics.Add("portentry", tc?.City ?? ""); // 入境口岸
  4570. }
  4571. }
  4572. }
  4573. #endregion
  4574. #region 申请人酒店信息
  4575. if (!string.IsNullOrEmpty(city))
  4576. {
  4577. //得到当前国家下的城市酒店信息
  4578. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  4579. .Where(x => x.DiId == groupId)
  4580. .Where(x => x.City.contains(city))
  4581. .First();
  4582. //酒店住址
  4583. if (hotelInfo != null)
  4584. {
  4585. dics.Add("hotelorfriend_name", hotelInfo?.HotelName ?? ""); // 酒店名称
  4586. dics.Add("hotelorfriend_tel", hotelInfo?.HotelAddress ?? ""); // 酒店地址
  4587. dics.Add("hotelorfriend_address", hotelInfo?.HotelTel ?? ""); // 酒店电话
  4588. }
  4589. }
  4590. #endregion
  4591. SetFieldValue(formFields, "japanduring_lasttime", ""); // 上次赴日日期及停留时间
  4592. #region 家庭信息
  4593. SetFieldValue(formFields, "family_address", custInfo.Address); // 地址
  4594. SetFieldValue(formFields, "family_tel", custInfo.Tel); // 电话
  4595. SetFieldValue(formFields, "family_phone", custInfo.Phone); // 手机
  4596. SetFieldValue(formFields, "family_email", custInfo.Email); // 电子邮件
  4597. #endregion
  4598. #region 工作单位信息
  4599. SetFieldValue(formFields, "company_name", companyInfos?.FirstOrDefault()?.Company ?? ""); // 名称
  4600. SetFieldValue(formFields, "company_tel", companyInfos?.FirstOrDefault()?.Phone ?? ""); // 电话
  4601. SetFieldValue(formFields, "family_address", companyInfos?.FirstOrDefault()?.CompanyAddress ?? "");// 地址
  4602. SetFieldValue(formFields, "company_job", custInfo?.Job ?? ""); // 职位
  4603. #endregion
  4604. SetFieldValue(formFields, "spouseorparents_job", custInfo?.MateJob ?? ""); // 配偶职业(如果是未成年人请填写服务的职业)
  4605. #region 担保人、邀请人 信息
  4606. if (!string.IsNullOrEmpty(county) && !string.IsNullOrEmpty(city))
  4607. {
  4608. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  4609. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  4610. .Where(x => x.Country.Contains(county))
  4611. .Where(x => x.Area.Contains(city))
  4612. .First();
  4613. //邀请 接待单位
  4614. if (oa != null)
  4615. {
  4616. dics.Add("guarantor_name_en", CommonFun.ConvertToPinyin(oa?.Contact?.Trim() ?? "")?.ToLower() ?? ""); // 担保人姓名(英文)
  4617. dics.Add("guarantor_name_cn", oa?.Contact ?? ""); // 担保人姓名(中文)
  4618. dics.Add("guarantor_tel", oa?.Tel ?? ""); // 担保人电话
  4619. dics.Add("guarantor_address_en", CommonFun.ConvertToPinyin(oa?.Address?.Trim() ?? "")?.ToLower() ?? ""); //担保人地址(英文)
  4620. dics.Add("guarantor_address_cn", oa?.Address ?? ""); // 担保人地址(中文)
  4621. dics.Add("guarantor_occuandposition", oa?.Job ?? ""); // 担保人职务
  4622. dics.Add("guarantor_relationship", "邀请方"); // 和申请人关系
  4623. dics.Add("guarantor_birthday", ""); // 出生日期
  4624. dics.Add("guarantor_sex_woman", "Off"); // 性别 女
  4625. dics.Add("guarantor_sex_man", "Off"); // 性别 男
  4626. dics.Add("guarantor_nationalityandvisatype", "日本"); // 邀请方 国家
  4627. dics.Add("inviter_name", "同上"); // 邀请人 姓名
  4628. dics.Add("inviter_tel", "同上"); // 邀请人 电话
  4629. dics.Add("inviter_addres", "同上"); // 邀请人 地址
  4630. dics.Add("inviter_birthday", "同上"); // 邀请人 出生日期
  4631. dics.Add("inviter_sex_man", "Off"); // 邀请人 性别 女
  4632. dics.Add("inviter_sex_woman", "Off"); // 邀请人 性别 男
  4633. dics.Add("inviter_relationship", "同上"); // 邀请人 与申请人关系
  4634. dics.Add("inviter_occuandposition", "同上"); // 邀请人 职业、职务
  4635. dics.Add("inviter_nationalityandvisatype", "同上"); // 邀请人 国籍
  4636. dics.Add("inviter_remark", ""); // 邀请人 备注
  4637. }
  4638. }
  4639. #endregion
  4640. #region 犯罪信息
  4641. // 在任何国家曾被判决有罪
  4642. dics.Add("criminal_conviction_yes", "Off");
  4643. dics.Add("criminal_conviction_no", "Off");
  4644. // 在任何国家曾被判处一年或一年以上徒刑
  4645. dics.Add("felony_conviction_yes", "Off");
  4646. dics.Add("felony_conviction_no", "Off");
  4647. // 在任何国家曾因非法滞留或违反改过法律法规而被驱逐出镜
  4648. dics.Add("deportation_order_yes", "Off");
  4649. dics.Add("deportation_order_no", "Off");
  4650. // 因违反毒品相关法律被判刑
  4651. dics.Add("drug_conviction_yes", "Off");
  4652. dics.Add("drug_conviction_no", "Off");
  4653. // 从事或参与卖淫相关活动
  4654. dics.Add("prostitution_involvement_yes", "Off");
  4655. dics.Add("prostitution_involvement_no", "Off");
  4656. // 贩卖人口相关犯罪经历
  4657. dics.Add("human_trafficking_offense_yes", "Off");
  4658. dics.Add("human_trafficking_offense_no", "Off");
  4659. //备注
  4660. dics.Add("yes_remark", "");
  4661. #endregion
  4662. SetFieldValue(formFields, "application_date", DateTime.Now.ToString("dd/MM/yyyy")); // 申请日期
  4663. #endregion
  4664. filePaths.Add(outputPath);
  4665. //return outputPath;
  4666. }
  4667. catch (Exception ex)
  4668. {
  4669. return Ok(JsonView(false, $"生成PDF文件时出错:{ex.Message}"));
  4670. }
  4671. finally
  4672. {
  4673. // 按正确顺序关闭资源
  4674. stamper?.Close();
  4675. reader?.Close();
  4676. templateStream?.Close();
  4677. outputStream?.Close();
  4678. }
  4679. #endregion
  4680. }
  4681. break;
  4682. case 3: // 韩国
  4683. visaTypeName = $"韩国签证申请表";
  4684. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  4685. var korSavePath = $"{fileServerPath}{visaTypeName}/";
  4686. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(korSavePath);
  4687. foreach (var custInfo in groupCustInfos)
  4688. {
  4689. EncryptionProcessor.DecryptProperties(custInfo);
  4690. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  4691. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  4692. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  4693. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4694. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4695. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4696. #region 生成文件
  4697. PdfReader reader = null;
  4698. FileStream templateStream = null;
  4699. FileStream outputStream = null;
  4700. PdfStamper stamper = null;
  4701. try
  4702. {
  4703. string outputPath = $"{korSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  4704. //读取模板文件
  4705. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  4706. reader = new PdfReader(templateStream);
  4707. //创建输出文件
  4708. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  4709. stamper = new PdfStamper(reader, outputStream);
  4710. AcroFields formFields = stamper.AcroFields;
  4711. #region 设置文本值
  4712. string selected = "√";
  4713. #region 1. 个人信息
  4714. SetFieldValue(formFields, "family_name", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? ""); // 姓 英文
  4715. SetFieldValue(formFields, "given_names", CommonFun.ConvertToPinyin(custInfo?.FirstName?.Trim() ?? "")?.ToLower() ?? ""); // 名 英文
  4716. string name_cn = custInfo.LastName + custInfo.FirstName;
  4717. SetFieldValue(formFields, "name_cn", name_cn); // 姓名 中文
  4718. #region 性别
  4719. //清除性别
  4720. SetFieldValue(formFields, "sex_male", "Off"); // 性别 - 男
  4721. SetFieldValue(formFields, "sex_female", "Off"); // 性别 - 女
  4722. //设置性别
  4723. if (custInfo.Sex == 0) //男
  4724. {
  4725. SetFieldValue(formFields, "sex_male", "Yes"); // 性别 - 男
  4726. }
  4727. else if (custInfo.Sex == 1) //女
  4728. {
  4729. SetFieldValue(formFields, "sex_female", "Yes"); // 性别 - 女
  4730. }
  4731. #endregion
  4732. #region 出生日期(日-月-年)
  4733. string idCard = idInfo?.CertNo?.Trim() ?? "";
  4734. string birthday = string.Empty;
  4735. if (!string.IsNullOrEmpty(idCard))
  4736. {
  4737. string year = idCard.Substring(6, 4);
  4738. string month = idCard.Substring(10, 2);
  4739. string day = idCard.Substring(12, 2);
  4740. birthday = day + "-" + month + "-" + year;
  4741. }
  4742. SetFieldValue(formFields, "birthday", birthday);
  4743. #endregion
  4744. SetFieldValue(formFields, "previous_nationality", "中国"); // 现国籍
  4745. SetFieldValue(formFields, "nationality", "中国"); // 出生国
  4746. SetFieldValue(formFields, "IdNo", idCard); // 身份证号码
  4747. #region 是否曾用别名从韩国出入境
  4748. SetFieldValue(formFields, "applicant_no", selected); // 否 默认选中
  4749. SetFieldValue(formFields, "applicant_yes", "");
  4750. string isGetSchengenStr = custInfo.IsGetSchengen == 0 ? "否" : "是";
  4751. string oldName = custInfo?.OldName ?? "";
  4752. if (!string.IsNullOrEmpty(oldName) && isGetSchengenStr.equals("是"))
  4753. {
  4754. SetFieldValue(formFields, "applicant_no", "");
  4755. SetFieldValue(formFields, "applicant_yes", selected);
  4756. if (!string.IsNullOrEmpty(oldName))
  4757. {
  4758. SetFieldValue(formFields, "former_surname", oldName.Substring(0, 1));
  4759. SetFieldValue(formFields, "former_given_name", oldName.Remove(0, 1));
  4760. }
  4761. }
  4762. #endregion
  4763. #region 是否拥有双重国籍
  4764. SetFieldValue(formFields, "dual_citizenship_no", selected); // 否 默认选中
  4765. SetFieldValue(formFields, "dual_citizenship_yes", "");
  4766. SetFieldValue(formFields, "dual_citizenship_remark", "");
  4767. #endregion
  4768. #endregion
  4769. #region 2. 申请签证信息
  4770. //SetFieldValue(formFields, "overstay_period_over_90_days", selected); // 90天以上长期滞留
  4771. //SetFieldValue(formFields, "overstay_period_under_90_days", selected); // 90天以下短期滞留
  4772. //SetFieldValue(formFields, "overstay_period_status", ""); // 滞留资格
  4773. #endregion
  4774. #region 3. 护照信息
  4775. //清除值
  4776. SetFieldValue(formFields, "passport_type_diplomatic", ""); // 旅行证件类型 - 外交护照
  4777. SetFieldValue(formFields, "passport_type__official", ""); // 旅行证件类型 - 公务护照
  4778. SetFieldValue(formFields, "passport_type__regular", ""); // 旅行证件类型 - 普通护照
  4779. SetFieldValue(formFields, "passport_type__other", ""); // 旅行证件类型 - 其它
  4780. //设置值
  4781. if (passportInfo != null)
  4782. {
  4783. // 签证类型
  4784. var visatypeInfo = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == passportInfo.PassportType);
  4785. if (visatypeInfo != null)
  4786. {
  4787. string visaName = visatypeInfo?.Name ?? "-";
  4788. if (visaName.contains("外交")) SetFieldValue(formFields, "passport_type_diplomatic", selected); // 旅行证件类型 - 外交护照
  4789. else if (visaName.contains("公务")) SetFieldValue(formFields, "passport_type__official", selected); // 旅行证件类型 - 公务护照
  4790. else if (visaName.contains("普通")) SetFieldValue(formFields, "passport_type__regular", selected); // 旅行证件类型 - 普通护照
  4791. else if (visaName.contains("其它")) // 旅行证件类型 - 其它
  4792. {
  4793. SetFieldValue(formFields, "passport_type__other", selected);
  4794. SetFieldValue(formFields, "passport_type__other_remark", "");
  4795. }
  4796. else SetFieldValue(formFields, "passport_ordinary", selected); // 旅行证件类型 - 普通护照
  4797. }
  4798. SetFieldValue(formFields, "passport_no", passportInfo.CertNo); // 签证 编号
  4799. SetFieldValue(formFields, "passport_country", passportInfo.Country); // 签发 国
  4800. SetFieldValue(formFields, "passport_issuePlace", passportInfo.Area); // 签发 地
  4801. SetFieldValue(formFields, "passport_issue_date", passportInfo.IssueDt?.ToString("yyyy-MM-dd") ?? ""); // 签发日期
  4802. SetFieldValue(formFields, "passport_expiryDate", passportInfo.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); // 有效期至
  4803. #region 是否有其他护照信息
  4804. SetFieldValue(formFields, "otherPassport_no", selected); // 否 默认选中
  4805. SetFieldValue(formFields, "otherPassport_yes", ""); // 是
  4806. //清除值
  4807. SetFieldValue(formFields, "other_passport_type_diplomatic", ""); // 旅行证件类型 - 外交护照
  4808. SetFieldValue(formFields, "other_passport_type_official", ""); // 旅行证件类型 - 公务护照
  4809. SetFieldValue(formFields, "other_passport_type_regular", ""); // 旅行证件类型 - 普通护照
  4810. SetFieldValue(formFields, "other_passport_type_other", ""); // 旅行证件类型 - 其它
  4811. SetFieldValue(formFields, "other_passport_no", ""); // 签证 编号
  4812. SetFieldValue(formFields, "other_passport_country", ""); // 签发 国
  4813. SetFieldValue(formFields, "other_passport_expiry_date", ""); // 有效期至
  4814. #endregion
  4815. }
  4816. #endregion
  4817. #region 4. 联系信息
  4818. SetFieldValue(formFields, "contact_info_address", custInfo.Address); // 本国地址
  4819. SetFieldValue(formFields, "contact_info_current_adress", ""); // 现居住地址,如与本国地址不同填写
  4820. SetFieldValue(formFields, "contact_info_tel_or_phone", custInfo.Tel); // 电话
  4821. SetFieldValue(formFields, "contact_info_email", custInfo.Email); // 电子邮件
  4822. #region 紧急联系人
  4823. //默认没有
  4824. SetFieldValue(formFields, "contact_info_emergency_name", ""); // 姓名
  4825. SetFieldValue(formFields, "contact_info_emergency_country", ""); // 居住国家
  4826. SetFieldValue(formFields, "contact_info_emergency_tel", ""); // 电话
  4827. SetFieldValue(formFields, "contact_info_emergency_relationship", ""); // 关系
  4828. #endregion
  4829. #endregion
  4830. #region 5. 婚姻状况及家庭成员信息
  4831. //清除婚姻状况
  4832. SetFieldValue(formFields, "marital_married", ""); // 婚姻状况 - 已婚
  4833. SetFieldValue(formFields, "marital_divorced", ""); // 婚姻状况 - 离婚
  4834. SetFieldValue(formFields, "marital_single", ""); // 婚姻状况 - 单身
  4835. //设置婚姻状况
  4836. switch (custInfo.Marriage)
  4837. {
  4838. case 1: // 未婚
  4839. break;
  4840. case 2: // 已婚
  4841. SetFieldValue(formFields, "marital_married", selected);
  4842. #region 配偶信息
  4843. string mateName = custInfo?.MateName ?? "";
  4844. if (!string.IsNullOrEmpty(mateName))
  4845. {
  4846. string mateFirstName = mateName.Remove(0, 1);
  4847. SetFieldValue(formFields, "marital_personal_surname", mateName.Substring(0, 1)); // 姓
  4848. SetFieldValue(formFields, "marital_personal_name", mateFirstName); // 名
  4849. }
  4850. SetFieldValue(formFields, "marital_personal_birthday", custInfo?.MateBirthDay.ToString("yyyy-MM-dd")); // 生日
  4851. SetFieldValue(formFields, "marital_personal_nationaliy", custInfo.MateBirthCountry); // 国家
  4852. SetFieldValue(formFields, "marital_personal_nationaliy", custInfo.MateAddress); // 居住地址
  4853. SetFieldValue(formFields, "marital_personal_nationaliy", ""); // 电话
  4854. #endregion
  4855. break;
  4856. case 3: // 离婚/离异
  4857. SetFieldValue(formFields, "marriage_divorce", selected);
  4858. break;
  4859. case 4: // 离异
  4860. break;
  4861. }
  4862. //子女信息
  4863. SetFieldValue(formFields, "famliy_children_no", selected); // 否
  4864. SetFieldValue(formFields, "famliy_children_yes", ""); // 是
  4865. if (currFamilyInfos.Count > 0)
  4866. {
  4867. // 定义接受子女人数
  4868. int children = currFamilyInfos.Where(x => x.Appellation.contains("儿子") || x.Appellation.contains("女儿")).ToList().Count;
  4869. // 判断子女人数
  4870. if (children > 0)
  4871. {
  4872. SetFieldValue(formFields, "famliy_children_yes", selected);
  4873. SetFieldValue(formFields, "famliy_children_number", children.ToString()); // 子女人数
  4874. }
  4875. }
  4876. #endregion
  4877. #region 6. 学历
  4878. SetFieldValue(formFields, "education_masters_or_doctoral_degree", "");// 博士/硕士
  4879. SetFieldValue(formFields, "education_bachelors_degree", ""); // 学士
  4880. SetFieldValue(formFields, "education_hight_school_diploma", ""); // 高中
  4881. SetFieldValue(formFields, "education_other", ""); // 其他
  4882. SetFieldValue(formFields, "education_other_remark", ""); // 其他 - 备注
  4883. if (custInfo.HighestEducation.Contains("硕士") || custInfo.HighestEducation.Contains("博士"))
  4884. SetFieldValue(formFields, "education_masters_or_doctoral_degree", selected);
  4885. else if (custInfo.HighestEducation.Contains("学士"))
  4886. SetFieldValue(formFields, "education_bachelors_degree", selected);
  4887. else if (custInfo.HighestEducation.Contains("高中"))
  4888. SetFieldValue(formFields, "education_hight_school_diploma", selected);
  4889. else
  4890. {
  4891. SetFieldValue(formFields, "education_other", selected);
  4892. SetFieldValue(formFields, "education_other_remark", custInfo.HighestEducation.Trim());
  4893. }
  4894. SetFieldValue(formFields, "education_school_name", ""); // 学校名称
  4895. SetFieldValue(formFields, "education_school_address", ""); // 学校地址
  4896. #endregion
  4897. #region 7. 职业
  4898. //清除值
  4899. SetFieldValue(formFields, "employment_entreeneur", ""); // 事业家
  4900. SetFieldValue(formFields, "employment_self_employed", ""); // 自雇
  4901. SetFieldValue(formFields, "employment_employed", ""); // 公司职员
  4902. SetFieldValue(formFields, "employment_civil_servant", selected);// 公务员 默认
  4903. SetFieldValue(formFields, "employment_student", ""); // 学生
  4904. SetFieldValue(formFields, "employment_retired", ""); // 退休
  4905. SetFieldValue(formFields, "employment_unemployed", ""); // 无业
  4906. SetFieldValue(formFields, "employment_other", ""); // 其他
  4907. SetFieldValue(formFields, "employment_other_remark", ""); // 其他 - 备注
  4908. //职业信息
  4909. if (companyInfos != null && companyInfos.Count > 0)
  4910. {
  4911. SetFieldValue(formFields, "employment_name", companyInfos.FirstOrDefault()?.Company ?? ""); // 单位名称
  4912. SetFieldValue(formFields, "employment_position", companyInfos.FirstOrDefault()?.Job ?? ""); // 职业
  4913. SetFieldValue(formFields, "employment_address", companyInfos.FirstOrDefault()?.CompanyAddress ?? ""); // 地址
  4914. SetFieldValue(formFields, "employment_tel", companyInfos.FirstOrDefault()?.Phone ?? ""); // 电话
  4915. }
  4916. #endregion
  4917. #region 8. 访问信息
  4918. //入境事由
  4919. //清除值
  4920. SetFieldValue(formFields, "korea_tourism", ""); // 旅游/过境
  4921. SetFieldValue(formFields, "korea_meeting", ""); // 参加会议等活动
  4922. SetFieldValue(formFields, "korea_medical_tourism", ""); // 医疗旅游
  4923. SetFieldValue(formFields, "korea_business", ""); // 短期商务
  4924. SetFieldValue(formFields, "korea_study", ""); // 学习/培训
  4925. SetFieldValue(formFields, "korea_work", ""); // 就业活动
  4926. SetFieldValue(formFields, "korea_trade", ""); // 贸易/投资/派驻
  4927. SetFieldValue(formFields, "korea_visiting_family", ""); // 探亲访友
  4928. SetFieldValue(formFields, "marriage_migrant", ""); // 结婚移民
  4929. SetFieldValue(formFields, "korea_diplomatic", ""); // 外交/公务
  4930. SetFieldValue(formFields, "korea_other", ""); // 其他
  4931. SetFieldValue(formFields, "korea_other_details", ""); // 其他 - 备注
  4932. var visit_purpose = groupInfo.VisitPurpose;
  4933. if (!string.IsNullOrEmpty(visit_purpose))
  4934. {
  4935. if (visit_purpose.contains("旅游") || visit_purpose.contains("过境"))
  4936. {
  4937. SetFieldValue(formFields, "korea_tourism", selected); // 旅游/过境
  4938. }
  4939. else if (visit_purpose.contains("会议") || visit_purpose.contains("活动"))
  4940. {
  4941. SetFieldValue(formFields, "korea_meeting", selected); // 参加会议等活动
  4942. }
  4943. else if (visit_purpose.contains("医疗") || visit_purpose.contains("旅游"))
  4944. {
  4945. SetFieldValue(formFields, "korea_medical_tourism", selected); // 医疗旅游
  4946. }
  4947. else if (visit_purpose.contains("短期商务") || visit_purpose.contains("商务"))
  4948. {
  4949. SetFieldValue(formFields, "korea_business", selected); // 短期商务
  4950. }
  4951. else if (visit_purpose.contains("学习") || visit_purpose.contains("培训"))
  4952. {
  4953. SetFieldValue(formFields, "korea_study", selected); // 学习/培训
  4954. }
  4955. else if (visit_purpose.contains("就业活动"))
  4956. {
  4957. SetFieldValue(formFields, "korea_work", selected); // 就业活动
  4958. }
  4959. else if (visit_purpose.contains("贸易") || visit_purpose.contains("投资") || visit_purpose.contains("派驻"))
  4960. {
  4961. SetFieldValue(formFields, "korea_trade", selected); // 贸易/投资/派驻
  4962. }
  4963. else if (visit_purpose.contains("探亲访友") || visit_purpose.contains("探亲") || visit_purpose.contains("访友"))
  4964. {
  4965. SetFieldValue(formFields, "korea_visiting_family", selected); // 探亲访友
  4966. }
  4967. else if (visit_purpose.contains("结婚移民") || visit_purpose.contains("结婚") || visit_purpose.contains("移民"))
  4968. {
  4969. SetFieldValue(formFields, "marriage_migrant", selected); // 结婚移民
  4970. }
  4971. else if (visit_purpose.contains("外交") || visit_purpose.contains("公务"))
  4972. {
  4973. SetFieldValue(formFields, "korea_diplomatic", selected); // 外交/公务
  4974. }
  4975. else
  4976. {
  4977. SetFieldValue(formFields, "korea_other", selected); // 其他
  4978. SetFieldValue(formFields, "korea_other_details", visit_purpose);// 其他 - 备注
  4979. }
  4980. }
  4981. #region 滞留信息
  4982. string day1 = ""; //得到抵达日期
  4983. string day2 = ""; //得到离开日期
  4984. string country = groupInfo.VisitCountry; //国家名
  4985. string HG_City = ""; //城市
  4986. string HG_Country = "";//国家
  4987. string[] HG_countryName = new string[] { };
  4988. if (!string.IsNullOrEmpty(country))
  4989. {
  4990. //处理国家名
  4991. if (country.Contains(" "))
  4992. HG_countryName = country.Split(' ');
  4993. else if (country.Contains(","))
  4994. HG_countryName = country.Split(',');
  4995. else if (country.Contains(","))
  4996. HG_countryName = country.Split(',');
  4997. else if (country.Contains("、"))
  4998. HG_countryName = country.Split('、');
  4999. }
  5000. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  5001. int k = 0;
  5002. for (int i = 0; i < HG_countryName.Length; i++)
  5003. {
  5004. for (int j = 0; j < atbc.Rows.Count; j++)
  5005. {
  5006. string HL_Three = atbc.Rows[j]["Three"].ToString();
  5007. if (!string.IsNullOrEmpty(HL_Three))
  5008. {
  5009. var hl_three = HL_Three.Substring(3);
  5010. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == hl_three).First();
  5011. if (tc != null)
  5012. {
  5013. HG_Country = HG_countryName[i];
  5014. HG_City = tc.City; //得到当前国家 城市名
  5015. day1 = atbc.Rows[j]["Day"].ToString(); //得到抵达日期
  5016. k = j + 1;
  5017. }
  5018. }
  5019. if (k == j)
  5020. day2 = atbc.Rows[j]["Day"].ToString(); //离开航班起飞时间
  5021. }
  5022. }
  5023. if (atbc != null)
  5024. {
  5025. if (day2 != null && day1 != null)
  5026. {
  5027. try
  5028. {
  5029. int Han_day = (Convert.ToDateTime(day2) - Convert.ToDateTime(day1)).Days; //得到天数
  5030. SetFieldValue(formFields, "visit_prtiod_stay", Han_day.ToString()); // 滞留天数
  5031. }
  5032. catch (Exception) { }
  5033. }
  5034. }
  5035. //得到当前国家下的城市酒店信息
  5036. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  5037. .Where(x => x.DiId == groupId)
  5038. .Where(x => x.City.contains(HG_City))
  5039. .First();
  5040. //访问信息
  5041. if (hotelInfo != null)
  5042. {
  5043. SetFieldValue(formFields, "visit_address", hotelInfo?.HotelAddress ?? ""); // 停留酒店地址
  5044. SetFieldValue(formFields, "visit_tel", hotelInfo?.HotelTel ?? ""); // 停留酒店联系电话
  5045. }
  5046. #endregion
  5047. SetFieldValue(formFields, "visit_tel", hotelInfo?.HotelTel ?? ""); // 停留酒店联系电话
  5048. SetFieldValue(formFields, "visit_tel", hotelInfo?.HotelTel ?? ""); // 停留酒店联系电话
  5049. SetFieldValue(formFields, "visit_travelled_5year_no", ""); // 近五年到访过韩国
  5050. SetFieldValue(formFields, "visit_travelled_5year_othercountry_no", ""); // 近五年到访过除韩国之外的国家
  5051. SetFieldValue(formFields, "visit_travelled_no", ""); // 是否有其他家人滞留在韩国
  5052. SetFieldValue(formFields, "visit_travelled_travelling_no", ""); // 是否有随行家属
  5053. #endregion
  5054. #region 9. 在韩邀请方信息
  5055. SetFieldValue(formFields, "invitation_no", selected); // 是否有邀请方 - 否 默认选中
  5056. SetFieldValue(formFields, "invitation_yes", ""); // 是否有邀请方 - 是
  5057. if (!string.IsNullOrEmpty(HG_Country) && !string.IsNullOrEmpty(HG_City))
  5058. {
  5059. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  5060. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  5061. .Where(x => x.Country.Contains(HG_Country))
  5062. .Where(x => x.Area.Contains(HG_City))
  5063. .First();
  5064. //邀请 接待单位
  5065. if (oa != null)
  5066. {
  5067. SetFieldValue(formFields, "invitation_no", ""); // 是否有邀请方 - 否
  5068. SetFieldValue(formFields, "invitation_yes", selected); // 是否有邀请方 - 是
  5069. SetFieldValue(formFields, "invitation_name", oa?.Contact?.Trim() ?? "");// 邀请方 姓名
  5070. SetFieldValue(formFields, "invitation_birthday", ""); // 邀请方 生日/证件号
  5071. SetFieldValue(formFields, "invitation_relationship", "邀请方"); // 邀请方 关系
  5072. SetFieldValue(formFields, "invitation_address", oa?.Address ?? ""); // 邀请方 地址
  5073. SetFieldValue(formFields, "invitation_tel", oa?.Tel ?? ""); // 邀请方 电话
  5074. }
  5075. }
  5076. #endregion
  5077. #region 9. 费用信息
  5078. var compnayName = currCompanyInfos.FirstOrDefault(x => x.Id == custInfo.CrmCompanyId)?.Company ?? "";
  5079. SetFieldValue(formFields, "funding_costs", ""); // 费用金额
  5080. SetFieldValue(formFields, "funding_pay_name_or_unit", compnayName); // 单位名称
  5081. SetFieldValue(formFields, "funding_pay_relationship", "企业"); // 关系
  5082. SetFieldValue(formFields, "funding_pay_cost_type", "自费"); // 费用类别
  5083. SetFieldValue(formFields, "funding_pay_tel", custInfo.ClientPhone); // 电话
  5084. #endregion
  5085. #region 10. 协助填表人信息
  5086. if (string.IsNullOrEmpty(custInfo.TableOpName))
  5087. SetFieldValue(formFields, "assistance_no", selected); // 否
  5088. else
  5089. {
  5090. SetFieldValue(formFields, "assistance_yes", selected); // 是
  5091. SetFieldValue(formFields, "assistance_name", selected); // 姓名
  5092. SetFieldValue(formFields, "assistance_birthday", ""); // 生日
  5093. SetFieldValue(formFields, "assistance_tel", custInfo.TableOpTel); // 电话
  5094. SetFieldValue(formFields, "assistance_relationship", "雇佣"); // 和协助人关系
  5095. }
  5096. #endregion
  5097. var date_year = DateTime.Now.Year.ToString();
  5098. var date_month = DateTime.Now.Month.ToString();
  5099. var date_day = DateTime.Now.Day.ToString();
  5100. SetFieldValue(formFields, "declaration_year", date_year); // 申请日期 - 年
  5101. SetFieldValue(formFields, "declaration_month", date_month); // 申请日期 - 月
  5102. SetFieldValue(formFields, "declaration_day", date_day); // 申请日期 - 日
  5103. var applicant_name = custInfo.LastName + custInfo.FirstName;
  5104. SetFieldValue(formFields, "declaration_applicant_name", applicant_name); // 申请人姓名
  5105. #endregion
  5106. filePaths.Add(outputPath);
  5107. }
  5108. catch (Exception ex)
  5109. {
  5110. return Ok(JsonView(false, $"生成PDF文件时出错:{ex.Message}"));
  5111. }
  5112. finally
  5113. {
  5114. // 按正确顺序关闭资源
  5115. stamper?.Close();
  5116. reader?.Close();
  5117. templateStream?.Close();
  5118. outputStream?.Close();
  5119. }
  5120. #endregion
  5121. }
  5122. break;
  5123. case 4: // 瑞典
  5124. visaTypeName = $"瑞典签证申请表";
  5125. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  5126. var swedenSavePath = $"{fileServerPath}{visaTypeName}/";
  5127. if (!Directory.Exists(swedenSavePath)) Directory.CreateDirectory(swedenSavePath);
  5128. if (!System.IO.File.Exists(currTempPath))
  5129. {
  5130. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  5131. }
  5132. foreach (var custInfo in groupCustInfos)
  5133. {
  5134. EncryptionProcessor.DecryptProperties(custInfo);
  5135. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  5136. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  5137. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  5138. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  5139. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  5140. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  5141. #region 生成文件
  5142. PdfReader reader = null;
  5143. FileStream templateStream = null;
  5144. FileStream outputStream = null;
  5145. PdfStamper stamper = null;
  5146. try
  5147. {
  5148. string outputPath = $"{swedenSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  5149. //读取模板文件
  5150. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  5151. reader = new PdfReader(templateStream);
  5152. //创建输出文件
  5153. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  5154. stamper = new PdfStamper(reader, outputStream);
  5155. AcroFields formFields = stamper.AcroFields;
  5156. #region 设置文本值
  5157. SetFieldValue(formFields, "LastName", custInfo.LastName); //姓
  5158. SetFieldValue(formFields, "BirthLastName", custInfo.LastName); // 出生时姓氏
  5159. SetFieldValue(formFields, "FirstName", custInfo.FirstName); // 名
  5160. // 出生日期(日-月-年)
  5161. string idCard = idInfo.CertNo;
  5162. string birthday = string.Empty;
  5163. if (!string.IsNullOrEmpty(idCard))
  5164. {
  5165. string year = idCard.Substring(6, 4);
  5166. string month = idCard.Substring(10, 2);
  5167. string day = idCard.Substring(12, 2);
  5168. birthday = day + "-" + month + "-" + year;
  5169. }
  5170. SetFieldValue(formFields, "Birthday", birthday);
  5171. string currentNationality = custInfo.BirthProvince + custInfo.BirthCity;
  5172. SetFieldValue(formFields, "CurrentNationality", currentNationality); // 出生地
  5173. SetFieldValue(formFields, "CountryBirth", "中国"); // 出生国
  5174. SetFieldValue(formFields, "CurrentNationalityCountry", "中国"); // 现国籍
  5175. SetFieldValue(formFields, "NationalityBirth", ""); // 出生时国籍,如与现国籍不同
  5176. SetFieldValue(formFields, "OtherNationalities", ""); // 其他国籍
  5177. #region 性别处理
  5178. //清除性别
  5179. SetFieldValue(formFields, "Male", "Off"); // 性别 - 男
  5180. SetFieldValue(formFields, "Female", "Off"); // 性别 - 女
  5181. //设置性别
  5182. if (custInfo.Sex == 0) //男
  5183. {
  5184. SetFieldValue(formFields, "Male", "Yes"); // 性别 - 男
  5185. }
  5186. else if (custInfo.Sex == 1) //女
  5187. {
  5188. SetFieldValue(formFields, "Female", "Yes"); // 性别 - 女
  5189. }
  5190. #endregion
  5191. #region 婚姻状况处理
  5192. //清除婚姻状况
  5193. SetFieldValue(formFields, "Single", "Off"); // 婚姻状况 - 未婚
  5194. SetFieldValue(formFields, "Married", "Off"); // 婚姻状况 - 已婚
  5195. SetFieldValue(formFields, "RegisteredPartnership", "Off"); // 婚姻状况 - 注册伴侣关系
  5196. SetFieldValue(formFields, "Separated", "Off"); // 婚姻状况 - 分居
  5197. SetFieldValue(formFields, "Divorced", "Off"); // 婚姻状况 - 离婚
  5198. SetFieldValue(formFields, "Widow(er)", "Off"); // 婚姻状况 - 丧偶
  5199. SetFieldValue(formFields, "OtherCivilStatus", "Off"); // 婚姻状况 - 其它
  5200. SetFieldValue(formFields, "CivilStatusOther", ""); // 婚姻状况 - 其它(请注明)
  5201. //设置婚姻状况
  5202. switch (custInfo.Marriage)
  5203. {
  5204. case 1: // 未婚
  5205. SetFieldValue(formFields, "Single", "Yes");
  5206. break;
  5207. case 2: // 已婚
  5208. SetFieldValue(formFields, "Married", "Yes");
  5209. break;
  5210. case 3: // 离异
  5211. SetFieldValue(formFields, "Divorced", "Yes");
  5212. break;
  5213. case 4: // 离异
  5214. SetFieldValue(formFields, "Widow(er)", "Yes");
  5215. break;
  5216. }
  5217. #endregion
  5218. //亲权人(如是未成年申请人 )/合法监护人(姓名、住址,如与申请人不同) 电话号码、电子邮件及国籍
  5219. SetFieldValue(formFields, "ParentalAuthority", "");
  5220. SetFieldValue(formFields, "NationalIdentityNumber", idCard); //公民身份证号码
  5221. #region 护照(旅行证件类型)处理
  5222. //清除值
  5223. SetFieldValue(formFields, "OrdinaryPassport", "Off"); //旅行证件类型 - 普通护照
  5224. SetFieldValue(formFields, "DiplomaticPassport", "Off"); //旅行证件类型 - 外交护照
  5225. SetFieldValue(formFields, "ServicePassport", "Off"); //旅行证件类型 - 公务护照
  5226. SetFieldValue(formFields, "OfficialPassport", "Off"); //旅行证件类型 - 因公护照
  5227. SetFieldValue(formFields, "SpecialPassport", "Off"); //旅行证件类型 - 特殊护照
  5228. SetFieldValue(formFields, "OtherTravel", "Off"); //旅行证件类型 - 其它旅行证件
  5229. SetFieldValue(formFields, "OtherTravelDesc", ""); //旅行证件类型 - 其它旅行证件(请注明)
  5230. //设置值
  5231. SetFieldValue(formFields, "OrdinaryPassport", "Yes"); //旅行证件类型 - 普通护照
  5232. if (passportInfo != null)
  5233. {
  5234. SetFieldValue(formFields, "TravelNumber", passportInfo.CertNo); //旅行证件编号
  5235. SetFieldValue(formFields, "IssueDate", passportInfo.IssueDt?.ToString("yyyy-MM-dd") ?? ""); //签发日期
  5236. SetFieldValue(formFields, "ValidUntil", passportInfo.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); //有效期至
  5237. SetFieldValue(formFields, "IssuedCountry", passportInfo.Country); //签发(国)
  5238. }
  5239. #endregion
  5240. //如有家庭成员为欧盟、欧洲经济区、瑞士或受益于退欧协议的英国公民的,请填写该家庭成员的个人信息
  5241. SetFieldValue(formFields, "LastName_om", ""); //姓
  5242. SetFieldValue(formFields, "FirstName_om", ""); //名
  5243. SetFieldValue(formFields, "BirthDate_om", ""); //出生日期(日-月-年)
  5244. SetFieldValue(formFields, "Nationality_om", ""); //国籍
  5245. SetFieldValue(formFields, "TravelNuber_om", ""); //旅行证件或身分证编号
  5246. //申请人与欧盟、欧洲经济区、瑞士或受益于退欧协议的英国公民的关系
  5247. SetFieldValue(formFields, "Spouse_om", ""); //配偶
  5248. SetFieldValue(formFields, "RegisteredPartnership_om", ""); //注册伴侣
  5249. SetFieldValue(formFields, "Child_om", ""); //子女
  5250. SetFieldValue(formFields, "DependentAscendant_om", ""); //受养人
  5251. SetFieldValue(formFields, "Grandchild_om", ""); //孙子女
  5252. SetFieldValue(formFields, "FamilyOther_om", ""); //其他
  5253. SetFieldValue(formFields, "FamilyOtherDesc_om", ""); //其他(说明)
  5254. //申请人住址及电子邮件
  5255. string applicantHomeAddress = $"{custInfo.Address} {custInfo.Email}";
  5256. SetFieldValue(formFields, "ApplicantHomeAddress", applicantHomeAddress); //申请人住址及电子邮件
  5257. SetFieldValue(formFields, "TelephoneNo", custInfo.Tel); //电话号码
  5258. //是否居住在现时国籍以外的国家
  5259. SetFieldValue(formFields, "AnotherCountryNo", "Yes"); //否
  5260. SetFieldValue(formFields, "AnotherCountryYes", ""); //是。
  5261. SetFieldValue(formFields, "ResidencePermit", ""); //居住许可或同等证
  5262. SetFieldValue(formFields, "Number", ""); //编号
  5263. SetFieldValue(formFields, "ValidUntils", ""); //有效期至
  5264. SetFieldValue(formFields, "CurrentOccupation", custInfo.Job); //当前职业
  5265. //工作单位名称,地址和电话,学生填写学校名称及地址
  5266. var currCompanyInfo = currCompanyInfos.FirstOrDefault();
  5267. string employerInfoStr = $"{currCompanyInfo?.Company ?? ""} {currCompanyInfo?.CompanyAddress ?? ""} {currCompanyInfo?.Phone ?? ""}";
  5268. SetFieldValue(formFields, "EmployerInfo", employerInfoStr);
  5269. #region 旅行的目的
  5270. //清空值
  5271. SetFieldValue(formFields, "Tourism", "Off"); //旅游
  5272. SetFieldValue(formFields, "Business", "Off"); //商务
  5273. SetFieldValue(formFields, "VisitingFamily", "Off"); //探亲访友
  5274. SetFieldValue(formFields, "Cultural", "Off"); //文化
  5275. SetFieldValue(formFields, "Sports", "Off"); //体育
  5276. SetFieldValue(formFields, "OfficialVisit", "Off"); //官方访问
  5277. SetFieldValue(formFields, "MedicalReasons", "Off"); //医疗
  5278. SetFieldValue(formFields, "Study", "Off"); //学习
  5279. SetFieldValue(formFields, "AirportTransit", "Off"); //机场过境
  5280. SetFieldValue(formFields, "Other", "Off"); //其它
  5281. SetFieldValue(formFields, "OtherDesc", ""); //其它 (请注明)
  5282. //设置值
  5283. if (groupInfo.VisitPurpose.contains("旅游")) SetFieldValue(formFields, "Tourism", "Yes"); //旅游
  5284. if (groupInfo.VisitPurpose.contains("商务")) SetFieldValue(formFields, "Business", "Yes"); //商务
  5285. if (groupInfo.VisitPurpose.contains("探亲访友")) SetFieldValue(formFields, "VisitingFamily", "Yes"); //探亲访友
  5286. if (groupInfo.VisitPurpose.contains("文化")) SetFieldValue(formFields, "Cultural", "Yes"); //文化
  5287. if (groupInfo.VisitPurpose.contains("体育")) SetFieldValue(formFields, "Sports", "Yes"); //体育
  5288. if (groupInfo.VisitPurpose.contains("官方访问")) SetFieldValue(formFields, "OfficialVisit", "Yes"); //官方访问
  5289. if (groupInfo.VisitPurpose.contains("医疗")) SetFieldValue(formFields, "MedicalReasons", "Yes"); //医疗
  5290. if (groupInfo.VisitPurpose.contains("学习")) SetFieldValue(formFields, "Study", "Yes"); //学习
  5291. if (groupInfo.VisitPurpose.contains("机场过境")) SetFieldValue(formFields, "AirportTransit", "Yes"); //机场过境
  5292. #endregion
  5293. SetFieldValue(formFields, "AdditionalInfo", ""); //有关停留原因的补充信息
  5294. string[] RD_country = new string[] { }; //接收处理的国家
  5295. string firstEntryLabel = string.Empty; //首入申根国标签
  5296. string membeDescLabel = string.Empty; //申根国目的地
  5297. string stopDays = string.Empty; //停留天数
  5298. if (!string.IsNullOrEmpty(groupInfo.VisitCountry))
  5299. {
  5300. List<string> SGGNames = new List<string>();//接收处理后的国家 是申根国
  5301. if (groupInfo.VisitCountry.Contains(","))
  5302. RD_country = groupInfo.VisitCountry.Split(',');
  5303. else if (groupInfo.VisitCountry.Contains(' '))
  5304. RD_country = groupInfo.VisitCountry.Split(' ');
  5305. else if (groupInfo.VisitCountry.Contains(","))
  5306. RD_country = groupInfo.VisitCountry.Split(',');
  5307. else if (groupInfo.VisitCountry.Contains("、"))
  5308. RD_country = groupInfo.VisitCountry.Split('、');
  5309. else if (groupInfo.VisitCountry.Contains("|"))
  5310. RD_country = groupInfo.VisitCountry.Split('|');
  5311. //判断是否是申根国家
  5312. for (int i = 0; i < RD_country.Length; i++)
  5313. {
  5314. if (RD_country[i].ToString() != null)
  5315. {
  5316. //在申根国家中筛选 该国家是否是申根国家
  5317. for (int j = 0; j < _shenGenGuos.Length; j++)
  5318. {
  5319. if (RD_country[i] == _shenGenGuos[j])
  5320. SGGNames.Add(_shenGenGuos[j]); //添加申根国
  5321. }
  5322. }
  5323. }
  5324. //目的地国是否有申根国
  5325. if (SGGNames.Count > 0)
  5326. {
  5327. firstEntryLabel = SGGNames.First();
  5328. membeDescLabel = string.Join(",", SGGNames.ToArray());
  5329. //接收生根国详细信息 存储顺序 起飞日期:Day 起飞时刻:StartTime 抵达日期:ArrivedDate 到达时刻:EndTime
  5330. List<SSGDetails> ListSSGDetails = new List<SSGDetails>();
  5331. //处理申根国家 预定到达时间 预定离开时间 预定停留天数
  5332. for (int i = 0; i < SGGNames.Count; i++)
  5333. {
  5334. //在相同的国家下 得到该航班的信息 //抵达时间 起飞日期:Day 起飞时刻:StartTime 到达时刻:EndTime 抵达日期:ArrivedDate 飞行时间:FlightTime 航司 Fliagtcode 入境口岸
  5335. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  5336. //ResidenceTime1 机票三字码信息
  5337. if (atbc != null)
  5338. {
  5339. string HL_Three = ""; //三字码 Three
  5340. for (int j = 0; j < atbc.Rows.Count; j++)
  5341. {
  5342. HL_Three = atbc.Rows[j]["Three"].ToString();
  5343. if (!string.IsNullOrEmpty(HL_Three))
  5344. {
  5345. string threeCodeTwo = HL_Three.Substring(3);
  5346. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  5347. if (tc != null)
  5348. {
  5349. //首入申根国时间
  5350. if (SGGNames[i] == tc.Country)
  5351. {
  5352. SSGDetails SSGDetails = new SSGDetails()
  5353. {
  5354. Three = atbc.Rows[j]["Three"].ToString(), //三字码
  5355. Fliagtcode = atbc.Rows[j]["Fliagtcode"].ToString(), //航司
  5356. startDate = atbc.Rows[j]["Day"].ToString(), //整理起飞日期
  5357. startTime = atbc.Rows[j]["StartTime"].ToString(), //整理起飞时刻
  5358. endDate = atbc.Rows[j]["ArrivedDate"].ToString(), //整理抵达日期
  5359. endTime = atbc.Rows[j]["EndTime"].ToString() //整理抵达时刻
  5360. };
  5361. ListSSGDetails.Add(SSGDetails);
  5362. }
  5363. }
  5364. }
  5365. }
  5366. }
  5367. }
  5368. ListSSGDetails.Sort((a, b) => a.startDate.CompareTo(b.startDate));
  5369. //得到并计算出入境时间
  5370. if (ListSSGDetails != null)
  5371. {
  5372. string RuJingTime = ListSSGDetails.First().endDate + " " + ListSSGDetails.First().endTime.Substring(0, 2) + ":" + ListSSGDetails.First().endTime.Substring(2); //入境时间
  5373. string LiJingTime = ListSSGDetails[ListSSGDetails.Count - 1].startDate + " " + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(0, 2) + ":" + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(2); //离境时间
  5374. stopDays = Convert.ToDateTime(LiJingTime).Subtract(Convert.ToDateTime(RuJingTime)).Days.ToString();
  5375. }
  5376. }
  5377. }
  5378. SetFieldValue(formFields, "MembeDesc", membeDescLabel); //主要申根目的地 (以及其他申根目的地,如适用)
  5379. SetFieldValue(formFields, "FirstEntry", firstEntryLabel); //首入申根国
  5380. //申请入境次数
  5381. SetFieldValue(formFields, "27.SingleEntry", ""); //单次
  5382. SetFieldValue(formFields, "27.TwoEntries", ""); //两次
  5383. SetFieldValue(formFields, "27.MultipleEntries", ""); //多次
  5384. SetFieldValue(formFields, "27.IntendedDateIn", ""); //在申根地区预计首次停留的预计抵达日期
  5385. SetFieldValue(formFields, "27.IntendedDateOut", ""); //在申根地区预计首次停留之后的预计离开日期
  5386. //以往申根国签证是否有指纹记录
  5387. SetFieldValue(formFields, "28.No", ""); //否
  5388. SetFieldValue(formFields, "28.Yes", ""); //是
  5389. SetFieldValue(formFields, "28.KnownDate", ""); //如有,请写明日期
  5390. SetFieldValue(formFields, "28.KnownVisanumber", ""); //如有,请写明签证贴纸号码
  5391. //最后目的地之入境许可
  5392. SetFieldValue(formFields, "29.Issued", ""); //签发机关
  5393. SetFieldValue(formFields, "29.ValidFrom", ""); //有效期由
  5394. SetFieldValue(formFields, "29.Until", ""); //至
  5395. //申根国的邀请人姓名。如无邀请人,请填写申根国的酒店或暂住居所名称
  5396. //得到当前国家下的城市酒店信息
  5397. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  5398. .Where(x => x.DiId == groupId)
  5399. //.Where(x => x.City.contains(city))
  5400. .First();
  5401. //酒店住址
  5402. if (hotelInfo != null)
  5403. {
  5404. SetFieldValue(formFields, "30.SurnameFirstName", hotelInfo?.HotelName ?? ""); //申根国的酒店
  5405. var otherInfo = $"{hotelInfo.HotelAddress}";
  5406. SetFieldValue(formFields, "30.HotelInfo", otherInfo); //邀请人/酒店/暂住居所的地址及电子邮件
  5407. SetFieldValue(formFields, "30.TelephoneNo", hotelInfo?.HotelTel ?? ""); //电话号码
  5408. }
  5409. //邀请公司或机构的名称及地址
  5410. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  5411. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  5412. //.Where(x => x.Country.Contains(county))
  5413. //.Where(x => x.Area.Contains(city))
  5414. .First();
  5415. if (oa != null)
  5416. {
  5417. //申根国的邀请人姓名。如无邀请人,请填写申根国的酒店或暂住居所名称
  5418. SetFieldValue(formFields, "30.SurnameFirstName", oa?.Contact ?? ""); //申根国的酒店
  5419. SetFieldValue(formFields, "30.HotelInfo", oa?.Address ?? ""); //邀请人/酒店/暂住居所的地址及电子邮件
  5420. SetFieldValue(formFields, "30.TelephoneNo", oa?.Tel ?? ""); //电话号码
  5421. string nameAddressLabel = $"{oa.Client} {oa.Address}";
  5422. SetFieldValue(formFields, "31.NameAddress", nameAddressLabel); //邀请公司或机构的名称及地址
  5423. string surnameLabel = $"{oa.Contact} {oa.Tel}";
  5424. SetFieldValue(formFields, "31.Surname", surnameLabel); //邀请公司或机构的联系人姓名、地址、电话号码及电子邮件
  5425. SetFieldValue(formFields, "31.TelephoneNo", oa?.Tel ?? ""); //邀请公司或机构的电话
  5426. }
  5427. //申请人的旅费以及在国外停留期间的生活费用
  5428. SetFieldValue(formFields, "32.Applicant", ""); //由申请人支付
  5429. SetFieldValue(formFields, "32.Cash", ""); //支付方式 - 现金
  5430. SetFieldValue(formFields, "32.Traveller", ""); //支付方式 - 旅行支票
  5431. SetFieldValue(formFields, "32.CreditCard", ""); //支付方式 - 信用卡
  5432. SetFieldValue(formFields, "32.Prepaid", ""); //支付方式 - 预缴住宿
  5433. SetFieldValue(formFields, "32.Prepaid1", ""); //支付方式 - 预缴交通
  5434. SetFieldValue(formFields, "32.OtherMeans", ""); //支付方式 - 其它
  5435. SetFieldValue(formFields, "32.OtherMeansDesc", ""); //支付方式 - 其它(请注明)
  5436. SetFieldValue(formFields, "32.Sponsor", ""); //由赞助方(邀请人、公司或机构)支付,请注明
  5437. SetFieldValue(formFields, "32.Referred", ""); //参见第 30 及 31 项
  5438. SetFieldValue(formFields, "32.ReferredDesc", ""); //参见第 30 及 31 项(请注明)
  5439. SetFieldValue(formFields, "32.OtherSponsor", ""); //其它
  5440. SetFieldValue(formFields, "32.OtherSponsorDesc", ""); //其它(请注明)
  5441. SetFieldValue(formFields, "32.SponsorCash", ""); //赞助方式 - 现金
  5442. SetFieldValue(formFields, "32.SponsorAccommodation", ""); //赞助方式 - 提供住宿
  5443. SetFieldValue(formFields, "32.SponsorExpenses", ""); //赞助方式 - 支付旅程期间所有开支
  5444. SetFieldValue(formFields, "32.SponsorPrepaid", ""); //赞助方式 - 预缴交通
  5445. SetFieldValue(formFields, "32.ponsorOther", ""); //赞助方式 - 其它
  5446. SetFieldValue(formFields, "32.ponsorOtherDesc", ""); //赞助方式 - 其它(请注明)
  5447. SetFieldValue(formFields, "33.PlaceAndDate", DateTime.Now.ToString("yyyy-MM-dd")); //地点及日期
  5448. #endregion
  5449. filePaths.Add(outputPath);
  5450. //return outputPath;
  5451. }
  5452. catch (Exception ex)
  5453. {
  5454. return Ok(JsonView(false, $"生成PDF文件时出错:{ex.Message}"));
  5455. }
  5456. finally
  5457. {
  5458. // 按正确顺序关闭资源
  5459. stamper?.Close();
  5460. reader?.Close();
  5461. templateStream?.Close();
  5462. outputStream?.Close();
  5463. }
  5464. #endregion
  5465. }
  5466. break;
  5467. case 5: // 波兰
  5468. visaTypeName = $"波兰签证申请表";
  5469. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  5470. var polandSavePath = $"{fileServerPath}{visaTypeName}/";
  5471. if (!Directory.Exists(polandSavePath)) Directory.CreateDirectory(polandSavePath);
  5472. if (!System.IO.File.Exists(currTempPath))
  5473. {
  5474. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  5475. }
  5476. foreach (var custInfo in groupCustInfos)
  5477. {
  5478. EncryptionProcessor.DecryptProperties(custInfo);
  5479. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  5480. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  5481. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  5482. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  5483. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  5484. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  5485. #region 生成文件
  5486. PdfReader reader = null;
  5487. FileStream templateStream = null;
  5488. FileStream outputStream = null;
  5489. PdfStamper stamper = null;
  5490. try
  5491. {
  5492. string outputPath = $"{polandSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  5493. //读取模板文件
  5494. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  5495. reader = new PdfReader(templateStream);
  5496. //创建输出文件
  5497. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  5498. stamper = new PdfStamper(reader, outputStream);
  5499. AcroFields formFields = stamper.AcroFields;
  5500. #region 设置文本值
  5501. SetFieldValue(formFields, "surname", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? ""); // 姓 英文
  5502. SetFieldValue(formFields, "surname_birth", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? ""); // 出生时姓 英文
  5503. SetFieldValue(formFields, "first_name", CommonFun.ConvertToPinyin(custInfo?.FirstName?.Trim() ?? "")?.ToLower() ?? ""); // 名 英文
  5504. #region 出生日期(日-月-年)
  5505. string idCard = idInfo?.CertNo?.Trim() ?? "";
  5506. string birthday = string.Empty;
  5507. if (!string.IsNullOrEmpty(idCard))
  5508. {
  5509. string year = idCard.Substring(6, 4);
  5510. string month = idCard.Substring(10, 2);
  5511. string day = idCard.Substring(12, 2);
  5512. birthday = day + "-" + month + "-" + year;
  5513. }
  5514. SetFieldValue(formFields, "birthday", birthday);
  5515. #endregion
  5516. var area = custInfo.BirthProvince + custInfo.BirthCity;
  5517. SetFieldValue(formFields, "birth_place", area); // 出生地区
  5518. SetFieldValue(formFields, "birth_country", "中国"); // 出生国籍
  5519. SetFieldValue(formFields, "current_nationality", "中国"); // 现国籍
  5520. SetFieldValue(formFields, "birth_nationality", "中国"); // 出生国
  5521. SetFieldValue(formFields, "other_nationality", ""); // 其他国籍
  5522. #region 设置性别
  5523. //清除性别
  5524. SetFieldValue(formFields, "sex_male", "Off"); // 性别 - 男
  5525. SetFieldValue(formFields, "sex_female", "Off"); // 性别 - 女
  5526. SetFieldValue(formFields, "sex_other", "Off"); // 性别 - 其他
  5527. //设置性别
  5528. if (custInfo.Sex == 0) // 男
  5529. {
  5530. SetFieldValue(formFields, "sex_male", "Yes"); // 性别 - 男
  5531. }
  5532. else if (custInfo.Sex == 1) // 女
  5533. {
  5534. SetFieldValue(formFields, "sex_female", "Yes"); // 性别 - 女
  5535. }
  5536. else // 其他
  5537. {
  5538. SetFieldValue(formFields, "sex_other", "Yes"); // 性别 - 其他
  5539. }
  5540. #endregion
  5541. #region 婚姻状态
  5542. //清除婚姻状况
  5543. SetFieldValue(formFields, "civil_single", "Off"); // 婚姻状况 - 未婚
  5544. SetFieldValue(formFields, "civil_married", "Off"); // 婚姻状况 - 已婚
  5545. SetFieldValue(formFields, "civil_registerered_partnership", "Off");// 婚姻状况 - 注册伴侣关系
  5546. SetFieldValue(formFields, "civil_separated", "Off"); // 婚姻状况 - 分居
  5547. SetFieldValue(formFields, "civil_divorced", "Off"); // 婚姻状况 - 离异
  5548. SetFieldValue(formFields, "civil_windower", "Off"); // 婚姻状况 - 妻子(丈夫)去世
  5549. SetFieldValue(formFields, "civil_other", "Off"); // 婚姻状况 - 其他
  5550. SetFieldValue(formFields, "civil_other_details", ""); // 婚姻状况 - 其他(请具体说明)
  5551. //设置婚姻状况
  5552. switch (custInfo.Marriage)
  5553. {
  5554. case 1: // 未婚
  5555. break;
  5556. case 2: // 已婚
  5557. SetFieldValue(formFields, "civil_married", "Yes");
  5558. break;
  5559. case 3: // 离婚/离异
  5560. SetFieldValue(formFields, "civil_divorced", "Yes");
  5561. break;
  5562. case 4:
  5563. break;
  5564. }
  5565. #endregion
  5566. // 父母的监护权(针对未成年人)/法定监护人(姓氏、名字、地址(若与申请人的地址不同)、电话号码、电子邮箱地址以及国籍)
  5567. SetFieldValue(formFields, "parental_authority", "");
  5568. //(如适用)国民身份号码
  5569. SetFieldValue(formFields, "id_number", idCard);
  5570. #region 护照信息
  5571. //清除值
  5572. SetFieldValue(formFields, "travel_type_ordinary_passport", "Off"); // 旅行证件类型 - 普通护照
  5573. SetFieldValue(formFields, "travel_type_diplomatic_passport", "Off"); // 旅行证件类型 - 外交护照
  5574. SetFieldValue(formFields, "travel_type_service_passport", "Off"); // 旅行证件类型 - 服务护照
  5575. SetFieldValue(formFields, "travel_type_offical_passport", "Off"); // 旅行证件类型 - 公务护照
  5576. SetFieldValue(formFields, "travel_type_special_passport", "Off"); // 旅行证件类型 - 特别护照
  5577. SetFieldValue(formFields, "travel_type_other_passport_details", ""); // 其他旅行证件(请注明)
  5578. //设置值
  5579. if (passportInfo != null)
  5580. {
  5581. // 签证类型
  5582. var visatypeInfo = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == passportInfo.PassportType);
  5583. if (visatypeInfo != null)
  5584. {
  5585. string visaName = visatypeInfo?.Name ?? "-";
  5586. if (visaName.contains("普通")) SetFieldValue(formFields, "travel_type_ordinary_passport", "Yes"); // 旅行证件类型 - 普通护照
  5587. else if (visaName.contains("外交")) SetFieldValue(formFields, "travel_type_diplomatic_passport", "Yes"); // 旅行证件类型 - 外交护照
  5588. else if (visaName.contains("服务")) SetFieldValue(formFields, "travel_type_service_passport", "Yes"); // 旅行证件类型 - 服务护照
  5589. else if (visaName.contains("公务")) SetFieldValue(formFields, "travel_type_offical_passport", "Yes"); // 旅行证件类型 - 公务护照
  5590. else // 旅行证件类型 - 特别护照
  5591. {
  5592. SetFieldValue(formFields, "travel_type_other_passport", "Yes");
  5593. SetFieldValue(formFields, "travel_type_other_passport_details", "");
  5594. }
  5595. }
  5596. #region 护照信息
  5597. SetFieldValue(formFields, "travel_number", passportInfo.CertNo); // 签证 编号
  5598. SetFieldValue(formFields, "travel_issue_country", passportInfo.Country); // 签发 国
  5599. SetFieldValue(formFields, "travel_issue_date", passportInfo.IssueDt?.ToString("yyyy-MM-dd") ?? ""); // 签发日期
  5600. SetFieldValue(formFields, "travel_issue_vaild", passportInfo.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); // 有效期至
  5601. #endregion
  5602. }
  5603. #endregion
  5604. #region 适用情况下,欧盟、欧洲经济区或瑞士公民,或英国籍且为《欧盟-英国脱欧协议》受益人的家庭成员的个人资料 “默认空”
  5605. SetFieldValue(formFields, "eu_info_surname", ""); // 姓氏(家族名)
  5606. SetFieldValue(formFields, "eu_info_first_name", ""); // 名字(名字)
  5607. SetFieldValue(formFields, "eu_info_birthday", ""); // 出生日期 (日-月-年)
  5608. SetFieldValue(formFields, "eu_info_nationality", ""); // 国籍
  5609. SetFieldValue(formFields, "eu_info_id_number", ""); // 旅行证件或身份证号码
  5610. #region 与欧盟、欧洲经济区或瑞士公民,或作为《欧盟-英国脱欧协议》受益人的英国国民之间的家庭关系(如适用)
  5611. SetFieldValue(formFields, "eu_family_relationship_spouse", "Off"); // 夫妻
  5612. SetFieldValue(formFields, "eu_family_relationship_child", "Off"); // 子女
  5613. SetFieldValue(formFields, "eu_family_relationship_grandchild", "Off"); // 孙子女
  5614. SetFieldValue(formFields, "eu_family_relationship_ascendant", "Off"); // 有赡养关系的长辈
  5615. SetFieldValue(formFields, "eu_family_relationship_registered", "Off"); // 注册伴侣关系
  5616. #endregion
  5617. #endregion
  5618. // 申请人的家庭住址和电子邮箱地址
  5619. string applicantAddressAndEmail = $"{custInfo.Address} {custInfo.Email}";
  5620. SetFieldValue(formFields, "applicant_address_and_email", applicantAddressAndEmail);
  5621. // 申请人的电话
  5622. SetFieldValue(formFields, "applicant_tel", custInfo.Tel);
  5623. #region 在非当前国籍所属国家的居住情况 “默认空”
  5624. SetFieldValue(formFields, "uncurrent_count_no", "Yes"); // 否
  5625. SetFieldValue(formFields, "uncurrent_count_yes", "Off"); // 是
  5626. SetFieldValue(formFields, "uncurrent_country_residence", "");// 居留许可或同等证明
  5627. SetFieldValue(formFields, "uncurrent_country_no", ""); // No
  5628. SetFieldValue(formFields, "uncurrent_country_valid_until", "");// 有效期至
  5629. #endregion
  5630. #region 职业
  5631. //职业信息
  5632. if (companyInfos != null && companyInfos.Count > 0)
  5633. {
  5634. // 当前职业
  5635. SetFieldValue(formFields, "current_occupation", companyInfos.FirstOrDefault()?.Job ?? "");
  5636. //雇主及雇主的地址和电话号码。对于学生而言,应填写教育机构的名称及地址
  5637. string employerInfo = $"{companyInfos.FirstOrDefault()?.CompanyAddress ?? ""} {companyInfos.FirstOrDefault()?.Phone ?? ""}";
  5638. }
  5639. #endregion
  5640. #region 此次行程的目的
  5641. //清除值
  5642. SetFieldValue(formFields, "purpose_tourism", "Off"); // 旅游
  5643. SetFieldValue(formFields, "purpose_business", "Off"); // 商务
  5644. SetFieldValue(formFields, "purpose_visiting_family_friends", "Off");// 庆祝亲友团聚
  5645. SetFieldValue(formFields, "purpose_cultural", "Off"); // 文化交流
  5646. SetFieldValue(formFields, "purpose_sports", "Off"); // 体育活动
  5647. SetFieldValue(formFields, "purpose_offcial_visit", "Off"); // 官方访问
  5648. SetFieldValue(formFields, "purpose_medical_reasons", "Off"); // 医疗原因
  5649. SetFieldValue(formFields, "purpose_study", "Off"); // 学习
  5650. SetFieldValue(formFields, "purpose_airport_transit", "Off"); // 机场中转
  5651. SetFieldValue(formFields, "purpose_other", "Off"); // 其他
  5652. SetFieldValue(formFields, "purpose_other_remark", ""); // 其他 - 备注
  5653. var visit_purpose = groupInfo.VisitPurpose;
  5654. if (!string.IsNullOrEmpty(visit_purpose))
  5655. {
  5656. if (visit_purpose.contains("旅游"))
  5657. {
  5658. SetFieldValue(formFields, "purpose_tourism", "Yes"); // 旅游
  5659. }
  5660. else if (visit_purpose.contains("商务"))
  5661. {
  5662. SetFieldValue(formFields, "purpose_business", "Yes"); // 商务
  5663. }
  5664. else if (visit_purpose.contains("亲友"))
  5665. {
  5666. SetFieldValue(formFields, "purpose_visiting_family_friends", "Yes");// 庆祝亲友团聚
  5667. }
  5668. else if (visit_purpose.contains("文化交流") || visit_purpose.contains("旅游"))
  5669. {
  5670. SetFieldValue(formFields, "purpose_cultural", "Yes"); // 文化交流
  5671. }
  5672. else if (visit_purpose.contains("体育") || visit_purpose.contains("活动"))
  5673. {
  5674. SetFieldValue(formFields, "purpose_sports", "Yes"); // 体育活动
  5675. }
  5676. else if (visit_purpose.contains("官方访问"))
  5677. {
  5678. SetFieldValue(formFields, "purpose_offcial_visit", "Yes"); // 官方访问
  5679. }
  5680. else if (visit_purpose.contains("医疗原因") || visit_purpose.contains("医疗"))
  5681. {
  5682. SetFieldValue(formFields, "purpose_medical_reasons", "Yes"); // 医疗原因
  5683. }
  5684. else if (visit_purpose.contains("学习"))
  5685. {
  5686. SetFieldValue(formFields, "purpose_study", "Yes"); // 学习
  5687. }
  5688. else if (visit_purpose.contains("机场中转"))
  5689. {
  5690. SetFieldValue(formFields, "purpose_airport_transit", "Yes"); // 机场中转
  5691. }
  5692. else
  5693. {
  5694. SetFieldValue(formFields, "purpose_other", "Yes"); // 其他
  5695. SetFieldValue(formFields, "purpose_other_remark", ""); // 其他 - 备注
  5696. }
  5697. }
  5698. #endregion
  5699. #region 目的国相关信息
  5700. //关于停留目的的补充说明
  5701. SetFieldValue(formFields, "purpose_stay_info", "");
  5702. string[] RD_country = new string[] { }; //接收处理的国家
  5703. string firstEntryLabel = string.Empty; // 首入申根国标签
  5704. string membeDescLabel = string.Empty; // 申根国目的地
  5705. string RuJingTime = string.Empty; // 入境时间
  5706. string LiJingTime = string.Empty; // 离境时间
  5707. string stopDays = string.Empty; // 停留天数
  5708. if (!string.IsNullOrEmpty(groupInfo.VisitCountry))
  5709. {
  5710. List<string> SGGNames = new List<string>();//接收处理后的国家 是申根国
  5711. if (groupInfo.VisitCountry.Contains(","))
  5712. RD_country = groupInfo.VisitCountry.Split(',');
  5713. else if (groupInfo.VisitCountry.Contains(' '))
  5714. RD_country = groupInfo.VisitCountry.Split(' ');
  5715. else if (groupInfo.VisitCountry.Contains(","))
  5716. RD_country = groupInfo.VisitCountry.Split(',');
  5717. else if (groupInfo.VisitCountry.Contains("、"))
  5718. RD_country = groupInfo.VisitCountry.Split('、');
  5719. else if (groupInfo.VisitCountry.Contains("|"))
  5720. RD_country = groupInfo.VisitCountry.Split('|');
  5721. //判断是否是申根国家
  5722. for (int i = 0; i < RD_country.Length; i++)
  5723. {
  5724. if (RD_country[i].ToString() != null)
  5725. {
  5726. //在申根国家中筛选 该国家是否是申根国家
  5727. for (int j = 0; j < _shenGenGuos.Length; j++)
  5728. {
  5729. if (RD_country[i] == _shenGenGuos[j])
  5730. SGGNames.Add(_shenGenGuos[j]); //添加申根国
  5731. }
  5732. }
  5733. }
  5734. //目的地国是否有申根国
  5735. if (SGGNames.Count > 0)
  5736. {
  5737. firstEntryLabel = SGGNames.First();
  5738. membeDescLabel = string.Join(",", SGGNames.ToArray());
  5739. //接收生根国详细信息 存储顺序 起飞日期:Day 起飞时刻:StartTime 抵达日期:ArrivedDate 到达时刻:EndTime
  5740. List<SSGDetails> ListSSGDetails = new List<SSGDetails>();
  5741. //处理申根国家 预定到达时间 预定离开时间 预定停留天数
  5742. for (int i = 0; i < SGGNames.Count; i++)
  5743. {
  5744. //在相同的国家下 得到该航班的信息 //抵达时间 起飞日期:Day 起飞时刻:StartTime 到达时刻:EndTime 抵达日期:ArrivedDate 飞行时间:FlightTime 航司 Fliagtcode 入境口岸
  5745. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  5746. //ResidenceTime1 机票三字码信息
  5747. if (atbc != null)
  5748. {
  5749. string HL_Three = ""; //三字码 Three
  5750. for (int j = 0; j < atbc.Rows.Count; j++)
  5751. {
  5752. HL_Three = atbc.Rows[j]["Three"].ToString();
  5753. if (!string.IsNullOrEmpty(HL_Three))
  5754. {
  5755. string threeCodeTwo = HL_Three.Substring(3);
  5756. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  5757. if (tc != null)
  5758. {
  5759. //首入申根国时间
  5760. if (SGGNames[i] == tc.Country)
  5761. {
  5762. SSGDetails SSGDetails = new SSGDetails()
  5763. {
  5764. Three = atbc.Rows[j]["Three"].ToString(), //三字码
  5765. Fliagtcode = atbc.Rows[j]["Fliagtcode"].ToString(), //航司
  5766. startDate = atbc.Rows[j]["Day"].ToString(), //整理起飞日期
  5767. startTime = atbc.Rows[j]["StartTime"].ToString(), //整理起飞时刻
  5768. endDate = atbc.Rows[j]["ArrivedDate"].ToString(), //整理抵达日期
  5769. endTime = atbc.Rows[j]["EndTime"].ToString() //整理抵达时刻
  5770. };
  5771. ListSSGDetails.Add(SSGDetails);
  5772. }
  5773. }
  5774. }
  5775. }
  5776. }
  5777. }
  5778. ListSSGDetails.Sort((a, b) => a.startDate.CompareTo(b.startDate));
  5779. //得到并计算出入境时间
  5780. if (ListSSGDetails != null)
  5781. {
  5782. RuJingTime = ListSSGDetails.First().endDate + " " + ListSSGDetails.First().endTime.Substring(0, 2) + ":" + ListSSGDetails.First().endTime.Substring(2); //入境时间
  5783. LiJingTime = ListSSGDetails[ListSSGDetails.Count - 1].startDate + " " + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(0, 2) + ":" + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(2); //离境时间
  5784. stopDays = Convert.ToDateTime(LiJingTime).Subtract(Convert.ToDateTime(RuJingTime)).Days.ToString();
  5785. }
  5786. }
  5787. }
  5788. SetFieldValue(formFields, "main_destination", membeDescLabel); // 主要目的地成员国(如适用,还包括目的地的其他成员国)
  5789. SetFieldValue(formFields, "first_entry", firstEntryLabel); // 首次加入的成员国
  5790. // 申请入境次数
  5791. SetFieldValue(formFields, "entries_requested_single", "Off"); // 一次入境
  5792. SetFieldValue(formFields, "entries_requested_two", "Off"); // 两次入境
  5793. SetFieldValue(formFields, "entries_requested_multiple", "Off"); // 多次入境
  5794. SetFieldValue(formFields, "first_schenggen_stay_arrival_date", RuJingTime); // 首次计划在申根区停留的预计抵达日期
  5795. SetFieldValue(formFields, "first_schenggen_stay_departure_date", LiJingTime); // 首次计划在申根区停留结束后离开申根区的预计离境日期
  5796. #endregion
  5797. #region 申请申根签证而先前采集的指纹
  5798. SetFieldValue(formFields, "schengen_visa_no", ""); // 否
  5799. SetFieldValue(formFields, "schengen_visa_yes", ""); // 是
  5800. SetFieldValue(formFields, "fingerpints_date", ""); // 如有,请写明日期
  5801. SetFieldValue(formFields, "fingerpints_visa_number", ""); // 如有,请写明签证贴纸号码
  5802. #endregion
  5803. #region 最终目的地国家的入境许可(如适用)
  5804. SetFieldValue(formFields, "entry_permit_country_issued", ""); // 颁发单位
  5805. SetFieldValue(formFields, "entry_permit_country_valid", ""); // 颁发日期
  5806. SetFieldValue(formFields, "entry_permit_country_until", ""); // 有效期限
  5807. #endregion
  5808. #region 招待方在成员国中的姓氏和名字。如无此信息,则填写成员国内的酒店或临时住宿场所的名称
  5809. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  5810. .Where(x => x.DiId == groupId)
  5811. //.Where(x => x.City.contains(city))
  5812. .First();
  5813. //酒店住址
  5814. if (hotelInfo != null)
  5815. {
  5816. SetFieldValue(formFields, "hotel_namee", hotelInfo?.HotelName ?? ""); // 招待方的地址和电子邮箱地址
  5817. var otherInfo = $"{hotelInfo.HotelAddress}";
  5818. SetFieldValue(formFields, "hotel_address_and_email", otherInfo); // 酒店/临时住宿场所的地址和电子邮箱地址
  5819. SetFieldValue(formFields, "hotel_tel", hotelInfo?.HotelTel ?? ""); // 电话号码
  5820. }
  5821. #endregion
  5822. #region 邀请公司/组织信息
  5823. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  5824. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  5825. //.Where(x => x.Country.Contains(county))
  5826. //.Where(x => x.Area.Contains(city))
  5827. .First();
  5828. if (oa != null)
  5829. {
  5830. string oaInfo = $"{oa.Client} {oa.Address}";
  5831. SetFieldValue(formFields, "inviting_name_and_address", oaInfo); // 邀请公司/组织的名称及地址
  5832. string contactInfo = $"{oa?.Contact ?? ""} {oa?.Tel ?? ""} {oa?.EmailOrWeChat ?? ""}";
  5833. SetFieldValue(formFields, "inviting_contact_Info", contactInfo); // 公司/组织中联系人的姓氏、名字、地址、电话号码以及电子邮箱地址
  5834. SetFieldValue(formFields, "inviting_company_tel", oa?.Tel ?? ""); //电话号码(关于)公司/组织
  5835. }
  5836. #endregion
  5837. #region 申请人在留宿期间的旅行及生活费用已由申请人本人承担
  5838. #region 支持方式
  5839. SetFieldValue(formFields, "cost_type_himself", "Off"); // 支持方式
  5840. SetFieldValue(formFields, "cost_type_himself_cash", "Off"); // 现金
  5841. SetFieldValue(formFields, "cost_type_himself_cheques", "Off"); // 旅行支票
  5842. SetFieldValue(formFields, "cost_type_himself_creditcard", "Off"); // 信用卡
  5843. SetFieldValue(formFields, "cost_type_himself_accommodation", "Off");// 预付费住宿
  5844. SetFieldValue(formFields, "cost_type_himself_transport", "Off"); // 预付费交通
  5845. SetFieldValue(formFields, "cost_type_himself_other", "Off"); // 其他
  5846. SetFieldValue(formFields, "cost_type_himself_other_specify", ""); // 其他(请具体说明)
  5847. #endregion
  5848. #region 由赞助方(主办方、公司、组织)提供
  5849. SetFieldValue(formFields, "cost_type_himself", "Off"); // 由赞助方(主办方、公司、组织)提供
  5850. SetFieldValue(formFields, "cost_type_himself_cash", "Off"); // 在第 30 或 31 栏中提及
  5851. SetFieldValue(formFields, "cost_type_sponsor_other", "Off"); // 其他
  5852. SetFieldValue(formFields, "cost_type_sponsor_other_specify", ""); // 其他(请具体说明
  5853. //支持方式
  5854. SetFieldValue(formFields, "cost_type_support_cash", "Off"); // 现金
  5855. SetFieldValue(formFields, "cost_type_support_provided", "Off"); // 提供住宿
  5856. SetFieldValue(formFields, "cost_type_support_covered", "Off"); // 旅行期间的所有费用均由主办方承担
  5857. SetFieldValue(formFields, "cost_type_support_transport", "Off"); // 预先支付的交通费用
  5858. SetFieldValue(formFields, "cost_type_support_other", "Off"); // 其他
  5859. SetFieldValue(formFields, "cost_type_support_other_specify", ""); // 其他(请具体说明
  5860. #endregion
  5861. #endregion
  5862. #region 填写申请表的人员的姓氏和名字(若与申请人姓名不同)
  5863. SetFieldValue(formFields, "application_form_name", custInfo.TableOpName); // 申请表的人员
  5864. SetFieldValue(formFields, "application_form_address_email", ""); // 申请表人员的地址及电子邮箱地址
  5865. SetFieldValue(formFields, "assistance_tel", custInfo.TableOpTel); // 电话号码
  5866. #endregion
  5867. var date_year = DateTime.Now.Year.ToString();
  5868. var date_month = DateTime.Now.Month.ToString();
  5869. var date_day = DateTime.Now.Day.ToString();
  5870. SetFieldValue(formFields, "place_and_date", DateTime.Now.ToString("yyyy-MM-dd")); // 申请日期
  5871. var applicant_name = custInfo.LastName + custInfo.FirstName;
  5872. SetFieldValue(formFields, "applicant_signature", applicant_name); // 申请人姓名
  5873. SetFieldValue(formFields, "signature_parental_info", ""); // (如适用,需签名的家长授权/监护人信息):
  5874. #endregion
  5875. filePaths.Add(outputPath);
  5876. }
  5877. catch (Exception ex)
  5878. {
  5879. return Ok(JsonView(false, $"生成PDF文件时出错:{ex.Message}"));
  5880. }
  5881. finally
  5882. {
  5883. // 按正确顺序关闭资源
  5884. stamper?.Close();
  5885. reader?.Close();
  5886. templateStream?.Close();
  5887. outputStream?.Close();
  5888. }
  5889. #endregion
  5890. }
  5891. break;
  5892. case 6: // 加拿大
  5893. visaTypeName = $"加拿大签证申请表";
  5894. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  5895. var canadaSavePath = $"{fileServerPath}{visaTypeName}/";
  5896. if (!Directory.Exists(canadaSavePath)) Directory.CreateDirectory(canadaSavePath);
  5897. if (!System.IO.File.Exists(currTempPath))
  5898. {
  5899. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  5900. }
  5901. foreach (var custInfo in groupCustInfos)
  5902. {
  5903. EncryptionProcessor.DecryptProperties(custInfo);
  5904. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  5905. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  5906. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  5907. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  5908. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  5909. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  5910. #region 生成文件
  5911. PdfReader reader = null;
  5912. FileStream templateStream = null;
  5913. FileStream outputStream = null;
  5914. PdfStamper stamper = null;
  5915. try
  5916. {
  5917. string outputPath = $"{canadaSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  5918. //读取模板文件
  5919. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  5920. reader = new PdfReader(templateStream);
  5921. //创建输出文件
  5922. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  5923. stamper = new PdfStamper(reader, outputStream);
  5924. AcroFields formFields = stamper.AcroFields;
  5925. #region 设置文本值
  5926. SetFieldValue(formFields, "surname", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? ""); // 姓 英文
  5927. SetFieldValue(formFields, "surname_birth", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? ""); // 出生时姓 英文
  5928. SetFieldValue(formFields, "first_name", CommonFun.ConvertToPinyin(custInfo?.FirstName?.Trim() ?? "")?.ToLower() ?? ""); // 名 英文
  5929. #region 出生日期(日-月-年)
  5930. string idCard = idInfo?.CertNo?.Trim() ?? "";
  5931. string birthday = string.Empty;
  5932. if (!string.IsNullOrEmpty(idCard))
  5933. {
  5934. string year = idCard.Substring(6, 4);
  5935. string month = idCard.Substring(10, 2);
  5936. string day = idCard.Substring(12, 2);
  5937. birthday = day + "-" + month + "-" + year;
  5938. }
  5939. SetFieldValue(formFields, "birthday", birthday);
  5940. #endregion
  5941. var area = custInfo.BirthProvince + custInfo.BirthCity;
  5942. SetFieldValue(formFields, "birth_place", area); // 出生地区
  5943. SetFieldValue(formFields, "birth_country", "中国"); // 出生国籍
  5944. SetFieldValue(formFields, "current_nationality", "中国"); // 现国籍
  5945. SetFieldValue(formFields, "birth_nationality", "中国"); // 出生国
  5946. SetFieldValue(formFields, "other_nationality", ""); // 其他国籍
  5947. #region 设置性别
  5948. //清除性别
  5949. SetFieldValue(formFields, "sex_male", "Off"); // 性别 - 男
  5950. SetFieldValue(formFields, "sex_female", "Off"); // 性别 - 女
  5951. SetFieldValue(formFields, "sex_other", "Off"); // 性别 - 其他
  5952. //设置性别
  5953. if (custInfo.Sex == 0) // 男
  5954. {
  5955. SetFieldValue(formFields, "sex_male", "Yes"); // 性别 - 男
  5956. }
  5957. else if (custInfo.Sex == 1) // 女
  5958. {
  5959. SetFieldValue(formFields, "sex_female", "Yes"); // 性别 - 女
  5960. }
  5961. else // 其他
  5962. {
  5963. SetFieldValue(formFields, "sex_other", "Yes"); // 性别 - 其他
  5964. }
  5965. #endregion
  5966. #region 婚姻状态
  5967. //清除婚姻状况
  5968. SetFieldValue(formFields, "civil_single", "Off"); // 婚姻状况 - 未婚
  5969. SetFieldValue(formFields, "civil_married", "Off"); // 婚姻状况 - 已婚
  5970. SetFieldValue(formFields, "civil_registerered_partnership", "Off");// 婚姻状况 - 注册伴侣关系
  5971. SetFieldValue(formFields, "civil_separated", "Off"); // 婚姻状况 - 分居
  5972. SetFieldValue(formFields, "civil_divorced", "Off"); // 婚姻状况 - 离异
  5973. SetFieldValue(formFields, "civil_windower", "Off"); // 婚姻状况 - 妻子(丈夫)去世
  5974. SetFieldValue(formFields, "civil_other", "Off"); // 婚姻状况 - 其他
  5975. SetFieldValue(formFields, "civil_other_details", ""); // 婚姻状况 - 其他(请具体说明)
  5976. //设置婚姻状况
  5977. switch (custInfo.Marriage)
  5978. {
  5979. case 1: // 未婚
  5980. break;
  5981. case 2: // 已婚
  5982. SetFieldValue(formFields, "civil_married", "Yes");
  5983. break;
  5984. case 3: // 离婚/离异
  5985. SetFieldValue(formFields, "civil_divorced", "Yes");
  5986. break;
  5987. case 4:
  5988. break;
  5989. }
  5990. #endregion
  5991. // 父母的监护权(针对未成年人)/法定监护人(姓氏、名字、地址(若与申请人的地址不同)、电话号码、电子邮箱地址以及国籍)
  5992. SetFieldValue(formFields, "parental_authority", "");
  5993. //(如适用)国民身份号码
  5994. SetFieldValue(formFields, "id_number", idCard);
  5995. #region 护照信息
  5996. //清除值
  5997. SetFieldValue(formFields, "travel_type_ordinary_passport", "Off"); // 旅行证件类型 - 普通护照
  5998. SetFieldValue(formFields, "travel_type_diplomatic_passport", "Off"); // 旅行证件类型 - 外交护照
  5999. SetFieldValue(formFields, "travel_type_service_passport", "Off"); // 旅行证件类型 - 服务护照
  6000. SetFieldValue(formFields, "travel_type_offical_passport", "Off"); // 旅行证件类型 - 公务护照
  6001. SetFieldValue(formFields, "travel_type_special_passport", "Off"); // 旅行证件类型 - 特别护照
  6002. SetFieldValue(formFields, "travel_type_other_passport_details", ""); // 其他旅行证件(请注明)
  6003. //设置值
  6004. if (passportInfo != null)
  6005. {
  6006. // 签证类型
  6007. var visatypeInfo = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == passportInfo.PassportType);
  6008. if (visatypeInfo != null)
  6009. {
  6010. string visaName = visatypeInfo?.Name ?? "-";
  6011. if (visaName.contains("普通")) SetFieldValue(formFields, "travel_type_ordinary_passport", "Yes"); // 旅行证件类型 - 普通护照
  6012. else if (visaName.contains("外交")) SetFieldValue(formFields, "travel_type_diplomatic_passport", "Yes"); // 旅行证件类型 - 外交护照
  6013. else if (visaName.contains("服务")) SetFieldValue(formFields, "travel_type_service_passport", "Yes"); // 旅行证件类型 - 服务护照
  6014. else if (visaName.contains("公务")) SetFieldValue(formFields, "travel_type_offical_passport", "Yes"); // 旅行证件类型 - 公务护照
  6015. else // 旅行证件类型 - 特别护照
  6016. {
  6017. SetFieldValue(formFields, "travel_type_other_passport", "Yes");
  6018. SetFieldValue(formFields, "travel_type_other_passport_details", "");
  6019. }
  6020. }
  6021. #region 护照信息
  6022. SetFieldValue(formFields, "travel_number", passportInfo.CertNo); // 签证 编号
  6023. SetFieldValue(formFields, "travel_issue_country", passportInfo.Country); // 签发 国
  6024. SetFieldValue(formFields, "travel_issue_date", passportInfo.IssueDt?.ToString("yyyy-MM-dd") ?? ""); // 签发日期
  6025. SetFieldValue(formFields, "travel_issue_vaild", passportInfo.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); // 有效期至
  6026. #endregion
  6027. }
  6028. #endregion
  6029. #region 适用情况下,欧盟、欧洲经济区或瑞士公民,或英国籍且为《欧盟-英国脱欧协议》受益人的家庭成员的个人资料 “默认空”
  6030. SetFieldValue(formFields, "eu_info_surname", ""); // 姓氏(家族名)
  6031. SetFieldValue(formFields, "eu_info_first_name", ""); // 名字(名字)
  6032. SetFieldValue(formFields, "eu_info_birthday", ""); // 出生日期 (日-月-年)
  6033. SetFieldValue(formFields, "eu_info_nationality", ""); // 国籍
  6034. SetFieldValue(formFields, "eu_info_id_number", ""); // 旅行证件或身份证号码
  6035. #region 与欧盟、欧洲经济区或瑞士公民,或作为《欧盟-英国脱欧协议》受益人的英国国民之间的家庭关系(如适用)
  6036. SetFieldValue(formFields, "eu_family_relationship_spouse", "Off"); // 夫妻
  6037. SetFieldValue(formFields, "eu_family_relationship_child", "Off"); // 子女
  6038. SetFieldValue(formFields, "eu_family_relationship_grandchild", "Off"); // 孙子女
  6039. SetFieldValue(formFields, "eu_family_relationship_ascendant", "Off"); // 有赡养关系的长辈
  6040. SetFieldValue(formFields, "eu_family_relationship_registered", "Off"); // 注册伴侣关系
  6041. #endregion
  6042. #endregion
  6043. // 申请人的家庭住址和电子邮箱地址
  6044. string applicantAddressAndEmail = $"{custInfo.Address} {custInfo.Email}";
  6045. SetFieldValue(formFields, "applicant_address_and_email", applicantAddressAndEmail);
  6046. // 申请人的电话
  6047. SetFieldValue(formFields, "applicant_tel", custInfo.Tel);
  6048. #region 在非当前国籍所属国家的居住情况 “默认空”
  6049. SetFieldValue(formFields, "uncurrent_count_no", "Yes"); // 否
  6050. SetFieldValue(formFields, "uncurrent_count_yes", "Off"); // 是
  6051. SetFieldValue(formFields, "uncurrent_country_residence", "");// 居留许可或同等证明
  6052. SetFieldValue(formFields, "uncurrent_country_no", ""); // No
  6053. SetFieldValue(formFields, "uncurrent_country_valid_until", "");// 有效期至
  6054. #endregion
  6055. #region 职业
  6056. //职业信息
  6057. if (companyInfos != null && companyInfos.Count > 0)
  6058. {
  6059. // 当前职业
  6060. SetFieldValue(formFields, "current_occupation", companyInfos.FirstOrDefault()?.Job ?? "");
  6061. //雇主及雇主的地址和电话号码。对于学生而言,应填写教育机构的名称及地址
  6062. string employerInfo = $"{companyInfos.FirstOrDefault()?.CompanyAddress ?? ""} {companyInfos.FirstOrDefault()?.Phone ?? ""}";
  6063. }
  6064. #endregion
  6065. #region 此次行程的目的
  6066. //清除值
  6067. SetFieldValue(formFields, "purpose_tourism", "Off"); // 旅游
  6068. SetFieldValue(formFields, "purpose_business", "Off"); // 商务
  6069. SetFieldValue(formFields, "purpose_visiting_family_friends", "Off");// 庆祝亲友团聚
  6070. SetFieldValue(formFields, "purpose_cultural", "Off"); // 文化交流
  6071. SetFieldValue(formFields, "purpose_sports", "Off"); // 体育活动
  6072. SetFieldValue(formFields, "purpose_offcial_visit", "Off"); // 官方访问
  6073. SetFieldValue(formFields, "purpose_medical_reasons", "Off"); // 医疗原因
  6074. SetFieldValue(formFields, "purpose_study", "Off"); // 学习
  6075. SetFieldValue(formFields, "purpose_airport_transit", "Off"); // 机场中转
  6076. SetFieldValue(formFields, "purpose_other", "Off"); // 其他
  6077. SetFieldValue(formFields, "purpose_other_remark", ""); // 其他 - 备注
  6078. var visit_purpose = groupInfo.VisitPurpose;
  6079. if (!string.IsNullOrEmpty(visit_purpose))
  6080. {
  6081. if (visit_purpose.contains("旅游"))
  6082. {
  6083. SetFieldValue(formFields, "purpose_tourism", "Yes"); // 旅游
  6084. }
  6085. else if (visit_purpose.contains("商务"))
  6086. {
  6087. SetFieldValue(formFields, "purpose_business", "Yes"); // 商务
  6088. }
  6089. else if (visit_purpose.contains("亲友"))
  6090. {
  6091. SetFieldValue(formFields, "purpose_visiting_family_friends", "Yes");// 庆祝亲友团聚
  6092. }
  6093. else if (visit_purpose.contains("文化交流") || visit_purpose.contains("旅游"))
  6094. {
  6095. SetFieldValue(formFields, "purpose_cultural", "Yes"); // 文化交流
  6096. }
  6097. else if (visit_purpose.contains("体育") || visit_purpose.contains("活动"))
  6098. {
  6099. SetFieldValue(formFields, "purpose_sports", "Yes"); // 体育活动
  6100. }
  6101. else if (visit_purpose.contains("官方访问"))
  6102. {
  6103. SetFieldValue(formFields, "purpose_offcial_visit", "Yes"); // 官方访问
  6104. }
  6105. else if (visit_purpose.contains("医疗原因") || visit_purpose.contains("医疗"))
  6106. {
  6107. SetFieldValue(formFields, "purpose_medical_reasons", "Yes"); // 医疗原因
  6108. }
  6109. else if (visit_purpose.contains("学习"))
  6110. {
  6111. SetFieldValue(formFields, "purpose_study", "Yes"); // 学习
  6112. }
  6113. else if (visit_purpose.contains("机场中转"))
  6114. {
  6115. SetFieldValue(formFields, "purpose_airport_transit", "Yes"); // 机场中转
  6116. }
  6117. else
  6118. {
  6119. SetFieldValue(formFields, "purpose_other", "Yes"); // 其他
  6120. SetFieldValue(formFields, "purpose_other_remark", ""); // 其他 - 备注
  6121. }
  6122. }
  6123. #endregion
  6124. #region 目的国相关信息
  6125. //关于停留目的的补充说明
  6126. SetFieldValue(formFields, "purpose_stay_info", "");
  6127. string[] RD_country = new string[] { }; //接收处理的国家
  6128. string firstEntryLabel = string.Empty; // 首入申根国标签
  6129. string membeDescLabel = string.Empty; // 申根国目的地
  6130. string RuJingTime = string.Empty; // 入境时间
  6131. string LiJingTime = string.Empty; // 离境时间
  6132. string stopDays = string.Empty; // 停留天数
  6133. if (!string.IsNullOrEmpty(groupInfo.VisitCountry))
  6134. {
  6135. List<string> SGGNames = new List<string>();//接收处理后的国家 是申根国
  6136. if (groupInfo.VisitCountry.Contains(","))
  6137. RD_country = groupInfo.VisitCountry.Split(',');
  6138. else if (groupInfo.VisitCountry.Contains(' '))
  6139. RD_country = groupInfo.VisitCountry.Split(' ');
  6140. else if (groupInfo.VisitCountry.Contains(","))
  6141. RD_country = groupInfo.VisitCountry.Split(',');
  6142. else if (groupInfo.VisitCountry.Contains("、"))
  6143. RD_country = groupInfo.VisitCountry.Split('、');
  6144. else if (groupInfo.VisitCountry.Contains("|"))
  6145. RD_country = groupInfo.VisitCountry.Split('|');
  6146. //判断是否是申根国家
  6147. for (int i = 0; i < RD_country.Length; i++)
  6148. {
  6149. if (RD_country[i].ToString() != null)
  6150. {
  6151. //在申根国家中筛选 该国家是否是申根国家
  6152. for (int j = 0; j < _shenGenGuos.Length; j++)
  6153. {
  6154. if (RD_country[i] == _shenGenGuos[j])
  6155. SGGNames.Add(_shenGenGuos[j]); //添加申根国
  6156. }
  6157. }
  6158. }
  6159. //目的地国是否有申根国
  6160. if (SGGNames.Count > 0)
  6161. {
  6162. firstEntryLabel = SGGNames.First();
  6163. membeDescLabel = string.Join(",", SGGNames.ToArray());
  6164. //接收生根国详细信息 存储顺序 起飞日期:Day 起飞时刻:StartTime 抵达日期:ArrivedDate 到达时刻:EndTime
  6165. List<SSGDetails> ListSSGDetails = new List<SSGDetails>();
  6166. //处理申根国家 预定到达时间 预定离开时间 预定停留天数
  6167. for (int i = 0; i < SGGNames.Count; i++)
  6168. {
  6169. //在相同的国家下 得到该航班的信息 //抵达时间 起飞日期:Day 起飞时刻:StartTime 到达时刻:EndTime 抵达日期:ArrivedDate 飞行时间:FlightTime 航司 Fliagtcode 入境口岸
  6170. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  6171. //ResidenceTime1 机票三字码信息
  6172. if (atbc != null)
  6173. {
  6174. string HL_Three = ""; //三字码 Three
  6175. for (int j = 0; j < atbc.Rows.Count; j++)
  6176. {
  6177. HL_Three = atbc.Rows[j]["Three"].ToString();
  6178. if (!string.IsNullOrEmpty(HL_Three))
  6179. {
  6180. string threeCodeTwo = HL_Three.Substring(3);
  6181. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  6182. if (tc != null)
  6183. {
  6184. //首入申根国时间
  6185. if (SGGNames[i] == tc.Country)
  6186. {
  6187. SSGDetails SSGDetails = new SSGDetails()
  6188. {
  6189. Three = atbc.Rows[j]["Three"].ToString(), //三字码
  6190. Fliagtcode = atbc.Rows[j]["Fliagtcode"].ToString(), //航司
  6191. startDate = atbc.Rows[j]["Day"].ToString(), //整理起飞日期
  6192. startTime = atbc.Rows[j]["StartTime"].ToString(), //整理起飞时刻
  6193. endDate = atbc.Rows[j]["ArrivedDate"].ToString(), //整理抵达日期
  6194. endTime = atbc.Rows[j]["EndTime"].ToString() //整理抵达时刻
  6195. };
  6196. ListSSGDetails.Add(SSGDetails);
  6197. }
  6198. }
  6199. }
  6200. }
  6201. }
  6202. }
  6203. ListSSGDetails.Sort((a, b) => a.startDate.CompareTo(b.startDate));
  6204. //得到并计算出入境时间
  6205. if (ListSSGDetails != null)
  6206. {
  6207. RuJingTime = ListSSGDetails.First().endDate + " " + ListSSGDetails.First().endTime.Substring(0, 2) + ":" + ListSSGDetails.First().endTime.Substring(2); //入境时间
  6208. LiJingTime = ListSSGDetails[ListSSGDetails.Count - 1].startDate + " " + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(0, 2) + ":" + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(2); //离境时间
  6209. stopDays = Convert.ToDateTime(LiJingTime).Subtract(Convert.ToDateTime(RuJingTime)).Days.ToString();
  6210. }
  6211. }
  6212. }
  6213. SetFieldValue(formFields, "main_destination", membeDescLabel); // 主要目的地成员国(如适用,还包括目的地的其他成员国)
  6214. SetFieldValue(formFields, "first_entry", firstEntryLabel); // 首次加入的成员国
  6215. // 申请入境次数
  6216. SetFieldValue(formFields, "entries_requested_single", "Off"); // 一次入境
  6217. SetFieldValue(formFields, "entries_requested_two", "Off"); // 两次入境
  6218. SetFieldValue(formFields, "entries_requested_multiple", "Off"); // 多次入境
  6219. SetFieldValue(formFields, "first_schenggen_stay_arrival_date", RuJingTime); // 首次计划在申根区停留的预计抵达日期
  6220. SetFieldValue(formFields, "first_schenggen_stay_departure_date", LiJingTime); // 首次计划在申根区停留结束后离开申根区的预计离境日期
  6221. #endregion
  6222. #region 申请申根签证而先前采集的指纹
  6223. SetFieldValue(formFields, "schengen_visa_no", ""); // 否
  6224. SetFieldValue(formFields, "schengen_visa_yes", ""); // 是
  6225. SetFieldValue(formFields, "fingerpints_date", ""); // 如有,请写明日期
  6226. SetFieldValue(formFields, "fingerpints_visa_number", ""); // 如有,请写明签证贴纸号码
  6227. #endregion
  6228. #region 最终目的地国家的入境许可(如适用)
  6229. SetFieldValue(formFields, "entry_permit_country_issued", ""); // 颁发单位
  6230. SetFieldValue(formFields, "entry_permit_country_valid", ""); // 颁发日期
  6231. SetFieldValue(formFields, "entry_permit_country_until", ""); // 有效期限
  6232. #endregion
  6233. #region 招待方在成员国中的姓氏和名字。如无此信息,则填写成员国内的酒店或临时住宿场所的名称
  6234. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  6235. .Where(x => x.DiId == groupId)
  6236. //.Where(x => x.City.contains(city))
  6237. .First();
  6238. //酒店住址
  6239. if (hotelInfo != null)
  6240. {
  6241. SetFieldValue(formFields, "hotel_namee", hotelInfo?.HotelName ?? ""); // 招待方的地址和电子邮箱地址
  6242. var otherInfo = $"{hotelInfo.HotelAddress}";
  6243. SetFieldValue(formFields, "hotel_address_and_email", otherInfo); // 酒店/临时住宿场所的地址和电子邮箱地址
  6244. SetFieldValue(formFields, "hotel_tel", hotelInfo?.HotelTel ?? ""); // 电话号码
  6245. }
  6246. #endregion
  6247. #region 邀请公司/组织信息
  6248. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  6249. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  6250. //.Where(x => x.Country.Contains(county))
  6251. //.Where(x => x.Area.Contains(city))
  6252. .First();
  6253. if (oa != null)
  6254. {
  6255. string oaInfo = $"{oa.Client} {oa.Address}";
  6256. SetFieldValue(formFields, "inviting_name_and_address", oaInfo); // 邀请公司/组织的名称及地址
  6257. string contactInfo = $"{oa?.Contact ?? ""} {oa?.Tel ?? ""} {oa?.EmailOrWeChat ?? ""}";
  6258. SetFieldValue(formFields, "inviting_contact_Info", contactInfo); // 公司/组织中联系人的姓氏、名字、地址、电话号码以及电子邮箱地址
  6259. SetFieldValue(formFields, "inviting_company_tel", oa?.Tel ?? ""); //电话号码(关于)公司/组织
  6260. }
  6261. #endregion
  6262. #region 申请人在留宿期间的旅行及生活费用已由申请人本人承担
  6263. #region 支持方式
  6264. SetFieldValue(formFields, "cost_type_himself", "Off"); // 支持方式
  6265. SetFieldValue(formFields, "cost_type_himself_cash", "Off"); // 现金
  6266. SetFieldValue(formFields, "cost_type_himself_cheques", "Off"); // 旅行支票
  6267. SetFieldValue(formFields, "cost_type_himself_creditcard", "Off"); // 信用卡
  6268. SetFieldValue(formFields, "cost_type_himself_accommodation", "Off");// 预付费住宿
  6269. SetFieldValue(formFields, "cost_type_himself_transport", "Off"); // 预付费交通
  6270. SetFieldValue(formFields, "cost_type_himself_other", "Off"); // 其他
  6271. SetFieldValue(formFields, "cost_type_himself_other_specify", ""); // 其他(请具体说明)
  6272. #endregion
  6273. #region 由赞助方(主办方、公司、组织)提供
  6274. SetFieldValue(formFields, "cost_type_himself", "Off"); // 由赞助方(主办方、公司、组织)提供
  6275. SetFieldValue(formFields, "cost_type_himself_cash", "Off"); // 在第 30 或 31 栏中提及
  6276. SetFieldValue(formFields, "cost_type_sponsor_other", "Off"); // 其他
  6277. SetFieldValue(formFields, "cost_type_sponsor_other_specify", ""); // 其他(请具体说明
  6278. //支持方式
  6279. SetFieldValue(formFields, "cost_type_support_cash", "Off"); // 现金
  6280. SetFieldValue(formFields, "cost_type_support_provided", "Off"); // 提供住宿
  6281. SetFieldValue(formFields, "cost_type_support_covered", "Off"); // 旅行期间的所有费用均由主办方承担
  6282. SetFieldValue(formFields, "cost_type_support_transport", "Off"); // 预先支付的交通费用
  6283. SetFieldValue(formFields, "cost_type_support_other", "Off"); // 其他
  6284. SetFieldValue(formFields, "cost_type_support_other_specify", ""); // 其他(请具体说明
  6285. #endregion
  6286. #endregion
  6287. #region 填写申请表的人员的姓氏和名字(若与申请人姓名不同)
  6288. SetFieldValue(formFields, "application_form_name", custInfo.TableOpName); // 申请表的人员
  6289. SetFieldValue(formFields, "application_form_address_email", ""); // 申请表人员的地址及电子邮箱地址
  6290. SetFieldValue(formFields, "assistance_tel", custInfo.TableOpTel); // 电话号码
  6291. #endregion
  6292. var date_year = DateTime.Now.Year.ToString();
  6293. var date_month = DateTime.Now.Month.ToString();
  6294. var date_day = DateTime.Now.Day.ToString();
  6295. SetFieldValue(formFields, "place_and_date", DateTime.Now.ToString("yyyy-MM-dd")); // 申请日期
  6296. var applicant_name = custInfo.LastName + custInfo.FirstName;
  6297. SetFieldValue(formFields, "applicant_signature", applicant_name); // 申请人姓名
  6298. SetFieldValue(formFields, "signature_parental_info", ""); // (如适用,需签名的家长授权/监护人信息):
  6299. #endregion
  6300. filePaths.Add(outputPath);
  6301. }
  6302. catch (Exception ex)
  6303. {
  6304. return Ok(JsonView(false, $"生成PDF文件时出错:{ex.Message}"));
  6305. }
  6306. finally
  6307. {
  6308. // 按正确顺序关闭资源
  6309. stamper?.Close();
  6310. reader?.Close();
  6311. templateStream?.Close();
  6312. outputStream?.Close();
  6313. }
  6314. #endregion
  6315. }
  6316. break;
  6317. case 7: // 克罗地亚
  6318. visaTypeName = $"克罗地亚签证申请表";
  6319. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  6320. var croatiaSavePath = $"{fileServerPath}{visaTypeName}/";
  6321. if (!Directory.Exists(croatiaSavePath)) Directory.CreateDirectory(croatiaSavePath);
  6322. if (!System.IO.File.Exists(currTempPath))
  6323. {
  6324. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  6325. }
  6326. foreach (var custInfo in groupCustInfos)
  6327. {
  6328. EncryptionProcessor.DecryptProperties(custInfo);
  6329. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  6330. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  6331. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  6332. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  6333. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  6334. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  6335. #region 生成文件
  6336. PdfReader reader = null;
  6337. FileStream templateStream = null;
  6338. FileStream outputStream = null;
  6339. PdfStamper stamper = null;
  6340. try
  6341. {
  6342. string outputPath = $"{croatiaSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  6343. //读取模板文件
  6344. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  6345. reader = new PdfReader(templateStream);
  6346. //创建输出文件
  6347. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  6348. stamper = new PdfStamper(reader, outputStream);
  6349. AcroFields formFields = stamper.AcroFields;
  6350. #region 设置文本值
  6351. SetFieldValue(formFields, "surname", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? ""); // 姓 英文
  6352. SetFieldValue(formFields, "surname_birth", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? ""); // 出生时姓 英文
  6353. SetFieldValue(formFields, "firstname", CommonFun.ConvertToPinyin(custInfo?.FirstName?.Trim() ?? "")?.ToLower() ?? ""); // 名 英文
  6354. #region 出生日期(日-月-年)
  6355. string idCard = idInfo?.CertNo?.Trim() ?? "";
  6356. string birthday = string.Empty;
  6357. if (!string.IsNullOrEmpty(idCard))
  6358. {
  6359. string year = idCard.Substring(6, 4);
  6360. string month = idCard.Substring(10, 2);
  6361. string day = idCard.Substring(12, 2);
  6362. birthday = day + "-" + month + "-" + year;
  6363. }
  6364. SetFieldValue(formFields, "birthday", birthday);
  6365. #endregion
  6366. var area = custInfo.BirthProvince + custInfo.BirthCity;
  6367. SetFieldValue(formFields, "birth_place", area); // 出生地区
  6368. SetFieldValue(formFields, "birth_country", "中国"); // 出生国籍
  6369. SetFieldValue(formFields, "current_nationality", "中国"); // 现国籍
  6370. #region 设置性别
  6371. //清除性别
  6372. SetFieldValue(formFields, "sex_male", "Off"); // 性别 - 男
  6373. SetFieldValue(formFields, "sex_female", "Off"); // 性别 - 女
  6374. //设置性别
  6375. if (custInfo.Sex == 0) // 男
  6376. {
  6377. SetFieldValue(formFields, "sex_male", "Yes"); // 性别 - 男
  6378. }
  6379. else if (custInfo.Sex == 1) // 女
  6380. {
  6381. SetFieldValue(formFields, "sex_female", "Yes"); // 性别 - 女
  6382. }
  6383. #endregion
  6384. #region 婚姻状态
  6385. //清除婚姻状况
  6386. SetFieldValue(formFields, "marital_single", "Off"); // 婚姻状况 - 未婚
  6387. SetFieldValue(formFields, "marital_married", "Off"); // 婚姻状况 - 已婚
  6388. SetFieldValue(formFields, "marital_separated", "Off"); // 婚姻状况 - 分居
  6389. SetFieldValue(formFields, "marital_dicorced", "Off"); // 婚姻状况 - 离异
  6390. SetFieldValue(formFields, "marital_widower", "Off"); // 婚姻状况 - 丧偶
  6391. SetFieldValue(formFields, "marital_other", "Off"); // 婚姻状况 - 其他
  6392. SetFieldValue(formFields, "marital_other_specify", ""); // 婚姻状况 - 其他(请具体说明)
  6393. //设置婚姻状况
  6394. switch (custInfo.Marriage)
  6395. {
  6396. case 1: // 未婚
  6397. SetFieldValue(formFields, "marital_single", "Yes");
  6398. break;
  6399. case 2: // 已婚
  6400. SetFieldValue(formFields, "marital_married", "Yes");
  6401. break;
  6402. case 3: // 离婚/离异
  6403. SetFieldValue(formFields, "marital_dicorced", "Yes");
  6404. break;
  6405. case 4:
  6406. break;
  6407. }
  6408. #endregion
  6409. // 父母的监护权(针对未成年人)/法定监护人(姓氏、名字、地址(若与申请人的地址不同)、电话号码、电子邮箱地址以及国籍)
  6410. SetFieldValue(formFields, "legalGuardian", "");
  6411. //(如适用)国民身份号码
  6412. SetFieldValue(formFields, "nationalIdNumber", idCard);
  6413. #region 护照信息
  6414. //清除值
  6415. SetFieldValue(formFields, "travel_ordinary_passport", "Off"); // 旅行证件类型 - 普通护照
  6416. SetFieldValue(formFields, "travel_diplomatic_passport", "Off");// 旅行证件类型 - 外交护照
  6417. SetFieldValue(formFields, "travel_service_passport", "Off"); // 旅行证件类型 - 服务护照
  6418. SetFieldValue(formFields, "travel_special_passport", "Off"); // 旅行证件类型 - 公务护照
  6419. SetFieldValue(formFields, "travel_other", "Off"); // 旅行证件类型 - 特别护照
  6420. SetFieldValue(formFields, "travel_other_specify", ""); // 其他旅行证件(请注明)
  6421. //设置值
  6422. if (passportInfo != null)
  6423. {
  6424. // 签证类型
  6425. var visatypeInfo = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == passportInfo.PassportType);
  6426. if (visatypeInfo != null)
  6427. {
  6428. string visaName = visatypeInfo?.Name ?? "-";
  6429. if (visaName.contains("普通")) SetFieldValue(formFields, "travel_ordinary_passport", "Yes"); // 旅行证件类型 - 普通护照
  6430. else if (visaName.contains("外交")) SetFieldValue(formFields, "travel_diplomatic_passport", "Yes"); // 旅行证件类型 - 外交护照
  6431. else if (visaName.contains("服务")) SetFieldValue(formFields, "travel_service_passport", "Yes"); // 旅行证件类型 - 服务护照
  6432. else if (visaName.contains("公务")) SetFieldValue(formFields, "travel_type_offical_passport", "Yes");// 旅行证件类型 - 公务护照
  6433. else // 旅行证件类型 - 特别护照
  6434. {
  6435. SetFieldValue(formFields, "travel_other", "Yes");
  6436. SetFieldValue(formFields, "travel_other_specify", "");
  6437. }
  6438. }
  6439. #region 护照信息
  6440. SetFieldValue(formFields, "travel_number", passportInfo.CertNo); // 签证 编号
  6441. SetFieldValue(formFields, "travel_issued", passportInfo.Country); // 签发 国
  6442. SetFieldValue(formFields, "travle_issueDate", passportInfo.IssueDt?.ToString("yyyy-MM-dd") ?? ""); // 签发日期
  6443. SetFieldValue(formFields, "travel_expiryDate", passportInfo.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); // 有效期至
  6444. #endregion
  6445. }
  6446. #endregion
  6447. #region 是否在非国籍国居住
  6448. SetFieldValue(formFields, "residesOutsideNationality_no", "Yes"); // 否
  6449. SetFieldValue(formFields, "residesOutsideNationality_yes", "Off"); // 是
  6450. SetFieldValue(formFields, "residesOutsideNationality_number", ""); // 编号
  6451. SetFieldValue(formFields, "residesOutsideNationality_validuntil", ""); // 有效期限
  6452. #endregion
  6453. #region 职业
  6454. //职业信息
  6455. if (companyInfos != null && companyInfos.Count > 0)
  6456. {
  6457. // 当前职业
  6458. SetFieldValue(formFields, "occupation", companyInfos.FirstOrDefault()?.Job ?? "");
  6459. //雇主及雇主的地址和电话号码。
  6460. string employerInfo = $"{companyInfos.FirstOrDefault()?.CompanyAddress ?? ""} {companyInfos.FirstOrDefault()?.Phone ?? ""}";
  6461. SetFieldValue(formFields, "employerInfo", employerInfo);
  6462. }
  6463. #endregion
  6464. #region 此次行程的目的
  6465. //清除值
  6466. SetFieldValue(formFields, "purpose_tourism", "Off"); // 旅游
  6467. SetFieldValue(formFields, "purpose_business", "Off"); // 商务
  6468. SetFieldValue(formFields, "purpose_visiting_friends_family", "Off");// 庆祝亲友团聚
  6469. SetFieldValue(formFields, "purpose_cultural", "Off"); // 文化交流
  6470. SetFieldValue(formFields, "purpose_sports", "Off"); // 体育活动
  6471. SetFieldValue(formFields, "purpose_official_visit", "Off"); // 官方访问
  6472. SetFieldValue(formFields, "purpose_medical_reasons", "Off"); // 医疗原因
  6473. SetFieldValue(formFields, "purpose_study", "Off"); // 学习
  6474. SetFieldValue(formFields, "purpose_transit", "Off"); // 过境
  6475. SetFieldValue(formFields, "purpose_airport_transit", "Off"); // 机场中转
  6476. SetFieldValue(formFields, "purpose_other", "Off"); // 其他
  6477. SetFieldValue(formFields, "purpose_other_specify", ""); // 其他 - 备注
  6478. var visit_purpose = groupInfo.VisitPurpose;
  6479. if (!string.IsNullOrEmpty(visit_purpose))
  6480. {
  6481. if (visit_purpose.contains("旅游"))
  6482. {
  6483. SetFieldValue(formFields, "purpose_tourism", "Yes"); // 旅游
  6484. }
  6485. else if (visit_purpose.contains("商务"))
  6486. {
  6487. SetFieldValue(formFields, "purpose_business", "Yes"); // 商务
  6488. }
  6489. else if (visit_purpose.contains("亲友"))
  6490. {
  6491. SetFieldValue(formFields, "purpose_visiting_friends_family", "Yes");// 庆祝亲友团聚
  6492. }
  6493. else if (visit_purpose.contains("文化交流") || visit_purpose.contains("旅游"))
  6494. {
  6495. SetFieldValue(formFields, "purpose_cultural", "Yes"); // 文化交流
  6496. }
  6497. else if (visit_purpose.contains("体育") || visit_purpose.contains("活动"))
  6498. {
  6499. SetFieldValue(formFields, "purpose_sports", "Yes"); // 体育活动
  6500. }
  6501. else if (visit_purpose.contains("官方访问"))
  6502. {
  6503. SetFieldValue(formFields, "purpose_official_visit", "Yes"); // 官方访问
  6504. }
  6505. else if (visit_purpose.contains("医疗原因") || visit_purpose.contains("医疗"))
  6506. {
  6507. SetFieldValue(formFields, "purpose_medical_reasons", "Yes"); // 医疗原因
  6508. }
  6509. else if (visit_purpose.contains("学习"))
  6510. {
  6511. SetFieldValue(formFields, "purpose_study", "Yes"); // 学习
  6512. }
  6513. else if (visit_purpose.contains("过境"))
  6514. {
  6515. SetFieldValue(formFields, "purpose_transit", "Yes"); // 过境
  6516. }
  6517. else if (visit_purpose.contains("机场中转"))
  6518. {
  6519. SetFieldValue(formFields, "purpose_airport_transit", "Yes"); // 机场中转
  6520. }
  6521. else
  6522. {
  6523. SetFieldValue(formFields, "purpose_other", "Yes"); // 其他
  6524. SetFieldValue(formFields, "purpose_other_specify", ""); // 其他 - 备注
  6525. }
  6526. }
  6527. #endregion
  6528. #region 目的国相关信息
  6529. //关于停留目的的补充说明
  6530. SetFieldValue(formFields, "purpose_stay_info", "");
  6531. string[] country = new string[] { }; //接收处理的国家
  6532. string firstEntryLabel = string.Empty; // 首入申根国标签
  6533. string membeDescLabel = string.Empty; // 申根国目的地
  6534. string RuJingTime = string.Empty; // 入境时间
  6535. string LiJingTime = string.Empty; // 离境时间
  6536. string stayDays = string.Empty; // 停留天数
  6537. if (!string.IsNullOrEmpty(groupInfo.VisitCountry))
  6538. {
  6539. List<string> SGGNames = new List<string>();//接收处理后的国家 是申根国
  6540. if (groupInfo.VisitCountry.Contains(","))
  6541. country = groupInfo.VisitCountry.Split(',');
  6542. else if (groupInfo.VisitCountry.Contains(' '))
  6543. country = groupInfo.VisitCountry.Split(' ');
  6544. else if (groupInfo.VisitCountry.Contains(","))
  6545. country = groupInfo.VisitCountry.Split(',');
  6546. else if (groupInfo.VisitCountry.Contains("、"))
  6547. country = groupInfo.VisitCountry.Split('、');
  6548. else if (groupInfo.VisitCountry.Contains("|"))
  6549. country = groupInfo.VisitCountry.Split('|');
  6550. //判断是否是申根国家
  6551. for (int i = 0; i < country.Length; i++)
  6552. {
  6553. if (country[i].ToString() != null)
  6554. {
  6555. //在申根国家中筛选 该国家是否是申根国家
  6556. for (int j = 0; j < _shenGenGuos.Length; j++)
  6557. {
  6558. if (country[i] == _shenGenGuos[j])
  6559. SGGNames.Add(_shenGenGuos[j]); //添加申根国
  6560. }
  6561. }
  6562. }
  6563. //目的地国是否有申根国
  6564. if (SGGNames.Count > 0)
  6565. {
  6566. firstEntryLabel = SGGNames.First();
  6567. membeDescLabel = string.Join(",", SGGNames.ToArray());
  6568. //接收生根国详细信息 存储顺序 起飞日期:Day 起飞时刻:StartTime 抵达日期:ArrivedDate 到达时刻:EndTime
  6569. List<SSGDetails> ListSSGDetails = new List<SSGDetails>();
  6570. //处理申根国家 预定到达时间 预定离开时间 预定停留天数
  6571. for (int i = 0; i < SGGNames.Count; i++)
  6572. {
  6573. //在相同的国家下 得到该航班的信息 //抵达时间 起飞日期:Day 起飞时刻:StartTime 到达时刻:EndTime 抵达日期:ArrivedDate 飞行时间:FlightTime 航司 Fliagtcode 入境口岸
  6574. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  6575. //ResidenceTime1 机票三字码信息
  6576. if (atbc != null)
  6577. {
  6578. string HL_Three = ""; //三字码 Three
  6579. for (int j = 0; j < atbc.Rows.Count; j++)
  6580. {
  6581. HL_Three = atbc.Rows[j]["Three"].ToString();
  6582. if (!string.IsNullOrEmpty(HL_Three))
  6583. {
  6584. string threeCodeTwo = HL_Three.Substring(3);
  6585. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  6586. if (tc != null)
  6587. {
  6588. //首入申根国时间
  6589. if (SGGNames[i] == tc.Country)
  6590. {
  6591. SSGDetails SSGDetails = new SSGDetails()
  6592. {
  6593. Three = atbc.Rows[j]["Three"].ToString(), //三字码
  6594. Fliagtcode = atbc.Rows[j]["Fliagtcode"].ToString(), //航司
  6595. startDate = atbc.Rows[j]["Day"].ToString(), //整理起飞日期
  6596. startTime = atbc.Rows[j]["StartTime"].ToString(), //整理起飞时刻
  6597. endDate = atbc.Rows[j]["ArrivedDate"].ToString(), //整理抵达日期
  6598. endTime = atbc.Rows[j]["EndTime"].ToString() //整理抵达时刻
  6599. };
  6600. ListSSGDetails.Add(SSGDetails);
  6601. }
  6602. }
  6603. }
  6604. }
  6605. }
  6606. }
  6607. ListSSGDetails.Sort((a, b) => a.startDate.CompareTo(b.startDate));
  6608. //得到并计算出入境时间
  6609. if (ListSSGDetails != null)
  6610. {
  6611. RuJingTime = ListSSGDetails.First().endDate + " " + ListSSGDetails.First().endTime.Substring(0, 2) + ":" + ListSSGDetails.First().endTime.Substring(2); //入境时间
  6612. LiJingTime = ListSSGDetails[ListSSGDetails.Count - 1].startDate + " " + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(0, 2) + ":" + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(2); //离境时间
  6613. stayDays = Convert.ToDateTime(LiJingTime).Subtract(Convert.ToDateTime(RuJingTime)).Days.ToString();
  6614. }
  6615. }
  6616. }
  6617. SetFieldValue(formFields, "finalDestinationCountry", membeDescLabel);// 主要目的地成员国(如适用,还包括目的地的其他成员国)
  6618. SetFieldValue(formFields, "firstEntryBorder", firstEntryLabel); // 口岸
  6619. // 申请入境次数
  6620. SetFieldValue(formFields, "requestedEntry_single", "Off"); // 一次入境
  6621. SetFieldValue(formFields, "requestedEntry_two", "Off"); // 两次入境
  6622. SetFieldValue(formFields, "requestedEntry_multiple", "Off"); // 多次入境
  6623. SetFieldValue(formFields, "intendedStayDays", stayDays); // 计划停留天数
  6624. #endregion
  6625. #region 过去三年签证
  6626. SetFieldValue(formFields, "hasPreviousVisas_no", "Yes"); // 否
  6627. SetFieldValue(formFields, "hasPreviousVisas_yes", "Off"); // 是
  6628. //第一年
  6629. SetFieldValue(formFields, "hasPreviousVisas_country1", ""); // 国家
  6630. SetFieldValue(formFields, "hasPreviousVisas_valid1", ""); // 有效期限 起
  6631. SetFieldValue(formFields, "hasPreviousVisas_until1", ""); // 有效期限 止
  6632. //第二年
  6633. SetFieldValue(formFields, "hasPreviousVisas_country2", ""); // 国家
  6634. SetFieldValue(formFields, "hasPreviousVisas_valid2", ""); // 有效期限 起
  6635. SetFieldValue(formFields, "hasPreviousVisas_until2", ""); // 有效期限 止
  6636. //第三年
  6637. SetFieldValue(formFields, "hasPreviousVisas_country3", ""); // 国家
  6638. SetFieldValue(formFields, "hasPreviousVisas_valid3", ""); // 有效期限 起
  6639. SetFieldValue(formFields, "hasPreviousVisas_until3", ""); // 有效期限 止
  6640. #endregion
  6641. #region 此前录过指纹
  6642. SetFieldValue(formFields, "fingerprintsPreviouslyCollected_no", "Yes"); // 否
  6643. SetFieldValue(formFields, "fingerprintsPreviouslyCollected_yes", "Off"); // 是
  6644. SetFieldValue(formFields, "fingerprintsPreviouslyCollected_date", ""); // 如有,请写明日期
  6645. #endregion
  6646. #region 最终目的地入境许可
  6647. SetFieldValue(formFields, "finalDestinationEntryPermit_issued", ""); // 发布者
  6648. SetFieldValue(formFields, "finalDestinationEntryPermit_vaild", ""); // 有效期限 起
  6649. SetFieldValue(formFields, "finalDestinationEntryPermit_until", ""); // 有效期限 止
  6650. #endregion
  6651. #region 计划旅行日期
  6652. SetFieldValue(formFields, "travelDates_arrivalDate", groupInfo.VisitStartDate.ToString("yyyy-MM-dd")); // 出发日期
  6653. SetFieldValue(formFields, "travelDates_departureDate", groupInfo.VisitEndDate.ToString("yyyy-MM-dd")); // 离开日期
  6654. #endregion
  6655. #region 邀请人/酒店信息
  6656. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  6657. .Where(x => x.DiId == groupId)
  6658. //.Where(x => x.City.contains(city))
  6659. .First();
  6660. //酒店住址
  6661. if (hotelInfo != null)
  6662. {
  6663. SetFieldValue(formFields, "accommodationInfo_name", hotelInfo?.HotelName ?? ""); // 招待方的地址和电子邮箱地址
  6664. var otherInfo = $"{hotelInfo.HotelAddress}";
  6665. SetFieldValue(formFields, "accommodationInfo_addressAndNameEmail", otherInfo); // 酒店/临时住宿场所的地址和电子邮箱地址
  6666. SetFieldValue(formFields, "accommodationInfo_tel", hotelInfo?.HotelTel ?? ""); // 电话号码
  6667. }
  6668. #endregion
  6669. #region 邀请公司/组织信息
  6670. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  6671. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  6672. //.Where(x => x.Country.Contains(county))
  6673. //.Where(x => x.Area.Contains(city))
  6674. .First();
  6675. if (oa != null)
  6676. {
  6677. string oaInfo = $"{oa.Client} {oa.Address}";
  6678. SetFieldValue(formFields, "invitingOrganization_addressAndName", oaInfo); // 邀请公司/组织的名称及地址
  6679. string contactInfo = $"{oa?.Contact ?? ""} {oa?.Tel ?? ""} {oa?.EmailOrWeChat ?? ""}";
  6680. SetFieldValue(formFields, "invitingOrganization_contactInfo", contactInfo); // 公司/组织中联系人的姓氏、名字、地址、电话号码以及电子邮箱地址
  6681. SetFieldValue(formFields, "invitingOrganization_tel", oa?.Tel ?? ""); //电话号码(关于)公司/组织
  6682. }
  6683. #endregion
  6684. #region 费用承担
  6685. #region 支持方式
  6686. SetFieldValue(formFields, "costCoverage_applicant", "Off"); // 支持方式
  6687. SetFieldValue(formFields, "costCoverage_applicant_cash", "Off"); // 现金
  6688. SetFieldValue(formFields, "costCoverage_applicant_travellers_cheques", "Off"); // 旅行支票
  6689. SetFieldValue(formFields, "costCoverage_applicant_credit_card", "Off"); // 信用卡
  6690. SetFieldValue(formFields, "costCoverage_applicant_prepaid_accommodation", "Off");// 预付费住宿
  6691. SetFieldValue(formFields, "costCoverage_applicant_prepaid_transport", "Off"); // 预付费交通
  6692. SetFieldValue(formFields, "costCoverage_applicant_other", "Off"); // 其他
  6693. SetFieldValue(formFields, "costCoverage_applicant_other_specify", ""); // 其他(请具体说明)
  6694. #endregion
  6695. #region 由赞助方(主办方、公司、组织)提供
  6696. SetFieldValue(formFields, "costCoverage_host", "Off"); // 由赞助方(主办方、公司、组织)提供
  6697. SetFieldValue(formFields, "costCoverage_host_referred", "Off"); // 在第 30 或 31 栏中提及
  6698. SetFieldValue(formFields, "costCoverage_host_referred_specify", "");// 在第 30 或 31 栏中提及(请具体说明
  6699. SetFieldValue(formFields, "costCoverage_host_other", "Off"); // 其他
  6700. SetFieldValue(formFields, "costCoverage_host_other_specify", ""); // 其他(请具体说明
  6701. //支持方式
  6702. SetFieldValue(formFields, "costCoverage_host_cash", "Off"); // 现金
  6703. SetFieldValue(formFields, "costCoverage_host_accommodation", "Off"); // 提供住宿
  6704. SetFieldValue(formFields, "costCoverage_host_duringStay", "Off"); // 旅行期间的所有费用均由主办方承担
  6705. SetFieldValue(formFields, "costCoverage_host_prepaid_transport", "Off");// 预先支付的交通费用
  6706. SetFieldValue(formFields, "costCoverage_host_other", "Off"); // 其他
  6707. SetFieldValue(formFields, "costCoverage_host_other_specify", ""); // 其他(请具体说明
  6708. #endregion
  6709. #endregion
  6710. #region 欧盟家庭成员个人信息
  6711. SetFieldValue(formFields, "euFamilyMember_surname", ""); // 姓氏(家族名)
  6712. SetFieldValue(formFields, "euFamilyMember_firstname", ""); // 名字(名字)
  6713. SetFieldValue(formFields, "euFamilyMember_birthday", ""); // 出生日期 (日-月-年)
  6714. SetFieldValue(formFields, "euFamilyMember_nationality", "");// 国籍
  6715. SetFieldValue(formFields, "euFamilyMember_number", ""); // 旅行证件或身份证号码
  6716. #endregion
  6717. #region 欧盟家庭关系
  6718. SetFieldValue(formFields, "familyRelationship_spouse", "Off"); // 夫妻
  6719. SetFieldValue(formFields, "familyRelationship_child", "Off"); // 子女
  6720. SetFieldValue(formFields, "familyRelationship_grandchild", "Off"); // 孙子女
  6721. SetFieldValue(formFields, "familyRelationship_dependent", "Off"); // 有赡养关系的长辈
  6722. #endregion
  6723. // 申请人的家庭住址和电子邮箱地址
  6724. string applicantAddressAndEmail = $"{custInfo.Address} {custInfo.Email}";
  6725. SetFieldValue(formFields, "applicant_address_and_email", applicantAddressAndEmail);
  6726. // 申请人的电话
  6727. SetFieldValue(formFields, "applicant_tel", custInfo.Tel);
  6728. #region 在非当前国籍所属国家的居住情况 “默认空”
  6729. SetFieldValue(formFields, "uncurrent_count_no", "Yes"); // 否
  6730. SetFieldValue(formFields, "uncurrent_count_yes", "Off"); // 是
  6731. SetFieldValue(formFields, "uncurrent_country_residence", "");// 居留许可或同等证明
  6732. SetFieldValue(formFields, "uncurrent_country_no", ""); // No
  6733. SetFieldValue(formFields, "uncurrent_country_valid_until", "");// 有效期至
  6734. #endregion
  6735. SetFieldValue(formFields, "declaration_place", ""); // 地点
  6736. SetFieldValue(formFields, "declaration_signture", "");// 签名
  6737. var date_year = DateTime.Now.Year.ToString();
  6738. var date_month = DateTime.Now.Month.ToString();
  6739. var date_day = DateTime.Now.Day.ToString();
  6740. SetFieldValue(formFields, "place_and_date", DateTime.Now.ToString("yyyy-MM-dd")); // 申请日期
  6741. var applicant_name = custInfo.LastName + custInfo.FirstName;
  6742. SetFieldValue(formFields, "signture", applicant_name); // 申请人姓名
  6743. #endregion
  6744. filePaths.Add(outputPath);
  6745. }
  6746. catch (Exception ex)
  6747. {
  6748. return Ok(JsonView(false, $"生成PDF文件时出错:{ex.Message}"));
  6749. }
  6750. finally
  6751. {
  6752. // 按正确顺序关闭资源
  6753. stamper?.Close();
  6754. reader?.Close();
  6755. templateStream?.Close();
  6756. outputStream?.Close();
  6757. }
  6758. #endregion
  6759. }
  6760. break;
  6761. case 8: // 西班牙
  6762. visaTypeName = $"西班牙签证申请表";
  6763. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  6764. var spianSavePath = $"{fileServerPath}{visaTypeName}/";
  6765. if (!Directory.Exists(spianSavePath)) Directory.CreateDirectory(spianSavePath);
  6766. if (!System.IO.File.Exists(currTempPath))
  6767. {
  6768. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  6769. }
  6770. foreach (var custInfo in groupCustInfos)
  6771. {
  6772. EncryptionProcessor.DecryptProperties(custInfo);
  6773. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  6774. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  6775. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  6776. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  6777. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  6778. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  6779. string templateKey = $"{custInfo.Id}_{custInfo.LastName}{custInfo.FirstName}";
  6780. //var pdfData = fdfDatas.GetValueOrDefault(templateKey) ?? new Dictionary<string, string>();
  6781. var pdfData = new Dictionary<string, string>();
  6782. #region 生成文件
  6783. PdfReader reader = null;
  6784. FileStream templateStream = null;
  6785. FileStream outputStream = null;
  6786. PdfStamper stamper = null;
  6787. try
  6788. {
  6789. string outputPath = $"{spianSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  6790. //读取模板文件
  6791. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  6792. reader = new PdfReader(templateStream);
  6793. //创建输出文件
  6794. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  6795. stamper = new PdfStamper(reader, outputStream);
  6796. AcroFields formFields = stamper.AcroFields;
  6797. #region 设置文本值
  6798. SetFieldValue(formFields, "surname", pdfData.GetSafeString("surname")); // 姓 英文
  6799. SetFieldValue(formFields, "birth_surname", pdfData.GetSafeString("birth_surname")); // 出生时姓 英文
  6800. SetFieldValue(formFields, "firstname", pdfData.GetSafeString("firstname")); // 名 英文
  6801. SetFieldValue(formFields, "birthday", pdfData.GetSafeString("birthday")); // 出生日期
  6802. SetFieldValue(formFields, "birth_place", pdfData.GetSafeString("birth_place")); // 出生地区
  6803. SetFieldValue(formFields, "birth_country", pdfData.GetSafeString("birth_country")); // 出生国籍
  6804. SetFieldValue(formFields, "current_nationality", pdfData.GetSafeString("current_nationality")); // 现国籍
  6805. SetFieldValue(formFields, "birth_nationality", pdfData.GetSafeString("birth_nationality")); // 出生国籍
  6806. SetFieldValue(formFields, "other_nacionality", pdfData.GetSafeString("other_nacionality")); // 其他国籍
  6807. #region 设置性别
  6808. //清除性别
  6809. SetFieldValue(formFields, "sex_male", "Off"); // 性别 - 男
  6810. SetFieldValue(formFields, "sex_female", "Off"); // 性别 - 女
  6811. SetFieldValue(formFields, "sex_other", "Off"); // 性别 - 其他
  6812. //设置性别
  6813. var sex = pdfData.GetSafeString("sex");
  6814. if (sex.Equals("0")) // 男
  6815. {
  6816. SetFieldValue(formFields, "sex_male", "Yes"); // 性别 - 男
  6817. }
  6818. else if (sex.Equals("1")) // 女
  6819. {
  6820. SetFieldValue(formFields, "sex_female", "Yes"); // 性别 - 女
  6821. }
  6822. else
  6823. {
  6824. SetFieldValue(formFields, "sex_other", "Yes"); // 性别 - 其他
  6825. }
  6826. #endregion
  6827. #region 婚姻状态
  6828. //清除婚姻状况
  6829. SetFieldValue(formFields, "marital_single", "Off"); // 婚姻状况 - 未婚
  6830. SetFieldValue(formFields, "marital_married", "Off"); // 婚姻状况 - 已婚
  6831. SetFieldValue(formFields, "marital_registered_union", "Off");// 婚姻状况 - 注册伴侣关系
  6832. SetFieldValue(formFields, "marital_separated", "Off"); // 婚姻状况 - 分居
  6833. SetFieldValue(formFields, "marital_divorced", "Off"); // 婚姻状况 - 离异
  6834. SetFieldValue(formFields, "marital_widower", "Off"); // 婚姻状况 - 丧偶
  6835. SetFieldValue(formFields, "marital_other", "Off"); // 婚姻状况 - 其他
  6836. SetFieldValue(formFields, "marital_other_specify", ""); // 婚姻状况 - 其他(请具体说明)
  6837. var maritalStatus = pdfData.GetSafeString("marital_status");
  6838. //设置婚姻状况
  6839. switch (maritalStatus)
  6840. {
  6841. case "1": // 未婚
  6842. SetFieldValue(formFields, "marital_single", "Yes");
  6843. break;
  6844. case "2": // 已婚
  6845. SetFieldValue(formFields, "marital_married", "Yes");
  6846. break;
  6847. case "3": // 离婚/离异
  6848. SetFieldValue(formFields, "marital_divorced", "Yes");
  6849. break;
  6850. case "4": // 分居
  6851. SetFieldValue(formFields, "marital_separated", "Yes");
  6852. break;
  6853. case "5": // 丧偶
  6854. SetFieldValue(formFields, "marital_widower", "Yes");
  6855. break;
  6856. case "6": // 其他
  6857. SetFieldValue(formFields, "marital_other", "Yes");
  6858. break;
  6859. }
  6860. #endregion
  6861. // 父母的监护权(针对未成年人)/法定监护人(姓氏、名字、地址(若与申请人的地址不同)、电话号码、电子邮箱地址以及国籍)
  6862. SetFieldValue(formFields, "legal_guardian_info", pdfData.GetSafeString("legal_guardian_info"));
  6863. //(如适用)国民身份号码
  6864. SetFieldValue(formFields, "national_identity_number", pdfData.GetSafeString("national_identity_number"));
  6865. #region 护照信息
  6866. //清除值
  6867. SetFieldValue(formFields, "passport_orfinary", "Off"); // 旅行证件类型 - 普通护照
  6868. SetFieldValue(formFields, "passport_diplomatic", "Off"); // 旅行证件类型 - 外交护照
  6869. SetFieldValue(formFields, "passport_service", "Off"); // 旅行证件类型 - 公务护照
  6870. SetFieldValue(formFields, "passport_official", "Off"); // 旅行证件类型 - 因公护照
  6871. SetFieldValue(formFields, "passport_other", "Off"); // 旅行证件类型 - 特别护照
  6872. SetFieldValue(formFields, "passport_other_specify", ""); // 其他旅行证件(请注明)
  6873. #region 设置 护照信息
  6874. string visaName = pdfData.GetSafeString("passport_type_name");
  6875. if (visaName.contains("普通")) SetFieldValue(formFields, "passport_orfinary", "Yes"); // 旅行证件类型 - 普通护照
  6876. else if (visaName.contains("外交")) SetFieldValue(formFields, "passport_diplomatic", "Yes"); // 旅行证件类型 - 外交护照
  6877. else if (visaName.contains("公务")) SetFieldValue(formFields, "passport_service", "Yes"); // 旅行证件类型 - 公务护照
  6878. else if (visaName.contains("因公")) SetFieldValue(formFields, "passport_official", "Yes"); // 旅行证件类型 - 因公护照
  6879. else // 旅行证件类型 - 特别护照
  6880. {
  6881. SetFieldValue(formFields, "passport_other", "Yes");
  6882. SetFieldValue(formFields, "passport_other_specify", "");
  6883. }
  6884. SetFieldValue(formFields, "travel_number", pdfData.GetSafeString("travel_number")); // 签证 编号
  6885. SetFieldValue(formFields, "travel_issues_country", pdfData.GetSafeString("travel_issues_country"));// 签发 国
  6886. SetFieldValue(formFields, "travel_issue_date", pdfData.GetSafeString("travel_issue_date")); // 签发日期
  6887. SetFieldValue(formFields, "travel_valid_until", pdfData.GetSafeString("travel_valid_until")); // 有效期至
  6888. #endregion
  6889. #endregion
  6890. #region 欧盟家庭成员个人信息
  6891. SetFieldValue(formFields, "ue_family_info", pdfData.GetSafeString("ue_family_info")); // 个人信息
  6892. SetFieldValue(formFields, "ue_family_surname", pdfData.GetSafeString("ue_family_surname")); // 姓氏(家族名)
  6893. SetFieldValue(formFields, "ue_family_firstname", pdfData.GetSafeString("ue_family_firstname")); // 名字(名字)
  6894. SetFieldValue(formFields, "ue_family_birthday", pdfData.GetSafeString("ue_family_birthday")); // 出生日期 (日-月-年)
  6895. SetFieldValue(formFields, "ue_family_nationality", pdfData.GetSafeString("ue_family_nationality")); // 国籍
  6896. SetFieldValue(formFields, "ue_family_travel_number", pdfData.GetSafeString("ue_family_travel_number"));// 旅行证件或身份证号码
  6897. #endregion
  6898. #region 欧盟家庭关系
  6899. SetFieldValue(formFields, "eu_family_relationship_spouse", "Off"); // 夫妻
  6900. SetFieldValue(formFields, "eu_family_relationship_child", "Off"); // 子女
  6901. SetFieldValue(formFields, "eu_family_relationship_grandchild", "Off"); // 孙子女
  6902. SetFieldValue(formFields, "eu_family_relationship_dependent", "Off"); // 受养人
  6903. SetFieldValue(formFields, "eu_family_relationship_registered_partnership", "Off"); // 注册伴侣
  6904. SetFieldValue(formFields, "eu_family_relationship_other", pdfData.GetSafeString("eu_family_relationship_other")); // 其他
  6905. SetFieldValue(formFields, "eu_family_relationship_other_specify", pdfData.GetSafeString("eu_family_relationship_other_specify")); // 其他
  6906. #endregion
  6907. // 申请人的家庭住址和电子邮箱地址
  6908. SetFieldValue(formFields, "applicant_address_and_email", pdfData.GetSafeString("applicant_address_and_email"));
  6909. // 申请人的电话
  6910. SetFieldValue(formFields, "applicant_tel", pdfData.GetSafeString("applicant_tel"));
  6911. #region 是否在非国籍国居住 默认否
  6912. SetFieldValue(formFields, "unresidente_no", "Yes"); // 否
  6913. SetFieldValue(formFields, "unresidente_yes", "Off"); // 是
  6914. SetFieldValue(formFields, "unresidente_equivalen", ""); // 居住许可证
  6915. SetFieldValue(formFields, "unresidente_number", ""); // 编号
  6916. SetFieldValue(formFields, "unresidente_vaild", ""); // 有效期限
  6917. #endregion
  6918. #region 职业
  6919. // 当前职业
  6920. SetFieldValue(formFields, "occupation", pdfData.GetSafeString("fileName"));
  6921. //雇主及雇主的地址和电话号码。
  6922. SetFieldValue(formFields, "employer_info", pdfData.GetSafeString("employer_info"));
  6923. #endregion
  6924. #region 此次行程的目的
  6925. //清除值
  6926. SetFieldValue(formFields, "purpose_tourism", "Off"); // 旅游
  6927. SetFieldValue(formFields, "purpose_business", "Off"); // 商务
  6928. SetFieldValue(formFields, "purpose_visiting_family_friends", "Off");// 庆祝亲友团聚
  6929. SetFieldValue(formFields, "purpose_cultural", "Off"); // 文化交流
  6930. SetFieldValue(formFields, "purpose_sports", "Off"); // 体育
  6931. SetFieldValue(formFields, "purpose_official", "Off"); // 官方访问
  6932. SetFieldValue(formFields, "purpose_medical_reasons", "Off"); // 医疗
  6933. SetFieldValue(formFields, "purpose_study", "Off"); // 学习
  6934. SetFieldValue(formFields, "purpose_airport_transit", "Off"); // 机场过境
  6935. SetFieldValue(formFields, "purpose_other", "Off"); // 其他
  6936. SetFieldValue(formFields, "purpose_other_specify", ""); // 其他 - 备注
  6937. var visit_purpose = pdfData.GetSafeString("purpose");
  6938. var visit_purpose_remark = pdfData.GetSafeString("purpose_other_specify");
  6939. if (!string.IsNullOrEmpty(visit_purpose))
  6940. {
  6941. if (visit_purpose.contains("tourism"))
  6942. {
  6943. SetFieldValue(formFields, "purpose_tourism", "Yes"); // 旅游
  6944. }
  6945. else if (visit_purpose.contains("business"))
  6946. {
  6947. SetFieldValue(formFields, "purpose_business", "Yes"); // 商务
  6948. }
  6949. else if (visit_purpose.contains("visiting_family_friends"))
  6950. {
  6951. SetFieldValue(formFields, "purpose_visiting_family_friends", "Yes");// 庆祝亲友团聚
  6952. }
  6953. else if (visit_purpose.contains("cultural") || visit_purpose.contains("tourism"))
  6954. {
  6955. SetFieldValue(formFields, "purpose_cultural", "Yes"); // 文化交流
  6956. }
  6957. else if (visit_purpose.contains("sports"))
  6958. {
  6959. SetFieldValue(formFields, "purpose_sports", "Yes"); // 体育
  6960. }
  6961. else if (visit_purpose.contains("official"))
  6962. {
  6963. SetFieldValue(formFields, "purpose_official", "Yes"); // 官方访问
  6964. }
  6965. else if (visit_purpose.contains("medical_reasons") || visit_purpose.contains("medical"))
  6966. {
  6967. SetFieldValue(formFields, "purpose_medical_reasons", "Yes"); // 医疗原因
  6968. }
  6969. else if (visit_purpose.contains("study"))
  6970. {
  6971. SetFieldValue(formFields, "purpose_study", "Yes"); // 学习
  6972. }
  6973. else if (visit_purpose.contains("airport_transit") || visit_purpose.contains("transit"))
  6974. {
  6975. SetFieldValue(formFields, "purpose_airport_transit", "Yes"); // 机场过境
  6976. }
  6977. else
  6978. {
  6979. SetFieldValue(formFields, "purpose_other", "Yes"); // 其他
  6980. SetFieldValue(formFields, "purpose_other_specify", visit_purpose_remark);// 其他 - 备注
  6981. }
  6982. }
  6983. #endregion
  6984. #region 目的国相关信息
  6985. // 关于停留目的的补充说明
  6986. SetFieldValue(formFields, "stay_info", pdfData.GetSafeString("stay_info"));
  6987. SetFieldValue(formFields, "member_destination", pdfData.GetSafeString("member_destination")); // 主要目的地成员国(如适用,还包括目的地的其他成员国)
  6988. SetFieldValue(formFields, "member_first_entry", pdfData.GetSafeString("member_first_entry")); // 首入申根国标签
  6989. // 申请入境次数
  6990. string request_entry = pdfData.GetSafeString("member_first_entry");
  6991. switch (request_entry)
  6992. {
  6993. case "1":
  6994. SetFieldValue(formFields, "request_entry_one", "Yes"); // 一次入境
  6995. break;
  6996. case "2":
  6997. SetFieldValue(formFields, "request_entry_two", "Yes"); // 两次入境
  6998. break;
  6999. case "3":
  7000. SetFieldValue(formFields, "request_entry_multiple", "Yes"); // 多次入境
  7001. break;
  7002. }
  7003. SetFieldValue(formFields, "schengen_first_area_arrival", pdfData.GetSafeString("schengen_first_area_arrival")); // 首次抵达日期
  7004. SetFieldValue(formFields, "schengen_first_area_departure", pdfData.GetSafeString("schengen_first_area_departure")); // 首次抵达日期
  7005. #endregion
  7006. #region 此前录过指纹
  7007. var fingerprints = pdfData.GetSafeString("schengen_fingerprints_status");
  7008. switch (fingerprints)
  7009. {
  7010. // 是
  7011. case "1":
  7012. SetFieldValue(formFields, "schengen_fingerprints_yes", "Yes"); // 是
  7013. SetFieldValue(formFields, "schengen_fingerprints_date", ""); // 如有,请写明日期
  7014. SetFieldValue(formFields, "schengen_fingerprints_visa_no", "");// 编号
  7015. break;
  7016. // 否
  7017. case "2":
  7018. SetFieldValue(formFields, "schengen_fingerprints_no", "Yes"); // 否
  7019. break;
  7020. }
  7021. #endregion
  7022. #region 最终目的地入境许可
  7023. SetFieldValue(formFields, "entry_permit_issued", pdfData.GetSafeString("entry_permit_issued")); // 发布者
  7024. SetFieldValue(formFields, "entry_permit_valid", pdfData.GetSafeString("entry_permit_valid")); // 有效期限 起
  7025. SetFieldValue(formFields, "entry_permit_until", pdfData.GetSafeString("entry_permit_until")); // 有效期限 止
  7026. #endregion
  7027. #region 邀请人/酒店信息
  7028. SetFieldValue(formFields, "schengen_inviting_name", pdfData.GetSafeString("schengen_inviting_name")); // 招待方的酒店、邀请人 名称
  7029. SetFieldValue(formFields, "schengen_inviting_hotel_address_email", pdfData.GetSafeString("schengen_inviting_hotel_address_email")); // 酒店/临时住宿场所的地址和电子邮箱地址
  7030. SetFieldValue(formFields, "schengen_inviting_hotel_tel", pdfData.GetSafeString("schengen_inviting_hotel_tel")); // 电话号码
  7031. #endregion
  7032. #region 邀请公司/组织信息
  7033. SetFieldValue(formFields, "inviting_name_address", pdfData.GetSafeString("inviting_name_address")); // 邀请公司/组织的名称及地址
  7034. SetFieldValue(formFields, "inviting_info", pdfData.GetSafeString("inviting_info")); // 公司/组织中联系人的姓氏、名字、地址、电话号码以及电子邮箱地址
  7035. SetFieldValue(formFields, "inviting_tel", pdfData.GetSafeString("inviting_tel")); // 电话号码(关于)公司/组织
  7036. #endregion
  7037. #region 费用承担
  7038. #region 支持方式
  7039. SetFieldValue(formFields, "cost_covered_herself", "Off"); // 支持方式
  7040. SetFieldValue(formFields, "cost_covered_herself_cash", "Off"); // 现金
  7041. SetFieldValue(formFields, "cost_covered_herself_cheques", "Off"); // 旅行支票
  7042. SetFieldValue(formFields, "cost_covered_herself_credit", "Off"); // 信用卡
  7043. SetFieldValue(formFields, "cost_covered_herself_accomodation", "Off"); // 预付费住宿
  7044. SetFieldValue(formFields, "cost_covered_herself_transport", "Off"); // 预付费交通
  7045. SetFieldValue(formFields, "cost_covered_herself_other", "Off"); // 其他
  7046. SetFieldValue(formFields, "cost_covered_herself_other_specift", ""); // 其他(请具体说明)
  7047. #endregion
  7048. #region 由赞助方(主办方、公司、组织)提供
  7049. SetFieldValue(formFields, "cost_covered_sponsor", "Off"); // 由赞助方(主办方、公司、组织)提供
  7050. SetFieldValue(formFields, "cost_covered_sponsor_referred", "Off"); // 在第 30 或 31 栏中提及
  7051. SetFieldValue(formFields, "cost_covered_sponsor_other", "Yes"); // 其他
  7052. SetFieldValue(formFields, "cost_covered_sponsor_other_specify", pdfData.GetSafeString("cost_covered_sponsor_other_specify")); // 其他(请具体说明
  7053. //支持方式
  7054. SetFieldValue(formFields, "cost_covered_sponsor_cash", "Off"); // 现金
  7055. SetFieldValue(formFields, "cost_covered_sponsor_accomodation", "Off"); // 提供住宿
  7056. SetFieldValue(formFields, "cost_covered_sponsor_during_stay", "Off"); // 旅行期间的所有费用均由主办方承担
  7057. SetFieldValue(formFields, "cost_covered_sponsor_transport", "Off"); // 预先支付的交通费用
  7058. SetFieldValue(formFields, "cost_covered_sponsor_other", "Off"); // 其他
  7059. SetFieldValue(formFields, "cost_covered_sponsor_other_specify", ""); // 其他(请具体说明
  7060. #endregion
  7061. #endregion
  7062. #endregion
  7063. filePaths.Add(outputPath);
  7064. }
  7065. catch (Exception ex)
  7066. {
  7067. return Ok(JsonView(false, $"生成PDF文件时出错:{ex.Message}"));
  7068. }
  7069. finally
  7070. {
  7071. // 按正确顺序关闭资源
  7072. stamper?.Close();
  7073. reader?.Close();
  7074. templateStream?.Close();
  7075. outputStream?.Close();
  7076. }
  7077. #endregion
  7078. }
  7079. break;
  7080. default:
  7081. return Ok(JsonView(false, "正在开发中,请等待。。。"));
  7082. }
  7083. // 压缩文件
  7084. var zipFilePathName = $"{groupInfo.TeamName}({visaTypeName}).zip";
  7085. var zipFilePath = $"{fileServerPath}{zipFilePathName}";
  7086. // 关键修复:先获取压缩文件的上级目录,检查并创建(如果不存在)
  7087. string zipDirectory = Path.GetDirectoryName(zipFilePath);
  7088. if (!Directory.Exists(zipDirectory))
  7089. {
  7090. // CreateDirectory会自动创建所有不存在的上级目录,无需手动逐层创建
  7091. Directory.CreateDirectory(zipDirectory);
  7092. }
  7093. using (var zipFileStream = new FileStream(zipFilePath, FileMode.Create))
  7094. {
  7095. using (var zipArchive = new ZipArchive(zipFileStream, ZipArchiveMode.Create))
  7096. {
  7097. foreach (string filePath in filePaths)
  7098. {
  7099. // 增加空值/空字符串校验,提升代码健壮性
  7100. if (!string.IsNullOrEmpty(filePath) && System.IO.File.Exists(filePath))
  7101. {
  7102. // 获取文件名
  7103. string fileName = Path.GetFileName(filePath);
  7104. // 将文件添加到ZIP归档中
  7105. zipArchive.CreateEntryFromFile(filePath, fileName);
  7106. }
  7107. }
  7108. }
  7109. }
  7110. url = $"{serverPath}{zipFilePathName}";
  7111. if (!string.IsNullOrEmpty(url))
  7112. {
  7113. return Ok(JsonView(true, "操作成功", url));
  7114. }
  7115. return Ok(JsonView(false, "操作失败!"));
  7116. }
  7117. /// <summary>
  7118. /// 团组&签证 New
  7119. /// 签证文申请表下载 批量
  7120. /// </summary>
  7121. /// <param name="groupId"></param>
  7122. /// <param name="fileTypeId"></param>
  7123. /// <param name="language">
  7124. /// 下载语言:1-中文,2-英文
  7125. /// </param>
  7126. /// <returns></returns>
  7127. [HttpGet]
  7128. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7129. public async Task<IActionResult> VisaFileDownload(int groupId, int fileTypeId, int language = 1)
  7130. {
  7131. if (!_visaTypeInit.TryGetValue(fileTypeId, out _))
  7132. {
  7133. return Ok(JsonView(false, "请选择正确的文件类型!"));
  7134. }
  7135. var visaBasicData = await GetVisaBasicData(groupId);
  7136. if (visaBasicData == null)
  7137. {
  7138. return Ok(JsonView(false, "基础数据信息为空!"));
  7139. }
  7140. if (visaBasicData.groupInfo == null)
  7141. {
  7142. return Ok(JsonView(false, "团组信息不存在!"));
  7143. }
  7144. if (visaBasicData.groupClients.Count < 1)
  7145. {
  7146. return Ok(JsonView(false, "该团组下暂无团组名单!"));
  7147. }
  7148. string group_unique_name = $"{visaBasicData.groupInfo.TeamName}";
  7149. //访问路径
  7150. var serverPath = $"http://132.232.92.186:24/Office/Word/VisaClientData/Downloads/{group_unique_name}/";
  7151. // 服务器存储文件位置
  7152. var fileServerPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Downloads/{group_unique_name}/";
  7153. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(fileServerPath);
  7154. var filePaths = new List<string>();
  7155. #region 多个下载
  7156. foreach (var custInfo in visaBasicData.groupCustInfos)
  7157. {
  7158. var groupCustInfos = new List<Crm_DeleClient>() { custInfo };
  7159. var idInfo = visaBasicData.certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  7160. var passportInfo = visaBasicData.certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  7161. var clinetInfo = visaBasicData.companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  7162. var currSchoolInfos = visaBasicData.schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  7163. var currFamilyInfos = visaBasicData.familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  7164. var currCompanyInfos = visaBasicData.companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  7165. var generatorFileReq = new GeneratorFileReq
  7166. {
  7167. groupId = groupId,
  7168. fileTypeId = fileTypeId,
  7169. dcIds = custInfo.Id,
  7170. fileServerPath = fileServerPath,
  7171. language = language,
  7172. dataBody = new DataBody
  7173. {
  7174. groupInfo = visaBasicData.groupInfo,
  7175. groupClients = visaBasicData.groupClients,
  7176. groupCustInfos = groupCustInfos,
  7177. familyInfos = visaBasicData.familyInfos,
  7178. certInfos = visaBasicData.certInfos,
  7179. companyInfos = visaBasicData.companyInfos,
  7180. schoolInfos = visaBasicData.schoolInfos
  7181. }
  7182. };
  7183. (bool resStatus, string saveUrl, string downloadUrl) = await GeneratorFileAsync(generatorFileReq);
  7184. if (resStatus)
  7185. {
  7186. filePaths.Add(saveUrl);
  7187. }
  7188. }
  7189. #endregion
  7190. // 压缩文件
  7191. var zipFilePathName = $"{visaBasicData.groupInfo.TeamName}({_visaTypeInit.GetValueOrDefault(fileTypeId)}签证申请表).zip";
  7192. var zipFilePath = $"{fileServerPath}{zipFilePathName}";
  7193. // 关键修复:先获取压缩文件的上级目录,检查并创建(如果不存在)
  7194. string zipDirectory = Path.GetDirectoryName(zipFilePath);
  7195. if (!Directory.Exists(zipDirectory))
  7196. {
  7197. // CreateDirectory会自动创建所有不存在的上级目录,无需手动逐层创建
  7198. Directory.CreateDirectory(zipDirectory);
  7199. }
  7200. using (var zipFileStream = new FileStream(zipFilePath, FileMode.Create))
  7201. {
  7202. using (var zipArchive = new ZipArchive(zipFileStream, ZipArchiveMode.Create))
  7203. {
  7204. foreach (string filePath in filePaths)
  7205. {
  7206. // 增加空值/空字符串校验,提升代码健壮性
  7207. if (!string.IsNullOrEmpty(filePath) && System.IO.File.Exists(filePath))
  7208. {
  7209. // 获取文件名
  7210. string fileName = Path.GetFileName(filePath);
  7211. // 将文件添加到ZIP归档中
  7212. zipArchive.CreateEntryFromFile(filePath, fileName);
  7213. }
  7214. }
  7215. }
  7216. }
  7217. url = $"{serverPath}{zipFilePathName}";
  7218. if (!string.IsNullOrEmpty(url))
  7219. {
  7220. return Ok(JsonView(true, "操作成功", url));
  7221. }
  7222. return Ok(JsonView(false, "操作失败!"));
  7223. }
  7224. /// <summary>
  7225. /// 团组&签证 New
  7226. /// 签证文申请表下载 单个文件生成后提供下载地址
  7227. /// </summary>
  7228. /// <param name="groupId"></param>
  7229. /// <param name="fileTypeId"></param>
  7230. /// <param name="dcId">客户资料Id(dcId)</param>
  7231. /// <param name="language">
  7232. /// 下载语言:1-中文,2-英文
  7233. /// </param>
  7234. /// <returns></returns>
  7235. [HttpGet]
  7236. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7237. public async Task<IActionResult> VisaFileDownloadSingle(int groupId, int fileTypeId, int dcId, int language = 1)
  7238. {
  7239. if (!_visaTypeInit.TryGetValue(fileTypeId, out _))
  7240. {
  7241. return Ok(JsonView(false, "请选择正确的文件类型!"));
  7242. }
  7243. var visaBasicData = await GetVisaBasicData(groupId);
  7244. if (visaBasicData == null)
  7245. {
  7246. return Ok(JsonView(false, "基础数据信息为空!"));
  7247. }
  7248. if (visaBasicData.groupInfo == null)
  7249. {
  7250. return Ok(JsonView(false, "团组信息不存在!"));
  7251. }
  7252. if (visaBasicData.groupClients.Count < 1)
  7253. {
  7254. return Ok(JsonView(false, "该团组下暂无团组名单!"));
  7255. }
  7256. string group_unique_name = $"{visaBasicData.groupInfo.TeamName}";
  7257. //访问路径
  7258. var serverPath = $"http://132.232.92.186:24/Office/Word/VisaClientData/Downloads/{group_unique_name}/";
  7259. // 服务器存储文件位置
  7260. var fileServerPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Downloads/{group_unique_name}/";
  7261. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(fileServerPath);
  7262. var generatorFileReq = new GeneratorFileReq
  7263. {
  7264. groupId = groupId,
  7265. fileTypeId = fileTypeId,
  7266. dcIds = dcId,
  7267. fileServerPath = fileServerPath,
  7268. language = language,
  7269. dataBody = new DataBody
  7270. {
  7271. groupInfo = visaBasicData.groupInfo,
  7272. groupClients = visaBasicData.groupClients.Where(x => x.ClientId == dcId).ToList(),
  7273. groupCustInfos = visaBasicData.groupCustInfos.Where(x => x.Id == dcId).ToList(),
  7274. familyInfos = visaBasicData.familyInfos.Where(x => x.DcId == dcId).ToList(),
  7275. certInfos = visaBasicData.certInfos.Where(x => x.DcId == dcId).ToList(),
  7276. companyInfos = visaBasicData.companyInfos.Where(x => x.DcId == dcId).ToList(),
  7277. schoolInfos = visaBasicData.schoolInfos.Where(x => x.DcId == dcId).ToList()
  7278. }
  7279. };
  7280. (bool resStatus, string msg, string downloadUrl) = await GeneratorFileAsync(generatorFileReq);
  7281. if (resStatus)
  7282. {
  7283. return Ok(JsonView(true, "操作成功", downloadUrl));
  7284. }
  7285. return Ok(JsonView(false, msg));
  7286. }
  7287. /// <summary>
  7288. /// 团组&签证 New
  7289. /// 签证文申请表下载 派遣函
  7290. /// </summary>
  7291. /// <param name="groupId"></param>
  7292. /// <param name="dcId">客户资料Id(dcId)</param>
  7293. /// <returns></returns>
  7294. [HttpGet]
  7295. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7296. public async Task<IActionResult> VisaFileDispatchDownload(int groupId, int dcId)
  7297. {
  7298. var visaBasicData = await GetVisaBasicData(groupId);
  7299. if (visaBasicData == null)
  7300. {
  7301. return Ok(JsonView(false, "基础数据信息为空!"));
  7302. }
  7303. if (visaBasicData.groupInfo == null)
  7304. {
  7305. return Ok(JsonView(false, "团组信息不存在!"));
  7306. }
  7307. if (visaBasicData.groupClients.Count < 1)
  7308. {
  7309. return Ok(JsonView(false, "该团组下暂无团组名单!"));
  7310. }
  7311. (bool resStatus, string msg, string downloadUrl) = await GeneratorDispatchAsync(new DataBody
  7312. {
  7313. groupInfo = visaBasicData.groupInfo,
  7314. groupClients = visaBasicData.groupClients.Where(x => x.ClientId == dcId).ToList(),
  7315. groupCustInfos = visaBasicData.groupCustInfos.Where(x => x.Id == dcId).ToList(),
  7316. familyInfos = visaBasicData.familyInfos.Where(x => x.DcId == dcId).ToList(),
  7317. certInfos = visaBasicData.certInfos.Where(x => x.DcId == dcId).ToList(),
  7318. companyInfos = visaBasicData.companyInfos.Where(x => x.DcId == dcId).ToList(),
  7319. schoolInfos = visaBasicData.schoolInfos.Where(x => x.DcId == dcId).ToList()
  7320. });
  7321. if (resStatus)
  7322. {
  7323. return Ok(JsonView(true, "操作成功", downloadUrl));
  7324. }
  7325. return Ok(JsonView(false, msg));
  7326. }
  7327. /// <summary>
  7328. /// 获取签证基础数据源
  7329. /// </summary>
  7330. /// <param name="groupId"></param>
  7331. /// <returns></returns>
  7332. private async Task<DataBody> GetVisaBasicData(int groupId)
  7333. {
  7334. var data = new DataBody();
  7335. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0 && x.Id == groupId).First();
  7336. if (groupInfo == null) return data;
  7337. // 基础数据
  7338. // 团组客户名单
  7339. var groupClients = await _sqlSugar.Queryable<Grp_TourClientList>()
  7340. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  7341. .ToListAsync();
  7342. if (groupClients.Count < 1) return data;
  7343. var groupClientIds = groupClients.Select(x => x.ClientId).ToList();
  7344. // 团组客户详细信息
  7345. var groupCustInfos = _sqlSugar.Queryable<Crm_DeleClient>().Where(x => x.IsDel == 0 && groupClientIds.Contains(x.Id)).ToList();
  7346. // 解密
  7347. foreach (var custInfo in groupCustInfos)
  7348. {
  7349. EncryptionProcessor.DecryptProperties(custInfo);
  7350. }
  7351. // 家庭成员资料
  7352. var familyInfos = _sqlSugar.Queryable<Crm_VisaCustomerFamily>().Where(x => x.IsDel == 0 && groupClientIds.Contains(x.DcId)).ToList();
  7353. // 公司资料
  7354. var companyInfo‌‌s = _sqlSugar.Queryable<Crm_VisaCustomerCompany>().Where(x => x.IsDel == 0 && groupClientIds.Contains(x.DcId)).ToList();
  7355. // 学校资料
  7356. var schoolInfos = _sqlSugar.Queryable<Crm_VisaCustomerSchool>().Where(x => x.IsDel == 0 && groupClientIds.Contains(x.DcId)).ToList();
  7357. /* 证件类型
  7358. *
  7359. * 773 身份证
  7360. * 774 护照
  7361. * 775 学生证
  7362. * 776 军人证
  7363. * 777 回乡证
  7364. * 778 台胞证
  7365. * 779 港澳通行证
  7366. * 780 国际海员证
  7367. * 781 外国人永久居留证
  7368. * 782 旅行证
  7369. * 783 台湾通行证
  7370. * 784 港澳台居住证
  7371. * 785 其他
  7372. */
  7373. // 证件资料
  7374. var certInfos = _sqlSugar.Queryable<Crm_CustomerCert>().Where(x => x.IsDel == 0 && groupClientIds.Contains(x.DcId)).ToList();
  7375. return new DataBody
  7376. {
  7377. groupInfo = groupInfo,
  7378. groupClients = groupClients,
  7379. groupCustInfos = groupCustInfos,
  7380. familyInfos = familyInfos,
  7381. certInfos = certInfos,
  7382. companyInfos = companyInfo‌‌s,
  7383. schoolInfos = schoolInfos
  7384. };
  7385. }
  7386. /// <summary>
  7387. /// 文件生成
  7388. /// </summary>
  7389. /// <param name="req"></param>
  7390. /// <returns></returns>
  7391. private async Task<(bool, string, string)> GeneratorFileAsync(GeneratorFileReq req)
  7392. {
  7393. string saveUrl = string.Empty;
  7394. string downloadUrl = string.Empty;
  7395. //模板存储位置
  7396. string tempPath = req.tempPath;
  7397. string fileServerPath = req.fileServerPath;
  7398. int fileTypeId = req.fileTypeId;
  7399. int groupId = req.groupId;
  7400. int language = req.language;
  7401. // 数据源
  7402. var custInfo = req.dataBody.groupCustInfos.FirstOrDefault();
  7403. var visaTypeName = string.Empty;
  7404. var currTempPath = string.Empty;
  7405. var pdfData = await FillPdfTemplateAsync(req.dataBody, language);
  7406. switch (fileTypeId)
  7407. {
  7408. case 1: // 美国
  7409. visaTypeName = $"美国签证申请表";
  7410. currTempPath = $"{tempPath}{visaTypeName}.doc";
  7411. var usaSavePath = $"{fileServerPath}{visaTypeName}/";
  7412. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(usaSavePath);
  7413. break;
  7414. case 2: // 日本
  7415. visaTypeName = $"新办日本申请表";
  7416. currTempPath = $"{tempPath}/{visaTypeName}.pdf";
  7417. var jpnSavePath = $"{fileServerPath}/{visaTypeName}/";
  7418. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(jpnSavePath);
  7419. break;
  7420. case 3: // 韩国
  7421. visaTypeName = $"韩国签证申请表";
  7422. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  7423. var korSavePath = $"{fileServerPath}{visaTypeName}/";
  7424. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(korSavePath);
  7425. break;
  7426. case 4: // 瑞典
  7427. visaTypeName = $"瑞典签证申请表";
  7428. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  7429. var swedenSavePath = $"{fileServerPath}{visaTypeName}/";
  7430. if (!Directory.Exists(swedenSavePath)) Directory.CreateDirectory(swedenSavePath);
  7431. break;
  7432. case 5: // 波兰
  7433. visaTypeName = $"波兰签证申请表";
  7434. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  7435. var polandSavePath = $"{fileServerPath}{visaTypeName}/";
  7436. if (!Directory.Exists(polandSavePath)) Directory.CreateDirectory(polandSavePath);
  7437. break;
  7438. case 6: // 加拿大
  7439. visaTypeName = $"加拿大签证申请表";
  7440. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  7441. var canadaSavePath = $"{fileServerPath}{visaTypeName}/";
  7442. if (!Directory.Exists(canadaSavePath)) Directory.CreateDirectory(canadaSavePath);
  7443. break;
  7444. case 7: // 克罗地亚
  7445. visaTypeName = $"克罗地亚签证申请表";
  7446. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  7447. var croatiaSavePath = $"{fileServerPath}{visaTypeName}/";
  7448. if (!Directory.Exists(croatiaSavePath)) Directory.CreateDirectory(croatiaSavePath);
  7449. if (!System.IO.File.Exists(currTempPath))
  7450. {
  7451. return (false, $"{currTempPath}模板不存在!", string.Empty);
  7452. }
  7453. #region 生成文件
  7454. PdfReader croatia_reader = null;
  7455. FileStream croatia_templateStream = null;
  7456. FileStream croatia_outputStream = null;
  7457. PdfStamper croatia_stamper = null;
  7458. try
  7459. {
  7460. string outputPath = $"{croatiaSavePath}{custInfo.LastName}{custInfo.FirstName}_{visaTypeName}.pdf";
  7461. // 读取模板文件
  7462. croatia_templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  7463. croatia_reader = new PdfReader(croatia_templateStream);
  7464. // 创建输出文件
  7465. croatia_outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  7466. croatia_stamper = new PdfStamper(croatia_reader, croatia_outputStream);
  7467. AcroFields formFields = croatia_stamper.AcroFields;
  7468. #region 设置文本值
  7469. SetFieldValue(formFields, "surname", pdfData.GetSafeString("surname")); // 姓
  7470. SetFieldValue(formFields, "surname_birth", pdfData.GetSafeString("birth_surname")); // 出生时姓
  7471. SetFieldValue(formFields, "firstname", pdfData.GetSafeString("firstname")); // 名
  7472. SetFieldValue(formFields, "birthday", pdfData.GetSafeString("birthday")); // 出生日期(日-月-年)
  7473. SetFieldValue(formFields, "birth_place", pdfData.GetSafeString("birth_place")); // 出生地区
  7474. SetFieldValue(formFields, "birth_country", pdfData.GetSafeString("birth_country")); // 出生国籍
  7475. SetFieldValue(formFields, "current_nationality", pdfData.GetSafeString("current_nationality")); // 现国籍
  7476. #region 设置性别
  7477. //清除性别
  7478. SetFieldValue(formFields, "sex_male", "Off"); // 性别 - 男
  7479. SetFieldValue(formFields, "sex_female", "Off"); // 性别 - 女
  7480. string sex = pdfData.GetSafeString("sex");
  7481. //设置性别
  7482. if (sex == "0") // 男
  7483. {
  7484. SetFieldValue(formFields, "sex_male", "Yes"); // 性别 - 男
  7485. }
  7486. else if (sex == "1") // 女
  7487. {
  7488. SetFieldValue(formFields, "sex_female", "Yes"); // 性别 - 女
  7489. }
  7490. #endregion
  7491. #region 婚姻状态
  7492. // 清除婚姻状况
  7493. SetFieldValue(formFields, "marital_single", "Off"); // 婚姻状况 - 未婚
  7494. SetFieldValue(formFields, "marital_married", "Off"); // 婚姻状况 - 已婚
  7495. SetFieldValue(formFields, "marital_separated", "Off"); // 婚姻状况 - 分居
  7496. SetFieldValue(formFields, "marital_dicorced", "Off"); // 婚姻状况 - 离异
  7497. SetFieldValue(formFields, "marital_widower", "Off"); // 婚姻状况 - 丧偶
  7498. SetFieldValue(formFields, "marital_other", "Off"); // 婚姻状况 - 其他
  7499. SetFieldValue(formFields, "marital_other_specify", ""); // 婚姻状况 - 其他(请具体说明)
  7500. string marriage = pdfData.GetSafeString("marriage");
  7501. // 设置婚姻状况
  7502. switch (marriage)
  7503. {
  7504. case "0": // 未设置
  7505. SetFieldValue(formFields, "marital_single", "Yes");
  7506. break;
  7507. case "1": // 未婚
  7508. SetFieldValue(formFields, "marital_single", "Yes");
  7509. break;
  7510. case "2": // 已婚
  7511. SetFieldValue(formFields, "marital_married", "Yes");
  7512. break;
  7513. case "3": // 离婚/离异
  7514. SetFieldValue(formFields, "marital_dicorced", "Yes");
  7515. break;
  7516. case "4": // 丧偶
  7517. break;
  7518. }
  7519. #endregion
  7520. // 父母的监护权(针对未成年人)/法定监护人(姓氏、名字、地址(若与申请人的地址不同)、电话号码、电子邮箱地址以及国籍)
  7521. SetFieldValue(formFields, "legalGuardian", pdfData.GetSafeString("legal_guardian_info"));
  7522. //(如适用)国民身份号码
  7523. SetFieldValue(formFields, "nationalIdNumber", pdfData.GetSafeString("national_identity_number"));
  7524. #region 护照信息
  7525. //清除值
  7526. SetFieldValue(formFields, "travel_ordinary_passport", "Off"); // 旅行证件类型 - 普通护照
  7527. SetFieldValue(formFields, "travel_diplomatic_passport", "Off");// 旅行证件类型 - 外交护照
  7528. SetFieldValue(formFields, "travel_service_passport", "Off"); // 旅行证件类型 - 服务护照
  7529. SetFieldValue(formFields, "travel_special_passport", "Off"); // 旅行证件类型 - 公务护照
  7530. SetFieldValue(formFields, "travel_other", "Off"); // 旅行证件类型 - 特别护照
  7531. SetFieldValue(formFields, "travel_other_specify", ""); // 其他旅行证件(请注明)
  7532. //设置值
  7533. string visaName = pdfData.GetSafeString("passport_type_name");
  7534. if (visaName.contains("普通")) SetFieldValue(formFields, "travel_ordinary_passport", "Yes"); // 旅行证件类型 - 普通护照
  7535. else if (visaName.contains("外交")) SetFieldValue(formFields, "travel_diplomatic_passport", "Yes"); // 旅行证件类型 - 外交护照
  7536. else if (visaName.contains("服务")) SetFieldValue(formFields, "travel_service_passport", "Yes"); // 旅行证件类型 - 服务护照
  7537. else if (visaName.contains("公务")) SetFieldValue(formFields, "travel_type_offical_passport", "Yes");// 旅行证件类型 - 公务护照
  7538. else // 旅行证件类型 - 特别护照
  7539. {
  7540. SetFieldValue(formFields, "travel_other", "Yes");
  7541. SetFieldValue(formFields, "travel_other_specify", "");
  7542. }
  7543. #region 护照信息
  7544. SetFieldValue(formFields, "travel_number", pdfData.GetSafeString("travel_number")); // 签证 编号
  7545. SetFieldValue(formFields, "travel_issued", pdfData.GetSafeString("travel_issues_country")); // 签发 国
  7546. SetFieldValue(formFields, "travle_issueDate", pdfData.GetSafeString("travel_issue_date")); // 签发日期
  7547. SetFieldValue(formFields, "travel_expiryDate", pdfData.GetSafeString("travel_valid_until")); // 有效期至
  7548. #endregion
  7549. #endregion
  7550. #region 是否在非国籍国居住
  7551. SetFieldValue(formFields, "residesOutsideNationality_no", "Yes"); // 否
  7552. SetFieldValue(formFields, "residesOutsideNationality_yes", "Off"); // 是
  7553. SetFieldValue(formFields, "residesOutsideNationality_number", ""); // 编号
  7554. SetFieldValue(formFields, "residesOutsideNationality_validuntil", ""); // 有效期限
  7555. #endregion
  7556. #region 职业
  7557. SetFieldValue(formFields, "employerInfo", pdfData.GetSafeString("employer_info")); // 职业信息
  7558. #endregion
  7559. #region 此次行程的目的
  7560. // 清除值
  7561. SetFieldValue(formFields, "purpose_tourism", "Off"); // 旅游
  7562. SetFieldValue(formFields, "purpose_business", "Off"); // 商务
  7563. SetFieldValue(formFields, "purpose_visiting_friends_family", "Off");// 庆祝亲友团聚
  7564. SetFieldValue(formFields, "purpose_cultural", "Off"); // 文化交流
  7565. SetFieldValue(formFields, "purpose_sports", "Off"); // 体育活动
  7566. SetFieldValue(formFields, "purpose_official_visit", "Off"); // 官方访问
  7567. SetFieldValue(formFields, "purpose_medical_reasons", "Off"); // 医疗原因
  7568. SetFieldValue(formFields, "purpose_study", "Off"); // 学习
  7569. SetFieldValue(formFields, "purpose_transit", "Off"); // 过境
  7570. SetFieldValue(formFields, "purpose_airport_transit", "Off"); // 机场中转
  7571. SetFieldValue(formFields, "purpose_other", "Off"); // 其他
  7572. SetFieldValue(formFields, "purpose_other_specify", ""); // 其他 - 备注
  7573. var visit_purpose = pdfData.GetSafeString("employer_info");
  7574. if (!string.IsNullOrEmpty(visit_purpose))
  7575. {
  7576. if (visit_purpose.contains("tourism"))
  7577. {
  7578. SetFieldValue(formFields, "purpose_tourism", "Yes"); // 旅游
  7579. }
  7580. else if (visit_purpose.contains("business"))
  7581. {
  7582. SetFieldValue(formFields, "purpose_business", "Yes"); // 商务
  7583. }
  7584. else if (visit_purpose.contains("visiting_family_friends"))
  7585. {
  7586. SetFieldValue(formFields, "purpose_visiting_friends_family", "Yes");// 庆祝亲友团聚
  7587. }
  7588. else if (visit_purpose.contains("cultural") || visit_purpose.contains("tourism"))
  7589. {
  7590. SetFieldValue(formFields, "purpose_cultural", "Yes"); // 文化交流
  7591. }
  7592. else if (visit_purpose.contains("sports") || visit_purpose.contains("activities"))
  7593. {
  7594. SetFieldValue(formFields, "purpose_sports", "Yes"); // 体育活动
  7595. }
  7596. else if (visit_purpose.contains("official"))
  7597. {
  7598. SetFieldValue(formFields, "purpose_official_visit", "Yes"); // 官方访问
  7599. }
  7600. else if (visit_purpose.contains("medical_reasons") || visit_purpose.contains("medical"))
  7601. {
  7602. SetFieldValue(formFields, "purpose_medical_reasons", "Yes"); // 医疗原因
  7603. }
  7604. else if (visit_purpose.contains("study"))
  7605. {
  7606. SetFieldValue(formFields, "purpose_study", "Yes"); // 学习
  7607. }
  7608. else if (visit_purpose.contains("airport_transit"))
  7609. {
  7610. SetFieldValue(formFields, "purpose_transit", "Yes"); // 过境
  7611. }
  7612. else if (visit_purpose.contains("airport_transit"))
  7613. {
  7614. SetFieldValue(formFields, "purpose_airport_transit", "Yes"); // 机场中转
  7615. }
  7616. else
  7617. {
  7618. SetFieldValue(formFields, "purpose_other", "Yes"); // 其他
  7619. SetFieldValue(formFields, "purpose_other_specify", ""); // 其他 - 备注
  7620. }
  7621. }
  7622. #endregion
  7623. #region 目的国相关信息
  7624. SetFieldValue(formFields, "purpose_stay_info", pdfData.GetSafeString("stay_info")); //关于停留目的的补充说明
  7625. SetFieldValue(formFields, "finalDestinationCountry", pdfData.GetSafeString("membeDescLabel")); // 主要目的地成员国(如适用,还包括目的地的其他成员国)
  7626. SetFieldValue(formFields, "firstEntryBorder", pdfData.GetSafeString("firstEntryLabel")); // 口岸
  7627. SetFieldValue(formFields, "intendedStayDays", pdfData.GetSafeString("stayDays")); // 计划停留天数
  7628. // 申请入境次数
  7629. string request_entry = pdfData.GetSafeString("firstEntryLabel");
  7630. if (request_entry == "1") SetFieldValue(formFields, "requestedEntry_single", "Yes"); // 一次入境
  7631. else if (request_entry == "2") SetFieldValue(formFields, "requestedEntry_two", "Yes"); // 两次入境
  7632. else if (request_entry == "3") SetFieldValue(formFields, "requestedEntry_multiple", "Yes"); // 多次入境
  7633. #endregion
  7634. #region 过去三年签证
  7635. SetFieldValue(formFields, "hasPreviousVisas_no", "Yes"); // 否
  7636. SetFieldValue(formFields, "hasPreviousVisas_yes", "Off"); // 是
  7637. //第一年
  7638. SetFieldValue(formFields, "hasPreviousVisas_country1", ""); // 国家
  7639. SetFieldValue(formFields, "hasPreviousVisas_valid1", ""); // 有效期限 起
  7640. SetFieldValue(formFields, "hasPreviousVisas_until1", ""); // 有效期限 止
  7641. //第二年
  7642. SetFieldValue(formFields, "hasPreviousVisas_country2", ""); // 国家
  7643. SetFieldValue(formFields, "hasPreviousVisas_valid2", ""); // 有效期限 起
  7644. SetFieldValue(formFields, "hasPreviousVisas_until2", ""); // 有效期限 止
  7645. //第三年
  7646. SetFieldValue(formFields, "hasPreviousVisas_country3", ""); // 国家
  7647. SetFieldValue(formFields, "hasPreviousVisas_valid3", ""); // 有效期限 起
  7648. SetFieldValue(formFields, "hasPreviousVisas_until3", ""); // 有效期限 止
  7649. #endregion
  7650. #region 此前录过指纹
  7651. string schengen_fingerprints_status = pdfData.GetSafeString("schengen_fingerprints_status");
  7652. if (schengen_fingerprints_status == "1")
  7653. {
  7654. SetFieldValue(formFields, "fingerprintsPreviouslyCollected_yes", "Yes"); // 是
  7655. SetFieldValue(formFields, "fingerprintsPreviouslyCollected_date", ""); // 如有,请写明日期
  7656. }
  7657. else if (schengen_fingerprints_status == "2")
  7658. {
  7659. SetFieldValue(formFields, "fingerprintsPreviouslyCollected_no", "Yes"); // 否
  7660. }
  7661. #endregion
  7662. #region 最终目的地入境许可
  7663. SetFieldValue(formFields, "finalDestinationEntryPermit_issued", pdfData.GetSafeString("entry_permit_issued")); // 发布者
  7664. SetFieldValue(formFields, "finalDestinationEntryPermit_vaild", pdfData.GetSafeString("entry_permit_valid")); // 有效期限 起
  7665. SetFieldValue(formFields, "finalDestinationEntryPermit_until", pdfData.GetSafeString("entry_permit_until")); // 有效期限 止
  7666. #endregion
  7667. #region 计划旅行日期
  7668. SetFieldValue(formFields, "travelDates_arrivalDate", pdfData.GetSafeString("schengen_first_area_arrival")); // 出发日期
  7669. SetFieldValue(formFields, "travelDates_departureDate", pdfData.GetSafeString("schengen_first_area_departure")); // 离开日期
  7670. #endregion
  7671. #region 邀请人/酒店信息
  7672. SetFieldValue(formFields, "accommodationInfo_name", pdfData.GetSafeString("schengen_inviting_name")); // 招待方的地址和电子邮箱地址
  7673. SetFieldValue(formFields, "accommodationInfo_addressAndNameEmail", pdfData.GetSafeString("schengen_inviting_hotel_address_email")); // 酒店/临时住宿场所的地址和电子邮箱地址
  7674. SetFieldValue(formFields, "accommodationInfo_tel", pdfData.GetSafeString("schengen_inviting_hotel_tel")); // 电话号码
  7675. #endregion
  7676. #region 邀请公司/组织信息
  7677. SetFieldValue(formFields, "invitingOrganization_addressAndName", pdfData.GetSafeString("inviting_name_address")); // 邀请公司/组织的名称及地址
  7678. SetFieldValue(formFields, "invitingOrganization_contactInfo", pdfData.GetSafeString("inviting_info")); // 公司/组织中联系人的姓氏、名字、地址、电话号码以及电子邮箱地址
  7679. SetFieldValue(formFields, "invitingOrganization_tel", pdfData.GetSafeString("inviting_tel")); // 电话号码(关于)公司/组织
  7680. #endregion
  7681. #region 费用承担
  7682. #region 支持方式
  7683. SetFieldValue(formFields, "costCoverage_applicant", "Off"); // 支持方式
  7684. SetFieldValue(formFields, "costCoverage_applicant_cash", "Off"); // 现金
  7685. SetFieldValue(formFields, "costCoverage_applicant_travellers_cheques", "Off"); // 旅行支票
  7686. SetFieldValue(formFields, "costCoverage_applicant_credit_card", "Off"); // 信用卡
  7687. SetFieldValue(formFields, "costCoverage_applicant_prepaid_accommodation", "Off");// 预付费住宿
  7688. SetFieldValue(formFields, "costCoverage_applicant_prepaid_transport", "Off"); // 预付费交通
  7689. SetFieldValue(formFields, "costCoverage_applicant_other", "Off"); // 其他
  7690. SetFieldValue(formFields, "costCoverage_applicant_other_specify", ""); // 其他(请具体说明)
  7691. #endregion
  7692. #region 由赞助方(主办方、公司、组织)提供
  7693. SetFieldValue(formFields, "costCoverage_host", "Off"); // 由赞助方(主办方、公司、组织)提供
  7694. SetFieldValue(formFields, "costCoverage_host_referred", "Off"); // 在第 30 或 31 栏中提及
  7695. SetFieldValue(formFields, "costCoverage_host_referred_specify", "");// 在第 30 或 31 栏中提及(请具体说明
  7696. SetFieldValue(formFields, "costCoverage_host_other", "Yes"); // 其他
  7697. SetFieldValue(formFields, "costCoverage_host_other_specify", pdfData.GetSafeString("cost_covered_sponsor_other_specify")); // 其他(请具体说明
  7698. //支持方式
  7699. SetFieldValue(formFields, "costCoverage_host_cash", "Off"); // 现金
  7700. SetFieldValue(formFields, "costCoverage_host_accommodation", "Off"); // 提供住宿
  7701. SetFieldValue(formFields, "costCoverage_host_duringStay", "Off"); // 旅行期间的所有费用均由主办方承担
  7702. SetFieldValue(formFields, "costCoverage_host_prepaid_transport", "Off");// 预先支付的交通费用
  7703. SetFieldValue(formFields, "costCoverage_host_other", "Off"); // 其他
  7704. SetFieldValue(formFields, "costCoverage_host_other_specify", ""); // 其他(请具体说明
  7705. #endregion
  7706. #endregion
  7707. #region 欧盟家庭成员个人信息
  7708. SetFieldValue(formFields, "euFamilyMember_surname", ""); // 姓氏(家族名)
  7709. SetFieldValue(formFields, "euFamilyMember_firstname", ""); // 名字(名字)
  7710. SetFieldValue(formFields, "euFamilyMember_birthday", ""); // 出生日期 (日-月-年)
  7711. SetFieldValue(formFields, "euFamilyMember_nationality", "");// 国籍
  7712. SetFieldValue(formFields, "euFamilyMember_number", ""); // 旅行证件或身份证号码
  7713. #endregion
  7714. #region 欧盟家庭关系
  7715. SetFieldValue(formFields, "familyRelationship_spouse", "Off"); // 夫妻
  7716. SetFieldValue(formFields, "familyRelationship_child", "Off"); // 子女
  7717. SetFieldValue(formFields, "familyRelationship_grandchild", "Off"); // 孙子女
  7718. SetFieldValue(formFields, "familyRelationship_dependent", "Off"); // 有赡养关系的长辈
  7719. #endregion
  7720. SetFieldValue(formFields, "applicant_address_and_email", pdfData.GetSafeString("applicant_address_and_email")); // 申请人的家庭住址和电子邮箱地址
  7721. SetFieldValue(formFields, "applicant_tel", pdfData.GetSafeString("applicant_tel")); // 申请人的电话
  7722. #region 在非当前国籍所属国家的居住情况 “默认空”
  7723. SetFieldValue(formFields, "uncurrent_count_no", "Yes"); // 否
  7724. SetFieldValue(formFields, "uncurrent_count_yes", "Off"); // 是
  7725. SetFieldValue(formFields, "uncurrent_country_residence", ""); // 居留许可或同等证明
  7726. SetFieldValue(formFields, "uncurrent_country_no", ""); // No
  7727. SetFieldValue(formFields, "uncurrent_country_valid_until", ""); // 有效期至
  7728. #endregion
  7729. #endregion
  7730. saveUrl = outputPath;
  7731. }
  7732. catch (Exception ex)
  7733. {
  7734. return (false, $"生成PDF文件时出错:{ex.Message}", string.Empty);
  7735. }
  7736. finally
  7737. {
  7738. // 按正确顺序关闭资源
  7739. croatia_stamper?.Close();
  7740. croatia_reader?.Close();
  7741. croatia_templateStream?.Close();
  7742. croatia_outputStream?.Close();
  7743. }
  7744. #endregion
  7745. break;
  7746. case 8: // 西班牙
  7747. visaTypeName = $"西班牙签证申请表";
  7748. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  7749. var spianSavePath = $"{fileServerPath}{visaTypeName}/";
  7750. if (!Directory.Exists(spianSavePath)) Directory.CreateDirectory(spianSavePath);
  7751. if (!System.IO.File.Exists(currTempPath))
  7752. {
  7753. return (false, $"{currTempPath}模板不存在!", string.Empty);
  7754. }
  7755. #region 生成文件
  7756. PdfReader spian_reader = null;
  7757. FileStream spian_templateStream = null;
  7758. FileStream spian_outputStream = null;
  7759. PdfStamper spian_stamper = null;
  7760. try
  7761. {
  7762. string outputPath = $"{spianSavePath}{custInfo.LastName}{custInfo.FirstName}_{visaTypeName}.pdf";
  7763. //读取模板文件
  7764. spian_templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  7765. spian_reader = new PdfReader(spian_templateStream);
  7766. //创建输出文件
  7767. spian_outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  7768. spian_stamper = new PdfStamper(spian_reader, spian_outputStream);
  7769. AcroFields formFields = spian_stamper.AcroFields;
  7770. #region 设置文本值
  7771. SetFieldValue(formFields, "surname", pdfData.GetSafeString("surname")); // 姓 英文
  7772. SetFieldValue(formFields, "birth_surname", pdfData.GetSafeString("birth_surname")); // 出生时姓 英文
  7773. SetFieldValue(formFields, "firstname", pdfData.GetSafeString("firstname")); // 名 英文
  7774. SetFieldValue(formFields, "birthday", pdfData.GetSafeString("birthday")); // 出生日期
  7775. SetFieldValue(formFields, "birth_place", pdfData.GetSafeString("birth_place")); // 出生地区
  7776. SetFieldValue(formFields, "birth_country", pdfData.GetSafeString("birth_country")); // 出生国籍
  7777. SetFieldValue(formFields, "current_nationality", pdfData.GetSafeString("current_nationality")); // 现国籍
  7778. SetFieldValue(formFields, "birth_nationality", pdfData.GetSafeString("birth_nationality")); // 出生国籍
  7779. SetFieldValue(formFields, "other_nacionality", pdfData.GetSafeString("other_nacionality")); // 其他国籍
  7780. #region 设置性别
  7781. //清除性别
  7782. SetFieldValue(formFields, "sex_male", "Off"); // 性别 - 男
  7783. SetFieldValue(formFields, "sex_female", "Off"); // 性别 - 女
  7784. SetFieldValue(formFields, "sex_other", "Off"); // 性别 - 其他
  7785. //设置性别
  7786. var sex = pdfData.GetSafeString("sex");
  7787. if (sex.Equals("0")) // 男
  7788. {
  7789. SetFieldValue(formFields, "sex_male", "Yes"); // 性别 - 男
  7790. }
  7791. else if (sex.Equals("1")) // 女
  7792. {
  7793. SetFieldValue(formFields, "sex_female", "Yes"); // 性别 - 女
  7794. }
  7795. else
  7796. {
  7797. SetFieldValue(formFields, "sex_other", "Yes"); // 性别 - 其他
  7798. }
  7799. #endregion
  7800. #region 婚姻状态
  7801. //清除婚姻状况
  7802. SetFieldValue(formFields, "marital_single", "Off"); // 婚姻状况 - 未婚
  7803. SetFieldValue(formFields, "marital_married", "Off"); // 婚姻状况 - 已婚
  7804. SetFieldValue(formFields, "marital_registered_union", "Off");// 婚姻状况 - 注册伴侣关系
  7805. SetFieldValue(formFields, "marital_separated", "Off"); // 婚姻状况 - 分居
  7806. SetFieldValue(formFields, "marital_divorced", "Off"); // 婚姻状况 - 离异
  7807. SetFieldValue(formFields, "marital_widower", "Off"); // 婚姻状况 - 丧偶
  7808. SetFieldValue(formFields, "marital_other", "Off"); // 婚姻状况 - 其他
  7809. SetFieldValue(formFields, "marital_other_specify", ""); // 婚姻状况 - 其他(请具体说明)
  7810. var maritalStatus = pdfData.GetSafeString("marital_status");
  7811. //设置婚姻状况
  7812. switch (maritalStatus)
  7813. {
  7814. case "1": // 未婚
  7815. SetFieldValue(formFields, "marital_single", "Yes");
  7816. break;
  7817. case "2": // 已婚
  7818. SetFieldValue(formFields, "marital_married", "Yes");
  7819. break;
  7820. case "3": // 离婚/离异
  7821. SetFieldValue(formFields, "marital_divorced", "Yes");
  7822. break;
  7823. case "4": // 分居
  7824. SetFieldValue(formFields, "marital_separated", "Yes");
  7825. break;
  7826. case "5": // 丧偶
  7827. SetFieldValue(formFields, "marital_widower", "Yes");
  7828. break;
  7829. case "6": // 其他
  7830. SetFieldValue(formFields, "marital_other", "Yes");
  7831. break;
  7832. }
  7833. #endregion
  7834. // 父母的监护权(针对未成年人)/法定监护人(姓氏、名字、地址(若与申请人的地址不同)、电话号码、电子邮箱地址以及国籍)
  7835. SetFieldValue(formFields, "legal_guardian_info", pdfData.GetSafeString("legal_guardian_info"));
  7836. //(如适用)国民身份号码
  7837. SetFieldValue(formFields, "national_identity_number", pdfData.GetSafeString("national_identity_number"));
  7838. #region 护照信息
  7839. //清除值
  7840. SetFieldValue(formFields, "passport_orfinary", "Off"); // 旅行证件类型 - 普通护照
  7841. SetFieldValue(formFields, "passport_diplomatic", "Off"); // 旅行证件类型 - 外交护照
  7842. SetFieldValue(formFields, "passport_service", "Off"); // 旅行证件类型 - 公务护照
  7843. SetFieldValue(formFields, "passport_official", "Off"); // 旅行证件类型 - 因公护照
  7844. SetFieldValue(formFields, "passport_other", "Off"); // 旅行证件类型 - 特别护照
  7845. SetFieldValue(formFields, "passport_other_specify", ""); // 其他旅行证件(请注明)
  7846. #region 设置 护照信息
  7847. string visaName = pdfData.GetSafeString("passport_type_name");
  7848. if (visaName.contains("普通")) SetFieldValue(formFields, "passport_orfinary", "Yes"); // 旅行证件类型 - 普通护照
  7849. else if (visaName.contains("外交")) SetFieldValue(formFields, "passport_diplomatic", "Yes"); // 旅行证件类型 - 外交护照
  7850. else if (visaName.contains("公务")) SetFieldValue(formFields, "passport_service", "Yes"); // 旅行证件类型 - 公务护照
  7851. else if (visaName.contains("因公")) SetFieldValue(formFields, "passport_official", "Yes"); // 旅行证件类型 - 因公护照
  7852. else // 旅行证件类型 - 特别护照
  7853. {
  7854. SetFieldValue(formFields, "passport_other", "Yes");
  7855. SetFieldValue(formFields, "passport_other_specify", "");
  7856. }
  7857. SetFieldValue(formFields, "travel_number", pdfData.GetSafeString("travel_number")); // 签证 编号
  7858. SetFieldValue(formFields, "travel_issues_country", pdfData.GetSafeString("travel_issues_country"));// 签发 国
  7859. SetFieldValue(formFields, "travel_issue_date", pdfData.GetSafeString("travel_issue_date")); // 签发日期
  7860. SetFieldValue(formFields, "travel_valid_until", pdfData.GetSafeString("travel_valid_until")); // 有效期至
  7861. #endregion
  7862. #endregion
  7863. #region 欧盟家庭成员个人信息
  7864. SetFieldValue(formFields, "ue_family_info", pdfData.GetSafeString("ue_family_info")); // 个人信息
  7865. SetFieldValue(formFields, "ue_family_surname", pdfData.GetSafeString("ue_family_surname")); // 姓氏(家族名)
  7866. SetFieldValue(formFields, "ue_family_firstname", pdfData.GetSafeString("ue_family_firstname")); // 名字(名字)
  7867. SetFieldValue(formFields, "ue_family_birthday", pdfData.GetSafeString("ue_family_birthday")); // 出生日期 (日-月-年)
  7868. SetFieldValue(formFields, "ue_family_nationality", pdfData.GetSafeString("ue_family_nationality")); // 国籍
  7869. SetFieldValue(formFields, "ue_family_travel_number", pdfData.GetSafeString("ue_family_travel_number"));// 旅行证件或身份证号码
  7870. #endregion
  7871. #region 欧盟家庭关系
  7872. SetFieldValue(formFields, "eu_family_relationship_spouse", "Off"); // 夫妻
  7873. SetFieldValue(formFields, "eu_family_relationship_child", "Off"); // 子女
  7874. SetFieldValue(formFields, "eu_family_relationship_grandchild", "Off"); // 孙子女
  7875. SetFieldValue(formFields, "eu_family_relationship_dependent", "Off"); // 受养人
  7876. SetFieldValue(formFields, "eu_family_relationship_registered_partnership", "Off"); // 注册伴侣
  7877. SetFieldValue(formFields, "eu_family_relationship_other", pdfData.GetSafeString("eu_family_relationship_other")); // 其他
  7878. SetFieldValue(formFields, "eu_family_relationship_other_specify", pdfData.GetSafeString("eu_family_relationship_other_specify")); // 其他
  7879. #endregion
  7880. // 申请人的家庭住址和电子邮箱地址
  7881. SetFieldValue(formFields, "applicant_address_and_email", pdfData.GetSafeString("applicant_address_and_email"));
  7882. // 申请人的电话
  7883. SetFieldValue(formFields, "applicant_tel", pdfData.GetSafeString("applicant_tel"));
  7884. #region 是否在非国籍国居住 默认否
  7885. SetFieldValue(formFields, "unresidente_no", "Yes"); // 否
  7886. SetFieldValue(formFields, "unresidente_yes", "Off"); // 是
  7887. SetFieldValue(formFields, "unresidente_equivalen", ""); // 居住许可证
  7888. SetFieldValue(formFields, "unresidente_number", ""); // 编号
  7889. SetFieldValue(formFields, "unresidente_vaild", ""); // 有效期限
  7890. #endregion
  7891. #region 职业
  7892. // 当前职业
  7893. SetFieldValue(formFields, "occupation", pdfData.GetSafeString("fileName"));
  7894. //雇主及雇主的地址和电话号码。
  7895. SetFieldValue(formFields, "employer_info", pdfData.GetSafeString("employer_info"));
  7896. #endregion
  7897. #region 此次行程的目的
  7898. //清除值
  7899. SetFieldValue(formFields, "purpose_tourism", "Off"); // 旅游
  7900. SetFieldValue(formFields, "purpose_business", "Off"); // 商务
  7901. SetFieldValue(formFields, "purpose_visiting_family_friends", "Off");// 庆祝亲友团聚
  7902. SetFieldValue(formFields, "purpose_cultural", "Off"); // 文化交流
  7903. SetFieldValue(formFields, "purpose_sports", "Off"); // 体育
  7904. SetFieldValue(formFields, "purpose_official", "Off"); // 官方访问
  7905. SetFieldValue(formFields, "purpose_medical_reasons", "Off"); // 医疗
  7906. SetFieldValue(formFields, "purpose_study", "Off"); // 学习
  7907. SetFieldValue(formFields, "purpose_airport_transit", "Off"); // 机场过境
  7908. SetFieldValue(formFields, "purpose_other", "Off"); // 其他
  7909. SetFieldValue(formFields, "purpose_other_specify", ""); // 其他 - 备注
  7910. var visit_purpose = pdfData.GetSafeString("purpose");
  7911. var visit_purpose_remark = pdfData.GetSafeString("purpose_other_specify");
  7912. if (!string.IsNullOrEmpty(visit_purpose))
  7913. {
  7914. if (visit_purpose.contains("tourism"))
  7915. {
  7916. SetFieldValue(formFields, "purpose_tourism", "Yes"); // 旅游
  7917. }
  7918. else if (visit_purpose.contains("business"))
  7919. {
  7920. SetFieldValue(formFields, "purpose_business", "Yes"); // 商务
  7921. }
  7922. else if (visit_purpose.contains("visiting_family_friends"))
  7923. {
  7924. SetFieldValue(formFields, "purpose_visiting_family_friends", "Yes");// 庆祝亲友团聚
  7925. }
  7926. else if (visit_purpose.contains("cultural") || visit_purpose.contains("tourism"))
  7927. {
  7928. SetFieldValue(formFields, "purpose_cultural", "Yes"); // 文化交流
  7929. }
  7930. else if (visit_purpose.contains("sports"))
  7931. {
  7932. SetFieldValue(formFields, "purpose_sports", "Yes"); // 体育
  7933. }
  7934. else if (visit_purpose.contains("official"))
  7935. {
  7936. SetFieldValue(formFields, "purpose_official", "Yes"); // 官方访问
  7937. }
  7938. else if (visit_purpose.contains("medical_reasons") || visit_purpose.contains("medical"))
  7939. {
  7940. SetFieldValue(formFields, "purpose_medical_reasons", "Yes"); // 医疗原因
  7941. }
  7942. else if (visit_purpose.contains("study"))
  7943. {
  7944. SetFieldValue(formFields, "purpose_study", "Yes"); // 学习
  7945. }
  7946. else if (visit_purpose.contains("airport_transit") || visit_purpose.contains("transit"))
  7947. {
  7948. SetFieldValue(formFields, "purpose_airport_transit", "Yes"); // 机场过境
  7949. }
  7950. else
  7951. {
  7952. SetFieldValue(formFields, "purpose_other", "Yes"); // 其他
  7953. SetFieldValue(formFields, "purpose_other_specify", visit_purpose_remark);// 其他 - 备注
  7954. }
  7955. }
  7956. #endregion
  7957. #region 目的国相关信息
  7958. // 关于停留目的的补充说明
  7959. SetFieldValue(formFields, "stay_info", pdfData.GetSafeString("stay_info"));
  7960. SetFieldValue(formFields, "member_destination", pdfData.GetSafeString("member_destination")); // 主要目的地成员国(如适用,还包括目的地的其他成员国)
  7961. SetFieldValue(formFields, "member_first_entry", pdfData.GetSafeString("member_first_entry")); // 首入申根国标签
  7962. // 申请入境次数
  7963. string request_entry = pdfData.GetSafeString("member_first_entry");
  7964. switch (request_entry)
  7965. {
  7966. case "1":
  7967. SetFieldValue(formFields, "request_entry_one", "Yes"); // 一次入境
  7968. break;
  7969. case "2":
  7970. SetFieldValue(formFields, "request_entry_two", "Yes"); // 两次入境
  7971. break;
  7972. case "3":
  7973. SetFieldValue(formFields, "request_entry_multiple", "Yes"); // 多次入境
  7974. break;
  7975. }
  7976. SetFieldValue(formFields, "schengen_first_area_arrival", pdfData.GetSafeString("schengen_first_area_arrival")); // 首次抵达日期
  7977. SetFieldValue(formFields, "schengen_first_area_departure", pdfData.GetSafeString("schengen_first_area_departure")); // 首次抵达日期
  7978. #endregion
  7979. #region 此前录过指纹
  7980. var fingerprints = pdfData.GetSafeString("schengen_fingerprints_status");
  7981. switch (fingerprints)
  7982. {
  7983. // 是
  7984. case "1":
  7985. SetFieldValue(formFields, "schengen_fingerprints_yes", "Yes"); // 是
  7986. SetFieldValue(formFields, "schengen_fingerprints_date", ""); // 如有,请写明日期
  7987. SetFieldValue(formFields, "schengen_fingerprints_visa_no", "");// 编号
  7988. break;
  7989. // 否
  7990. case "2":
  7991. SetFieldValue(formFields, "schengen_fingerprints_no", "Yes"); // 否
  7992. break;
  7993. }
  7994. #endregion
  7995. #region 最终目的地入境许可
  7996. SetFieldValue(formFields, "entry_permit_issued", pdfData.GetSafeString("entry_permit_issued")); // 发布者
  7997. SetFieldValue(formFields, "entry_permit_valid", pdfData.GetSafeString("entry_permit_valid")); // 有效期限 起
  7998. SetFieldValue(formFields, "entry_permit_until", pdfData.GetSafeString("entry_permit_until")); // 有效期限 止
  7999. #endregion
  8000. #region 邀请人/酒店信息
  8001. SetFieldValue(formFields, "schengen_inviting_name", pdfData.GetSafeString("schengen_inviting_name")); // 招待方的酒店、邀请人 名称
  8002. SetFieldValue(formFields, "schengen_inviting_hotel_address_email", pdfData.GetSafeString("schengen_inviting_hotel_address_email")); // 酒店/临时住宿场所的地址和电子邮箱地址
  8003. SetFieldValue(formFields, "schengen_inviting_hotel_tel", pdfData.GetSafeString("schengen_inviting_hotel_tel")); // 电话号码
  8004. #endregion
  8005. #region 邀请公司/组织信息
  8006. SetFieldValue(formFields, "inviting_name_address", pdfData.GetSafeString("inviting_name_address")); // 邀请公司/组织的名称及地址
  8007. SetFieldValue(formFields, "inviting_info", pdfData.GetSafeString("inviting_info")); // 公司/组织中联系人的姓氏、名字、地址、电话号码以及电子邮箱地址
  8008. SetFieldValue(formFields, "inviting_tel", pdfData.GetSafeString("inviting_tel")); // 电话号码(关于)公司/组织
  8009. #endregion
  8010. #region 费用承担
  8011. #region 支持方式
  8012. SetFieldValue(formFields, "cost_covered_herself", "Off"); // 支持方式
  8013. SetFieldValue(formFields, "cost_covered_herself_cash", "Off"); // 现金
  8014. SetFieldValue(formFields, "cost_covered_herself_cheques", "Off"); // 旅行支票
  8015. SetFieldValue(formFields, "cost_covered_herself_credit", "Off"); // 信用卡
  8016. SetFieldValue(formFields, "cost_covered_herself_accomodation", "Off"); // 预付费住宿
  8017. SetFieldValue(formFields, "cost_covered_herself_transport", "Off"); // 预付费交通
  8018. SetFieldValue(formFields, "cost_covered_herself_other", "Off"); // 其他
  8019. SetFieldValue(formFields, "cost_covered_herself_other_specift", ""); // 其他(请具体说明)
  8020. #endregion
  8021. #region 由赞助方(主办方、公司、组织)提供
  8022. SetFieldValue(formFields, "cost_covered_sponsor", "Off"); // 由赞助方(主办方、公司、组织)提供
  8023. SetFieldValue(formFields, "cost_covered_sponsor_referred", "Off"); // 在第 30 或 31 栏中提及
  8024. SetFieldValue(formFields, "cost_covered_sponsor_other", "Yes"); // 其他
  8025. SetFieldValue(formFields, "cost_covered_sponsor_other_specify", pdfData.GetSafeString("cost_covered_sponsor_other_specify")); // 其他(请具体说明
  8026. //支持方式
  8027. SetFieldValue(formFields, "cost_covered_sponsor_cash", "Off"); // 现金
  8028. SetFieldValue(formFields, "cost_covered_sponsor_accomodation", "Off"); // 提供住宿
  8029. SetFieldValue(formFields, "cost_covered_sponsor_during_stay", "Off"); // 旅行期间的所有费用均由主办方承担
  8030. SetFieldValue(formFields, "cost_covered_sponsor_transport", "Off"); // 预先支付的交通费用
  8031. SetFieldValue(formFields, "cost_covered_sponsor_other", "Off"); // 其他
  8032. SetFieldValue(formFields, "cost_covered_sponsor_other_specify", ""); // 其他(请具体说明
  8033. #endregion
  8034. #endregion
  8035. #endregion
  8036. saveUrl = outputPath;
  8037. }
  8038. catch (Exception ex)
  8039. {
  8040. return (false, $"生成PDF文件时出错:{ex.Message}", string.Empty);
  8041. }
  8042. finally
  8043. {
  8044. // 按正确顺序关闭资源
  8045. spian_stamper?.Close();
  8046. spian_reader?.Close();
  8047. spian_templateStream?.Close();
  8048. spian_outputStream?.Close();
  8049. }
  8050. #endregion
  8051. break;
  8052. default:
  8053. return (false, "正在开发中,请等待。。。", string.Empty);
  8054. }
  8055. // 文件下载地址
  8056. downloadUrl = saveUrl.Replace(@"\", @"/").Replace("D:/FTP/File/OA2023", "http://132.232.92.186:24");
  8057. return (true, saveUrl, downloadUrl);
  8058. }
  8059. /// <summary>
  8060. /// 派遣函 生成
  8061. /// </summary>
  8062. /// <returns></returns>
  8063. private async Task<(bool, string, string)> GeneratorDispatchAsync(DataBody dataBody)
  8064. {
  8065. var wordDic = new Dictionary<string, string>();
  8066. var custInfo = dataBody.groupCustInfos.FirstOrDefault();
  8067. var clientInfo = dataBody.companyInfos.FirstOrDefault();
  8068. var groupInfo = dataBody?.groupInfo;
  8069. string clientName = clientInfo?.Company ?? "";
  8070. string clientAddress = clientInfo?.CompanyAddress ?? "";
  8071. string clientTel = clientInfo?.Phone ?? "";
  8072. string clientFax = "";
  8073. string name = $"{custInfo?.LastName ?? ""}{custInfo?.FirstName ?? ""}";
  8074. int sexId = custInfo?.Sex ?? -1;
  8075. string sex = sexId switch
  8076. {
  8077. 0 => "男",
  8078. 1 => "女",
  8079. _ => ""
  8080. };
  8081. string birthday = string.Empty;
  8082. #region 出生日期(日-月-年)
  8083. string idCard = dataBody?.certInfos.FirstOrDefault(x => x.PassportType == 773)?.CertNo?.Trim() ?? "";
  8084. // 1. 优先从身份证中提取 (需为18位身份证)
  8085. if (!string.IsNullOrEmpty(idCard) && idCard.Length >= 14)
  8086. {
  8087. try
  8088. {
  8089. string year = idCard.Substring(6, 4);
  8090. string month = idCard.Substring(10, 2);
  8091. string day = idCard.Substring(12, 2);
  8092. // 统一格式为 yyyy-MM-dd
  8093. birthday = $"{year}-{month}-{day}";
  8094. }
  8095. catch
  8096. {
  8097. // 如果截取失败,回退为空
  8098. birthday = string.Empty;
  8099. }
  8100. }
  8101. // 2. 身份证不存在或提取失败,则从 custInfo 获取
  8102. if (string.IsNullOrEmpty(birthday))
  8103. {
  8104. DateTime? date = custInfo?.BirthDay;
  8105. // 验证逻辑:排除空值、1900年、或 DateTime.MinValue
  8106. if (!date.HasValue || date.Value.Year == 1900 || date.Value == DateTime.MinValue)
  8107. {
  8108. birthday = "";
  8109. }
  8110. else
  8111. {
  8112. birthday = date.Value.ToString("yyyy-MM-dd");
  8113. }
  8114. }
  8115. #endregion
  8116. string passportNo = dataBody.certInfos.FirstOrDefault(x => x.PassportType == 774)?.CertNo ?? "";
  8117. string jobInfo = $"{clientInfo?.WorkStart?.ToString("yyyy-MM-dd") ?? ""} {clientInfo?.Job}";
  8118. string wage = custInfo?.Wage ?? "";
  8119. string invitingPartyName = ""; // 邀请方名称
  8120. string destinationCountry = ""; // 出访国家
  8121. string durationOfStay = ""; // 在外停留天数
  8122. string entryDate = ""; // 入境国外时间
  8123. string exitDate = ""; // 出境国外时间
  8124. string visitPurpose = groupInfo?.VisitPurpose ?? ""; // 出访目的
  8125. string shengenCountryInfos = ""; // 申根国相关信息
  8126. string fillingDate = DateTime.Now.ToString("yyyy-MM-dd"); //填写日期
  8127. #region 国家、(入、离)境信息
  8128. string[] country = new string[] { }; // 接收处理的国家
  8129. string firstEntryLabel = string.Empty; // 首入申根国标签
  8130. string membeDescLabel = string.Empty; // 申根国目的地
  8131. string visitCountry = groupInfo?.VisitCountry;
  8132. if (!string.IsNullOrEmpty(visitCountry))
  8133. {
  8134. List<string> SGGNames = new List<string>(); // 接收处理后的国家 是申根国
  8135. if (visitCountry.Contains(","))
  8136. country = visitCountry.Split(',');
  8137. else if (visitCountry.Contains(' '))
  8138. country = visitCountry.Split(' ');
  8139. else if (visitCountry.Contains(","))
  8140. country = visitCountry.Split(',');
  8141. else if (visitCountry.Contains("、"))
  8142. country = visitCountry.Split('、');
  8143. else if (visitCountry.Contains("|"))
  8144. country = visitCountry.Split('|');
  8145. //判断是否是申根国家
  8146. for (int i = 0; i < country.Length; i++)
  8147. {
  8148. if (country[i].ToString() != null)
  8149. {
  8150. //在申根国家中筛选 该国家是否是申根国家
  8151. for (int j = 0; j < _shenGenGuos.Length; j++)
  8152. {
  8153. if (country[i] == _shenGenGuos[j])
  8154. SGGNames.Add(_shenGenGuos[j]); //添加申根国
  8155. }
  8156. }
  8157. }
  8158. //目的地国是否有申根国
  8159. if (SGGNames.Count > 0)
  8160. {
  8161. firstEntryLabel = SGGNames.First();
  8162. membeDescLabel = string.Join(",", SGGNames.ToArray());
  8163. //接收生根国详细信息 存储顺序 起飞日期:Day 起飞时刻:StartTime 抵达日期:ArrivedDate 到达时刻:EndTime
  8164. List<SSGDetails> ListSSGDetails = new List<SSGDetails>();
  8165. //处理申根国家 预定到达时间 预定离开时间 预定停留天数
  8166. for (int i = 0; i < SGGNames.Count; i++)
  8167. {
  8168. //在相同的国家下 得到该航班的信息 //抵达时间 起飞日期:Day 起飞时刻:StartTime 到达时刻:EndTime 抵达日期:ArrivedDate 飞行时间:FlightTime 航司 Fliagtcode 入境口岸
  8169. var atbc = GeneralMethod.GetTableByBlackCode(groupInfo?.Id ?? 0);
  8170. //ResidenceTime1 机票三字码信息
  8171. if (atbc != null)
  8172. {
  8173. string HL_Three = ""; //三字码 Three
  8174. for (int j = 0; j < atbc.Rows.Count; j++)
  8175. {
  8176. HL_Three = atbc.Rows[j]["Three"].ToString();
  8177. if (!string.IsNullOrEmpty(HL_Three))
  8178. {
  8179. string threeCodeTwo = HL_Three.Substring(3);
  8180. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  8181. if (tc != null)
  8182. {
  8183. //首入申根国时间
  8184. if (SGGNames[i] == tc.Country)
  8185. {
  8186. SSGDetails SSGDetails = new SSGDetails()
  8187. {
  8188. Three = atbc.Rows[j]["Three"].ToString(), //三字码
  8189. Fliagtcode = atbc.Rows[j]["Fliagtcode"].ToString(), //航司
  8190. startDate = atbc.Rows[j]["Day"].ToString(), //整理起飞日期
  8191. startTime = atbc.Rows[j]["StartTime"].ToString(), //整理起飞时刻
  8192. endDate = atbc.Rows[j]["ArrivedDate"].ToString(), //整理抵达日期
  8193. endTime = atbc.Rows[j]["EndTime"].ToString() //整理抵达时刻
  8194. };
  8195. ListSSGDetails.Add(SSGDetails);
  8196. }
  8197. }
  8198. }
  8199. }
  8200. }
  8201. }
  8202. ListSSGDetails.Sort((a, b) => a.startDate.CompareTo(b.startDate));
  8203. //得到并计算出入境时间
  8204. if (ListSSGDetails != null)
  8205. {
  8206. entryDate = ListSSGDetails.First().endDate + " " + ListSSGDetails.First().endTime.Substring(0, 2) + ":" + ListSSGDetails.First().endTime.Substring(2); //入境时间
  8207. exitDate = ListSSGDetails[ListSSGDetails.Count - 1].startDate + " " + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(0, 2) + ":" + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(2); //离境时间
  8208. durationOfStay = Convert.ToDateTime(exitDate).Subtract(Convert.ToDateTime(entryDate)).Days.ToString();
  8209. }
  8210. // (出访2个及以上申根国家,每个国家邀请方名称及出访时间均需要写清楚)
  8211. if (SGGNames.Count >= 2)
  8212. {
  8213. var oaItem = _sqlSugar.Queryable<Res_OfficialActivities>()
  8214. .Where(x => x.IsDel == 0 && x.DiId == groupInfo.Id)
  8215. .Where(x => SGGNames.Contains(x.Country))
  8216. .OrderBy(x => x.Date)
  8217. .ToList();
  8218. foreach (var item in oaItem)
  8219. {
  8220. shengenCountryInfos += $"{item.Country} {item.Client} {item.Date} {item.Time};\r\n";
  8221. }
  8222. }
  8223. }
  8224. destinationCountry = string.Join(", ", country);
  8225. }
  8226. #endregion
  8227. #region 邀请公司/组织信息
  8228. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  8229. .Where(x => x.IsDel == 0 && x.DiId == groupInfo.Id)
  8230. //.Where(x => x.Country.Contains(county))
  8231. //.Where(x => x.Area.Contains(city))
  8232. .First();
  8233. invitingPartyName = $"{oa?.Client ?? ""}";
  8234. #endregion
  8235. #region 填充派遣函数据
  8236. wordDic.Add("clientName", clientName);
  8237. wordDic.Add("clientAddress", clientAddress);
  8238. wordDic.Add("clientTel", clientTel);
  8239. wordDic.Add("clientFax", clientFax);
  8240. wordDic.Add("name", name);
  8241. wordDic.Add("sex", sex);
  8242. wordDic.Add("birthday", birthday);
  8243. wordDic.Add("passportNo", passportNo);
  8244. wordDic.Add("jobInfo", jobInfo);
  8245. wordDic.Add("wage", wage);
  8246. wordDic.Add("invitingPartyName", invitingPartyName);
  8247. wordDic.Add("destinationCountry", destinationCountry);
  8248. wordDic.Add("durationOfStay", durationOfStay);
  8249. wordDic.Add("entryDate", entryDate);
  8250. wordDic.Add("exitDate", exitDate);
  8251. wordDic.Add("visitPurpose", visitPurpose);
  8252. wordDic.Add("shengenCountryInfos", shengenCountryInfos);
  8253. #endregion
  8254. // DeepSeek AI 中转英
  8255. wordDic = await DeepSeekCNToENAsync(JsonConvert.SerializeObject(wordDic));
  8256. #region 加载模板生成值
  8257. string templatePath = @$"D:\FTP\File\OA2023\Office\Word\VisaClientData\Template\申根派遣函模板.doc";
  8258. if (!System.IO.File.Exists(templatePath))
  8259. {
  8260. return (false, $"找不到指定的派遣函模板: {templatePath}", string.Empty);
  8261. }
  8262. Document doc = new Document(templatePath);
  8263. DocumentBuilder builder = new DocumentBuilder(doc);
  8264. // 填充值
  8265. FillBookmark(doc, builder, "clientNameCN", clientName); // 单位名称(中文)
  8266. FillBookmark(doc, builder, "clientNameEN", wordDic.GetSafeString("clientName")); // 单位名称(英文)
  8267. FillBookmark(doc, builder, "clientAddressCN", clientAddress); // 单位地址(中文)
  8268. FillBookmark(doc, builder, "clientAddressEN", wordDic.GetSafeString("clientAddress")); // 单位地址(英文)
  8269. FillBookmark(doc, builder, "clientTel", wordDic.GetSafeString("clientTel")); // 单位电话
  8270. FillBookmark(doc, builder, "clientFax", wordDic.GetSafeString("clientFax")); // 单位传真
  8271. FillBookmark(doc, builder, "fillingDate", wordDic.GetSafeString("fillingDate")); // 填写日期
  8272. FillBookmark(doc, builder, "name", wordDic.GetSafeString("name")); // 姓名
  8273. FillBookmark(doc, builder, "sex", wordDic.GetSafeString("sex")); // 性别
  8274. FillBookmark(doc, builder, "birthday", wordDic.GetSafeString("birthday")); // 出生日期
  8275. FillBookmark(doc, builder, "passportNo", wordDic.GetSafeString("passportNo")); // 护照号码
  8276. FillBookmark(doc, builder, "clientName", wordDic.GetSafeString("clientName")); // 单位名称
  8277. FillBookmark(doc, builder, "jobInfo", wordDic.GetSafeString("jobInfo")); // 工作信息
  8278. FillBookmark(doc, builder, "wage", wordDic.GetSafeString("wage")); // 工资
  8279. FillBookmark(doc, builder, "invitingPartyName", wordDic.GetSafeString("invitingPartyName")); // 邀请方名称
  8280. FillBookmark(doc, builder, "destinationCountry", wordDic.GetSafeString("destinationCountry")); // 出访国家
  8281. FillBookmark(doc, builder, "durationOfStay", wordDic.GetSafeString("durationOfStay")); // 在外停留天数
  8282. FillBookmark(doc, builder, "entryDate", wordDic.GetSafeString("entryDate")); // 入境国外时间
  8283. FillBookmark(doc, builder, "exitDate", wordDic.GetSafeString("exitDate")); // 出境国外时间
  8284. FillBookmark(doc, builder, "visitPurpose", wordDic.GetSafeString("visitPurpose")); // 出访目的
  8285. FillBookmark(doc, builder, "nameEnd", wordDic.GetSafeString("name")); // 姓名 END
  8286. FillBookmark(doc, builder, "visitCountryEnd", wordDic.GetSafeString("destinationCountry")); // 出访国家 END
  8287. FillBookmark(doc, builder, "clientNameEnd", wordDic.GetSafeString("clientName")); // 详细费用承担方单位名称 END
  8288. #endregion
  8289. var groupName = dataBody.groupInfo?.TeamName ?? $"";
  8290. //访问路径
  8291. var serverPath = $"http://132.232.92.186:24/Office/Word/VisaClientData/Downloads/{groupName}/派遣函/";
  8292. // 服务器存储文件位置
  8293. var fileServerPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Downloads/{groupName}/派遣函/";
  8294. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(fileServerPath);
  8295. string fileName = $"{name}_派遣函.docx";
  8296. string fullPath = Path.Combine(fileServerPath, fileName);
  8297. doc.Save(fullPath, Aspose.Words.SaveFormat.Docx);
  8298. // 转换为下载地址
  8299. string downloadUrl = fullPath
  8300. .Replace(@"\", "/")
  8301. .Replace("D:/FTP/File/OA2023", "http://132.232.92.186:24", StringComparison.OrdinalIgnoreCase);
  8302. return (true, fullPath, downloadUrl);
  8303. }
  8304. /// <summary>
  8305. /// 填充 PDF 模板数据
  8306. /// </summary>
  8307. /// <param name="dataBody"></param>
  8308. /// <param name="language">
  8309. /// 下载语言:1-中文,2-英文
  8310. /// </param>
  8311. /// <returns></returns>
  8312. private async Task<Dictionary<string, string>> FillPdfTemplateAsync(DataBody dataBody, int language = 1)
  8313. {
  8314. #region PDF模板数据填充,数据来源:团组客户信息、家庭成员资料、公司资料、学校资料、证件信息等
  8315. var custInfo = dataBody.groupCustInfos.FirstOrDefault();
  8316. var groupInfo = dataBody.groupInfo;
  8317. var groupId = groupInfo?.Id ?? 0;
  8318. var idInfo = dataBody.certInfos.Where(x => x.SdId == 773).FirstOrDefault();
  8319. var passportInfo = dataBody.certInfos.Where(x => x.SdId == 774).FirstOrDefault();
  8320. var clinetInfo = dataBody.companyInfos;
  8321. var schoolInfos = dataBody.schoolInfos;
  8322. var familyInfos = dataBody.familyInfos;
  8323. var companyInfos = dataBody.companyInfos;
  8324. var pdfData = new Dictionary<string, string>();
  8325. #region 定义pdf模板中字段存储值
  8326. #region 个人信息
  8327. pdfData.Add("surname", custInfo?.LastName?.Trim() ?? ""); // 姓名(姓氏、名字)
  8328. pdfData.Add("birth_surname", custInfo?.LastName?.Trim() ?? ""); // 出生时姓氏
  8329. pdfData.Add("firstname", custInfo?.FirstName?.Trim() ?? ""); // 名字
  8330. #region 出生日期(日-月-年)
  8331. string birthday = string.Empty;
  8332. string idCard = idInfo?.CertNo?.Trim() ?? "";
  8333. // 1. 优先从身份证中提取 (需为18位身份证)
  8334. if (!string.IsNullOrEmpty(idCard) && idCard.Length >= 14)
  8335. {
  8336. try
  8337. {
  8338. string year = idCard.Substring(6, 4);
  8339. string month = idCard.Substring(10, 2);
  8340. string day = idCard.Substring(12, 2);
  8341. // 统一格式为 yyyy-MM-dd
  8342. birthday = $"{day}-{month}-{year}";
  8343. }
  8344. catch
  8345. {
  8346. // 如果截取失败,回退为空
  8347. birthday = string.Empty;
  8348. }
  8349. }
  8350. // 2. 身份证不存在或提取失败,则从 custInfo 获取
  8351. if (string.IsNullOrEmpty(birthday))
  8352. {
  8353. DateTime? date = custInfo?.BirthDay;
  8354. // 验证逻辑:排除空值、1900年、或 DateTime.MinValue
  8355. if (!date.HasValue || date.Value.Year == 1900 || date.Value == DateTime.MinValue)
  8356. {
  8357. birthday = "";
  8358. }
  8359. else
  8360. {
  8361. birthday = date.Value.ToString("dd-MM-yyyy");
  8362. }
  8363. }
  8364. #endregion
  8365. pdfData.Add("birthday", birthday); // 出生日期
  8366. var area = custInfo.BirthProvince + custInfo.BirthCity; // 出生地区
  8367. pdfData.Add("birth_place", area);
  8368. pdfData.Add("birth_country", "中国"); // 出生国籍
  8369. pdfData.Add("current_nationality", "中国"); // 现国籍
  8370. pdfData.Add("birth_nationality", ""); // 出生国籍
  8371. pdfData.Add("other_nacionality", ""); // 其他国籍
  8372. pdfData.Add("sex", custInfo.Sex.ToString()); // 性别
  8373. pdfData.Add("marriage", custInfo.Marriage.ToString()); // 婚姻
  8374. pdfData.Add("legal_guardian_info", ""); // 国民身份号码
  8375. pdfData.Add("national_identity_number", idCard); // 父母的监护权(针对未成年人)/法定监护人
  8376. string applicantAddressAndEmail = $"{custInfo.Address} {custInfo.Email}";
  8377. pdfData.Add("applicant_address_and_email", applicantAddressAndEmail); // 申请人的家庭住址和电子邮箱地址
  8378. pdfData.Add("applicant_tel", custInfo.Tel); // 申请人的电话
  8379. #endregion
  8380. #region 护照信息
  8381. int passportType = passportInfo?.PassportType ?? 0;
  8382. var visatypeInfo = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == passportType);
  8383. pdfData.Add("passport_type_name", visatypeInfo?.Name ?? "");// 护照类型
  8384. pdfData.Add("travel_number", passportInfo?.CertNo ?? ""); // 签证 编号
  8385. pdfData.Add("travel_issues_country", passportInfo?.Country ?? "");// 签发 国
  8386. pdfData.Add("travel_issue_date", passportInfo?.IssueDt?.ToString("yyyy-MM-dd") ?? ""); // 签发日期
  8387. pdfData.Add("travel_valid_until", passportInfo?.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); // 有效期至
  8388. #endregion
  8389. #region 欧盟家庭成员个人信息
  8390. pdfData.Add("ue_family_info", ""); // 个人信息
  8391. pdfData.Add("ue_family_surname", ""); // 姓氏(家族名)
  8392. pdfData.Add("ue_family_firstname", ""); // 名字(名字)
  8393. pdfData.Add("ue_family_birthday", ""); // 出生日期 (日-月-年)
  8394. pdfData.Add("ue_family_nationality", ""); // 国籍
  8395. pdfData.Add("ue_family_travel_number", "");// 旅行证件或身份证号码
  8396. #endregion
  8397. #region 欧盟家庭关系 默认其他值
  8398. pdfData.Add("eu_family_relationship_other", "Off"); // 其他
  8399. pdfData.Add("eu_family_relationship_other_specify", ""); // 其他
  8400. #endregion
  8401. #region 是否在非国籍国居住 默认否
  8402. //pdfData.Add("unresidente_no", "Yes"); // 否
  8403. //pdfData.Add("unresidente_yes", "Off"); // 是
  8404. //pdfData.Add("unresidente_equivalen", ""); // 居住许可证
  8405. //pdfData.Add("unresidente_number", ""); // 编号
  8406. //pdfData.Add("unresidente_vaild", ""); // 有效期限
  8407. #endregion
  8408. #region 此次行程的目的
  8409. var visit_purpose = groupInfo.VisitPurpose;
  8410. if (!string.IsNullOrEmpty(visit_purpose))
  8411. {
  8412. if (visit_purpose.contains("旅游"))
  8413. {
  8414. pdfData.Add("purpose", "tourism"); // 旅游
  8415. }
  8416. else if (visit_purpose.contains("商务"))
  8417. {
  8418. pdfData.Add("purpose", "business"); // 商务
  8419. }
  8420. else if (visit_purpose.contains("亲友"))
  8421. {
  8422. pdfData.Add("purpose", "visiting_family_friends"); // 庆祝亲友团聚
  8423. }
  8424. else if (visit_purpose.contains("文化交流") || visit_purpose.contains("旅游"))
  8425. {
  8426. pdfData.Add("purpose", "cultural"); // 文化交流
  8427. }
  8428. else if (visit_purpose.contains("体育"))
  8429. {
  8430. pdfData.Add("purpose", "sports"); // 体育
  8431. }
  8432. else if (visit_purpose.contains("官方访问"))
  8433. {
  8434. pdfData.Add("purpose", "official"); // 官方访问
  8435. }
  8436. else if (visit_purpose.contains("医疗原因") || visit_purpose.contains("医疗"))
  8437. {
  8438. pdfData.Add("purpose", "medical_reasons"); // 医疗原因
  8439. }
  8440. else if (visit_purpose.contains("学习"))
  8441. {
  8442. pdfData.Add("purpose", "study"); // 学习
  8443. }
  8444. else if (visit_purpose.contains("机场中转") || visit_purpose.contains("过境"))
  8445. {
  8446. pdfData.Add("purpose", "airport_transit"); // 机场过境
  8447. }
  8448. else
  8449. {
  8450. pdfData.Add("purpose", "other"); // 其他
  8451. pdfData.Add("purpose_other_specify", ""); // 其他 - 备注
  8452. }
  8453. }
  8454. else
  8455. {
  8456. pdfData.Add("purpose", "other"); // 其他
  8457. pdfData.Add("purpose_other_specify", ""); // 其他 - 备注
  8458. }
  8459. #endregion
  8460. #region 职业
  8461. // 当前职业
  8462. string employer_info = string.Empty;
  8463. // 雇主及雇主的地址和电话号码。
  8464. string occupation = string.Empty;
  8465. // 职业信息
  8466. if (companyInfos != null && companyInfos.Count > 0)
  8467. {
  8468. occupation = companyInfos.FirstOrDefault()?.Job ?? "";
  8469. employer_info = $"{companyInfos.FirstOrDefault()?.Company ?? ""} {companyInfos.FirstOrDefault()?.CompanyAddress ?? ""} {companyInfos.FirstOrDefault()?.Phone ?? ""}";
  8470. }
  8471. pdfData.Add("employer_info", employer_info);
  8472. pdfData.Add("occupation", occupation);
  8473. #endregion
  8474. #region 停留信息
  8475. // 关于停留目的的补充说明
  8476. pdfData.Add("stay_info", "");
  8477. string[] country = new string[] { }; //接收处理的国家
  8478. string firstEntryLabel = string.Empty; // 首入申根国标签
  8479. string membeDescLabel = string.Empty; // 申根国目的地
  8480. string RuJingTime = string.Empty; // 入境时间
  8481. string LiJingTime = string.Empty; // 离境时间
  8482. string stayDays = string.Empty; // 停留天数
  8483. if (!string.IsNullOrEmpty(groupInfo.VisitCountry))
  8484. {
  8485. List<string> SGGNames = new List<string>();//接收处理后的国家 是申根国
  8486. if (groupInfo.VisitCountry.Contains(","))
  8487. country = groupInfo.VisitCountry.Split(',');
  8488. else if (groupInfo.VisitCountry.Contains(' '))
  8489. country = groupInfo.VisitCountry.Split(' ');
  8490. else if (groupInfo.VisitCountry.Contains(","))
  8491. country = groupInfo.VisitCountry.Split(',');
  8492. else if (groupInfo.VisitCountry.Contains("、"))
  8493. country = groupInfo.VisitCountry.Split('、');
  8494. else if (groupInfo.VisitCountry.Contains("|"))
  8495. country = groupInfo.VisitCountry.Split('|');
  8496. //判断是否是申根国家
  8497. for (int i = 0; i < country.Length; i++)
  8498. {
  8499. if (country[i].ToString() != null)
  8500. {
  8501. //在申根国家中筛选 该国家是否是申根国家
  8502. for (int j = 0; j < _shenGenGuos.Length; j++)
  8503. {
  8504. if (country[i] == _shenGenGuos[j])
  8505. SGGNames.Add(_shenGenGuos[j]); //添加申根国
  8506. }
  8507. }
  8508. }
  8509. //目的地国是否有申根国
  8510. if (SGGNames.Count > 0)
  8511. {
  8512. firstEntryLabel = SGGNames.First();
  8513. membeDescLabel = string.Join(",", SGGNames.ToArray());
  8514. //接收生根国详细信息 存储顺序 起飞日期:Day 起飞时刻:StartTime 抵达日期:ArrivedDate 到达时刻:EndTime
  8515. List<SSGDetails> ListSSGDetails = new List<SSGDetails>();
  8516. //处理申根国家 预定到达时间 预定离开时间 预定停留天数
  8517. for (int i = 0; i < SGGNames.Count; i++)
  8518. {
  8519. //在相同的国家下 得到该航班的信息 //抵达时间 起飞日期:Day 起飞时刻:StartTime 到达时刻:EndTime 抵达日期:ArrivedDate 飞行时间:FlightTime 航司 Fliagtcode 入境口岸
  8520. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  8521. //ResidenceTime1 机票三字码信息
  8522. if (atbc != null)
  8523. {
  8524. string HL_Three = ""; //三字码 Three
  8525. for (int j = 0; j < atbc.Rows.Count; j++)
  8526. {
  8527. HL_Three = atbc.Rows[j]["Three"].ToString();
  8528. if (!string.IsNullOrEmpty(HL_Three))
  8529. {
  8530. string threeCodeTwo = HL_Three.Substring(3);
  8531. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  8532. if (tc != null)
  8533. {
  8534. //首入申根国时间
  8535. if (SGGNames[i] == tc.Country)
  8536. {
  8537. SSGDetails SSGDetails = new SSGDetails()
  8538. {
  8539. Three = atbc.Rows[j]["Three"].ToString(), //三字码
  8540. Fliagtcode = atbc.Rows[j]["Fliagtcode"].ToString(), //航司
  8541. startDate = atbc.Rows[j]["Day"].ToString(), //整理起飞日期
  8542. startTime = atbc.Rows[j]["StartTime"].ToString(), //整理起飞时刻
  8543. endDate = atbc.Rows[j]["ArrivedDate"].ToString(), //整理抵达日期
  8544. endTime = atbc.Rows[j]["EndTime"].ToString() //整理抵达时刻
  8545. };
  8546. ListSSGDetails.Add(SSGDetails);
  8547. }
  8548. }
  8549. }
  8550. }
  8551. }
  8552. }
  8553. ListSSGDetails.Sort((a, b) => a.startDate.CompareTo(b.startDate));
  8554. //得到并计算出入境时间
  8555. if (ListSSGDetails != null)
  8556. {
  8557. RuJingTime = ListSSGDetails.First().endDate + " " + ListSSGDetails.First().endTime.Substring(0, 2) + ":" + ListSSGDetails.First().endTime.Substring(2); //入境时间
  8558. LiJingTime = ListSSGDetails[ListSSGDetails.Count - 1].startDate + " " + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(0, 2) + ":" + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(2); //离境时间
  8559. stayDays = Convert.ToDateTime(LiJingTime).Subtract(Convert.ToDateTime(RuJingTime)).Days.ToString();
  8560. }
  8561. }
  8562. }
  8563. pdfData.Add("member_destination", membeDescLabel); // 主要目的地成员国(如适用,还包括目的地的其他成员国)
  8564. pdfData.Add("member_first_entry", firstEntryLabel); // 首入申根国标签
  8565. pdfData.Add("stayDays", stayDays); // 停留天数
  8566. pdfData.Add("request_entry", "1"); // 申请入境次数(默认一次) 1:一次入境 2:两次入境 3:多次入境
  8567. pdfData.Add("schengen_first_area_arrival", RuJingTime); // 首次抵达日期
  8568. pdfData.Add("schengen_first_area_departure", LiJingTime); // 首次离开日期
  8569. #endregion
  8570. #region 此前录过指纹
  8571. pdfData.Add("schengen_fingerprints_status", "1"); // 1 是 2 否 默认 否
  8572. //pdfData.Add("schengen_fingerprints_date", ""); // 如有,请写明日期
  8573. //pdfData.Add("schengen_fingerprints_visa_no", ""); // 编号
  8574. #endregion
  8575. #region 最终目的地入境许可
  8576. pdfData.Add("entry_permit_issued", ""); // 发布者
  8577. pdfData.Add("entry_permit_valid", ""); // 有效期限 起
  8578. pdfData.Add("entry_permit_until", ""); // 有效期限 止
  8579. #endregion
  8580. #region 邀请人/酒店信息
  8581. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  8582. .Where(x => x.DiId == groupId)
  8583. //.Where(x => x.City.contains(city))
  8584. .First();
  8585. //酒店住址
  8586. pdfData.Add("schengen_inviting_name", hotelInfo?.HotelName ?? ""); // 招待方的酒店、邀请人 名称
  8587. var otherInfo = $"{hotelInfo?.HotelAddress ?? ""}";
  8588. pdfData.Add("schengen_inviting_hotel_address_email", otherInfo); // 酒店/临时住宿场所的地址和电子邮箱地址
  8589. pdfData.Add("schengen_inviting_hotel_tel", hotelInfo?.HotelTel ?? ""); // 电话号码
  8590. #endregion
  8591. #region 邀请公司/组织信息
  8592. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  8593. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  8594. //.Where(x => x.Country.Contains(county))
  8595. //.Where(x => x.Area.Contains(city))
  8596. .First();
  8597. string oaInfo = $"{oa?.Client ?? ""} {oa?.Address ?? ""}";
  8598. pdfData.Add("inviting_name_address", oaInfo); // 邀请公司/组织的名称及地址
  8599. string contactInfo = $"{oa?.Contact ?? ""} {oa?.Tel ?? ""} {oa?.EmailOrWeChat ?? ""}";
  8600. pdfData.Add("inviting_info", contactInfo); // 公司/组织中联系人的姓氏、名字、地址、电话号码以及电子邮箱地址
  8601. pdfData.Add("inviting_tel", oa?.Tel ?? ""); // 电话号码(关于)公司/组织
  8602. #endregion
  8603. // 由赞助方(主办方、公司、组织)提供 - 其他(请具体说明) 默认单位名称
  8604. pdfData.Add("cost_covered_sponsor_other_specify", companyInfos.FirstOrDefault()?.Company ?? "");
  8605. #endregion
  8606. #endregion
  8607. #region 通过 DeepSeek AI实现中文转英文 language == 2 时转换 英文
  8608. if (language == 2)
  8609. {
  8610. pdfData = await DeepSeekCNToENAsync(JsonConvert.SerializeObject(pdfData));
  8611. }
  8612. #endregion
  8613. return pdfData;
  8614. }
  8615. /// <summary>
  8616. /// 通过 DeepSeek AI实现中文转英文
  8617. /// </summary>
  8618. /// <param name="jsonstring"></param>
  8619. /// <returns></returns>
  8620. private async Task<Dictionary<string, string>> DeepSeekCNToENAsync(string jsonstring)
  8621. {
  8622. var dic = new Dictionary<string, string>();
  8623. string question = $@"JSON中文字段转英文大写
  8624. 任务
  8625. 将JSON中所有中文字段值转换为英文,并全部大写。
  8626. 输入数据
  8627. {jsonstring}
  8628. 转换规则
  8629. 1.中文姓名:拼音转换,姓氏单字,名字连写
  8630. 2.中文地址:按层级翻译(中国→CHINA,省/市/区→拼音+PROVINCE/CITY/DISTRICT,街道建筑→拼音)
  8631. 3.公司名称:标准英文译名
  8632. 4.国家/国籍:CHINA
  8633. 5.枚举值:other→OTHER,但Yes/Off保持原样不变
  8634. 6.全部大写:所有转换后的英文字母转大写(Yes/Off除外)
  8635. 7.空值:保持不变
  8636. 输出
  8637. 保持JSON结构不变,只转换中文内容。只返回JSON结构体。";
  8638. var deepseek_result = await _deepSeekService.ChatAsync(question);
  8639. if (deepseek_result.Success)
  8640. {
  8641. _logger.LogInformation("【签证文件下载】【DeepSeekAI】中文转英文完成!消耗Token:{TokensUsed}", deepseek_result.TokensUsed);
  8642. try
  8643. {
  8644. string rawJson = deepseek_result.Answer ?? "";
  8645. // 核心优化:清洗 Markdown 代码块标识 (```json ... ```)
  8646. if (rawJson.Contains("```"))
  8647. {
  8648. rawJson = rawJson.Replace("```json", "").Replace("```", "").Trim();
  8649. }
  8650. // 使用 Newtonsoft.Json 解析
  8651. dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(rawJson);
  8652. if (dic == null)
  8653. {
  8654. _logger.LogWarning("【签证文件下载】警告:解析后的字典为空。内容:{RawJson}", rawJson);
  8655. }
  8656. }
  8657. catch (JsonReaderException jex)
  8658. {
  8659. // 专门捕获 JSON 格式错误
  8660. _logger.LogError("【签证文件下载】【DeepSeekAI】JSON 语法错误:{Message}", jex.Message);
  8661. }
  8662. catch (Exception ex)
  8663. {
  8664. _logger.LogError("【签证文件下载】【DeepSeekAI】系统异常:{ErrorMessage}", ex.Message);
  8665. }
  8666. }
  8667. return dic;
  8668. }
  8669. #region iTextSharp pdf 设置值辅助方法
  8670. /// <summary>
  8671. /// 设置文本值
  8672. /// 辅助方法
  8673. /// </summary>
  8674. /// <param name="formFields"></param>
  8675. /// <param name="fieldName"></param>
  8676. /// <param name="value"></param>
  8677. private static void SetFieldValue(AcroFields formFields, string fieldName, string value)
  8678. {
  8679. if (formFields.Fields.ContainsKey(fieldName) && !string.IsNullOrEmpty(value))
  8680. {
  8681. formFields.SetField(fieldName, value);
  8682. }
  8683. }
  8684. /// <summary>
  8685. /// Word填充书签
  8686. /// </summary>
  8687. /// <param name="doc"></param>
  8688. /// <param name="builder"></param>
  8689. /// <param name="bookmarkName"></param>
  8690. /// <param name="value"></param>
  8691. private void FillBookmark(Document doc, DocumentBuilder builder, string bookmarkName, string value)
  8692. {
  8693. if (doc.Range.Bookmarks[bookmarkName] != null)
  8694. {
  8695. builder.MoveToBookmark(bookmarkName);
  8696. builder.Write(value ?? "");
  8697. }
  8698. }
  8699. #endregion
  8700. #region 文档下载辅助实体类
  8701. private class VisaDateView
  8702. {
  8703. /// <summary>
  8704. /// 团组信息
  8705. /// </summary>
  8706. public Grp_DelegationInfo groupInfo { get; set; }
  8707. /// <summary>
  8708. /// 身份证信息
  8709. /// </summary>
  8710. public Crm_CustomerCert idInfo { get; set; }
  8711. /// <summary>
  8712. /// 护照信息
  8713. /// </summary>
  8714. public Crm_CustomerCert passportInfo { get; set; }
  8715. /// <summary>
  8716. /// 客户信息
  8717. /// </summary>
  8718. public Crm_DeleClient custInfo { get; set; }
  8719. /// <summary>
  8720. /// 学校资料
  8721. /// </summary>
  8722. public List<Crm_VisaCustomerSchool> schoolInfos { get; set; }
  8723. /// <summary>
  8724. /// 家庭成员资料
  8725. /// </summary>
  8726. public List<Crm_VisaCustomerFamily> familyInfos { get; set; }
  8727. /// <summary>
  8728. /// 公司资料
  8729. /// </summary>
  8730. public List<Crm_VisaCustomerCompany> companyInfos { get; set; }
  8731. }
  8732. private class SSGDetails
  8733. {
  8734. public string Three { get; set; } //三字码
  8735. public string Fliagtcode { get; set; } //航司
  8736. public string startDate { get; set; } //首入申根国日期
  8737. public string startTime { get; set; } //首入申根国时间
  8738. public string endDate { get; set; } //离开申根国日期
  8739. public string endTime { get; set; } //离开申根国时间
  8740. }
  8741. /// <summary>
  8742. /// 文件生成请求体
  8743. /// </summary>
  8744. private class GeneratorFileReq
  8745. {
  8746. public int groupId { get; set; }
  8747. public int fileTypeId { get; set; }
  8748. public int dcIds { get; set; }
  8749. /// <summary>
  8750. /// 模板存储地址
  8751. /// </summary>
  8752. public string tempPath { get; set; } = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Template/";
  8753. public string fileServerPath { get; set; }
  8754. public int language { get; set; } = 1;
  8755. public DataBody dataBody { get; set; }
  8756. }
  8757. private class DataBody
  8758. {
  8759. public Grp_DelegationInfo groupInfo { get; set; }
  8760. public List<Grp_TourClientList> groupClients { get; set; }
  8761. public List<Crm_DeleClient> groupCustInfos { get; set; }
  8762. public List<Crm_VisaCustomerFamily> familyInfos { get; set; }
  8763. public List<Crm_CustomerCert> certInfos { get; set; }
  8764. public List<Crm_VisaCustomerCompany> companyInfos { get; set; }
  8765. public List<Crm_VisaCustomerSchool> schoolInfos { get; set; }
  8766. }
  8767. #endregion
  8768. #endregion
  8769. /// <summary>
  8770. /// 根据团组Id获取签证客户信息List
  8771. /// </summary>
  8772. /// <param name="dto">请求dto</param>
  8773. /// <returns></returns>
  8774. [HttpPost]
  8775. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8776. public async Task<IActionResult> GetCrmByGroupId(ClientByGroupIdDto dto)
  8777. {
  8778. var data = await _groupRepository.GetCrmByGroupId(dto);
  8779. return Ok(JsonView(data.Code == 0, data.Code != 0 ? "暂无信息" : "操作成功", data.Data));
  8780. }
  8781. /// <summary>
  8782. /// IOS获取团组签证拍照上传进度01(团组列表)
  8783. /// </summary>
  8784. /// <param name="dto">请求dto</param>
  8785. /// <returns></returns>
  8786. [HttpPost]
  8787. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8788. public async Task<IActionResult> PostIOSVisaProgress(IOS_VisaDto dto)
  8789. {
  8790. if (dto == null)
  8791. {
  8792. return Ok(JsonView(false, "参数为空"));
  8793. }
  8794. DelegationVisaViewList visaList = _delegationVisaRep.GetDelegationList(dto);
  8795. return Ok(JsonView(visaList));
  8796. }
  8797. /// <summary>
  8798. /// IOS获取团组签证拍照上传进度02(团组签证详情\人员列表\国家)
  8799. /// </summary>
  8800. /// <returns></returns>
  8801. [HttpPost]
  8802. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8803. public async Task<ActionResult> PostIOSVisaProgressContent(IOS_VisaCustomerListDto dto)
  8804. {
  8805. if (dto == null)
  8806. {
  8807. return Ok(JsonView(false, "请求错误:"));
  8808. }
  8809. List<DelegationVisaProgressView> list = _delegationVisaRep.GetDelegationProgressList(dto.diId);
  8810. return Ok(JsonView(list));
  8811. }
  8812. /// <summary>
  8813. /// IOS获取团组签证拍照上传进度03(相册)
  8814. /// </summary>
  8815. /// <returns></returns>
  8816. [HttpPost]
  8817. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8818. public async Task<ActionResult> PostIOSVisaProgressImageList(IOS_VisaImageListDto dto)
  8819. {
  8820. if (dto == null)
  8821. {
  8822. return Ok(JsonView(false, "请求错误:"));
  8823. }
  8824. List<VisaProgressImageView> list = _delegationVisaRep.GetVisaProgressImageList(dto.visaProgressCustomerId, dto.picType);
  8825. string url = AppSettingsHelper.Get("VisaProgressImageBaseUrl") + AppSettingsHelper.Get("VisaProgressImageFtpPath");
  8826. list.ForEach(s => s.url = url);
  8827. return Ok(JsonView(list));
  8828. }
  8829. /// <summary>
  8830. /// IOS获取团组签证拍照上传进度04(图片上传)
  8831. /// </summary>
  8832. /// <param name="dto"></param>
  8833. /// <returns></returns>
  8834. [HttpPost]
  8835. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8836. public async Task<ActionResult> PostIOSVisaProgressUploadImage(IOS_VisaUploadImageDto dto)
  8837. {
  8838. //string result = decodeBase64ToImage(dto.base64DataURL, dto.imageName);
  8839. //if (!string.IsNullOrEmpty(result))
  8840. //{
  8841. //}
  8842. //else {
  8843. // return Ok(JsonView(false, "上传失败"));
  8844. //}
  8845. var dt1970 = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  8846. int sucNum = 0;
  8847. try
  8848. {
  8849. foreach (var item in dto.base64DataList)
  8850. {
  8851. string imageName = dto.imageName + ((DateTime.Now.Ticks - dt1970.Ticks) / 10000).ToString();
  8852. string result = DecodeBase64ToImage(item, imageName);
  8853. if (!string.IsNullOrEmpty(result))
  8854. {
  8855. var pic = new Grp_VisaProgressCustomerPicture
  8856. {
  8857. CreateUserId = dto.CreateUserId,
  8858. PicName = imageName,
  8859. PicPath = result,
  8860. VisaProgressCustomerId = dto.visaProgressCustomerId
  8861. };
  8862. int insertResult = await _delegationVisaRep.AddAsync<Grp_VisaProgressCustomerPicture>(pic);
  8863. if (insertResult > 0)
  8864. {
  8865. sucNum++;
  8866. }
  8867. }
  8868. }
  8869. }
  8870. catch (Exception ex)
  8871. {
  8872. return Ok(JsonView(false, ex.Message));
  8873. }
  8874. string msg = string.Format(@"成功上传{0}张", sucNum);
  8875. return Ok(JsonView(true, msg));
  8876. }
  8877. private string DecodeBase64ToImage(string base64DataURL, string imgName)
  8878. {
  8879. string filename = "";//声明一个string类型的相对路径
  8880. String base64 = base64DataURL.Substring(base64DataURL.IndexOf(",") + 1); //将‘,’以前的多余字符串删除
  8881. System.Drawing.Bitmap bitmap = null;//定义一个Bitmap对象,接收转换完成的图片
  8882. try//会有异常抛出,try,catch一下
  8883. {
  8884. byte[] arr = Convert.FromBase64String(base64);//将纯净资源Base64转换成等效的8位无符号整形数组
  8885. var ms = new System.IO.MemoryStream(arr);//转换成无法调整大小的MemoryStream对象
  8886. bitmap = new System.Drawing.Bitmap(ms);//将MemoryStream对象转换成Bitmap对象
  8887. var fileDir = AppSettingsHelper.Get("VisaProgressImageBasePath");
  8888. //文件名称
  8889. filename = "VisaProgress_" + DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + imgName + ".jpeg";//所要保存的相对路径及名字
  8890. //上传的文件的路径
  8891. string filePath = "";
  8892. if (!Directory.Exists(fileDir))
  8893. {
  8894. Directory.CreateDirectory(fileDir);
  8895. }
  8896. //上传的文件的路径
  8897. filePath = fileDir + filename;
  8898. //string url = HttpRuntime.AppDomainAppPath.ToString();
  8899. //string tmpRootDir = System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString()); //获取程序根目录
  8900. //string imagesurl2 = tmpRootDir + filename; //转换成绝对路径
  8901. bitmap.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);//保存到服务器路径
  8902. //bitmap.Save(filePath + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
  8903. //bitmap.Save(filePath + ".gif", System.Drawing.Imaging.ImageFormat.Gif);
  8904. //bitmap.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
  8905. ms.Close();//关闭当前流,并释放所有与之关联的资源
  8906. bitmap.Dispose();
  8907. }
  8908. catch (Exception e)
  8909. {
  8910. string massage = e.Message;
  8911. Logs("IOS图片上传Error:" + massage);
  8912. //filename = e.Message;
  8913. }
  8914. return filename;//返回相对路径
  8915. }
  8916. /// <summary>
  8917. /// IOS获取团组签证拍照上传进度05(修改签证状态/通知)
  8918. /// </summary>
  8919. /// <param name="dto"></param>
  8920. /// <returns></returns>
  8921. [HttpPost]
  8922. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8923. public async Task<ActionResult> PostIOSVisaProgressChangeStatus(IOS_VisaChangeStatusDto dto)
  8924. {
  8925. if (dto == null)
  8926. {
  8927. return Ok(JsonView(false, "请求错误:"));
  8928. }
  8929. string msg = "参数错误";
  8930. if (dto.diId > 0 && dto.visaStatus > 0 && dto.visaStatus < 4)
  8931. {
  8932. try
  8933. {
  8934. //_delegationVisaRep.BeginTran();
  8935. var updCount = await _delegationVisaRep._sqlSugar.Updateable<Grp_VisaProgressCustomer>()
  8936. .SetColumns(it => it.WorkStatus == dto.visaStatus)
  8937. .Where(s => s.Id == dto.visaProgressCustomerId)
  8938. .ExecuteCommandAsync();
  8939. if (updCount > 0 && dto.publishCode == 1)
  8940. {
  8941. _delegationVisaRep.ChangeDataBase(DBEnum.OA2014DB); //切换到新OA后删除
  8942. string sqlDelegation = string.Format(@" Select * From DelegationInfo With(Nolock) Where Id = {0} ", dto.diId);
  8943. OA2021_DelegationInfo groupData = _sqlSugar.SqlQueryable<OA2021_DelegationInfo>(sqlDelegation).First();
  8944. //GroupInfoDto grpDto = new GroupInfoDto() { Id = dto.diId };
  8945. //var groupData = await _groupRepository.GetGroupInfo(grpDto);
  8946. _delegationVisaRep.ChangeDataBase(DBEnum.OA2023DB); //切换到新OA后删除
  8947. if (groupData == null)
  8948. {
  8949. _delegationVisaRep.RollbackTran();
  8950. }
  8951. string title = string.Format(@"[签证进度更新]");
  8952. string content = string.Format(@"测试文本");
  8953. bool rst = await _message.AddMsg(new MessageDto()
  8954. {
  8955. Type = MessageTypeEnum.GroupVisaProgressUpdate,
  8956. IssuerId = dto.publisher,
  8957. Title = title,
  8958. Content = content,
  8959. ReleaseTime = DateTime.Now,
  8960. UIdList = new List<int> {
  8961. 234
  8962. }
  8963. });
  8964. if (rst)
  8965. {
  8966. return Ok(JsonView(true, "发送通知成功"));
  8967. }
  8968. }
  8969. //_delegationVisaRep.CommitTran();
  8970. }
  8971. catch (Exception)
  8972. {
  8973. //_delegationVisaRep.RollbackTran();
  8974. }
  8975. }
  8976. return Ok(JsonView(true, msg));
  8977. }
  8978. #endregion
  8979. #endregion
  8980. #region 团组任务分配
  8981. /// <summary>
  8982. /// 团组任务分配初始化
  8983. /// </summary>
  8984. /// <returns></returns>
  8985. [HttpPost]
  8986. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8987. public async Task<IActionResult> GetTaskAssignmen()
  8988. {
  8989. var groupData = await _taskAssignmentRep.GetTaskAssignmen();
  8990. if (groupData.Code != 0)
  8991. {
  8992. return Ok(JsonView(false, groupData.Msg));
  8993. }
  8994. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  8995. }
  8996. /// <summary>
  8997. /// 团组任务分配查询
  8998. /// </summary>
  8999. /// <param name="dto"></param>
  9000. /// <returns></returns>
  9001. [HttpPost]
  9002. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9003. public async Task<IActionResult> TaskAssignmenQuery(TaskAssignmenQueryDto dto)
  9004. {
  9005. var groupData = await _taskAssignmentRep.TaskAssignmenQuery(dto);
  9006. if (groupData.Code != 0)
  9007. {
  9008. return Ok(JsonView(false, groupData.Msg));
  9009. }
  9010. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  9011. }
  9012. /// <summary>
  9013. /// 团组任务分配操作
  9014. /// </summary>
  9015. /// <param name="dto"></param>
  9016. /// <returns></returns>
  9017. [HttpPost]
  9018. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9019. public async Task<IActionResult> GetTaskAssignmenOp(TaskAssignmenDto dto)
  9020. {
  9021. Result groupData = await _taskAssignmentRep.GetTaskAssignmenOp(dto);
  9022. if (groupData.Code != 0)
  9023. {
  9024. return Ok(JsonView(false, groupData.Msg));
  9025. }
  9026. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  9027. }
  9028. /// <summary>
  9029. /// 团组任务分配
  9030. /// 批量分配
  9031. /// 查询团组
  9032. /// </summary>
  9033. /// <param name="dto"></param>
  9034. /// <returns></returns>
  9035. [HttpPost]
  9036. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9037. public async Task<IActionResult> TaskAllocationGroupSelect(TaskAllocationGroupSelectDto dto)
  9038. {
  9039. //参数验证
  9040. if (dto.PortType < 1 || dto.PortType > 3) return Ok(JsonView(false, MsgTips.Port));
  9041. if (!DateTime.TryParse(dto.VisitBeginDt, out _) || !DateTime.TryParse(dto.VisitEndDt, out _))
  9042. return Ok(JsonView(false, "团组出访开始/结束日期格式不正确!"));
  9043. return Ok(await _taskAssignmentRep.TaskAllocationGroupSelect(dto));
  9044. }
  9045. /// <summary>
  9046. /// 团组任务分配
  9047. /// 批量分配
  9048. /// </summary>
  9049. /// <param name="dto"></param>
  9050. /// <returns></returns>
  9051. [HttpPost]
  9052. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9053. public async Task<IActionResult> TaskAllocationBulkAdd(TaskAllocationBulkAddDto dto)
  9054. {
  9055. //参数验证
  9056. if (dto.UserIds.Length < 1) return Ok(JsonView(false, $"请选择分配人员!"));
  9057. if (dto.PermissionTypeIds.Length < 1) return Ok(JsonView(false, $"请选择分配类型!"));
  9058. if (dto.GroupIds.Length < 1) return Ok(JsonView(false, "请选择分配团组Id"));
  9059. if (dto.CurrUserId < 1) return Ok(JsonView(false, "请传入有效的CurrUserId数组参数"));
  9060. return Ok(await _taskAssignmentRep.TaskAllocationBulkAdd(dto));
  9061. }
  9062. #endregion
  9063. #region 团组费用审核
  9064. /// <summary>
  9065. /// 费用审核
  9066. /// 团组列表 Page
  9067. /// </summary>
  9068. /// <param name="dto">团组列表请求dto</param>
  9069. /// <returns></returns>
  9070. [HttpPost]
  9071. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9072. public async Task<IActionResult> PostExpenseAuditGroupPageItems(ExpenseAuditGroupPageItemsDto dto)
  9073. {
  9074. #region 参数验证
  9075. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  9076. if (dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  9077. #region 页面操作权限验证
  9078. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  9079. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  9080. #endregion
  9081. #endregion
  9082. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) // web/Android/IOS
  9083. {
  9084. string sqlWhere = "WHERE gdi.IsDel = 0";
  9085. var parameters = new List<SugarParameter>();
  9086. // 状态条件(保持不变)
  9087. if (dto.IsSure >= 0)
  9088. {
  9089. sqlWhere += $" AND IsSure = {dto.IsSure}";
  9090. }
  9091. // 搜索条件
  9092. if (!string.IsNullOrEmpty(dto.SearchCriteria))
  9093. {
  9094. // 将搜索词按空格分割为多个关键字(支持多关键字检索)
  9095. var keywords = dto.SearchCriteria.Split(new[] { ' ', ',', ',' }, StringSplitOptions.RemoveEmptyEntries);
  9096. if (keywords.Length > 0)
  9097. {
  9098. var searchConditions = new List<string>();
  9099. foreach (var keyword in keywords)
  9100. {
  9101. if (!string.IsNullOrWhiteSpace(keyword))
  9102. {
  9103. // 对每个关键字构建多字段检索条件
  9104. var keywordConditions = new List<string>
  9105. {
  9106. $"ssd.Name LIKE '%{keyword}%'",
  9107. $"gdi.TeamName LIKE '%{keyword}%'",
  9108. $"gdi.ClientName LIKE '%{keyword}%'",
  9109. $"su.CnName LIKE '%{keyword}%'",
  9110. $"gdi.SalesQuoteNo LIKE '%{keyword}%'",
  9111. $"gdi.TourCode LIKE '%{keyword}%'",
  9112. $"gdi.ClientUnit LIKE '%{keyword}%'",
  9113. $"ssd1.Name LIKE '%{keyword}%'"
  9114. };
  9115. // 将多个字段条件用 OR 连接
  9116. searchConditions.Add($"({string.Join(" OR ", keywordConditions)})");
  9117. }
  9118. }
  9119. // 将多个关键字条件用 AND 连接(实现多关键字AND搜索)
  9120. if (searchConditions.Count > 0)
  9121. {
  9122. sqlWhere += $" AND ({string.Join(" AND ", searchConditions)})";
  9123. }
  9124. }
  9125. }
  9126. // 基础查询sql
  9127. string sql = $@"
  9128. SELECT Row_Number, Id, SalesQuoteNo, TourCode, TeamTypeId, TeamType,
  9129. TeamName, ClientName, ClientUnit, TeamLevId, TeamLev, VisitDate,
  9130. VisitDays, VisitPNumber, JietuanOperator, IsSure, CreateTime
  9131. FROM (
  9132. SELECT ROW_NUMBER() OVER (ORDER BY gdi.VisitDate DESC) AS Row_Number,
  9133. gdi.Id, gdi.SalesQuoteNo, gdi.TourCode,
  9134. ssd1.Id AS TeamLevId, ssd1.Name AS TeamLev,
  9135. gdi.TeamName, gdi.ClientName, gdi.ClientUnit,
  9136. ssd.Id AS TeamTypeId, ssd.Name AS TeamType,
  9137. gdi.VisitDate, gdi.VisitDays, gdi.VisitPNumber,
  9138. su.CnName AS JietuanOperator, gdi.IsSure, gdi.CreateTime
  9139. FROM Grp_DelegationInfo gdi
  9140. LEFT JOIN Sys_SetData ssd ON gdi.TeamDid = ssd.Id
  9141. LEFT JOIN Sys_SetData ssd1 ON gdi.TeamLevSId = ssd1.Id
  9142. LEFT JOIN Sys_Users su ON gdi.JietuanOperator = su.Id
  9143. {sqlWhere}
  9144. ) AS temp";
  9145. RefAsync<int> total = 0;
  9146. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql)
  9147. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  9148. var _view = new
  9149. {
  9150. PageFuncAuth = pageFunAuthView,
  9151. Data = _DelegationList
  9152. };
  9153. return Ok(JsonView(true, "查询成功!", _view, total));
  9154. }
  9155. else
  9156. {
  9157. return Ok(JsonView(false, "查询失败"));
  9158. }
  9159. }
  9160. /// <summary>
  9161. /// 获取团组费用审核
  9162. /// </summary>
  9163. /// <param name="_dto"></param>
  9164. /// <returns></returns>
  9165. [HttpPost]
  9166. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9167. public async Task<IActionResult> PostSearchGrpCreditCardPayment(Search_GrpCreditCardPaymentDto _dto)
  9168. {
  9169. try
  9170. {
  9171. #region 参数验证
  9172. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  9173. if (_dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  9174. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  9175. #region 页面操作权限验证
  9176. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  9177. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  9178. #endregion
  9179. #endregion
  9180. var _view = new Grp_CreditCardPaymentView();
  9181. var clientNameList = GetSimplClientList(_dto.DiId);
  9182. #region 费用清单
  9183. var exp = Expressionable.Create<Grp_CreditCardPayment>();
  9184. exp.AndIF(_dto.AuditStatus != -1, it => it.IsAuditGM == _dto.AuditStatus);
  9185. exp.AndIF(_dto.Label != -1, it => it.CTable == _dto.Label);
  9186. var entityList = _groupRepository.Query<Grp_CreditCardPayment>(s => s.DIId == _dto.DiId && s.IsDel == 0 && s.CreateUserId > 0).Where(exp.ToExpression()).ToList();
  9187. var detailList = new List<Grp_CreditCardPaymentDetailView>();
  9188. var ccpCurrencyPrices = new List<CreditCardPaymentCurrencyPriceItem>();
  9189. /*
  9190. * 76://酒店预订
  9191. */
  9192. var _HotelReservations = await _groupRepository.Query<Grp_HotelReservations>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9193. var _HotelReservationsContents = await _groupRepository.Query<Grp_HotelReservationsContent>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9194. /*
  9195. * 79://车/导游地接
  9196. */
  9197. var _CarTouristGuideGroundReservations = await _groupRepository.Query<Grp_CarTouristGuideGroundReservations>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9198. var _CarTouristGuideGroundReservationsContent = await _groupRepository.Query<Grp_CarTouristGuideGroundReservationsContent>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9199. /*
  9200. * 80: //签证
  9201. */
  9202. var _VisaInfos = await _groupRepository.Query<Grp_VisaInfo>(s => s.DIId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9203. /*
  9204. *81: //邀请/公务活动
  9205. */
  9206. var _InvitationOfficialActivities = await _groupRepository.Query<Grp_InvitationOfficialActivities>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9207. /*
  9208. * 82: //团组客户保险
  9209. */
  9210. var _Customers = await _groupRepository.Query<Grp_Customers>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9211. /*
  9212. * Lable = 85 机票预订
  9213. */
  9214. var p_AirTicketReservations = await _groupRepository.Query<Grp_AirTicketReservations>(s => s.DIId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9215. /*
  9216. * 85 机票预定
  9217. */
  9218. var _AirTicketReservations = await _groupRepository.Query<Grp_AirTicketReservations>(s => s.DIId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9219. /*
  9220. * 98 其他款项
  9221. */
  9222. var _DecreasePayments = await _groupRepository.Query<Grp_DecreasePayments>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9223. /*
  9224. * 285:收款退还
  9225. */
  9226. var _PaymentRefundAndOtherMoneys = await _groupRepository.Query<Fin_PaymentRefundAndOtherMoney>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9227. /*
  9228. * 1015: //超支费用
  9229. */
  9230. var _GroupExtraCosts = await _groupRepository.Query<Fin_GroupExtraCost>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9231. var initDatas = await _groupRepository.Query<Sys_SetData>(s => s.IsDel == 0).ToListAsync();
  9232. /*
  9233. * 币种信息
  9234. */
  9235. var currencyItems = initDatas.Where(s => s.STid == 66).ToList();
  9236. /*
  9237. * 车/导游地接 费用类型
  9238. */
  9239. var carFeeTypeItems = initDatas.Where(s => s.STid == 17).ToList();
  9240. /*
  9241. * 车/导游地接 费用类型
  9242. */
  9243. var carFeeItems = initDatas.Where(s => s.STid == 83).ToList();
  9244. var cityData = await _groupRepository.Query<Grp_NationalTravelFee>(s => s.IsDel == 0).ToListAsync();
  9245. /*
  9246. * 用户信息
  9247. */
  9248. var userItems = await _groupRepository._sqlSugar.Queryable<Sys_Users>().ToListAsync();
  9249. /*
  9250. * 费用模块
  9251. */
  9252. var sdPriceName = initDatas.Where(s => s.Id == _dto.Label).First();
  9253. string priceModule = string.Empty;
  9254. if (sdPriceName != null)
  9255. {
  9256. priceModule = sdPriceName.Name;
  9257. }
  9258. /*
  9259. * 成本信息
  9260. */
  9261. var groupCost = _groupRepository.Query<Grp_GroupCostParameter>(s => s.DiId == _dto.DiId && s.IsDel == 0).First();
  9262. decimal _groupRate = 0.0000M;
  9263. string _groupCurrencyCode = "-";
  9264. if (groupCost != null)
  9265. {
  9266. _groupRate = groupCost.Rate;
  9267. if (int.TryParse(groupCost.Currency, out int _currency))
  9268. {
  9269. _groupCurrencyCode = currencyItems.Find(it => it.Id == _currency)?.Name ?? "-";
  9270. }
  9271. else _groupCurrencyCode = groupCost.Currency;
  9272. }
  9273. string costContentSql = $"Select * From Grp_GroupCost";
  9274. var groupCostDetails = _sqlSugar.SqlQueryable<GroupCostAuditView>(costContentSql).Where(x => x.IsDel == 0 && x.Diid == _dto.DiId).ToList();
  9275. //处理日期为空的天数
  9276. for (int i = 0; i < groupCostDetails.Count; i++)
  9277. if (i != 0)
  9278. if (string.IsNullOrEmpty(groupCostDetails[i].Date))
  9279. groupCostDetails[i].Date = groupCostDetails[i - 1].Date;
  9280. /*
  9281. * 处理详情数据
  9282. */
  9283. foreach (var entity in entityList)
  9284. {
  9285. var _detail = new Grp_CreditCardPaymentDetailView
  9286. {
  9287. Id = entity.Id,
  9288. PriceName = priceModule,
  9289. PayType = initDatas.Find(it => it.Id == entity.PayDId)?.Name ?? "-"
  9290. };
  9291. if (_detail.PayType.Equals("现金")) _detail.CardType = "-";
  9292. else _detail.CardType = initDatas.Find(it => it.Id == entity.CTDId)?.Name ?? "-";
  9293. //处理金额
  9294. if (entity.CTable == 1015)
  9295. {
  9296. var czInfo = _GroupExtraCosts.Find(x => entity.CId == x.Id);
  9297. if (czInfo != null)
  9298. {
  9299. entity.PayMoney = czInfo.Price * czInfo.PriceCount;
  9300. entity.RMBPrice = czInfo.Price * czInfo.PriceCount * entity.DayRate;
  9301. }
  9302. }
  9303. /*
  9304. * 应付款金额
  9305. */
  9306. var sdPaymentCurrency_WaitPay = currencyItems.Where(s => s.Id == entity.PaymentCurrency).FirstOrDefault();
  9307. string PaymentCurrency_WaitPay = "Unknown";
  9308. string hotelCurrncyCode = "Unknown";
  9309. string hotelCurrncyName = "Unknown";
  9310. if (sdPaymentCurrency_WaitPay != null)
  9311. {
  9312. PaymentCurrency_WaitPay = sdPaymentCurrency_WaitPay.Name;
  9313. hotelCurrncyCode = sdPaymentCurrency_WaitPay.Name;
  9314. hotelCurrncyName = sdPaymentCurrency_WaitPay.Remark;
  9315. if (hotelCurrncyCode.Equals("CNY"))
  9316. {
  9317. entity.DayRate = 1.0000M;
  9318. }
  9319. }
  9320. _detail.WaitPay = entity.PayMoney.ConvertToDecimal1().ToString("#0.00") + " " + PaymentCurrency_WaitPay;
  9321. /*
  9322. * 此次付款金额
  9323. */
  9324. decimal CurrPayStr = 0.00M,
  9325. OriginalCurrPay = 0.00M;
  9326. if (entity.PayPercentage == 0)
  9327. {
  9328. if (entity.PayThenMoney != 0)
  9329. CurrPayStr = (entity.PayThenMoney * entity.DayRate).ConvertToDecimal1();
  9330. }
  9331. else
  9332. {
  9333. if (entity.PayMoney != 0)
  9334. {
  9335. CurrPayStr = (entity.PayMoney * entity.PayPercentage / 100 * entity.DayRate).ConvertToDecimal1();
  9336. }
  9337. }
  9338. //if (_dto.Label == 79)
  9339. //{
  9340. // string original = string.Empty;
  9341. // if (hotelCurrncyCode.Equals("CNY"))
  9342. // {
  9343. // OriginalCurrPay = CurrPayStr;
  9344. // _detail.CurrPay = CurrPayStr.ToString("#0.00") + " CNY";
  9345. // }
  9346. // else
  9347. // {
  9348. // OriginalCurrPay = ((entity.PayMoney / 100) * entity.PayPercentage).ConvertToDecimal1();
  9349. // //760 EUR(7600.00 CNY)
  9350. // _detail.CurrPay = $"{OriginalCurrPay.ToString("#0.00")} {hotelCurrncyCode}({CurrPayStr.ToString("#0.00")} CNY)";
  9351. // }
  9352. //}
  9353. //else _detail.CurrPay = CurrPayStr.ToString("#0.00") + " CNY";
  9354. string original = string.Empty;
  9355. if (hotelCurrncyCode.Equals("CNY"))
  9356. {
  9357. OriginalCurrPay = CurrPayStr;
  9358. _detail.CurrPay = CurrPayStr.ToString("#0.00") + " CNY";
  9359. }
  9360. else
  9361. {
  9362. OriginalCurrPay = ((entity.PayMoney / 100) * entity.PayPercentage).ConvertToDecimal1();
  9363. //760 EUR(7600.00 CNY)
  9364. _detail.CurrPay = $"{OriginalCurrPay:#0.00} {hotelCurrncyCode}({CurrPayStr:#0.00} CNY)";
  9365. }
  9366. /*
  9367. * 剩余尾款
  9368. */
  9369. decimal BalanceStr = 0;
  9370. if (CurrPayStr != 0)
  9371. {
  9372. if (entity.PayMoney - (CurrPayStr / entity.DayRate) < 0.01M)
  9373. BalanceStr = 0;
  9374. else
  9375. BalanceStr = (entity.PayMoney - CurrPayStr / entity.DayRate).ConvertToDecimal1();
  9376. }
  9377. _detail.Balance = BalanceStr.ToString("#0.00") + " " + PaymentCurrency_WaitPay;
  9378. /*
  9379. * Bus名称
  9380. */
  9381. _detail.BusName = "待增加";
  9382. /*
  9383. *费用所属
  9384. */
  9385. switch (entity.CTable)
  9386. {
  9387. case 76://酒店预订
  9388. Grp_HotelReservations hotelReservations = _HotelReservations.Where(s => s.Id == entity.CId).FirstOrDefault();
  9389. if (hotelReservations != null)
  9390. {
  9391. DateTime checkIn = Convert.ToDateTime(hotelReservations.CheckInDate),
  9392. checkOut = Convert.ToDateTime(hotelReservations.CheckOutDate);
  9393. int hotel_days = (int)(checkOut - checkIn).TotalDays;
  9394. string roomFeeStr = "", roomFeestr1 = "";
  9395. //是否比较房型价格
  9396. //bool __isSingle = false, __isDouble = false, __isSuite = false, __isOther = false;
  9397. //roomFeeStr += $"<br/><span style='width:70px;display: inline-block;'></span>";
  9398. roomFeeStr += $"<br/>";
  9399. var roomTotal = 0.00M;
  9400. if (hotelReservations.SingleRoomPrice > 0)
  9401. {
  9402. var fee = hotelReservations.SingleRoomPrice * hotelReservations.SingleRoomCount * hotel_days;
  9403. roomFeestr1 += $"<span style='width:70px;display: inline-block;'></span>单间:{hotelReservations.SingleRoomPrice:#0.00} * {hotelReservations.SingleRoomCount}间 * {hotel_days}晚 = {fee:#0.00}<br/>";
  9404. //__isSingle = true;
  9405. roomTotal += fee;
  9406. }
  9407. if (hotelReservations.DoubleRoomPrice > 0)
  9408. {
  9409. var fee = hotelReservations.DoubleRoomPrice * hotelReservations.DoubleRoomCount * hotel_days;
  9410. roomFeestr1 += $"<span style='width:70px;display: inline-block;'></span>双人间:{hotelReservations.DoubleRoomPrice:#0.00} * {hotelReservations.DoubleRoomCount}间 * {hotel_days}晚 = {fee:#0.00}<br/>";
  9411. // __isDouble = true;
  9412. roomTotal += fee;
  9413. }
  9414. if (hotelReservations.SuiteRoomPrice > 0)
  9415. {
  9416. var fee = hotelReservations.SuiteRoomPrice * hotelReservations.SuiteRoomCount * hotel_days;
  9417. roomFeestr1 += $"<span style='width:70px;display: inline-block;'></span>套房:{hotelReservations.SuiteRoomPrice:#0.00} * {hotelReservations.SuiteRoomCount}间 * {hotel_days}晚 = {fee:#0.00}<br/>";
  9418. //__isSuite = true;
  9419. roomTotal += fee;
  9420. }
  9421. if (hotelReservations.OtherRoomPrice > 0)
  9422. {
  9423. var fee = hotelReservations.OtherRoomPrice * hotelReservations.OtherRoomCount * hotel_days;
  9424. roomFeestr1 += $"<span style='width:70px;display: inline-block;'></span>其他:{hotelReservations.OtherRoomPrice:#0.00} * {hotelReservations.OtherRoomCount}间 * {hotel_days}晚 = {fee:#0.00}<br/>";
  9425. //__isOther = true;
  9426. roomTotal += fee;
  9427. }
  9428. if (roomFeestr1.Length > 0) roomFeeStr += roomFeestr1 + $"<span style='width:70px;display: inline-block;'></span>房费总金额:{roomTotal:#0.00}";
  9429. else roomFeeStr += " 0.00 * 0";
  9430. decimal governmentRentFee = 0.00M, cityTaxFee = 0.00M, breakfastFee = 0.00M, roomFee = 0.00M;
  9431. string governmentRentBool = "否", cityTaxBool = "否", breakfastBool = "否", roomBool = "否";
  9432. string governmentRentCode = "", governmentRentName = "", cityTaxCode = "", cityTaxName = "", breakfastCode = "", breakfastName = "", roomCode = "", roomName = "";
  9433. var _HotelReservationsContents1 = _HotelReservationsContents.Where(it => it.HrId == hotelReservations.Id).ToList();
  9434. /*
  9435. * 费用类型
  9436. * 1:房费
  9437. * 2:早餐
  9438. * 3:地税
  9439. * 4:城市税
  9440. * </summary>
  9441. */
  9442. //地税
  9443. var governmentRentData = _HotelReservationsContents1.Find(it => it.PriceType == 3);
  9444. if (governmentRentData != null)
  9445. {
  9446. governmentRentBool = governmentRentData.IsOppay == 1 ? "是" : "否";
  9447. governmentRentFee = governmentRentData.Price;
  9448. var governmentRentCurrData = currencyItems.Find(s => s.Id == governmentRentData.Currency);
  9449. if (governmentRentCurrData != null)
  9450. {
  9451. governmentRentCode = governmentRentCurrData.Name;
  9452. governmentRentName = $"({governmentRentCurrData.Remark})";
  9453. }
  9454. }
  9455. //城市税
  9456. var cityTaxData = _HotelReservationsContents1.Find(it => it.PriceType == 4);
  9457. if (cityTaxData != null)
  9458. {
  9459. cityTaxBool = cityTaxData.IsOppay == 1 ? "是" : "否";
  9460. cityTaxFee = cityTaxData.Price;
  9461. var cityTaxCurrData = currencyItems.Find(s => s.Id == cityTaxData.Currency);
  9462. if (cityTaxCurrData != null)
  9463. {
  9464. cityTaxCode = cityTaxCurrData.Name;
  9465. cityTaxName = $"({cityTaxCurrData.Remark})";
  9466. }
  9467. }
  9468. //酒店早餐
  9469. var breakfastData = _HotelReservationsContents1.Find(it => it.PriceType == 2);
  9470. if (breakfastData != null)
  9471. {
  9472. breakfastBool = breakfastData.IsOppay == 1 ? "是" : "否";
  9473. breakfastFee = breakfastData.Price;
  9474. var breakfastCurrData = currencyItems.Find(s => s.Id == breakfastData.Currency);
  9475. if (breakfastCurrData != null)
  9476. {
  9477. breakfastCode = breakfastCurrData.Name;
  9478. breakfastName = $"({breakfastCurrData.Remark})";
  9479. }
  9480. }
  9481. //房间费用
  9482. var roomData = _HotelReservationsContents1.Find(it => it.PriceType == 1);
  9483. if (roomData != null)
  9484. {
  9485. _detail.PayType = initDatas.Find(it => it.Id == roomData.PayDId)?.Name ?? "-";
  9486. if (_detail.PayType.Equals("现金")) _detail.CardType = "-";
  9487. else _detail.CardType = initDatas.Find(it => it.Id == roomData.CTDId)?.Name ?? "-";
  9488. roomBool = roomData.IsOppay == 1 ? "是" : "否";
  9489. roomFee = roomData.Price;
  9490. var roomCurrData = currencyItems.Find(s => s.Id == roomData.Currency);
  9491. if (roomCurrData != null)
  9492. {
  9493. roomCode = roomCurrData.Name;
  9494. roomName = $"({roomCurrData.Remark})";
  9495. }
  9496. }
  9497. string hotelCostTitalStr = "<span style='font-weight:800;'>成本信息</span><br/>";
  9498. string hotelCostStr = "";
  9499. decimal hotelCsotTotal = 0.00M;
  9500. if (groupCost != null)
  9501. {
  9502. if (int.TryParse(groupCost.Currency, out int currencyId)) groupCost.Currency = currencyItems.Find(s => s.Id == currencyId)?.Name ?? "-";
  9503. hotelCostStr += $"{groupCost.Currency}(汇率:{groupCost.Rate:#0.0000})<br/>";
  9504. }
  9505. if (checkOut > checkIn) checkOut = checkOut.AddDays(-1);
  9506. var hotelCostDetails = groupCostDetails.Where(x => Convert.ToDateTime(x.Date) >= checkIn && Convert.ToDateTime(x.Date) <= checkOut).ToList();
  9507. string hotelCost_day = "";
  9508. var hotelCostDetails1 = hotelCostDetails.GroupBy(x => x.Date);
  9509. foreach (var item in hotelCostDetails1)
  9510. {
  9511. hotelCsotTotal += item.Sum(x => x.HotelSingleRoomFee) + item.Sum(x => x.HotelDoubleRoomFee) + item.Sum(x => x.HotelSuiteRoomFee) + item.Sum(x => x.HotelSuiteFee);
  9512. hotelCost_day += @$"{item.First()?.Date ?? "-"}";
  9513. if (item.Sum(x => x.HotelSingleRoomFee) != 0) hotelCost_day += @$" 单间:{item.Sum(x => x.HotelSingleRoomFee):#0.00}";
  9514. //else { if (__isSingle) hotelCost_day += @$" 单间:0.00"; }
  9515. if (item.Sum(x => x.HotelDoubleRoomFee) != 0) hotelCost_day += @$" 双人间:{item.Sum(x => x.HotelDoubleRoomFee):#0.00}";
  9516. //else { if (__isDouble) hotelCost_day += @$" 双人间:0.00"; }
  9517. if (item.Sum(x => x.HotelSuiteRoomFee) != 0) hotelCost_day += @$" 小套房/豪华套房:{item.Sum(x => x.HotelSuiteRoomFee):#0.00}";
  9518. //else { if (__isSuite) hotelCost_day += @$" 小套房/豪华套房:0.00"; }
  9519. if (item.Sum(x => x.HotelSuiteFee) != 0) hotelCost_day += @$" 套房:{item.Sum(x => x.HotelSuiteFee):#0.00}";
  9520. //else { if (__isOther) hotelCost_day += @$" 套房:0.00"; }
  9521. hotelCost_day += @$"<br/>";
  9522. }
  9523. string hotelBreakfastStr = "", hotelGovernmentRentStr = "", hotelCityTaxStr = "";
  9524. if (breakfastFee > 0) hotelBreakfastStr = $"酒店早餐: {breakfastFee:#0.00} {breakfastCode} {breakfastName} 当时汇率 {breakfastData?.Rate:#0.0000} <br/>是否由地接或其他人代付:{breakfastBool}<br/><br/>";
  9525. if (governmentRentFee > 0) hotelGovernmentRentStr = $"地税: {governmentRentFee:#0.00} {governmentRentCode} {governmentRentName} 当时汇率 {governmentRentData?.Rate:#0.0000} <br/>是否由地接或其他人代付:{governmentRentBool}<br/><br/>";
  9526. if (cityTaxFee > 0) hotelCityTaxStr = $"城市税: {cityTaxFee:#0.00} {cityTaxCode} {cityTaxName} 当时汇率 {cityTaxData?.Rate:#0.0000)} <br/>是否由地接或其他人代付:{cityTaxBool}<br/>";
  9527. string hotelCostTotalStr = "";// $"&nbsp;&nbsp;成本合计:{hotelCsotTotal.ToString("#0.00")}<br/>";
  9528. _detail.PriceMsgContent = $"{hotelCostTitalStr}{hotelCostStr}{hotelCostTotalStr}{hotelCost_day}<br/>" +
  9529. $"<span style='font-weight:800;'>{hotelReservations.HotelName} [{hotelReservations.CheckInDate} - {hotelReservations.CheckOutDate}]</span><br/>" +
  9530. $"酒店费用总额:{_detail.WaitPay} ({hotelCurrncyName})<br/>" +
  9531. $"房间说明: {hotelReservations.Remark} <br/>" +
  9532. $"房间费用: {roomCode} {roomName} 当时汇率:{roomData?.Rate.ToString("#0.0000")}{roomFeeStr} <br/>是否由地接或其他人代付:{roomBool}<br/><br/>" +
  9533. $"{hotelBreakfastStr}" +
  9534. $"{hotelGovernmentRentStr}" +
  9535. $"{hotelCityTaxStr}";
  9536. _detail.PriceNameContent = hotelReservations.HotelName;
  9537. }
  9538. break;
  9539. case 79://车/导游地接
  9540. Grp_CarTouristGuideGroundReservations touristGuideGroundReservations = _CarTouristGuideGroundReservations.Where(s => s.Id == entity.CId).FirstOrDefault();
  9541. if (touristGuideGroundReservations != null)
  9542. {
  9543. if (!string.IsNullOrEmpty(touristGuideGroundReservations.BusName))
  9544. {
  9545. _detail.BusName = touristGuideGroundReservations.BusName;
  9546. }
  9547. _detail.PriceNameContent = touristGuideGroundReservations.PriceName;
  9548. //bool isInt = int.TryParse(touristGuideGroundReservations.Area, out int cityId);
  9549. //if (isInt)
  9550. //{
  9551. // var cityInfo = cityData.Find(it => it.Id == cityId);
  9552. // if (cityInfo != null)
  9553. // {
  9554. // string nameContent = $@"{cityInfo.Country}-{cityInfo.City}";
  9555. // var carFeeItem = carFeeItems.Find(it => it.Id == touristGuideGroundReservations.PriceType);
  9556. // if (carFeeItem != null)
  9557. // {
  9558. // nameContent += $@"({carFeeItem.Name})";
  9559. // }
  9560. // _detail.PriceNameContent = nameContent;
  9561. // }
  9562. //}
  9563. //else
  9564. //{
  9565. // _detail.PriceNameContent = touristGuideGroundReservations.Area;
  9566. //}
  9567. var touristGuideGroundReservationsContents =
  9568. _CarTouristGuideGroundReservationsContent.Where(s => s.CTGGRId == touristGuideGroundReservations.Id && s.IsDel == 0 && s.Price != 0).ToList();
  9569. var opContent_sb = new StringBuilder();
  9570. string contetTitle = $"<span style='font-weight:800;'>{touristGuideGroundReservations.PriceName}({touristGuideGroundReservations.ServiceStartTime} - {touristGuideGroundReservations.ServiceEndTime})</span><br/>";
  9571. opContent_sb.AppendLine(contetTitle);
  9572. foreach (var item in touristGuideGroundReservationsContents)
  9573. {
  9574. string typeName = "Unknown";
  9575. string carCurrencyCode = "Unknown";
  9576. string carCurrencyName = "Unknown";
  9577. var carTypeData = carFeeTypeItems.Where(s => s.Id == item.SId && s.IsDel == 0).FirstOrDefault();
  9578. if (carTypeData != null) typeName = carTypeData.Name;
  9579. var currencyData = currencyItems.Where(s => s.Id == item.Currency && s.IsDel == 0).FirstOrDefault();
  9580. if (currencyData != null)
  9581. {
  9582. carCurrencyCode = currencyData.Name;
  9583. carCurrencyName = currencyData.Remark;
  9584. }
  9585. //op、成本 币种是否一致 (币种一致只比较金额:2025-04-18)
  9586. bool IsCurrencyAgreement = false;
  9587. if (carCurrencyCode.Equals(_groupCurrencyCode)) IsCurrencyAgreement = true;
  9588. string opCostStr = string.Empty;
  9589. decimal opCostTypePrice = 0.00M;
  9590. #region 处理成本各项费用
  9591. var opDate = item.DatePrice?.ToString("yyyy-MM-dd");
  9592. var opCost = groupCostDetails.Where(x => x.Date.Equals(opDate)).ToList();
  9593. decimal aduitOPFeeCNY = 0.00M, //费用审核 op费用
  9594. costOPFeeCNY = 0.00M, //团组成本 op费用
  9595. opPayPercentage = entity.PayPercentage == 0.00M ? 1.00M : entity.PayPercentage / 100M; //费用审核 op付款百分比
  9596. if (opCost.Count > 0)
  9597. {
  9598. switch (item.SId)
  9599. {
  9600. case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //91车费
  9601. //case 982: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //982 车超时费 -- 暂无
  9602. case 92: opCostTypePrice = opCost.Sum(x => x.GuideFee); break; //92 导游费
  9603. case 94: opCostTypePrice = opCost.Sum(x => x.GuideScenicFee); break; //94 导游景点费
  9604. case 95: opCostTypePrice = opCost.Sum(x => x.GuideTipFee); break; //95 导游小费
  9605. case 983: opCostTypePrice = opCost.Sum(x => x.GuideMealFee); break; //983 导游餐补
  9606. case 984: opCostTypePrice = opCost.Sum(x => x.GuideMealFee); break; //984 导游房补
  9607. case 985: opCostTypePrice = opCost.Sum(x => x.GuideRoomFee); break; //985 导游交通
  9608. //case 96: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //96 接送机费 -- 暂无
  9609. //case 97: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //97 其他费用 -- 暂无
  9610. case 979: opCostTypePrice = opCost.Sum(x => x.DriverFee); break; //979 司机工资
  9611. case 980: opCostTypePrice = opCost.Sum(x => x.DriverTipFee); break; //980 司机小费
  9612. case 981: opCostTypePrice = opCost.Sum(x => x.DriverMealFee); break; //981 司机餐补
  9613. case 988: opCostTypePrice = opCost.Sum(x => x.ClientBreakfastFee); break; //988 客户早餐费用
  9614. case 93: opCostTypePrice = opCost.Sum(x => x.ClientDinnerFee); break; //93 客户午餐费用
  9615. case 989: opCostTypePrice = opCost.Sum(x => x.ClientLunchFee); break; //989 客户晚餐费用
  9616. case 990: opCostTypePrice = opCost.Sum(x => x.ScenicTicketFee); break; //990 景点门票费
  9617. case 991: opCostTypePrice = opCost.Sum(x => x.DrinkSnackFruitFee); break; //991 饮料/零食/水果
  9618. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //992 住补费用 -- 暂无
  9619. case 994: opCostTypePrice = opCost.Sum(x => x.TranslatorFee); break; //994 翻译费
  9620. case 1059: opCostTypePrice = opCost.Sum(x => x.GuideOverTimeFee); break; //1059 导游超时费用
  9621. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1070 尾款金额
  9622. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1071 其他额外费用
  9623. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1073 翻译超时费
  9624. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1074 早餐超支费用
  9625. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1075 午餐超支费用
  9626. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1076 晚餐超支费用
  9627. }
  9628. opCostStr = $"&nbsp;&nbsp;/&nbsp;&nbsp;成本:{opCostTypePrice:#0.00} {_groupCurrencyCode}(汇率:{_groupRate:#0.0000})";
  9629. costOPFeeCNY = opCostTypePrice * _groupRate;
  9630. if (!IsCurrencyAgreement) opCostStr += $" ≈ {costOPFeeCNY:#0.00} CNY";
  9631. }
  9632. #endregion
  9633. string opTypeStr = $"{typeName}:{item.Price:#0.00} {carCurrencyCode}(汇率:{entity.DayRate:#0.0000})";
  9634. aduitOPFeeCNY = item.Price * entity.DayRate;
  9635. if (!IsCurrencyAgreement) opTypeStr += $" ≈ {aduitOPFeeCNY:#0.0000} CNY";
  9636. var opContent = $"日期:{item.DatePrice?.ToString("yyyy-MM-dd") ?? "-"}<br/>" +
  9637. $"{opTypeStr} {opCostStr}<br/>" +
  9638. $"明细:{item.PriceContent ?? "-"}<br/>" +
  9639. $"备注:{item.Remark ?? "-"}<br/><br/>";
  9640. if (entity.IsAuditGM != 3) //状态 != 自动审核
  9641. {
  9642. if (IsCurrencyAgreement)
  9643. {
  9644. if (item.Price > opCostTypePrice)
  9645. {
  9646. opContent_sb.Append("<span style='color:red;'>");
  9647. opContent_sb.Append(opContent);
  9648. opContent_sb.Append("</span>");
  9649. opContent_sb.AppendLine();
  9650. }
  9651. else
  9652. {
  9653. opContent_sb.Append(opContent);
  9654. opContent_sb.AppendLine();
  9655. }
  9656. }
  9657. else
  9658. {
  9659. //验证是否超成本 按付款比例计算
  9660. if (aduitOPFeeCNY * opPayPercentage > costOPFeeCNY * opPayPercentage)
  9661. {
  9662. opContent_sb.Append("<span style='color:red;'>");
  9663. opContent_sb.Append(opContent);
  9664. opContent_sb.Append("</span>");
  9665. opContent_sb.AppendLine();
  9666. }
  9667. else
  9668. {
  9669. opContent_sb.Append(opContent);
  9670. opContent_sb.AppendLine();
  9671. }
  9672. }
  9673. }
  9674. else
  9675. {
  9676. opContent_sb.Append(opContent);
  9677. opContent_sb.AppendLine();
  9678. }
  9679. }
  9680. _detail.PriceMsgContent = opContent_sb.ToString();
  9681. }
  9682. break;
  9683. case 80: //签证
  9684. Grp_VisaInfo visaInfo = _VisaInfos.Where(s => s.Id == entity.CId).FirstOrDefault();
  9685. if (visaInfo != null)
  9686. {
  9687. string visaName = GetClientNameStr1(clientNameList, visaInfo.VisaClient);
  9688. _detail.PriceNameContent = visaInfo.VisaDescription;
  9689. _detail.PriceMsgContent = $"签证描述:{visaName}<br/> 备注:{visaInfo.Remark}";
  9690. }
  9691. break;
  9692. case 81: //邀请/公务活动
  9693. Grp_InvitationOfficialActivities _ioa = _InvitationOfficialActivities.Where(s => s.Id == entity.CId).FirstOrDefault();
  9694. if (_ioa != null)
  9695. {
  9696. string inviteCurrName = "Unknown", //邀请费用币种 Name
  9697. inviteCurrCode = "Unknown", //邀请费用币种 Code
  9698. sendCurrName = "Unknown", //快递费用币种 Name
  9699. sendCurrCode = "Unknown", //快递费用币种 Code
  9700. eventsCurrName = "Unknown", //公务活动费币种 Name
  9701. eventsCurrCode = "Unknown", //公务活动费币种 Code
  9702. translateCurrName = "Unknown", //公务翻译费 Name
  9703. translateCurrCode = "Unknown"; //公务翻译费 Code
  9704. #region 处理费用币种
  9705. var inviteCurrData = currencyItems.Where(s => s.Id == _ioa.InviteCurrency && s.IsDel == 0).FirstOrDefault();
  9706. if (inviteCurrData != null)
  9707. {
  9708. inviteCurrName = inviteCurrData.Remark;
  9709. inviteCurrCode = inviteCurrData.Name;
  9710. }
  9711. var sendCurrData = currencyItems.Where(s => s.Id == _ioa.SendCurrency && s.IsDel == 0).FirstOrDefault();
  9712. if (sendCurrData != null)
  9713. {
  9714. sendCurrName = sendCurrData.Remark;
  9715. sendCurrCode = sendCurrData.Name;
  9716. }
  9717. var eventsCurrData = currencyItems.Where(s => s.Id == _ioa.EventsCurrency && s.IsDel == 0).FirstOrDefault();
  9718. if (eventsCurrData != null)
  9719. {
  9720. eventsCurrName = eventsCurrData.Remark;
  9721. eventsCurrCode = eventsCurrData.Name;
  9722. }
  9723. var translateCurrData = currencyItems.Where(s => s.Id == _ioa.TranslateCurrency && s.IsDel == 0).FirstOrDefault();
  9724. if (translateCurrData != null)
  9725. {
  9726. translateCurrName = translateCurrData.Remark;
  9727. translateCurrCode = translateCurrData.Name;
  9728. }
  9729. #endregion
  9730. _detail.PriceNameContent = _ioa.InviterArea;
  9731. //2025-09-08 商邀费用名称更改:单项费用不等于0,则在名称后面最加费用类型名称。
  9732. List<string> priceExpNames = new List<string>();
  9733. if (_ioa.InviteCost != 0.00M) priceExpNames.Add("邀请费");
  9734. if (_ioa.SendCost != 0.00M) priceExpNames.Add("快递费");
  9735. if (_ioa.EventsCost != 0.00M) priceExpNames.Add("公务活动费");
  9736. if (_ioa.TranslateCost != 0.00M) priceExpNames.Add("公务翻译费");
  9737. if (priceExpNames != null && priceExpNames.Count > 0)
  9738. {
  9739. _detail.PriceNameContent += $"({string.Join("+", priceExpNames)})";
  9740. }
  9741. _detail.PriceMsgContent = $@"邀请费用:{_ioa.InviteCost:#0.00} {inviteCurrCode}({inviteCurrName})<br/>" +
  9742. $@"快递费用:{_ioa.SendCost:#0.00} {sendCurrCode}({sendCurrName})<br/>" +
  9743. $@"公务活动费:{_ioa.EventsCost:#0.00} {eventsCurrCode}({eventsCurrName})<br/>" +
  9744. $@"公务翻译费:{_ioa.TranslateCost:#0.00} {translateCurrCode}({translateCurrName})<br/>" +
  9745. $@"备注:" + _ioa.Remark + "<br/>";
  9746. }
  9747. break;
  9748. case 82: //团组客户保险
  9749. Grp_Customers customers = _Customers.Where(s => s.Id == entity.CId && s.IsDel == 0).FirstOrDefault();
  9750. if (customers != null)
  9751. {
  9752. _detail.PriceNameContent = GetClientNameStr(clientNameList, customers.ClientName);
  9753. _detail.PriceMsgContent = "备注:" + customers.Remark + "<br/>";
  9754. }
  9755. break;
  9756. case 85: //机票预订
  9757. Grp_AirTicketReservations jpRes = _AirTicketReservations.Where(s => s.Id == entity.CId).FirstOrDefault();
  9758. if (jpRes != null)
  9759. {
  9760. string FlightsDescription = jpRes.FlightsDescription;
  9761. string PriceDescription = jpRes.PriceDescription;
  9762. _detail.PriceMsgContent = "航班号:" + jpRes.FlightsCode + "<br/>城市A-B:" + jpRes.FlightsCity + "<br/>航班描述:" + FlightsDescription.Replace("\r\n", "<br />") + "<br/>" + "价格描述:" + PriceDescription;
  9763. _detail.PriceNameContent = "(" + jpRes.FlightsCode + ")";
  9764. }
  9765. break;
  9766. case 98://其他款项
  9767. Grp_DecreasePayments gdpRes = _DecreasePayments.Where(s => s.Id == entity.CId).FirstOrDefault();
  9768. if (gdpRes != null)
  9769. {
  9770. //var urlBase = $"http://132.232.92.186:24/Office/GrpFile/http://132.232.92.186:24/Office/GrpFile/%E5%9B%A2%E7%BB%84%E5%A2%9E%E5%87%8F%E6%AC%BE%E9%A1%B9%E7%9B%B8%E5%85%B3%E6%96%87%E4%BB%B6/";
  9771. //if (!string.IsNullOrEmpty(gdpRes.FilePath))
  9772. //{
  9773. // _detail.FileUrl = $"{urlBase}{gdpRes.FilePath}";
  9774. //}
  9775. _detail.PriceMsgContent = "备注:" + gdpRes.Remark;
  9776. _detail.PriceNameContent = gdpRes.PriceName;
  9777. }
  9778. break;
  9779. case 285://收款退还
  9780. Fin_PaymentRefundAndOtherMoney refundAndOtherMoney = _PaymentRefundAndOtherMoneys.Where(s => s.Id == entity.CId).FirstOrDefault();
  9781. if (refundAndOtherMoney != null)
  9782. {
  9783. _detail.PriceMsgContent = "备注:" + refundAndOtherMoney.Remark;
  9784. _detail.PriceNameContent = refundAndOtherMoney.PriceName;
  9785. }
  9786. break;
  9787. case 751://酒店早餐
  9788. break;
  9789. case 1015://超支费用
  9790. Fin_GroupExtraCost groupExtraCost = _GroupExtraCosts.Where(s => s.Id == entity.CId).FirstOrDefault();
  9791. if (groupExtraCost != null)
  9792. {
  9793. _detail.PriceNameContent = groupExtraCost.PriceName;
  9794. _detail.PriceMsgContent = "备注:" + groupExtraCost.Remark;
  9795. }
  9796. break;
  9797. default:
  9798. break;
  9799. }
  9800. /*
  9801. * 申请人
  9802. */
  9803. string operatorName = " - ";
  9804. var _opUser = userItems.Where(s => s.Id == entity.CreateUserId).FirstOrDefault();
  9805. if (_opUser != null)
  9806. {
  9807. operatorName = _opUser.CnName;
  9808. }
  9809. _detail.OperatorName = operatorName;
  9810. /*
  9811. * 审核人
  9812. */
  9813. string auditOperatorName = " - ";
  9814. if (entity.IsAuditGM != 0)
  9815. {
  9816. if (entity.AuditGMOperate == 0) auditOperatorName = " - ";
  9817. else if (entity.AuditGMOperate == 4) auditOperatorName = "自动审核";
  9818. else
  9819. {
  9820. var _adUser = userItems.Where(s => s.Id == entity.AuditGMOperate).FirstOrDefault();
  9821. if (_adUser != null)
  9822. {
  9823. auditOperatorName = _adUser.CnName;
  9824. }
  9825. }
  9826. }
  9827. _detail.AuditOperatorName = auditOperatorName;
  9828. /*
  9829. * 超预算比例
  9830. */
  9831. string overBudgetStr = "";
  9832. if (entity.ExceedBudget == -1) overBudgetStr = sdPriceName.Name + "尚无预算";
  9833. else if (entity.ExceedBudget == 0)
  9834. {
  9835. if (entity.CTable == 76 || entity.CTable == 79)
  9836. {
  9837. if (entity.IsAuditGM == 3) overBudgetStr = "未超预算";
  9838. else overBudgetStr = _feeAuditRep.IsOverBudget(entity.CTable, entity.DIId, entity.CId);
  9839. }
  9840. else
  9841. {
  9842. overBudgetStr = "未超预算";
  9843. }
  9844. }
  9845. else overBudgetStr = entity.ExceedBudget.ToString("P");
  9846. _detail.OverBudget = overBudgetStr;
  9847. decimal auditFee = 0.00M; //已审核金额 人名币
  9848. decimal auditedFeeOriginal = 0.00M; ////已审核金额 原始
  9849. decimal unAuditFeeCNY = 0.00M; //未审核款项 原始
  9850. decimal unAuditFeeOriginal = 0.00M; //未审核款项 人名币
  9851. if (entity.IsAuditGM == 1 || entity.IsAuditGM == 3)
  9852. {
  9853. auditedFeeOriginal = entity.PayMoney;
  9854. auditFee = CurrPayStr;
  9855. }
  9856. else if (entity.IsAuditGM == 0)
  9857. {
  9858. unAuditFeeCNY = CurrPayStr;
  9859. unAuditFeeOriginal = OriginalCurrPay;
  9860. OriginalCurrPay = 0.00M;
  9861. }
  9862. /*
  9863. * 费用总计
  9864. */
  9865. ccpCurrencyPrices.Add(new CreditCardPaymentCurrencyPriceItem()
  9866. {
  9867. CurrencyId = entity.PaymentCurrency,
  9868. CurrencyName = PaymentCurrency_WaitPay,
  9869. AmountPayable = entity.PayMoney,
  9870. ThisPayment = OriginalCurrPay,
  9871. BalancePayment = BalanceStr,
  9872. AuditedFunds = auditFee,
  9873. AuditedFundsOriginal = auditedFeeOriginal,
  9874. UnAuditFundsCNY = unAuditFeeCNY,
  9875. UnAuditFundsOriginal = unAuditFeeOriginal
  9876. });
  9877. _detail.IsAuditGM = entity.IsAuditGM;
  9878. detailList.Add(_detail);
  9879. }
  9880. #endregion
  9881. _view.DetailList = new List<Grp_CreditCardPaymentDetailView>(detailList);
  9882. /*
  9883. * 下方描述处理
  9884. */
  9885. var nonDuplicat = ccpCurrencyPrices.Where((x, i) => ccpCurrencyPrices.FindIndex(z => z.CurrencyId == x.CurrencyId) == i).ToList();//Lambda表达式去重
  9886. var ccpCurrencyPrice = nonDuplicat.Where(it => it.CurrencyId == 836).FirstOrDefault();
  9887. if (ccpCurrencyPrice != null)
  9888. {
  9889. int CNYIndex = nonDuplicat.IndexOf(ccpCurrencyPrice);
  9890. nonDuplicat.MoveItemAtIndexToFront(CNYIndex);
  9891. }
  9892. else
  9893. {
  9894. nonDuplicat = nonDuplicat.OrderBy(it => it.CurrencyId).ToList();
  9895. }
  9896. string amountPayableStr = string.Format(@"应付款总金额: ");
  9897. string thisPaymentStr = string.Format(@"此次付款总金额: ");
  9898. string balancePaymentStr = string.Format(@"目前剩余尾款总金额: ");
  9899. string auditedFundsStr = string.Format(@"已审费用总额: ");
  9900. string unAuditedFundsStr = string.Format(@"未审费用总额: ");
  9901. foreach (var item in nonDuplicat)
  9902. {
  9903. var currencyName = item.CurrencyName;
  9904. var strs = ccpCurrencyPrices.Where(it => it.CurrencyId == item.CurrencyId).ToList();
  9905. if (strs.Count > 0)
  9906. {
  9907. decimal amountPayable = strs.Sum(it => it.AmountPayable);
  9908. decimal thisPayment = ccpCurrencyPrices.Sum(it => it.ThisPayment);
  9909. decimal balancePayment = strs.Sum(it => it.BalancePayment);
  9910. amountPayableStr += string.Format(@"{0}{1}&nbsp;|", amountPayable.ToString("#0.00"), currencyName);
  9911. //单独处理此次付款金额
  9912. thisPaymentStr += string.Format(@"{0}{1}&nbsp;|", strs.Sum(x => x.ThisPayment).ToString("#0.00"), currencyName);
  9913. balancePaymentStr += string.Format(@"{0}{1}&nbsp;|", balancePayment.ToString("#0.00"), currencyName);
  9914. //单独处理已审核费用
  9915. //if (item.CurrencyId == 836) //人民币
  9916. //{
  9917. // decimal auditedFunds = ccpCurrencyPrices.Sum(it => it.AuditedFunds);
  9918. // auditedFundsStr += string.Format(@"{0}{1}&nbsp;|", auditedFunds.ToString("#0.00"), currencyName);
  9919. //}
  9920. //else
  9921. //{
  9922. // auditedFundsStr += string.Format(@"{0}{1}&nbsp;|", strs.Sum(x => x.AmountPayable), currencyName);
  9923. //}
  9924. if (currencyName.Equals("CNY"))
  9925. {
  9926. //已审核费用
  9927. auditedFundsStr += string.Format(@"{0}{1}&nbsp;|", strs.Sum(x => x.ThisPayment).ToString("#0.00"), currencyName);
  9928. //未审核费用
  9929. unAuditedFundsStr += string.Format(@"{0}{1}&nbsp;|", strs.Sum(x => x.UnAuditFundsOriginal).ToString("#0.00"), currencyName);
  9930. }
  9931. else
  9932. {
  9933. //已审核费用
  9934. auditedFundsStr += string.Format(@"{0}{1}({2}CNY)&nbsp;|", strs.Sum(x => x.ThisPayment).ToString("#0.00"), currencyName, strs.Sum(x => x.AuditedFunds).ToString("#0.00"));
  9935. //未审核费用
  9936. unAuditedFundsStr += string.Format(@"{0}{1}({2}CNY)&nbsp;|", strs.Sum(x => x.UnAuditFundsOriginal).ToString("#0.00"), currencyName, strs.Sum(x => x.UnAuditFundsCNY).ToString("#0.00"));
  9937. }
  9938. }
  9939. }
  9940. _view.TotalStr1 = amountPayableStr[..^1];
  9941. _view.TotalStr2 = thisPaymentStr[..^1];
  9942. _view.TotalStr3 = balancePaymentStr[..^1];
  9943. _view.TotalStr4 = $"{auditedFundsStr[..^1]}<br/>{unAuditedFundsStr[..^1]}";
  9944. //_view.TotalStr5 = unAuditedFundsStr.Substring(0, unAuditedFundsStr.Length - 1);
  9945. var _view1 = new
  9946. {
  9947. PageFuncAuth = pageFunAuthView,
  9948. Data = _view
  9949. };
  9950. return Ok(JsonView(_view1));
  9951. }
  9952. catch (Exception ex)
  9953. {
  9954. return Ok(JsonView(false, ex.Message));
  9955. }
  9956. }
  9957. /// <summary>
  9958. /// 费用审核
  9959. /// 修改团组费用审核状态
  9960. /// </summary>
  9961. /// <param name="_dto">参数Json字符串</param>
  9962. /// <returns></returns>
  9963. [HttpPost]
  9964. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9965. public async Task<IActionResult> PostAuditGrpCreditCardPayment(Edit_GrpCreditCardPaymentDto _dto)
  9966. {
  9967. #region 参数验证
  9968. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  9969. if (_dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  9970. #endregion
  9971. #region 页面操作权限验证
  9972. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  9973. if (pageFunAuthView.AuditAuth == 0) return Ok(JsonView(false, "您没有审核权限"));
  9974. #endregion
  9975. List<string> idList = _dto.CreditIdStr.Split(',').ToList();
  9976. Grp_CreditCardPayment _detail = _mapper.Map<Grp_CreditCardPayment>(_dto);
  9977. DateTime dtNow = DateTime.Now;
  9978. _groupRepository.BeginTran();
  9979. int rst = 0;
  9980. var creditDatas = _grpScheduleRep._sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.IsDel == 0 && idList.Contains(it.Id.ToString())).ToList();
  9981. var creditTypeDatas = _grpScheduleRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 16).ToList();
  9982. var creditCurrencyDatas = _grpScheduleRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  9983. var groupDatas = _grpScheduleRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).ToList();
  9984. var msgDatas = new List<dynamic>();
  9985. var dic_ccp_user = new Dictionary<int, int>() { };
  9986. foreach (var item in idList)
  9987. {
  9988. int CreditId = int.Parse(item);
  9989. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_CreditCardPayment>()
  9990. .SetColumns(it => it.IsAuditGM == _dto.AuditCode)
  9991. .SetColumns(it => it.AuditGMOperate == _dto.UserId)
  9992. .SetColumns(it => it.AuditGMDate == dtNow.ToString("yyyy-MM-dd HH:mm:ss"))
  9993. .Where(s => s.Id == CreditId)
  9994. .ExecuteCommandAsync();
  9995. if (result < 1)
  9996. {
  9997. rst = -1;
  9998. _groupRepository.RollbackTran();
  9999. return Ok(JsonView(false, "操作失败并回滚!"));
  10000. }
  10001. var creditData = creditDatas.Where(it => it.Id == CreditId).FirstOrDefault();
  10002. if (creditData != null)
  10003. {
  10004. #region 应用通知配置
  10005. try
  10006. {
  10007. dic_ccp_user.Add(creditData.Id, creditData.CreateUserId);
  10008. }
  10009. catch (Exception ex)
  10010. {
  10011. }
  10012. #endregion
  10013. string auditStr = _dto.AuditCode == 1 ? "已通过" : _dto.AuditCode == 2 ? "未通过" : "未审核";
  10014. string groupNameStr = string.Empty;
  10015. var groupData = groupDatas.Where(it => it.Id == creditData.DIId).FirstOrDefault();
  10016. if (groupData != null) groupNameStr = groupData.TeamName;
  10017. string creditTypeStr = string.Empty;
  10018. var creditTypeData = creditTypeDatas.Where(it => it.Id == creditData.CTable).FirstOrDefault();
  10019. if (creditTypeData != null) creditTypeStr = creditTypeData.Name;
  10020. string creditCurrency = string.Empty;
  10021. var creditCurrencyData = creditCurrencyDatas.Where(it => it.Id == creditData.PaymentCurrency).FirstOrDefault();
  10022. if (creditCurrencyData != null) creditCurrency = creditCurrencyData.Name;
  10023. if (creditCurrency.Equals("CNY"))
  10024. {
  10025. creditData.DayRate = 1.0000M;
  10026. }
  10027. if (creditData.PayPercentage == 0.00M)
  10028. {
  10029. creditData.PayPercentage = 100M;
  10030. }
  10031. decimal CNYPrice = (creditData.PayMoney * (creditData.PayPercentage / 100)) * creditData.DayRate;
  10032. string msgTitle = $"[{groupNameStr}({creditTypeStr})]的费用申请";
  10033. string msgContent = "";
  10034. if (creditCurrency.Equals("CNY"))
  10035. {
  10036. msgContent = $"[{groupNameStr}({creditTypeStr})]费用申请(金额:{CNYPrice:0.00} CNY) {auditStr}!";
  10037. }
  10038. else
  10039. {
  10040. msgContent = $"[{groupNameStr}({creditTypeStr})]费用申请(金额:{CNYPrice:0.00} CNY({creditData.PayMoney:0.00} {creditCurrency})) {auditStr}!";
  10041. }
  10042. msgDatas.Add(new { DiId = creditData.DIId, UserId = creditData.CreateUserId, MsgTitle = msgTitle, MsgContent = msgContent });
  10043. }
  10044. }
  10045. if (rst == 0)
  10046. {
  10047. _groupRepository.CommitTran();
  10048. foreach (var item in msgDatas)
  10049. {
  10050. //发送消息
  10051. GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupExpenseAudit, item.MsgTitle, item.MsgContent, new List<int>() { item.UserId }, item.DiId);
  10052. }
  10053. #region 应用推送
  10054. try
  10055. {
  10056. foreach (var ccpId in dic_ccp_user.Keys)
  10057. {
  10058. var templist = new List<string>() { dic_ccp_user[ccpId].ToString() };
  10059. await AppNoticeLibrary.SendUserMsg_GroupStatus_AuditFee(ccpId, templist, QiyeWeChatEnum.CaiWuChat);
  10060. }
  10061. }
  10062. catch (Exception)
  10063. {
  10064. }
  10065. #endregion
  10066. return Ok(JsonView(true, "操作成功!"));
  10067. }
  10068. return Ok(JsonView(false, "操作失败!"));
  10069. }
  10070. /// <summary>
  10071. /// 费用审核
  10072. /// 其他款项 文件下载
  10073. /// </summary>
  10074. /// <param name="id">其他款项 主键编号</param>
  10075. /// <returns></returns>
  10076. [HttpGet("{id}")]
  10077. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10078. public async Task<IActionResult> FeeAuditOtherFileDownlaod([Range(1, int.MaxValue, ErrorMessage = "请传入有效的ID")] int id)
  10079. {
  10080. //网站域名
  10081. const string baseUrl = "http://132.232.92.186:24/Office/GrpFile/%E5%9B%A2%E7%BB%84%E5%A2%9E%E5%87%8F%E6%AC%BE%E9%A1%B9%E7%9B%B8%E5%85%B3%E6%96%87%E4%BB%B6/";
  10082. var otherInfo = await _decreasePaymentsRep._sqlSugar
  10083. .Queryable<Grp_DecreasePayments>()
  10084. .InnerJoin<Grp_CreditCardPayment>((x, y) => x.Id == y.CId && y.Id == id)
  10085. .Where(((x, y) => x.IsDel == 0 && y.IsDel == 0))
  10086. .Select((x, y) => new
  10087. {
  10088. x.Id,
  10089. x.FilePath
  10090. })
  10091. .FirstAsync();
  10092. if (otherInfo != null && !string.IsNullOrEmpty(otherInfo.FilePath.Trim()))
  10093. {
  10094. var url = $"{baseUrl}{otherInfo.FilePath}";
  10095. return Ok(JsonView(true, "操作成功!", url));
  10096. }
  10097. return Ok(JsonView(false, "暂无附件"));
  10098. }
  10099. #endregion
  10100. #region 机票费用录入
  10101. /// <summary>
  10102. /// 机票录入当前登录人可操作团组
  10103. /// </summary>
  10104. /// <param name="dto"></param>
  10105. /// <returns></returns>
  10106. [HttpPost]
  10107. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10108. public async Task<IActionResult> AirTicketResSelect(AirTicketResDto dto)
  10109. {
  10110. try
  10111. {
  10112. Result groupData = await _airTicketResRep.AirTicketResSelect(dto);
  10113. if (groupData.Code != 0)
  10114. {
  10115. return Ok(JsonView(false, groupData.Msg));
  10116. }
  10117. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  10118. }
  10119. catch (Exception ex)
  10120. {
  10121. return Ok(JsonView(false, ex.Message));
  10122. }
  10123. }
  10124. /// <summary>
  10125. /// 机票费用录入列表
  10126. /// </summary>
  10127. /// <param name="dto"></param>
  10128. /// <returns></returns>
  10129. [HttpPost]
  10130. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10131. public async Task<IActionResult> AirTicketResList(AirTicketResDto dto)
  10132. {
  10133. try
  10134. {
  10135. Result groupData = await _airTicketResRep.AirTicketResList(dto);
  10136. if (groupData.Code != 0)
  10137. {
  10138. return Ok(JsonView(false, groupData.Msg));
  10139. }
  10140. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  10141. }
  10142. catch (Exception ex)
  10143. {
  10144. return Ok(JsonView(false, ex.Message));
  10145. throw;
  10146. }
  10147. }
  10148. /// <summary>
  10149. /// 根据id查询费用录入信息
  10150. /// </summary>
  10151. /// <param name="dto"></param>
  10152. /// <returns></returns>
  10153. [HttpPost]
  10154. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10155. public async Task<IActionResult> AirTicketResById(AirTicketResByIdDto dto)
  10156. {
  10157. Result groupData = await _airTicketResRep.AirTicketResById(dto);
  10158. if (groupData.Code != 0)
  10159. {
  10160. return Ok(JsonView(false, groupData.Msg));
  10161. }
  10162. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  10163. }
  10164. /// <summary>
  10165. /// 机票费用录入操作(Status:1.新增,2.修改)
  10166. /// </summary>
  10167. /// <param name="dto"></param>
  10168. /// <returns></returns>
  10169. [HttpPost]
  10170. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10171. public async Task<IActionResult> OpAirTicketRes(AirTicketResOpDto dto)
  10172. {
  10173. //验证
  10174. if (dto.Status == 2)
  10175. {
  10176. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.AirTicketResOpData.Id, 85);
  10177. if (!valid) return Ok(JsonView(false, msg));
  10178. }
  10179. Result groupData = await _airTicketResRep.OpAirTicketRes(dto, _setDataRep.PostCurrencyByDiid);
  10180. if (groupData.Code != 0)
  10181. {
  10182. return Ok(JsonView(false, groupData.Msg));
  10183. }
  10184. #region 应用推送
  10185. try
  10186. {
  10187. var diId = dto.AirTicketResOpData.DiId;
  10188. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  10189. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  10190. int dataId = groupData.Data.GetType().GetProperty("dataId").GetValue(groupData.Data, null);
  10191. //自动审核
  10192. //var autoAdit1 = await _feeAuditRep.FeeAutomaticAudit(5, diId, dataId); //机票费用合计方式
  10193. (bool status, string auditMsg) = await AirTicketResAutoAudit(diId, dataId); //KIMI-AI识别INIT方式
  10194. _logger.LogInformation("【机票费用自动审核(KIMI-AI识别INIT)】请求参数:{RequstData} 返回结果:是否执行:{IsExecute}; 结果消息:{ResponseMsg};",
  10195. $"GroupId:{diId};airId:{dataId};",
  10196. status,
  10197. auditMsg);
  10198. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  10199. //2024-10-21 新增LZ UID
  10200. var userIds = new List<int>() { 21 };
  10201. string title = $"系统通知";
  10202. string content = "";
  10203. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  10204. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  10205. if (dto.Status == 1) content = $"[新增-机票费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  10206. else if (dto.Status == 2) content = $"[更新-机票费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  10207. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  10208. var h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "85" };
  10209. await APNsTools.iOS_PushNotifications1("051", $"机票费用审核", "", content, true, "ExpenseAuditWebView", h5);
  10210. }
  10211. catch (Exception ex)
  10212. {
  10213. }
  10214. #endregion
  10215. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  10216. }
  10217. /// <summary>
  10218. /// 机票费用自动审核 AI识别方式
  10219. /// </summary>
  10220. /// <returns></returns>
  10221. private async Task<(bool, string)> AirTicketResAutoAudit(int diId, int dataId)
  10222. {
  10223. var ecoTypeIds = new List<int>() {
  10224. 459, //超经舱
  10225. 460, //经济舱
  10226. 1430, //公务舱(实际经济舱)
  10227. 1432, //头等舱(实际经济舱)
  10228. };
  10229. var bizTypeIds = new List<int>() {
  10230. 457, //头等舱
  10231. 458, //公务舱
  10232. 1431, //头等舱(实际公务舱)
  10233. };
  10234. var auditFeeTypeIds = new List<int>() { };
  10235. auditFeeTypeIds.AddRange(ecoTypeIds);
  10236. auditFeeTypeIds.AddRange(bizTypeIds);
  10237. int currModule = 85;
  10238. var airInfo = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  10239. .InnerJoin<Grp_CreditCardPayment>((x, y) => x.Id == y.CId && y.CTable == currModule && y.IsDel == 0)
  10240. .Where((x, y) => x.Id == dataId && x.IsDel == 0 && auditFeeTypeIds.Contains(x.CType))
  10241. .Select((x, y) => new
  10242. {
  10243. x.Id,
  10244. CcpId = y.Id,
  10245. x.FlightsDate,
  10246. x.PrePrice,
  10247. x.CType,
  10248. x.ClientNum,
  10249. x.DIId
  10250. })
  10251. .FirstAsync();
  10252. if (airInfo == null) return (false, "机票信息为空或费用类型不在自动审核范围内,不可自动审核!");
  10253. var groupDetails = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.IsDel == 0 && x.Id == diId);
  10254. if (groupDetails == null) return (false, "团组信息为空,不可自动审核!");
  10255. var groupCostInfo = await _sqlSugar.Queryable<Grp_GroupCostParameter>().FirstAsync(x => x.IsDel == 0 && x.DiId == diId);
  10256. if (groupCostInfo == null) return (false, "团组成本信息未填写!");
  10257. var groupCostContents = await _sqlSugar
  10258. .SqlQueryable<GroupCostAuditView>($"Select * From Grp_GroupCost")
  10259. .Where(x => x.IsDel == 0 && x.Diid == diId)
  10260. .ToListAsync();
  10261. if (groupCostContents.Count < 1) return (false, "团组成本信息未填写!");
  10262. //处理 成本详细信息日期为空 填装费用信息
  10263. var airFeeLabel = new StringBuilder();
  10264. airFeeLabel.AppendLine("费用成本:");
  10265. for (int i = 0; i < groupCostContents.Count; i++)
  10266. {
  10267. if (string.IsNullOrEmpty(groupCostContents[i].Date))
  10268. {
  10269. int index = i - 1;
  10270. if (index >= 0)
  10271. {
  10272. groupCostContents[i].Date = groupCostContents[index].Date;
  10273. var dtBool = DateTime.TryParse(groupCostContents[i].Date, out DateTime _dateTime);
  10274. if (dtBool) groupCostContents[i].CurrTime = _dateTime;
  10275. }
  10276. }
  10277. else
  10278. {
  10279. var dtBool = DateTime.TryParse(groupCostContents[i].Date, out DateTime _dateTime);
  10280. if (dtBool) groupCostContents[i].CurrTime = _dateTime;
  10281. }
  10282. var item = groupCostContents[i];
  10283. airFeeLabel.AppendLine($"{item.Date}");
  10284. airFeeLabel.AppendLine($"{item.ITIN.Replace("\n", " ")}");
  10285. }
  10286. airFeeLabel.AppendLine($"注:费用:位置:航班号或者航班时间后面; 组成:经济舱/公务舱;");
  10287. airFeeLabel.AppendLine($"取出“{airInfo.FlightsDate}”费用金额,按照经济舱/公务舱格式返回,如果不存在的话则返回0.00/0.00,只返回金额格式文本;不需要其他文字描述;");
  10288. //访问Kimi AI 返回价格结果
  10289. var msgs = new List<SeedMessages>()
  10290. {
  10291. new ()
  10292. {
  10293. Role = KimiRole.user,
  10294. Content = airFeeLabel.ToString()
  10295. }
  10296. };
  10297. var client = new KiMiApiClient();
  10298. var kimiApiResult = await client.SeedMessage(msgs);
  10299. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  10300. string clients = kimiApiResult_JObject["content"].ToString();
  10301. decimal ecoPri_kimiAI = 0.00M,
  10302. bizPri_kimiAI = 0.00M;
  10303. //单个价格: 经济舱价格
  10304. if (decimal.TryParse(clients, out ecoPri_kimiAI)) { }
  10305. //价格文本包含/:/前经济舱价格 /后公务舱价格
  10306. if (clients.Contains('/'))
  10307. {
  10308. var priArray = clients.Split('/');
  10309. decimal.TryParse(priArray[0], out ecoPri_kimiAI); //
  10310. decimal.TryParse(priArray[1], out bizPri_kimiAI); //经济舱价格
  10311. }
  10312. else return (false, "价格文本不存在价格或KIMI-AI未识别出价格,不可自动审核!");
  10313. var isAutoAudit = false;
  10314. //价格验证处理
  10315. //经济舱
  10316. if (ecoTypeIds.Contains(airInfo.CType))
  10317. {
  10318. if (airInfo.PrePrice <= ecoPri_kimiAI) isAutoAudit = true;
  10319. }
  10320. //公务舱
  10321. else if (bizTypeIds.Contains(airInfo.CType))
  10322. {
  10323. if (airInfo.PrePrice <= bizPri_kimiAI) isAutoAudit = true;
  10324. }
  10325. else return (false, "该舱位类型不在自动审核范围内,不可自动审核!");
  10326. //是否执行自动审核
  10327. if (isAutoAudit)
  10328. {
  10329. var auditStatus = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  10330. .SetColumns(x => x.IsAuditGM == 3)
  10331. .SetColumns(x => x.AuditGMOperate == 4)
  10332. .SetColumns(x => x.AuditGMDate == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  10333. .Where(x => x.Id == airInfo.CcpId)
  10334. .ExecuteCommandAsync();
  10335. if (auditStatus > 0) return (true, "机票自动审核(KIMI-AI识别方式)执行成功!");
  10336. }
  10337. return (false, "当前费用超过成本费用,不可自动审核!");
  10338. }
  10339. /// <summary>
  10340. /// 机票费用录入
  10341. /// 自动审核测试 - AI 识别
  10342. /// </summary>
  10343. /// <param name="groupId"></param>
  10344. /// <param name="Id"></param>
  10345. /// <returns></returns>
  10346. [HttpPost]
  10347. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10348. public async Task<IActionResult> AirTicketResAutoAuditTest(int groupId, int Id)
  10349. {
  10350. (bool status, string msg) = await AirTicketResAutoAudit(groupId, Id);
  10351. return Ok(JsonView(status, msg));
  10352. }
  10353. /// <summary>
  10354. /// 根据舱位类型查询接团客户名单信息
  10355. /// </summary>
  10356. /// <param name="dto"></param>
  10357. /// <returns></returns>
  10358. [HttpPost]
  10359. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10360. public async Task<IActionResult> TankType(AirTicketResByIdDto dto)
  10361. {
  10362. try
  10363. {
  10364. List<Crm_GroupCustomer> crm_Groups = _sqlSugar.Queryable<Crm_GroupCustomer>().Where(a => a.IsDel == 0 && a.AirType == dto.Id).ToList();
  10365. if (crm_Groups.Count != 0)
  10366. {
  10367. var Customer = new List<dynamic>();
  10368. foreach (var item in crm_Groups)
  10369. {
  10370. var data = new
  10371. {
  10372. item.Id,
  10373. item.Pinyin,
  10374. Name = item.LastName + item.FirstName
  10375. };
  10376. Customer.Add(data);
  10377. }
  10378. return Ok(JsonView(true, "查询成功!", Customer));
  10379. }
  10380. return Ok(JsonView(true, "暂无数据", crm_Groups));
  10381. }
  10382. catch (Exception ex)
  10383. {
  10384. return Ok(JsonView(false, "程序错误!"));
  10385. throw;
  10386. }
  10387. }
  10388. /// <summary>
  10389. /// 根据团号获取客户信息
  10390. /// </summary>
  10391. /// <param name="dto"></param>
  10392. /// <returns></returns>
  10393. [HttpPost]
  10394. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10395. public IActionResult QueryClientInfoByDIID(QueryClientInfoByDIIDDto dto)
  10396. {
  10397. var jw = JsonView(false);
  10398. if (dto.DIID < 1)
  10399. {
  10400. jw.Msg += "请输入正确的diid";
  10401. return Ok(jw);
  10402. }
  10403. var arr = GetSimplClientList(dto.DIID);
  10404. jw = JsonView(true, "获取成功!", arr);
  10405. return Ok(jw);
  10406. }
  10407. private List<SimplClientInfo> GetSimplClientList(int diId)
  10408. {
  10409. string sql = string.Format("select b.Id,b.Pinyin,b.lastName,b.firstName,b.phone from Grp_TourClientList a, Crm_DeleClient b where a.clientid = b.id and a.isdel = 0 and a.diid = {0}", diId);
  10410. List<SimplClientInfo> arr = _sqlSugar.SqlQueryable<SimplClientInfo>(sql).ToList();
  10411. foreach (var item in arr)
  10412. {
  10413. EncryptionProcessor.DecryptProperties(item);
  10414. }
  10415. return arr;
  10416. }
  10417. private static string GetClientNameStr(List<SimplClientInfo> list, string origin)
  10418. {
  10419. string result = origin;
  10420. if (Regex.Match(origin, @"\d+,?").Value.Length > 0)
  10421. {
  10422. string[] temparr = origin.Split(',');
  10423. string fistrStr = temparr[0];
  10424. int count = temparr.Length;
  10425. bool success = int.TryParse(fistrStr, out int tempId);
  10426. if (success)
  10427. {
  10428. SimplClientInfo tempInfo = list.FirstOrDefault(s => s.Id == tempId);
  10429. if (tempInfo != null)
  10430. {
  10431. if (count > 1)
  10432. {
  10433. result = string.Format(@"{0}{1}等{2}人", tempInfo.LastName, tempInfo.FirstName, count);
  10434. }
  10435. else
  10436. {
  10437. result = string.Format(@"{0}{1}", tempInfo.LastName, tempInfo.FirstName);
  10438. }
  10439. }
  10440. }
  10441. }
  10442. return result;
  10443. }
  10444. private static string GetClientNameStr1(List<SimplClientInfo> list, string origin)
  10445. {
  10446. string result = origin;
  10447. if (Regex.Match(origin, @"\d+,?").Value.Length > 0)
  10448. {
  10449. string[] temparr = origin.Split(',');
  10450. result = "";
  10451. foreach (var item in temparr)
  10452. {
  10453. bool success = int.TryParse(item, out int tempId);
  10454. if (success)
  10455. {
  10456. SimplClientInfo tempInfo = list.FirstOrDefault(s => s.Id == tempId);
  10457. if (tempInfo != null)
  10458. {
  10459. result += string.Format(@"{0}{1}、", tempInfo.LastName, tempInfo.FirstName);
  10460. }
  10461. }
  10462. }
  10463. }
  10464. if (result.Length > 0) result = result.Substring(0, result.Length - 1);
  10465. return result;
  10466. }
  10467. /// <summary>
  10468. /// 机票费用录入,删除
  10469. /// </summary>
  10470. /// <param name="dto"></param>
  10471. /// <returns></returns>
  10472. [HttpPost]
  10473. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10474. public async Task<IActionResult> DelAirTicketRes(DelBaseDto dto)
  10475. {
  10476. try
  10477. {
  10478. //验证
  10479. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 85);
  10480. if (!valid) return Ok(JsonView(false, msg));
  10481. var res = await _airTicketResRep.SoftDeleteByIdAsync<Grp_AirTicketReservations>(dto.Id.ToString(), dto.DeleteUserId);
  10482. if (res)
  10483. {
  10484. var result = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == dto.Id && a.CTable == 85).SetColumns(a => new Grp_CreditCardPayment()
  10485. {
  10486. IsDel = 1,
  10487. DeleteUserId = dto.DeleteUserId,
  10488. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  10489. }).ExecuteCommandAsync();
  10490. return Ok(JsonView(true, "删除成功!"));
  10491. }
  10492. return Ok(JsonView(false, "删除失败!"));
  10493. }
  10494. catch (Exception ex)
  10495. {
  10496. return Ok(JsonView(false, "程序错误!"));
  10497. }
  10498. }
  10499. /// <summary>
  10500. /// 导出机票录入报表
  10501. /// </summary>
  10502. /// <param name="dto"></param>
  10503. /// <returns></returns>
  10504. [HttpPost]
  10505. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10506. public async Task<IActionResult> DeriveAirTicketRes(AirTicketResDto dto)
  10507. {
  10508. try
  10509. {
  10510. Result groupData = await _airTicketResRep.DeriveAirTicketRes(dto);
  10511. if (groupData.Code != 0)
  10512. {
  10513. return Ok(JsonView(StatusCodes.Status400BadRequest, groupData.Msg, ""));
  10514. }
  10515. else
  10516. {
  10517. List<AirTicketReservationsPayView> AirTicketReservations = groupData.Data.GetType().GetProperty("AirTicketRes").GetValue(groupData.Data);
  10518. if (AirTicketReservations.Count != 0)
  10519. {
  10520. Grp_DelegationInfo DelegationInfo = groupData.Data.GetType().GetProperty("Delegation").GetValue(groupData.Data);
  10521. Sys_Users _Users = groupData.Data.GetType().GetProperty("Users").GetValue(groupData.Data);
  10522. string diCode = DelegationInfo != null ? DelegationInfo.TourCode : "XXX";
  10523. string diName = DelegationInfo != null ? DelegationInfo.TeamName : "XXX";
  10524. var designer = new WorkbookDesigner
  10525. {
  10526. Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/机票预订费用报表模板.xlsx")
  10527. };
  10528. decimal countCost = 0;
  10529. foreach (var item in AirTicketReservations)
  10530. {
  10531. #region 处理客人姓名
  10532. string clientNames = _tourClientListRep.ResolveCustomerName(item.ClientName);
  10533. item.ClientName = clientNames;
  10534. #endregion
  10535. if (item.BankType == "其他")
  10536. {
  10537. item.BankNo = "--";
  10538. }
  10539. else
  10540. {
  10541. if (!string.IsNullOrEmpty(item.BankType))
  10542. {
  10543. item.BankNo = $"{item.BankType}:{item.BankNo?[..3]}";
  10544. }
  10545. }
  10546. item.PrePrice = System.Decimal.Round(item.PrePrice, 2);
  10547. item.Price = System.Decimal.Round(item.Price, 2);
  10548. countCost += Convert.ToDecimal(item.Price);
  10549. }
  10550. designer.SetDataSource("Export", AirTicketReservations);
  10551. designer.SetDataSource("ExportDiCode", diCode);
  10552. designer.SetDataSource("ExportDiName", diName);
  10553. designer.SetDataSource("ExportOpUserName", _Users.CnName);
  10554. designer.SetDataSource("ExportCountCost", countCost + "(" + AirTicketReservations[0].CurrencyStr);
  10555. designer.Process();
  10556. string fileName = ("AirfareStatement/" + diName + "机票费用报表" + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx").Replace(":", "");
  10557. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  10558. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  10559. return Ok(JsonView(true, "成功", url = rst));
  10560. }
  10561. else
  10562. {
  10563. return Ok(JsonView(StatusCodes.Status400BadRequest, "暂无数据!", ""));
  10564. }
  10565. }
  10566. }
  10567. catch (Exception ex)
  10568. {
  10569. return Ok(JsonView(StatusCodes.Status400BadRequest, ex.Message, ""));
  10570. throw;
  10571. }
  10572. }
  10573. private Dictionary<string, string> transDic = new Dictionary<string, string>();
  10574. /// <summary>
  10575. /// 行程单导出
  10576. /// </summary>
  10577. /// <param name="dto"></param>
  10578. /// <returns></returns>
  10579. [HttpPost]
  10580. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10581. public async Task<IActionResult> ItineraryAirTicketRes(ItineraryAirTicketResDto dto)
  10582. {
  10583. try
  10584. {
  10585. Result groupData = await _airTicketResRep.ItineraryAirTicketRes(dto);
  10586. if (groupData.Code != 0)
  10587. {
  10588. return Ok(JsonView(StatusCodes.Status400BadRequest, groupData.Msg, ""));
  10589. }
  10590. else
  10591. {
  10592. List<AirTicketReservationsView> _AirTicketReservations = groupData.Data;
  10593. if (dto.Language == "CN")
  10594. {
  10595. var doc = new Document(AppSettingsHelper.Get("WordBasePath") + "Template/电子客票行程单模板_CN.docx");
  10596. var builder = new DocumentBuilder(doc);
  10597. int tableIndex = 0;//表格索引
  10598. //得到文档中的第一个表格
  10599. Table table = (Table)doc.GetChild(NodeType.Table, tableIndex, true);
  10600. foreach (var item in _AirTicketReservations)
  10601. {
  10602. #region 处理固定数据
  10603. string[] FlightsCode = item.FlightsCode.Split('/');
  10604. if (FlightsCode.Length != 0)
  10605. {
  10606. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  10607. if (_AirCompany != null)
  10608. {
  10609. table.Range.Bookmarks["AirlineCompany"].Text = _AirCompany.CnName;
  10610. }
  10611. else
  10612. {
  10613. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  10614. }
  10615. }
  10616. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  10617. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  10618. string[] nameArray = Regex.Split(item.ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  10619. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  10620. string name = "";
  10621. foreach (string clientName in nameArray)
  10622. {
  10623. if (!name.Contains(clientName))
  10624. {
  10625. name += clientName + ",";
  10626. }
  10627. }
  10628. if (!string.IsNullOrWhiteSpace(name))
  10629. {
  10630. table.Range.Bookmarks["ClientName"].Text = name.Substring(0, name.Length - 1);
  10631. }
  10632. else
  10633. {
  10634. table.Range.Bookmarks["ClientName"].Text = "--";
  10635. }
  10636. table.Range.Bookmarks["TicketNumber"].Text = "--";
  10637. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  10638. table.Range.Bookmarks["JointTicket"].Text = "--";
  10639. table.Range.Bookmarks["TimeIssue"].Text = "--";
  10640. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  10641. table.Range.Bookmarks["NavigationCode"].Text = "--";
  10642. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  10643. table.Range.Bookmarks["AgentPhone"].Text = "--";
  10644. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  10645. #endregion
  10646. #region 循环数据处理
  10647. var airs = new List<AirInfo>();
  10648. string[] DayArray = Regex.Split(item.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase);
  10649. DayArray = DayArray.Where(s => s != " " && s != "" && !string.IsNullOrEmpty(s)).ToArray();
  10650. for (int i = 0; i < FlightsCode.Length; i++)
  10651. {
  10652. var air = new AirInfo();
  10653. string[] tempstr = DayArray[i]
  10654. .Replace("\r\n", string.Empty)
  10655. .Replace("\\r\\n", string.Empty)
  10656. .TrimStart().TrimEnd()
  10657. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  10658. Res_ThreeCode star_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(0, 3));
  10659. string starCity = "";
  10660. if (star_Three != null)
  10661. {
  10662. starCity = star_Three.AirPort;
  10663. }
  10664. Res_ThreeCode End_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(3, 3));
  10665. string EndCity = "";
  10666. if (End_Three != null)
  10667. {
  10668. EndCity = End_Three.AirPort;
  10669. }
  10670. air.Destination = starCity + "/" + EndCity;
  10671. air.Flight = FlightsCode[i];
  10672. air.SeatingClass = item.CTypeName;
  10673. string dateTime = tempstr[2];
  10674. string DateTemp = dateTime.Substring(2, 5).ToUpper();
  10675. air.FlightDate = DateTemp;
  10676. air.DepartureTime = tempstr[5];
  10677. air.LandingTime = tempstr[6];
  10678. air.ValidityPeriod = DateTemp + "/" + DateTemp;
  10679. air.TicketStatus = "--";
  10680. air.Luggage = "--";
  10681. air.DepartureTerminal = "--";
  10682. air.LandingTerminal = "--";
  10683. airs.Add(air);
  10684. }
  10685. int row = 13;
  10686. for (int i = 0; i < airs.Count; i++)
  10687. {
  10688. if (airs.Count > 2)
  10689. {
  10690. for (int j = 0; j < airs.Count - 2; j++)
  10691. {
  10692. var CopyRow = table.Rows[12].Clone(true);
  10693. table.Rows.Add(CopyRow);
  10694. }
  10695. }
  10696. PropertyInfo[] properties = airs[i].GetType().GetProperties();
  10697. int index = 0;
  10698. foreach (PropertyInfo property in properties)
  10699. {
  10700. string value = property.GetValue(airs[i]).ToString();
  10701. Cell ishcel0 = table.Rows[row].Cells[index];
  10702. var p = new Paragraph(doc);
  10703. string s = value;
  10704. p.AppendChild(new Run(doc, s));
  10705. p.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐
  10706. ishcel0.AppendChild(p);
  10707. ishcel0.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
  10708. index++;
  10709. }
  10710. row++;
  10711. }
  10712. #endregion
  10713. var lastParagraph = new Paragraph(doc);
  10714. //第一个表格末尾加段落
  10715. table.ParentNode.InsertAfter(lastParagraph, table);
  10716. //复制第一个表格
  10717. Table cloneTable = (Table)table.Clone(true);
  10718. //在文档末尾段落后面加入复制的表格
  10719. table.ParentNode.InsertAfter(cloneTable, lastParagraph);
  10720. if (item != _AirTicketReservations[_AirTicketReservations.Count - 1])
  10721. {
  10722. int rownewsIndex = 13;
  10723. for (int i = 0; i < 2; i++)
  10724. {
  10725. var CopyRow = table.Rows[12].Clone(true);
  10726. table.Rows.RemoveAt(13);
  10727. table.Rows.Add(CopyRow);
  10728. rownewsIndex++;
  10729. }
  10730. }
  10731. else
  10732. {
  10733. table.Rows.RemoveAt(12);
  10734. }
  10735. cloneTable.Rows.RemoveAt(12);
  10736. }
  10737. if (_AirTicketReservations.Count != 0)
  10738. {
  10739. string[] FlightsCode = _AirTicketReservations[0].FlightsCode.Split('/');
  10740. if (FlightsCode.Length != 0)
  10741. {
  10742. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  10743. if (_AirCompany != null)
  10744. {
  10745. table.Range.Bookmarks["AirlineCompany"].Text = _AirCompany.CnName;
  10746. }
  10747. else
  10748. {
  10749. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  10750. }
  10751. }
  10752. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  10753. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  10754. string[] nameArray = Regex.Split(_AirTicketReservations[0].ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  10755. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  10756. string name = "";
  10757. foreach (string clientName in nameArray)
  10758. {
  10759. if (!name.Contains(clientName))
  10760. {
  10761. name += clientName + ",";
  10762. }
  10763. }
  10764. if (!string.IsNullOrWhiteSpace(name))
  10765. {
  10766. table.Range.Bookmarks["ClientName"].Text = name.Substring(0, name.Length - 1);
  10767. }
  10768. else
  10769. {
  10770. table.Range.Bookmarks["ClientName"].Text = "--";
  10771. }
  10772. table.Range.Bookmarks["TicketNumber"].Text = "--";
  10773. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  10774. table.Range.Bookmarks["JointTicket"].Text = "--";
  10775. table.Range.Bookmarks["TimeIssue"].Text = "--";
  10776. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  10777. table.Range.Bookmarks["NavigationCode"].Text = "--";
  10778. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  10779. table.Range.Bookmarks["AgentPhone"].Text = "--";
  10780. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  10781. }
  10782. doc.MailMerge.Execute(new[] { "PageCount" }, new object[] { doc.PageCount });
  10783. //保存合并后的文档
  10784. string fileName = "AirItinerary/电子客票中文行程单_CN.docx";
  10785. string rst = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + fileName;
  10786. doc.Save(AppSettingsHelper.Get("WordBasePath") + fileName);
  10787. return Ok(JsonView(true, "成功!", rst));
  10788. }
  10789. else
  10790. {
  10791. var doc = new Document(AppSettingsHelper.Get("WordBasePath") + "Template/电子客票行程单模板_EN.docx");
  10792. var builder = new DocumentBuilder(doc);
  10793. int tableIndex = 0;//表格索引
  10794. //得到文档中的第一个表格
  10795. Table table = (Table)doc.GetChild(NodeType.Table, tableIndex, true);
  10796. var texts = new List<string>();
  10797. foreach (var item in _AirTicketReservations)
  10798. {
  10799. string[] FlightsCode = item.FlightsCode.Split('/');
  10800. if (FlightsCode.Length != 0)
  10801. {
  10802. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  10803. if (_AirCompany != null)
  10804. {
  10805. if (!transDic.ContainsKey(_AirCompany.CnName))
  10806. {
  10807. transDic.Add(_AirCompany.CnName, _AirCompany.EnName);
  10808. }
  10809. }
  10810. else
  10811. {
  10812. if (!transDic.ContainsKey("--"))
  10813. {
  10814. transDic.Add("--", "--");
  10815. }
  10816. }
  10817. }
  10818. string[] nameArray = Regex.Split(item.ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  10819. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  10820. string name = "";
  10821. foreach (string clientName in nameArray)
  10822. {
  10823. name += clientName + ",";
  10824. }
  10825. if (!texts.Contains(name))
  10826. {
  10827. texts.Add(name);
  10828. }
  10829. var airs = new List<AirInfo>();
  10830. string[] DayArray = Regex.Split(item.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase);
  10831. DayArray = DayArray.Where(s => s != " " && s != "" && !string.IsNullOrEmpty(s)).ToArray();
  10832. for (int i = 0; i < FlightsCode.Length; i++)
  10833. {
  10834. var air = new AirInfo();
  10835. string[] tempstr = DayArray[i]
  10836. .Replace("\r\n", string.Empty)
  10837. .Replace("\\r\\n", string.Empty)
  10838. .TrimStart().TrimEnd()
  10839. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  10840. Res_ThreeCode star_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(0, 3));
  10841. if (star_Three != null)
  10842. {
  10843. if (!transDic.ContainsKey(star_Three.AirPort))
  10844. {
  10845. transDic.Add(star_Three.AirPort, star_Three.AirPort_En);
  10846. }
  10847. }
  10848. Res_ThreeCode End_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(3, 3));
  10849. if (End_Three != null)
  10850. {
  10851. if (!transDic.ContainsKey(End_Three.AirPort))
  10852. {
  10853. transDic.Add(End_Three.AirPort, End_Three.AirPort_En);
  10854. }
  10855. }
  10856. if (!texts.Contains(item.CTypeName))
  10857. {
  10858. texts.Add(item.CTypeName);
  10859. }
  10860. }
  10861. }
  10862. List<TranslateResult> transData = await _airTicketResRep.ReTransBatch(texts, "en");
  10863. if (transData.Count > 0)
  10864. {
  10865. foreach (TranslateResult item in transData)
  10866. {
  10867. if (!transDic.ContainsKey(item.Query))
  10868. {
  10869. transDic.Add(item.Query, item.Translation);
  10870. }
  10871. }
  10872. }
  10873. foreach (var item in _AirTicketReservations)
  10874. {
  10875. #region 处理固定数据
  10876. string[] FlightsCode = item.FlightsCode.Split('/');
  10877. if (FlightsCode.Length != 0)
  10878. {
  10879. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  10880. if (_AirCompany != null)
  10881. {
  10882. string str = "--";
  10883. string translateResult = transDic.Where(s => s.Key == _AirCompany.CnName).FirstOrDefault().Value;
  10884. if (!string.IsNullOrEmpty(translateResult))
  10885. {
  10886. str = translateResult;
  10887. str = _airTicketResRep.Processing(str);
  10888. }
  10889. table.Range.Bookmarks["AirlineCompany"].Text = str;
  10890. }
  10891. else
  10892. {
  10893. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  10894. }
  10895. }
  10896. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  10897. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  10898. string[] nameArray = Regex.Split(item.ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  10899. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  10900. string names = "";
  10901. foreach (string clientName in nameArray)
  10902. {
  10903. names += clientName + ",";
  10904. }
  10905. if (!string.IsNullOrWhiteSpace(names))
  10906. {
  10907. string str = "--";
  10908. string translateResult = transDic.Where(s => s.Key == names).FirstOrDefault().Value;
  10909. if (!string.IsNullOrEmpty(translateResult))
  10910. {
  10911. str = translateResult;
  10912. str = _airTicketResRep.Processing(str);
  10913. }
  10914. table.Range.Bookmarks["ClientName"].Text = str;
  10915. }
  10916. else
  10917. {
  10918. table.Range.Bookmarks["ClientName"].Text = "--";
  10919. }
  10920. table.Range.Bookmarks["TicketNumber"].Text = "--";
  10921. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  10922. table.Range.Bookmarks["JointTicket"].Text = "--";
  10923. table.Range.Bookmarks["TimeIssue"].Text = "--";
  10924. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  10925. table.Range.Bookmarks["NavigationCode"].Text = "--";
  10926. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  10927. table.Range.Bookmarks["AgentPhone"].Text = "--";
  10928. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  10929. #endregion
  10930. #region 循环数据处理
  10931. var airs = new List<AirInfo>();
  10932. string[] DayArray = Regex.Split(item.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase);
  10933. DayArray = DayArray.Where(s => s != " " && s != "" && !string.IsNullOrEmpty(s)).ToArray();
  10934. for (int i = 0; i < FlightsCode.Length; i++)
  10935. {
  10936. var air = new AirInfo();
  10937. string[] tempstr = DayArray[i]
  10938. .Replace("\r\n", string.Empty)
  10939. .Replace("\\r\\n", string.Empty)
  10940. .TrimStart().TrimEnd()
  10941. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  10942. Res_ThreeCode star_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(0, 3));
  10943. string starCity = "";
  10944. if (star_Three != null)
  10945. {
  10946. string str2 = "--";
  10947. string translateResult2 = transDic.Where(s => s.Key == star_Three.AirPort).FirstOrDefault().Value;
  10948. if (!string.IsNullOrEmpty(translateResult2))
  10949. {
  10950. str2 = translateResult2;
  10951. str2 = _airTicketResRep.Processing(str2);
  10952. }
  10953. starCity = str2;
  10954. }
  10955. Res_ThreeCode End_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(3, 3));
  10956. string EndCity = "";
  10957. if (End_Three != null)
  10958. {
  10959. string str1 = "--";
  10960. string translateResult1 = transDic.Where(s => s.Key == End_Three.AirPort).FirstOrDefault().Value;
  10961. if (!string.IsNullOrEmpty(translateResult1))
  10962. {
  10963. str1 = translateResult1;
  10964. str1 = _airTicketResRep.Processing(str1);
  10965. }
  10966. EndCity = str1;
  10967. }
  10968. air.Destination = starCity + "/" + EndCity;
  10969. air.Flight = FlightsCode[i];
  10970. string str = "--";
  10971. string translateResult = transDic.Where(s => s.Key == item.CTypeName).FirstOrDefault().Value;
  10972. if (!string.IsNullOrEmpty(translateResult))
  10973. {
  10974. str = translateResult;
  10975. str = _airTicketResRep.Processing(str);
  10976. }
  10977. air.SeatingClass = str;
  10978. string dateTime = tempstr[2];
  10979. string DateTemp = dateTime.Substring(2, 5).ToUpper();
  10980. air.FlightDate = DateTemp;
  10981. air.DepartureTime = tempstr[5];
  10982. air.LandingTime = tempstr[6];
  10983. air.ValidityPeriod = DateTemp + "/" + DateTemp;
  10984. air.TicketStatus = "--";
  10985. air.Luggage = "--";
  10986. air.DepartureTerminal = "--";
  10987. air.LandingTerminal = "--";
  10988. airs.Add(air);
  10989. }
  10990. int row = 13;
  10991. for (int i = 0; i < airs.Count; i++)
  10992. {
  10993. if (airs.Count > 2)
  10994. {
  10995. for (int j = 0; j < airs.Count - 2; j++)
  10996. {
  10997. var CopyRow = table.Rows[12].Clone(true);
  10998. table.Rows.Add(CopyRow);
  10999. }
  11000. }
  11001. PropertyInfo[] properties = airs[i].GetType().GetProperties();
  11002. int index = 0;
  11003. foreach (PropertyInfo property in properties)
  11004. {
  11005. string value = property.GetValue(airs[i]).ToString();
  11006. Cell ishcel0 = table.Rows[row].Cells[index];
  11007. var p = new Paragraph(doc);
  11008. string s = value;
  11009. p.AppendChild(new Run(doc, s));
  11010. p.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐
  11011. ishcel0.AppendChild(p);
  11012. ishcel0.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
  11013. //ishcel0.CellFormat.VerticalAlignment=
  11014. index++;
  11015. }
  11016. row++;
  11017. }
  11018. #endregion
  11019. var lastParagraph = new Paragraph(doc);
  11020. //第一个表格末尾加段落
  11021. table.ParentNode.InsertAfter(lastParagraph, table);
  11022. //复制第一个表格
  11023. Table cloneTable = (Table)table.Clone(true);
  11024. //在文档末尾段落后面加入复制的表格
  11025. table.ParentNode.InsertAfter(cloneTable, lastParagraph);
  11026. if (item != _AirTicketReservations[_AirTicketReservations.Count - 1])
  11027. {
  11028. int rownewsIndex = 13;
  11029. for (int i = 0; i < 2; i++)
  11030. {
  11031. var CopyRow = table.Rows[12].Clone(true);
  11032. table.Rows.RemoveAt(13);
  11033. table.Rows.Add(CopyRow);
  11034. rownewsIndex++;
  11035. }
  11036. }
  11037. else
  11038. {
  11039. table.Rows.RemoveAt(12);
  11040. }
  11041. cloneTable.Rows.RemoveAt(12);
  11042. }
  11043. if (_AirTicketReservations.Count != 0)
  11044. {
  11045. string[] FlightsCode = _AirTicketReservations[0].FlightsCode.Split('/');
  11046. if (FlightsCode.Length != 0)
  11047. {
  11048. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  11049. if (_AirCompany != null)
  11050. {
  11051. string str = "--";
  11052. string translateResult = transDic.Where(s => s.Key == _AirCompany.CnName).FirstOrDefault().Value;
  11053. if (!string.IsNullOrEmpty(translateResult))
  11054. {
  11055. str = translateResult;
  11056. str = _airTicketResRep.Processing(str);
  11057. }
  11058. table.Range.Bookmarks["AirlineCompany"].Text = str;
  11059. }
  11060. else
  11061. {
  11062. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  11063. }
  11064. }
  11065. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  11066. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  11067. string[] nameArray = Regex.Split(_AirTicketReservations[0].ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  11068. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  11069. string names = "";
  11070. foreach (string clientName in nameArray)
  11071. {
  11072. names += clientName + ",";
  11073. }
  11074. if (!string.IsNullOrWhiteSpace(names))
  11075. {
  11076. string str = "--";
  11077. string translateResult = transDic.Where(s => s.Key == names).FirstOrDefault().Value;
  11078. if (!string.IsNullOrEmpty(translateResult))
  11079. {
  11080. str = translateResult;
  11081. str = _airTicketResRep.Processing(str);
  11082. }
  11083. table.Range.Bookmarks["ClientName"].Text = str;
  11084. }
  11085. else
  11086. {
  11087. table.Range.Bookmarks["ClientName"].Text = "--";
  11088. }
  11089. table.Range.Bookmarks["TicketNumber"].Text = "--";
  11090. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  11091. table.Range.Bookmarks["JointTicket"].Text = "--";
  11092. table.Range.Bookmarks["TimeIssue"].Text = "--";
  11093. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  11094. table.Range.Bookmarks["NavigationCode"].Text = "--";
  11095. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  11096. table.Range.Bookmarks["AgentPhone"].Text = "--";
  11097. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  11098. }
  11099. doc.MailMerge.Execute(new[] { "PageCount" }, new object[] { doc.PageCount });
  11100. //保存合并后的文档
  11101. string fileName = "AirItinerary/电子客票英文行程单_EN.docx";
  11102. string rst = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + fileName;
  11103. doc.Save(AppSettingsHelper.Get("WordBasePath") + fileName);
  11104. return Ok(JsonView(true, "成功!", rst));
  11105. }
  11106. }
  11107. }
  11108. catch (Exception ex)
  11109. {
  11110. return Ok(JsonView(StatusCodes.Status400BadRequest, "程序错误!", ""));
  11111. throw;
  11112. }
  11113. }
  11114. #endregion
  11115. #region 团组增减款项 --> 其他款项
  11116. /// <summary>
  11117. /// 团组增减款项下拉框绑定
  11118. /// </summary>
  11119. /// <param name="dto"></param>
  11120. /// <returns></returns>
  11121. [HttpPost]
  11122. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11123. public async Task<IActionResult> DecreasePaymentsSelect(DecreasePaymentsDto dto)
  11124. {
  11125. #region 参数验证
  11126. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  11127. if (dto.CTId < 1) return Ok(JsonView(false, "请传入有效的CTId参数!"));
  11128. #endregion
  11129. return Ok(await _decreasePaymentsRep.DecreasePaymentsSelect(dto));
  11130. }
  11131. /// <summary>
  11132. /// 根据团组Id查询团组增减款项
  11133. /// </summary>
  11134. /// <param name="dto"></param>
  11135. /// <returns></returns>
  11136. [HttpPost]
  11137. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11138. public async Task<IActionResult> DecreasePaymentsList(DecreasePaymentsListDto dto)
  11139. {
  11140. #region 参数验证
  11141. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  11142. if (dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId参数!"));
  11143. #endregion
  11144. return Ok(await _decreasePaymentsRep.DecreasePaymentsList(dto));
  11145. }
  11146. /// <summary>
  11147. /// 团组增减款项操作(Status:1.新增,2.修改)
  11148. /// </summary>
  11149. /// <param name="dto"></param>
  11150. /// <returns></returns>
  11151. [HttpPost]
  11152. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11153. public async Task<IActionResult> OpDecreasePayments(DecreasePaymentsOpDto dto)
  11154. {
  11155. JsonView groupData = await _decreasePaymentsRep.OpDecreasePayments(dto);
  11156. if (groupData.Code != 200)
  11157. {
  11158. return Ok(JsonView(false, groupData.Msg));
  11159. }
  11160. #region 应用推送
  11161. //int otherId = (int)groupData.Data.GetType().GetProperty("dataId").GetValue(groupData.Data, null);
  11162. //int ccpId = (int)groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  11163. //int sign = (int)groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  11164. int otherId = Convert.ToInt32(groupData.Data.GetType().GetProperty("dataId").GetValue(groupData.Data, null) ?? 0);
  11165. int ccpId = Convert.ToInt32(groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null) ?? 0);
  11166. int sign = Convert.ToInt32(groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null) ?? 0);
  11167. bool recheck = Convert.ToBoolean(groupData.Data.GetType().GetProperty("recheck").GetValue(groupData.Data, null) ?? "True");
  11168. if (recheck)
  11169. {
  11170. //自动审核
  11171. var autoAdit = await _feeAuditRep.FeeAutomaticAudit(3, dto.DiId, otherId);
  11172. }
  11173. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  11174. //2024-10-21 新增LZ UID
  11175. var userIds = new List<int>() { 21 };
  11176. string title = $"系统通知";
  11177. string content = "";
  11178. var diId = dto.DiId;
  11179. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  11180. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  11181. if (dto.Status == 1) content = $"[新增-其他款项({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  11182. else if (dto.Status == 2) content = $"[更新-其他款项({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  11183. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  11184. //await APNsTools.iOS_PushNotifications1("051", $"其他款项费用审核", "", content);
  11185. #endregion
  11186. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  11187. }
  11188. /// <summary>
  11189. /// 团组增减款项操作 删除
  11190. /// </summary>
  11191. /// <param name="dto"></param>
  11192. /// <returns></returns>
  11193. [HttpPost]
  11194. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11195. public async Task<IActionResult> DelDecreasePayments(DelBaseDto dto)
  11196. {
  11197. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数!"));
  11198. if (dto.DeleteUserId < 1) return Ok(JsonView(false, "请传入有效的DeleteUserId参数!"));
  11199. var res = await _decreasePaymentsRep._Del(dto.Id, dto.DeleteUserId);
  11200. if (res.Code == 0) return Ok(JsonView(true, "删除成功!"));
  11201. return Ok(JsonView(false, res?.Msg ?? "删除失败!"));
  11202. }
  11203. /// <summary>
  11204. /// 根据团组增减款项Id查询
  11205. /// </summary>
  11206. /// <param name="dto"></param>
  11207. /// <returns></returns>
  11208. [HttpPost]
  11209. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11210. public async Task<IActionResult> QueryDecreasePaymentsById(DecreasePaymentsByIdDto dto)
  11211. {
  11212. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的数据Id!"));
  11213. return Ok(await _decreasePaymentsRep.QueryDecreasePaymentsById(dto));
  11214. }
  11215. /// <summary>
  11216. /// 查询供应商名称
  11217. /// </summary>
  11218. /// <param name="dto"></param>
  11219. /// <returns></returns>
  11220. [HttpPost]
  11221. public IActionResult QueryAssociateSupplier(AssociateSupplierDto dto)
  11222. {
  11223. var dbResult = _sqlSugar.Queryable<Grp_DecreasePayments>()
  11224. .Where(x => x.SupplierName.Contains(dto.param) && x.IsDel == 0).ToList()
  11225. ?? new List<Grp_DecreasePayments>();
  11226. dbResult = dbResult.Distinct(new
  11227. ProductComparer()).ToList();
  11228. var jw = JsonView(true, "success", dbResult.OrderByDescending(x => x.Id).Select(x => new
  11229. {
  11230. x.Id,
  11231. x.SupplierAddress,
  11232. x.SupplierArea,
  11233. x.SupplierContact,
  11234. x.SupplierContactNumber,
  11235. x.SupplierEmail,
  11236. x.SupplierName,
  11237. x.SupplierSocialAccount,
  11238. x.SupplierTypeId,
  11239. }).ToList());
  11240. return Ok(jw);
  11241. }
  11242. /// <summary>
  11243. /// 团组增减款项 OTA匹配
  11244. /// </summary>
  11245. /// <param name="file"></param>
  11246. /// <returns></returns>
  11247. [HttpPost]
  11248. public async Task<IActionResult> DecreasePaymentsOTAMate(IFormFile file)
  11249. {
  11250. if (file.Length < 1) return Ok(JsonView(false, "请上传文件!"));
  11251. string fileName = file.FileName;
  11252. if (!fileName.EndsWith(".xlsx") && !fileName.EndsWith(".xls"))
  11253. {
  11254. return Ok(JsonView(false, "请上传Excel文件!"));
  11255. }
  11256. //D:\FTP\File\OA2023\Office\GrpFile\团组增减款项相关文件\团组其他款项(OTA)
  11257. var path = @$"{AppSettingsHelper.Get("GrpFileBasePath")}团组增减款项相关文件/团组其他款项(OTA)";
  11258. if (!Directory.Exists(path))
  11259. {
  11260. Directory.CreateDirectory(path);
  11261. }
  11262. var filePath = @$"{path}/{fileName}";
  11263. //保存文件
  11264. using (FileStream fs = System.IO.File.Create(filePath))
  11265. {
  11266. file.CopyTo(fs);
  11267. fs.Flush();
  11268. }
  11269. if (!System.IO.File.Exists(filePath)) return Ok(JsonView(false, "文件不存在!"));
  11270. //读取ExcelFile
  11271. DataTable dt = ConvertExcelToDataTable(filePath);
  11272. if (dt == null) return Ok(JsonView(false, $"您上传的Excel工作表没有内容,请检查!!!"));
  11273. dt.TableName = "TB";
  11274. //修改table列名
  11275. dt.Columns[0].ColumnName = "OrderNo"; // 订单号
  11276. dt.Columns[1].ColumnName = "OTAOrderNo"; // OTA订单号
  11277. dt.Columns[2].ColumnName = "PackageName"; // 套餐名
  11278. dt.Columns[3].ColumnName = "IsPay"; // 是否支付
  11279. dt.Columns[4].ColumnName = "IsShipments"; // 是否发货
  11280. dt.Columns[5].ColumnName = "IsSendBack"; // 是否寄回
  11281. dt.Columns[6].ColumnName = "OpUser"; // 使用人信息
  11282. dt.Columns[7].ColumnName = "OrderTime"; // 下单时间
  11283. dt.Columns[8].ColumnName = "UseTime"; // 使用时间
  11284. dt.Columns[9].ColumnName = "Quantity"; // 台数
  11285. dt.Columns[10].ColumnName = "Days"; // 租赁天数
  11286. dt.Columns[11].ColumnName = "QuantityShipped";// 发货数量
  11287. dt.Columns[12].ColumnName = "TotalPrice"; // 总金额
  11288. dt.Columns[13].ColumnName = "GroupName"; // 团组名称
  11289. dt.Columns[14].ColumnName = "OATotalPrice"; // OA金额
  11290. var otaOrderNos = new List<string>();
  11291. foreach (DataRow item in dt.Rows)
  11292. {
  11293. otaOrderNos.Add(item["OTAOrderNo"].ToString());
  11294. }
  11295. var oaDatas = await _sqlSugar.Queryable<Grp_DecreasePayments>()
  11296. .LeftJoin<Grp_DelegationInfo>((dp, di) => dp.DiId == di.Id)
  11297. .Where((dp, di) => dp.IsDel == 0 && dp.PriceName.Contains("wifi") || otaOrderNos.Contains(dp.OTAOrderNo))
  11298. .Select((dp, di) => new
  11299. {
  11300. dp.PriceName,
  11301. dp.OTAOrderNo,
  11302. dp.FeeTotal,
  11303. di.TeamName,
  11304. })
  11305. .ToListAsync();
  11306. foreach (DataRow item in dt.Rows)
  11307. {
  11308. var otaOrderNo = item["OTAOrderNo"].ToString();
  11309. var oaData = oaDatas.Find(x => !string.IsNullOrEmpty(x.OTAOrderNo) && x.OTAOrderNo.Contains(otaOrderNo));
  11310. if (oaData == null) continue;
  11311. item["GroupName"] = oaData.TeamName;
  11312. item["OATotalPrice"] = oaData.FeeTotal.ToString("#0.00");
  11313. }
  11314. string fileName1 = $"OTA_WIFI费用{DateTime.Now:yyyyMMddHHmmss}.xls";
  11315. var pairs = new Dictionary<string, object>();
  11316. var datas = new List<DataTable>
  11317. {
  11318. dt
  11319. };
  11320. url = AsposeHelper.ExpertExcelToModel("WIFI费用清单-模板.xlsx", $"GrpFile/团组增减款项相关文件/团组其他款项(OTA)", fileName1, pairs, datas);
  11321. return Ok(JsonView(true, "操作成功", new { url }));
  11322. }
  11323. #region
  11324. private static DataTable ConvertExcelToDataTable(string excelFilePath)
  11325. {
  11326. // 创建Workbook对象
  11327. var workbook = new Workbook(excelFilePath);
  11328. // 获取第一个工作表
  11329. var worksheet = workbook.Worksheets[0];
  11330. // 将工作表转换为DataTable
  11331. DataTable dataTable = worksheet.Cells.ExportDataTable(1, 0, worksheet.Cells.MaxDataRow + 1, worksheet.Cells.MaxDataColumn + 1);
  11332. return dataTable;
  11333. }
  11334. #endregion
  11335. /// <summary>
  11336. /// 世运会数据
  11337. /// </summary>
  11338. /// <returns></returns>
  11339. [HttpGet]
  11340. public IActionResult WorldGamesData()
  11341. {
  11342. var setData = _sqlSugar.Queryable<Grp_GamesBudgetMaster>().Where(x => x.IsDel == 0).ToList();
  11343. var groupMenu = setData.GroupBy(x => x.T0);
  11344. var resultArr = new List<DecreasePaymentsWorldGamesDataView>();
  11345. foreach (var item in groupMenu)
  11346. {
  11347. resultArr.Add(new DecreasePaymentsWorldGamesDataView
  11348. {
  11349. Data = new SetDataView
  11350. {
  11351. Name = item.Key
  11352. },
  11353. Child = item.Select(x => x.CalculationContent).ToList() ?? new List<string>()
  11354. });
  11355. }
  11356. return Ok(JsonView(true, "success", resultArr));
  11357. }
  11358. #endregion
  11359. #region 文件上传、删除
  11360. /// <summary>
  11361. /// region 文件上传 可以带参数
  11362. /// </summary>
  11363. /// <param name="file"></param>
  11364. /// <returns></returns>
  11365. [HttpPost]
  11366. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11367. public async Task<IActionResult> UploadProject(IFormFile file)
  11368. {
  11369. //var TypeName = Request.Headers["TypeName"].ToString();
  11370. //if (file == null) return Ok(JsonView(false, "文件不存在!"));
  11371. //var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  11372. ////文件名称
  11373. //string projectFileName = file.FileName;
  11374. ////上传的文件的路径
  11375. //string filePath = $"{fileDir}/{projectFileName}";
  11376. //if (TypeName == "A")//A代表团组增减款项
  11377. //{
  11378. // filePath = fileDir + $@"\团组增减款项相关文件";
  11379. // if (!Directory.Exists(filePath))
  11380. // {
  11381. // Directory.CreateDirectory(filePath);
  11382. // }
  11383. // //上传的文件的路径
  11384. // filePath += $@"\{projectFileName}";
  11385. //}
  11386. //else if (TypeName == "B")//B代表商邀相关文件
  11387. //{
  11388. // //上传的文件的路径
  11389. // filePath = fileDir + $@"\商邀相关文件\{projectFileName}";
  11390. // if (!Directory.Exists(filePath))
  11391. // {
  11392. // Directory.CreateDirectory(filePath);
  11393. // }
  11394. // //上传的文件的路径
  11395. // filePath = $@"\{projectFileName}";
  11396. //}
  11397. //try
  11398. //{
  11399. // using (FileStream fs = System.IO.File.Create(filePath))
  11400. // {
  11401. // file.CopyTo(fs);
  11402. // fs.Flush();
  11403. // }
  11404. //}
  11405. //catch (Exception ex)
  11406. //{
  11407. // return Ok(JsonView(false, $"文件上传失败! Error:{ex.Message}"));
  11408. //}
  11409. //return Ok(JsonView(true, "上传成功!", projectFileName));
  11410. try
  11411. {
  11412. var TypeName = Request.Headers["TypeName"].ToString();
  11413. if (file != null)
  11414. {
  11415. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  11416. //文件名称
  11417. string projectFileName = file.FileName;
  11418. //上传的文件的路径
  11419. string filePath = $"{fileDir}/{projectFileName}";
  11420. if (TypeName == "A")//A代表团组增减款项
  11421. {
  11422. if (!Directory.Exists(fileDir))
  11423. {
  11424. Directory.CreateDirectory(fileDir);
  11425. }
  11426. //上传的文件的路径
  11427. filePath = fileDir + $@"\团组增减款项相关文件\{projectFileName}";
  11428. }
  11429. else if (TypeName == "B")//B代表商邀相关文件
  11430. {
  11431. if (!Directory.Exists(fileDir))
  11432. {
  11433. Directory.CreateDirectory(fileDir);
  11434. }
  11435. //上传的文件的路径
  11436. filePath = fileDir + $@"\商邀相关文件\{projectFileName}";
  11437. }
  11438. using (FileStream fs = System.IO.File.Create(filePath))
  11439. {
  11440. file.CopyTo(fs);
  11441. fs.Flush();
  11442. }
  11443. return Ok(JsonView(true, "上传成功!", projectFileName));
  11444. }
  11445. else
  11446. {
  11447. return Ok(JsonView(false, "上传失败!"));
  11448. }
  11449. }
  11450. catch (Exception ex)
  11451. {
  11452. return Ok(JsonView(false, ex.Message));
  11453. }
  11454. }
  11455. /// <summary>
  11456. /// 删除指定文件
  11457. /// </summary>
  11458. /// <param name="dto"></param>
  11459. /// <returns></returns>
  11460. [HttpPost]
  11461. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11462. public async Task<IActionResult> DelFile(DelFileDto dto)
  11463. {
  11464. try
  11465. {
  11466. var TypeName = Request.Headers["TypeName"].ToString();
  11467. if (string.IsNullOrEmpty(TypeName)) return Ok(JsonView(false, "请选择选组对应模块!"));
  11468. string filePath = "";
  11469. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  11470. // 返回与指定虚拟路径相对应的物理路径即绝对路径
  11471. int id = 0;
  11472. if (TypeName == "A")
  11473. {
  11474. filePath = fileDir + "/团组增减款项相关文件/" + dto.fileName;
  11475. // 删除该文件
  11476. System.IO.File.Delete(filePath);
  11477. id = await _sqlSugar.Updateable<Grp_DecreasePayments>()
  11478. .Where(a => a.Id == dto.Id)
  11479. .SetColumns(a => new Grp_DecreasePayments { FilePath = "" })
  11480. .ExecuteCommandAsync();
  11481. }
  11482. else if (TypeName == "B")
  11483. {
  11484. filePath = fileDir + "/商邀相关文件/" + dto.fileName;
  11485. // 删除该文件
  11486. System.IO.File.Delete(filePath);
  11487. var info = await _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(x => x.Id == dto.Id && x.IsDel == 0).FirstAsync();
  11488. if (info != null)
  11489. {
  11490. string[] files = Array.Empty<string>();
  11491. if (!string.IsNullOrEmpty(info.Attachment))
  11492. {
  11493. try
  11494. {
  11495. files = JsonConvert.DeserializeObject<string[]>(info.Attachment);
  11496. }
  11497. catch (Exception)
  11498. {
  11499. files = new List<string>() { info.Attachment }.ToArray();
  11500. }
  11501. }
  11502. if (files.Length > 0)
  11503. {
  11504. var files1 = files.Where(x => !x.Equals(dto.fileName)).ToArray();
  11505. string filePath2 = string.Empty;
  11506. if (files1.Length > 0)
  11507. {
  11508. filePath2 = JsonConvert.SerializeObject(files1);
  11509. }
  11510. id = await _sqlSugar.Updateable<Grp_InvitationOfficialActivities>()
  11511. .Where(a => a.Id == dto.Id)
  11512. .SetColumns(a => new Grp_InvitationOfficialActivities { Attachment = filePath2 })
  11513. .ExecuteCommandAsync();
  11514. }
  11515. }
  11516. }
  11517. if (id != 0)
  11518. {
  11519. return Ok(JsonView(true, "成功!"));
  11520. }
  11521. else
  11522. {
  11523. return Ok(JsonView(false, "失败!"));
  11524. }
  11525. }
  11526. catch (Exception ex)
  11527. {
  11528. return Ok(JsonView(false, "程序错误!"));
  11529. throw;
  11530. }
  11531. }
  11532. /// <summary>
  11533. /// 文件上传多个文件 可以带参数
  11534. /// </summary>
  11535. /// <param name="files"></param>
  11536. /// <returns></returns>
  11537. [HttpPost]
  11538. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11539. public async Task<IActionResult> UploadProjects(IFormFile[] files)
  11540. {
  11541. try
  11542. {
  11543. var TypeName = Request.Headers["TypeName"].ToString();
  11544. if (string.IsNullOrEmpty(TypeName)) return Ok(JsonView(false, "请选择选组对应模块!"));
  11545. if (files.Length < 1) return Ok(JsonView(false, "请选择文件!"));
  11546. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  11547. var filePahts = new List<string>();
  11548. foreach (var file in files)
  11549. {
  11550. //文件名称
  11551. string projectFileName = file.FileName;
  11552. //上传的文件的路径
  11553. string filePath = $"{fileDir}/{projectFileName}";
  11554. if (TypeName == "A")//A代表团组增减款项
  11555. {
  11556. if (!Directory.Exists(fileDir))
  11557. {
  11558. Directory.CreateDirectory(fileDir);
  11559. }
  11560. //上传的文件的路径
  11561. filePath = fileDir + $@"\团组增减款项相关文件\{projectFileName}";
  11562. }
  11563. else if (TypeName == "B")//B代表商邀相关文件
  11564. {
  11565. if (!Directory.Exists(fileDir))
  11566. {
  11567. Directory.CreateDirectory(fileDir);
  11568. }
  11569. //上传的文件的路径
  11570. filePath = fileDir + $@"\商邀相关文件\{projectFileName}";
  11571. }
  11572. using (FileStream fs = System.IO.File.Create(filePath))
  11573. {
  11574. file.CopyTo(fs);
  11575. fs.Flush();
  11576. }
  11577. filePahts.Add(projectFileName);
  11578. }
  11579. return Ok(JsonView(true, "上传成功!", filePahts));
  11580. }
  11581. catch (Exception ex)
  11582. {
  11583. return Ok(JsonView(false, ex.Message));
  11584. }
  11585. }
  11586. #endregion
  11587. #region 商邀费用录入
  11588. /// <summary>
  11589. /// 根据团组Id查询商邀费用列表
  11590. /// </summary>
  11591. /// <param name="dto"></param>
  11592. /// <returns></returns>
  11593. [HttpPost]
  11594. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11595. public async Task<IActionResult> InvitationOfficialActivitiesList(InvitationOfficialActivitiesListDto dto)
  11596. {
  11597. Result groupData = await _InvitationOfficialActivitiesRep.InvitationOfficialActivitiesList(dto);
  11598. if (groupData.Code != 0)
  11599. {
  11600. return Ok(JsonView(false, groupData.Msg));
  11601. }
  11602. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  11603. }
  11604. /// <summary>
  11605. /// 商邀费用列表
  11606. /// 下载文件
  11607. /// </summary>
  11608. /// <param name="id"></param>
  11609. /// <returns></returns>
  11610. [HttpGet("{id}")]
  11611. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11612. public async Task<IActionResult> InvitationOfficialActivitiesListDownFile(int id)
  11613. {
  11614. if (id < 1) return Ok(JsonView(false, "请传入有效的Id!"));
  11615. var info = await _InvitationOfficialActivitiesRep.Query(x => x.Id == id).FirstAsync();
  11616. if (info == null) return Ok(JsonView(false, "数据不存在!"));
  11617. if (string.IsNullOrEmpty(info.Attachment)) return Ok(JsonView(false, "文件不存在!"));
  11618. var filePaths = new List<string>();
  11619. var filePathBase = @$"{AppSettingsHelper.Get("GrpFileBasePath")}/商邀相关文件/";
  11620. try
  11621. {
  11622. filePaths = JsonConvert.DeserializeObject<List<string>>(info.Attachment);
  11623. }
  11624. catch (Exception ex)
  11625. {
  11626. filePaths.Add(info.Attachment);
  11627. }
  11628. if (filePaths != null && filePaths.Count < 1) return Ok(JsonView(false, "文件不存在!"));
  11629. for (int i = 0; i < filePaths.Count; i++)
  11630. {
  11631. filePaths[i] = $"{filePathBase}{filePaths[i]}";
  11632. }
  11633. var zipFilePathGuid = $"{Guid.NewGuid()}.zip";
  11634. var zipFilePath = $"{AppSettingsHelper.Get("GrpFileBasePath")}/商邀相关文件/{zipFilePathGuid}";
  11635. using (var zipFileStream = new FileStream(zipFilePath, FileMode.Create))
  11636. {
  11637. using (var zipArchive = new ZipArchive(zipFileStream, ZipArchiveMode.Create))
  11638. {
  11639. foreach (string filePath in filePaths)
  11640. {
  11641. if (System.IO.File.Exists(filePath))
  11642. {
  11643. // 获取文件名
  11644. string fileName = Path.GetFileName(filePath);
  11645. // 将文件添加到ZIP归档中
  11646. zipArchive.CreateEntryFromFile(filePath, fileName);
  11647. }
  11648. }
  11649. }
  11650. }
  11651. return Ok(JsonView(new { url = @$"{AppSettingsHelper.Get("OfficeBaseUrl")}{AppSettingsHelper.Get("GrpFileFtpPath")}/商邀相关文件/{zipFilePathGuid}" }));
  11652. }
  11653. /// <summary>
  11654. /// 商邀费用 Info Page 基础数据源
  11655. /// </summary>
  11656. /// <returns></returns>
  11657. [HttpPost]
  11658. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11659. public async Task<IActionResult> InvitationOfficialActivityInitBasicData()
  11660. {
  11661. try
  11662. {
  11663. Result groupData = await _InvitationOfficialActivitiesRep.InitBasicData();
  11664. if (groupData.Code != 0)
  11665. {
  11666. return Ok(JsonView(false, groupData.Msg));
  11667. }
  11668. return Ok(JsonView(true, "操作成功", groupData.Data));
  11669. }
  11670. catch (Exception ex)
  11671. {
  11672. return Ok(JsonView(false, ex.Message));
  11673. throw;
  11674. }
  11675. }
  11676. /// <summary>
  11677. /// 根据商邀费用ID查询C表和商邀费用数据
  11678. /// </summary>
  11679. /// <param name="dto"></param>
  11680. /// <returns></returns>
  11681. [HttpPost]
  11682. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11683. public async Task<IActionResult> InvitationOfficialActivitiesById(InvitationOfficialActivitiesByIdDto dto)
  11684. {
  11685. try
  11686. {
  11687. Result groupData = await _InvitationOfficialActivitiesRep.InvitationOfficialActivitiesById(dto);
  11688. if (groupData.Code != 0)
  11689. {
  11690. return Ok(JsonView(false, groupData.Msg));
  11691. }
  11692. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  11693. }
  11694. catch (Exception ex)
  11695. {
  11696. return Ok(JsonView(false, ex.Message));
  11697. throw;
  11698. }
  11699. }
  11700. /// <summary>
  11701. /// 商邀费用录入操作(Status:1.新增,2.修改)
  11702. /// </summary>
  11703. /// <param name="dto"></param>
  11704. /// <returns></returns>
  11705. [HttpPost]
  11706. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11707. public async Task<IActionResult> OpInvitationOfficialActivities(OpInvitationOfficialActivitiesDto dto)
  11708. {
  11709. //验证
  11710. if (dto.Status == 2)
  11711. {
  11712. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 81);
  11713. if (!valid) return Ok(JsonView(false, msg));
  11714. }
  11715. Result groupData = await _InvitationOfficialActivitiesRep.OpInvitationOfficialActivities(dto, _setDataRep.PostCurrencyByDiid);
  11716. if (groupData.Code != 0)
  11717. {
  11718. return Ok(JsonView(false, groupData.Msg));
  11719. }
  11720. #region 应用推送
  11721. try
  11722. {
  11723. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  11724. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  11725. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  11726. //2024-10-21 新增LZ UID
  11727. var userIds = new List<int>() { 21 };
  11728. string title = $"系统通知";
  11729. string content = "";
  11730. var diId = dto.DiId;
  11731. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  11732. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  11733. if (dto.Status == 1) content = $"[新增-商邀费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  11734. else if (dto.Status == 2) content = $"[更新-商邀费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  11735. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  11736. var h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "81" };
  11737. await APNsTools.iOS_PushNotifications1("051", $"商邀费用审核", "", content, true, "ExpenseAuditWebView", h5);
  11738. }
  11739. catch (Exception ex)
  11740. {
  11741. }
  11742. #endregion
  11743. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  11744. }
  11745. /// <summary>
  11746. /// 商邀删除
  11747. /// </summary>
  11748. /// <param name="dto"></param>
  11749. /// <returns></returns>
  11750. [HttpPost]
  11751. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11752. public async Task<IActionResult> DelInvitationOfficialActivities(DelBaseDto dto)
  11753. {
  11754. try
  11755. {
  11756. //验证
  11757. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 81);
  11758. if (!valid) return Ok(JsonView(false, msg));
  11759. _sqlSugar.BeginTran();
  11760. var res1 = _sqlSugar.Updateable<Grp_InvitationOfficialActivities>()
  11761. .SetColumns(it => new Grp_InvitationOfficialActivities()
  11762. {
  11763. IsDel = 1,
  11764. DeleteUserId = dto.DeleteUserId,
  11765. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  11766. })
  11767. .Where(it => it.Id == dto.Id)
  11768. .ExecuteCommand();
  11769. if (res1 > 0)
  11770. {
  11771. int _diId = 0;
  11772. var _ioaInfo = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(it => it.Id == dto.Id).First();
  11773. if (_ioaInfo != null)
  11774. {
  11775. _diId = _ioaInfo.DiId;
  11776. }
  11777. var res2 = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  11778. .SetColumns(a => new Grp_CreditCardPayment()
  11779. {
  11780. IsDel = 1,
  11781. DeleteUserId = dto.DeleteUserId,
  11782. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  11783. })
  11784. .Where(a => a.CId == dto.Id && a.DIId == _diId && a.CTable == 81)
  11785. .ExecuteCommand();
  11786. if (res2 > 0)
  11787. {
  11788. _sqlSugar.CommitTran();
  11789. return Ok(JsonView(true, "删除成功!"));
  11790. }
  11791. }
  11792. _sqlSugar.RollbackTran();
  11793. return Ok(JsonView(false, "删除失败"));
  11794. }
  11795. catch (Exception ex)
  11796. {
  11797. _sqlSugar.RollbackTran();
  11798. return Ok(JsonView(false, ex.Message));
  11799. }
  11800. }
  11801. #endregion
  11802. #region 商邀Ai
  11803. /// <summary>
  11804. /// 请示文件生成
  11805. /// </summary>
  11806. /// <param name="dto"></param>
  11807. /// <returns></returns>
  11808. [HttpPost]
  11809. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11810. public async Task<IActionResult> BusinessInvitationInstructionsFile(BusinessInvitationInstructionsFileDto dto)
  11811. {
  11812. var jw = JsonView(false);
  11813. if (dto.Diid < 1)
  11814. {
  11815. jw.Msg = "团组Id不能为空!";
  11816. return Ok(jw);
  11817. }
  11818. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.IsDel == 0 && x.Id == dto.Diid);
  11819. if (groupInfo == null)
  11820. {
  11821. jw.Msg = "团组信息不存在!";
  11822. return Ok(jw);
  11823. }
  11824. var clients = await _sqlSugar.Queryable<Grp_TourClientList>()
  11825. .Where(x => x.IsDel == 0 && x.DiId == dto.Diid)
  11826. .ToListAsync();
  11827. if (!clients.Any())
  11828. {
  11829. jw.Msg = "团组客户信息不存在!";
  11830. return Ok(jw);
  11831. }
  11832. var TravelList = await _sqlSugar.Queryable<Grp_ApprovalTravel>()
  11833. .Where(x => x.IsDel == 0 && x.Diid == dto.Diid).ToListAsync();
  11834. if (!TravelList.Any())
  11835. {
  11836. jw.Msg = "团组行程信息不存在!";
  11837. return Ok(jw);
  11838. }
  11839. string chat = string.Empty;
  11840. var templateSetting = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == 1550 && x.IsDel == 0);
  11841. if (templateSetting != null && !string.IsNullOrEmpty(templateSetting.Remark))
  11842. {
  11843. var stringFormatResp = await GeneralMethod.StringFormatAsync(new StringFormatDto
  11844. {
  11845. FormatTemplate = templateSetting.Remark,
  11846. Parameters = new List<string> {
  11847. JsonConvert.SerializeObject(clients),
  11848. JsonConvert.SerializeObject(TravelList)
  11849. }
  11850. });
  11851. if (stringFormatResp.Success)
  11852. {
  11853. chat = stringFormatResp.FormattedResult;
  11854. }
  11855. else
  11856. {
  11857. jw.Msg = "对话内容模板格式化失败! templateSetting.Id: " + templateSetting.Id + ",错误:" + stringFormatResp.Message;
  11858. return Ok(jw);
  11859. }
  11860. }
  11861. else
  11862. {
  11863. jw.Msg = "获取对话内容模板失败! templateSetting.Id: " + templateSetting.Id;
  11864. return Ok(jw);
  11865. }
  11866. var chatResult = await _doubaoService.CompleteChatAsync(new List<DouBaoChatMessage> { new DouBaoChatMessage { Role = DouBaoRole.user, Content = chat } });
  11867. if (string.IsNullOrEmpty(chatResult))
  11868. {
  11869. jw.Msg = "请示文件生成失败!";
  11870. return Ok(jw);
  11871. }
  11872. return Ok(JsonView(true, "请示文件生成成功!", chatResult));
  11873. }
  11874. /// <summary>
  11875. /// 企业拜访内容续写
  11876. /// </summary>
  11877. /// <param name="dto"></param>
  11878. /// <returns></returns>
  11879. [HttpPost]
  11880. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11881. public async Task<IActionResult> BusinessEnterpriseContinueWrite(BusinessEnterpriseContinueWriteDto dto)
  11882. {
  11883. var jw = JsonView(false);
  11884. if (string.IsNullOrEmpty(dto.DepartEnterpriseName))
  11885. {
  11886. jw.Msg = "出访企业名称不能为空!";
  11887. return Ok(jw);
  11888. }
  11889. if (dto.EnterpriseNames == null || dto.EnterpriseNames.Count == 0)
  11890. {
  11891. jw.Msg = "企业名称列表不能为空!";
  11892. return Ok(jw);
  11893. }
  11894. ArrayList result = new ArrayList();
  11895. foreach (var enterpriseName in dto.EnterpriseNames)
  11896. {
  11897. var kimiResult = await this.ApprovalJourneyAiWrite(new ApprovalJourneyAiWriteDto { ClientName = dto.DepartEnterpriseName, ClientPurpose = enterpriseName });
  11898. result.Add(new
  11899. {
  11900. EnterpriseName = enterpriseName,
  11901. Content = kimiResult
  11902. });
  11903. }
  11904. return Ok(JsonView(true, "企业拜访内容续写成功!", result));
  11905. }
  11906. /// <summary>
  11907. /// 行程单位安排
  11908. /// </summary>
  11909. /// <param name="dto"></param>
  11910. /// <returns></returns>
  11911. [HttpPost]
  11912. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11913. public async Task<IActionResult> BusinessSynchronizationWrite(BusinessSynchronizationWriteDto dto)
  11914. {
  11915. var jw = JsonView(false);
  11916. var travelList = await _sqlSugar.Queryable<Grp_ApprovalTravel>()
  11917. .LeftJoin<Grp_ApprovalTravelDetails>((x, a) => x.Id == a.ParentId && a.IsDel == 0)
  11918. .Where((x, a) => x.IsDel == 0 && x.Diid == dto.Diid)
  11919. .Select((x, a) => new
  11920. {
  11921. 日期 = x.Date,
  11922. 具体时间 = a.Time,
  11923. 行程安排 = a.Details,
  11924. 数据id = a.Id,
  11925. })
  11926. .ToListAsync();
  11927. if (!travelList.Any())
  11928. {
  11929. jw.Msg = "团组行程信息不存在!";
  11930. return Ok(jw);
  11931. }
  11932. if (dto.EnterpriseNames == null || dto.EnterpriseNames.Count == 0)
  11933. {
  11934. jw.Msg = "企业名称列表不能为空!";
  11935. return Ok(jw);
  11936. }
  11937. string chat = string.Empty;
  11938. var templateSetting = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == 1552 && x.IsDel == 0);
  11939. if (templateSetting != null && !string.IsNullOrEmpty(templateSetting.Remark))
  11940. {
  11941. var stringFormatResp = await GeneralMethod.StringFormatAsync(new StringFormatDto
  11942. {
  11943. FormatTemplate = templateSetting.Remark,
  11944. Parameters = new List<string> {
  11945. JsonConvert.SerializeObject(dto.EnterpriseNames),
  11946. JsonConvert.SerializeObject(travelList)
  11947. }
  11948. });
  11949. if (stringFormatResp.Success)
  11950. {
  11951. chat = stringFormatResp.FormattedResult;
  11952. }
  11953. else
  11954. {
  11955. jw.Msg = "对话内容模板格式化失败! templateSetting.Id: " + templateSetting.Id + ",错误:" + stringFormatResp.Message;
  11956. return Ok(jw);
  11957. }
  11958. }
  11959. else
  11960. {
  11961. jw.Msg = "获取对话内容模板失败! templateSetting.Id: " + templateSetting.Id;
  11962. return Ok(jw);
  11963. }
  11964. var chatResult = await _doubaoService.CompleteChatAsync(new List<DouBaoChatMessage> { new DouBaoChatMessage { Role = DouBaoRole.user, Content = chat } });
  11965. if (string.IsNullOrEmpty(chatResult))
  11966. {
  11967. jw.Msg = "报批日程安排失败!";
  11968. return Ok(jw);
  11969. }
  11970. var jsonResult = JsonConvert.DeserializeObject<List<Grp_ApprovalTravelDetails>>(chatResult);
  11971. if (!jsonResult.Any())
  11972. {
  11973. jw.Msg = "AI报批日程安排失败!";
  11974. return Ok(jw);
  11975. }
  11976. _sqlSugar.Updateable<Grp_ApprovalTravelDetails>(jsonResult)
  11977. .UpdateColumns(x => new { x.Details })
  11978. .ExecuteCommand();
  11979. return Ok(JsonView(true, "报批日程安排成功!", chatResult));
  11980. }
  11981. /// <summary>
  11982. /// 商邀Ai行程框架导出
  11983. /// </summary>
  11984. /// <param name="dto"></param>
  11985. /// <returns></returns>
  11986. [HttpPost]
  11987. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11988. public async Task<IActionResult> BusinessJourneyFileDown(BusinessJourneyFileDownDto dto)
  11989. {
  11990. var jw = JsonView(false);
  11991. var travelList = await _sqlSugar.Queryable<Grp_ApprovalTravel>()
  11992. .LeftJoin<Grp_ApprovalTravelDetails>((x, a) => x.Id == a.ParentId && a.IsDel == 0)
  11993. .Where((x, a) => x.IsDel == 0 && x.Diid == dto.Diid)
  11994. .Select((x, a) => new
  11995. {
  11996. 日期 = x.Date,
  11997. 具体时间 = a.Time,
  11998. 行程安排 = a.Details,
  11999. 数据id = a.Id,
  12000. })
  12001. .ToListAsync();
  12002. if (!travelList.Any())
  12003. {
  12004. jw.Msg = "团组行程信息不存在!";
  12005. return Ok(jw);
  12006. }
  12007. var groupTraveList = travelList
  12008. .Where(x => !string.IsNullOrWhiteSpace(x.行程安排))
  12009. .GroupBy(x => x.日期).ToList();
  12010. var grouopTraveListByStr = groupTraveList.ToDictionary(
  12011. x => x.Key,
  12012. x => string.Join("\r\n", x.Select(y => $"{y.具体时间} {y.行程安排}".Trim()))
  12013. );
  12014. return Ok(JsonView(true, "团组行程信息导出成功!", grouopTraveListByStr));
  12015. }
  12016. #endregion
  12017. #region 票据上传
  12018. /// <summary>
  12019. /// 团组模块文件上传
  12020. /// </summary>
  12021. /// <param name="dto"></param>
  12022. /// <returns></returns>
  12023. [HttpPost]
  12024. public IActionResult CommonSaveFile([FromForm] CommonSaveFileDto dto)
  12025. {
  12026. var jw = JsonView(false);
  12027. long M = 1024 * 1024;
  12028. if (dto.Files == null || dto.Files.Count == 0)
  12029. {
  12030. jw.Msg = "无文件信息!";
  12031. return Ok(jw);
  12032. }
  12033. if (dto.Files.Sum(x => x.Length) > 20 * M)
  12034. {
  12035. jw.Msg = "文件大小超过20M!";
  12036. return Ok(jw);
  12037. }
  12038. //var nameSp = dto.File.FileName.Split(".");
  12039. //if (nameSp.Length < 2)
  12040. //{
  12041. // jw.Msg = "拓展名称有误!";
  12042. // return Ok(jw);
  12043. //}
  12044. //var existsName = new string[]{ "RAR", "ZIP", "ARJ","GZ","Z","7Z","TAR" };
  12045. //if (!existsName.Contains(nameSp[1].ToUpper()))
  12046. //{
  12047. // jw.Msg = $"请使用指定拓展名!({string.Join("-",existsName)})";
  12048. // return Ok(jw);
  12049. //}
  12050. var Ctable = _sqlSugar.Queryable<Sys_SetData>().First(x => x.STid == 16 && x.IsDel == 0 && x.Id == dto.Ctable);
  12051. if (Ctable == null)
  12052. {
  12053. jw.Msg = "Ctable指向有误!";
  12054. return Ok(jw);
  12055. }
  12056. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  12057. if (groupInfo == null)
  12058. {
  12059. jw.Msg = "团组信息不存在!";
  12060. return Ok(jw);
  12061. }
  12062. Ctable.Name = Regex.Replace(Ctable.Name, @"[^\w\.@-]", "",
  12063. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  12064. groupInfo.TeamName = Regex.Replace(groupInfo.TeamName, @"[^\w\.@-]", "",
  12065. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  12066. var path = "\\GroupModelFiles\\" + groupInfo.TeamName + "\\" + Ctable.Name;
  12067. var fileBase = AppSettingsHelper.Get("GrpFileBasePath") + path;
  12068. try
  12069. {
  12070. if (!Directory.Exists(fileBase))
  12071. {
  12072. Directory.CreateDirectory(fileBase);
  12073. }
  12074. var saveArr = new List<Grp_GroupModelFile>();
  12075. foreach (var fileStream in dto.Files)
  12076. {
  12077. var fileName = fileStream.FileName;
  12078. string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
  12079. string extension = Path.GetExtension(fileName);
  12080. int counter = 0;
  12081. //文件重命名验证
  12082. string newFilePath;
  12083. string currFileName;
  12084. do
  12085. {
  12086. string newFileName;
  12087. if (counter == 0) newFileName = $"{fileNameWithoutExtension}{extension}";
  12088. else newFileName = $"{fileNameWithoutExtension} ({counter}){extension}";
  12089. currFileName = newFileName;
  12090. newFilePath = Path.Combine(fileBase, newFileName);
  12091. counter++;
  12092. } while (System.IO.File.Exists(newFilePath));
  12093. var saveFilePath = fileBase + "\\" + currFileName;
  12094. var file = new Grp_GroupModelFile()
  12095. {
  12096. Cid = dto.Cid,
  12097. CreateTime = DateTime.Now,
  12098. CreateUserId = dto.Userid,
  12099. Ctable = dto.Ctable,
  12100. Diid = dto.Diid,
  12101. IsDel = 0,
  12102. FilePath = saveFilePath,
  12103. FileName = currFileName
  12104. };
  12105. using (FileStream fs = System.IO.File.Create(saveFilePath))
  12106. {
  12107. fileStream.CopyTo(fs);
  12108. fs.Flush();
  12109. }
  12110. saveArr.Add(file);
  12111. }
  12112. var addResult = _sqlSugar.Insertable<Grp_GroupModelFile>(saveArr).ExecuteCommand();
  12113. //url = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("GrpFileFtpPath") + path + "\\" + dto.File.FileName
  12114. jw = JsonView(true, "保存成功!", new
  12115. {
  12116. count = addResult,
  12117. filesName = saveArr.Select(x => x.FileName)
  12118. });
  12119. }
  12120. catch (Exception ex)
  12121. {
  12122. jw = JsonView(false, $"保存失败! ({ex.Message}) ", new
  12123. {
  12124. count = 0,
  12125. filesName = Array.Empty<string>(),
  12126. });
  12127. }
  12128. return Ok(jw);
  12129. }
  12130. /// <summary>
  12131. /// 查询各模块已保存文件
  12132. /// </summary>
  12133. /// <param name="dto"></param>
  12134. /// <returns></returns>
  12135. [HttpPost]
  12136. public IActionResult QueryGroupModelFile(QueryGroupModelFileDto dto)
  12137. {
  12138. var expression = Expressionable.Create<Grp_GroupModelFile>()
  12139. .AndIF(dto.UserId != -1, x => x.CreateUserId == dto.UserId);
  12140. var visaIds = _sqlSugar.Queryable<Sys_Users>().Where(x => x.JobPostId == 26).Select(x => x.Id).ToList();
  12141. if (visaIds.Contains(dto.UserId) && dto.Ctable == 80)
  12142. {
  12143. expression = Expressionable.Create<Grp_GroupModelFile>()
  12144. .And(x => visaIds.Contains(x.CreateUserId));
  12145. }
  12146. var dbQuery = _sqlSugar.Queryable<Grp_GroupModelFile>()
  12147. .Where(x => x.IsDel == 0 && x.Cid == dto.Cid && x.Ctable == dto.Ctable && x.Diid == dto.Diid)
  12148. .Where(expression.ToExpression())
  12149. .ToList();
  12150. //.ToPageList(pagenumber, pageSize, ref totalCount, ref totalPage)
  12151. return Ok(JsonView(true, "success", dbQuery.Select(x => new
  12152. {
  12153. x.FileName,
  12154. x.Id,
  12155. Url = AppSettingsHelper.Get("GrpFileBaseUrl") + x.FilePath.Replace(AppSettingsHelper.Get("GrpFileBasePath"), AppSettingsHelper.Get("GrpFileFtpPath")),
  12156. CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH-mm"),
  12157. })));
  12158. }
  12159. /// <summary>
  12160. /// 下载该团组下的所有文件
  12161. /// </summary>
  12162. /// <param name="dto"></param>
  12163. /// <returns></returns>
  12164. [HttpPost]
  12165. public IActionResult ExportGroupZip(ExportGroupZipDto dto)
  12166. {
  12167. var jw = JsonView(false);
  12168. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.IsDel == 0 && x.Id == dto.Diid);
  12169. if (groupInfo == null)
  12170. {
  12171. jw.Msg = "团组信息不存在!";
  12172. return Ok(jw);
  12173. }
  12174. var dbQuery = _sqlSugar.Queryable<Grp_GroupModelFile>().Where(x => x.IsDel == 0 && x.Diid == dto.Diid).ToList();
  12175. var isModule = Convert.ToBoolean(dto.isModule);
  12176. var Zips = new Dictionary<string, Stream>();
  12177. var io = new IOOperatorHelper();
  12178. if (isModule)
  12179. {
  12180. var moduleGroup = dbQuery.GroupBy(x => x.Ctable);
  12181. foreach (var moduleArr in moduleGroup)
  12182. {
  12183. var key = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == moduleArr.Key && x.IsDel == 0);
  12184. key.Name = Regex.Replace(key.Name, @"[^\w\.@-]", "",
  12185. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  12186. var chiZips = new Dictionary<string, Stream>();
  12187. foreach (var item in moduleArr)
  12188. {
  12189. if (System.IO.File.Exists(item.FilePath))
  12190. {
  12191. using (var fileStream = new FileStream(item.FilePath, FileMode.Open, FileAccess.Read))
  12192. {
  12193. byte[] bytes = new byte[fileStream.Length];
  12194. fileStream.Read(bytes, 0, bytes.Length);
  12195. fileStream.Close();
  12196. Stream stream = new MemoryStream(bytes);
  12197. chiZips.Add(item.FileName, stream);
  12198. }
  12199. }
  12200. }
  12201. if (chiZips.Count > 0)
  12202. {
  12203. var byts = io.ConvertZipStream(chiZips);
  12204. Stream stream = new MemoryStream(byts);
  12205. Zips.Add(key.Name + "_.zip", stream);
  12206. }
  12207. }
  12208. }
  12209. else
  12210. {
  12211. foreach (var item in dbQuery)
  12212. {
  12213. using (var fileStream = new FileStream(item.FilePath, FileMode.Open, FileAccess.Read))
  12214. {
  12215. byte[] bytes = new byte[fileStream.Length];
  12216. fileStream.Read(bytes, 0, bytes.Length);
  12217. fileStream.Close();
  12218. var stream = new MemoryStream(bytes);
  12219. while (Zips.ContainsKey(item.FileName))
  12220. {
  12221. item.FileName = new Random().Next(100) + "_" + item.FileName;
  12222. }
  12223. Zips.Add(item.FileName, stream);
  12224. }
  12225. }
  12226. }
  12227. groupInfo.TeamName = Regex.Replace(groupInfo.TeamName, @"[^\w\.@-]", "",
  12228. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  12229. if (Zips.Count > 0)
  12230. {
  12231. var byts = io.ConvertZipStream(Zips);
  12232. var path = "\\GroupModelFiles\\" + groupInfo.TeamName;
  12233. io.ByteToFile(byts, AppSettingsHelper.Get("GrpFileBasePath") + $"{path}\\{groupInfo.TeamName}_.Zip");
  12234. jw = JsonView(true, "success", new { url = AppSettingsHelper.Get("GrpFileBaseUrl") + $"{AppSettingsHelper.Get("GrpFileFtpPath")}{path}\\{groupInfo.TeamName}_.zip" });
  12235. }
  12236. else
  12237. {
  12238. jw.Msg = "暂无生成文件!";
  12239. }
  12240. return Ok(jw);
  12241. }
  12242. /// <summary>
  12243. /// 下载该团组下此模块的所有文件
  12244. /// </summary>
  12245. /// <param name="dto"></param>
  12246. /// <returns></returns>
  12247. [HttpPost]
  12248. public IActionResult ExportGroupByModule(ExportGroupByModuleDto dto)
  12249. {
  12250. var jw = JsonView(false);
  12251. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.IsDel == 0 && x.Id == dto.Diid);
  12252. if (groupInfo == null)
  12253. {
  12254. jw.Msg = "团组信息不存在!";
  12255. return Ok(jw);
  12256. }
  12257. var dbQuery = _sqlSugar.Queryable<Grp_GroupModelFile>().Where(x => x.IsDel == 0 && x.Diid == dto.Diid && x.Ctable == dto.Ctable).ToList();
  12258. var key = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == dto.Ctable
  12259. && x.IsDel == 0);
  12260. if (key == null)
  12261. {
  12262. jw.Msg = "Ctable指向错误!";
  12263. return Ok(jw);
  12264. }
  12265. key.Name = Regex.Replace(key.Name, @"[^\w\.@-]", "",
  12266. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  12267. groupInfo.TeamName = Regex.Replace(groupInfo.TeamName, @"[^\w\.@-]", "",
  12268. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  12269. var io = new IOOperatorHelper();
  12270. var Zips = new Dictionary<string, Stream>();
  12271. foreach (var item in dbQuery)
  12272. {
  12273. if (System.IO.File.Exists(item.FilePath))
  12274. {
  12275. using (var fileStream = new FileStream(item.FilePath, FileMode.Open, FileAccess.Read))
  12276. {
  12277. byte[] bytes = new byte[fileStream.Length];
  12278. fileStream.Read(bytes, 0, bytes.Length);
  12279. fileStream.Close();
  12280. var stream = new MemoryStream(bytes);
  12281. while (Zips.ContainsKey(item.FileName))
  12282. {
  12283. item.FileName = new Random().Next(100) + "_" + item.FileName;
  12284. }
  12285. Zips.Add(item.FileName, stream);
  12286. }
  12287. }
  12288. }
  12289. if (Zips.Count > 0)
  12290. {
  12291. var byts = io.ConvertZipStream(Zips);
  12292. var path = "\\GroupModelFiles\\" + groupInfo.TeamName;
  12293. io.ByteToFile(byts, AppSettingsHelper.Get("GrpFileBasePath") + $"{path}\\{groupInfo.TeamName}_{key.Name}_.Zip");
  12294. jw = JsonView(true, "success", new { url = AppSettingsHelper.Get("GrpFileBaseUrl") + $"{AppSettingsHelper.Get("GrpFileFtpPath")}{path}\\{groupInfo.TeamName}_{key.Name}_.Zip" });
  12295. }
  12296. else
  12297. {
  12298. jw.Msg = "暂无生成文件!";
  12299. }
  12300. return Ok(jw);
  12301. }
  12302. /// <summary>
  12303. /// 删除该团组下的指定文件
  12304. /// </summary>
  12305. /// <param name="dto"></param>
  12306. /// <returns></returns>
  12307. [HttpPost]
  12308. public IActionResult DeleteGroupFile(DeleteGroupFileDto dto)
  12309. {
  12310. var jw = JsonView(false);
  12311. var sing = _sqlSugar.Queryable<Grp_GroupModelFile>().First(x => x.Id == dto.Id && x.IsDel == 0);
  12312. if (sing == null)
  12313. {
  12314. jw.Msg = "暂无";
  12315. return Ok(jw);
  12316. }
  12317. if (System.IO.File.Exists(sing.FilePath))
  12318. {
  12319. try
  12320. {
  12321. System.IO.File.Delete(sing.FilePath);
  12322. }
  12323. catch (Exception ex)
  12324. {
  12325. jw.Msg = "删除失败!" + ex.Message;
  12326. return Ok(jw);
  12327. }
  12328. }
  12329. sing.IsDel = 1;
  12330. sing.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  12331. sing.DeleteUserId = dto.UserId;
  12332. _sqlSugar.Updateable<Grp_GroupModelFile>(sing).ExecuteCommand();
  12333. jw = JsonView(true, "删除成功!");
  12334. return Ok(jw);
  12335. }
  12336. #endregion
  12337. #region 共享文件上传
  12338. /// <summary>
  12339. /// 超支通知推送
  12340. /// </summary>
  12341. /// <param name="dto"></param>
  12342. /// <returns></returns>
  12343. [HttpPost]
  12344. public async Task<IActionResult> qyWeChatNotification(qyWeChatNotificationDto dto)
  12345. {
  12346. //81 邀请/公务活动
  12347. var syCTable = new List<int> { 81 };
  12348. //76 酒店预订
  12349. //79 车/导游地接
  12350. //85 机票预订
  12351. var gjCTable = new List<int> { 76, 79, 85 };
  12352. var jw = JsonView(false);
  12353. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.IsDel == 0 && x.Id == dto.Diid);
  12354. if (di == null)
  12355. {
  12356. jw.Msg = "团组信息不存在!";
  12357. return Ok(jw);
  12358. }
  12359. var user = _sqlSugar.Queryable<Sys_Users>().First(x => x.IsDel == 0 && x.Id == dto.UserId);
  12360. if (user == null)
  12361. {
  12362. jw.Msg = "用户信息不存在!";
  12363. return Ok(jw);
  12364. }
  12365. if (syCTable.Contains(dto.CTable))
  12366. {
  12367. await AppNoticeLibrary.SendChatMsg_ExpenseOverrunsChat(dto.Diid, dto.UserId, dto.CTable, QiyeWeChatEnum.ExpenseOverrunsChat02);
  12368. }
  12369. else if (gjCTable.Contains(dto.CTable))
  12370. {
  12371. await AppNoticeLibrary.SendChatMsg_ExpenseOverrunsChat(dto.Diid, dto.UserId, dto.CTable, QiyeWeChatEnum.ExpenseOverrunsChat01);
  12372. }
  12373. else
  12374. {
  12375. jw.Msg = "CTABLE类型有误!";
  12376. }
  12377. jw = JsonView(true, "推送成功!", "");
  12378. return Ok(jw);
  12379. }
  12380. /// <summary>
  12381. /// 共享文件数据初始化
  12382. /// </summary>
  12383. /// <returns></returns>
  12384. [HttpGet]
  12385. public async Task<IActionResult> SharedFileInit(int userid, int portType)
  12386. {
  12387. var marketingDepartmentIds = new List<int> { 6, 26, 27, 28 };
  12388. var isMarketingDepartment = _sqlSugar.Queryable<Sys_Users>()
  12389. .Where(x => x.IsDel == 0 && marketingDepartmentIds.Contains(x.DepId))
  12390. .Select(x => x.Id)
  12391. .ToList()
  12392. .Contains(userid);
  12393. var dropDownType = _sqlSugar.Queryable<Sys_SetData>()
  12394. .Where(x => x.STid == 111 && x.IsDel == 0)
  12395. .Select(x => new
  12396. {
  12397. x.Name,
  12398. x.Id,
  12399. }).ToList();
  12400. if (isMarketingDepartment)
  12401. {
  12402. dropDownType = dropDownType.Where(x => x.Id == 1412).ToList();
  12403. }
  12404. if (portType == 1)
  12405. {
  12406. var provCityDatas = await _groupRepository.ProvinceCityBasicSource();
  12407. var dropDownGroupList = _sqlSugar.Queryable<Grp_DelegationInfo>()
  12408. .Where(x => x.IsDel == 0)
  12409. .OrderByDescending(x => x.VisitDate)
  12410. .Select(x => new
  12411. {
  12412. x.TeamName,
  12413. x.Id,
  12414. x.CityId,
  12415. })
  12416. .ToList()
  12417. .Select(x =>
  12418. {
  12419. var provinceId = x.CityId;
  12420. var isDefualtVal = true;
  12421. if (provinceId > 0)
  12422. {
  12423. var parentId = _groupRepository.FindParentIdByChildId(provCityDatas, provinceId);
  12424. if (parentId != null)
  12425. {
  12426. isDefualtVal = false;
  12427. provinceId = (int)parentId;
  12428. }
  12429. }
  12430. if (isDefualtVal)
  12431. {
  12432. provinceId = 122; //默认四川
  12433. }
  12434. return new
  12435. {
  12436. x.TeamName,
  12437. x.Id,
  12438. provinceId,
  12439. };
  12440. })
  12441. .ToList();
  12442. return Ok(JsonView(true, "SUCCESS!", new
  12443. {
  12444. dropDownType,
  12445. dropDownGroupList,
  12446. isMarketingDepartment
  12447. }));
  12448. }
  12449. else if (portType == 2 || portType == 3)
  12450. {
  12451. return Ok(JsonView(true, "SUCCESS!", new
  12452. {
  12453. dropDownType,
  12454. isMarketingDepartment
  12455. }));
  12456. }
  12457. else
  12458. {
  12459. return Ok(JsonView(false, "portType有误!"));
  12460. }
  12461. }
  12462. /// <summary>
  12463. /// 共享文件上传
  12464. /// </summary>
  12465. /// <param name="dto"></param>
  12466. /// <returns></returns>
  12467. [HttpPost]
  12468. public IActionResult SharedFileUpload([FromForm] SharedFileUploadDto dto)
  12469. {
  12470. var isGroup = new List<int> { 1412 };
  12471. if (isGroup.Contains(dto.FileType) && dto.Diid < 1)
  12472. {
  12473. return Ok(JsonView(false, "该文件需要关联团组!"));
  12474. }
  12475. if (dto.Files == null || dto.Files.Count == 0)
  12476. {
  12477. return Ok(JsonView(false, "无文件信息!"));
  12478. }
  12479. if (dto.Files.Sum(x => x.Length) > 20 * 1024 * 1024)
  12480. {
  12481. return Ok(JsonView(false, "文件大小超过20M!"));
  12482. }
  12483. if (dto.Userid < 1)
  12484. {
  12485. return Ok(JsonView(false, "请传入有效的Userid!"));
  12486. }
  12487. var jobInfo = _sqlSugar.Queryable<Sys_Users, Sys_JobPost>((u, j) => u.JobPostId == j.Id && j.IsDel == 0)
  12488. .Where(u => u.IsDel == 0 && u.Id == dto.Userid)
  12489. .Select((u, j) => new
  12490. {
  12491. u.CnName,
  12492. UserId = u.Id,
  12493. j.JobName,
  12494. })
  12495. .First();
  12496. if (jobInfo == null)
  12497. {
  12498. return Ok(JsonView(false, "请传入有效的Userid!"));
  12499. }
  12500. var commonFileExtensions = new List<string>
  12501. {
  12502. // 文本文件
  12503. ".txt", ".doc", ".docx", ".odt", ".pdf", ".rtf", ".md", ".log",
  12504. // 图片文件
  12505. ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".svg",
  12506. // 视频文件
  12507. ".mp4", ".avi", ".mov", ".mkv", ".wmv", ".flv", ".mpg", ".mpeg",
  12508. // 音频文件
  12509. ".mp3", ".wav", ".ogg", ".aac", ".flac",
  12510. // 压缩文件
  12511. ".zip", ".rar", ".7z", ".tar", ".gz", ".bz2",
  12512. // 数据文件
  12513. ".csv", ".xls", ".xlsx", ".json", ".xml", ".yaml", ".ini",
  12514. };
  12515. try
  12516. {
  12517. var setting = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == 1416);
  12518. var settingExtend = JsonConvert.DeserializeObject<List<string>>(setting.Remark);
  12519. commonFileExtensions.AddRange(settingExtend);
  12520. }
  12521. catch (Exception)
  12522. { }
  12523. var setdata = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == dto.FileType);
  12524. if (setdata == null)
  12525. {
  12526. return Ok(JsonView(false, "请传入有效的FileType!"));
  12527. }
  12528. var insertList = new List<Grp_GroupShareFile>();
  12529. string winPath = AppSettingsHelper.Get("ShareFileBasePath") + $"{setdata.Name}/";
  12530. if (!Directory.Exists(winPath))
  12531. {
  12532. Directory.CreateDirectory(winPath);
  12533. }
  12534. foreach (var item in dto.Files)
  12535. {
  12536. var houzui = Path.GetExtension(item.FileName);
  12537. if (!commonFileExtensions.Contains(houzui))
  12538. {
  12539. return Ok(JsonView(false, "未知后缀名称!"));
  12540. }
  12541. var fileName = $"{jobInfo.JobName}-{jobInfo.CnName}-{item.FileName}";
  12542. var saveFilePath = winPath + fileName;
  12543. using (FileStream fs = System.IO.File.Create(saveFilePath))
  12544. {
  12545. item.CopyTo(fs);
  12546. fs.Flush();
  12547. }
  12548. var fileDetail = new Grp_GroupShareFile()
  12549. {
  12550. CreateUserId = dto.Userid,
  12551. CreateTime = DateTime.Now,
  12552. UploadJob = jobInfo.JobName,
  12553. FileName = fileName,
  12554. FileType = dto.FileType,
  12555. Diid = dto.Diid,
  12556. FilePath = winPath + fileName,
  12557. };
  12558. insertList.Add(fileDetail);
  12559. }
  12560. _sqlSugar.Insertable<Grp_GroupShareFile>(insertList).ExecuteCommand();
  12561. return Ok(JsonView(true, "保存成功!"));
  12562. }
  12563. /// <summary>
  12564. /// 查询共享文件列表
  12565. /// </summary>
  12566. /// <param name="dto"></param>
  12567. /// <returns></returns>
  12568. [HttpPost]
  12569. public IActionResult QuerySharedFile(QuerySharedFileDto dto)
  12570. {
  12571. var isGroup = new List<int> { 1412 };
  12572. if (!isGroup.Contains(dto.FileType)) dto.Diid = 0;
  12573. var queryExpression = Expressionable.Create<Grp_GroupShareFile>()
  12574. .And(x => x.Diid == dto.Diid)
  12575. .And(x => x.FileType == dto.FileType)
  12576. .And(x => x.IsDel == 0)
  12577. .AndIF(!dto.FileName.IsNullOrWhiteSpace(), x => x.FileName.Contains(dto.FileName))
  12578. .AndIF(DateTime.TryParse(dto.StartTime, out DateTime Start), x => x.CreateTime >= Start)
  12579. .AndIF(DateTime.TryParse(dto.EndTime, out DateTime End), x => x.CreateTime <= End);
  12580. int totalCount = 0;
  12581. var dbQuery = _sqlSugar.Queryable<Grp_GroupShareFile>()
  12582. .Where(queryExpression.ToExpression())
  12583. .OrderBy(x => x.UploadJob)
  12584. .Select(x => new
  12585. {
  12586. x.Id,
  12587. FilePath = AppSettingsHelper.Get("ShareFileBaseUrl") + x.FilePath.Replace(AppSettingsHelper.Get("ShareFileBasePath"), AppSettingsHelper.Get("ShareFileFtpPath")),
  12588. x.FileName,
  12589. x.FileType,
  12590. x.CreateTime,
  12591. })
  12592. .ToPageList(dto.PageIndex, dto.PageSize, ref totalCount);
  12593. return Ok(JsonView(true, "SUCCESS!", new
  12594. {
  12595. FileList = dbQuery,
  12596. dto.PageSize,
  12597. dto.PageIndex,
  12598. totalCount
  12599. }));
  12600. }
  12601. /// <summary>
  12602. /// 删除共享文件模块下的指定文件
  12603. /// </summary>
  12604. /// <param name="dto"></param>
  12605. /// <returns></returns>
  12606. [HttpPost]
  12607. public IActionResult DeleteSharedFile(DeleteGroupFileDto dto)
  12608. {
  12609. var jw = JsonView(false);
  12610. var sing = _sqlSugar.Queryable<Grp_GroupShareFile>().First(x => x.Id == dto.Id && x.IsDel == 0);
  12611. if (sing == null)
  12612. {
  12613. jw.Msg = "暂无文件信息!";
  12614. return Ok(jw);
  12615. }
  12616. if (sing.CreateUserId != dto.UserId)
  12617. {
  12618. jw.Msg = "只能删除自己上传的文件!";
  12619. return Ok(jw);
  12620. }
  12621. if (System.IO.File.Exists(sing.FilePath))
  12622. {
  12623. try
  12624. {
  12625. System.IO.File.Delete(sing.FilePath);
  12626. }
  12627. catch (Exception ex)
  12628. {
  12629. jw.Msg = "删除失败!" + ex.Message;
  12630. return Ok(jw);
  12631. }
  12632. }
  12633. sing.IsDel = 1;
  12634. sing.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  12635. sing.DeleteUserId = dto.UserId;
  12636. _sqlSugar.Updateable<Grp_GroupShareFile>(sing).ExecuteCommand();
  12637. jw = JsonView(true, "删除成功!");
  12638. return Ok(jw);
  12639. }
  12640. #endregion
  12641. #region 团组英文资料
  12642. /// <summary>
  12643. /// 查询团组英文所有资料
  12644. /// </summary>
  12645. /// <param name="dto"></param>
  12646. /// <returns></returns>
  12647. [HttpPost]
  12648. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12649. public async Task<IActionResult> QueryDelegationEnData(QueryDelegationEnDataDto dto)
  12650. {
  12651. try
  12652. {
  12653. Result groupData = await _delegationEnDataRep.QueryDelegationEnData(dto);
  12654. if (groupData.Code != 0)
  12655. {
  12656. return Ok(JsonView(false, groupData.Msg));
  12657. }
  12658. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  12659. }
  12660. catch (Exception ex)
  12661. {
  12662. return Ok(JsonView(false, ex.Message));
  12663. throw;
  12664. }
  12665. }
  12666. /// <summary>
  12667. /// 团组英文资料操作(Status:1.新增,2.修改)
  12668. /// </summary>
  12669. /// <param name="dto"></param>
  12670. /// <returns></returns>
  12671. [HttpPost]
  12672. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12673. public async Task<IActionResult> OpDelegationEnData(OpDelegationEnDataDto dto)
  12674. {
  12675. try
  12676. {
  12677. Result groupData = await _delegationEnDataRep.OpDelegationEnData(dto);
  12678. if (groupData.Code != 0)
  12679. {
  12680. return Ok(JsonView(false, groupData.Msg));
  12681. }
  12682. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  12683. }
  12684. catch (Exception ex)
  12685. {
  12686. return Ok(JsonView(false, ex.Message));
  12687. throw;
  12688. }
  12689. }
  12690. /// <summary>
  12691. /// 团组英文资料Id查询数据
  12692. /// </summary>
  12693. /// <param name="dto"></param>
  12694. /// <returns></returns>
  12695. [HttpPost]
  12696. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12697. public async Task<IActionResult> QueryDelegationEnDataById(QueryDelegationEnDataByIdDto dto)
  12698. {
  12699. try
  12700. {
  12701. Grp_DelegationEnData _DelegationEnData = await _sqlSugar.Queryable<Grp_DelegationEnData>().FirstAsync(it => it.Id == dto.Id && it.IsDel == 0);
  12702. if (_DelegationEnData != null)
  12703. {
  12704. return Ok(JsonView(true, "查询成功!", _DelegationEnData));
  12705. }
  12706. return Ok(JsonView(true, "暂无数据!", _DelegationEnData));
  12707. }
  12708. catch (Exception ex)
  12709. {
  12710. return Ok(JsonView(false, "程序错误!"));
  12711. throw;
  12712. }
  12713. }
  12714. /// <summary>
  12715. /// 团组英文资料删除
  12716. /// </summary>
  12717. /// <param name="dto"></param>
  12718. /// <returns></returns>
  12719. [HttpPost]
  12720. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12721. public async Task<IActionResult> DelDelegationEnData(DelBaseDto dto)
  12722. {
  12723. try
  12724. {
  12725. var res = await _delegationEnDataRep.SoftDeleteByIdAsync<Grp_DelegationEnData>(dto.Id.ToString(), dto.DeleteUserId);
  12726. if (!res)
  12727. {
  12728. return Ok(JsonView(false, "删除失败"));
  12729. }
  12730. return Ok(JsonView(true, "删除成功!"));
  12731. }
  12732. catch (Exception ex)
  12733. {
  12734. return Ok(JsonView(false, ex.Message));
  12735. throw;
  12736. }
  12737. }
  12738. #endregion
  12739. #region 导出邀请函
  12740. /// <summary>
  12741. /// 导出邀请函页面初始化
  12742. /// </summary>
  12743. /// <param name="dto"></param>
  12744. /// <returns></returns>
  12745. [HttpPost]
  12746. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12747. public async Task<IActionResult> QueryinvitationLetter(DecreasePaymentsListDto dto)
  12748. {
  12749. try
  12750. {
  12751. var grp_Delegations = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(a => a.IsDel == 0).OrderBy(a => a.VisitStartDate, OrderByType.Desc).ToList();
  12752. var crm_Deles = new List<Crm_DeleClient>();
  12753. if (dto.DiId == 0)
  12754. {
  12755. crm_Deles = await _sqlSugar.Queryable<Crm_DeleClient>().Where(a => a.DiId == grp_Delegations[0].Id && a.IsDel == 0).ToListAsync();
  12756. }
  12757. else
  12758. {
  12759. crm_Deles = await _sqlSugar.Queryable<Crm_DeleClient>().Where(a => a.DiId == dto.DiId && a.IsDel == 0).ToListAsync();
  12760. }
  12761. return Ok(JsonView(true, "查询成功!", new
  12762. {
  12763. deleClient = crm_Deles,
  12764. delegations = grp_Delegations
  12765. }));
  12766. }
  12767. catch (Exception ex)
  12768. {
  12769. return Ok(JsonView(false, "程序错误!"));
  12770. throw;
  12771. }
  12772. }
  12773. /// <summary>
  12774. /// 导出邀请函
  12775. /// </summary>
  12776. /// <param name="dto"></param>
  12777. /// <returns></returns>
  12778. [HttpPost]
  12779. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12780. public async Task<IActionResult> invitationLetter(DecreasePaymentsListDto dto)
  12781. {
  12782. #region 参数验证
  12783. //if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  12784. if (dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId参数!"));
  12785. #endregion
  12786. try
  12787. {
  12788. var transDic = new Dictionary<string, string>();
  12789. string sql = string.Format(@"Select tcl.Id,tcl.DiId,temp.*,tcl.ShippingSpaceTypeId,tcl.ShippingSpaceSpecialNeeds,
  12790. tcl.HotelSpecialNeeds,tcl.MealSpecialNeeds,tcl.Remark
  12791. From Grp_TourClientList tcl
  12792. Left Join
  12793. (Select dc.Id As DcId,dc.LastName,dc.FirstName,dc.Pinyin,dc.Sex,ccom.CompanyFullName,dc.Job,
  12794. cc1.CertNo As IDCardNo,dc.Phone,dc.BirthDay,cc2.PassportType,cc2.CertNo As PassportNo,cc2.Country,
  12795. cc2.Area,cc2.IssueDt,cc2.ExpiryDt
  12796. From Crm_DeleClient dc
  12797. Left Join Crm_CustomerCompany ccom On dc.CrmCompanyId = ccom.Id And ccom.IsDel = 0
  12798. Left Join Crm_CustomerCert cc1 On dc.Id = cc1.DcId And cc1.SdId = 773 And cc1.IsDel = 0
  12799. Left Join Crm_CustomerCert cc2 On dc.Id = cc2.DcId And cc2.SdId = 774 And cc2.IsDel = 0
  12800. Where dc.IsDel = 0) temp
  12801. On temp.DcId =tcl.ClientId
  12802. Where tcl.IsDel = 0 And tcl.DiId = {0}", dto.DiId);
  12803. var datas = _sqlSugar.SqlQueryable<TourClientListDetailsView>(sql).ToList();
  12804. var texts = new List<string>();
  12805. if (datas.Count != 0)
  12806. {
  12807. foreach (TourClientListDetailsView item in datas)
  12808. {
  12809. if (!string.IsNullOrWhiteSpace(item.Pinyin))
  12810. {
  12811. transDic.Add(item.LastName + item.FirstName, item.Pinyin);
  12812. }
  12813. else
  12814. {
  12815. string name = item.LastName + item.FirstName;
  12816. texts.Add(name);
  12817. }
  12818. if (!string.IsNullOrEmpty(item.Job) && !texts.Contains(item.Job))
  12819. {
  12820. if (!transDic.ContainsKey(item.Job))
  12821. {
  12822. texts.Add(item.Job);
  12823. }
  12824. }
  12825. if (!string.IsNullOrEmpty(item.CompanyFullName))
  12826. {
  12827. texts.Add(item.CompanyFullName);
  12828. }
  12829. }
  12830. var transData = await _airTicketResRep.ReTransBatch(texts, "en");
  12831. if (transData.Count > 0)
  12832. {
  12833. foreach (TranslateResult item in transData)
  12834. {
  12835. if (!transDic.ContainsKey(item.Query))
  12836. {
  12837. transDic.Add(item.Query, item.Translation);
  12838. }
  12839. }
  12840. }
  12841. var list = new List<GuestList>();
  12842. foreach (var dele in datas)
  12843. {
  12844. var guestList = new GuestList();
  12845. if (!string.IsNullOrWhiteSpace(dele.Pinyin))
  12846. {
  12847. guestList.Name = dele.Pinyin;
  12848. }
  12849. else
  12850. {
  12851. string Name = transDic.Where(s => s.Key == dele.LastName + dele.FirstName).FirstOrDefault().Value;
  12852. guestList.Name = Name;
  12853. }
  12854. if (dele.Sex == 0)
  12855. {
  12856. guestList.Sex = "Male";
  12857. }
  12858. else if (dele.Sex == 1)
  12859. {
  12860. guestList.Sex = "Female";
  12861. }
  12862. guestList.DOB = dele.BirthDay.Replace('-', '.');
  12863. if (!string.IsNullOrEmpty(dele.Job))
  12864. {
  12865. guestList.Job = dele.Job;
  12866. }
  12867. list.Add(guestList);
  12868. }
  12869. //载入模板
  12870. var doc = new Document(AppSettingsHelper.Get("WordBasePath") + "Template/邀请函模板0210.docx");
  12871. var builder = new DocumentBuilder(doc);
  12872. //获取word里所有表格
  12873. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  12874. //获取所填表格的序数
  12875. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  12876. var rowStart = tableOne.Rows[0]; //获取第1行
  12877. //循环赋值
  12878. for (int i = 0; i < list.Count; i++)
  12879. {
  12880. builder.MoveToCell(0, i + 1, 0, 0);
  12881. builder.Write(list[i].Name.ToString());
  12882. builder.MoveToCell(0, i + 1, 1, 0);
  12883. builder.Write(list[i].Sex.ToString());
  12884. builder.MoveToCell(0, i + 1, 2, 0);
  12885. builder.Write(list[i].DOB.ToString());
  12886. builder.MoveToCell(0, i + 1, 3, 0);
  12887. builder.Write(list[i].Job.ToString());
  12888. }
  12889. //删除多余行
  12890. while (tableOne.Rows.Count > list.Count + 1)
  12891. {
  12892. tableOne.Rows.RemoveAt(list.Count + 1);
  12893. }
  12894. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  12895. string fileName = "邀请函" + DateTime.Now.ToString("yyyy-MM-dd") + ".docx";
  12896. string filePath = fileDir + $@"商邀相关文件/{fileName}";
  12897. doc.Save(filePath);
  12898. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/GrpFile/商邀相关文件/" + fileName;
  12899. return Ok(JsonView(true, "操作成功!", Url));
  12900. }
  12901. else
  12902. {
  12903. return Ok(JsonView(false, "该团组客户名单暂未录入!"));
  12904. }
  12905. }
  12906. catch (Exception ex)
  12907. {
  12908. return Ok(JsonView(false, ex.Message));
  12909. throw;
  12910. }
  12911. }
  12912. #endregion
  12913. #region 团组经理模块 出入境费用
  12914. /// <summary>
  12915. /// 团组模块 - 出入境费用 - 省份基础数据源
  12916. /// </summary>
  12917. /// <returns></returns>
  12918. [HttpGet]
  12919. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12920. public async Task<IActionResult> GetEnterExitProvBelongCostDataSource()
  12921. {
  12922. return Ok(JsonView(await _groupRepository.ProvinceBasicSource()));
  12923. }
  12924. /// <summary>
  12925. /// 团组模块 - 出入境费用 - 基础数据源(团组名称/币种类型)
  12926. /// </summary>
  12927. /// <param name="dto"></param>
  12928. /// <returns></returns>
  12929. [HttpPost]
  12930. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12931. public async Task<IActionResult> GetEnterExitCostDataSource(EnterExitCostDataSourceDto dto)
  12932. {
  12933. var groupNameData = await _groupRepository.EnterExitCostGroupNameAsync();
  12934. var groupNamFirst = groupNameData.FirstOrDefault();
  12935. //SetDataInfoView
  12936. var dataSource = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToListAsync();
  12937. var currencyData = dataSource.Where(it => it.STid == 66).ToList(); //所有币种
  12938. List<SetDataInfoView> _CurrencyData = _mapper.Map<List<SetDataInfoView>>(currencyData);
  12939. //验证城市归属并给默认值
  12940. int provinceId = 122;
  12941. if (groupNamFirst != null) provinceId = groupNamFirst.ProvinceId;
  12942. (SetDataInfoView[] wordTypeData, SetDataInfoView[] excelTypeData) = await _enterExitCostRep.FileOwner(provinceId);
  12943. var _currencyInfos = await GeneralMethod.EnterExitCostInitRate();
  12944. var viewPermissionData = await _enterExitCostRep.PermissionViewUsersAsync();
  12945. return Ok(JsonView(true, "查询成功!", new
  12946. {
  12947. GroupNameData = groupNameData,
  12948. CurrencyData = _CurrencyData,
  12949. WordTypeData = wordTypeData,
  12950. ExcelTypeData = excelTypeData,
  12951. CurrencyInit = _currencyInfos
  12952. }));
  12953. }
  12954. /// <summary>
  12955. /// 团组模块 - 出入境费用 - 文件类型list 跟据省份Id获取
  12956. /// </summary>
  12957. /// <returns></returns>
  12958. [HttpGet("{provinceId}")]
  12959. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12960. public async Task<IActionResult> EnterExitCostFileOwner([FromRoute] int provinceId = 122)
  12961. {
  12962. //验证城市归属并给默认值
  12963. if (provinceId < 1) provinceId = 122;
  12964. /*
  12965. * 122 四川
  12966. * 108 贵州
  12967. * 103 重庆
  12968. * 132 云南
  12969. */
  12970. (SetDataInfoView[] wordTypeData, SetDataInfoView[] excelTypeData) = await _enterExitCostDraftRep.FileOwner(provinceId);
  12971. return Ok(JsonView(true, "查询成功!", new
  12972. {
  12973. WordTypeData = wordTypeData,
  12974. ExcelTypeData = excelTypeData,
  12975. }));
  12976. }
  12977. /// <summary>
  12978. /// 团组模块 - 出入境费用
  12979. /// 实时汇率 tips
  12980. /// 签证费用 tips
  12981. /// 机票费用 tips
  12982. /// </summary>
  12983. /// <returns></returns>
  12984. [HttpPost]
  12985. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12986. public async Task<IActionResult> GetEnterExitCostCorrelationTips(EnterExitCostInfobyDiIdDto dto)
  12987. {
  12988. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(it => it.Id == dto.DiId && it.IsDel == 0);
  12989. //默认币种显示
  12990. var reteInfos = await GeneralMethod.EnterExitCostLiveRate();
  12991. var visaData = await _visaFeeInfoRep.EnterExitCostVisaTips(dto.DiId);
  12992. var airData = await GeneralMethod.EntryAndExitTips(dto.DiId);
  12993. return Ok(JsonView(true, "查询成功!", new
  12994. {
  12995. //GroupNameData = groupNameData.Data,
  12996. visaData = visaData.Data,
  12997. airData,
  12998. reteInfos
  12999. }));
  13000. }
  13001. #region 城市区间交通费
  13002. /// <summary>
  13003. /// 团组模块 - 出入境费用 - 基础数据源(境外用车)
  13004. /// </summary>
  13005. /// <param name="groupId"></param>
  13006. /// <returns></returns>
  13007. [HttpGet("{groupId}")]
  13008. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13009. public async Task<IActionResult> GetEnterExitCostOVByGroupId(int groupId)
  13010. {
  13011. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  13012. if (groupInfo == null)
  13013. {
  13014. return Ok(JsonView(false, "团组信息为空"));
  13015. }
  13016. var countryies = _groupRepository.GroupSplitCountry(groupInfo.VisitCountry);
  13017. if (countryies?.Any() != true)
  13018. {
  13019. return Ok(JsonView(false, "团组出访国家信息为空"));
  13020. }
  13021. var currencies = await GeneralMethod.EnterExitCostOVFeeUsedCurrencyAsync(groupId);
  13022. var currencyData = await _sqlSugar.Queryable<Sys_SetData>()
  13023. .Where(x => x.IsDel == 0 && x.STid == 66)
  13024. .ToListAsync();
  13025. var overseaVehicles = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  13026. .Where(x => x.IsDel == 0 && countryies.Contains(x.CountryName))
  13027. .ToListAsync();
  13028. var overseaVehicleIds = overseaVehicles.Select(x => x.Id).ToList();
  13029. //只返回接送机的数据
  13030. var overseaVehicleTypes = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  13031. .Where(x => x.IsDel == 0 && x.ServiceType == VehicleServiceTypeEnum.TransferService && overseaVehicleIds.Contains(x.OvId))
  13032. .ToListAsync();
  13033. var sysUers = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToListAsync();
  13034. var overseaVehicleCityDatas = new List<dynamic>() {
  13035. new
  13036. {
  13037. Id = 0,
  13038. area= "未选择",
  13039. CarTypeName = "",
  13040. serviceType = "",
  13041. Price = 0.00M,
  13042. guidePrice = 0.00M,
  13043. otherPrice = 0.00M,
  13044. currency = 0,
  13045. currencyName = "",
  13046. currRate = 1.0000M,
  13047. LastUpdateUserName = "",
  13048. LastUpdateTime = "",
  13049. Remark = ""
  13050. }};
  13051. foreach (var item in overseaVehicleTypes)
  13052. {
  13053. var parentInfo = overseaVehicles.FirstOrDefault(x => x.Id == item.OvId);
  13054. string area = string.Empty,
  13055. serviceType = "未设置",
  13056. currencyName = string.Empty;
  13057. decimal otherPrice = 0.00M;
  13058. if (parentInfo != null)
  13059. {
  13060. if (parentInfo.CountryName == parentInfo.CityName) area = parentInfo.CountryName;
  13061. else area = $"{parentInfo.CountryName}-{parentInfo.CityName}";
  13062. serviceType = item.ServiceType.GetDescription();
  13063. currencyName = currencyData.FirstOrDefault(x => x.Id == parentInfo.Currency)?.Name ?? "-";
  13064. otherPrice = parentInfo.OtherPrice1 + parentInfo.OtherPrice2;
  13065. }
  13066. //当前币种汇率值
  13067. var currRate = 1.0000M;
  13068. var currencyInfo = currencies.FirstOrDefault(x => x.CurrencyCode == currencyName);
  13069. if (currencyInfo != null) currRate = currencyInfo.Rate;
  13070. overseaVehicleCityDatas.add(new
  13071. {
  13072. item.Id,
  13073. area,
  13074. item.CarTypeName,
  13075. serviceType,
  13076. item.Price,
  13077. guidePrice = parentInfo?.GuidePrice ?? 0.00M,
  13078. otherPrice,
  13079. currency = parentInfo?.Currency ?? 0,
  13080. currencyName,
  13081. currRate,
  13082. LastUpdateUserName = sysUers.FirstOrDefault(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-",
  13083. item.LastUpdateTime,
  13084. item.Remark
  13085. });
  13086. }
  13087. var total = overseaVehicleCityDatas.Count;
  13088. var view = new
  13089. {
  13090. visitCountries = string.Join("、", countryies),
  13091. groupSize = groupInfo.VisitPNumber, //出访人数
  13092. defAirportTransferCoeff = Def_AirportTransferCoeff, //接送机默认报价系数
  13093. defServiceCount = Def_ServiceCount, //接送机默认服务次数
  13094. defTrainCoeff = Def_TrainCoeff, //火车默认报价系数
  13095. defPullCartCoeff = Def_PullCartCoeff, //拉车默认报价系数
  13096. defCityFlightCoeff = Def_CityFlightCoeff, //城市机票默认报价系数
  13097. Currencies = currencies,
  13098. data = overseaVehicleCityDatas
  13099. };
  13100. if (overseaVehicleCityDatas.Count == 0)
  13101. {
  13102. return Ok(JsonView(true, "暂无数据!", view));
  13103. }
  13104. return Ok(JsonView(true, "查询成功!", view, total));
  13105. }
  13106. /// <summary>
  13107. /// 团组模块 - 出入境费用 - 境外用车计算详细信息
  13108. /// </summary>
  13109. /// <param name="groupId"></param>
  13110. /// <param name="currUserId"></param>
  13111. /// <returns></returns>
  13112. [HttpGet("{groupId}")]
  13113. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13114. public async Task<IActionResult> GetEnterExitCostOVFeeDetails(int groupId, int currUserId)
  13115. {
  13116. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  13117. if (groupInfo == null)
  13118. {
  13119. return Ok(JsonView(false, "团组信息为空"));
  13120. }
  13121. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).FirstAsync();
  13122. //CityIntervalInfo
  13123. var info = new CityIntervalInfo();
  13124. if (eecInfo != null && !string.IsNullOrEmpty(eecInfo.CityIntervalFeeDetails))
  13125. {
  13126. info = JsonConvert.DeserializeObject<CityIntervalInfo>(eecInfo.CityIntervalFeeDetails);
  13127. return Ok(JsonView(true, "查询成功!", info));
  13128. }
  13129. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == currUserId).FirstAsync();
  13130. var userName = userInfo?.CnName ?? "-";
  13131. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  13132. //返回默认数据
  13133. info = new CityIntervalInfo()
  13134. {
  13135. APTFeeDetails = new List<RoundTripTransferInfo>() { new() { No = 1, Coefficient = Def_AirportTransferCoeff, ServiceCount = Def_ServiceCount } },
  13136. PullCartFeeDetails = new List<PullCartInfo>() { new() { No = 1, Coefficient = Def_PullCartCoeff } },
  13137. TrainFeeDetails = new List<TrainInfo>() { new() { No = 1, Coefficient = Def_TrainCoeff } },
  13138. CityAirTicketFeeDetails = new List<CityAirTicketInfo>() { new() { No = 1, Coefficient = Def_CityFlightCoeff } },
  13139. LastUpdateUserName = userName,
  13140. LastUpdateTime = nowTime,
  13141. CreateUserName = userName,
  13142. Currencies = await GeneralMethod.EnterExitCostOVFeeUsedCurrencyAsync(groupId),
  13143. CreateTime = nowTime
  13144. };
  13145. return Ok(JsonView(true, "查询成功!", info));
  13146. }
  13147. /// <summary>
  13148. /// 团组模块 - 出入境费用 - 境外用车计算 保存
  13149. /// </summary>
  13150. /// <param name="dto"></param>
  13151. /// <returns></returns>
  13152. [HttpPost]
  13153. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13154. public async Task<IActionResult> GetEnterExitCostOVFeeSave(GetEnterExitCostOVFeeSaveDto dto)
  13155. {
  13156. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == dto.GroupId).FirstAsync();
  13157. if (groupInfo == null)
  13158. {
  13159. return Ok(JsonView(false, "团组信息为空"));
  13160. }
  13161. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == dto.CurrUserId).FirstAsync();
  13162. if (userInfo == null)
  13163. {
  13164. return Ok(JsonView(false, "员工信息为空"));
  13165. }
  13166. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == dto.GroupId).FirstAsync();
  13167. if (eecInfo == null)
  13168. {
  13169. return Ok(JsonView(false, "出入境费用信息为空"));
  13170. }
  13171. var oldData = new CityIntervalInfo();
  13172. if (!string.IsNullOrEmpty(eecInfo.CityIntervalFeeDetails))
  13173. {
  13174. oldData = JsonConvert.DeserializeObject<CityIntervalInfo>(eecInfo.CityIntervalFeeDetails);
  13175. }
  13176. var userName = userInfo?.CnName ?? "-";
  13177. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  13178. var info = new CityIntervalInfo()
  13179. {
  13180. APTFeeTotal = dto.APTFeeTotal,
  13181. APTFeeDetails = dto.APTFeeDetails,
  13182. PullCartFeeTotal = dto.PullCartFeeTotal,
  13183. PullCartFeeDetails = dto.PullCartFeeDetails,
  13184. TrainFeeTotal = dto.TrainFeeTotal,
  13185. TrainFeeDetails = dto.TrainFeeDetails,
  13186. CityAirTicketFeeTotal = dto.CityAirTicketFeeTotal,
  13187. CityAirTicketFeeDetails = dto.CityAirTicketFeeDetails,
  13188. Currencies = dto.Currencies,
  13189. LastUpdateUserName = userName,
  13190. LastUpdateTime = nowTime,
  13191. CreateUserName = oldData?.CreateUserName ?? userName,
  13192. CreateTime = oldData?.CreateTime ?? nowTime
  13193. };
  13194. eecInfo.CityIntervalFeeDetails = JsonConvert.SerializeObject(info);
  13195. var upd = await _sqlSugar.Updateable<Grp_EnterExitCost>()
  13196. .SetColumns(it => it.CityIntervalFeeDetails == eecInfo.CityIntervalFeeDetails)
  13197. .SetColumns(it => it.LastUpdateUserId == dto.CurrUserId)
  13198. .SetColumns(it => it.LastUpdateTime == nowTime)
  13199. .Where(x => x.Id == eecInfo.Id)
  13200. .ExecuteCommandAsync();
  13201. if (upd < 1)
  13202. {
  13203. return Ok(JsonView(false));
  13204. }
  13205. //返回数据处理
  13206. var label = new StringBuilder();
  13207. //接送机
  13208. if (dto.APTFeeDetails?.Any() == true)
  13209. {
  13210. var ovIds = dto.APTFeeDetails.Select(x => x.OvId).ToList();
  13211. var areas = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  13212. .LeftJoin<Res_OverseaVehicle>((ovtp, ov) => ovtp.OvId == ov.Id)
  13213. .Where((ovtp, ov) => ovtp.IsDel == 0 && ovIds.Contains(ovtp.Id))
  13214. .Select((ovtp, ov) => new
  13215. {
  13216. ovtp.Id,
  13217. ov.CountryName,
  13218. ov.CityName
  13219. }).ToListAsync();
  13220. var items = dto.APTFeeDetails
  13221. .Select(item =>
  13222. {
  13223. var areaInfo = areas.FirstOrDefault(x => x.Id == item.OvId);
  13224. if (areaInfo == null) return null;
  13225. return areaInfo.CountryName == areaInfo.CityName
  13226. ? $"{areaInfo.CountryName}({item.Quote:#0.00} CNY)"
  13227. : $"{areaInfo.CountryName}-{areaInfo.CityName}({item.Quote:#0.00} CNY)";
  13228. })
  13229. .Where(item => item != null)
  13230. .ToList();
  13231. label.AppendLine($"接送机({string.Join("、", items)});");
  13232. }
  13233. //拉车
  13234. if (dto.PullCartFeeDetails?.Any() == true)
  13235. {
  13236. var feeLabel = string.Join("、",
  13237. dto.PullCartFeeDetails.Select(x =>
  13238. $"{x.Quote:#0.00} CNY"
  13239. ));
  13240. label.AppendLine($"拉车({feeLabel});");
  13241. }
  13242. //火车
  13243. if (dto.TrainFeeDetails?.Any() == true)
  13244. {
  13245. var feeLabel = string.Join("、",
  13246. dto.TrainFeeDetails.Select(x =>
  13247. $"{x.Quote:#0.00} CNY"
  13248. ));
  13249. label.AppendLine($"火车票({feeLabel});");
  13250. }
  13251. //城市机票
  13252. if (dto.CityAirTicketFeeDetails?.Any() == true)
  13253. {
  13254. var feeLabel = string.Join("、",
  13255. dto.CityAirTicketFeeDetails.Select(x =>
  13256. $"{x.Quote:#0.00} CNY"
  13257. ));
  13258. label.AppendLine($"城市机票({feeLabel});");
  13259. }
  13260. //费用
  13261. decimal quote = (dto.APTFeeTotal + dto.PullCartFeeTotal + dto.TrainFeeTotal + dto.CityAirTicketFeeTotal).ConvertToDecimal1();
  13262. decimal jjcQuote = quote;
  13263. decimal gwcQuote = quote;
  13264. decimal tdcQuote = quote;
  13265. var view = new
  13266. {
  13267. label = label.ToString(),
  13268. jjcQuote,
  13269. gwcQuote,
  13270. tdcQuote
  13271. };
  13272. return Ok(JsonView(view));
  13273. }
  13274. #endregion
  13275. /// <summary>
  13276. /// 团组模块 - 出入境费用 - Info
  13277. /// </summary>
  13278. /// <param name="dto"></param>
  13279. /// <returns></returns>
  13280. [HttpPost]
  13281. //[ApiLog("Grp_EnterExitCost", OperationEnum.Details)]
  13282. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13283. public async Task<IActionResult> GetEnterExitCostInfobyDiId(EnterExitCostInfobyDiIdDto dto)
  13284. {
  13285. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  13286. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  13287. return Ok(await _enterExitCostRep.GetEnterExitCostInfoByDiId(dto));
  13288. }
  13289. /// <summary>
  13290. /// 团组模块 - 出入境费用 - 设置view权限
  13291. /// </summary>
  13292. /// <returns></returns>
  13293. [HttpPost]
  13294. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13295. public async Task<IActionResult> EnterExitCostSetViewPermissiion(EnterExitCostSetViewPermissiionDto dto)
  13296. {
  13297. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  13298. if (dto.GroupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  13299. if (dto.UserIds.Length < 1) return Ok(JsonView(false, "请传入有效的userId;"));
  13300. var permissions = new List<Grp_EnterExitCostPermission>();
  13301. foreach (var userId in dto.UserIds)
  13302. {
  13303. permissions.Add(new Grp_EnterExitCostPermission { Permission = 1, GroupId = dto.GroupId, UserId = userId, CreateUserId = dto.CurrUserId });
  13304. }
  13305. if (permissions.Any())
  13306. {
  13307. _sqlSugar.BeginTran();
  13308. try
  13309. {
  13310. await _sqlSugar.Deleteable<Grp_EnterExitCostPermission>().Where(it => it.GroupId == dto.GroupId).ExecuteCommandAsync();
  13311. var result = await _sqlSugar.Insertable(permissions).ExecuteCommandAsync();
  13312. if (result < 1)
  13313. {
  13314. _sqlSugar.RollbackTran();
  13315. return Ok(JsonView(false));
  13316. }
  13317. }
  13318. catch (Exception ex)
  13319. {
  13320. _sqlSugar.RollbackTran();
  13321. return Ok(JsonView(false, ex.Message));
  13322. }
  13323. _sqlSugar.CommitTran();
  13324. return Ok(JsonView(true));
  13325. }
  13326. return Ok(JsonView(false));
  13327. }
  13328. /// <summary>
  13329. /// 团组模块 - 出入境费用 - Add And Update
  13330. /// </summary>
  13331. /// <returns></returns>
  13332. [HttpPost]
  13333. [ApiLog("Grp_EnterExitCost", OperationEnum.Add)]
  13334. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13335. public async Task<IActionResult> PostEnterExitCostOperate(EnterExitCostOperateDto dto)
  13336. {
  13337. try
  13338. {
  13339. var rateRecords = new List<RateRecordInfo>();
  13340. #region 汇率保存前存储
  13341. var info = await _sqlSugar.Queryable<Grp_EnterExitCost>().FirstAsync(x => x.IsDel == 0 && x.DiId == dto.DiId);
  13342. if (info != null)
  13343. {
  13344. var cacheRateInfos = CommonFun.GetCurrencyChinaToList(info.CurrencyRemark);
  13345. if (cacheRateInfos != null && cacheRateInfos.Count > 0)
  13346. {
  13347. rateRecords = cacheRateInfos.Select(x => new RateRecordInfo()
  13348. {
  13349. CurrencyCode = x.CurrencyCode,
  13350. CurrencyName = x.CurrencyName,
  13351. UpdatePreRate = x.Rate,
  13352. UpdateBreRate = dto.Currencys.Where(x1 => x1.CurrencyName.Equals(x.CurrencyName)).FirstOrDefault()?.Rate ?? 0.00M
  13353. }).ToList();
  13354. }
  13355. else
  13356. {
  13357. rateRecords = dto.Currencys.Select(x => new RateRecordInfo()
  13358. {
  13359. CurrencyCode = x.CurrencyCode,
  13360. CurrencyName = x.CurrencyName,
  13361. UpdatePreRate = 0.00M,
  13362. UpdateBreRate = x.Rate
  13363. }).ToList();
  13364. }
  13365. }
  13366. else
  13367. {
  13368. rateRecords = dto.Currencys.Select(x => new RateRecordInfo()
  13369. {
  13370. CurrencyCode = x.CurrencyCode,
  13371. CurrencyName = x.CurrencyName,
  13372. UpdatePreRate = 0.00M,
  13373. UpdateBreRate = x.Rate
  13374. }).ToList();
  13375. }
  13376. #endregion
  13377. var data = await _enterExitCostRep.PostEnterExitCostOperate(dto);
  13378. if (dto.DayOtherPriceData.Any())
  13379. {
  13380. var inserList = dto.DayOtherPriceData
  13381. .Where(x => x.Id == 0)
  13382. .Select(x => new Grp_DayOtherPrice
  13383. {
  13384. Cost = x.Cost,
  13385. Id = x.Id,
  13386. CreateTime = DateTime.Now,
  13387. CreateUserId = dto.UserId,
  13388. Currency = x.Currency,
  13389. Diid = x.DiId,
  13390. Index = x.Index,
  13391. IsDel = 0,
  13392. SetDataId = x.SetDataId,
  13393. SubTotal = x.SubTotal,
  13394. Remark = x.Remark
  13395. })
  13396. .ToList();
  13397. var updateList = dto.DayOtherPriceData
  13398. .Where(x => x.Id != 0)
  13399. .Select(x => new Grp_DayOtherPrice
  13400. {
  13401. Cost = x.Cost,
  13402. Id = x.Id,
  13403. CreateTime = DateTime.Now,
  13404. CreateUserId = dto.UserId,
  13405. Currency = x.Currency,
  13406. Diid = x.DiId,
  13407. Index = x.Index,
  13408. IsDel = 0,
  13409. SetDataId = x.SetDataId,
  13410. SubTotal = x.SubTotal,
  13411. Remark = x.Remark
  13412. })
  13413. .ToList();
  13414. //添加
  13415. _sqlSugar.BeginTran();
  13416. if (inserList.Any())
  13417. {
  13418. var rowCount = _sqlSugar.Insertable<Grp_DayOtherPrice>(inserList).ExecuteCommand();
  13419. }
  13420. if (updateList.Any())
  13421. {
  13422. var rowCount = _sqlSugar.Updateable<Grp_DayOtherPrice>(updateList).ExecuteCommand();
  13423. }
  13424. _sqlSugar.CommitTran();
  13425. }
  13426. if (data.Code != 0)
  13427. {
  13428. return Ok(JsonView(false, data.Msg));
  13429. }
  13430. //生成默认文件pdf并且通知人员
  13431. var fileView = await GeneralMethod.EnterExitCostDownload(new EnterExitCostDownloadDto()
  13432. {
  13433. DiId = dto.DiId,
  13434. ExportType = 1,
  13435. SubTypeId = 1005
  13436. }, "pdf");
  13437. //发送通知
  13438. string fileUrl = (string)fileView.Data.GetType().GetProperty("Url").GetValue(fileView.Data, null);
  13439. int sign = (int)data.Data.GetType().GetProperty("sign").GetValue(data.Data, null);
  13440. string md5Sign = GeneralMethod.Encrypt($"{sign}&fileName={fileUrl}");
  13441. string url = string.Format("http://oa.pan-american-intl.com:4399/#/Sankunginfo?sign={0}&fileName={1}", sign, fileUrl);
  13442. await AppNoticeLibrary.SendUserMsg_GroupShare_ToGM(dto.DiId, new List<string>() { "208", "233", "21" }, dto.UserId, url);
  13443. //汇率信息记录
  13444. await GeneralMethod.RateRecordSave(dto.UserId, sign, "出入境费用");
  13445. var checkCurrencys = await _enterExitCostRep.GetCheckCurrencies(dto.DiId);
  13446. //汇率验证、反推
  13447. (bool isSendMsg, string msgContent, List<CurrencyInfo> liveRates) = await GeneralMethod.EnterExitCostCheckRate(dto.DiId, checkCurrencys);
  13448. if (isSendMsg)
  13449. {
  13450. //消息推送
  13451. await AppNoticeLibrary.SendUserMsg_GroupShare_ToFin(dto.DiId, dto.UserId, msgContent);
  13452. }
  13453. #region 日志汇率记录
  13454. //按照已使用币种记录
  13455. if (checkCurrencys != null && checkCurrencys.Count > 0)
  13456. {
  13457. rateRecords = rateRecords.Where(x => checkCurrencys.Select(x1 => x1.CurrencyName).ToList().Contains(x.CurrencyName)).ToList();
  13458. //汇率记录中加入实时汇率
  13459. if (liveRates != null && liveRates.Count > 0)
  13460. {
  13461. foreach (var item in rateRecords)
  13462. {
  13463. item.CurrLiveRate = liveRates.Where(x => x.CurrencyName.Equals(item.CurrencyName)).FirstOrDefault()?.Rate ?? 0.00M;
  13464. }
  13465. }
  13466. var teamName = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == dto.DiId && x.IsDel == 0).Select(x => x.TeamName).FirstAsync();
  13467. var operationName = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == dto.UserId && x.IsDel == 0).Select(x => x.CnName).FirstAsync();
  13468. var logContent = new StringBuilder();
  13469. foreach (var item in rateRecords)
  13470. {
  13471. var blRate = (item.CurrLiveRate * 1.0350M).TruncDecimals(4);
  13472. string msg = $">- {item.CurrencyName}汇率:(页面保存前){item.UpdatePreRate:#0.0000}/(页面保存){item.UpdateBreRate:#0.0000}/实时汇率(已上浮1.0350):{blRate:#0.0000}【注:原接口输出汇率为:{item.CurrLiveRate:#0.0000}】";
  13473. logContent.AppendLine(msg);
  13474. }
  13475. _eec_textLogger.LogInformation("团组:【{teamName}({groupId})】 操作人:【{operationName}】 操作时间:【{operationTime}】\r\n{logContent}", teamName, dto.DiId, operationName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), logContent.ToString());
  13476. }
  13477. #endregion
  13478. return Ok(JsonView(true, data.Msg, data.Data));
  13479. }
  13480. catch (Exception ex)
  13481. {
  13482. return Ok(JsonView(false, ex.Message));
  13483. }
  13484. }
  13485. /// <summary>
  13486. /// 团组模块 - 出入境费用 - Confirm 费用
  13487. /// </summary>
  13488. /// <returns></returns>
  13489. [HttpPost]
  13490. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13491. public async Task<IActionResult> PostEnterExitCostIsConfirm(ConfirmCostDto dto)
  13492. {
  13493. //TODO:测试完毕需把对应的用户ID更改
  13494. //1、数据表添加字段
  13495. //2、更改字段接口()
  13496. var _view = await _enterExitCostRep.ConfirmCost(dto);
  13497. //3、确认成功 给财务发送消息
  13498. if (_view.Code == 200)
  13499. {
  13500. if (dto.Type == 1)
  13501. {
  13502. int diId = _enterExitCostRep._sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.Id == dto.Id).First()?.DiId ?? 0;
  13503. await AppNoticeLibrary.SendUserMsg_GroupShare_ToFinance(diId);
  13504. }
  13505. }
  13506. return Ok(_view);
  13507. }
  13508. /// <summary>
  13509. /// 团组模块 - 出入境费用 - File download
  13510. /// </summary>
  13511. /// <param name="dto"></param>
  13512. /// <returns></returns>
  13513. [HttpPost]
  13514. //[ApiLog("Grp_EnterExitCost", OperationEnum.Download)]
  13515. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13516. public async Task<IActionResult> PostEnterExitCostDownload(EnterExitCostDownloadDto dto)
  13517. {
  13518. try
  13519. {
  13520. if (dto.DiId < 1) return Ok(JsonView(400, "请传入有效的DiId参数;", ""));
  13521. if (dto.ExportType < 1) return Ok(JsonView(400, "请传入有效的ExportType参数; 1 明细表 2 表格", ""));
  13522. if (dto.SubTypeId < 1) return Ok(JsonView(400, @"请传入有效的SubTypeId参数;
  13523. 1 明细表 --> 1005(默认明细表) 1006(因公出国(境)经费测算明细表) 1007(四川省商务厅出国经费财政先行审核表)
  13524. 2 表格 --> 1008(派员单位出(境)任务和预算审批意见表) 1009(省级单位出(境)经费报销单)
  13525. 3 团组成员名单 1 团组成员名单", ""));
  13526. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).OrderByDescending(x => x.CreateTime).First();
  13527. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).ToList();
  13528. if (_EnterExitCosts == null) return Ok(JsonView(400, "该团组未填写出入境费用;", ""));
  13529. var currencyInit = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToList();
  13530. var enterExitCostCurrencys = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(_EnterExitCosts.CurrencyRemark);
  13531. //数据源
  13532. // 住宿费
  13533. var dac1 = _EnterExitCosts.ChoiceThree == 1 ? _DayAndCosts.Where(it => it.Type == 1).ToList() : new List<Grp_DayAndCost>();
  13534. // 伙食费
  13535. var dac2 = _EnterExitCosts.ChoiceFour == 1 ? _DayAndCosts.Where(it => it.Type == 2).ToList() : new List<Grp_DayAndCost>();
  13536. // 公杂费
  13537. var dac3 = _EnterExitCosts.ChoiceFive == 1 ? _DayAndCosts.Where(it => it.Type == 3).ToList() : new List<Grp_DayAndCost>();
  13538. // 培训费
  13539. var dac4 = _EnterExitCosts.ChoiceSix == 1 ? _DayAndCosts.Where(it => it.Type == 4).ToList() : new List<Grp_DayAndCost>();
  13540. // 其他款项费
  13541. var dac5 = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  13542. .LeftJoin<Sys_SetData>((x, a) => a.IsDel == 0 && a.Id == x.SetDataId)
  13543. .LeftJoin<Sys_SetData>((x, a, b) => b.IsDel == 0 && b.Id == x.Currency)
  13544. .Where((x, a, b) => x.IsDel == 0 && x.Diid == dto.DiId)
  13545. .Select((x, a, b) => new
  13546. {
  13547. x.Index,
  13548. itemName = a.Name,
  13549. CurrencyStr = b.Name,
  13550. x.Cost,
  13551. x.SubTotal,
  13552. x.Remark
  13553. })
  13554. .OrderBy((x) => x.Index)
  13555. .ToList();
  13556. var peiceItemCurrencys = new List<string>();
  13557. if (_DayAndCosts.Any())
  13558. {
  13559. var currencyIds = _DayAndCosts.Select(x => x.Currency).Distinct().ToList();
  13560. if (currencyIds.Any()) peiceItemCurrencys.AddRange(currencyInit.Where(x => currencyIds.Contains(x.Id)).Select(x => x.Name).ToList());
  13561. }
  13562. if (dac5.Any()) peiceItemCurrencys.AddRange(dac5.Select(x => x.CurrencyStr).Distinct().ToList());
  13563. var peiceItemCurrencyInfos = new List<CurrencyInfo>();
  13564. if (enterExitCostCurrencys.Any() && peiceItemCurrencys.Any())
  13565. {
  13566. peiceItemCurrencyInfos = enterExitCostCurrencys.Where(x => peiceItemCurrencys.Contains(x.CurrencyCode)).ToList();
  13567. }
  13568. var _CurrDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  13569. var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == dto.DiId).First();
  13570. if (_DelegationInfo == null)
  13571. {
  13572. return Ok(JsonView(400, "团组信息为空!", ""));
  13573. }
  13574. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  13575. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  13576. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  13577. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
  13578. .Select((tcl, dc, cc) => new ClientInfo
  13579. {
  13580. LastName = dc.LastName,
  13581. FirstName = dc.FirstName,
  13582. Sex = dc.Sex,
  13583. Birthday = dc.BirthDay,
  13584. Company = cc.CompanyFullName,
  13585. Job = dc.Job
  13586. })
  13587. .ToList();
  13588. foreach (var item in DeleClientList)
  13589. {
  13590. EncryptionProcessor.DecryptProperties(item);
  13591. }
  13592. var blackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  13593. var threeCodes = _sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList();
  13594. var placeData = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  13595. var rateDatas = await _EnterExitCosts.CurrencyRemark.SplitExchangeRate();
  13596. _DelegationInfo.VisitCountry = _DelegationInfo.VisitCountry.Replace("|", "、");
  13597. if (dto.ExportType == 1) //明细表
  13598. {
  13599. if (dto.SubTypeId == 1005) //1005(默认明细表)
  13600. {
  13601. //获取模板
  13602. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/出入境费用表模板.docx");
  13603. //载入模板
  13604. var doc = new Document(tempPath);
  13605. var builder = new DocumentBuilder(doc);
  13606. var dic = new Dictionary<string, string>();
  13607. decimal stayFeeTotal = _EnterExitCosts.ChoiceThree == 1 ? _DayAndCosts.Where(it => it.Type == 1).Sum(it => it.SubTotal) : 0.00M; // 住宿费
  13608. decimal mealsFeeTotal = _EnterExitCosts.ChoiceFour == 1 ? _DayAndCosts.Where(it => it.Type == 2).Sum(it => it.SubTotal) : 0.00M; // 伙食费费
  13609. decimal miscellaneousFeeTotal = _EnterExitCosts.ChoiceFive == 1 ? _DayAndCosts.Where(it => it.Type == 3).Sum(it => it.SubTotal) : 0.00M; // 公杂费
  13610. decimal tainFeeTotal = _EnterExitCosts.ChoiceSix == 1 ? _DayAndCosts.Where(it => it.Type == 4).Sum(it => it.SubTotal) : 0.00M; // 培训费
  13611. decimal otherPriceTotal = _EnterExitCosts.OtherExpenses_Checked == 1 ? dac5.Sum(x => x.SubTotal) : 0.00M; //其他费用
  13612. decimal insidePayTotal = _EnterExitCosts.ChoiceOne == 1 ? _EnterExitCosts.InsidePay : 0.00M;
  13613. //境内费用(其他费用)
  13614. if (_EnterExitCosts.ChoiceOne == 1)
  13615. {
  13616. string row1 = "";
  13617. if (_EnterExitCosts.Visa > 0)
  13618. {
  13619. //insidePayTotal += _EnterExitCosts.Visa;
  13620. row1 = $"签证费:{_EnterExitCosts.Visa:#0.00} 元/人\r\n";
  13621. //if (!string.IsNullOrEmpty(_EnterExitCosts.VisaRemark))
  13622. //{
  13623. // row1_1 += $"\t签证费用描述: {_EnterExitCosts.VisaRemark} 人民币/人";
  13624. //}
  13625. }
  13626. if (_EnterExitCosts.YiMiao > 0)
  13627. {
  13628. //insidePayTotal += _EnterExitCosts.YiMiao;
  13629. row1 += $"疫苗费:{_EnterExitCosts.YiMiao:#0.00} 元/人\r\n";
  13630. }
  13631. if (_EnterExitCosts.HeSuan > 0)
  13632. {
  13633. //insidePayTotal += _EnterExitCosts.HeSuan;
  13634. row1 += $"核酸检测费:{_EnterExitCosts.HeSuan:#0.00} 元/人\r\n";
  13635. }
  13636. if (_EnterExitCosts.Service > 0)
  13637. {
  13638. //insidePayTotal += _EnterExitCosts.Service;
  13639. row1 += $"服务费:{_EnterExitCosts.Service:#0.00} 元/人\r\n";
  13640. }
  13641. if (_EnterExitCosts.Safe > 0)
  13642. {
  13643. //insidePayTotal += _EnterExitCosts.Safe;
  13644. row1 += $"保险费:{_EnterExitCosts.Safe:#0.00} 元/人\r\n";
  13645. }
  13646. if (_EnterExitCosts.Ticket > 0)
  13647. {
  13648. //insidePayTotal += _EnterExitCosts.Ticket;
  13649. row1 += $"参展门票:{_EnterExitCosts.Ticket:#0.00} 元/人\r\n";
  13650. }
  13651. row1 += $"备注:{_EnterExitCosts.FirstItemRemark}";
  13652. dic.Add("InsidePay", insidePayTotal.ToString("#0.00"));
  13653. dic.Add("Row1Str", row1);
  13654. }
  13655. var airTotalStr = new StringBuilder();
  13656. var airPriceStr = new StringBuilder();
  13657. var cityTrafficLabel = new StringBuilder();
  13658. //经济舱
  13659. if (_EnterExitCosts.SumJJC == 1)
  13660. {
  13661. airTotalStr.AppendFormat($"{_EnterExitCosts.OutsideJJPay:#0.00}元/人(经济舱)");
  13662. airPriceStr.AppendFormat($"{_EnterExitCosts.AirJJ:#0.00}元/人(经济舱)");
  13663. cityTrafficLabel.AppendFormat("经济舱:{0:#0.00} 元/人 ", _EnterExitCosts.CityTranffic);
  13664. }
  13665. //公务舱
  13666. if (_EnterExitCosts.SumGWC == 1)
  13667. {
  13668. airTotalStr.AppendFormat($"{_EnterExitCosts.OutsideGWPay:#0.00} 元/人(公务舱)");
  13669. airPriceStr.AppendFormat($"{_EnterExitCosts.AirGW:#0.00} 元/人(公务舱)");
  13670. cityTrafficLabel.AppendFormat("公务舱:{0:#0.00} 元/人 ", _EnterExitCosts.CityTranffic1);
  13671. }
  13672. //头等舱
  13673. if (_EnterExitCosts.SumTDC == 1)
  13674. {
  13675. airTotalStr.AppendFormat($"{_EnterExitCosts.OutsideTDPay:#0.00} 元/人(头等舱)");
  13676. airPriceStr.AppendFormat($"{_EnterExitCosts.AirTD:#0.00} 元/人(头等舱)");
  13677. cityTrafficLabel.AppendFormat("头等舱:{0:#0.00} 元/人 ", _EnterExitCosts.CityTranffic2);
  13678. }
  13679. //描述
  13680. var remarkLable = new StringBuilder();
  13681. //第二项描述
  13682. remarkLable.Append("备注:");
  13683. if (!string.IsNullOrEmpty(_EnterExitCosts.TwoItemRemark)) remarkLable.AppendFormat(_EnterExitCosts.TwoItemRemark);
  13684. //汇率描述
  13685. if (peiceItemCurrencyInfos.Any())
  13686. {
  13687. remarkLable.AppendLine();
  13688. remarkLable.AppendFormat("汇率描述:");
  13689. foreach (var item in peiceItemCurrencyInfos)
  13690. {
  13691. remarkLable.AppendFormat($"{item.CurrencyName}({item.CurrencyCode}):{item.Rate:#0.0000} ");
  13692. }
  13693. }
  13694. dic.Add("AirTotalStr", airTotalStr.ToString());
  13695. dic.Add("AirPriceStr", airPriceStr.ToString());
  13696. dic.Add("CityTranffic", cityTrafficLabel.ToString());
  13697. dic.Add("TwoItemRemark", remarkLable.ToString());
  13698. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  13699. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  13700. int table1Row = 0,
  13701. table2Row = 0,
  13702. table3Row = 0,
  13703. table4Row = 0,
  13704. table5Row = 0;
  13705. //住宿费
  13706. if (_EnterExitCosts.ChoiceThree == 1)
  13707. {
  13708. dic.Add("SubZS", stayFeeTotal.ToString("#0.00"));
  13709. table1Row = dac1.Count;
  13710. #region 填充word表格内容
  13711. for (int i = 0; i < dac1.Count; i++)
  13712. {
  13713. Grp_DayAndCost dac = dac1[i];
  13714. if (dac == null) continue;
  13715. builder.MoveToCell(0, i, 0, 0);
  13716. builder.Write("第" + dac.Days.ToString() + "晚:");
  13717. builder.MoveToCell(0, i, 1, 0);
  13718. //builder.Write(placeData.Find(it => it.Id == dac.NationalTravelFeeId)?.Country ?? "Unknown");
  13719. //builder.Write(dac.Place == null ? "" : dac.Place);
  13720. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  13721. builder.MoveToCell(0, i, 2, 0);
  13722. builder.Write("费用标准:");
  13723. string curr = "";
  13724. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  13725. if (currData != null)
  13726. {
  13727. curr = currData.Name;
  13728. }
  13729. builder.MoveToCell(0, i, 3, 0);
  13730. builder.Write(dac.Cost.ToString("#0.00") + curr);
  13731. builder.MoveToCell(0, i, 4, 0);
  13732. builder.Write("费用小计:");
  13733. builder.MoveToCell(0, i, 5, 0);
  13734. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  13735. }
  13736. #endregion
  13737. }
  13738. else dic.Add("SubZS", "0.00");
  13739. //删除多余行
  13740. while (table1 != null && table1.Rows.Count > table1Row)
  13741. {
  13742. table1.Rows.RemoveAt(table1Row);
  13743. }
  13744. //伙食费
  13745. Aspose.Words.Tables.Table table2 = allTables[1] as Aspose.Words.Tables.Table;
  13746. if (_EnterExitCosts.ChoiceFour == 1)
  13747. {
  13748. dic.Add("SubHS", mealsFeeTotal.ToString("#0.00"));
  13749. table2Row = dac2.Count;
  13750. #region 填充word表格内容
  13751. for (int i = 0; i < dac2.Count; i++)
  13752. {
  13753. Grp_DayAndCost dac = dac2[i];
  13754. if (dac == null) continue;
  13755. builder.MoveToCell(1, i, 0, 0);
  13756. builder.Write("第" + dac.Days.ToString() + "天:");
  13757. builder.MoveToCell(1, i, 1, 0);
  13758. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  13759. builder.MoveToCell(1, i, 2, 0);
  13760. builder.Write("费用标准:");
  13761. string curr = "";
  13762. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  13763. if (currData != null)
  13764. {
  13765. curr = currData.Name;
  13766. }
  13767. builder.MoveToCell(1, i, 3, 0);
  13768. builder.Write(dac.Cost.ToString("#0.00") + curr);
  13769. builder.MoveToCell(1, i, 4, 0);
  13770. builder.Write("费用小计:");
  13771. builder.MoveToCell(1, i, 5, 0);
  13772. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  13773. }
  13774. #endregion
  13775. }
  13776. else dic.Add("SubHS", "0.00");
  13777. //删除多余行
  13778. while (table2 != null && table2.Rows.Count > table2Row)
  13779. {
  13780. table2.Rows.RemoveAt(table2Row);
  13781. }
  13782. //公杂费
  13783. Aspose.Words.Tables.Table table3 = allTables[2] as Aspose.Words.Tables.Table;
  13784. if (_EnterExitCosts.ChoiceFive == 1)
  13785. {
  13786. dic.Add("SubGZF", miscellaneousFeeTotal.ToString("#0.00"));
  13787. table3Row = dac3.Count;
  13788. #region 填充word表格内容
  13789. for (int i = 0; i < dac3.Count; i++)
  13790. {
  13791. Grp_DayAndCost dac = dac3[i];
  13792. if (dac == null) continue;
  13793. builder.MoveToCell(2, i, 0, 0);
  13794. builder.Write("第" + dac.Days.ToString() + "天:");
  13795. builder.MoveToCell(2, i, 1, 0);
  13796. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  13797. builder.MoveToCell(2, i, 2, 0);
  13798. builder.Write("费用标准:");
  13799. string curr = "";
  13800. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  13801. if (currData != null)
  13802. {
  13803. curr = currData.Name;
  13804. }
  13805. builder.MoveToCell(2, i, 3, 0);
  13806. builder.Write(dac.Cost.ToString("#0.00") + curr);
  13807. builder.MoveToCell(2, i, 4, 0);
  13808. builder.Write("费用小计:");
  13809. builder.MoveToCell(2, i, 5, 0);
  13810. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  13811. }
  13812. //删除多余行
  13813. while (table3.Rows.Count > table3Row)
  13814. {
  13815. table3.Rows.RemoveAt(table3Row);
  13816. }
  13817. #endregion
  13818. }
  13819. else dic.Add("SubGZF", "0.00");
  13820. //删除多余行
  13821. while (table3 != null && table3.Rows.Count > table3Row)
  13822. {
  13823. table3.Rows.RemoveAt(table3Row);
  13824. }
  13825. //培训费
  13826. Aspose.Words.Tables.Table table4 = allTables[3] as Aspose.Words.Tables.Table;
  13827. if (_EnterExitCosts.ChoiceSix == 1)
  13828. {
  13829. string pxStr = $"六、培训费合计: {tainFeeTotal:#0.00} 元/人";
  13830. dic.Add("SubPX", pxStr);
  13831. table4Row = dac4.Count;
  13832. #region 填充word表格内容
  13833. for (int i = 0; i < dac4.Count; i++)
  13834. {
  13835. Grp_DayAndCost dac = dac4[i];
  13836. if (dac == null) continue;
  13837. builder.MoveToCell(3, i, 0, 0);
  13838. builder.Write("第" + dac.Days.ToString() + "天:");
  13839. builder.MoveToCell(3, i, 1, 0);
  13840. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  13841. builder.MoveToCell(3, i, 2, 0);
  13842. builder.Write("费用标准:");
  13843. string curr = "";
  13844. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  13845. if (currData != null)
  13846. {
  13847. curr = currData.Name;
  13848. }
  13849. builder.MoveToCell(3, i, 3, 0);
  13850. builder.Write(dac.Cost.ToString("#0.00") + curr);
  13851. builder.MoveToCell(3, i, 4, 0);
  13852. builder.Write("费用小计:");
  13853. builder.MoveToCell(3, i, 5, 0);
  13854. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  13855. }
  13856. #endregion
  13857. }
  13858. //else dic.Add("SubPX", $"六、培训费合计: 0.00 元/人");
  13859. //删除多余行
  13860. while (table4 != null && table4.Rows.Count > table4Row)
  13861. {
  13862. table4.Rows.RemoveAt(table4Row);
  13863. }
  13864. //其他费用
  13865. Aspose.Words.Tables.Table table5 = allTables[4] as Aspose.Words.Tables.Table;
  13866. if (_EnterExitCosts.OtherExpenses_Checked == 1)
  13867. {
  13868. string qtStr = $"七、其他费用合计: {otherPriceTotal:#0.00} 元/人";
  13869. dic.Add("titleQi", qtStr);
  13870. table5Row = dac5.Count;
  13871. #region 填充word表格内容
  13872. for (int i = 0; i < dac5.Count; i++)
  13873. {
  13874. var dac = dac5[i];
  13875. if (dac == null) continue;
  13876. builder.MoveToCell(4, i, 0, 0);
  13877. builder.Write("第" + dac.Index.ToString() + "项:");
  13878. builder.MoveToCell(4, i, 1, 0);
  13879. builder.Write(dac.itemName);
  13880. builder.MoveToCell(4, i, 2, 0);
  13881. builder.Write("费用标准:");
  13882. builder.MoveToCell(4, i, 3, 0);
  13883. builder.Write(dac.Cost.ToString("#0.00") + dac.CurrencyStr);
  13884. builder.MoveToCell(4, i, 4, 0);
  13885. builder.Write("费用小计:");
  13886. builder.MoveToCell(4, i, 5, 0);
  13887. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  13888. builder.MoveToCell(4, i, 6, 0);
  13889. builder.Write("备注:");
  13890. builder.MoveToCell(4, i, 7, 0);
  13891. builder.Write(dac.Remark);
  13892. }
  13893. #endregion
  13894. }
  13895. //else dic.Add("SubQT", "七、其他费用合计: 0 元/人");
  13896. //删除多余行
  13897. while (table5 != null && table5.Rows.Count > table5Row)
  13898. {
  13899. table5.Rows.RemoveAt(table5Row);
  13900. }
  13901. //加上其他费用
  13902. decimal otherFeeTotal = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + otherPriceTotal;
  13903. decimal subJJC = 0.00M,
  13904. subGWC = 0.00M,
  13905. subTDC = 0.00M;
  13906. //全部费用总计: 元 / 人(经济舱) 元 / 人(公务舱) 元 / 人(头等舱)
  13907. string totalLabel = string.Format("全部费用总计:");
  13908. //经济舱
  13909. if (_EnterExitCosts.SumJJC == 1)
  13910. {
  13911. subJJC = otherFeeTotal + _EnterExitCosts.OutsideJJPay;
  13912. totalLabel += $"{subJJC:#0.00} 元/人(经济舱)";
  13913. }
  13914. //公务舱
  13915. if (_EnterExitCosts.SumGWC == 1)
  13916. {
  13917. subGWC = otherFeeTotal + _EnterExitCosts.OutsideGWPay;
  13918. totalLabel += $"{subGWC:#0.00} 元/人(公务舱)";
  13919. }
  13920. //头等舱
  13921. if (_EnterExitCosts.SumTDC == 1)
  13922. {
  13923. subTDC = otherFeeTotal + _EnterExitCosts.OutsideTDPay;
  13924. totalLabel += $"{subTDC:#0.00} 元/人(头等舱)";
  13925. }
  13926. //TotalLabel
  13927. dic.Add("TotalLabel", totalLabel);
  13928. //dic.Add("SubJJC", subJJC.ToString("#0.00"));
  13929. //dic.Add("SubGWC", subGWC.ToString("#0.00"));
  13930. //dic.Add("SubTDC", subTDC.ToString("#0.00"));
  13931. #region 填充word模板书签内容
  13932. foreach (var key in dic.Keys)
  13933. {
  13934. Bookmark bookmark = doc.Range.Bookmarks[key];
  13935. if (bookmark != null)
  13936. {
  13937. builder.MoveToBookmark(key);
  13938. builder.Write(dic[key]);
  13939. }
  13940. }
  13941. #endregion
  13942. #region 设置页眉
  13943. string userLabel = string.Empty;
  13944. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  13945. if (currUserInfo != null)
  13946. {
  13947. var userInfo = await _usersRep.GetUserBriefInfo(currUserInfo.UserId);
  13948. if (userInfo != null)
  13949. {
  13950. string ext = string.IsNullOrEmpty(userInfo.ExtensionNumber) ? "-" : userInfo.ExtensionNumber;
  13951. //userLabel = $"联系人:{userInfo.Name} 职位:{userInfo.Job}\r\n座机/分机号:{ext} 手机号:{userInfo.Tel} 公司邮箱:{userInfo.Email}";
  13952. userLabel = $"联系人:{userInfo.Name} 职 位:{userInfo.Job} 手机号:{userInfo.Tel}\r\n公司邮箱:{userInfo.Email}";
  13953. }
  13954. }
  13955. //设置页脚
  13956. //GeneralMethod.AsposeWordSetFooter(builder, userLabel, "华文仿宋", 10);
  13957. #endregion
  13958. var guid = CommonFun.GUID.Substring(0, 8);
  13959. //文件名
  13960. string strFileName = CommonFun.ValidFileName($"{_DelegationInfo.TeamName}出入境费用{guid}.docx");
  13961. AsposeHelper.removewatermark_v2180();
  13962. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  13963. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  13964. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  13965. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  13966. }
  13967. else if (dto.SubTypeId == 1006)//1006(因公出国(境)经费测算明细表)
  13968. {
  13969. //获取模板
  13970. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/因公出国(境)经费测算明细表.docx");
  13971. //载入模板
  13972. var doc = new Document(tempPath);
  13973. var builder = new DocumentBuilder(doc);
  13974. var dic = new Dictionary<string, string>();
  13975. if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  13976. {
  13977. var list = new List<string>();
  13978. try
  13979. {
  13980. var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  13981. foreach (var item in spilitArr)
  13982. {
  13983. var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  13984. var depCode = spDotandEmpty[2].Substring(0, 3);
  13985. var arrCode = spDotandEmpty[2].Substring(3, 3);
  13986. string depName = threeCodes.Find(it => it.Three.Equals(depCode)).City,
  13987. arrName = threeCodes.Find(it => it.Three.Equals(arrCode)).City;
  13988. list.Add(depName);
  13989. list.Add(arrName);
  13990. }
  13991. list = list.Distinct().ToList();
  13992. dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  13993. }
  13994. catch (Exception)
  13995. {
  13996. dic.Add("ReturnCode", "行程录入不正确!");
  13997. }
  13998. }
  13999. else
  14000. {
  14001. dic.Add("ReturnCode", "未录入行程!");
  14002. }
  14003. dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  14004. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  14005. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  14006. if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  14007. {
  14008. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  14009. dic.Add("Day", sp.Days.ToString());
  14010. }
  14011. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  14012. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  14013. //var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  14014. //dic.Add("Names", Names);
  14015. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  14016. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  14017. decimal dac1totalPrice = 0.00M;
  14018. int accommodationStartIndex = 6, foodandotherStartIndex = 22;
  14019. foreach (var dac in dac1)
  14020. {
  14021. if (dac.SubTotal == 0.00M)
  14022. {
  14023. continue;
  14024. }
  14025. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  14026. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  14027. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  14028. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  14029. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  14030. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  14031. builder.Write(currency);//币种
  14032. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  14033. builder.Write(dac.Cost.ToString("#0.00"));//标准
  14034. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  14035. builder.Write("");//人数
  14036. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  14037. builder.Write("");//天数
  14038. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  14039. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  14040. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  14041. decimal rate = 0.00M;
  14042. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  14043. builder.Write(rate.ToString("#0.0000"));//汇率
  14044. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  14045. decimal rbmPrice = dac.SubTotal;
  14046. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  14047. accommodationStartIndex++;
  14048. dac1totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  14049. }
  14050. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  14051. for (int i = 21; i > (dac1.Count == 0 ? 1 : dac1.Count) + 6; i--)
  14052. {
  14053. table1.Rows.RemoveAt(i - 1);
  14054. foodandotherStartIndex--;
  14055. }
  14056. if (dac2.Count == dac3.Count)//国家 币种 金额
  14057. {
  14058. for (int i = 0; i < dac2.Count; i++)
  14059. {
  14060. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  14061. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  14062. }
  14063. }
  14064. decimal dac2totalPrice = 0.00M;
  14065. foreach (var dac in dac2)
  14066. {
  14067. if (dac.SubTotal == 0)
  14068. {
  14069. continue;
  14070. }
  14071. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  14072. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  14073. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  14074. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  14075. builder.Write(currency);//币种
  14076. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  14077. builder.Write(dac.Cost.ToString("#0.00"));//标准
  14078. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  14079. builder.Write("");//人数
  14080. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  14081. builder.Write("");//天数
  14082. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  14083. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  14084. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  14085. decimal rate = 0.00M;
  14086. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  14087. builder.Write(rate.ToString("#0.0000"));//汇率
  14088. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  14089. decimal rbmPrice = dac.SubTotal;
  14090. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  14091. foodandotherStartIndex++;
  14092. dac2totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  14093. }
  14094. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  14095. for (int i = foodandotherStartIndex + (15 - dac2.Count); i > (dac2.Count == 0 ? 1 : 0) + foodandotherStartIndex; i--)
  14096. {
  14097. table1.Rows.RemoveAt(i - 1);
  14098. }
  14099. var cityTrafficLabel = new StringBuilder()
  14100. .AppendFormat(" 经济舱:{0:#0.00} 元", _EnterExitCosts.CityTranffic)
  14101. .AppendFormat(" 公务舱:{0:#0.00} 元", _EnterExitCosts.CityTranffic1)
  14102. .AppendFormat(" 头等舱:{0:#0.00} ", _EnterExitCosts.CityTranffic2)
  14103. .ToString();
  14104. dic.Add("CityTranffic", cityTrafficLabel);
  14105. string otherFeeStr = "";
  14106. if (_EnterExitCosts.Visa > 0) otherFeeStr += $"签证费:{_EnterExitCosts.Visa:#0.00} 元,";
  14107. if (_EnterExitCosts.Safe > 0) otherFeeStr += $"保险费:{_EnterExitCosts.Safe:#0.00} 元,";
  14108. if (_EnterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费:{_EnterExitCosts.Ticket:#0.00} 元,";
  14109. #region 其他款项费用 增加位置:模板第6项其他费用字符串追加
  14110. foreach (var otherInfo in dac5)
  14111. {
  14112. otherFeeStr += $"{otherInfo.itemName}:{otherInfo.SubTotal.ToString("#0.00")} 元,";
  14113. }
  14114. #endregion
  14115. if (otherFeeStr.Length > 0)
  14116. {
  14117. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  14118. otherFeeStr = $"({otherFeeStr})";
  14119. dic.Add("OtherFeeStr", otherFeeStr);
  14120. }
  14121. //总计
  14122. decimal allPrice = dac1totalPrice + dac2totalPrice + _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket;
  14123. //国际旅费
  14124. string outsideAir = string.Empty;
  14125. string allPriceAir = string.Empty;
  14126. if (_EnterExitCosts.SumJJC == 1)
  14127. {
  14128. outsideAir += string.Format(@"经济舱:{0} 元/人;", _EnterExitCosts.AirJJ.ToString("#0.00"));
  14129. allPriceAir += string.Format(@"经济舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideJJPay).ToString("#0.00"));
  14130. }
  14131. if (_EnterExitCosts.SumGWC == 1)
  14132. {
  14133. outsideAir += string.Format(@"公务舱:{0} 元/人;", _EnterExitCosts.AirGW.ToString("#0.00"));
  14134. allPriceAir += string.Format(@"公务舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  14135. }
  14136. if (_EnterExitCosts.SumTDC == 1)
  14137. {
  14138. outsideAir += string.Format(@"头等舱:{0} 元/人;", _EnterExitCosts.AirTD.ToString("#0.00"));
  14139. allPriceAir += string.Format(@"头等舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideTDPay).ToString("#0.00"));
  14140. }
  14141. dic.Add("InTravelPrice", $"({outsideAir})");
  14142. dic.Add("FinalSumPrice", $"({allPriceAir})");
  14143. //dic.Add("VisaPay", _EnterExitCosts.Visa.ToString("#0.00"));
  14144. //dic.Add("SafePay", _EnterExitCosts.Safe.ToString("#0.00"));
  14145. //dic.Add("YiMiao", _EnterExitCosts.YiMiao.ToString("#0.00"));
  14146. foreach (var key in dic.Keys)
  14147. {
  14148. builder.MoveToBookmark(key);
  14149. builder.Write(dic[key]);
  14150. }
  14151. //模板文件名
  14152. string strFileName = $"{_DelegationInfo.TeamName}因公出国(境)经费测算明细表{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
  14153. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  14154. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  14155. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  14156. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  14157. }
  14158. else if (dto.SubTypeId == 1007) //1007(四川省商务厅出国经费财政先行审核表)
  14159. {
  14160. //获取模板
  14161. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/四川省商务厅出国经费财政先行审核表.xls");
  14162. //载入模板
  14163. var designer = new WorkbookDesigner
  14164. {
  14165. Workbook = new Workbook(tempPath)
  14166. };
  14167. var dic = new Dictionary<string, string>();
  14168. if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  14169. {
  14170. var list = new List<string>();
  14171. try
  14172. {
  14173. var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  14174. foreach (var item in spilitArr)
  14175. {
  14176. var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  14177. var depCode = spDotandEmpty[2].Substring(0, 3);
  14178. var arrCode = spDotandEmpty[2].Substring(3, 3);
  14179. string depName = threeCodes.Find(it => it.Three.Equals(depCode))?.City ?? "Unknwon",
  14180. arrName = threeCodes.Find(it => it.Three.Equals(arrCode))?.City ?? "Unknown";
  14181. list.Add(depName);
  14182. list.Add(arrName);
  14183. }
  14184. list = list.Distinct().ToList();
  14185. dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  14186. }
  14187. catch (Exception)
  14188. {
  14189. dic.Add("ReturnCode", "行程录入不正确!");
  14190. }
  14191. }
  14192. else
  14193. {
  14194. dic.Add("ReturnCode", "未录入行程!");
  14195. }
  14196. dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  14197. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  14198. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  14199. if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  14200. {
  14201. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  14202. dic.Add("Day", sp.Days.ToString());
  14203. }
  14204. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  14205. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  14206. var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  14207. designer.SetDataSource("ClientUnit", _DelegationInfo.ClientUnit);
  14208. designer.SetDataSource("VisitCountry", _DelegationInfo.VisitCountry);
  14209. designer.SetDataSource("Group", _DelegationInfo.TeamName);
  14210. designer.SetDataSource("ClientUnitTitle", _DelegationInfo.TeamName);
  14211. designer.SetDataSource("Name", Names);
  14212. designer.SetDataSource("VisitStartDate", dic["VisitStartDate"] + "-" + dic["VisitEndDate"]);
  14213. designer.SetDataSource("Day", dic["Day"] + "天");
  14214. designer.SetDataSource("ReturnCode", dic["ReturnCode"]);
  14215. designer.SetDataSource("ReturnCodeAir", dic["ReturnCodeAir"]);
  14216. int startIndex = 10;
  14217. const int startIndexcopy = 10;
  14218. if (dac2.Count == dac3.Count)//国家 币种 金额
  14219. {
  14220. for (int i = 0; i < dac2.Count; i++)
  14221. {
  14222. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  14223. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  14224. }
  14225. }
  14226. var dtdac1 = new DataTable();
  14227. var place = new List<string>();
  14228. dtdac1.Columns.AddRange(new DataColumn[] {
  14229. new(){ ColumnName = "city"},
  14230. new(){ ColumnName = "curr"},
  14231. new(){ ColumnName = "criterion"},
  14232. new(){ ColumnName = "number",DataType = typeof(int)},
  14233. new(){ ColumnName = "day",DataType = typeof(int)},
  14234. new(){ ColumnName = "cost", DataType = typeof(decimal)},
  14235. new(){ ColumnName = "rate", DataType = typeof(decimal) },
  14236. new(){ ColumnName = "costRMB", DataType = typeof(decimal) },
  14237. });
  14238. var dtdac2 = new DataTable();
  14239. dtdac2.Columns.AddRange(new DataColumn[] {
  14240. new(){ ColumnName = "city"},
  14241. new(){ ColumnName = "curr"},
  14242. new(){ ColumnName = "criterion"},
  14243. new(){ ColumnName = "number",DataType = typeof(int)},
  14244. new(){ ColumnName = "day",DataType = typeof(int)},
  14245. new(){ ColumnName = "cost", DataType = typeof(decimal)},
  14246. new(){ ColumnName = "rate", DataType = typeof(decimal) },
  14247. new(){ ColumnName = "costRMB",DataType = typeof(decimal)},
  14248. });
  14249. dtdac1.TableName = "tb1";
  14250. dtdac2.TableName = "tb2";
  14251. decimal dac1totalPrice = 0.00M, dac2totalPrice = 0.00M;
  14252. foreach (var item in dac1)
  14253. {
  14254. item.Place = GetEnterExitCostExportCity(placeData, item.NationalTravelFeeId);
  14255. if (place.Contains(item.Place))
  14256. {
  14257. continue;
  14258. }
  14259. DataRow row = dtdac1.NewRow();
  14260. row["city"] = item.Place;
  14261. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  14262. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  14263. row["curr"] = currency;
  14264. row["rate"] = rate.ToString("#0.0000");
  14265. row["criterion"] = item.Cost.ToString("#0.00");
  14266. row["number"] = 1;
  14267. row["day"] = dac1.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  14268. //row["costRMB"] = rbmPrice;
  14269. dtdac1.Rows.Add(row);
  14270. place.Add(item.Place);
  14271. }
  14272. place = new List<string>();
  14273. foreach (var item in dac2)
  14274. {
  14275. item.Place = GetEnterExitCostExportCity(placeData, item.NationalTravelFeeId);
  14276. if (place.Contains(item.Place))
  14277. {
  14278. continue;
  14279. }
  14280. DataRow row = dtdac2.NewRow();
  14281. row["city"] = item.Place;
  14282. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  14283. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  14284. row["curr"] = currency;
  14285. row["rate"] = rate.ToString("#0.0000");
  14286. row["criterion"] = item.Cost.ToString("#0.00");
  14287. row["number"] = 1;
  14288. row["day"] = dac2.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  14289. //row["cost"] = item.SubTotal;
  14290. //row["costRMB"] = rbmPrice;
  14291. dtdac2.Rows.Add(row);
  14292. place.Add(item.Place);
  14293. //dac2totalPrice += rbmPrice;
  14294. }
  14295. dac1totalPrice = dac1.Sum(it => it.SubTotal);
  14296. dac2totalPrice = dac2.Sum(it => it.SubTotal);
  14297. designer.SetDataSource("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  14298. designer.SetDataSource("dac2totalPrice", dac2totalPrice);
  14299. var cityTrafficLabel = new StringBuilder()
  14300. .AppendFormat(" 其中:国外城市间")
  14301. .AppendFormat(" 经济舱费:{0:#0.00} 元、", _EnterExitCosts.CityTranffic)
  14302. .AppendFormat(" 公务舱费:{0:#0.00} 元、", _EnterExitCosts.CityTranffic1)
  14303. .AppendFormat(" 头等舱费:{0:#0.00} 元", _EnterExitCosts.CityTranffic2)
  14304. .ToString();
  14305. //decimal cityTraffic =_EnterExitCosts.CityTranffic + _EnterExitCosts.CityTranffic1 + _EnterExitCosts.CityTranffic2;
  14306. designer.SetDataSource("cityTranffic", cityTrafficLabel);
  14307. // designer.SetDataSource("sumCityTranffic", @$"{cityTraffic:#0.00} ");
  14308. string cell4Str1 = string.Empty;
  14309. if (_EnterExitCosts.SumJJC == 1) cell4Str1 += $"经济舱:{_EnterExitCosts.AirJJ:#0.00} 元/人;";
  14310. if (_EnterExitCosts.SumGWC == 1) cell4Str1 += $"公务舱:{_EnterExitCosts.AirGW:#0.00} 元/人;";
  14311. if (_EnterExitCosts.SumTDC == 1) cell4Str1 += $"公务舱:{_EnterExitCosts.AirTD:#0.00} 元/人;";
  14312. string cell4Str = $" 4.国际旅费:{cell4Str1}";
  14313. string cellStr = $" 5.其他费用(";
  14314. if (_EnterExitCosts.Visa > 0) cellStr += $"签证费:{_EnterExitCosts.Visa:#0.00}元,";
  14315. if (_EnterExitCosts.YiMiao > 0) cellStr += $"疫苗费:{_EnterExitCosts.YiMiao:#0.00}元,";
  14316. if (_EnterExitCosts.HeSuan > 0) cellStr += $"核酸费:{_EnterExitCosts.HeSuan:#0.00}元,";
  14317. if (_EnterExitCosts.Safe > 0) cellStr += $"保险费:{_EnterExitCosts.Safe:#0.00}元,";
  14318. if (_EnterExitCosts.Ticket > 0) cellStr += $"参展门票费:{_EnterExitCosts.Ticket:#0.00}元,";
  14319. if (_EnterExitCosts.Service > 0) cellStr += $"服务费:{_EnterExitCosts.Service:#0.00}元,";
  14320. #region 其他款项费用 增加位置:模板第5项其他费用字符串追加
  14321. var otherPriceTotal = dac5.Sum(x => x.SubTotal);
  14322. foreach (var otherInfo in dac5)
  14323. {
  14324. cellStr += $"{otherInfo.itemName}:{otherInfo.SubTotal.ToString("#0.00")} 元,";
  14325. }
  14326. #endregion
  14327. if (cellStr.Length > 8)
  14328. {
  14329. cellStr = cellStr.Substring(0, cellStr.Length - 1);
  14330. }
  14331. cellStr += ")";
  14332. decimal otherFee = _EnterExitCosts.Visa + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.Service + otherPriceTotal;
  14333. decimal s = dac1totalPrice + dac2totalPrice + _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay + otherFee;
  14334. decimal pxFee = dac4.Sum(it => it.Cost);
  14335. decimal glvFee = _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay;
  14336. string celllastStr1 = "";
  14337. if (dac1totalPrice > 0) celllastStr1 += $"住宿费 {dac1totalPrice:#0.00} 元";
  14338. if (dac2totalPrice > 0) celllastStr1 += $",伙食费和公杂费 {dac2totalPrice:#0.00} 元";
  14339. if (pxFee > 0) celllastStr1 += $",培训费 {pxFee:#0.00} 元";
  14340. celllastStr1 += $",国际旅费 元";
  14341. if (otherFee > 0) celllastStr1 += $",其他费用 {otherFee:#0.00} 元";
  14342. string celllastStr = $" 经审核,{celllastStr1},本次出国经费预算合计为 元。其中:市本级安排 。";
  14343. designer.SetDataSource("cell4Str", cell4Str);
  14344. designer.SetDataSource("cellStr", cellStr);
  14345. designer.SetDataSource("cellSum", otherFee.ToString("#0.00"));
  14346. designer.SetDataSource("cellSum4", (_EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  14347. designer.SetDataSource("celllastStr", celllastStr);
  14348. Workbook wb = designer.Workbook;
  14349. var sheet = wb.Worksheets[0];
  14350. //绑定datatable数据集
  14351. designer.SetDataSource(dtdac1);
  14352. designer.SetDataSource(dtdac2);
  14353. designer.Process();
  14354. var rowStart = dtdac1.Rows.Count;
  14355. while (rowStart > 0)
  14356. {
  14357. sheet.Cells[startIndex, 8].Formula = $"=G{startIndex + 1} * H{startIndex + 1}";
  14358. sheet.Cells[startIndex, 6].Formula = $"=E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  14359. startIndex++;
  14360. rowStart--;
  14361. }
  14362. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + 1}: I{startIndex})";
  14363. startIndex += 1; //总计行
  14364. rowStart = dtdac2.Rows.Count;
  14365. while (rowStart > 0)
  14366. {
  14367. sheet.Cells[startIndex, 8].Formula = $"= G{startIndex + 1} * H{startIndex + 1}";
  14368. sheet.Cells[startIndex, 6].Formula = $"= E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  14369. startIndex++;
  14370. rowStart--;
  14371. }
  14372. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + dtdac1.Rows.Count + 2}: I{startIndex})";
  14373. wb.CalculateFormula(true);
  14374. //模板文件名
  14375. string strFileName = $"{_DelegationInfo.TeamName}-四川省商务厅出国经费财政先行审核表{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  14376. designer.Workbook.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  14377. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  14378. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  14379. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  14380. }
  14381. else if (dto.SubTypeId == 1066) //成都市因公临时出国任务和预算审批意见表(外专培训团专用)
  14382. {
  14383. //获取模板
  14384. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/成都市因公临时出国任务和预算审批意见表.docx");
  14385. //载入模板
  14386. var doc = new Document(tempPath);
  14387. var builder = new DocumentBuilder(doc);
  14388. var dic = new Dictionary<string, string>
  14389. {
  14390. { "GroupName", _DelegationInfo.TeamName },
  14391. { "ClientUnit", _DelegationInfo.ClientUnit }
  14392. };
  14393. string missionLeader = ""; //团负责人默认接团客户名单第一个人
  14394. string missionLeaderJob = "";//负责人job
  14395. //int groupNumber = 0; //团人数
  14396. if (DeleClientList.Count > 0)
  14397. {
  14398. missionLeader = DeleClientList[0]?.Name ?? "";
  14399. missionLeaderJob = DeleClientList[0]?.Job ?? "";
  14400. }
  14401. dic.Add("MissionLeader", missionLeader); //团负责人
  14402. dic.Add("MissionLeaderJob", missionLeaderJob); //团负责人job
  14403. dic.Add("GroupNumber", _DelegationInfo.VisitPNumber.ToString()); //团人数
  14404. #region MyRegion
  14405. //if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  14406. //{
  14407. // List<string> list = new List<string>();
  14408. // try
  14409. // {
  14410. // var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  14411. // foreach (var item in spilitArr)
  14412. // {
  14413. // var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  14414. // var depCode = spDotandEmpty[2].Substring(0, 3);
  14415. // var arrCode = spDotandEmpty[2].Substring(3, 3);
  14416. // string depName = threeCodes.Find(it => it.Three.Equals(depCode)).City,
  14417. // arrName = threeCodes.Find(it => it.Three.Equals(arrCode)).City;
  14418. // list.Add(depName);
  14419. // list.Add(arrName);
  14420. // }
  14421. // list = list.Distinct().ToList();
  14422. // dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  14423. // }
  14424. // catch (Exception)
  14425. // {
  14426. // dic.Add("ReturnCode", "行程录入不正确!");
  14427. // }
  14428. //}
  14429. //else
  14430. //{
  14431. // dic.Add("ReturnCode", "未录入行程!");
  14432. //}
  14433. List<string> countrys = _groupRepository.GroupSplitCountry(_DelegationInfo.VisitCountry);
  14434. dic.Add("ReturnCode", string.Join("、", countrys));
  14435. #endregion
  14436. //dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  14437. //dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  14438. //dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  14439. //if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  14440. //{
  14441. // TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  14442. // dic.Add("Day", sp.Days.ToString());
  14443. //}
  14444. dic.Add("Day", _DelegationInfo.VisitDays.ToString());
  14445. dic.Add("CultivateDay", dac4.Count.ToString()); //培训天数
  14446. // dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  14447. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  14448. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  14449. //培训人员名单
  14450. int cultivateRowIndex = 7;
  14451. foreach (var item in DeleClientList)
  14452. {
  14453. builder.MoveToCell(0, cultivateRowIndex, 0, 0);
  14454. builder.Write(item.Name);
  14455. builder.MoveToCell(0, cultivateRowIndex, 1, 0);
  14456. builder.Write(item.Sex == 0 ? "男" : item.Sex == 1 ? "女" : "");
  14457. builder.MoveToCell(0, cultivateRowIndex, 2, 0);
  14458. string birthDay = "";
  14459. if (item.Birthday != null)
  14460. {
  14461. DateTime dt = Convert.ToDateTime(item.Birthday);
  14462. birthDay = $"{dt.Year}.{dt.Month}";
  14463. }
  14464. builder.Write(birthDay);
  14465. builder.MoveToCell(0, cultivateRowIndex, 3, 0);
  14466. builder.Write(item.Company);
  14467. builder.MoveToCell(0, cultivateRowIndex, 4, 0);
  14468. builder.Write(item.Job);
  14469. cultivateRowIndex++;
  14470. }
  14471. //删除多余行
  14472. //cultivateRowIndex -= 2;
  14473. int delRows = 10 + 7 - cultivateRowIndex;
  14474. if (delRows > 0)
  14475. {
  14476. for (int i = 0; i < delRows; i++)
  14477. {
  14478. table1.Rows.RemoveAt(cultivateRowIndex);
  14479. //cultivateRowIndex++;
  14480. }
  14481. }
  14482. decimal hotelFeeTotal = dac1.Sum(it => it.SubTotal);//住宿费
  14483. dic.Add("HotelFeeTotal", hotelFeeTotal.ToString("#0.00"));
  14484. decimal mealsFeeTotal = dac2.Sum(it => it.SubTotal);//伙食费
  14485. dic.Add("MealsFeeTotal", mealsFeeTotal.ToString("#0.00"));
  14486. decimal miscellaneousFeeTotal = dac3.Sum(it => it.SubTotal);//公杂费
  14487. dic.Add("MiscellaneousFeeTotal", miscellaneousFeeTotal.ToString("#0.00"));
  14488. decimal trainingFeeTotal = dac4.Sum(it => it.SubTotal);//培训费
  14489. dic.Add("TrainingFeeTotal", trainingFeeTotal.ToString("#0.00"));
  14490. //decimal cityTranfficFeeToatal = _EnterExitCosts.CityTranffic; //城市区间交通费
  14491. decimal cityTranfficFeeToatal = 0.00M;
  14492. //dic.Add("CityTranfficFeeToatal", cityTranfficFeeToatal.ToString("#0.00"));
  14493. //其他费用
  14494. decimal otherFeeTotal = _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Service + dac5.Sum(x => x.SubTotal);
  14495. dic.Add("OtherFeeTotal", otherFeeTotal.ToString("#0.00"));
  14496. //其他费用合计
  14497. decimal _otherFeeTotal = hotelFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + trainingFeeTotal + cityTranfficFeeToatal + otherFeeTotal;
  14498. decimal _jjcFeeToatal = _EnterExitCosts.OutsideJJPay + _otherFeeTotal; //经济舱
  14499. decimal _gwcFeeToatal = _EnterExitCosts.OutsideGWPay + _otherFeeTotal; //公务舱
  14500. //公务舱合计
  14501. //国际旅费
  14502. //string outsideJJ = "";
  14503. //string allPriceJJ = "";
  14504. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 0)
  14505. {
  14506. dic.Add("AirFeeTotal", _EnterExitCosts.OutsideJJPay.ToString("#0.00"));
  14507. dic.Add("FeeTotal", _jjcFeeToatal.ToString("#0.00"));
  14508. }
  14509. if (_EnterExitCosts.SumGWC == 1 && _EnterExitCosts.SumJJC == 0)
  14510. {
  14511. dic.Add("AirFeeTotal", _EnterExitCosts.OutsideGWPay.ToString("#0.00"));
  14512. dic.Add("FeeTotal", _gwcFeeToatal.ToString("#0.00"));
  14513. }
  14514. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 1)
  14515. {
  14516. string airFeeTotalStr = string.Format(@$"经济舱:{_EnterExitCosts.OutsideJJPay:#0.00} 公务舱:{_EnterExitCosts.OutsideGWPay:#0.00}");
  14517. dic.Add("AirFeeTotal", airFeeTotalStr);
  14518. string feeTotalStr = string.Format(@$"经济舱:{_jjcFeeToatal:#0.00} 公务舱:{_gwcFeeToatal:#0.00}");
  14519. dic.Add("FeeTotal", feeTotalStr);
  14520. }
  14521. foreach (var key in dic.Keys)
  14522. {
  14523. builder.MoveToBookmark(key);
  14524. builder.Write(dic[key]);
  14525. }
  14526. //模板文件名
  14527. string strFileName = $"{_DelegationInfo.TeamName}-成都市因公临时出国任务和预算审批意见表(外专培训团专用).docx";
  14528. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  14529. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  14530. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  14531. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  14532. }
  14533. }
  14534. else if (dto.ExportType == 2) //表格
  14535. {
  14536. //利用键值对存放数据
  14537. Dictionary<string, string> dic = new Dictionary<string, string>();
  14538. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  14539. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  14540. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  14541. dic.Add("Day", sp.Days.ToString());
  14542. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  14543. if (dto.SubTypeId == 1008) //1008(派员单位出(境)任务和预算审批意见表)
  14544. {
  14545. //获取模板
  14546. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/派员单位出(境)任务和预算审批意见表.docx");
  14547. //载入模板
  14548. var doc = new Document(tempPath);
  14549. var builder = new DocumentBuilder(doc);
  14550. dic.Add("TeamName", _DelegationInfo.TeamName);
  14551. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  14552. //dic.Add("TellPhone", _DelegationInfo.TellPhone);
  14553. string missionLeaderName = "",
  14554. missionLeaderJob = "";
  14555. if (DeleClientList.Count > 0)
  14556. {
  14557. missionLeaderName = DeleClientList[0].Name;
  14558. missionLeaderJob = DeleClientList[0].Job;
  14559. }
  14560. dic.Add("MissionLeaderName", missionLeaderName);
  14561. dic.Add("MissionLeaderJob", missionLeaderJob);
  14562. dic.Add("VisitPNumber", _DelegationInfo.VisitPNumber.ToString());
  14563. dic.Add("VisitPurpose", _DelegationInfo.VisitPurpose);
  14564. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  14565. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  14566. int rowCount = 10;//总人数行
  14567. int startRowIndex = 7; //起始行
  14568. for (int i = 0; i < DeleClientList.Count; i++)
  14569. {
  14570. builder.MoveToCell(0, startRowIndex, 0, 0);
  14571. builder.Write(DeleClientList[i].Name); //出国人员姓名
  14572. builder.MoveToCell(0, startRowIndex, 1, 0);
  14573. string sex = DeleClientList[i].Sex == 0 ? "男" : DeleClientList[i].Sex == 1 ? "女" : "";
  14574. builder.Write(sex);//性别
  14575. builder.MoveToCell(0, startRowIndex, 2, 0);
  14576. builder.Write(Convert.ToDateTime(DeleClientList[i].Birthday).ToString("yyyy年MM月dd日"));//出生年月
  14577. builder.MoveToCell(0, startRowIndex, 3, 0);
  14578. builder.Write(DeleClientList[i].Company);//工作单位
  14579. builder.MoveToCell(0, startRowIndex, 4, 0);
  14580. builder.Write(DeleClientList[i].Job);//职务及级别
  14581. builder.MoveToCell(0, startRowIndex, 5, 0);
  14582. builder.Write("");//人员属性
  14583. builder.MoveToCell(0, startRowIndex, 6, 0);
  14584. builder.Write("");//上次出国时间
  14585. startRowIndex++;
  14586. }
  14587. int nullRow = rowCount - DeleClientList.Count;//空行
  14588. for (int i = 0; i < nullRow; i++)
  14589. {
  14590. table1.Rows.Remove(table1.Rows[startRowIndex]);
  14591. }
  14592. foreach (var key in dic.Keys)
  14593. {
  14594. builder.MoveToBookmark(key);
  14595. builder.Write(dic[key]);
  14596. }
  14597. //模板文件名
  14598. string strFileName = $"派员单位出(境)任务和预算审批意见表.docx";
  14599. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  14600. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  14601. if (dto.PortType == 1) return Ok(JsonView(true, "成功", new { Url = url }));
  14602. else if (dto.PortType == 2 || dto.PortType == 3) return Ok(JsonView(true, "成功", url));
  14603. }
  14604. else if (dto.SubTypeId == 1009)//1009(省级单位出(境)经费报销单)
  14605. {
  14606. //获取模板
  14607. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/省级单位出(境)经费报销单.docx");
  14608. //载入模板
  14609. var doc = new Document(tempPath);
  14610. var builder = new DocumentBuilder(doc);
  14611. dic.Add("GroupClient", _DelegationInfo.ClientUnit);
  14612. var Names = string.Join("、", DeleClientList.Select(x => x.Name)).TrimEnd('、');
  14613. dic.Add("Names", Names);
  14614. int accommodationRows = 12;
  14615. //int foodandotherRows = 12;
  14616. var Dac1currCn = dac1.GroupBy(x => x.Currency).Select(x => x.Key).ToList();
  14617. var Dac2currCn = dac2.GroupBy(x => x.Currency).Select(x => x.Key).ToList();
  14618. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  14619. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  14620. int accommodationStartIndex = 6;
  14621. decimal dac1totalPrice = 0.00M;
  14622. foreach (var dac in dac1)
  14623. {
  14624. if (dac.SubTotal == 0)
  14625. {
  14626. continue;
  14627. }
  14628. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  14629. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  14630. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  14631. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));//城市
  14632. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  14633. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknwon";
  14634. builder.Write(currency);//币种
  14635. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  14636. builder.Write(dac.Cost.ToString("#0.00"));//标准
  14637. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  14638. builder.Write("");//人数
  14639. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  14640. builder.Write("");//天数
  14641. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  14642. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  14643. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  14644. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  14645. builder.Write(rate.ToString("#0.0000"));//汇率
  14646. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  14647. decimal rbmPrice = rate * dac.SubTotal;
  14648. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  14649. accommodationStartIndex++;
  14650. dac1totalPrice += rbmPrice;
  14651. }
  14652. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  14653. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  14654. builder.Write("小计");
  14655. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  14656. builder.Write(dac1totalPrice.ToString("#0.00"));
  14657. accommodationStartIndex++;
  14658. int nullRow = accommodationRows - dac1.Count;
  14659. //删除空行
  14660. //if (nullRow > 0)
  14661. //{
  14662. // int rowIndex = accommodationStartIndex;
  14663. // for (int i = 0; i < nullRow; i++)
  14664. // {
  14665. // Aspose.Words.Tables.Row row = table1.Rows[rowIndex];
  14666. // row.Remove();
  14667. // rowIndex++;
  14668. // }
  14669. //}
  14670. if (dac2.Count == dac3.Count)//国家 币种 金额
  14671. {
  14672. for (int i = 0; i < dac2.Count; i++)
  14673. {
  14674. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  14675. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  14676. }
  14677. }
  14678. int foodandotherStartIndex = 19;//
  14679. decimal dac2totalPrice = 0.00M;
  14680. foreach (var dac in dac2)
  14681. {
  14682. if (dac.SubTotal == 0)
  14683. {
  14684. continue;
  14685. }
  14686. //foodandotherStartIndex = 12;
  14687. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  14688. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));//城市
  14689. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  14690. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknwon";
  14691. builder.Write(currency);//币种
  14692. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  14693. builder.Write(dac.Cost.ToString("#0.00"));//标准
  14694. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  14695. builder.Write("");//人数
  14696. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  14697. builder.Write("");//天数
  14698. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  14699. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  14700. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  14701. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  14702. builder.Write(rate.ToString("#0.0000"));//汇率
  14703. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  14704. decimal rbmPrice = rate * dac.SubTotal;
  14705. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  14706. foodandotherStartIndex++;
  14707. dac2totalPrice += rbmPrice;
  14708. }
  14709. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  14710. Aspose.Words.Tables.Table table2 = allTables[1] as Aspose.Words.Tables.Table;
  14711. //删除空行
  14712. //if (dac2.Count < foodandotherRows)
  14713. //{
  14714. // while (table2.Rows.Count > dac2.Count)
  14715. // {
  14716. // table2.Rows.RemoveAt(dac2.Count);
  14717. // }
  14718. //}
  14719. var citytrafficLable = new StringBuilder()
  14720. .AppendFormat($"经济舱费用:{_EnterExitCosts.CityTranffic:#0.00} 元、")
  14721. .AppendFormat($"公务舱费用:{_EnterExitCosts.CityTranffic1:#0.00}元、")
  14722. .AppendFormat($"头等舱费用:{_EnterExitCosts.CityTranffic2:#0.00}")
  14723. .ToString();
  14724. dic.Add("CityTranffic", citytrafficLable);
  14725. string otherFeeStr = "";
  14726. if (_EnterExitCosts.Visa > 0) otherFeeStr += $"签证费:{_EnterExitCosts.Visa:#0.00}元,";
  14727. if (_EnterExitCosts.YiMiao > 0) otherFeeStr += $"疫苗费:{_EnterExitCosts.YiMiao:#0.00}元,";
  14728. if (_EnterExitCosts.HeSuan > 0) otherFeeStr += $"核酸费:{_EnterExitCosts.HeSuan:#0.00}元,";
  14729. if (_EnterExitCosts.Safe > 0) otherFeeStr += $"保险费:{_EnterExitCosts.Safe:#0.00}元,";
  14730. if (_EnterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费:{_EnterExitCosts.Ticket:#0.00}元,";
  14731. if (_EnterExitCosts.Service > 0) otherFeeStr += $"服务费:{_EnterExitCosts.Service:#0.00}元,";
  14732. #region 其他款项费用 增加位置:模板第6项其他费用字符串追加
  14733. foreach (var otherInfo in dac5)
  14734. {
  14735. otherFeeStr += $"{otherInfo.itemName}:{otherInfo.SubTotal:#0.00} 元,";
  14736. }
  14737. #endregion
  14738. if (otherFeeStr.Length > 0)
  14739. {
  14740. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  14741. otherFeeStr = $"({otherFeeStr})";
  14742. dic.Add("OtherFeeStr", otherFeeStr);
  14743. }
  14744. foreach (var key in dic.Keys)
  14745. {
  14746. builder.MoveToBookmark(key);
  14747. builder.Write(dic[key]);
  14748. }
  14749. //模板文件名
  14750. string strFileName = $"省级单位出(境)经费报销单{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
  14751. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  14752. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  14753. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  14754. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  14755. }
  14756. else if (dto.SubTypeId == 1538)// 1538 省级单位出国经费报销单
  14757. {
  14758. // 获取模板
  14759. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/省级单位出国经费报销单.xls");
  14760. // 载入模板
  14761. var designer = new WorkbookDesigner
  14762. {
  14763. Workbook = new Workbook(tempPath)
  14764. };
  14765. Workbook workbook = designer.Workbook;
  14766. var worksheet1 = workbook.Worksheets[0];
  14767. var worksheet2 = workbook.Worksheets[1];
  14768. var worksheet3 = workbook.Worksheets[2];
  14769. // 日期格式化
  14770. var dateFormat = "yyyy年MM月dd日";
  14771. designer.SetDataSource("DeptOffice", ""); // 处室
  14772. // 报销日期
  14773. var currDateStr = DateTime.Now.ToString(dateFormat);
  14774. designer.SetDataSource("ReimbDate", currDateStr);
  14775. designer.SetDataSource("GroupUnit", _DelegationInfo.ClientUnit); // 组团单位
  14776. // 出国人员姓名
  14777. var overseasName = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  14778. if (string.IsNullOrEmpty(overseasName)) overseasName = "-";
  14779. designer.SetDataSource("OverseasName", overseasName);
  14780. // 国家和地区(含经停)
  14781. string countryRegionStops = _groupRepository.FormartTeamName(_DelegationInfo.VisitCountry);
  14782. designer.SetDataSource("CountryRegionStops", countryRegionStops);
  14783. // 具体线路
  14784. string specificLine = "";
  14785. if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  14786. {
  14787. var list = new List<string>();
  14788. try
  14789. {
  14790. var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  14791. foreach (var item in spilitArr)
  14792. {
  14793. var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  14794. var depCode = spDotandEmpty[2].Substring(0, 3);
  14795. var arrCode = spDotandEmpty[2].Substring(3, 3);
  14796. string depName = threeCodes.Find(it => it.Three.Equals(depCode)).City;
  14797. string arrName = threeCodes.Find(it => it.Three.Equals(arrCode)).City;
  14798. list.Add(depName);
  14799. list.Add(arrName);
  14800. }
  14801. list = list.Distinct().ToList();
  14802. specificLine = string.Join("-", list);
  14803. }
  14804. catch (Exception)
  14805. {
  14806. specificLine = "行程录入不正确!";
  14807. }
  14808. }
  14809. else
  14810. {
  14811. specificLine = "未录入行程!";
  14812. }
  14813. designer.SetDataSource("SpecRoute", specificLine);
  14814. // 出国时间
  14815. string overseasTime = $"{_DelegationInfo.VisitStartDate.ToString(dateFormat)} - {_DelegationInfo.VisitEndDate.ToString(dateFormat)}";
  14816. designer.SetDataSource("OverseasTime", overseasTime);
  14817. // 实际天数
  14818. TimeSpan overseasActualDays_ts = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  14819. designer.SetDataSource("OverseasActualDays", $"{overseasActualDays_ts.Days}天");
  14820. // 数据整理
  14821. // 住宿费
  14822. var accomFees = dac1.GroupBy(x => x.NationalTravelFeeId)
  14823. .Select(group =>
  14824. {
  14825. var currData = group.FirstOrDefault();
  14826. // 币种信息
  14827. var currencyInfo = _CurrDatas.Where(x => x.Id == currData.Currency).FirstOrDefault();
  14828. // 币种名称
  14829. string currencyName = currencyInfo?.Remark ?? "";
  14830. // 币种Code
  14831. string currencyCode = currencyInfo?.Name ?? "";
  14832. // 币种汇率信息
  14833. var currencyRateInfo = enterExitCostCurrencys.Where(x => x.CurrencyName.Equals(currencyName)).FirstOrDefault();
  14834. // 币种汇率
  14835. decimal currencyRate = currencyRateInfo != null ? currencyRateInfo.Rate : 1.00M;
  14836. // 城市信息 Grp_NationalTravelFee
  14837. var placeName = GetEnterExitCostExportCity(placeData, group.Key);
  14838. // 天数
  14839. int totalDays = group.Count();
  14840. // 原始币种小计
  14841. decimal totalAmount = group.Sum(x => x.Cost);
  14842. // 人名币金额
  14843. decimal totalCNY = totalDays * totalAmount * currencyRate;
  14844. return new
  14845. {
  14846. TravelFeeId = group.Key,
  14847. PlaceName = placeName,
  14848. TotalDays = totalDays,
  14849. currData.Cost,
  14850. TotalAmount = totalAmount,
  14851. currData.Currency,
  14852. CurrencyCode = currencyCode,
  14853. CurrencyName = currencyName,
  14854. CurrencyRate = currencyRate,
  14855. TotalCNY = totalCNY,
  14856. Details = group.ToList()
  14857. };
  14858. })
  14859. .ToList();
  14860. // 伙食费和公杂费
  14861. var foodSundCosts = _DayAndCosts.Where(x => x.Type == 2 || x.Type == 3)
  14862. .GroupBy(x => x.NationalTravelFeeId)
  14863. .Select(group =>
  14864. {
  14865. var currData = group.FirstOrDefault();
  14866. // 币种信息
  14867. var currencyInfo = _CurrDatas.Where(x => x.Id == currData.Currency).FirstOrDefault();
  14868. // 币种名称
  14869. string currencyName = currencyInfo?.Remark ?? "";
  14870. // 币种Code
  14871. string currencyCode = currencyInfo?.Name ?? "";
  14872. // 币种汇率信息
  14873. var currencyRateInfo = enterExitCostCurrencys.Where(x => x.CurrencyName.Equals(currencyName)).FirstOrDefault();
  14874. // 币种汇率
  14875. decimal currencyRate = currencyRateInfo != null ? currencyRateInfo.Rate : 1.00M;
  14876. // 城市信息 Grp_NationalTravelFee
  14877. var placeName = GetEnterExitCostExportCity(placeData, group.Key);
  14878. // 天数
  14879. int totalDays = group.Count() / 2;
  14880. // 原始币种小计
  14881. decimal totalAmount = group.Sum(x => x.Cost);
  14882. // 原始伙食费、公杂费单价合计
  14883. decimal cost = totalAmount / totalDays;
  14884. // 人名币金额
  14885. decimal totalCNY = totalDays * totalAmount * currencyRate;
  14886. return new
  14887. {
  14888. TravelFeeId = group.Key,
  14889. PlaceName = placeName,
  14890. TotalDays = totalDays,
  14891. Cost = cost,
  14892. TotalAmount = totalAmount,
  14893. currData.Currency,
  14894. CurrencyCode = currencyCode,
  14895. CurrencyName = currencyName,
  14896. CurrencyRate = currencyRate,
  14897. TotalCNY = totalCNY,
  14898. Details = group.ToList()
  14899. };
  14900. })
  14901. .ToList();
  14902. // 其他费用
  14903. var otherFeestrs = new List<string>();
  14904. decimal totalOtherFee = 0.00M;
  14905. if (_EnterExitCosts.Visa > 0)
  14906. {
  14907. otherFeestrs.Add($"签证费:{_EnterExitCosts.Visa:#0.00}元/人");
  14908. totalOtherFee += _EnterExitCosts.Visa;
  14909. }
  14910. if (_EnterExitCosts.YiMiao > 0)
  14911. {
  14912. otherFeestrs.Add($"疫苗费:{_EnterExitCosts.YiMiao:#0.00}元/人");
  14913. totalOtherFee += _EnterExitCosts.YiMiao;
  14914. }
  14915. if (_EnterExitCosts.HeSuan > 0)
  14916. {
  14917. otherFeestrs.Add($"核酸费:{_EnterExitCosts.HeSuan:#0.00}元/人");
  14918. totalOtherFee += _EnterExitCosts.HeSuan;
  14919. }
  14920. if (_EnterExitCosts.Safe > 0)
  14921. {
  14922. otherFeestrs.Add($"保险费:{_EnterExitCosts.Safe:#0.00}元/人");
  14923. totalOtherFee += _EnterExitCosts.Safe;
  14924. }
  14925. if (_EnterExitCosts.Ticket > 0)
  14926. {
  14927. otherFeestrs.Add($"参展门票费:{_EnterExitCosts.Ticket:#0.00}元/人");
  14928. totalOtherFee += _EnterExitCosts.Ticket;
  14929. }
  14930. if (_EnterExitCosts.Service > 0)
  14931. {
  14932. otherFeestrs.Add($"服务费:{_EnterExitCosts.Service:#0.00}元/人");
  14933. totalOtherFee += _EnterExitCosts.Service;
  14934. }
  14935. #region 其他款项费用 增加位置:模板第5项其他费用字符串追加
  14936. var otherPriceTotal = dac5.Sum(x => x.SubTotal);
  14937. foreach (var otherInfo in dac5)
  14938. {
  14939. otherFeestrs.Add($"{otherInfo.itemName}:{otherInfo.SubTotal:#0.00}元/人");
  14940. totalOtherFee += otherInfo.SubTotal;
  14941. }
  14942. #endregion
  14943. designer.SetDataSource("TotalOtherFeeLabel", $"5.其他费用({string.Join(";", otherFeestrs)})");
  14944. designer.SetDataSource("TotalOtherFee", $"{totalOtherFee:0.00}");
  14945. // 住宿费、伙食费和公杂费合计
  14946. decimal grandTotalFee = foodSundCosts.Sum(x => x.TotalCNY) + foodSundCosts.Sum(x => x.TotalCNY);
  14947. //其他费用合计
  14948. decimal otherFee = _EnterExitCosts.Visa + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.Service + otherPriceTotal;
  14949. // 国际旅行费 - 经济舱
  14950. var cellLabel4_jjc = new StringBuilder()
  14951. .AppendFormat($"4.国际旅费(经济舱:{_EnterExitCosts.AirJJ:0.00}/人;城市间交通费:{_EnterExitCosts.CityTranffic:0.00}元/人)")
  14952. .ToString();
  14953. decimal totalAirJJC = _EnterExitCosts.AirJJ + _EnterExitCosts.CityTranffic;
  14954. designer.SetDataSource("TotalAirLabel_JJC", cellLabel4_jjc);
  14955. designer.SetDataSource("TotalAir_JJC", $"{totalAirJJC:#0.00}");
  14956. decimal totalPrice_jjc = grandTotalFee + totalAirJJC + totalOtherFee;
  14957. designer.SetDataSource("TotalFeeLabel_JJC", $"大写 :{CommonFun.ToChinese(totalPrice_jjc)}整"); // 合计金额中文大写
  14958. designer.SetDataSource("TotalFee_JJC", $"{totalPrice_jjc:0.00}"); // 合计金额
  14959. designer.SetDataSource("ActualAmount_JJC", $"{totalPrice_jjc:0.00}元"); // 合计金额
  14960. // 国际旅行费 - 公务舱
  14961. var cellLabel4_gwc = new StringBuilder()
  14962. .AppendFormat($"4.国际旅费(公务舱:{_EnterExitCosts.AirGW:0.00}/人;城市间交通费:{_EnterExitCosts.CityTranffic1:0.00}元/人)")
  14963. .ToString();
  14964. decimal totalAir_gwc = _EnterExitCosts.AirGW + _EnterExitCosts.CityTranffic1;
  14965. designer.SetDataSource("TotalAirLabel_GWC", cellLabel4_gwc);
  14966. designer.SetDataSource("TotalAir_GWC", $"{totalAir_gwc:#0.00}");
  14967. decimal totalPrice_gwc = grandTotalFee + totalAir_gwc + totalOtherFee;
  14968. designer.SetDataSource("TotalFeeLabel_GWC", $"大写 :{CommonFun.ToChinese(totalPrice_gwc)}整"); // 合计金额中文大写
  14969. designer.SetDataSource("TotalFee_GWC", $"{totalPrice_gwc:0.00}"); // 合计金额
  14970. designer.SetDataSource("ActualAmount_GWC", $"{totalPrice_gwc:0.00}元"); // 合计金额
  14971. // 国际旅行费 - 头等舱
  14972. var cellLabel4_tdc = new StringBuilder()
  14973. .AppendFormat($"4.国际旅费(头等舱:{_EnterExitCosts.AirTD:0.00}/人;城市间交通费:{_EnterExitCosts.CityTranffic2:0.00}元/人)")
  14974. .ToString();
  14975. decimal totalAir_tdc = _EnterExitCosts.AirTD + _EnterExitCosts.CityTranffic2;
  14976. designer.SetDataSource("TotalAirLabel_TDC", cellLabel4_tdc);
  14977. designer.SetDataSource("TotalAir_TDC", $"{totalAir_tdc:#0.00}");
  14978. decimal totalPrice_tdc = grandTotalFee + totalAir_tdc + totalOtherFee;
  14979. designer.SetDataSource("TotalFeeLabel_TDC", $"大写 :{CommonFun.ToChinese(totalPrice_tdc)}整"); // 合计金额中文大写
  14980. designer.SetDataSource("TotalFee_TDC", $"{totalPrice_tdc:0.00}"); // 合计金额
  14981. designer.SetDataSource("ActualAmount_TDC", $"{totalPrice_tdc:0.00}元"); // 合计金额
  14982. designer.Process();
  14983. #region 设置 住宿费、伙食费和公杂显示值
  14984. // 开始行
  14985. int startRow = 8;
  14986. // 开始列
  14987. int startColumn = 1;
  14988. // 数据展示默认行 含小计行
  14989. int defualtRow = 4;
  14990. // 设置住宿费
  14991. for (int i = 0; i < accomFees.Count; i++)
  14992. {
  14993. var currData = accomFees[i];
  14994. int startRow1 = startRow + i;
  14995. // 插入数据到对应列
  14996. worksheet1.Cells[startRow1, startColumn].PutValue(currData.PlaceName); // 国家(地区)/城市
  14997. worksheet1.Cells[startRow1, startColumn + 1].PutValue(currData.CurrencyName); // 币种
  14998. worksheet1.Cells[startRow1, startColumn + 2].PutValue($"{currData.Cost:0.00}"); // 标准
  14999. worksheet1.Cells[startRow1, startColumn + 3].PutValue("1"); // 人数
  15000. worksheet1.Cells[startRow1, startColumn + 4].PutValue(currData.TotalDays); // 天数
  15001. worksheet1.Cells[startRow1, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}"); // 小计
  15002. worksheet1.Cells[startRow1, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
  15003. worksheet1.Cells[startRow1, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}"); // 折合人民币(元)
  15004. worksheet2.Cells[startRow1, startColumn].PutValue(currData.PlaceName); // 国家(地区)/城市
  15005. worksheet2.Cells[startRow1, startColumn + 1].PutValue(currData.CurrencyName); // 币种
  15006. worksheet2.Cells[startRow1, startColumn + 2].PutValue($"{currData.Cost:0.00}"); // 标准
  15007. worksheet2.Cells[startRow1, startColumn + 3].PutValue("1"); // 人数
  15008. worksheet2.Cells[startRow1, startColumn + 4].PutValue(currData.TotalDays); // 天数
  15009. worksheet2.Cells[startRow1, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}"); // 小计
  15010. worksheet2.Cells[startRow1, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
  15011. worksheet2.Cells[startRow1, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}"); // 折合人民币(元)
  15012. worksheet3.Cells[startRow1, startColumn].PutValue(currData.PlaceName); // 国家(地区)/城市
  15013. worksheet3.Cells[startRow1, startColumn + 1].PutValue(currData.CurrencyName); // 币种
  15014. worksheet3.Cells[startRow1, startColumn + 2].PutValue($"{currData.Cost:0.00}"); // 标准
  15015. worksheet3.Cells[startRow1, startColumn + 3].PutValue("1"); // 人数
  15016. worksheet3.Cells[startRow1, startColumn + 4].PutValue(currData.TotalDays); // 天数
  15017. worksheet3.Cells[startRow1, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}"); // 小计
  15018. worksheet3.Cells[startRow1, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
  15019. worksheet3.Cells[startRow1, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}"); // 折合人民币(元)
  15020. }
  15021. //设置小计行 合计金额 固定单元格
  15022. worksheet1.Cells[11, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}"); // 折合人民币(元)
  15023. worksheet2.Cells[11, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}"); // 折合人民币(元)
  15024. worksheet3.Cells[11, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}"); // 折合人民币(元)
  15025. // 新增小计行
  15026. if (accomFees.Count == (defualtRow - 1)) startRow += 1;
  15027. else startRow += defualtRow;
  15028. // 设置伙食费和公杂费行
  15029. for (int i = 0; i < foodSundCosts.Count; i++)
  15030. {
  15031. var currData = foodSundCosts[i];
  15032. int startRow2 = startRow + i;
  15033. // 插入数据到对应列
  15034. worksheet1.Cells[startRow2, startColumn].PutValue(currData.PlaceName); // 国家(地区)/城市
  15035. worksheet1.Cells[startRow2, startColumn + 1].PutValue(currData.CurrencyName); // 币种
  15036. worksheet1.Cells[startRow2, startColumn + 2].PutValue($"{currData.Cost:0.00}"); // 标准
  15037. worksheet1.Cells[startRow2, startColumn + 3].PutValue("1"); // 人数
  15038. worksheet1.Cells[startRow2, startColumn + 4].PutValue(currData.TotalDays); // 天数
  15039. worksheet1.Cells[startRow2, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}"); // 小计
  15040. worksheet1.Cells[startRow2, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
  15041. worksheet1.Cells[startRow2, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}"); // 折合人民币(元)
  15042. worksheet2.Cells[startRow2, startColumn].PutValue(currData.PlaceName); // 国家(地区)/城市
  15043. worksheet2.Cells[startRow2, startColumn + 1].PutValue(currData.CurrencyName); // 币种
  15044. worksheet2.Cells[startRow2, startColumn + 2].PutValue($"{currData.Cost:0.00}"); // 标准
  15045. worksheet2.Cells[startRow2, startColumn + 3].PutValue("1"); // 人数
  15046. worksheet2.Cells[startRow2, startColumn + 4].PutValue(currData.TotalDays); // 天数
  15047. worksheet2.Cells[startRow2, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}"); // 小计
  15048. worksheet2.Cells[startRow2, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
  15049. worksheet2.Cells[startRow2, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}"); // 折合人民币(元)
  15050. worksheet3.Cells[startRow2, startColumn].PutValue(currData.PlaceName); // 国家(地区)/城市
  15051. worksheet3.Cells[startRow2, startColumn + 1].PutValue(currData.CurrencyName); // 币种
  15052. worksheet3.Cells[startRow2, startColumn + 2].PutValue($"{currData.Cost:0.00}"); // 标准
  15053. worksheet3.Cells[startRow2, startColumn + 3].PutValue("1"); // 人数
  15054. worksheet3.Cells[startRow2, startColumn + 4].PutValue(currData.TotalDays); // 天数
  15055. worksheet3.Cells[startRow2, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}"); // 小计
  15056. worksheet3.Cells[startRow2, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
  15057. worksheet3.Cells[startRow2, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}"); // 折合人民币(元)
  15058. }
  15059. //设置小计行 合计金额 固定单元格
  15060. worksheet1.Cells[15, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}"); // 折合人民币(元)
  15061. worksheet2.Cells[15, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}"); // 折合人民币(元)
  15062. worksheet3.Cells[15, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}"); // 折合人民币(元)
  15063. #endregion
  15064. workbook.CalculateFormula(true);
  15065. // 根据舱位选择,删除指定的sheet
  15066. if (_EnterExitCosts.SumJJC == 0)
  15067. {
  15068. var sheetNameToDelete1 = "经济舱";
  15069. if (workbook.Worksheets[sheetNameToDelete1] != null)
  15070. {
  15071. workbook.Worksheets.RemoveAt(sheetNameToDelete1);
  15072. }
  15073. }
  15074. if (_EnterExitCosts.SumGWC == 0)
  15075. {
  15076. var sheetNameToDelete2 = "公务舱";
  15077. if (workbook.Worksheets[sheetNameToDelete2] != null)
  15078. {
  15079. workbook.Worksheets.RemoveAt(sheetNameToDelete2);
  15080. }
  15081. }
  15082. if (_EnterExitCosts.SumTDC == 0)
  15083. {
  15084. var sheetNameToDelete3 = "头等舱";
  15085. if (workbook.Worksheets[sheetNameToDelete3] != null)
  15086. {
  15087. workbook.Worksheets.RemoveAt(sheetNameToDelete3);
  15088. }
  15089. }
  15090. // 模板文件名
  15091. string strFileName = $"{_DelegationInfo.TeamName}_省级单位出国经费报销单_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  15092. designer.Workbook.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  15093. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  15094. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  15095. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  15096. }
  15097. }
  15098. else if (dto.ExportType == 3)
  15099. {
  15100. if (dto.SubTypeId == 1) //团组成员名单
  15101. {
  15102. if (!DeleClientList.Any()) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组成员暂未录入!!!", ""));
  15103. //获取模板
  15104. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/dwon_团组人员列表模板.doc");
  15105. //载入模板
  15106. var doc = new Document(tempPath);
  15107. var builder = new DocumentBuilder(doc);
  15108. //获取word里所有表格
  15109. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  15110. //获取所填表格的序数
  15111. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  15112. var rowStart = tableOne.Rows[0]; //获取第1行
  15113. //循环赋值
  15114. for (int i = 0; i < DeleClientList.Count; i++)
  15115. {
  15116. builder.MoveToCell(0, i + 1, 0, 0);
  15117. builder.Write(DeleClientList[i].Name);
  15118. builder.MoveToCell(0, i + 1, 1, 0);
  15119. string sex = DeleClientList[i].Sex == 0 ? "男" : DeleClientList[i].Sex == 1 ? "女" : "";
  15120. builder.Write(sex);
  15121. builder.MoveToCell(0, i + 1, 2, 0);
  15122. builder.Write(Convert.ToDateTime(DeleClientList[i].Birthday).ToString("yyyy年MM月dd日"));
  15123. builder.MoveToCell(0, i + 1, 3, 0);
  15124. builder.Write(DeleClientList[i].Company);
  15125. builder.MoveToCell(0, i + 1, 4, 0);
  15126. builder.Write(DeleClientList[i].Job);
  15127. }
  15128. //删除多余行
  15129. while (tableOne.Rows.Count > DeleClientList.Count + 1)
  15130. {
  15131. tableOne.Rows.RemoveAt(DeleClientList.Count + 1);
  15132. }
  15133. string strFileName = $"{_DelegationInfo.TeamName}组团人员名单({DateTime.Now.ToString("yyyyMMddHHmmss")}).doc";
  15134. //C:/Server/File/OA2023/Office/Word/EnterExitCost/File/
  15135. //C:\Server\File\OA2023\Office\Word\EnterExitCost\File\
  15136. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  15137. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  15138. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  15139. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  15140. }
  15141. }
  15142. return Ok(JsonView(400, "操作失败!", ""));
  15143. }
  15144. catch (Exception ex)
  15145. {
  15146. return Ok(JsonView(400, ex.Message, ""));
  15147. }
  15148. }
  15149. /// <summary>
  15150. /// 获取三公费用标准city
  15151. /// </summary>
  15152. /// <param name="placeData"></param>
  15153. /// <param name="nationalTravelFeeId"></param>
  15154. /// <returns></returns>
  15155. private static string GetEnterExitCostExportCity(List<Grp_NationalTravelFee> placeData, int nationalTravelFeeId)
  15156. {
  15157. string _city = string.Empty;
  15158. if (placeData.Count < 1) return _city;
  15159. var data = placeData.Find(it => it.Id == nationalTravelFeeId);
  15160. if (data == null) return _city;
  15161. string country = data.Country;
  15162. string city = data.City;
  15163. if (city.Contains("其他城市") || city.Contains("所有城市")) _city = $"{country}-{city}";
  15164. else _city = city;
  15165. return _city;
  15166. }
  15167. ///// <summary>
  15168. ///// 团组模块 - 出入境费用 - 明细表导出
  15169. ///// </summary>
  15170. ///// <returns></returns>
  15171. //[HttpPost]
  15172. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15173. //public async Task<IActionResult> PostEnterExitCostExportDetailsList(EnterExitCostOperateDto dto)
  15174. //{
  15175. // var data = await _enterExitCostRep.PostEnterExitCostOperate(dto);
  15176. // if (data.Code != 0)
  15177. // {
  15178. // return Ok(JsonView(false, data.Msg));
  15179. // }
  15180. // return Ok(JsonView(true, data.Msg, data.Data));
  15181. //}
  15182. /// <summary>
  15183. /// 团组模块 - 出入境费用 - 一键清空
  15184. /// </summary>
  15185. /// <returns></returns>
  15186. [HttpPost]
  15187. //[ApiLog("Grp_EnterExitCost", OperationEnum.Del)]
  15188. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15189. public async Task<IActionResult> PostEnterExitCostOneClickClear(EnterExitCostOneClickClearDto dto)
  15190. {
  15191. if (dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId参数;"));
  15192. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数;"));
  15193. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数;"));
  15194. var _view = await _enterExitCostRep.OneClickClear(dto.Id, dto.DiId, dto.UserId);
  15195. await _sqlSugar.Updateable<Grp_DayOtherPrice>()
  15196. .Where(x => x.Diid == dto.DiId && x.IsDel == 0)
  15197. .SetColumns(x => new Grp_DayOtherPrice
  15198. {
  15199. IsDel = 1,
  15200. DeleteUserId = dto.UserId,
  15201. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  15202. })
  15203. .ExecuteCommandAsync();
  15204. if (_view.Code == 0)
  15205. {
  15206. return Ok(JsonView(true, "操作成功"));
  15207. }
  15208. return Ok(JsonView(false, "操作失败"));
  15209. }
  15210. /// <summary>
  15211. /// 团组模块 - 出入境费用 - 子项删除
  15212. /// </summary>
  15213. /// <returns></returns>
  15214. [HttpPost]
  15215. //[ApiLog("Grp_EnterExitCost", OperationEnum.Del)]
  15216. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15217. public async Task<IActionResult> PostEnterExitCostSubItemDel(EnterExitCostSubItemDelDto dto)
  15218. {
  15219. var data = await _enterExitCostRep.PostEnterExitCostSubItemDel(dto);
  15220. if (data.Code != 0)
  15221. {
  15222. return Ok(JsonView(false, data.Msg));
  15223. }
  15224. return Ok(JsonView(true, "操作成功!", data.Data));
  15225. }
  15226. /// <summary>
  15227. /// 删除三公其他费用
  15228. /// </summary>
  15229. /// <param name="dto"></param>
  15230. /// <returns></returns>
  15231. [HttpPost]
  15232. //[ApiLog("Grp_EnterExitCost", OperationEnum.Del)]
  15233. public IActionResult DeleteOtherExpenses(EnterExitCostSubItemDelDto dto)
  15234. {
  15235. var jw = JsonView(false, "删除失败!");
  15236. var data = new Grp_DayOtherPrice()
  15237. {
  15238. Id = dto.Id,
  15239. IsDel = 1,
  15240. DeleteUserId = dto.DeleteUserId,
  15241. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  15242. };
  15243. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  15244. if (del > 0)
  15245. {
  15246. jw.Code = 200;
  15247. jw.Msg = "删除成功!";
  15248. }
  15249. return Ok(jw);
  15250. }
  15251. /// <summary>
  15252. /// 团组模块 - 出入境国家费用标准 List
  15253. /// </summary>
  15254. /// <returns></returns>
  15255. [HttpPost]
  15256. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15257. public async Task<IActionResult> GetNationalTravelFeeData(NationalTravelFeeDataDto dto)
  15258. {
  15259. int provinceId = dto.ProvinceId;
  15260. if (provinceId < 1) provinceId = 122; //默认四川省数据
  15261. var nftData = await _sqlSugar
  15262. .Queryable<Grp_NationalTravelFee, Sys_SetData, Sys_Users, Sys_Cities>((ntf, sd1, u, c) => new JoinQueryInfos(
  15263. JoinType.Left, ntf.Currency == sd1.Id,
  15264. JoinType.Left, ntf.LastUpdateUserId == u.Id,
  15265. JoinType.Left, ntf.ProvinceId == c.Id
  15266. ))
  15267. .Where((ntf, sd1, u, c) => ntf.IsDel == 0 && ntf.ProvinceId == provinceId)
  15268. .Select((ntf, sd1, u, c) => new NationalTravelFeeInfoView
  15269. {
  15270. Id = ntf.Id,
  15271. ProvinceId = ntf.ProvinceId,
  15272. ProvinceName = c.Name_CN,
  15273. Continent = ntf.Continent,
  15274. Country = ntf.Country,
  15275. City = ntf.City,
  15276. Currency = ntf.Currency,
  15277. CurrencyCode = sd1.Name,
  15278. CurrencyName = sd1.Remark,
  15279. RoomCost = ntf.RoomCost,
  15280. FoodCost = ntf.FoodCost,
  15281. PublicCost = ntf.PublicCost,
  15282. LastUpdateUserId = ntf.LastUpdateUserId,
  15283. LastUpdateUserName = u.CnName,
  15284. LastUpdateTime = ntf.LastUpdateTime
  15285. })
  15286. .ToListAsync();
  15287. return Ok(JsonView(true, "查询成功!", nftData));
  15288. }
  15289. /// <summary>
  15290. /// 团组模块 - 出入境国家费用标准 Page List Data Source
  15291. /// </summary>
  15292. /// <returns></returns>
  15293. [HttpPost]
  15294. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15295. public async Task<IActionResult> GetNationalTravelFeePageDataSource()
  15296. {
  15297. string sql = string.Format(@"Select * From Grp_NationalTravelFee Where Isdel = 0 ");
  15298. var nationalTravelFeeData = await _groupRepository._sqlSugar.SqlQueryable<Grp_NationalTravelFee>(sql).ToListAsync();
  15299. List<string> countryData = new List<string>();
  15300. countryData.AddRange(nationalTravelFeeData.Select(it => it.Country!).ToList());
  15301. countryData = countryData.Distinct().ToList();
  15302. List<dynamic> dataSource = new List<dynamic>();
  15303. foreach (var item in countryData)
  15304. {
  15305. var cityData1 = new List<string>();
  15306. cityData1 = nationalTravelFeeData.Where(it => it.Country == item).Select(it => it.City ?? "").ToList();
  15307. var countryData2 = new
  15308. {
  15309. CountryName = item,
  15310. CityData = cityData1
  15311. };
  15312. if (!dataSource.Contains(countryData2))
  15313. {
  15314. dataSource.Add(countryData2);
  15315. }
  15316. }
  15317. return Ok(JsonView(true, "查询成功!", dataSource));
  15318. }
  15319. /// <summary>
  15320. /// 团组模块 - 出入境国家费用标准 Page List
  15321. /// </summary>
  15322. /// <returns></returns>
  15323. [HttpPost]
  15324. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15325. public async Task<IActionResult> PostNationalTravelFeePage(NationalTravelFeePageDto dto)
  15326. {
  15327. int portId = dto.PortType,
  15328. pageIndex = dto.PageIndex,
  15329. pageSize = dto.PageSize;
  15330. if (portId != 1 && portId != 2 && portId != 3) return Ok(JsonView(false, "请输入正确的端口号!\r\n请求端口分类1 Web 2 Android 3 IOS"));
  15331. if (pageIndex == 0) pageIndex = 1;
  15332. if (pageSize == 0) pageSize = 10;
  15333. RefAsync<int> total = 0;
  15334. var nationalTravelFeeData = await _sqlSugar
  15335. .Queryable<Grp_NationalTravelFee, Sys_SetData, Sys_Users, Sys_Cities>((ntf, sd1, u, sd2) => new JoinQueryInfos(
  15336. JoinType.Left, ntf.Currency == sd1.Id,
  15337. JoinType.Left, ntf.LastUpdateUserId == u.Id,
  15338. JoinType.Left, ntf.ProvinceId == sd2.Id
  15339. ))
  15340. .Where((ntf, sd1, u, sd2) => ntf.IsDel == 0)
  15341. .WhereIF(dto.ProvinceId > 0, (ntf, sd1, u, sd2) => ntf.ProvinceId == dto.ProvinceId)
  15342. .WhereIF(!string.IsNullOrEmpty(dto.Country), (ntf, sd1, u, sd2) => ntf.Country.Contains(dto.Country))
  15343. .WhereIF(!string.IsNullOrEmpty(dto.City), (ntf, sd1, u, sd2) => ntf.City.Contains(dto.City))
  15344. .OrderByDescending((ntf, sd1, u, sd2) => ntf.LastUpdateTime)
  15345. .Select((ntf, sd1, u, sd2) => new NationalTravelFeePageInfoView
  15346. {
  15347. RowNumber = SqlFunc.RowNumber($"{ntf.LastUpdateTime} Desc"),
  15348. Id = ntf.Id,
  15349. ProvinceId = ntf.ProvinceId,
  15350. ProvinceName = sd2.Name_CN,
  15351. Continent = ntf.Continent,
  15352. Country = ntf.Country,
  15353. City = ntf.City,
  15354. Currency = ntf.Currency,
  15355. CurrencyCode = sd1.Name,
  15356. CurrencyName = sd1.Remark,
  15357. RoomCost = ntf.RoomCost,
  15358. FoodCost = ntf.FoodCost,
  15359. PublicCost = ntf.PublicCost,
  15360. LastUpdateUserId = ntf.LastUpdateUserId,
  15361. LastUpdateUserName = u.CnName,
  15362. LastUpdateTime = ntf.LastUpdateTime,
  15363. Remark = ntf.Remark
  15364. })
  15365. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  15366. return Ok(JsonView(true, "查询成功!", nationalTravelFeeData, (int)total));
  15367. }
  15368. /// <summary>
  15369. /// 团组模块 - 出入境国家费用标准 根据城市查询
  15370. /// </summary>
  15371. /// <returns></returns>
  15372. [HttpPost]
  15373. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15374. public async Task<IActionResult> PostNationalTravelFeeInfoByCountryAndCity(NationalTravelFeeByCountryAndCityDto dto)
  15375. {
  15376. if (dto == null) return Ok(JsonView(false, "请传入参数!"));
  15377. int portId = dto.PortType;
  15378. if (portId != 1 && portId != 2 && portId != 3) return Ok(JsonView(false, "请输入正确的端口号!\r\n请求端口分类1 Web 2 Android 3 IOS"));
  15379. string whereSql = string.Empty;
  15380. if (!string.IsNullOrEmpty(dto.Country))
  15381. {
  15382. whereSql = string.Format(@"And Country = '{0}' ", dto.Country);
  15383. }
  15384. if (!string.IsNullOrEmpty(dto.City))
  15385. {
  15386. whereSql = string.Format(@"And City = '{0}' ", dto.City);
  15387. }
  15388. string sql = string.Format(@"Select gntf.Country,gntf.City,gntf.Currency,ssd.Name as CurrencyCode,
  15389. ssd.Remark as CurrencyName,gntf.RoomCost,gntf.FoodCost,gntf.PublicCost,gntf.TrainCost,
  15390. gntf.LastUpdateUserId,su.CnName as LastUpdateUserName,gntf.LastUpdateTime
  15391. From Grp_NationalTravelFee gntf
  15392. Left Join Sys_SetData ssd On ssd.STid = 66 And gntf.Currency = ssd.Id
  15393. Left Join Sys_Users su On gntf.LastUpdateUserId = su.Id
  15394. Where gntf.Isdel = 0 {0} ", whereSql);
  15395. var nationalTravelFeeData = await _groupRepository._sqlSugar.SqlQueryable<NationalTravelFeeInfoByCountryAndCityView>(sql).FirstAsync();
  15396. return Ok(JsonView(true, "查询成功!", nationalTravelFeeData));
  15397. }
  15398. /// <summary>
  15399. /// 团组模块 - 出入境国家费用标准 - Add Or Update
  15400. /// </summary>
  15401. /// <returns></returns>
  15402. [HttpPost]
  15403. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15404. public async Task<IActionResult> PostNationalTravelFeeOperate(NationalTravelFeeOperateDto dto)
  15405. {
  15406. return Ok(await _enterExitCostRep.PostNationalTravelFeeOperate(dto));
  15407. }
  15408. /// <summary>
  15409. /// 团组模块 - 出入境国家费用标准 - Del
  15410. /// </summary>
  15411. /// <returns></returns>
  15412. [HttpPost]
  15413. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15414. public async Task<IActionResult> PostNationalTravelFeeDel(NationalTravelFeeDelDto dto)
  15415. {
  15416. Grp_NationalTravelFee _nationalTravelFee = new Grp_NationalTravelFee()
  15417. {
  15418. Id = dto.Id,
  15419. DeleteUserId = dto.DeleteUserId,
  15420. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  15421. IsDel = 1
  15422. };
  15423. var delStatus = await _enterExitCostRep._sqlSugar.Updateable<Grp_NationalTravelFee>(_nationalTravelFee)
  15424. .UpdateColumns(it => new { it.DeleteTime, it.DeleteUserId, it.IsDel })
  15425. .WhereColumns(it => new { it.Id })
  15426. .ExecuteCommandAsync();
  15427. if (delStatus <= 0)
  15428. {
  15429. return Ok(JsonView(false, "删除失败!"));
  15430. }
  15431. return Ok(JsonView(true, "操作成功!"));
  15432. }
  15433. /// <summary>
  15434. /// 团组模块 - 出入境国家费用标准 - 费用导入收款账单
  15435. /// 注:Get 请求Headers 加 Token
  15436. /// </summary>
  15437. /// <param name="groupId"></param>
  15438. /// <returns></returns>
  15439. [HttpGet("{groupId}")]
  15440. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15441. public async Task<IActionResult> NationalTravelFeeImportReceivables(int groupId)
  15442. {
  15443. var _currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  15444. if (_currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  15445. var data = await GeneralMethod.ReceivablesImportFeeAsync(groupId);
  15446. data.ForEach(x =>
  15447. {
  15448. x.CreateUserId = _currUserInfo.UserId;
  15449. });
  15450. if (data.Any())
  15451. {
  15452. var add = await _sqlSugar.Insertable(data).ExecuteCommandAsync();
  15453. if (add > 0)
  15454. {
  15455. return Ok(JsonView(true, "操作成功!"));
  15456. }
  15457. }
  15458. return Ok(JsonView(false, "未操作!"));
  15459. }
  15460. #endregion
  15461. #region 团组经理模块 出入境费用-草稿
  15462. /// <summary>
  15463. /// 团组模块-出入境费用-草稿
  15464. /// 基础数据源-省份归属
  15465. /// </summary>
  15466. /// <returns></returns>
  15467. [HttpGet]
  15468. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15469. public async Task<IActionResult> EnterExitDraftProvBelongCostDataSource()
  15470. {
  15471. var provData = await _groupRepository.ProvinceBasicSource();
  15472. return Ok(JsonView(true, "查询成功!", provData));
  15473. }
  15474. /// <summary>
  15475. /// 团组模块-出入境费用-草稿
  15476. /// 文件类型list 根据省份Id获取
  15477. /// </summary>
  15478. /// <returns></returns>
  15479. [HttpGet("{provinceId}")]
  15480. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15481. public async Task<IActionResult> EnterExitCostDraftFileOwner([FromRoute] int provinceId = 122)
  15482. {
  15483. //验证城市归属并给默认值
  15484. if (provinceId < 1) provinceId = 122;
  15485. /*
  15486. * 122 四川
  15487. * 108 贵州
  15488. * 103 重庆
  15489. * 132 云南
  15490. */
  15491. (SetDataInfoView[] wordTypeData, SetDataInfoView[] excelTypeData) = await _enterExitCostDraftRep.FileOwner(provinceId);
  15492. return Ok(JsonView(true, "查询成功!", new
  15493. {
  15494. WordTypeData = wordTypeData,
  15495. ExcelTypeData = excelTypeData,
  15496. }));
  15497. }
  15498. /// <summary>
  15499. /// 团组模块 - 出入境费用-草稿
  15500. /// 基础数据源(团组名称/币种类型)
  15501. /// </summary>
  15502. /// <returns></returns>
  15503. [HttpPost]
  15504. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15505. public async Task<IActionResult> EnterExitCostDraftDataSource(EnterExitCostDraftDataSourceDto dto)
  15506. {
  15507. var draftNameDatas = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>()
  15508. .Where(x => x.IsDel == 0)
  15509. .OrderByDescending(x => x.CreateTime)
  15510. .Select(x => new { x.Id, x.DraftName })
  15511. .ToListAsync();
  15512. string sql = string.Format("Select * From Sys_SetData Where IsDel = 0");
  15513. //SetDataInfoView
  15514. var dataSource = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToListAsync();
  15515. var currencyData = dataSource.Where(it => it.STid == 66).ToList(); //所有币种
  15516. var _CurrencyData = _mapper.Map<List<SetDataInfoView>>(currencyData);
  15517. int provinceId = dto.ProvinceId;
  15518. if (provinceId < 1) provinceId = 122;
  15519. /*
  15520. * 122 四川
  15521. * 108 贵州
  15522. * 103 重庆
  15523. * 132 云南
  15524. */
  15525. (SetDataInfoView[] wordTypeData, SetDataInfoView[] excelTypeData) = await _enterExitCostRep.FileOwner(provinceId);
  15526. //默认币种显示
  15527. var _currencyInfos = await GeneralMethod.EnterExitCostInitRate();
  15528. var viewPermissionData = await _enterExitCostDraftRep.PermissionViewUsersAsync();
  15529. return Ok(JsonView(true, "查询成功!", new
  15530. {
  15531. DraftNameDatas = draftNameDatas,
  15532. CurrencyData = _CurrencyData,
  15533. WordTypeData = wordTypeData,
  15534. ExcelTypeData = excelTypeData,
  15535. CurrencyInit = _currencyInfos,
  15536. ViewPermissionData = viewPermissionData
  15537. }));
  15538. }
  15539. /// <summary>
  15540. /// 团组模块 - 出入境费用-草稿
  15541. /// 实时汇率 tips、机票费用 tips
  15542. /// </summary>
  15543. /// <returns></returns>
  15544. [HttpPost]
  15545. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15546. public async Task<IActionResult> EnterExitCostDraftCorrelationTips(EnterExitCostDraftCorrelationTipsDto dto)
  15547. {
  15548. //var airData = await _ticketBlackCodeRep.EntryAndExitTips(dto.DiId);
  15549. return Ok(JsonView(true, "查询成功!", new
  15550. {
  15551. //GroupNameData = groupNameData.Data,
  15552. //visaData = visaData.Data,
  15553. //airData = airData.Data,
  15554. reteInfos = await GeneralMethod.EnterExitCostLiveRate()
  15555. }));
  15556. }
  15557. /// <summary>
  15558. /// 团组模块 - 出入境费用-草稿
  15559. /// 签证费用 tips
  15560. /// </summary>
  15561. /// <returns></returns>
  15562. [HttpPost]
  15563. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15564. public async Task<IActionResult> EnterExitCostDraftVisaTips(EnterExitCostDraftVisaTipsDto dto)
  15565. {
  15566. //if (dto.DraftId < 1) return Ok(JsonView(false,MsgTips.Id));
  15567. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  15568. .Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId)
  15569. .Select(x => x.NationalTravelFeeId)
  15570. .Distinct()
  15571. .ToListAsync();
  15572. //if (!cityIds.Any()) return Ok(JsonView(false, "请先录入出入境费用明细!"));
  15573. var countrys = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  15574. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  15575. .Select(x => x.Country)
  15576. .Distinct()
  15577. .ToArrayAsync();
  15578. //if (!countrys.Any()) return Ok(JsonView(false, "请先录入出入境费用明细!"));
  15579. (decimal totalAmt, string remark) = await _visaFeeInfoRep.EnterExitCostDraftVisaTips(countrys);
  15580. return Ok(JsonView(true, "查询成功!", new
  15581. {
  15582. totalAmt,
  15583. remark
  15584. }));
  15585. }
  15586. #region 城市区间交通费
  15587. /// <summary>
  15588. /// 团组模块 - 出入境费用-草稿
  15589. /// 境外用车 基础数据源
  15590. /// </summary>
  15591. /// <param name="draftId">草稿Id</param>
  15592. /// <returns></returns>
  15593. [HttpGet("{draftId}")]
  15594. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15595. public async Task<IActionResult> EnterExitCostDraftOVByGroupId(int draftId)
  15596. {
  15597. var draftInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == draftId).FirstAsync();
  15598. if (draftInfo == null)
  15599. {
  15600. return Ok(JsonView(false, "三公费用草稿信息为空"));
  15601. }
  15602. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  15603. .Where(x => x.IsDel == 0 && x.ParentId == draftId)
  15604. .Select(x => x.NationalTravelFeeId)
  15605. .Distinct()
  15606. .ToListAsync();
  15607. var countries = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  15608. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  15609. .Select(x => x.Country)
  15610. .Distinct()
  15611. .ToListAsync();
  15612. if (countries?.Any() != true)
  15613. {
  15614. return Ok(JsonView(false, "草稿选择城市信息为空"));
  15615. }
  15616. var currencies = await GeneralMethod.EnterExitCostDrafOVFeeUsedCurrencyAsync(draftId);
  15617. var currencyData = await _sqlSugar.Queryable<Sys_SetData>()
  15618. .Where(x => x.IsDel == 0 && x.STid == 66)
  15619. .ToListAsync();
  15620. var overseaVehicles = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  15621. .Where(x => x.IsDel == 0 && countries.Contains(x.CountryName))
  15622. .ToListAsync();
  15623. var overseaVehicleIds = overseaVehicles.Select(x => x.Id).ToList();
  15624. //只返回接送机的数据
  15625. var overseaVehicleTypes = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  15626. .Where(x => x.IsDel == 0 && x.ServiceType == VehicleServiceTypeEnum.TransferService && overseaVehicleIds.Contains(x.OvId))
  15627. .ToListAsync();
  15628. var sysUers = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToListAsync();
  15629. var overseaVehicleCityDatas = new List<dynamic>() {
  15630. new
  15631. {
  15632. Id = 0,
  15633. area= "未选择",
  15634. CarTypeName = "",
  15635. serviceType = "",
  15636. Price = 0.00M,
  15637. guidePrice = 0.00M,
  15638. otherPrice = 0.00M,
  15639. currency = 0,
  15640. currencyName = "",
  15641. currRate = 1.0000M,
  15642. LastUpdateUserName = "",
  15643. LastUpdateTime = "",
  15644. Remark = ""
  15645. }};
  15646. foreach (var item in overseaVehicleTypes)
  15647. {
  15648. var parentInfo = overseaVehicles.FirstOrDefault(x => x.Id == item.OvId);
  15649. string area = string.Empty,
  15650. serviceType = "未设置",
  15651. currencyName = string.Empty;
  15652. decimal otherPrice = 0.00M;
  15653. if (parentInfo != null)
  15654. {
  15655. if (parentInfo.CountryName == parentInfo.CityName) area = parentInfo.CountryName;
  15656. else area = $"{parentInfo.CountryName}-{parentInfo.CityName}";
  15657. serviceType = item.ServiceType.GetDescription();
  15658. currencyName = currencyData.FirstOrDefault(x => x.Id == parentInfo.Currency)?.Name ?? "-";
  15659. otherPrice = parentInfo.OtherPrice1 + parentInfo.OtherPrice2;
  15660. }
  15661. //当前币种汇率值
  15662. var currRate = 1.0000M;
  15663. var currencyInfo = currencies.FirstOrDefault(x => x.CurrencyCode == currencyName);
  15664. if (currencyInfo != null) currRate = currencyInfo.Rate;
  15665. overseaVehicleCityDatas.add(new
  15666. {
  15667. item.Id,
  15668. area,
  15669. item.CarTypeName,
  15670. serviceType,
  15671. item.Price,
  15672. guidePrice = parentInfo?.GuidePrice ?? 0.00M,
  15673. otherPrice,
  15674. currency = parentInfo?.Currency ?? 0,
  15675. currencyName,
  15676. currRate,
  15677. LastUpdateUserName = sysUers.FirstOrDefault(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-",
  15678. item.LastUpdateTime,
  15679. item.Remark
  15680. });
  15681. }
  15682. var total = overseaVehicleCityDatas.Count;
  15683. var view = new
  15684. {
  15685. visitCountries = string.Join("、", countries),
  15686. groupSize = 0, //出访人数
  15687. defAirportTransferCoeff = Def_AirportTransferCoeff, //接送机默认报价系数
  15688. defServiceCount = Def_ServiceCount, //接送机默认服务次数
  15689. defTrainCoeff = Def_TrainCoeff, //火车默认报价系数
  15690. defPullCartCoeff = Def_PullCartCoeff, //拉车默认报价系数
  15691. defCityFlightCoeff = Def_CityFlightCoeff, //城市机票默认报价系数
  15692. Currencies = currencies,
  15693. data = overseaVehicleCityDatas
  15694. };
  15695. if (overseaVehicleCityDatas.Count == 0)
  15696. {
  15697. return Ok(JsonView(true, "暂无数据!", view));
  15698. }
  15699. return Ok(JsonView(true, "查询成功!", view, total));
  15700. }
  15701. /// <summary>
  15702. /// 团组模块 - 出入境费用-草稿
  15703. /// 境外用车 计算详细信息
  15704. /// </summary>
  15705. /// <param name="draftId"></param>
  15706. /// <param name="currUserId"></param>
  15707. /// <returns></returns>
  15708. [HttpGet("{draftId}")]
  15709. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15710. public async Task<IActionResult> EnterExitCostDraftOVFeeDetails(int draftId, int currUserId)
  15711. {
  15712. // 1. 验证草稿是否存在
  15713. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>()
  15714. .Where(x => x.Id == draftId && x.IsDel == 0)
  15715. .FirstAsync();
  15716. if (eecInfo == null)
  15717. {
  15718. return Ok(JsonView(false, "草稿信息为空"));
  15719. }
  15720. // 2. 获取用户信息
  15721. var userInfo = await _sqlSugar.Queryable<Sys_Users>()
  15722. .Where(x => x.IsDel == 0 && x.Id == currUserId)
  15723. .FirstAsync();
  15724. var userName = userInfo?.CnName ?? "-";
  15725. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  15726. // 3. 处理草稿信息
  15727. CityIntervalDraftInfo info;
  15728. if (eecInfo.CityIntervalFeeDetails != null)
  15729. {
  15730. info = eecInfo.CityIntervalFeeDetails;
  15731. // 检查费用详情是否为空
  15732. bool isEmpty = !info.APTFeeDetails.Any() &&
  15733. !info.PullCartFeeDetails.Any() &&
  15734. !info.TrainFeeDetails.Any() &&
  15735. !info.CityAirTicketFeeDetails.Any();
  15736. if (isEmpty)
  15737. {
  15738. info = await CreateDefaultCityIntervalDraftInfo(draftId, userName, nowTime);
  15739. }
  15740. else
  15741. {
  15742. // 更新时间和用户信息
  15743. info.LastUpdateUserName = userName;
  15744. info.LastUpdateTime = nowTime;
  15745. }
  15746. }
  15747. else
  15748. {
  15749. // 创建默认信息
  15750. info = await CreateDefaultCityIntervalDraftInfo(draftId, userName, nowTime);
  15751. }
  15752. return Ok(JsonView(true, "查询成功!", info));
  15753. }
  15754. /// <summary>
  15755. /// 创建默认的城市区间费用草稿信息
  15756. /// </summary>
  15757. private static async Task<CityIntervalDraftInfo> CreateDefaultCityIntervalDraftInfo(
  15758. int draftId,
  15759. string userName,
  15760. string nowTime)
  15761. {
  15762. return new CityIntervalDraftInfo()
  15763. {
  15764. APTFeeDetails = new List<RoundTripTransferInfo>()
  15765. {
  15766. new()
  15767. {
  15768. No = 1,
  15769. Coefficient = Def_AirportTransferCoeff,
  15770. ServiceCount = Def_ServiceCount
  15771. }
  15772. },
  15773. PullCartFeeDetails = new List<PullCartInfo>()
  15774. {
  15775. new()
  15776. {
  15777. No = 1,
  15778. Coefficient = Def_PullCartCoeff
  15779. }
  15780. },
  15781. TrainFeeDetails = new List<TrainInfo>()
  15782. {
  15783. new()
  15784. {
  15785. No = 1,
  15786. Coefficient = Def_TrainCoeff
  15787. }
  15788. },
  15789. CityAirTicketFeeDetails = new List<CityAirTicketInfo>()
  15790. {
  15791. new()
  15792. {
  15793. No = 1,
  15794. Coefficient = Def_CityFlightCoeff
  15795. }
  15796. },
  15797. LastUpdateUserName = userName,
  15798. LastUpdateTime = nowTime,
  15799. CreateUserName = userName,
  15800. CreateTime = nowTime,
  15801. Currencies = await GeneralMethod.EnterExitCostDrafOVFeeUsedCurrencyAsync(draftId)
  15802. };
  15803. }
  15804. /// <summary>
  15805. /// 团组模块 - 出入境费用-草稿
  15806. /// 境外用车 保存
  15807. /// </summary>
  15808. /// <param name="dto"></param>
  15809. /// <returns></returns>
  15810. [HttpPost]
  15811. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15812. public async Task<IActionResult> EnterExitCostDraftOVFeeSave(EnterExitCostDraftOVFeeSaveDto dto)
  15813. {
  15814. var draftInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == dto.DraftId).FirstAsync();
  15815. if (draftInfo == null)
  15816. {
  15817. return Ok(JsonView(false, "草稿信息为空"));
  15818. }
  15819. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == dto.CurrUserId).FirstAsync();
  15820. if (userInfo == null)
  15821. {
  15822. return Ok(JsonView(false, "员工信息为空"));
  15823. }
  15824. var userName = userInfo?.CnName ?? "-";
  15825. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  15826. var info = new CityIntervalDraftInfo()
  15827. {
  15828. GroupSize = dto.GroupSize,
  15829. APTFeeTotal = dto.APTFeeTotal,
  15830. APTFeeDetails = dto.APTFeeDetails,
  15831. PullCartFeeTotal = dto.PullCartFeeTotal,
  15832. PullCartFeeDetails = dto.PullCartFeeDetails,
  15833. TrainFeeTotal = dto.TrainFeeTotal,
  15834. TrainFeeDetails = dto.TrainFeeDetails,
  15835. CityAirTicketFeeTotal = dto.CityAirTicketFeeTotal,
  15836. CityAirTicketFeeDetails = dto.CityAirTicketFeeDetails,
  15837. Currencies = dto.Currencies,
  15838. LastUpdateUserName = userName,
  15839. LastUpdateTime = nowTime,
  15840. CreateUserName = draftInfo.CityIntervalFeeDetails?.CreateUserName ?? userName,
  15841. CreateTime = draftInfo.CityIntervalFeeDetails?.CreateTime ?? nowTime
  15842. };
  15843. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>()
  15844. .SetColumns(it => it.CityIntervalFeeDetails == info)
  15845. .Where(x => x.Id == draftInfo.Id)
  15846. .ExecuteCommandAsync();
  15847. if (upd < 1)
  15848. {
  15849. return Ok(JsonView(false));
  15850. }
  15851. //返回参数处理
  15852. var label = new StringBuilder();
  15853. if (dto.APTFeeDetails.Any())
  15854. {
  15855. var ovIds = dto.APTFeeDetails.Select(x => x.OvId).ToList();
  15856. var areas = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  15857. .LeftJoin<Res_OverseaVehicle>((ovtp, ov) => ovtp.OvId == ov.Id)
  15858. .Where((ovtp, ov) => ovtp.IsDel == 0 && ovIds.Contains(ovtp.Id))
  15859. .Select((ovtp, ov) => new
  15860. {
  15861. ovtp.Id,
  15862. ov.CountryName,
  15863. ov.CityName
  15864. })
  15865. .ToListAsync();
  15866. if (areas.Any())
  15867. {
  15868. var items = dto.APTFeeDetails
  15869. .Select(item =>
  15870. {
  15871. var areaInfo = areas.FirstOrDefault(x => x.Id == item.OvId);
  15872. if (areaInfo == null) return null;
  15873. return areaInfo.CountryName == areaInfo.CityName
  15874. ? $"{areaInfo.CountryName}({item.Quote:#0.00} CNY)"
  15875. : $"{areaInfo.CountryName}-{areaInfo.CityName}({item.Quote:#0.00} CNY)";
  15876. })
  15877. .Where(item => item != null)
  15878. .ToList();
  15879. string areaLabel = $"接送机({string.Join("、", items)});";
  15880. label.AppendLine(areaLabel);
  15881. }
  15882. }
  15883. if (dto.PullCartFeeDetails.Any())
  15884. {
  15885. var amounts = dto.PullCartFeeDetails.Select(item => $"{item.Quote:#0.00}");
  15886. string subLabel = $"拉车({string.Join("、", amounts)});";
  15887. label.AppendLine(subLabel);
  15888. }
  15889. if (dto.TrainFeeDetails.Any())
  15890. {
  15891. var amounts = dto.TrainFeeDetails.Select(item => $"{item.Quote:#0.00}");
  15892. string subLabel = $"火车票({string.Join("、", amounts)});";
  15893. label.AppendLine(subLabel);
  15894. }
  15895. if (dto.CityAirTicketFeeDetails.Any())
  15896. {
  15897. var amounts = dto.CityAirTicketFeeDetails.Select(item => $"{item.Quote:#0.00}");
  15898. string subLabel = $"城市机票({string.Join("、", amounts)});";
  15899. label.AppendLine(subLabel);
  15900. }
  15901. //费用
  15902. decimal quote = (dto.APTFeeTotal + dto.PullCartFeeTotal + dto.TrainFeeTotal + dto.CityAirTicketFeeTotal).ConvertToDecimal1();
  15903. decimal jjcQuote = quote;
  15904. decimal gwcQuote = quote;
  15905. decimal tdcQuote = quote;
  15906. var view = new
  15907. {
  15908. label = label.ToString(),
  15909. jjcQuote,
  15910. gwcQuote,
  15911. tdcQuote
  15912. };
  15913. return Ok(JsonView(view));
  15914. }
  15915. #endregion
  15916. /// <summary>
  15917. /// 团组模块 - 出入境费用-草稿
  15918. /// Info
  15919. /// </summary>
  15920. /// <returns></returns>
  15921. [HttpPost]
  15922. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Details)]
  15923. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15924. public async Task<IActionResult> EnterExitCostDraftInfoById(EnterExitCostDraftInfoByIdDto dto)
  15925. {
  15926. return Ok(await _enterExitCostDraftRep.EnterExitCostDraftInfoById(dto));
  15927. }
  15928. /// <summary>
  15929. /// 团组模块 - 出入境费用-草稿
  15930. /// 设置view权限
  15931. /// </summary>
  15932. /// <returns></returns>
  15933. [HttpPost]
  15934. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15935. public async Task<IActionResult> EnterExitCostDraftSetViewPermissiion(EnterExitCostDraftSetViewPermissiionDto dto)
  15936. {
  15937. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15938. if (dto.DraftId < 1) return Ok(JsonView(false, "请传入有效的DraftId;"));
  15939. if (dto.UserIds.Length < 1) return Ok(JsonView(false, "请传入有效的userId;"));
  15940. var permissions = new List<Grp_EnterExitCostDraftPermission>();
  15941. foreach (var userId in dto.UserIds)
  15942. {
  15943. permissions.Add(new Grp_EnterExitCostDraftPermission { Permission = 1, DraftId = dto.DraftId, UserId = userId, CreateUserId = dto.CurrUserId });
  15944. }
  15945. if (permissions.Any())
  15946. {
  15947. _sqlSugar.BeginTran();
  15948. try
  15949. {
  15950. await _sqlSugar.Deleteable<Grp_EnterExitCostDraftPermission>().Where(it => it.DraftId == dto.DraftId).ExecuteCommandAsync();
  15951. var result = await _sqlSugar.Insertable(permissions).ExecuteCommandAsync();
  15952. if (result < 1)
  15953. {
  15954. _sqlSugar.RollbackTran();
  15955. return Ok(JsonView(false));
  15956. }
  15957. }
  15958. catch (Exception ex)
  15959. {
  15960. _sqlSugar.RollbackTran();
  15961. return Ok(JsonView(false, ex.Message));
  15962. }
  15963. _sqlSugar.CommitTran();
  15964. return Ok(JsonView(true));
  15965. }
  15966. return Ok(JsonView(false));
  15967. }
  15968. /// <summary>
  15969. /// 团组模块 - 出入境费用-草稿
  15970. /// Add And Update
  15971. /// </summary>
  15972. /// <returns></returns>
  15973. [HttpPost]
  15974. [ApiLog("Grp_EnterExitCostDraft", OperationEnum.Add)]
  15975. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15976. public async Task<IActionResult> EnterExitCostDraftOp(EnterExitCostDraftOpDto dto)
  15977. {
  15978. var data = await _enterExitCostDraftRep.EnterExitCostDraftOp(dto);
  15979. if (data.Code != 0)
  15980. {
  15981. return Ok(JsonView(false, data.Msg));
  15982. }
  15983. int sign = (int)data.Data.GetType().GetProperty("sign").GetValue(data.Data, null);
  15984. //汇率信息记录
  15985. await GeneralMethod.RateRecordSave(dto.UserId, sign, "出入境费用");
  15986. return Ok(JsonView(true, data.Msg, data.Data));
  15987. }
  15988. /// <summary>
  15989. /// 团组模块 - 出入境费用-草稿
  15990. /// File downlaod
  15991. /// </summary>
  15992. /// <param name="dto"></param>
  15993. /// <returns></returns>
  15994. [HttpPost]
  15995. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Download)]
  15996. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15997. public async Task<IActionResult> EnterExitCostDraftDownload(EnterExitCostDraftDownloadDto dto)
  15998. {
  15999. try
  16000. {
  16001. var id = dto.Id;
  16002. if (id < 1) return Ok(JsonView(400, "请传入有效的DiId参数;", ""));
  16003. if (dto.ExportType < 1) return Ok(JsonView(400, "请传入有效的ExportType参数; 1 明细表 2 表格", ""));
  16004. if (dto.SubTypeId < 1) return Ok(JsonView(400, @"请传入有效的SubTypeId参数;
  16005. 1 明细表 --> 1005(默认明细表) 1006(因公出国(境)经费测算明细表) 1007(四川省商务厅出国经费财政先行审核表)
  16006. 2 表格 --> 1008(派员单位出(境)任务和预算审批意见表) 1009(省级单位出(境)经费报销单)
  16007. 3 团组成员名单 1 团组成员名单", ""));
  16008. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(it => it.IsDel == 0 && it.Id == id).OrderByDescending(x => x.CreateTime).First();
  16009. if (_EnterExitCosts == null) return Ok(JsonView(400, "未填写出入境费用-草稿;", ""));
  16010. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCostDraft>().Where(it => it.IsDel == 0 && it.ParentId == id).ToList();
  16011. var countryIds = _DayAndCosts.Select(x => x.NationalTravelFeeId).ToList();
  16012. var nationalTravelFeeData = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0 && countryIds.Contains(it.Id)).ToList();
  16013. var enterExitCostCurrencys = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(_EnterExitCosts.CurrencyRemark);
  16014. //数据源
  16015. var dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  16016. var dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  16017. var dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  16018. var dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  16019. var dac5 = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>()
  16020. .LeftJoin<Sys_SetData>((x, a) => a.IsDel == 0 && a.Id == x.SetDataId)
  16021. .LeftJoin<Sys_SetData>((x, a, b) => b.IsDel == 0 && b.Id == x.Currency)
  16022. .Where((x, a, b) => x.IsDel == 0 && x.ParentId == id)
  16023. .Select((x, a, b) => new
  16024. {
  16025. x.Index,
  16026. itemName = a.Name,
  16027. CurrencyStr = b.Name,
  16028. x.Cost,
  16029. x.SubTotal,
  16030. x.Remark
  16031. })
  16032. .OrderBy((x) => x.Index)
  16033. .ToList(); //其他款项费用
  16034. var _CurrDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  16035. var peiceItemCurrencys = new List<string>();
  16036. if (_DayAndCosts.Any())
  16037. {
  16038. var currencyIds = _DayAndCosts.Select(x => x.Currency).Distinct().ToList();
  16039. if (currencyIds.Any()) peiceItemCurrencys.AddRange(_CurrDatas.Where(x => currencyIds.Contains(x.Id)).Select(x => x.Name).ToList());
  16040. }
  16041. if (dac5.Any()) peiceItemCurrencys.AddRange(dac5.Select(x => x.CurrencyStr).Distinct().ToList());
  16042. var peiceItemCurrencyInfos = new List<CurrencyInfo>();
  16043. if (enterExitCostCurrencys.Any() && peiceItemCurrencys.Any())
  16044. {
  16045. peiceItemCurrencyInfos = enterExitCostCurrencys.Where(x => peiceItemCurrencys.Contains(x.CurrencyCode)).ToList();
  16046. }
  16047. var threeCodes = _sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList();
  16048. var placeData = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  16049. var rateDatas = await _EnterExitCosts.CurrencyRemark.SplitExchangeRate();
  16050. if (dto.ExportType == 1) //明细表
  16051. {
  16052. if (dto.SubTypeId == 1005) //1005(默认明细表)
  16053. {
  16054. //获取模板
  16055. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/出入境费用表模板.docx");
  16056. //载入模板
  16057. Document doc = new Document(tempPath);
  16058. DocumentBuilder builder = new DocumentBuilder(doc);
  16059. //利用键值对存放数据
  16060. Dictionary<string, string> dic = new Dictionary<string, string>();
  16061. decimal stayFeeTotal = _EnterExitCosts.ChoiceThree == 1 ? _DayAndCosts.Where(it => it.Type == 1).Sum(it => it.SubTotal) : 0.00M; // 住宿费
  16062. decimal mealsFeeTotal = _EnterExitCosts.ChoiceFour == 1 ? _DayAndCosts.Where(it => it.Type == 2).Sum(it => it.SubTotal) : 0.00M; // 伙食费费
  16063. decimal miscellaneousFeeTotal = _EnterExitCosts.ChoiceFive == 1 ? _DayAndCosts.Where(it => it.Type == 3).Sum(it => it.SubTotal) : 0.00M; // 公杂费
  16064. decimal tainFeeTotal = _EnterExitCosts.ChoiceSix == 1 ? _DayAndCosts.Where(it => it.Type == 4).Sum(it => it.SubTotal) : 0.00M; // 培训费
  16065. decimal otherPriceTotal = _EnterExitCosts.OtherExpenses_Checked == 1 ? dac5.Sum(x => x.SubTotal) : 0.00M; //其他费用
  16066. decimal insidePayTotal = _EnterExitCosts.ChoiceOne == 1 ? _EnterExitCosts.InsidePay : 0.00M;
  16067. //境内费用(其他费用)
  16068. if (_EnterExitCosts.ChoiceOne == 1)
  16069. {
  16070. string row1_1 = "";
  16071. if (_EnterExitCosts.Visa > 0)
  16072. {
  16073. //insidePayTotal += _EnterExitCosts.Visa;
  16074. row1_1 = $"签证费:{_EnterExitCosts.Visa.ToString("#0.00")} 人民币/人";
  16075. //if (!string.IsNullOrEmpty(_EnterExitCosts.VisaRemark))
  16076. //{
  16077. // row1_1 += $"\t签证费用描述: {_EnterExitCosts.VisaRemark} 人民币/人";
  16078. //}
  16079. }
  16080. string row1_2 = "";
  16081. if (_EnterExitCosts.YiMiao > 0)
  16082. {
  16083. //insidePayTotal += _EnterExitCosts.YiMiao;
  16084. row1_2 += $"疫苗费:{_EnterExitCosts.YiMiao.ToString("#0.00")} 人民币/人";
  16085. }
  16086. if (_EnterExitCosts.HeSuan > 0)
  16087. {
  16088. //insidePayTotal += _EnterExitCosts.HeSuan;
  16089. row1_2 += $"核酸检测费:{_EnterExitCosts.HeSuan.ToString("#0.00")} 人民币/人";
  16090. }
  16091. if (_EnterExitCosts.Service > 0)
  16092. {
  16093. //insidePayTotal += _EnterExitCosts.Service;
  16094. row1_2 += $"服务费:{_EnterExitCosts.Service.ToString("#0.00")} 人民币/人";
  16095. }
  16096. string row1_3 = "";
  16097. if (_EnterExitCosts.Safe > 0)
  16098. {
  16099. //insidePayTotal += _EnterExitCosts.Safe;
  16100. row1_3 += $"保险费:{_EnterExitCosts.Safe.ToString("#0.00")} 人民币/人";
  16101. }
  16102. if (_EnterExitCosts.Ticket > 0)
  16103. {
  16104. //insidePayTotal += _EnterExitCosts.Ticket;
  16105. row1_3 += $"参展门票:{_EnterExitCosts.Ticket.ToString("#0.00")} 人民币/人";
  16106. }
  16107. string row1 = "";
  16108. if (!string.IsNullOrEmpty(row1_1)) row1 += $"{row1_1}\r\n";
  16109. if (!string.IsNullOrEmpty(row1_2)) row1 += $"{row1_2}\r\n";
  16110. if (!string.IsNullOrEmpty(row1_3)) row1 += $"{row1_3}\r\n";
  16111. row1 += $"备注:{_EnterExitCosts.Remark}";
  16112. dic.Add("InsidePay", insidePayTotal.ToString("#0.00"));
  16113. dic.Add("Row1Str", row1);
  16114. }
  16115. string airTotalStr = string.Empty,
  16116. airPriceStr = string.Empty;
  16117. //经济舱
  16118. if (_EnterExitCosts.SumJJC == 1)
  16119. {
  16120. airTotalStr += $"{_EnterExitCosts.OutsideJJPay.ToString("#0.00")}元/人(经济舱)";
  16121. airPriceStr += $"{_EnterExitCosts.AirJJ.ToString("#0.00")}元/人(经济舱)";
  16122. }
  16123. //公务舱
  16124. if (_EnterExitCosts.SumGWC == 1)
  16125. {
  16126. airTotalStr += $" {_EnterExitCosts.OutsideGWPay.ToString("#0.00")} 元/人(公务舱)";
  16127. airPriceStr += $" {_EnterExitCosts.AirGW.ToString("#0.00")} 元/人(公务舱)";
  16128. }
  16129. //头等舱
  16130. if (_EnterExitCosts.SumTDC == 1)
  16131. {
  16132. airTotalStr += $" {_EnterExitCosts.OutsideTDPay.ToString("#0.00")} 元/人(头等舱)";
  16133. airPriceStr += $" {_EnterExitCosts.AirTD.ToString("#0.00")} 元/人(头等舱)";
  16134. }
  16135. //汇率描述
  16136. string rateStr = "";
  16137. if (peiceItemCurrencyInfos.Any())
  16138. {
  16139. rateStr = "\r\n汇率描述:";
  16140. foreach (var item in peiceItemCurrencyInfos)
  16141. {
  16142. rateStr += $"{item.CurrencyName}({item.CurrencyCode}):{item.Rate.ToString("#0.0000")} ";
  16143. }
  16144. }
  16145. string twoItemRemark = "备注:";
  16146. if (!string.IsNullOrEmpty(_EnterExitCosts.TwoItemRemark)) twoItemRemark += _EnterExitCosts.TwoItemRemark;
  16147. if (!string.IsNullOrEmpty(rateStr)) twoItemRemark += rateStr;
  16148. dic.Add("AirTotalStr", airTotalStr);
  16149. dic.Add("AirPriceStr", airPriceStr);
  16150. dic.Add("CityTranffic", _EnterExitCosts.CityTranffic.ToString("#0.00"));
  16151. dic.Add("TwoItemRemark", twoItemRemark);
  16152. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  16153. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  16154. int table1Row = 0,
  16155. table2Row = 0,
  16156. table3Row = 0,
  16157. table4Row = 0,
  16158. table5Row = 0;
  16159. //住宿费
  16160. if (_EnterExitCosts.ChoiceThree == 1)
  16161. {
  16162. dic.Add("SubZS", stayFeeTotal.ToString("#0.00"));
  16163. table1Row = dac1.Count;
  16164. #region 填充word表格内容
  16165. for (int i = 0; i < dac1.Count; i++)
  16166. {
  16167. var dac = dac1[i];
  16168. if (dac == null) continue;
  16169. builder.MoveToCell(0, i, 0, 0);
  16170. builder.Write("第" + dac.Days.ToString() + "晚:");
  16171. builder.MoveToCell(0, i, 1, 0);
  16172. //builder.Write(placeData.Find(it => it.Id == dac.NationalTravelFeeId)?.Country ?? "Unknown");
  16173. //builder.Write(dac.Place == null ? "" : dac.Place);
  16174. builder.Write(GetEnterExitCostDraftExportCity(placeData, dac.NationalTravelFeeId));
  16175. builder.MoveToCell(0, i, 2, 0);
  16176. builder.Write("费用标准:");
  16177. string curr = "";
  16178. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  16179. if (currData != null)
  16180. {
  16181. curr = currData.Name;
  16182. }
  16183. builder.MoveToCell(0, i, 3, 0);
  16184. builder.Write(dac.Cost.ToString("#0.00") + curr);
  16185. builder.MoveToCell(0, i, 4, 0);
  16186. builder.Write("费用小计:");
  16187. builder.MoveToCell(0, i, 5, 0);
  16188. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  16189. }
  16190. #endregion
  16191. }
  16192. else dic.Add("SubZS", "0.00");
  16193. if (table1 != null && table1.Rows.Count > 0)
  16194. {
  16195. //删除多余行
  16196. while (table1.Rows.Count > table1Row)
  16197. {
  16198. table1.Rows.RemoveAt(table1Row);
  16199. }
  16200. }
  16201. //伙食费
  16202. Aspose.Words.Tables.Table table2 = allTables[1] as Aspose.Words.Tables.Table;
  16203. if (_EnterExitCosts.ChoiceFour == 1)
  16204. {
  16205. dic.Add("SubHS", mealsFeeTotal.ToString("#0.00"));
  16206. table2Row = dac2.Count;
  16207. #region 填充word表格内容
  16208. for (int i = 0; i < dac2.Count; i++)
  16209. {
  16210. var dac = dac2[i];
  16211. if (dac == null) continue;
  16212. builder.MoveToCell(1, i, 0, 0);
  16213. builder.Write("第" + dac.Days.ToString() + "天:");
  16214. builder.MoveToCell(1, i, 1, 0);
  16215. builder.Write(GetEnterExitCostDraftExportCity(placeData, dac.NationalTravelFeeId));
  16216. builder.MoveToCell(1, i, 2, 0);
  16217. builder.Write("费用标准:");
  16218. string curr = "";
  16219. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  16220. if (currData != null)
  16221. {
  16222. curr = currData.Name;
  16223. }
  16224. builder.MoveToCell(1, i, 3, 0);
  16225. builder.Write(dac.Cost.ToString("#0.00") + curr);
  16226. builder.MoveToCell(1, i, 4, 0);
  16227. builder.Write("费用小计:");
  16228. builder.MoveToCell(1, i, 5, 0);
  16229. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  16230. }
  16231. #endregion
  16232. }
  16233. else dic.Add("SubHS", "0.00");
  16234. if (table2 != null && table2.Rows.Count > 0)
  16235. {
  16236. //删除多余行
  16237. while (table2.Rows.Count > table2Row)
  16238. {
  16239. table2.Rows.RemoveAt(table2Row);
  16240. }
  16241. }
  16242. //公杂费
  16243. Aspose.Words.Tables.Table table3 = allTables[2] as Aspose.Words.Tables.Table;
  16244. if (_EnterExitCosts.ChoiceFive == 1)
  16245. {
  16246. dic.Add("SubGZF", miscellaneousFeeTotal.ToString("#0.00"));
  16247. table3Row = dac3.Count;
  16248. #region 填充word表格内容
  16249. for (int i = 0; i < dac3.Count; i++)
  16250. {
  16251. var dac = dac3[i];
  16252. if (dac == null) continue;
  16253. builder.MoveToCell(2, i, 0, 0);
  16254. builder.Write("第" + dac.Days.ToString() + "天:");
  16255. builder.MoveToCell(2, i, 1, 0);
  16256. builder.Write(GetEnterExitCostDraftExportCity(placeData, dac.NationalTravelFeeId));
  16257. builder.MoveToCell(2, i, 2, 0);
  16258. builder.Write("费用标准:");
  16259. string curr = "";
  16260. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  16261. if (currData != null)
  16262. {
  16263. curr = currData.Name;
  16264. }
  16265. builder.MoveToCell(2, i, 3, 0);
  16266. builder.Write(dac.Cost.ToString("#0.00") + curr);
  16267. builder.MoveToCell(2, i, 4, 0);
  16268. builder.Write("费用小计:");
  16269. builder.MoveToCell(2, i, 5, 0);
  16270. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  16271. }
  16272. //删除多余行
  16273. while (table3.Rows.Count > table3Row)
  16274. {
  16275. table3.Rows.RemoveAt(table3Row);
  16276. }
  16277. #endregion
  16278. }
  16279. else dic.Add("SubGZF", "0.00");
  16280. if (table3 != null && table3.Rows.Count > 0)
  16281. {
  16282. //删除多余行
  16283. while (table3.Rows.Count > table3Row)
  16284. {
  16285. table3.Rows.RemoveAt(table3Row);
  16286. }
  16287. }
  16288. //培训费
  16289. Aspose.Words.Tables.Table table4 = allTables[3] as Aspose.Words.Tables.Table;
  16290. if (_EnterExitCosts.ChoiceSix == 1)
  16291. {
  16292. string pxStr = $"六、培训费合计: {tainFeeTotal.ToString("#0.00")} 元/人";
  16293. dic.Add("SubPX", pxStr);
  16294. table4Row = dac4.Count;
  16295. #region 填充word表格内容
  16296. for (int i = 0; i < dac4.Count; i++)
  16297. {
  16298. var dac = dac4[i];
  16299. if (dac == null) continue;
  16300. builder.MoveToCell(3, i, 0, 0);
  16301. builder.Write("第" + dac.Days.ToString() + "天:");
  16302. builder.MoveToCell(3, i, 1, 0);
  16303. builder.Write(GetEnterExitCostDraftExportCity(placeData, dac.NationalTravelFeeId));
  16304. builder.MoveToCell(3, i, 2, 0);
  16305. builder.Write("费用标准:");
  16306. string curr = "";
  16307. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  16308. if (currData != null)
  16309. {
  16310. curr = currData.Name;
  16311. }
  16312. builder.MoveToCell(3, i, 3, 0);
  16313. builder.Write(dac.Cost.ToString("#0.00") + curr);
  16314. builder.MoveToCell(3, i, 4, 0);
  16315. builder.Write("费用小计:");
  16316. builder.MoveToCell(3, i, 5, 0);
  16317. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  16318. }
  16319. #endregion
  16320. }
  16321. //else dic.Add("SubPX", $"六、培训费合计: 0 元/人");
  16322. //删除多余行
  16323. if (table4 != null && table4.Rows.Count > 0)
  16324. {
  16325. while (table4.Rows.Count > table4Row)
  16326. {
  16327. table4.Rows.RemoveAt(table4Row);
  16328. }
  16329. }
  16330. //其他费用
  16331. Aspose.Words.Tables.Table table5 = allTables[4] as Aspose.Words.Tables.Table;
  16332. if (_EnterExitCosts.OtherExpenses_Checked == 1)
  16333. {
  16334. string qtStr = $"七、其他费用合计: {otherPriceTotal.ToString("#0.00")} 元/人";
  16335. dic.Add("titleQi", qtStr);
  16336. table5Row = dac5.Count;
  16337. #region 填充word表格内容
  16338. for (int i = 0; i < dac5.Count; i++)
  16339. {
  16340. var dac = dac5[i];
  16341. if (dac == null) continue;
  16342. builder.MoveToCell(4, i, 0, 0);
  16343. builder.Write("第" + dac.Index.ToString() + "项:");
  16344. builder.MoveToCell(4, i, 1, 0);
  16345. builder.Write(dac.itemName);
  16346. builder.MoveToCell(4, i, 2, 0);
  16347. builder.Write("费用标准:");
  16348. builder.MoveToCell(4, i, 3, 0);
  16349. builder.Write(dac.Cost.ToString("#0.00") + dac.CurrencyStr);
  16350. builder.MoveToCell(4, i, 4, 0);
  16351. builder.Write("费用小计:");
  16352. builder.MoveToCell(4, i, 5, 0);
  16353. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  16354. builder.MoveToCell(4, i, 6, 0);
  16355. builder.Write("备注:");
  16356. builder.MoveToCell(4, i, 7, 0);
  16357. builder.Write(dac.Remark);
  16358. }
  16359. #endregion
  16360. }
  16361. //else dic.Add("SubQT", "七、其他费用合计: 0 元/人");
  16362. if (table5 != null && table5.Rows.Count > 0)
  16363. {
  16364. //删除多余行
  16365. while (table5.Rows.Count > table5Row)
  16366. {
  16367. table5.Rows.RemoveAt(table5Row);
  16368. }
  16369. }
  16370. //加上其他费用
  16371. decimal otherFeeTotal = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + otherPriceTotal;
  16372. decimal subJJC = 0.00M,
  16373. subGWC = 0.00M,
  16374. subTDC = 0.00M;
  16375. //全部费用总计: 元 / 人(经济舱) 元 / 人(公务舱) 元 / 人(头等舱)
  16376. string totalLabel = string.Format("全部费用总计:");
  16377. //经济舱
  16378. if (_EnterExitCosts.SumJJC == 1)
  16379. {
  16380. subJJC = otherFeeTotal + _EnterExitCosts.OutsideJJPay;
  16381. totalLabel += $"{subJJC.ToString("#0.00")} 元/人(经济舱)";
  16382. }
  16383. //公务舱
  16384. if (_EnterExitCosts.SumGWC == 1)
  16385. {
  16386. subGWC = otherFeeTotal + _EnterExitCosts.OutsideGWPay;
  16387. totalLabel += $"{subGWC.ToString("#0.00")} 元/人(公务舱)";
  16388. }
  16389. //头等舱
  16390. if (_EnterExitCosts.SumTDC == 1)
  16391. {
  16392. subTDC = otherFeeTotal + _EnterExitCosts.OutsideTDPay;
  16393. totalLabel += $"{subTDC.ToString("#0.00")} 元/人(头等舱)";
  16394. }
  16395. //TotalLabel
  16396. dic.Add("TotalLabel", totalLabel);
  16397. #region 填充word模板书签内容
  16398. foreach (var key in dic.Keys)
  16399. {
  16400. Bookmark bookmark = doc.Range.Bookmarks[key];
  16401. if (bookmark != null)
  16402. {
  16403. builder.MoveToBookmark(key);
  16404. builder.Write(dic[key]);
  16405. }
  16406. }
  16407. #endregion
  16408. //文件名
  16409. string strFileName = $"{_EnterExitCosts.DraftName}_出入境费用-草稿{Guid.NewGuid().ToString()}.docx";
  16410. strFileName = CommonFun.ValidFileName(strFileName);
  16411. AsposeHelper.removewatermark_v2180();
  16412. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  16413. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  16414. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  16415. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  16416. }
  16417. else if (dto.SubTypeId == 1006)//1006(因公出国(境)经费测算明细表)
  16418. {
  16419. //获取模板
  16420. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/因公出国(境)经费测算明细表.docx");
  16421. //载入模板
  16422. Document doc = new Document(tempPath);
  16423. DocumentBuilder builder = new DocumentBuilder(doc);
  16424. Dictionary<string, string> dic = new Dictionary<string, string>();
  16425. string returnCodeLabel = string.Empty;
  16426. if (nationalTravelFeeData.Any())
  16427. {
  16428. List<string> list = new List<string>();
  16429. foreach (var item in nationalTravelFeeData)
  16430. {
  16431. list.Add($"{item.Country}({item.City})");
  16432. }
  16433. list = list.Distinct().ToList();
  16434. returnCodeLabel = string.Join("-", list).TrimEnd('-');
  16435. }
  16436. var countryLabel = string.Empty;
  16437. var countryData = nationalTravelFeeData.Select(x => x.Country).Distinct().ToList();
  16438. if (countryData.Any())
  16439. {
  16440. countryLabel = string.Join("、", countryData);
  16441. }
  16442. dic.Add("ReturnCodeAir", returnCodeLabel);
  16443. dic.Add("VisitStartDate", "-");
  16444. dic.Add("VisitEndDate", "-");
  16445. dic.Add("Day", "-");
  16446. dic.Add("VisitCountry", countryLabel);
  16447. dic.Add("ClientUnit", "-");
  16448. //var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  16449. //dic.Add("Names", Names);
  16450. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  16451. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  16452. decimal dac1totalPrice = 0.00M;
  16453. int accommodationStartIndex = 6, foodandotherStartIndex = 22;
  16454. foreach (var dac in dac1)
  16455. {
  16456. if (dac.SubTotal == 0.00M)
  16457. {
  16458. continue;
  16459. }
  16460. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  16461. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  16462. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  16463. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  16464. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  16465. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  16466. builder.Write(currency);//币种
  16467. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  16468. builder.Write(dac.Cost.ToString("#0.00"));//标准
  16469. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  16470. builder.Write("");//人数
  16471. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  16472. builder.Write("");//天数
  16473. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  16474. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  16475. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  16476. decimal rate = 0.00M;
  16477. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  16478. builder.Write(rate.ToString("#0.0000"));//汇率
  16479. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  16480. decimal rbmPrice = dac.SubTotal;
  16481. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  16482. accommodationStartIndex++;
  16483. dac1totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  16484. }
  16485. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  16486. for (int i = 21; i > (dac1.Count == 0 ? 1 : dac1.Count) + 6; i--)
  16487. {
  16488. table1.Rows.RemoveAt(i - 1);
  16489. foodandotherStartIndex--;
  16490. }
  16491. if (dac2.Count == dac3.Count)//国家 币种 金额
  16492. {
  16493. for (int i = 0; i < dac2.Count; i++)
  16494. {
  16495. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  16496. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  16497. }
  16498. }
  16499. decimal dac2totalPrice = 0.00M;
  16500. foreach (var dac in dac2)
  16501. {
  16502. if (dac.SubTotal == 0)
  16503. {
  16504. continue;
  16505. }
  16506. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  16507. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  16508. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  16509. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  16510. builder.Write(currency);//币种
  16511. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  16512. builder.Write(dac.Cost.ToString("#0.00"));//标准
  16513. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  16514. builder.Write("");//人数
  16515. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  16516. builder.Write("");//天数
  16517. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  16518. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  16519. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  16520. decimal rate = 0.00M;
  16521. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  16522. builder.Write(rate.ToString("#0.0000"));//汇率
  16523. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  16524. decimal rbmPrice = dac.SubTotal;
  16525. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  16526. foodandotherStartIndex++;
  16527. dac2totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  16528. }
  16529. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  16530. for (int i = foodandotherStartIndex + (15 - dac2.Count); i > (dac2.Count == 0 ? 1 : 0) + foodandotherStartIndex; i--)
  16531. {
  16532. table1.Rows.RemoveAt(i - 1);
  16533. }
  16534. dic.Add("CityTranffic", _EnterExitCosts.CityTranffic.ToString("#0.00"));
  16535. string otherFeeStr = "";
  16536. if (_EnterExitCosts.Visa > 0) otherFeeStr += $"签证费:{_EnterExitCosts.Visa.ToString("#0.00")} 元,";
  16537. if (_EnterExitCosts.Safe > 0) otherFeeStr += $"保险费:{_EnterExitCosts.Safe.ToString("#0.00")} 元,";
  16538. if (_EnterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费:{_EnterExitCosts.Ticket.ToString("#0.00")} 元,";
  16539. #region 其他款项费用 增加位置:模板第6项其他费用字符串追加
  16540. foreach (var otherInfo in dac5)
  16541. {
  16542. otherFeeStr += $"{otherInfo.itemName}:{otherInfo.SubTotal.ToString("#0.00")} 元,";
  16543. }
  16544. #endregion
  16545. if (otherFeeStr.Length > 0)
  16546. {
  16547. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  16548. otherFeeStr = $"({otherFeeStr})";
  16549. dic.Add("OtherFeeStr", otherFeeStr);
  16550. }
  16551. //总计
  16552. decimal allPrice = dac1totalPrice + dac2totalPrice + _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket;
  16553. //国际旅费
  16554. string outsideAir = string.Empty;
  16555. string allPriceAir = string.Empty;
  16556. if (_EnterExitCosts.SumJJC == 1)
  16557. {
  16558. outsideAir += string.Format(@"经济舱:{0} 元/人;", _EnterExitCosts.AirJJ.ToString("#0.00"));
  16559. allPriceAir += string.Format(@"经济舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideJJPay).ToString("#0.00"));
  16560. }
  16561. if (_EnterExitCosts.SumGWC == 1)
  16562. {
  16563. outsideAir += string.Format(@"公务舱:{0} 元/人;", _EnterExitCosts.AirGW.ToString("#0.00"));
  16564. allPriceAir += string.Format(@"公务舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  16565. }
  16566. if (_EnterExitCosts.SumTDC == 1)
  16567. {
  16568. outsideAir += string.Format(@"头等舱:{0} 元/人;", _EnterExitCosts.AirTD.ToString("#0.00"));
  16569. allPriceAir += string.Format(@"头等舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideTDPay).ToString("#0.00"));
  16570. }
  16571. dic.Add("InTravelPrice", $"({outsideAir})");
  16572. dic.Add("FinalSumPrice", $"({allPriceAir})");
  16573. //dic.Add("VisaPay", _EnterExitCosts.Visa.ToString("#0.00"));
  16574. //dic.Add("SafePay", _EnterExitCosts.Safe.ToString("#0.00"));
  16575. //dic.Add("YiMiao", _EnterExitCosts.YiMiao.ToString("#0.00"));
  16576. foreach (var key in dic.Keys)
  16577. {
  16578. builder.MoveToBookmark(key);
  16579. builder.Write(dic[key]);
  16580. }
  16581. //模板文件名
  16582. string strFileName = $"草稿_{_EnterExitCosts.DraftName}_因公出国(境)经费测算明细表{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
  16583. strFileName = CommonFun.ValidFileName(strFileName);
  16584. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  16585. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  16586. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  16587. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  16588. }
  16589. else if (dto.SubTypeId == 1007) //1007(四川省商务厅出国经费财政先行审核表)
  16590. {
  16591. //获取模板
  16592. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/四川省商务厅出国经费财政先行审核表.xls");
  16593. //载入模板
  16594. WorkbookDesigner designer = new WorkbookDesigner();
  16595. designer.Workbook = new Workbook(tempPath);
  16596. Dictionary<string, string> dic = new Dictionary<string, string>();
  16597. string returnCodeLabel = string.Empty;
  16598. if (nationalTravelFeeData.Any())
  16599. {
  16600. List<string> list = new List<string>();
  16601. foreach (var item in nationalTravelFeeData)
  16602. {
  16603. list.Add($"{item.Country}({item.City})");
  16604. }
  16605. list = list.Distinct().ToList();
  16606. returnCodeLabel = string.Join("-", list).TrimEnd('-');
  16607. }
  16608. var countryLabel = string.Empty;
  16609. var countryData = nationalTravelFeeData.Select(x => x.Country).Distinct().ToList();
  16610. if (countryData.Any())
  16611. {
  16612. countryLabel = string.Join("、", countryData);
  16613. }
  16614. dic.Add("ReturnCodeAir", returnCodeLabel);
  16615. dic.Add("VisitStartDate", "-");
  16616. dic.Add("VisitEndDate", "-");
  16617. dic.Add("Day", "0");
  16618. dic.Add("VisitCountry", countryLabel);
  16619. dic.Add("ClientUnit", "-");
  16620. designer.SetDataSource("ClientUnit", "-");
  16621. designer.SetDataSource("VisitCountry", countryLabel);
  16622. designer.SetDataSource("Group", "-");
  16623. designer.SetDataSource("ClientUnitTitle", "-");
  16624. designer.SetDataSource("Name", "-");
  16625. designer.SetDataSource("VisitStartDate", "-");
  16626. designer.SetDataSource("Day", "0");
  16627. designer.SetDataSource("ReturnCode", returnCodeLabel);
  16628. designer.SetDataSource("ReturnCodeAir", "-");
  16629. int startIndex = 10;
  16630. const int startIndexcopy = 10;
  16631. if (dac2.Count == dac3.Count)//国家 币种 金额
  16632. {
  16633. for (int i = 0; i < dac2.Count; i++)
  16634. {
  16635. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  16636. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  16637. }
  16638. }
  16639. DataTable dtdac1 = new DataTable();
  16640. List<string> place = new List<string>();
  16641. dtdac1.Columns.AddRange(new DataColumn[] {
  16642. new DataColumn(){ ColumnName = "city"},
  16643. new DataColumn(){ ColumnName = "curr"},
  16644. new DataColumn(){ ColumnName = "criterion"},
  16645. new DataColumn(){ ColumnName = "number",DataType = typeof(int)},
  16646. new DataColumn(){ ColumnName = "day",DataType = typeof(int)},
  16647. new DataColumn(){ ColumnName = "cost", DataType = typeof(decimal)},
  16648. new DataColumn(){ ColumnName = "rate", DataType = typeof(decimal) },
  16649. new DataColumn(){ ColumnName = "costRMB", DataType = typeof(decimal) },
  16650. });
  16651. DataTable dtdac2 = new DataTable();
  16652. dtdac2.Columns.AddRange(new DataColumn[] {
  16653. new DataColumn(){ ColumnName = "city"},
  16654. new DataColumn(){ ColumnName = "curr"},
  16655. new DataColumn(){ ColumnName = "criterion"},
  16656. new DataColumn(){ ColumnName = "number",DataType = typeof(int)},
  16657. new DataColumn(){ ColumnName = "day",DataType = typeof(int)},
  16658. new DataColumn(){ ColumnName = "cost", DataType = typeof(decimal)},
  16659. new DataColumn(){ ColumnName = "rate", DataType = typeof(decimal) },
  16660. new DataColumn(){ ColumnName = "costRMB",DataType = typeof(decimal)},
  16661. });
  16662. dtdac1.TableName = "tb1";
  16663. dtdac2.TableName = "tb2";
  16664. decimal dac1totalPrice = 0.00M, dac2totalPrice = 0.00M;
  16665. foreach (var item in dac1)
  16666. {
  16667. item.Place = GetEnterExitCostDraftExportCity(placeData, item.NationalTravelFeeId);
  16668. if (place.Contains(item.Place))
  16669. {
  16670. continue;
  16671. }
  16672. DataRow row = dtdac1.NewRow();
  16673. row["city"] = item.Place;
  16674. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  16675. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  16676. row["curr"] = currency;
  16677. row["rate"] = rate.ToString("#0.0000");
  16678. row["criterion"] = item.Cost.ToString("#0.00");
  16679. row["number"] = 1;
  16680. row["day"] = dac1.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  16681. //row["costRMB"] = rbmPrice;
  16682. dtdac1.Rows.Add(row);
  16683. place.Add(item.Place);
  16684. }
  16685. place = new List<string>();
  16686. foreach (var item in dac2)
  16687. {
  16688. item.Place = GetEnterExitCostDraftExportCity(placeData, item.NationalTravelFeeId);
  16689. if (place.Contains(item.Place))
  16690. {
  16691. continue;
  16692. }
  16693. DataRow row = dtdac2.NewRow();
  16694. row["city"] = item.Place;
  16695. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  16696. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  16697. row["curr"] = currency;
  16698. row["rate"] = rate.ToString("#0.0000");
  16699. row["criterion"] = item.Cost.ToString("#0.00");
  16700. row["number"] = 1;
  16701. row["day"] = dac2.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  16702. //row["cost"] = item.SubTotal;
  16703. //row["costRMB"] = rbmPrice;
  16704. dtdac2.Rows.Add(row);
  16705. place.Add(item.Place);
  16706. //dac2totalPrice += rbmPrice;
  16707. }
  16708. dac1totalPrice = dac1.Sum(it => it.SubTotal);
  16709. dac2totalPrice = dac2.Sum(it => it.SubTotal);
  16710. designer.SetDataSource("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  16711. designer.SetDataSource("dac2totalPrice", dac2totalPrice);
  16712. designer.SetDataSource("cityTranffic", @$"其中:国外城市间机票费: {_EnterExitCosts.CityTranffic:#0.00} 元");
  16713. designer.SetDataSource("sumCityTranffic", @$"{_EnterExitCosts.CityTranffic:#0.00} ");
  16714. string cell4Str1 = string.Empty;
  16715. if (_EnterExitCosts.SumJJC == 1) cell4Str1 += $"经济舱:{_EnterExitCosts.AirJJ:#0.00} 元/人;";
  16716. if (_EnterExitCosts.SumGWC == 1) cell4Str1 += $"公务舱:{_EnterExitCosts.AirGW:#0.00} 元/人;";
  16717. if (_EnterExitCosts.SumTDC == 1) cell4Str1 += $"公务舱:{_EnterExitCosts.AirTD:#0.00} 元/人;";
  16718. string cell4Str = $" 4.国际旅费:{cell4Str1}";
  16719. string cellStr = $" 5.其他费用(";
  16720. if (_EnterExitCosts.Visa > 0) cellStr += $"签证费:{_EnterExitCosts.Visa:#0.00}元,";
  16721. if (_EnterExitCosts.YiMiao > 0) cellStr += $"疫苗费:{_EnterExitCosts.YiMiao:#0.00}元,";
  16722. if (_EnterExitCosts.HeSuan > 0) cellStr += $"核酸费:{_EnterExitCosts.HeSuan:#0.00}元,";
  16723. if (_EnterExitCosts.Safe > 0) cellStr += $"保险费:{_EnterExitCosts.Safe:#0.00}元,";
  16724. if (_EnterExitCosts.Ticket > 0) cellStr += $"参展门票费:{_EnterExitCosts.Ticket:#0.00}元,";
  16725. if (_EnterExitCosts.Service > 0) cellStr += $"服务费:{_EnterExitCosts.Service:#0.00}元,";
  16726. #region 其他款项费用 增加位置:模板第5项其他费用字符串追加
  16727. var otherPriceTotal = dac5.Sum(x => x.SubTotal);
  16728. foreach (var otherInfo in dac5)
  16729. {
  16730. cellStr += $"{otherInfo.itemName}:{otherInfo.SubTotal:#0.00} 元,";
  16731. }
  16732. #endregion
  16733. if (cellStr.Length > 8)
  16734. {
  16735. cellStr = cellStr.Substring(0, cellStr.Length - 1);
  16736. }
  16737. cellStr += ")";
  16738. decimal otherFee = _EnterExitCosts.Visa + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.Service + otherPriceTotal;
  16739. decimal s = dac1totalPrice + dac2totalPrice + _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay + otherFee;
  16740. decimal pxFee = dac4.Sum(it => it.Cost);
  16741. decimal glvFee = _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay;
  16742. string celllastStr1 = "";
  16743. if (dac1totalPrice > 0) celllastStr1 += $"住宿费 {dac1totalPrice:#0.00} 元";
  16744. if (dac2totalPrice > 0) celllastStr1 += $",伙食费和公杂费 {dac2totalPrice:#0.00} 元";
  16745. if (pxFee > 0) celllastStr1 += $",培训费 {pxFee:#0.00} 元";
  16746. celllastStr1 += $",国际旅费 元";
  16747. if (otherFee > 0) celllastStr1 += $",其他费用 {otherFee:#0.00} 元";
  16748. string celllastStr = $" 经审核,{celllastStr1},本次出国经费预算合计为 元。其中:市本级安排 。";
  16749. designer.SetDataSource("cell4Str", cell4Str);
  16750. designer.SetDataSource("cellStr", cellStr);
  16751. designer.SetDataSource("cellSum", otherFee.ToString("#0.00"));
  16752. designer.SetDataSource("cellSum4", (_EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  16753. designer.SetDataSource("celllastStr", celllastStr);
  16754. Workbook wb = designer.Workbook;
  16755. var sheet = wb.Worksheets[0];
  16756. //绑定datatable数据集
  16757. designer.SetDataSource(dtdac1);
  16758. designer.SetDataSource(dtdac2);
  16759. designer.Process();
  16760. var rowStart = dtdac1.Rows.Count;
  16761. while (rowStart > 0)
  16762. {
  16763. sheet.Cells[startIndex, 8].Formula = $"=G{startIndex + 1} * H{startIndex + 1}";
  16764. sheet.Cells[startIndex, 6].Formula = $"=E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  16765. startIndex++;
  16766. rowStart--;
  16767. }
  16768. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + 1}: I{startIndex})";
  16769. startIndex += 1; //总计行
  16770. rowStart = dtdac2.Rows.Count;
  16771. while (rowStart > 0)
  16772. {
  16773. sheet.Cells[startIndex, 8].Formula = $"= G{startIndex + 1} * H{startIndex + 1}";
  16774. sheet.Cells[startIndex, 6].Formula = $"= E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  16775. startIndex++;
  16776. rowStart--;
  16777. }
  16778. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + dtdac1.Rows.Count + 2}: I{startIndex})";
  16779. wb.CalculateFormula(true);
  16780. //模板文件名
  16781. string strFileName = $"草稿_{_EnterExitCosts.DraftName}_四川省商务厅出国经费财政先行审核表{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  16782. designer.Workbook.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  16783. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  16784. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  16785. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  16786. }
  16787. else if (dto.SubTypeId == 1066) //成都市因公临时出国任务和预算审批意见表(外专培训团专用)
  16788. {
  16789. //获取模板
  16790. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/成都市因公临时出国任务和预算审批意见表.docx");
  16791. //载入模板
  16792. Document doc = new Document(tempPath);
  16793. DocumentBuilder builder = new DocumentBuilder(doc);
  16794. Dictionary<string, string> dic = new Dictionary<string, string>();
  16795. dic.Add("GroupName", "-");
  16796. dic.Add("ClientUnit", "-");
  16797. //string missionLeader = ""; //团负责人默认接团客户名单第一个人
  16798. //string missionLeaderJob = "";//负责人job
  16799. //int groupNumber = 0; //团人数
  16800. dic.Add("MissionLeader", "-"); //团负责人
  16801. dic.Add("MissionLeaderJob", "-"); //团负责人job
  16802. dic.Add("GroupNumber", "0"); //团人数
  16803. dic.Add("Day", "0");
  16804. dic.Add("CultivateDay", dac4.Count.ToString()); //培训天数
  16805. // dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  16806. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  16807. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  16808. decimal hotelFeeTotal = dac1.Sum(it => it.SubTotal);//住宿费
  16809. dic.Add("HotelFeeTotal", hotelFeeTotal.ToString("#0.00"));
  16810. decimal mealsFeeTotal = dac2.Sum(it => it.SubTotal);//伙食费
  16811. dic.Add("MealsFeeTotal", mealsFeeTotal.ToString("#0.00"));
  16812. decimal miscellaneousFeeTotal = dac3.Sum(it => it.SubTotal);//公杂费
  16813. dic.Add("MiscellaneousFeeTotal", miscellaneousFeeTotal.ToString("#0.00"));
  16814. decimal trainingFeeTotal = dac4.Sum(it => it.SubTotal);//培训费
  16815. dic.Add("TrainingFeeTotal", trainingFeeTotal.ToString("#0.00"));
  16816. decimal cityTranfficFeeToatal = _EnterExitCosts.CityTranffic; //城市区间交通费
  16817. dic.Add("CityTranfficFeeToatal", cityTranfficFeeToatal.ToString("#0.00"));//
  16818. //其他费用
  16819. decimal otherFeeTotal = _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Service + dac5.Sum(x => x.SubTotal);
  16820. dic.Add("OtherFeeTotal", otherFeeTotal.ToString("#0.00"));
  16821. //其他费用合计
  16822. decimal _otherFeeTotal = hotelFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + trainingFeeTotal + cityTranfficFeeToatal + otherFeeTotal;
  16823. decimal _jjcFeeToatal = _EnterExitCosts.AirJJ + _otherFeeTotal; //经济舱
  16824. decimal _gwcFeeToatal = _EnterExitCosts.AirGW + _otherFeeTotal; //公务舱
  16825. //公务舱合计
  16826. //国际旅费
  16827. //string outsideJJ = "";
  16828. //string allPriceJJ = "";
  16829. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 0)
  16830. {
  16831. dic.Add("AirFeeTotal", _EnterExitCosts.AirJJ.ToString("#0.00"));
  16832. dic.Add("FeeTotal", _jjcFeeToatal.ToString("#0.00"));
  16833. }
  16834. if (_EnterExitCosts.SumGWC == 1 && _EnterExitCosts.SumJJC == 0)
  16835. {
  16836. dic.Add("AirFeeTotal", _EnterExitCosts.AirGW.ToString("#0.00"));
  16837. dic.Add("FeeTotal", _gwcFeeToatal.ToString("#0.00"));
  16838. }
  16839. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 1)
  16840. {
  16841. string airFeeTotalStr = string.Format(@$"经济舱:{_EnterExitCosts.AirJJ:#0.00} 公务舱:{_EnterExitCosts.AirGW:#0.00}");
  16842. dic.Add("AirFeeTotal", airFeeTotalStr);
  16843. string feeTotalStr = string.Format(@$"经济舱:{_jjcFeeToatal:#0.00} 公务舱:{_gwcFeeToatal:#0.00}");
  16844. dic.Add("FeeTotal", feeTotalStr);
  16845. }
  16846. foreach (var key in dic.Keys)
  16847. {
  16848. builder.MoveToBookmark(key);
  16849. builder.Write(dic[key]);
  16850. }
  16851. //模板文件名
  16852. string strFileName = $"草稿_{_EnterExitCosts.DraftName}_成都市因公临时出国任务和预算审批意见表(外专培训团专用).docx";
  16853. strFileName = CommonFun.ValidFileName(strFileName);
  16854. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  16855. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  16856. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  16857. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  16858. }
  16859. }
  16860. else if (dto.ExportType == 2) //表格
  16861. {
  16862. return Ok(JsonView(400, "因需关联团组信息和客户信息,请在出入境费用明细里下载!", ""));
  16863. }
  16864. else if (dto.ExportType == 3)
  16865. {
  16866. return Ok(JsonView(400, "因需关联团组信息和客户信息,请在出入境费用明细里下载!", ""));
  16867. }
  16868. return Ok(JsonView(400, "只可导出明细表!", ""));
  16869. }
  16870. catch (Exception ex)
  16871. {
  16872. return Ok(JsonView(400, ex.Message, ""));
  16873. }
  16874. }
  16875. /// <summary>
  16876. /// 团组模块 - 出入境费用-草稿
  16877. /// 获取三公费用标准city
  16878. /// </summary>
  16879. /// <param name="placeData"></param>
  16880. /// <param name="nationalTravelFeeId"></param>
  16881. /// <returns></returns>
  16882. private string GetEnterExitCostDraftExportCity(List<Grp_NationalTravelFee> placeData, int nationalTravelFeeId)
  16883. {
  16884. string _city = string.Empty;
  16885. if (!placeData.Any()) return _city;
  16886. var data = placeData.Find(it => it.Id == nationalTravelFeeId);
  16887. if (data == null) return _city;
  16888. string country = data.Country;
  16889. string city = data.City;
  16890. if (city.Contains("其他城市") || city.Contains("所有城市")) _city = $"{country}-{city}";
  16891. else _city = city;
  16892. return _city;
  16893. }
  16894. /// <summary>
  16895. /// 团组模块 - 出入境费用-草稿
  16896. /// 一键清空
  16897. /// </summary>
  16898. /// <returns></returns>
  16899. [HttpPost]
  16900. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Del)]
  16901. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16902. public async Task<IActionResult> EnterExitCostDraftOneClickEmpty(EnterExitCostDraftOneClickEmptyDto dto)
  16903. {
  16904. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数;"));
  16905. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数;"));
  16906. var _view = await _enterExitCostDraftRep.OneClickEmpty(dto.Id, dto.UserId);
  16907. if (_view.Code == 0)
  16908. {
  16909. return Ok(JsonView(true, "操作成功"));
  16910. }
  16911. return Ok(JsonView(false, "操作失败"));
  16912. }
  16913. /// <summary>
  16914. /// 团组模块 - 出入境费用-草稿
  16915. /// 子项删除
  16916. /// </summary>
  16917. /// <returns></returns>
  16918. [HttpPost]
  16919. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Del)]
  16920. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16921. public async Task<IActionResult> EnterExitCostDraftSubItemDel(EnterExitCostDraftSubItemDelDto dto)
  16922. {
  16923. var data = await _enterExitCostDraftRep.EnterExitCostDraftSubItemDel(dto);
  16924. if (data.Code != 0)
  16925. {
  16926. return Ok(JsonView(false, data.Msg));
  16927. }
  16928. return Ok(JsonView(true, "操作成功!", data.Data));
  16929. }
  16930. /// <summary>
  16931. /// 团组模块 - 出入境费用-草稿
  16932. /// 删除
  16933. /// </summary>
  16934. /// <param name="dto"></param>
  16935. /// <returns></returns>
  16936. [HttpPost]
  16937. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Del)]
  16938. public IActionResult EnterExitCostDraftOtherExpensesDel(EnterExitCostDraftOtherExpensesDelDto dto)
  16939. {
  16940. var jw = JsonView(false, "删除失败!");
  16941. var data = new Grp_DayOtherPriceDraft()
  16942. {
  16943. Id = dto.Id,
  16944. IsDel = 1,
  16945. DeleteUserId = dto.DeleteUserId,
  16946. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  16947. };
  16948. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  16949. if (del > 0)
  16950. {
  16951. jw.Code = 200;
  16952. jw.Msg = "删除成功!";
  16953. }
  16954. return Ok(jw);
  16955. }
  16956. /// <summary>
  16957. /// 团组模块 - 出入境费用-草稿
  16958. /// 导入正式出入境费用基础数据
  16959. /// </summary>
  16960. /// <returns></returns>
  16961. [HttpPost]
  16962. public async Task<IActionResult> EnterExitCostDraftImportDataInit()
  16963. {
  16964. var jw = JsonView(false);
  16965. var groupNameDatas = await _groupRepository.EnterExitCostGroupNameAsync();
  16966. var draftDatas = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.IsDel == 0).OrderByDescending(x => x.CreateTime).Select(x => new { x.Id, x.DraftName }).ToListAsync();
  16967. jw.Code = StatusCodes.Status200OK;
  16968. jw.Msg = "操作成功!";
  16969. jw.Data = new { groupNameDatas, draftNames = draftDatas };
  16970. return Ok(jw);
  16971. }
  16972. /// <summary>
  16973. /// 团组模块 - 出入境费用-草稿
  16974. /// 导入正式出入境费用
  16975. /// </summary>
  16976. /// <param name="dto"></param>
  16977. /// <returns></returns>
  16978. [HttpPost]
  16979. public async Task<IActionResult> EnterExitCostDraftImportData(EnterExitCostDraftImportDataDto dto)
  16980. {
  16981. int userId = dto.UserId,
  16982. portId = dto.PortType,
  16983. groupId = dto.GroupId,
  16984. draftId = dto.DraftId;
  16985. _portTypeData.Add(1);
  16986. if (userId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16987. if (!_portTypeData.Contains(portId)) return Ok(JsonView(false, MsgTips.Port));
  16988. if (groupId < 1) return Ok(JsonView(false, "请传入有效的GroupId!"));
  16989. if (draftId < 1) return Ok(JsonView(false, "请传入有效的DraftId!"));
  16990. _sqlSugar.BeginTran();
  16991. try
  16992. {
  16993. var draftDatas = _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.IsDel == 0 && x.Id == draftId).First();
  16994. if (draftDatas == null)
  16995. {
  16996. _sqlSugar.RollbackTran();
  16997. return Ok(JsonView(false, "草稿数据为空,不可导入!"));
  16998. }
  16999. //验证可覆盖已有数据 两边创建人需为同一人;
  17000. int draftCreateUserId = draftDatas.CreateUserId,
  17001. formalCreateUserId = 0;
  17002. var formalData = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).First();
  17003. if (formalData != null)
  17004. {
  17005. formalCreateUserId = formalData.CreateUserId;
  17006. if (draftCreateUserId != formalCreateUserId)
  17007. {
  17008. _sqlSugar.RollbackTran();
  17009. return Ok(JsonView(false, "由草稿数据到入至正式数据,两边创建人为同一人才可导入正式版!"));
  17010. }
  17011. }
  17012. //默认添加查看、编辑权限(创建人、自己)
  17013. await _enterExitCostRep.InitPerm(dto.GroupId, dto.UserId);
  17014. var dayDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>().Where(x => x.IsDel == 0 && x.ParentId == draftId).ToList();
  17015. var otherDatas = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>().Where(x => x.IsDel == 0 && x.ParentId == draftId).ToList();
  17016. var newExterData = _mapper.Map<Grp_EnterExitCost>(draftDatas);
  17017. newExterData.DiId = groupId;
  17018. newExterData.CreateUserId = userId;
  17019. newExterData.Remark = $"由草稿数据导入;草稿数Id:{draftId}";
  17020. var newDayDatas = _mapper.Map<List<Grp_DayAndCost>>(dayDatas);
  17021. if (newDayDatas.Any()) newDayDatas.Select(x => { x.DiId = groupId; x.CreateUserId = userId; return x; }).ToList();
  17022. var newOtherDatas = _mapper.Map<List<Grp_DayOtherPrice>>(otherDatas);
  17023. if (newOtherDatas.Any()) newOtherDatas.Select(x => { x.Diid = groupId; x.CreateUserId = userId; return x; }).ToList();
  17024. var enterExitCostInfo = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).First();
  17025. //数据如果存在执行删除
  17026. if (enterExitCostInfo != null)
  17027. {
  17028. _sqlSugar.Updateable<Grp_EnterExitCost>()
  17029. .SetColumns(x => new Grp_EnterExitCost() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Remark = "由草稿数据导入前软删除数据!" })
  17030. .Where(x => x.Id == enterExitCostInfo.Id)
  17031. .ExecuteCommand();
  17032. _sqlSugar.Updateable<Grp_DayAndCost>()
  17033. .SetColumns(x => new Grp_DayAndCost() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
  17034. .Where(x => x.DiId == groupId)
  17035. .ExecuteCommand();
  17036. _sqlSugar.Updateable<Grp_DayOtherPrice>()
  17037. .SetColumns(x => new Grp_DayOtherPrice() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
  17038. .Where(x => x.Diid == groupId)
  17039. .ExecuteCommand();
  17040. _sqlSugar.Updateable<Grp_EnterExitCostPermission>()
  17041. .SetColumns(x => new Grp_EnterExitCostPermission() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
  17042. .Where(x => x.GroupId == groupId)
  17043. .ExecuteCommand();
  17044. }
  17045. //执行insert
  17046. var insertId = _sqlSugar.Insertable(newExterData).ExecuteReturnIdentity();
  17047. if (insertId < 1)
  17048. {
  17049. _sqlSugar.RollbackTran();
  17050. return Ok(JsonView(false, "草稿数据导入失败!"));
  17051. }
  17052. if (newDayDatas.Any()) _sqlSugar.Insertable(newDayDatas).ExecuteCommand();
  17053. if (newOtherDatas.Any()) _sqlSugar.Insertable(newOtherDatas).ExecuteCommand();
  17054. #region 默认添加权限
  17055. #endregion
  17056. _sqlSugar.CommitTran();
  17057. //执行操作之后
  17058. //生成默认文件pdf并且通知人员
  17059. var fileView = await GeneralMethod.EnterExitCostDownload(new EnterExitCostDownloadDto()
  17060. {
  17061. DiId = groupId,
  17062. ExportType = 1,
  17063. SubTypeId = 1005
  17064. }, "pdf");
  17065. //发送通知
  17066. string fileUrl = (string)fileView.Data.GetType().GetProperty("Url").GetValue(fileView.Data, null);
  17067. string md5Sign = GeneralMethod.Encrypt($"{insertId}&fileName={fileUrl}");
  17068. string url = string.Format("http://oa.pan-american-intl.com:4399/#/Sankunginfo?sign={0}&fileName={1}", insertId, fileUrl);
  17069. await AppNoticeLibrary.SendUserMsg_GroupShare_ToGM(groupId, new List<string>() { "208", "233", "21" }, dto.UserId, url);
  17070. //汇率信息记录
  17071. await GeneralMethod.RateRecordSave(userId, insertId, "出入境费用-草稿导入");
  17072. return Ok(JsonView(true));
  17073. }
  17074. catch (Exception ex)
  17075. {
  17076. _sqlSugar.RollbackTran();
  17077. return Ok(JsonView(false, ex.Message));
  17078. }
  17079. }
  17080. #endregion
  17081. #region 团组经理模块 出入境费用 移动端(Android/IOS)
  17082. #region 城市区间交通费
  17083. /// <summary>
  17084. /// 团组模块 - 出入境费用 - 移动端 - 基础数据源(境外用车)
  17085. /// </summary>
  17086. /// <param name="groupId"></param>
  17087. /// <returns></returns>
  17088. [HttpGet("{groupId}")]
  17089. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17090. public async Task<IActionResult> EnterExitCostMobileOVByGroupId(int groupId)
  17091. {
  17092. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  17093. if (groupInfo == null)
  17094. {
  17095. return Ok(JsonView(false, "团组信息为空"));
  17096. }
  17097. var countryies = _groupRepository.GroupSplitCountry(groupInfo.VisitCountry);
  17098. if (countryies?.Any() != true)
  17099. {
  17100. return Ok(JsonView(false, "团组出访国家信息为空"));
  17101. }
  17102. var currencies = await GeneralMethod.EnterExitCostOVFeeUsedCurrencyAsync(groupId);
  17103. var currencyData = await _sqlSugar.Queryable<Sys_SetData>()
  17104. .Where(x => x.IsDel == 0 && x.STid == 66)
  17105. .ToListAsync();
  17106. var overseaVehicles = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  17107. .Where(x => x.IsDel == 0 && countryies.Contains(x.CountryName))
  17108. .ToListAsync();
  17109. var overseaVehicleIds = overseaVehicles.Select(x => x.Id).ToList();
  17110. //只返回接送机的数据
  17111. var overseaVehicleTypes = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  17112. .Where(x => x.IsDel == 0 && x.ServiceType == VehicleServiceTypeEnum.TransferService && overseaVehicleIds.Contains(x.OvId))
  17113. .ToListAsync();
  17114. var sysUers = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToListAsync();
  17115. var overseaVehicleCityDatas = new List<dynamic>() {
  17116. new
  17117. {
  17118. Id = 0,
  17119. area= "未选择",
  17120. CarTypeName = "",
  17121. serviceType = "",
  17122. Price = 0.00M,
  17123. guidePrice = 0.00M,
  17124. otherPrice = 0.00M,
  17125. currency = 0,
  17126. currencyName = "",
  17127. currRate = 1.0000M,
  17128. LastUpdateUserName = "",
  17129. LastUpdateTime = "",
  17130. Remark = ""
  17131. }};
  17132. foreach (var item in overseaVehicleTypes)
  17133. {
  17134. var parentInfo = overseaVehicles.FirstOrDefault(x => x.Id == item.OvId);
  17135. string area = string.Empty,
  17136. serviceType = "未设置",
  17137. currencyName = string.Empty;
  17138. decimal otherPrice = 0.00M;
  17139. if (parentInfo != null)
  17140. {
  17141. if (parentInfo.CountryName == parentInfo.CityName) area = parentInfo.CountryName;
  17142. else area = $"{parentInfo.CountryName}-{parentInfo.CityName}";
  17143. serviceType = item.ServiceType.GetDescription();
  17144. currencyName = currencyData.FirstOrDefault(x => x.Id == parentInfo.Currency)?.Name ?? "-";
  17145. otherPrice = parentInfo.OtherPrice1 + parentInfo.OtherPrice2;
  17146. }
  17147. //当前币种汇率值
  17148. var currRate = 1.0000M;
  17149. var currencyInfo = currencies.FirstOrDefault(x => x.CurrencyCode == currencyName);
  17150. if (currencyInfo != null) currRate = currencyInfo.Rate;
  17151. overseaVehicleCityDatas.add(new
  17152. {
  17153. item.Id,
  17154. area,
  17155. item.CarTypeName,
  17156. serviceType,
  17157. item.Price,
  17158. guidePrice = parentInfo?.GuidePrice ?? 0.00M,
  17159. otherPrice,
  17160. currency = parentInfo?.Currency ?? 0,
  17161. currencyName,
  17162. currRate,
  17163. LastUpdateUserName = sysUers.FirstOrDefault(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-",
  17164. item.LastUpdateTime,
  17165. item.Remark
  17166. });
  17167. }
  17168. var total = overseaVehicleCityDatas.Count;
  17169. var view = new
  17170. {
  17171. visitCountries = string.Join("、", countryies),
  17172. groupSize = groupInfo.VisitPNumber, //出访人数
  17173. defAirportTransferCoeff = Def_AirportTransferCoeff, //接送机默认报价系数
  17174. defServiceCount = Def_ServiceCount, //接送机默认服务次数
  17175. defTrainCoeff = Def_TrainCoeff, //火车默认报价系数
  17176. defPullCartCoeff = Def_PullCartCoeff, //拉车默认报价系数
  17177. defCityFlightCoeff = Def_CityFlightCoeff, //城市机票默认报价系数
  17178. Currencies = currencies,
  17179. data = overseaVehicleCityDatas
  17180. };
  17181. if (overseaVehicleCityDatas.Count == 0)
  17182. {
  17183. return Ok(JsonView(true, "暂无数据!", view));
  17184. }
  17185. return Ok(JsonView(true, "查询成功!", view, total));
  17186. }
  17187. /// <summary>
  17188. /// 团组模块 - 出入境费用 - 移动端 - 境外用车计算详细信息
  17189. /// </summary>
  17190. /// <param name="groupId"></param>
  17191. /// <param name="currUserId"></param>
  17192. /// <returns></returns>
  17193. [HttpGet("{groupId}")]
  17194. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17195. public async Task<IActionResult> EnterExitCostMobileOVFeeDetails(int groupId, int currUserId)
  17196. {
  17197. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  17198. if (groupInfo == null)
  17199. {
  17200. return Ok(JsonView(false, "团组信息为空"));
  17201. }
  17202. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).FirstAsync();
  17203. //CityIntervalInfo
  17204. var info = new CityIntervalInfo();
  17205. if (eecInfo != null && !string.IsNullOrEmpty(eecInfo.CityIntervalFeeDetails))
  17206. {
  17207. info = JsonConvert.DeserializeObject<CityIntervalInfo>(eecInfo.CityIntervalFeeDetails);
  17208. return Ok(JsonView(true, "查询成功!", info));
  17209. }
  17210. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == currUserId).FirstAsync();
  17211. var userName = userInfo?.CnName ?? "-";
  17212. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  17213. //返回默认数据
  17214. info = new CityIntervalInfo()
  17215. {
  17216. APTFeeDetails = new List<RoundTripTransferInfo>() { new() { No = 1, Coefficient = Def_AirportTransferCoeff, ServiceCount = Def_ServiceCount } },
  17217. PullCartFeeDetails = new List<PullCartInfo>() { new() { No = 1, Coefficient = Def_PullCartCoeff } },
  17218. TrainFeeDetails = new List<TrainInfo>() { new() { No = 1, Coefficient = Def_TrainCoeff } },
  17219. CityAirTicketFeeDetails = new List<CityAirTicketInfo>() { new() { No = 1, Coefficient = Def_CityFlightCoeff } },
  17220. LastUpdateUserName = userName,
  17221. LastUpdateTime = nowTime,
  17222. CreateUserName = userName,
  17223. Currencies = await GeneralMethod.EnterExitCostOVFeeUsedCurrencyAsync(groupId),
  17224. CreateTime = nowTime
  17225. };
  17226. return Ok(JsonView(true, "查询成功!", info));
  17227. }
  17228. /// <summary>
  17229. /// 团组模块 - 出入境费用 - 移动端 - 境外用车计算 保存
  17230. /// </summary>
  17231. /// <param name="dto"></param>
  17232. /// <returns></returns>
  17233. [HttpPost]
  17234. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17235. public async Task<IActionResult> EnterExitCostMobileOVFeeSave(GetEnterExitCostOVFeeSaveDto dto)
  17236. {
  17237. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == dto.GroupId).FirstAsync();
  17238. if (groupInfo == null)
  17239. {
  17240. return Ok(JsonView(false, "团组信息为空"));
  17241. }
  17242. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == dto.CurrUserId).FirstAsync();
  17243. if (userInfo == null)
  17244. {
  17245. return Ok(JsonView(false, "员工信息为空"));
  17246. }
  17247. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == dto.GroupId).FirstAsync();
  17248. if (eecInfo == null)
  17249. {
  17250. return Ok(JsonView(false, "出入境费用信息为空"));
  17251. }
  17252. var oldData = new CityIntervalInfo();
  17253. if (!string.IsNullOrEmpty(eecInfo.CityIntervalFeeDetails))
  17254. {
  17255. oldData = JsonConvert.DeserializeObject<CityIntervalInfo>(eecInfo.CityIntervalFeeDetails);
  17256. }
  17257. var userName = userInfo?.CnName ?? "-";
  17258. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  17259. var info = new CityIntervalInfo()
  17260. {
  17261. APTFeeTotal = dto.APTFeeTotal,
  17262. APTFeeDetails = dto.APTFeeDetails,
  17263. PullCartFeeTotal = dto.PullCartFeeTotal,
  17264. PullCartFeeDetails = dto.PullCartFeeDetails,
  17265. TrainFeeTotal = dto.TrainFeeTotal,
  17266. TrainFeeDetails = dto.TrainFeeDetails,
  17267. CityAirTicketFeeTotal = dto.CityAirTicketFeeTotal,
  17268. CityAirTicketFeeDetails = dto.CityAirTicketFeeDetails,
  17269. Currencies = dto.Currencies,
  17270. LastUpdateUserName = userName,
  17271. LastUpdateTime = nowTime,
  17272. CreateUserName = oldData?.CreateUserName ?? userName,
  17273. CreateTime = oldData?.CreateTime ?? nowTime
  17274. };
  17275. eecInfo.CityIntervalFeeDetails = JsonConvert.SerializeObject(info);
  17276. var upd = await _sqlSugar.Updateable<Grp_EnterExitCost>()
  17277. .SetColumns(it => it.CityIntervalFeeDetails == eecInfo.CityIntervalFeeDetails)
  17278. .SetColumns(it => it.LastUpdateUserId == dto.CurrUserId)
  17279. .SetColumns(it => it.LastUpdateTime == nowTime)
  17280. .Where(x => x.Id == eecInfo.Id)
  17281. .ExecuteCommandAsync();
  17282. if (upd < 1)
  17283. {
  17284. return Ok(JsonView(false));
  17285. }
  17286. //返回数据处理
  17287. var label = new StringBuilder();
  17288. //接送机
  17289. if (dto.APTFeeDetails?.Any() == true)
  17290. {
  17291. var ovIds = dto.APTFeeDetails.Select(x => x.OvId).ToList();
  17292. var areas = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  17293. .LeftJoin<Res_OverseaVehicle>((ovtp, ov) => ovtp.OvId == ov.Id)
  17294. .Where((ovtp, ov) => ovtp.IsDel == 0 && ovIds.Contains(ovtp.Id))
  17295. .Select((ovtp, ov) => new
  17296. {
  17297. ovtp.Id,
  17298. ov.CountryName,
  17299. ov.CityName
  17300. }).ToListAsync();
  17301. var items = dto.APTFeeDetails
  17302. .Select(item =>
  17303. {
  17304. var areaInfo = areas.FirstOrDefault(x => x.Id == item.OvId);
  17305. if (areaInfo == null) return null;
  17306. return areaInfo.CountryName == areaInfo.CityName
  17307. ? $"{areaInfo.CountryName}({item.Quote:#0.00} CNY)"
  17308. : $"{areaInfo.CountryName}-{areaInfo.CityName}({item.Quote:#0.00} CNY)";
  17309. })
  17310. .Where(item => item != null)
  17311. .ToList();
  17312. label.AppendLine($"接送机({string.Join("、", items)});");
  17313. }
  17314. //拉车
  17315. if (dto.PullCartFeeDetails?.Any() == true)
  17316. {
  17317. var feeLabel = string.Join("、",
  17318. dto.PullCartFeeDetails.Select(x =>
  17319. $"{x.Quote:#0.00} CNY"
  17320. ));
  17321. label.AppendLine($"拉车({feeLabel});");
  17322. }
  17323. //火车
  17324. if (dto.TrainFeeDetails?.Any() == true)
  17325. {
  17326. var feeLabel = string.Join("、",
  17327. dto.TrainFeeDetails.Select(x =>
  17328. $"{x.Quote:#0.00} CNY"
  17329. ));
  17330. label.AppendLine($"火车票({feeLabel});");
  17331. }
  17332. //城市机票
  17333. if (dto.CityAirTicketFeeDetails?.Any() == true)
  17334. {
  17335. var feeLabel = string.Join("、",
  17336. dto.CityAirTicketFeeDetails.Select(x =>
  17337. $"{x.Quote:#0.00} CNY"
  17338. ));
  17339. label.AppendLine($"城市机票({feeLabel});");
  17340. }
  17341. //费用
  17342. decimal quote = (dto.APTFeeTotal + dto.PullCartFeeTotal + dto.TrainFeeTotal + dto.CityAirTicketFeeTotal).ConvertToDecimal1();
  17343. decimal jjcQuote = quote;
  17344. decimal gwcQuote = quote;
  17345. decimal tdcQuote = quote;
  17346. var view = new
  17347. {
  17348. label = label.ToString(),
  17349. jjcQuote,
  17350. gwcQuote,
  17351. tdcQuote
  17352. };
  17353. return Ok(JsonView(view));
  17354. }
  17355. #endregion
  17356. /// <summary>
  17357. /// 获取币种基础数据(含逻辑处理)
  17358. /// </summary>
  17359. /// <returns></returns>
  17360. private async Task<List<CurrencyInfo>> EnterExitCostMobileGetCurrencyInit()
  17361. {
  17362. return await GeneralMethod.EnterExitCostInitRate();
  17363. }
  17364. /// <summary>
  17365. /// 团组模块 - 出入境费用-移动端 - 基础数据源(Word明细类型、Excel明细类型、默认币种显示)
  17366. /// </summary>
  17367. /// <returns></returns>
  17368. [HttpPost]
  17369. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17370. public async Task<IActionResult> EnterExitCostMobileDataSource(EnterExitCostMobileDataSourceDto dto)
  17371. {
  17372. //验证城市归属并给默认值
  17373. int provinceId = dto.ProvinceId;
  17374. if (provinceId < 1) provinceId = 122;
  17375. var dataSource = await _sqlSugar
  17376. .Queryable<Sys_SetData>()
  17377. .Where(x => x.IsDel == 0 && (x.STid == 72 || x.STid == 73) && x.Remark.Contains(provinceId.ToString()))
  17378. .ToListAsync();
  17379. var fileTypes = new List<EecSetDataInfoView>();
  17380. //三公费用-Word明细类型
  17381. var wordTypeData = dataSource
  17382. .Where(it => it.STid == 72)
  17383. .Select(x => new EecSetDataInfoView
  17384. {
  17385. ParentId = 1,
  17386. Id = x.Id,
  17387. Name = x.Name
  17388. })
  17389. .ToArray();
  17390. if (wordTypeData.Any()) fileTypes.AddRange(wordTypeData);
  17391. var excelTypeData = dataSource
  17392. .Where(it => it.STid == 73)
  17393. .Select(x => new EecSetDataInfoView
  17394. {
  17395. ParentId = 2,
  17396. Id = x.Id,
  17397. Name = x.Name
  17398. })
  17399. .ToArray();
  17400. if (excelTypeData.Any()) fileTypes.AddRange(excelTypeData);
  17401. var groupNameList = new EecSetDataInfoView() { ParentId = 3, Id = 1, Name = "团组成员名单" };
  17402. fileTypes.Add(groupNameList);
  17403. fileTypes = fileTypes.OrderBy(x => x.ParentId).ThenBy(x => x.Id).ToList();
  17404. //默认币种显示
  17405. var _currencyInfos = await EnterExitCostMobileGetCurrencyInit();
  17406. var viewPermissionData = await _enterExitCostRep.PermissionViewUsersAsync();
  17407. return Ok(JsonView(true, "查询成功!", new
  17408. {
  17409. FileTypeData = fileTypes,
  17410. CurrencyInit = _currencyInfos,
  17411. viewPermissionData = viewPermissionData
  17412. }));
  17413. }
  17414. /// <summary>
  17415. /// 团组模块 - 出入境费用-移动端 - 团组基础数据Data
  17416. /// </summary>
  17417. /// <returns></returns>
  17418. [HttpPost]
  17419. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17420. public async Task<IActionResult> EnterExitCostMobileGroupData(PostEnterExitCostMobileGroupDataDto dto)
  17421. {
  17422. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  17423. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  17424. RefAsync<int> total = 0;
  17425. int diId = 0;
  17426. var status = int.TryParse(dto.GroupName, out diId);
  17427. var basicUserId = await _enterExitCostRep.PermissionViewUsersAsync();
  17428. var data = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  17429. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.TeamName))
  17430. .WhereIF(!string.IsNullOrEmpty(dto.GroupName) && diId > 0, x => x.Id == diId)
  17431. .WhereIF(!string.IsNullOrEmpty(dto.GroupName) && !status, x => x.TeamName.Contains(dto.GroupName))
  17432. .OrderByDescending(x => x.VisitStartDate)
  17433. .Select(x => new EnterExitCostMobileGroupView()
  17434. {
  17435. Id = x.Id,
  17436. GroupName = x.TeamName,
  17437. IsNull = SqlFunc.Subqueryable<Grp_EnterExitCost>().Where(x1 => x1.DiId == x.Id && x1.IsDel == 0).Any() ? false : true,
  17438. IsView = SqlFunc.Subqueryable<Grp_EnterExitCostPermission>().Where(x1 => x1.GroupId == x.Id && x1.UserId == dto.CurrUserId).Any(),
  17439. ProvinceId = x.CityId
  17440. })
  17441. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  17442. //处理省份Id
  17443. if (data.Any())
  17444. {
  17445. var provCityDatas = await _groupRepository.ProvinceCityBasicSource();
  17446. if (provCityDatas.Any())
  17447. {
  17448. foreach (var item in data)
  17449. {
  17450. var provinceId = item.ProvinceId;
  17451. var isDefualtVal = true;
  17452. if (provinceId > 0)
  17453. {
  17454. var parentId = _groupRepository.FindParentIdByChildId(provCityDatas, provinceId);
  17455. if (parentId != null)
  17456. {
  17457. isDefualtVal = false;
  17458. item.ProvinceId = (int)parentId;
  17459. }
  17460. }
  17461. if (isDefualtVal)
  17462. {
  17463. item.ProvinceId = 122; //默认四川
  17464. }
  17465. }
  17466. }
  17467. }
  17468. //处理是否显示
  17469. if (basicUserId.Any(x => x.Id == dto.CurrUserId))
  17470. {
  17471. foreach (var item in data)
  17472. {
  17473. item.IsView = true;
  17474. }
  17475. }
  17476. return Ok(JsonView(true, "查询成功!", data, total));
  17477. }
  17478. /// <summary>
  17479. /// 团组模块 - 出入境费用-移动端 - 币种基础数据Data
  17480. /// </summary>
  17481. /// <returns></returns>
  17482. [HttpPost]
  17483. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17484. public async Task<IActionResult> EnterExitCostMobileCurrencyData(PostEnterExitCostMobileCurrencyDataDto dto)
  17485. {
  17486. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  17487. RefAsync<int> total = 0;
  17488. var data = await _sqlSugar.Queryable<Sys_SetData>()
  17489. .Where(x => x.IsDel == 0 && x.STid == 66)
  17490. .WhereIF(!string.IsNullOrEmpty(dto.CurrencyName), x => x.Name.ToLower().Contains(dto.CurrencyName) || x.Remark.Contains(dto.CurrencyName))
  17491. .Select(x => new
  17492. {
  17493. id = x.Id,
  17494. name = x.Name,
  17495. remark = x.Remark,
  17496. })
  17497. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  17498. return Ok(JsonView(true, "查询成功!", data, total));
  17499. }
  17500. /// <summary>
  17501. /// 团组模块 - 出入境费用-移动端 - 其他款项 - 币种、费用类型基础数据Data
  17502. /// </summary>
  17503. /// <returns></returns>
  17504. [HttpPost]
  17505. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17506. public async Task<IActionResult> EnterExitCostMobileOtherItemCurrencyData(PostEnterExitCostMobileOtherItemCurrencyDataDto dto)
  17507. {
  17508. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  17509. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  17510. var groupRateData = await GeneralMethod.PostGroupTeamRateByDiIdAndCTableId(dto.PortType, dto.DiId, 98);
  17511. if (groupRateData == null) return Ok(JsonView(false, "请填写“团组汇率-->其他款项”汇率!"));
  17512. var groupOtherRateData = groupRateData.TeamRates;
  17513. var enterExitCostInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().FirstAsync(it => it.DiId == dto.DiId && it.IsDel == 0);
  17514. if (enterExitCostInfo == null) return Ok(JsonView(groupOtherRateData));
  17515. var eecRateData = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(enterExitCostInfo.CurrencyRemark);
  17516. groupOtherRateData = groupOtherRateData
  17517. .Select(x => new TeamRateDescAddCurrencyIdView
  17518. {
  17519. CurrencyId = x.CurrencyId,
  17520. CurrencyName = x.CurrencyName,
  17521. CurrencyCode = x.CurrencyCode,
  17522. Rate = eecRateData.Find(it => it.CurrencyCode.ToUpper().Equals(x.CurrencyCode.ToUpper()))?.Rate ?? x.Rate
  17523. }).ToList();
  17524. var otherFeeTypeData = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 92).Select(x => new { x.Id, x.Name }).ToListAsync();
  17525. return Ok(JsonView(true, "查询成功!", new { groupOtherRateData = groupOtherRateData, otherFeeTypeData = otherFeeTypeData }));
  17526. }
  17527. /// <summary>
  17528. /// 团组模块 - 出入境费用-移动端 - 实时汇率、签证费用、机票费用 Tips
  17529. /// </summary>
  17530. /// <returns></returns>
  17531. [HttpPost]
  17532. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17533. public async Task<IActionResult> EnterExitCostMobileFeeTips(GetEnterExitCostMobileFeeTipsDto dto)
  17534. {
  17535. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  17536. if (dto.GroupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  17537. var tipsData = new List<int>() { 1, 2, 3 };
  17538. if (!tipsData.Contains(dto.TipsType)) return Ok(JsonView(false, $"请传入有效的TipsType参数;1 实时汇率;2 签证费用;3 机票费用;"));
  17539. if (dto.TipsType == 1)
  17540. {
  17541. return Ok(JsonView(true, "查询成功!", await GeneralMethod.EnterExitCostLiveRate()));
  17542. }
  17543. else if (dto.TipsType == 2)
  17544. {
  17545. var visaData = await _visaFeeInfoRep.EnterExitCostVisaTips(dto.GroupId);
  17546. return Ok(JsonView(true, "查询成功!", visaData.Data));
  17547. }
  17548. else if (dto.TipsType == 3)
  17549. {
  17550. var airData = await GeneralMethod.EntryAndExitTips(dto.GroupId);
  17551. return Ok(JsonView(true, "查询成功!", airData));
  17552. }
  17553. return Ok(JsonView(false));
  17554. }
  17555. /// <summary>
  17556. /// 团组模块 - 出入境国家费用标准-移动端 List
  17557. /// </summary>
  17558. /// <returns></returns>
  17559. [HttpPost]
  17560. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17561. public async Task<IActionResult> NationalTravelFeeMobileData(PostNationalTravelFeeMobileDataDto dto)
  17562. {
  17563. Stopwatch sw = new Stopwatch();
  17564. sw.Start();
  17565. int provinceId = dto.ProvinceId;
  17566. if (provinceId < 1) provinceId = 122; // 默认四川
  17567. RefAsync<int> total = 0;
  17568. var data = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  17569. .LeftJoin<Sys_SetData>((ntf, sd) => ntf.Currency == sd.Id)
  17570. .LeftJoin<Sys_Users>((ntf, sd, u) => ntf.CreateUserId == u.Id)
  17571. .LeftJoin<Sys_Cities>((ntf, sd, u, sd1) => ntf.ProvinceId == sd1.Id)
  17572. .Where((ntf, sd, u, sd1) => ntf.IsDel == 0 && ntf.ProvinceId == provinceId)
  17573. .WhereIF(!string.IsNullOrEmpty(dto.Search), (ntf, sd, u, sd1) => dto.Search.Contains(ntf.Country) || dto.Search.Contains(ntf.City))
  17574. .Select((ntf, sd, u, sd1) => new
  17575. {
  17576. Id = ntf.Id,
  17577. Area = $"{ntf.Country}-{ntf.City}",
  17578. Currency = ntf.Currency,
  17579. CurrencyCode = sd.Name,
  17580. CurrencyName = sd.Remark,
  17581. RoomCost = ntf.RoomCost,
  17582. FoodCost = ntf.FoodCost,
  17583. PublicCost = ntf.PublicCost,
  17584. TrainCost = ntf.TrainCost,
  17585. LastUpdateUserId = ntf.LastUpdateUserId,
  17586. LastUpdateUserName = u.CnName,
  17587. LastUpdateTime = ntf.LastUpdateTime
  17588. })
  17589. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  17590. sw.Stop();
  17591. return Ok(JsonView(true, "查询成功!耗时:" + sw.ElapsedMilliseconds + "ms", data, total));
  17592. }
  17593. /// <summary>
  17594. /// 团组模块 - 出入境费用-移动端 - Info
  17595. /// </summary>
  17596. /// <returns></returns>
  17597. [HttpPost]
  17598. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17599. public async Task<IActionResult> EnterExitCostMobileInfo(EnterExitCostInfobyDiIdDto dto)
  17600. {
  17601. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  17602. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  17603. var data = await _enterExitCostRep.GetEnterExitCostInfoByDiId(dto);
  17604. return Ok(data);
  17605. }
  17606. /// <summary>
  17607. /// 团组模块 - 出入境费用-移动端 - ParentInfo
  17608. /// </summary>
  17609. /// <returns></returns>
  17610. [HttpPost]
  17611. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17612. public async Task<IActionResult> EnterExitCostMobileParentInfo(EnterExitCostInfobyDiIdDto dto)
  17613. {
  17614. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  17615. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  17616. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  17617. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.DiId == dto.DiId && it.IsDel == 0);
  17618. var mobileInfo = new EnterExitCostMobileParentInfoView();
  17619. mobileInfo.DiId = dto.DiId;
  17620. mobileInfo.Currencys = await EnterExitCostMobileGetCurrencyInit();
  17621. if (eecInfo == null) return Ok(mobileInfo);
  17622. //验证查看权限
  17623. (bool isView, bool isSet) = await _enterExitCostRep.PermissionValidationAsync(dto.DiId, dto.CurrUserId);
  17624. if (!isView) return Ok(JsonView(false, "没有查看权限!"));
  17625. mobileInfo = _mapper.Map<EnterExitCostMobileParentInfoView>(eecInfo);
  17626. mobileInfo.IsAssignPerm = isSet;
  17627. var dayAndCostData = _sqlSugar.Queryable<Grp_DayAndCost>()
  17628. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  17629. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  17630. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId)
  17631. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  17632. {
  17633. SubId = dac.Id,
  17634. DiId = dac.DiId,
  17635. Type = dac.Type,
  17636. Days = dac.Days,
  17637. NationalTravelFeeId = dac.NationalTravelFeeId,
  17638. Arae = $"{ntf.Country}-{ntf.City}",
  17639. Cost = dac.Cost,
  17640. Currency = dac.Currency,
  17641. CurrencyName = sd.Name,
  17642. SubTotal = dac.SubTotal,
  17643. })
  17644. .ToList();
  17645. mobileInfo.ChoiceOneTotalCost = eecInfo.InsidePay;
  17646. mobileInfo.ChoiceTwoJJ = eecInfo.SumJJC;
  17647. mobileInfo.ChoiceTwoGW = eecInfo.SumGWC;
  17648. mobileInfo.ChoiceTwoTD = eecInfo.SumTDC;
  17649. mobileInfo.Currencys = !string.IsNullOrEmpty(eecInfo.CurrencyRemark) ? CommonFun.GetCurrencyChinaToList(eecInfo.CurrencyRemark) : mobileInfo.Currencys;
  17650. mobileInfo.ChoiceThreeTotalCost = dayAndCostData.Where(it => it.Type == 1).Sum(x => x.SubTotal); //住宿费 1
  17651. mobileInfo.ChoiceFourTotalCost = dayAndCostData.Where(it => it.Type == 2).Sum(x => x.SubTotal); //伙食费 2
  17652. mobileInfo.ChoiceFiveTotalCost = dayAndCostData.Where(it => it.Type == 3).Sum(x => x.SubTotal); //公杂费 3
  17653. mobileInfo.ChoiceSixTotalCost = dayAndCostData.Where(it => it.Type == 4).Sum(x => x.SubTotal); //培训费 4
  17654. //其他款项
  17655. var otherData = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  17656. .LeftJoin<Sys_SetData>((dop, sd1) => dop.SetDataId == sd1.Id)
  17657. .LeftJoin<Sys_SetData>((dop, sd1, sd2) => dop.Currency == sd2.Id)
  17658. .Where((dop, sd1, sd2) => dop.IsDel == 0 && dop.Diid == dto.DiId)
  17659. .OrderBy((dop, sd1, sd2) => dop.Index)
  17660. .Select((dop, sd1, sd2) => new DayOtherPriceMobileInfoView
  17661. {
  17662. SubId = dop.Id,
  17663. DiId = dop.Diid,
  17664. Index = dop.Index,
  17665. SetDataId = dop.SetDataId,
  17666. SetDataName = sd1.Name,
  17667. Cost = dop.Cost,
  17668. Currency = dop.Currency,
  17669. CurrencyName = sd2.Remark,
  17670. SubTotal = dop.SubTotal,
  17671. Remark = dop.Remark,
  17672. })
  17673. .ToArray();
  17674. mobileInfo.OtherExpensesTotalCost = otherData.Sum(x => x.SubTotal);
  17675. return Ok(mobileInfo);
  17676. }
  17677. /// <summary>
  17678. /// 团组模块 - 出入境费用-移动端 - 查看权限用户
  17679. /// </summary>
  17680. /// <returns></returns>
  17681. [HttpPost]
  17682. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17683. public async Task<IActionResult> EnterExitCostMobileViewPermissionUsers(EnterExitCostMobileViewPermissionUsersDto dto)
  17684. {
  17685. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  17686. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  17687. //验证查看权限
  17688. (bool viewPerm, bool assignPerm) = await _enterExitCostRep.PermissionValidationAsync(dto.DiId, dto.CurrUserId);//分配权限
  17689. if (!viewPerm) return Ok(JsonView(false, "未分配查看权限,如要查看,请联系市场部或国交部负责人!"));
  17690. var userIds = await _sqlSugar
  17691. .Queryable<Grp_EnterExitCostPermission>()
  17692. .Where(x => x.IsDel == 0 && x.GroupId == dto.DiId)
  17693. .Select(x => x.UserId)
  17694. .ToArrayAsync();
  17695. var perUsers = await _enterExitCostRep.PermissionViewUsersAsync();
  17696. var perUsersView = new List<dynamic>();
  17697. foreach (var item in perUsers)
  17698. {
  17699. bool isView1 = false;
  17700. if (userIds.Any(x => x == item.Id)) isView1 = true;
  17701. perUsersView.Add(new { Id = item.Id, Name = item.Name, IsView = isView1 });
  17702. }
  17703. return Ok(JsonView(perUsersView));
  17704. }
  17705. /// <summary>
  17706. /// 团组模块 - 出入境费用-移动端 - SubInfo
  17707. /// </summary>
  17708. /// <returns></returns>
  17709. [HttpPost]
  17710. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17711. public async Task<IActionResult> EnterExitCostMobileSubInfo(PostEnterExitCostMobileSubInfoDto dto)
  17712. {
  17713. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  17714. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  17715. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  17716. var subTypes = new List<int>() { 1, 2, 3, 4, 5, 6, 7 };
  17717. if (!subTypes.Contains(dto.SubType)) return Ok(JsonView(false, $"请传入有效的subTypeId!"));
  17718. //验证查看权限
  17719. //(bool isView, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId);
  17720. //if (!isView) return Ok(JsonView(false, msg));
  17721. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.DiId == dto.DiId && it.IsDel == 0);
  17722. if (eecInfo == null) return Ok(JsonView(false, $"出入境费用明细未录入!"));
  17723. var subType = dto.SubType;
  17724. if (subType == 1) //1:境内费用
  17725. {
  17726. var oneData = new ChoiceOneMobileSubInfoView()
  17727. {
  17728. Id = eecInfo.Id,
  17729. ChoiceOne = eecInfo.ChoiceOne,
  17730. ChoiceOneTotalCost = eecInfo.InsidePay,
  17731. Visa = eecInfo.Visa,
  17732. VisaRemark = eecInfo.VisaRemark,
  17733. YiMiao = eecInfo.YiMiao,
  17734. HeSuan = eecInfo.HeSuan,
  17735. Service = eecInfo.Service,
  17736. Ticket = eecInfo.Ticket,
  17737. Safe = eecInfo.Safe,
  17738. FirstItemRemark = eecInfo.FirstItemRemark
  17739. };
  17740. return Ok(JsonView(oneData));
  17741. }
  17742. else if (subType == 2) //2:国际旅费
  17743. {
  17744. var twoData = new ChoiceTwoMobileSubInfoView()
  17745. {
  17746. Id = eecInfo.Id,
  17747. ChoiceTwoJJ = eecInfo.SumJJC,
  17748. OutsideJJPay = eecInfo.OutsideJJPay,
  17749. ChoiceTwoGW = eecInfo.SumGWC,
  17750. OutsideGWPay = eecInfo.OutsideGWPay,
  17751. ChoiceTwoTD = eecInfo.SumTDC,
  17752. OutsideTDPay = eecInfo.OutsideTDPay,
  17753. AirJJ = eecInfo.AirJJ,
  17754. AirGW = eecInfo.AirGW,
  17755. AirTD = eecInfo.AirTD,
  17756. CityTranffic = eecInfo.CityTranffic,
  17757. CityTranffic1 = eecInfo.CityTranffic1,
  17758. CityTranffic2 = eecInfo.CityTranffic2,
  17759. TwoItemRemark = eecInfo.TwoItemRemark
  17760. };
  17761. return Ok(JsonView(twoData));
  17762. }
  17763. else if (subType == 3) //3:住宿费
  17764. {
  17765. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCost>()
  17766. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  17767. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  17768. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId && dac.Type == 1)
  17769. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  17770. {
  17771. SubId = dac.Id,
  17772. DiId = dac.DiId,
  17773. Type = dac.Type,
  17774. Days = dac.Days,
  17775. NationalTravelFeeId = dac.NationalTravelFeeId,
  17776. Arae = $"{ntf.Country}-{ntf.City}",
  17777. Cost = dac.Cost,
  17778. Currency = dac.Currency,
  17779. CurrencyName = sd.Name,
  17780. SubTotal = dac.SubTotal,
  17781. })
  17782. .ToArray();
  17783. var data = new ChoiceMobileSubInfo3To6View()
  17784. {
  17785. ParentId = eecInfo.Id,
  17786. Choice = eecInfo.ChoiceThree,
  17787. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  17788. Details = dayAndCostDatas
  17789. };
  17790. return Ok(JsonView(data));
  17791. }
  17792. else if (subType == 4) //4:伙食费
  17793. {
  17794. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCost>()
  17795. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  17796. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  17797. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId && dac.Type == 2)
  17798. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  17799. {
  17800. SubId = dac.Id,
  17801. DiId = dac.DiId,
  17802. Type = dac.Type,
  17803. Days = dac.Days,
  17804. NationalTravelFeeId = dac.NationalTravelFeeId,
  17805. Arae = $"{ntf.Country}-{ntf.City}",
  17806. Cost = dac.Cost,
  17807. Currency = dac.Currency,
  17808. CurrencyName = sd.Name,
  17809. SubTotal = dac.SubTotal,
  17810. })
  17811. .ToArray();
  17812. var data = new ChoiceMobileSubInfo3To6View()
  17813. {
  17814. ParentId = eecInfo.Id,
  17815. Choice = eecInfo.ChoiceFour,
  17816. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  17817. Details = dayAndCostDatas
  17818. };
  17819. return Ok(JsonView(data));
  17820. }
  17821. else if (subType == 5) //5:公杂费
  17822. {
  17823. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCost>()
  17824. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  17825. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  17826. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId && dac.Type == 3)
  17827. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  17828. {
  17829. SubId = dac.Id,
  17830. DiId = dac.DiId,
  17831. Type = dac.Type,
  17832. Days = dac.Days,
  17833. NationalTravelFeeId = dac.NationalTravelFeeId,
  17834. Arae = $"{ntf.Country}-{ntf.City}",
  17835. Cost = dac.Cost,
  17836. Currency = dac.Currency,
  17837. CurrencyName = sd.Name,
  17838. SubTotal = dac.SubTotal,
  17839. })
  17840. .ToArray();
  17841. var data = new ChoiceMobileSubInfo3To6View()
  17842. {
  17843. ParentId = eecInfo.Id,
  17844. Choice = eecInfo.ChoiceFive,
  17845. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  17846. Details = dayAndCostDatas
  17847. };
  17848. return Ok(JsonView(data));
  17849. }
  17850. else if (subType == 6) //6:培训费
  17851. {
  17852. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCost>()
  17853. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  17854. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  17855. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId && dac.Type == 4)
  17856. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  17857. {
  17858. SubId = dac.Id,
  17859. DiId = dac.DiId,
  17860. Type = dac.Type,
  17861. Days = dac.Days,
  17862. NationalTravelFeeId = dac.NationalTravelFeeId,
  17863. Arae = $"{ntf.Country}-{ntf.City}",
  17864. Cost = dac.Cost,
  17865. Currency = dac.Currency,
  17866. CurrencyName = sd.Name,
  17867. SubTotal = dac.SubTotal,
  17868. })
  17869. .ToArray();
  17870. var data = new ChoiceMobileSubInfo3To6View()
  17871. {
  17872. ParentId = eecInfo.Id,
  17873. Choice = eecInfo.ChoiceSix,
  17874. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  17875. Details = dayAndCostDatas
  17876. };
  17877. return Ok(JsonView(data));
  17878. }
  17879. else if (subType == 7) //7:其他
  17880. {
  17881. //其他款项
  17882. var otherData = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  17883. .LeftJoin<Sys_SetData>((dop, sd1) => dop.SetDataId == sd1.Id)
  17884. .LeftJoin<Sys_SetData>((dop, sd1, sd2) => dop.Currency == sd2.Id)
  17885. .Where((dop, sd1, sd2) => dop.IsDel == 0 && dop.Diid == dto.DiId)
  17886. .OrderBy((dop, sd1, sd2) => dop.Index)
  17887. .Select((dop, sd1, sd2) => new DayOtherPriceMobileInfoView
  17888. {
  17889. SubId = dop.Id,
  17890. DiId = dop.Diid,
  17891. Index = dop.Index,
  17892. SetDataId = dop.SetDataId,
  17893. SetDataName = sd1.Name,
  17894. Cost = dop.Cost,
  17895. Currency = dop.Currency,
  17896. CurrencyName = sd2.Name,
  17897. SubTotal = dop.SubTotal,
  17898. Remark = dop.Remark,
  17899. })
  17900. .ToArray();
  17901. var data = new ChoiceSevenMobileSubInfoView()
  17902. {
  17903. ParentId = eecInfo.Id,
  17904. OtherExpenses_Checked = eecInfo.OtherExpenses_Checked,
  17905. OtherExpensesTotalCost = otherData.Sum(x => x.SubTotal),
  17906. Details = otherData
  17907. };
  17908. return Ok(JsonView(data));
  17909. }
  17910. return Ok(JsonView(false));
  17911. }
  17912. #region op
  17913. ///// <summary>
  17914. ///// 移动端更新费用消息通知
  17915. ///// </summary>
  17916. ///// <param name="diid"></param>
  17917. ///// <param name="id"></param>
  17918. ///// <param name="currUserId"></param>
  17919. //private async Task EnterExitCostMobileOpNotice(int diid, int id, int currUserId)
  17920. //{
  17921. // try
  17922. // {
  17923. // ////生成默认文件pdf并且通知人员
  17924. // //var fileView = await GeneralMethod.EnterExitCostDownload(new EnterExitCostDownloadDto()
  17925. // //{
  17926. // // DiId = diid,
  17927. // // ExportType = 1,
  17928. // // SubTypeId = 1005
  17929. // //}, "pdf");
  17930. // ////发送通知
  17931. // //string fileUrl = (string)fileView.Data.GetType().GetProperty("Url").GetValue(fileView.Data, null);
  17932. // //string md5Sign = GeneralMethod.Encrypt($"{id}&fileName={fileUrl}");
  17933. // //string url = string.Format("http://oa.pan-american-intl.com:4399/#/Sankunginfo?sign={0}&fileName={1}", id, fileUrl);
  17934. // //await AppNoticeLibrary.SendUserMsg_GroupShare_ToGM(diid, new List<string>() { "208", "233", "21" }, currUserId, url);
  17935. // ////汇率信息记录
  17936. // //await GeneralMethod.RateRecordSave(currUserId, id, "出入境费用");
  17937. // }
  17938. // catch (Exception ex)
  17939. // {
  17940. // //记录日志
  17941. // throw;
  17942. // }
  17943. //}
  17944. /// <summary>
  17945. /// 验证出入境费用数据是否存在
  17946. /// 不存在添加
  17947. /// </summary>
  17948. /// <param name="diId"></param>
  17949. /// <param name="currUserId"></param>
  17950. /// <returns></returns>
  17951. private async Task<int> EnterExitCostVerifyIsNull(int diId, int currUserId)
  17952. {
  17953. var parentId = 0;
  17954. var info = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == diId).OrderByDescending(x => x.CreateTime).FirstAsync();
  17955. if (info != null)
  17956. {
  17957. parentId = info.Id;
  17958. }
  17959. else
  17960. {
  17961. var currencys = await EnterExitCostMobileGetCurrencyInit();
  17962. int addId = await _sqlSugar.Insertable(new Grp_EnterExitCost() { DiId = diId, CreateUserId = currUserId, CurrencyRemark = JsonConvert.SerializeObject(currencys) }).ExecuteReturnIdentityAsync();
  17963. parentId = addId;
  17964. }
  17965. return parentId;
  17966. }
  17967. /// <summary>
  17968. /// 团组模块 - 出入境费用-移动端 - 设置view权限
  17969. /// </summary>
  17970. /// <returns></returns>
  17971. [HttpPost]
  17972. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17973. public async Task<IActionResult> EnterExitCostMobileSetViewPermissiion(EnterExitCostMobileSetViewPermissiionDto dto)
  17974. {
  17975. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  17976. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  17977. if (dto.UserIds.Length < 1) return Ok(JsonView(false, "请传入有效的userId;"));
  17978. //验证编辑权限
  17979. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  17980. //if (!isEdit) return Ok(JsonView(false, msg));
  17981. var permissions = new List<Grp_EnterExitCostPermission>();
  17982. foreach (var userId in dto.UserIds)
  17983. {
  17984. permissions.Add(new Grp_EnterExitCostPermission { Permission = 1, GroupId = dto.DiId, UserId = userId, CreateUserId = dto.CurrUserId });
  17985. }
  17986. if (permissions.Any())
  17987. {
  17988. if (!permissions.Any(x => x.UserId == dto.CurrUserId))
  17989. {
  17990. permissions.Add(new Grp_EnterExitCostPermission { Permission = 1, GroupId = dto.DiId, UserId = dto.CurrUserId, CreateUserId = dto.CurrUserId });
  17991. }
  17992. _sqlSugar.BeginTran();
  17993. await _sqlSugar.Deleteable<Grp_EnterExitCostPermission>().Where(it => it.GroupId == dto.DiId).ExecuteCommandAsync();
  17994. var result = await _sqlSugar.Insertable(permissions).ExecuteCommandAsync();
  17995. if (result < 1)
  17996. {
  17997. _sqlSugar.RollbackTran();
  17998. return Ok(JsonView(false));
  17999. }
  18000. _sqlSugar.CommitTran();
  18001. return Ok(JsonView(true));
  18002. }
  18003. return Ok(JsonView(false));
  18004. }
  18005. /// <summary>
  18006. /// 团组模块 - 出入境费用-移动端 - OP --> 汇率
  18007. /// </summary>
  18008. /// <returns></returns>
  18009. [HttpPost]
  18010. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18011. public async Task<IActionResult> EnterExitCostMobileOpRate(PostEnterExitCostMobileFeeRateOpDto dto)
  18012. {
  18013. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18014. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18015. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18016. if (dto.Currencys.Length < 1) return Ok(JsonView(false, "请传入有效的汇率信息!"));
  18017. var currencyStr = CommonFun.GetCurrencyChinaToString(dto.Currencys.ToList());
  18018. int id = dto.Id;
  18019. if (id <= 0) //add
  18020. {
  18021. //int provinceId = dto.ProvinceId;
  18022. int groupId = dto.DiId;
  18023. //if (provinceId < 1) provinceId = 122;
  18024. var info = new Grp_EnterExitCost() { DiId = groupId, CurrencyRemark = currencyStr, CreateUserId = dto.CurrUserId };
  18025. info.LastUpdateUserId = dto.CurrUserId;
  18026. info.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  18027. var add = await _sqlSugar.Insertable(info).ExecuteCommandAsync();
  18028. if (add < 1) return Ok(JsonView(false));
  18029. id = add;
  18030. }
  18031. else //update
  18032. {
  18033. ////验证编辑权限
  18034. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  18035. //if (!isEdit) return Ok(JsonView(false, msg));
  18036. var upd = await _sqlSugar.Updateable<Grp_EnterExitCost>().SetColumns(x => new Grp_EnterExitCost()
  18037. {
  18038. CurrencyRemark = currencyStr,
  18039. LastUpdateUserId = dto.CurrUserId,
  18040. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  18041. }).Where(x => x.Id == dto.Id).ExecuteCommandAsync();
  18042. if (upd < 1) return Ok(JsonView(false));
  18043. }
  18044. #region 汇率变更时更改币种相关费用
  18045. var opDayCosts = new List<Grp_DayAndCost>();
  18046. var opDayOtherCosts = new List<Grp_DayOtherPrice>();
  18047. var eecCurrencys = dto.Currencys.Select(x => x.CurrencyCode.ToUpper()).ToList();
  18048. var dayCosts = _sqlSugar.Queryable<Grp_DayAndCost>()
  18049. .LeftJoin<Sys_SetData>((dac, sd) => dac.Currency == sd.Id)
  18050. .Where((dac, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId)
  18051. .Select((dac, sd) => new
  18052. {
  18053. dac.Id,
  18054. dac.DiId,
  18055. CurrencyCode = sd.Name,
  18056. dac.Cost
  18057. })
  18058. .ToList();
  18059. var dayOtherCosts = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  18060. .LeftJoin<Sys_SetData>((dop, sd) => dop.Currency == sd.Id)
  18061. .Where((dop, sd) => dop.IsDel == 0 && dop.Diid == dto.DiId)
  18062. .Select((dop, sd) => new
  18063. {
  18064. dop.Id,
  18065. dop.Diid,
  18066. CurrencyCode = sd.Name,
  18067. dop.Cost
  18068. })
  18069. .ToList();
  18070. if (dayCosts.Count > 0)
  18071. {
  18072. var new_dayCosts = dayCosts.Where(x => eecCurrencys.Contains(x.CurrencyCode.ToUpper())).GroupBy(x => x.CurrencyCode);
  18073. foreach (var dc in new_dayCosts)
  18074. {
  18075. var thisCurrency = dc.Key.ToUpper();
  18076. var thisRate = dto.Currencys.Where(x => x.CurrencyCode.ToUpper().Equals(thisCurrency)).First()?.Rate ?? 0.00M;
  18077. if (thisRate == 0.00M) continue;
  18078. foreach (var dcSub in dc)
  18079. {
  18080. opDayCosts.Add(new Grp_DayAndCost()
  18081. {
  18082. Id = dcSub.Id,
  18083. DiId = dcSub.DiId,
  18084. Cost = dcSub.Cost,
  18085. SubTotal = dcSub.Cost * thisRate,
  18086. Remark = $"[移动端->汇率变更时费用变更][变更信息:currency:{thisCurrency}、opDatetime:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}、opUserId:{dto.CurrUserId}]"
  18087. });
  18088. }
  18089. }
  18090. if (opDayCosts.Count > 0)
  18091. {
  18092. await _sqlSugar.Updateable(opDayCosts).UpdateColumns(x => new { x.SubTotal, x.Remark }).WhereColumns(x => new { x.Id }).ExecuteCommandAsync();
  18093. }
  18094. }
  18095. if (dayOtherCosts.Count > 0)
  18096. {
  18097. var new_dayOtherCosts = dayOtherCosts.Where(x => eecCurrencys.Contains(x.CurrencyCode.ToUpper())).GroupBy(x => x.CurrencyCode);
  18098. foreach (var dc in new_dayOtherCosts)
  18099. {
  18100. var thisCurrency = dc.Key.ToUpper();
  18101. var thisRate = dto.Currencys.Where(x => x.CurrencyCode.ToUpper().Equals(thisCurrency)).First()?.Rate ?? 0.00M;
  18102. if (thisRate == 0.00M) continue;
  18103. foreach (var dcSub in dc)
  18104. {
  18105. opDayOtherCosts.Add(new Grp_DayOtherPrice()
  18106. {
  18107. Id = dcSub.Id,
  18108. Diid = dcSub.Diid,
  18109. Cost = dcSub.Cost,
  18110. SubTotal = dcSub.Cost * thisRate,
  18111. // Remark = $"[移动端->汇率变更时费用变更][变更信息:currency:{thisCurrency}、opDatetime:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}、opUserId:{dto.CurrUserId}]"
  18112. });
  18113. }
  18114. }
  18115. if (opDayOtherCosts.Count > 0)
  18116. {
  18117. await _sqlSugar.Updateable(opDayOtherCosts).UpdateColumns(x => new { x.SubTotal }).WhereColumns(x => new { x.Id }).ExecuteCommandAsync();
  18118. }
  18119. }
  18120. #endregion
  18121. //消息通知
  18122. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  18123. //汇率信息记录
  18124. await GeneralMethod.RateRecordSave(dto.CurrUserId, id, "出入境费用");
  18125. return Ok(JsonView(new { parentId = id }));
  18126. }
  18127. /// <summary>
  18128. /// 团组模块 - 出入境费用-移动端 - OP --> 复选框
  18129. /// </summary>
  18130. /// <returns></returns>
  18131. [HttpPost]
  18132. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18133. public async Task<IActionResult> EnterExitCostMobileOpCheckbox(PostEnterExitCostMobileFeeOpCheckboxDto dto)
  18134. {
  18135. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18136. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18137. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18138. //if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  18139. var checkboxInfo = _mapper.Map<Grp_EnterExitCost>(dto);
  18140. checkboxInfo.LastUpdateUserId = dto.CurrUserId;
  18141. checkboxInfo.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  18142. int id = dto.Id;
  18143. if (id <= 0) //add
  18144. {
  18145. checkboxInfo.CreateUserId = dto.CurrUserId;
  18146. checkboxInfo.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  18147. var add = await _sqlSugar.Insertable(checkboxInfo).ExecuteCommandAsync();
  18148. if (add < 1) return Ok(JsonView(false));
  18149. }
  18150. else //update
  18151. {
  18152. ////验证编辑权限
  18153. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  18154. //if (!isEdit) return Ok(JsonView(false, msg));
  18155. var upd = await _sqlSugar.Updateable(checkboxInfo)
  18156. .UpdateColumns(x => new
  18157. {
  18158. x.ChoiceOne,
  18159. x.ChoiceTwo,
  18160. x.SumJJC,
  18161. x.SumGWC,
  18162. x.SumTDC,
  18163. x.ChoiceThree,
  18164. x.ChoiceFour,
  18165. x.ChoiceFive,
  18166. x.ChoiceSix,
  18167. x.OtherExpenses_Checked
  18168. })
  18169. .Where(x => x.Id == id)
  18170. .ExecuteCommandAsync();
  18171. if (upd < 1) return Ok(JsonView(false));
  18172. }
  18173. return Ok(JsonView(new { parentId = id }));
  18174. }
  18175. /// <summary>
  18176. /// 团组模块 - 出入境费用-移动端 - OP --> 3-7项复选框单个复选框更改
  18177. /// </summary>
  18178. /// <returns></returns>
  18179. [HttpPost]
  18180. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18181. public async Task<IActionResult> EnterExitCostMobileOpSingleCheckbox(EnterExitCostMobileOpSingleCheckboxDto dto)
  18182. {
  18183. int itemTypeId = dto.ItemType, id = dto.Id, currUserId = dto.CurrUserId, diId = dto.DiId, isSelected = dto.IsSelected;
  18184. // if (provinceId < 1) provinceId = 122;
  18185. var itemTypes = new List<int>() { 3, 4, 5, 6, 7 };
  18186. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18187. if (diId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18188. if (currUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18189. if (!itemTypes.Contains(itemTypeId)) return Ok(JsonView(false, $"请传入要修改的项类型;3:住宿费; 4:伙食费; 5:公杂费; 6:培训费;7:其他;"));
  18190. var checkboxInfo = new Grp_EnterExitCost()
  18191. {
  18192. Id = id,
  18193. //ProvinceId = provinceId,
  18194. DiId = diId,
  18195. CreateUserId = currUserId,
  18196. LastUpdateUserId = dto.CurrUserId,
  18197. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  18198. };
  18199. if (itemTypeId == 3) checkboxInfo.ChoiceThree = isSelected;
  18200. else if (itemTypeId == 4) checkboxInfo.ChoiceFour = isSelected;
  18201. else if (itemTypeId == 5) checkboxInfo.ChoiceFive = isSelected;
  18202. else if (itemTypeId == 6) checkboxInfo.ChoiceSix = isSelected;
  18203. else if (itemTypeId == 7) checkboxInfo.OtherExpenses_Checked = isSelected;
  18204. if (id <= 0) //add
  18205. {
  18206. checkboxInfo.CreateUserId = dto.CurrUserId;
  18207. checkboxInfo.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  18208. var add = await _sqlSugar.Insertable(checkboxInfo).ExecuteCommandAsync();
  18209. if (add < 1) return Ok(JsonView(false));
  18210. }
  18211. else //update
  18212. {
  18213. ////验证编辑权限
  18214. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  18215. //if (!isEdit) return Ok(JsonView(false, msg));
  18216. var upd = await _sqlSugar.Updateable<Grp_EnterExitCost>()
  18217. .SetColumns(it => it.LastUpdateUserId == dto.CurrUserId)
  18218. .SetColumns(it => it.LastUpdateTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  18219. .SetColumnsIF(itemTypeId == 3, it => it.ChoiceThree == isSelected)
  18220. .SetColumnsIF(itemTypeId == 4, it => it.ChoiceFour == isSelected)
  18221. .SetColumnsIF(itemTypeId == 5, it => it.ChoiceFive == isSelected)
  18222. .SetColumnsIF(itemTypeId == 6, it => it.ChoiceSix == isSelected)
  18223. .SetColumnsIF(itemTypeId == 7, it => it.OtherExpenses_Checked == isSelected)
  18224. .Where(x => x.Id == id)
  18225. .ExecuteCommandAsync();
  18226. if (upd < 1) return Ok(JsonView(false));
  18227. }
  18228. return Ok(JsonView(new { parentId = id }));
  18229. }
  18230. /// <summary>
  18231. /// 团组模块 - 出入境费用-移动端 - OP --> 境内费用 Step1
  18232. /// </summary>
  18233. /// <returns></returns>
  18234. [HttpPost]
  18235. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18236. public async Task<IActionResult> EnterExitCostMobileOpStep1(PostEnterExitCostMobileOpStep1Dto dto)
  18237. {
  18238. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18239. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18240. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18241. //if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  18242. var info = _mapper.Map<Grp_EnterExitCost>(dto);
  18243. info.FirstItemRemark = dto.FirstItemRemark;
  18244. info.LastUpdateUserId = dto.CurrUserId;
  18245. info.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  18246. info.InsidePay = dto.Visa + dto.Service + dto.Safe + dto.Ticket + dto.HeSuan + dto.YiMiao;
  18247. int id = dto.Id;
  18248. if (id <= 0) //add
  18249. {
  18250. info.CreateUserId = dto.CurrUserId;
  18251. info.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  18252. var add = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  18253. if (add < 1) return Ok(JsonView(false));
  18254. id = add;
  18255. }
  18256. else //update
  18257. {
  18258. ////验证编辑权限
  18259. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  18260. //if (!isEdit) return Ok(JsonView(false, msg));
  18261. var upd = await _sqlSugar.Updateable(info)
  18262. .UpdateColumns(x => new
  18263. {
  18264. x.ChoiceOne,
  18265. x.InsidePay,
  18266. x.VisaRemark,
  18267. x.Visa,
  18268. x.Service,
  18269. x.Safe,
  18270. x.Ticket,
  18271. x.HeSuan,
  18272. x.YiMiao,
  18273. x.FirstItemRemark,
  18274. x.LastUpdateUserId,
  18275. x.LastUpdateTime
  18276. })
  18277. .Where(x => x.Id == id)
  18278. .ExecuteCommandAsync();
  18279. if (upd < 1) return Ok(JsonView(false));
  18280. }
  18281. //消息通知
  18282. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  18283. return Ok(JsonView(new { parentId = id, itemTotal = info.InsidePay }));
  18284. }
  18285. /// <summary>
  18286. /// 团组模块 - 出入境费用-移动端 - OP --> 国际旅费 Step2
  18287. /// </summary>
  18288. /// <returns></returns>
  18289. [HttpPost]
  18290. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18291. public async Task<IActionResult> EnterExitCostMobileOpStep2(PostEnterExitCostMobileOpStep2Dto dto)
  18292. {
  18293. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18294. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18295. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18296. //if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  18297. var info = _mapper.Map<Grp_EnterExitCost>(dto);
  18298. info.DiId = dto.DiId;
  18299. //info.ProvinceId = dto.ProvinceId;
  18300. info.OutsideJJPay = dto.OutsideJJPay;
  18301. info.OutsideGWPay = dto.OutsideGWPay;
  18302. info.OutsideTDPay = dto.OutsideTDPay;
  18303. info.AirJJ = dto.AirJJ;
  18304. info.AirGW = dto.AirGW;
  18305. info.AirTD = dto.AirTD;
  18306. info.CityTranffic = dto.CityTranffic;
  18307. info.CityTranffic1 = dto.CityTranffic1;
  18308. info.CityTranffic2 = dto.CityTranffic2;
  18309. info.TwoItemRemark = dto.TwoItemRemark;
  18310. info.SumJJC = dto.ChoiceTwoJJ;
  18311. info.SumGWC = dto.ChoiceTwoGW;
  18312. info.SumTDC = dto.ChoiceTwoTD;
  18313. info.LastUpdateUserId = dto.CurrUserId;
  18314. info.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  18315. int id = dto.Id;
  18316. decimal jjcItemTotal = 0.00M, gwcItemTotal = 0.00M, tdcItemTotal = 0.00M;
  18317. if (id <= 0) //add i
  18318. {
  18319. info.CreateUserId = dto.CurrUserId;
  18320. info.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  18321. var addId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  18322. if (addId <= 0) return Ok(JsonView(false));
  18323. id = addId;
  18324. }
  18325. else //update
  18326. {
  18327. ////验证编辑权限
  18328. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  18329. //if (!isEdit) return Ok(JsonView(false, msg));
  18330. var upd = await _sqlSugar.Updateable(info)
  18331. .UpdateColumns(x => new
  18332. {
  18333. x.SumJJC,
  18334. x.OutsideJJPay,
  18335. x.SumGWC,
  18336. x.OutsideGWPay,
  18337. x.SumTDC,
  18338. x.OutsideTDPay,
  18339. x.AirJJ,
  18340. x.AirGW,
  18341. x.AirTD,
  18342. x.CityTranffic,
  18343. x.CityTranffic1,
  18344. x.CityTranffic2,
  18345. x.TwoItemRemark,
  18346. x.LastUpdateTime,
  18347. x.LastUpdateUserId
  18348. })
  18349. .Where(x => x.Id == id)
  18350. .ExecuteCommandAsync();
  18351. if (upd < 1) return Ok(JsonView(false));
  18352. }
  18353. jjcItemTotal = info.AirJJ + info.CityTranffic;
  18354. gwcItemTotal = info.AirGW + info.CityTranffic1;
  18355. tdcItemTotal = info.AirTD + info.CityTranffic2;
  18356. //消息通知
  18357. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  18358. return Ok(JsonView(new
  18359. {
  18360. parentId = id,
  18361. choiceTwoJJ = dto.ChoiceTwoJJ,
  18362. jjcItemTotal = jjcItemTotal,
  18363. choiceTwoGW = dto.ChoiceTwoGW,
  18364. gwcItemTotal = gwcItemTotal,
  18365. choiceTwoTD = dto.ChoiceTwoTD,
  18366. tdcItemTotal = tdcItemTotal
  18367. }));
  18368. }
  18369. /// <summary>
  18370. /// 团组模块 - 出入境费用-移动端 - OP --> 批量(住宿、伙食、公杂、培训) Step3-Step6
  18371. /// </summary>
  18372. /// <returns></returns>
  18373. [HttpPost]
  18374. [ApiExplorerSettings(IgnoreApi = true)]
  18375. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18376. public async Task<IActionResult> EnterExitCostMobileOpBatchStep3To6(PostEnterExitCostMobileOpStep3To6Dto dto)
  18377. {
  18378. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18379. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18380. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18381. if (dto.Infos.Length < 1) return Ok(JsonView(false, "请传入有效的费用信息!"));
  18382. var feeTypeIds = new List<int>() { 1, 2, 3, 4, };
  18383. if (!feeTypeIds.Contains(dto.FeeType)) return Ok(JsonView(false, "请传入有效的费用类型!"));
  18384. var infos1 = _mapper.Map<List<Grp_DayAndCost>>(dto.Infos);
  18385. var infos = infos1.Select(x => new Grp_DayAndCost
  18386. {
  18387. Id = x.Id,
  18388. DiId = dto.DiId,
  18389. Type = dto.FeeType,
  18390. Days = x.Days,
  18391. NationalTravelFeeId = x.NationalTravelFeeId,
  18392. Cost = x.Cost,
  18393. Currency = x.Currency,
  18394. SubTotal = x.SubTotal,
  18395. CreateUserId = dto.CurrUserId
  18396. })
  18397. .ToList();
  18398. var adds = infos.Where(x => x.Id <= 0).ToList();
  18399. var upds = infos.Where(x => x.Id > 0).ToList();
  18400. if (adds.Count > 0)
  18401. {
  18402. var add = await _sqlSugar.Insertable(adds).ExecuteCommandAsync();
  18403. if (add < 1) return Ok(JsonView(false));
  18404. }
  18405. if (upds.Count > 0)
  18406. {
  18407. var upd = await _sqlSugar.Updateable(adds)
  18408. .UpdateColumns(x => new
  18409. {
  18410. x.Days,
  18411. x.NationalTravelFeeId,
  18412. x.Cost,
  18413. x.Currency,
  18414. x.SubTotal
  18415. })
  18416. .WhereColumns(x => new { x.Id })
  18417. .ExecuteCommandAsync();
  18418. if (upd < 1) return Ok(JsonView(false));
  18419. }
  18420. var itemTotal = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.IsDel == 0 && x.DiId == dto.DiId && x.Type == dto.FeeType).Sum(x => x.SubTotal);
  18421. //消息通知
  18422. var id = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == dto.DiId).First()?.Id ?? 0;
  18423. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  18424. return Ok(JsonView(new { itemTotal = itemTotal }));
  18425. }
  18426. /// <summary>
  18427. /// 团组模块 - 出入境费用-移动端 - OP --> 单条(住宿、伙食、公杂、培训) Step3-Step6
  18428. /// </summary>
  18429. /// <returns></returns>
  18430. [HttpPost]
  18431. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18432. public async Task<IActionResult> EnterExitCostMobileOpSingleStep3To6(PostEnterExitCostMobileOpSingleStep3To6Dto dto)
  18433. {
  18434. var feeTypeIds = new List<int>() { 3, 4, 5, 6 };
  18435. int subId = dto.SubId, feeType = dto.FeeType;
  18436. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18437. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18438. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18439. if (!feeTypeIds.Contains(dto.FeeType)) return Ok(JsonView(false, "请传入有效的费用类型!"));
  18440. var subInfo = _mapper.Map<Grp_DayAndCost>(dto);
  18441. subInfo.Id = subId;
  18442. subInfo.DiId = dto.DiId;
  18443. if (feeType == 3) subInfo.Type = 1;
  18444. else if (feeType == 4) subInfo.Type = 2;
  18445. else if (feeType == 5) subInfo.Type = 3;
  18446. else if (feeType == 6) subInfo.Type = 4;
  18447. subInfo.CreateUserId = dto.CurrUserId;
  18448. int parentId = await EnterExitCostVerifyIsNull(dto.DiId, dto.CurrUserId); //主表验证
  18449. if (parentId < 1) return Ok(JsonView(false));
  18450. //子表op
  18451. if (subId < 1)
  18452. {
  18453. var subAdd = await _sqlSugar.Insertable(subInfo).ExecuteCommandAsync();
  18454. if (subAdd < 1) return Ok(JsonView(false));
  18455. }
  18456. else
  18457. {
  18458. ////验证编辑权限
  18459. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  18460. //if (!isEdit) return Ok(JsonView(false, msg));
  18461. var subUpd = await _sqlSugar.Updateable(subInfo)
  18462. .UpdateColumns(x => new
  18463. {
  18464. x.Days,
  18465. x.NationalTravelFeeId,
  18466. x.Cost,
  18467. x.Currency,
  18468. x.SubTotal
  18469. })
  18470. .WhereColumns(x => new { x.Id })
  18471. .ExecuteCommandAsync();
  18472. if (subUpd < 1) return Ok(JsonView(false));
  18473. }
  18474. var itemTotal = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.IsDel == 0 && x.DiId == dto.DiId && x.Type == feeType).Sum(x => x.SubTotal);
  18475. //await EnterExitCostMobileOpNotice(dto.DiId, parentId, dto.CurrUserId);
  18476. return Ok(JsonView(new { parentId = parentId, itemTotal = itemTotal }));
  18477. }
  18478. /// <summary>
  18479. /// 团组模块 - 出入境费用-移动端 - OP --> 其他费用-批量 Step7
  18480. /// </summary>
  18481. /// <returns></returns>
  18482. [HttpPost]
  18483. [ApiExplorerSettings(IgnoreApi = true)]
  18484. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18485. public async Task<IActionResult> EnterExitCostMobileOpBatchStep7(PostEnterExitCostMobileOpStep7Dto dto)
  18486. {
  18487. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18488. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18489. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18490. var infos1 = _mapper.Map<List<Grp_DayOtherPrice>>(dto.Infos);
  18491. var infos = infos1.Select(x => new Grp_DayOtherPrice()
  18492. {
  18493. Id = x.Id,
  18494. Diid = dto.DiId,
  18495. SetDataId = x.SetDataId,
  18496. Index = x.Index,
  18497. Cost = x.Cost,
  18498. Currency = x.Currency,
  18499. SubTotal = x.SubTotal,
  18500. CreateUserId = dto.CurrUserId,
  18501. Remark = x.Remark
  18502. }).ToList();
  18503. var adds = infos.Where(x => x.Id <= 0).ToList();
  18504. var upds = infos.Where(x => x.Id > 0).ToList();
  18505. if (adds.Count > 0)
  18506. {
  18507. var add = await _sqlSugar.Insertable(adds).ExecuteCommandAsync();
  18508. if (add < 1) return Ok(JsonView(false));
  18509. }
  18510. if (upds.Count > 0)
  18511. {
  18512. var upd = await _sqlSugar.Updateable(adds)
  18513. .UpdateColumns(x => new
  18514. {
  18515. x.Index,
  18516. x.SetDataId,
  18517. x.Cost,
  18518. x.Currency,
  18519. x.SubTotal,
  18520. x.Remark
  18521. })
  18522. .WhereColumns(x => new { x.Id })
  18523. .ExecuteCommandAsync();
  18524. if (upd < 1) return Ok(JsonView(false));
  18525. }
  18526. var itemTotal = _sqlSugar.Queryable<Grp_DayOtherPrice>().Where(x => x.IsDel == 0 && x.Diid == dto.DiId).Sum(x => x.SubTotal);
  18527. //消息通知
  18528. var id = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == dto.DiId).First()?.Id ?? 0;
  18529. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  18530. return Ok(JsonView(new { itemTotal = itemTotal }));
  18531. }
  18532. /// <summary>
  18533. /// 团组模块 - 出入境费用-移动端 - OP --> 其他费用-单条 Step7
  18534. /// </summary>
  18535. /// <returns></returns>
  18536. [HttpPost]
  18537. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18538. public async Task<IActionResult> EnterExitCostMobileOpSingleStep7(PostEnterExitCostMobileOpSingleStep7Dto dto)
  18539. {
  18540. int subId = dto.SubId;
  18541. int diId = dto.Diid;
  18542. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18543. if (diId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18544. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18545. var subInfo = _mapper.Map<Grp_DayOtherPrice>(dto);
  18546. subInfo.Id = subId;
  18547. subInfo.Diid = dto.Diid;
  18548. subInfo.CreateUserId = dto.CurrUserId;
  18549. int parentId = await EnterExitCostVerifyIsNull(diId, dto.CurrUserId); //主表验证
  18550. if (parentId < 1) return Ok(JsonView(false));
  18551. #region 子表op
  18552. if (subId < 1)//add
  18553. {
  18554. var subAdd = await _sqlSugar.Insertable(subInfo).ExecuteCommandAsync();
  18555. if (subAdd < 1) return Ok(JsonView(false));
  18556. }
  18557. else //upd
  18558. {
  18559. ////验证编辑权限
  18560. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.Diid, dto.CurrUserId, 2);
  18561. //if (!isEdit) return Ok(JsonView(false, msg));
  18562. var subUpd = await _sqlSugar.Updateable(subInfo)
  18563. .UpdateColumns(x => new
  18564. {
  18565. x.Index,
  18566. x.SetDataId,
  18567. x.Cost,
  18568. x.Currency,
  18569. x.SubTotal,
  18570. x.Remark
  18571. })
  18572. .WhereColumns(x => new { x.Id })
  18573. .ExecuteCommandAsync();
  18574. if (subUpd < 1) return Ok(JsonView(false));
  18575. }
  18576. #endregion
  18577. var itemTotal = _sqlSugar.Queryable<Grp_DayOtherPrice>().Where(x => x.IsDel == 0 && x.Diid == diId).Sum(x => x.SubTotal);
  18578. //消息通知
  18579. //await EnterExitCostMobileOpNotice(dto.Diid, parentId, dto.CurrUserId);
  18580. return Ok(JsonView(new { parentId = parentId, itemTotal = itemTotal }));
  18581. }
  18582. /// <summary>
  18583. /// 团组模块 - 出入境费用-移动端 - 3-6子项删除
  18584. /// </summary>
  18585. /// <returns></returns>
  18586. [HttpPost]
  18587. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18588. public async Task<IActionResult> EnterExitCostMobileSubItemDel(EnterExitCostSubItemDelDto dto)
  18589. {
  18590. var data = await _enterExitCostRep.PostEnterExitCostSubItemDel(dto);
  18591. if (data.Code != 0)
  18592. {
  18593. return Ok(JsonView(false, data.Msg));
  18594. }
  18595. return Ok(JsonView(true, "操作成功!", data.Data));
  18596. }
  18597. /// <summary>
  18598. /// 团组模块 - 出入境费用-移动端 - 其他费用删除
  18599. /// </summary>
  18600. /// <param name="dto"></param>
  18601. /// <returns></returns>
  18602. [HttpPost]
  18603. public IActionResult EnterExitCostMobileOtherFeeDel(EnterExitCostSubItemDelDto dto)
  18604. {
  18605. var data = new Grp_DayOtherPrice()
  18606. {
  18607. Id = dto.Id,
  18608. IsDel = 1,
  18609. DeleteUserId = dto.DeleteUserId,
  18610. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  18611. };
  18612. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  18613. if (del > 0) return Ok(JsonView(true, "删除成功!"));
  18614. return Ok(JsonView(false, "删除失败!"));
  18615. }
  18616. #endregion
  18617. #endregion
  18618. #region 团组经理模块 出入境费用-草稿 移动端(Android/IOS)
  18619. /// <summary>
  18620. /// 团组模块 - 出入境费用-草稿 - 基础数据源 - 省份归属
  18621. /// </summary>
  18622. /// <returns></returns>
  18623. [HttpGet]
  18624. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18625. public async Task<IActionResult> EnterExitDraftMobileProvBelongCostDataSource()
  18626. {
  18627. var provData = await _groupRepository.ProvinceBasicSource();
  18628. return Ok(JsonView(true, "查询成功!", provData));
  18629. }
  18630. /// <summary>
  18631. /// 团组模块 - 出入境费用-草稿-移动端 - 草稿名称数据Data
  18632. /// </summary>
  18633. /// <returns></returns>
  18634. [HttpPost]
  18635. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18636. public async Task<IActionResult> EnterExitCostDraftMobileNameData(EnterExitCostDraftMobileNameDataDto dto)
  18637. {
  18638. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18639. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18640. RefAsync<int> total = 0;
  18641. var data = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>()
  18642. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.DraftName))
  18643. .WhereIF(!string.IsNullOrEmpty(dto.DraftName), x => x.DraftName.Contains(dto.DraftName))
  18644. .Select(x => new
  18645. {
  18646. Id = x.Id,
  18647. DraftName = x.DraftName,
  18648. IsViewOrEdit = SqlFunc.Subqueryable<Grp_EnterExitCostDraftPermission>()
  18649. .Where(x1 => x1.IsDel == 0 && x1.Permission == 1 && x1.DraftId == x.Id && x1.UserId == dto.CurrUserId)
  18650. .Any()
  18651. })
  18652. .OrderByDescending(x => x.Id)
  18653. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  18654. return Ok(JsonView(true, "查询成功!", data, total));
  18655. }
  18656. /// <summary>
  18657. /// 出入境费用-草稿 移动端
  18658. /// 获取币种基础数据(含逻辑处理)
  18659. /// </summary>
  18660. /// <returns></returns>
  18661. private async Task<List<CurrencyInfo>> EnterExitCostDraftMobileGetCurrencyInit()
  18662. {
  18663. return await GeneralMethod.EnterExitCostInitRate();
  18664. }
  18665. /// <summary>
  18666. /// 团组模块 - 出入境费用-草稿-移动端 - 基础数据源(Word明细类型、Excel明细类型、默认币种显示)
  18667. /// </summary>
  18668. /// <returns></returns>
  18669. [HttpPost]
  18670. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18671. public async Task<IActionResult> EnterExitCostDraftMobileDataSource(EnterExitCostDraftMobileDataSourceDto dto)
  18672. {
  18673. //验证城市归属并给默认值
  18674. int provinceId = dto.ProvinceId;
  18675. if (provinceId < 1) provinceId = 122;
  18676. var dataSource = await _sqlSugar
  18677. .Queryable<Sys_SetData>()
  18678. .Where(x => x.IsDel == 0 && (x.STid == 72 || x.STid == 73) && x.Remark.Contains(provinceId.ToString()))
  18679. .ToListAsync();
  18680. //三公费用-Word明细类型
  18681. var wordTypeData = dataSource.Where(it => it.STid == 72)
  18682. .Select(x => new SetDataInfoView
  18683. {
  18684. Id = x.Id,
  18685. Name = x.Name,
  18686. Remark = x.Remark
  18687. })
  18688. .ToList();
  18689. //三公费用-Excel明细类型
  18690. var excelTypeData = dataSource.Where(it => it.STid == 73)
  18691. .Select(x => new SetDataInfoView
  18692. {
  18693. Id = x.Id,
  18694. Name = x.Name,
  18695. Remark = x.Remark
  18696. })
  18697. .ToList();
  18698. //默认币种显示
  18699. var _currencyInfos = await EnterExitCostMobileGetCurrencyInit();
  18700. var viewPermissionData = await _enterExitCostRep.PermissionViewUsersAsync();
  18701. return Ok(JsonView(true, "查询成功!", new
  18702. {
  18703. WordTypeData = wordTypeData,
  18704. ExcelTypeData = excelTypeData,
  18705. CurrencyInit = _currencyInfos,
  18706. viewPermissionData = viewPermissionData
  18707. }));
  18708. }
  18709. /// <summary>
  18710. /// 团组模块 - 出入境费用-草稿-移动端 - 团组基础数据Data
  18711. /// </summary>
  18712. /// <returns></returns>
  18713. [HttpPost]
  18714. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18715. public async Task<IActionResult> EnterExitCostDraftMobileGroupData(PostEnterExitCostDraftMobileGroupDataDto dto)
  18716. {
  18717. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18718. RefAsync<int> total = 0;
  18719. int diId = 0;
  18720. var status = int.TryParse(dto.GroupName, out diId);
  18721. var data = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  18722. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.TeamName))
  18723. .WhereIF(!string.IsNullOrEmpty(dto.GroupName) && diId > 0, x => x.Id == diId)
  18724. .WhereIF(!string.IsNullOrEmpty(dto.GroupName) && !status, x => x.TeamName.Contains(dto.GroupName))
  18725. .OrderByDescending(x => x.VisitStartDate)
  18726. .Select(x => new
  18727. {
  18728. Id = x.Id,
  18729. GroupName = x.TeamName
  18730. })
  18731. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  18732. return Ok(JsonView(true, "查询成功!", data, total));
  18733. }
  18734. /// <summary>
  18735. /// 团组模块 - 出入境费用-草稿-移动端 - 币种基础数据Data
  18736. /// </summary>
  18737. /// <returns></returns>
  18738. [HttpPost]
  18739. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18740. public async Task<IActionResult> EnterExitCostDraftMobileCurrencyData(PostEnterExitCostDraftMobileCurrencyDataDto dto)
  18741. {
  18742. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18743. RefAsync<int> total = 0;
  18744. var data = await _sqlSugar.Queryable<Sys_SetData>()
  18745. .Where(x => x.IsDel == 0 && x.STid == 66)
  18746. .WhereIF(!string.IsNullOrEmpty(dto.CurrencyName), x => x.Name.ToLower().Contains(dto.CurrencyName) || x.Remark.Contains(dto.CurrencyName))
  18747. .Select(x => new
  18748. {
  18749. id = x.Id,
  18750. name = x.Name,
  18751. remark = x.Remark,
  18752. })
  18753. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  18754. return Ok(JsonView(true, "查询成功!", data, total));
  18755. }
  18756. /// <summary>
  18757. /// 团组模块 - 出入境费用-草稿-移动端 - 其他款项 - 币种、费用类型基础数据Data
  18758. /// </summary>
  18759. /// <returns></returns>
  18760. [HttpPost]
  18761. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18762. public async Task<IActionResult> EnterExitCostDraftMobileOtherItemCurrencyData(PostEnterExitCostDraftMobileOtherItemCurrencyDataDto dto)
  18763. {
  18764. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18765. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  18766. var groupRateData = await GeneralMethod.PostGroupTeamRateByDiIdAndCTableId(1, 2477, 98);
  18767. if (groupRateData == null) return Ok(JsonView(false, "请填写“团组汇率-->其他款项”汇率!"));
  18768. var groupOtherRateData = groupRateData.TeamRates;
  18769. var enterExitCostInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().FirstAsync(it => it.Id == dto.DraftId && it.IsDel == 0);
  18770. if (enterExitCostInfo == null) return Ok(JsonView(groupOtherRateData));
  18771. var eecRateData = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(enterExitCostInfo.CurrencyRemark);
  18772. groupOtherRateData = groupOtherRateData
  18773. .Select(x => new TeamRateDescAddCurrencyIdView
  18774. {
  18775. CurrencyId = x.CurrencyId,
  18776. CurrencyName = x.CurrencyName,
  18777. CurrencyCode = x.CurrencyCode,
  18778. Rate = eecRateData.Find(it => it.CurrencyCode.ToUpper().Equals(x.CurrencyCode.ToUpper()))?.Rate ?? x.Rate
  18779. }).ToList();
  18780. var otherFeeTypeData = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 92).Select(x => new { x.Id, x.Name }).ToListAsync();
  18781. return Ok(JsonView(true, "查询成功!", new { groupOtherRateData = groupOtherRateData, otherFeeTypeData = otherFeeTypeData }));
  18782. }
  18783. /// <summary>
  18784. /// 团组模块 - 出入境费用-草稿-移动端 - 实时汇率、签证费用、机票费用 Tips
  18785. /// </summary>
  18786. /// <returns></returns>
  18787. [HttpPost]
  18788. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18789. public async Task<IActionResult> EnterExitCostDraftMobileFeeTips(EnterExitCostDraftMobileFeeTipsDto dto)
  18790. {
  18791. int portType = dto.PortType;
  18792. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18793. var tipsData = new List<int>() { 1, 2, 3 };
  18794. if (!tipsData.Contains(dto.TipsType)) return Ok(JsonView(false, $"请传入有效的TipsType参数;1 实时汇率;2 签证费用;3 机票费用;"));
  18795. if (dto.TipsType == 1)
  18796. {
  18797. return Ok(JsonView(true, "查询成功!", await GeneralMethod.EnterExitCostLiveRate()));
  18798. }
  18799. else if (dto.TipsType == 2)
  18800. {
  18801. if (portType == 2)
  18802. {
  18803. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  18804. }
  18805. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  18806. .Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId)
  18807. .Select(x => x.NationalTravelFeeId)
  18808. .Distinct()
  18809. .ToListAsync();
  18810. if (portType == 2)
  18811. {
  18812. if (!cityIds.Any()) return Ok(JsonView(false, "请先录入出入境费用明细!"));
  18813. }
  18814. var countrys = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  18815. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  18816. .Select(x => x.Country)
  18817. .Distinct()
  18818. .ToArrayAsync();
  18819. if (portType == 2)
  18820. {
  18821. if (!countrys.Any()) return Ok(JsonView(false, "请先录入出入境费用明细!"));
  18822. }
  18823. (decimal totalAmt, string remark) = await _visaFeeInfoRep.EnterExitCostDraftVisaTips(countrys);
  18824. return Ok(JsonView(true, "查询成功!", new
  18825. {
  18826. totalAmt = totalAmt,
  18827. remark = remark
  18828. }));
  18829. }
  18830. else if (dto.TipsType == 3)
  18831. {
  18832. return Ok(JsonView(false, "暂无机票费用提示信息!"));
  18833. }
  18834. return Ok(JsonView(false));
  18835. }
  18836. #region 城市区间交通费
  18837. /// <summary>
  18838. /// 团组模块 - 出入境费用 - 草稿 - 移动端 - 基础数据源(境外用车)
  18839. /// </summary>
  18840. /// <param name="draftId">草稿Id</param>
  18841. /// <returns></returns>
  18842. [HttpGet("{darfId}")]
  18843. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18844. public async Task<IActionResult> EnterExitCostDraftOVMobileByGroupId(int draftId)
  18845. {
  18846. var groupInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == draftId).FirstAsync();
  18847. if (groupInfo == null)
  18848. {
  18849. return Ok(JsonView(false, "三公费用草稿信息为空"));
  18850. }
  18851. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  18852. .Where(x => x.IsDel == 0 && x.ParentId == draftId)
  18853. .Select(x => x.NationalTravelFeeId)
  18854. .Distinct()
  18855. .ToListAsync();
  18856. var countries = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  18857. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  18858. .Select(x => x.Country)
  18859. .Distinct()
  18860. .ToListAsync();
  18861. if (countries?.Any() != true)
  18862. {
  18863. return Ok(JsonView(false, "草稿选择城市信息为空"));
  18864. }
  18865. var currencies = await GeneralMethod.EnterExitCostDrafOVFeeUsedCurrencyAsync(draftId);
  18866. var currencyData = await _sqlSugar.Queryable<Sys_SetData>()
  18867. .Where(x => x.IsDel == 0 && x.STid == 66)
  18868. .ToListAsync();
  18869. var overseaVehicles = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  18870. .Where(x => x.IsDel == 0 && countries.Contains(x.CountryName))
  18871. .ToListAsync();
  18872. var overseaVehicleIds = overseaVehicles.Select(x => x.Id).ToList();
  18873. //只返回接送机的数据
  18874. var overseaVehicleTypes = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  18875. .Where(x => x.IsDel == 0 && x.ServiceType == VehicleServiceTypeEnum.TransferService && overseaVehicleIds.Contains(x.OvId))
  18876. .ToListAsync();
  18877. var sysUers = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToListAsync();
  18878. var overseaVehicleCityDatas = new List<dynamic>() {
  18879. new
  18880. {
  18881. Id = 0,
  18882. area= "未选择",
  18883. CarTypeName = "",
  18884. serviceType = "",
  18885. Price = 0.00M,
  18886. guidePrice = 0.00M,
  18887. otherPrice = 0.00M,
  18888. currency = 0,
  18889. currencyName = "",
  18890. currRate = 1.0000M,
  18891. LastUpdateUserName = "",
  18892. LastUpdateTime = "",
  18893. Remark = ""
  18894. }};
  18895. foreach (var item in overseaVehicleTypes)
  18896. {
  18897. var parentInfo = overseaVehicles.FirstOrDefault(x => x.Id == item.OvId);
  18898. string area = string.Empty,
  18899. serviceType = "未设置",
  18900. currencyName = string.Empty;
  18901. decimal otherPrice = 0.00M;
  18902. if (parentInfo != null)
  18903. {
  18904. if (parentInfo.CountryName == parentInfo.CityName) area = parentInfo.CountryName;
  18905. else area = $"{parentInfo.CountryName}-{parentInfo.CityName}";
  18906. serviceType = item.ServiceType.GetDescription();
  18907. currencyName = currencyData.FirstOrDefault(x => x.Id == parentInfo.Currency)?.Name ?? "-";
  18908. otherPrice = parentInfo.OtherPrice1 + parentInfo.OtherPrice2;
  18909. }
  18910. //当前币种汇率值
  18911. var currRate = 1.0000M;
  18912. var currencyInfo = currencies.FirstOrDefault(x => x.CurrencyCode == currencyName);
  18913. if (currencyInfo != null) currRate = currencyInfo.Rate;
  18914. overseaVehicleCityDatas.add(new
  18915. {
  18916. item.Id,
  18917. area,
  18918. item.CarTypeName,
  18919. serviceType,
  18920. item.Price,
  18921. guidePrice = parentInfo?.GuidePrice ?? 0.00M,
  18922. otherPrice,
  18923. currency = parentInfo?.Currency ?? 0,
  18924. currencyName,
  18925. currRate,
  18926. LastUpdateUserName = sysUers.FirstOrDefault(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-",
  18927. item.LastUpdateTime,
  18928. item.Remark
  18929. });
  18930. }
  18931. var total = overseaVehicleCityDatas.Count;
  18932. var view = new
  18933. {
  18934. visitCountries = string.Join("、", countries),
  18935. //groupSize = 0, //出访人数
  18936. defAirportTransferCoeff = Def_AirportTransferCoeff, //接送机默认报价系数
  18937. defServiceCount = Def_ServiceCount, //接送机默认服务次数
  18938. defTrainCoeff = Def_TrainCoeff, //火车默认报价系数
  18939. defPullCartCoeff = Def_PullCartCoeff, //拉车默认报价系数
  18940. defCityFlightCoeff = Def_CityFlightCoeff, //城市机票默认报价系数
  18941. Currencies = currencies,
  18942. data = overseaVehicleCityDatas
  18943. };
  18944. if (overseaVehicleCityDatas.Count == 0)
  18945. {
  18946. return Ok(JsonView(true, "暂无数据!", view));
  18947. }
  18948. return Ok(JsonView(true, "查询成功!", view, total));
  18949. }
  18950. /// <summary>
  18951. /// 团组模块 - 出入境费用 - 草稿 - 境外用车计算详细信息
  18952. /// </summary>
  18953. /// <param name="draftId"></param>
  18954. /// <param name="currUserId"></param>
  18955. /// <returns></returns>
  18956. [HttpGet("{groupId}")]
  18957. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18958. public async Task<IActionResult> EnterExitCostDraftOVFeeMobileDetails(int draftId, int currUserId)
  18959. {
  18960. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == draftId && x.IsDel == 0).FirstAsync();
  18961. if (eecInfo == null)
  18962. {
  18963. return Ok(JsonView(false, "草稿信息为空"));
  18964. }
  18965. var info = new CityIntervalDraftInfo();
  18966. if (eecInfo != null)
  18967. {
  18968. info = eecInfo.CityIntervalFeeDetails;
  18969. return Ok(JsonView(true, "查询成功!", info));
  18970. }
  18971. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == currUserId).FirstAsync();
  18972. var userName = userInfo?.CnName ?? "-";
  18973. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  18974. //返回默认数据
  18975. info = new CityIntervalDraftInfo()
  18976. {
  18977. APTFeeDetails = new List<RoundTripTransferInfo>() { new() { No = 1, Coefficient = Def_AirportTransferCoeff, ServiceCount = Def_ServiceCount } },
  18978. PullCartFeeDetails = new List<PullCartInfo>() { new() { No = 1, Coefficient = Def_PullCartCoeff } },
  18979. TrainFeeDetails = new List<TrainInfo>() { new() { No = 1, Coefficient = Def_TrainCoeff } },
  18980. CityAirTicketFeeDetails = new List<CityAirTicketInfo>() { new() { No = 1, Coefficient = Def_CityFlightCoeff } },
  18981. LastUpdateUserName = userName,
  18982. LastUpdateTime = nowTime,
  18983. CreateUserName = userName,
  18984. Currencies = await GeneralMethod.EnterExitCostDrafOVFeeUsedCurrencyAsync(draftId),
  18985. CreateTime = nowTime
  18986. };
  18987. return Ok(JsonView(true, "查询成功!", info));
  18988. }
  18989. /// <summary>
  18990. /// 团组模块 - 出入境费用 - 草稿 - 境外用车计算 保存
  18991. /// </summary>
  18992. /// <param name="dto"></param>
  18993. /// <returns></returns>
  18994. [HttpPost]
  18995. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18996. public async Task<IActionResult> EnterExitCostDraftOVFeeMobileSave(EnterExitCostDraftOVFeeSaveDto dto)
  18997. {
  18998. var draftInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == dto.DraftId).FirstAsync();
  18999. if (draftInfo == null)
  19000. {
  19001. return Ok(JsonView(false, "草稿信息为空"));
  19002. }
  19003. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == dto.CurrUserId).FirstAsync();
  19004. if (userInfo == null)
  19005. {
  19006. return Ok(JsonView(false, "员工信息为空"));
  19007. }
  19008. var userName = userInfo?.CnName ?? "-";
  19009. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  19010. var info = new CityIntervalDraftInfo()
  19011. {
  19012. GroupSize = dto.GroupSize,
  19013. APTFeeTotal = dto.APTFeeTotal,
  19014. APTFeeDetails = dto.APTFeeDetails,
  19015. PullCartFeeTotal = dto.PullCartFeeTotal,
  19016. PullCartFeeDetails = dto.PullCartFeeDetails,
  19017. TrainFeeTotal = dto.TrainFeeTotal,
  19018. TrainFeeDetails = dto.TrainFeeDetails,
  19019. CityAirTicketFeeTotal = dto.CityAirTicketFeeTotal,
  19020. CityAirTicketFeeDetails = dto.CityAirTicketFeeDetails,
  19021. Currencies = dto.Currencies,
  19022. LastUpdateUserName = userName,
  19023. LastUpdateTime = nowTime,
  19024. CreateUserName = draftInfo.CityIntervalFeeDetails?.CreateUserName ?? userName,
  19025. CreateTime = draftInfo.CityIntervalFeeDetails?.CreateTime ?? nowTime
  19026. };
  19027. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>()
  19028. .SetColumns(it => it.CityIntervalFeeDetails == info)
  19029. .Where(x => x.Id == draftInfo.Id)
  19030. .ExecuteCommandAsync();
  19031. if (upd < 1)
  19032. {
  19033. return Ok(JsonView(false));
  19034. }
  19035. //返回参数处理
  19036. var label = new StringBuilder();
  19037. if (dto.APTFeeDetails.Any())
  19038. {
  19039. var ovIds = dto.APTFeeDetails.Select(x => x.OvId).ToList();
  19040. var areas = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  19041. .LeftJoin<Res_OverseaVehicle>((ovtp, ov) => ovtp.OvId == ov.Id)
  19042. .Where((ovtp, ov) => ovtp.IsDel == 0 && ovIds.Contains(ovtp.Id))
  19043. .Select((ovtp, ov) => new
  19044. {
  19045. ovtp.Id,
  19046. ov.CountryName,
  19047. ov.CityName
  19048. })
  19049. .ToListAsync();
  19050. if (areas.Any())
  19051. {
  19052. var items = dto.APTFeeDetails
  19053. .Select(item =>
  19054. {
  19055. var areaInfo = areas.FirstOrDefault(x => x.Id == item.OvId);
  19056. if (areaInfo == null) return null;
  19057. return areaInfo.CountryName == areaInfo.CityName
  19058. ? $"{areaInfo.CountryName}({item.Quote:#0.00} CNY)"
  19059. : $"{areaInfo.CountryName}-{areaInfo.CityName}({item.Quote:#0.00} CNY)";
  19060. })
  19061. .Where(item => item != null)
  19062. .ToList();
  19063. string areaLabel = $"接送机({string.Join("、", items)});";
  19064. label.AppendLine(areaLabel);
  19065. }
  19066. }
  19067. if (dto.PullCartFeeDetails.Any())
  19068. {
  19069. var amounts = dto.PullCartFeeDetails.Select(item => $"{item.Quote:#0.00}");
  19070. string subLabel = $"拉车({string.Join("、", amounts)});";
  19071. label.AppendLine(subLabel);
  19072. }
  19073. if (dto.TrainFeeDetails.Any())
  19074. {
  19075. var amounts = dto.TrainFeeDetails.Select(item => $"{item.Quote:#0.00}");
  19076. string subLabel = $"火车票({string.Join("、", amounts)});";
  19077. label.AppendLine(subLabel);
  19078. }
  19079. if (dto.CityAirTicketFeeDetails.Any())
  19080. {
  19081. var amounts = dto.CityAirTicketFeeDetails.Select(item => $"{item.Quote:#0.00}");
  19082. string subLabel = $"城市机票({string.Join("、", amounts)});";
  19083. label.AppendLine(subLabel);
  19084. }
  19085. //费用
  19086. decimal quote = (dto.APTFeeTotal + dto.PullCartFeeTotal + dto.TrainFeeTotal + dto.CityAirTicketFeeTotal).ConvertToDecimal1();
  19087. decimal jjcQuote = quote;
  19088. decimal gwcQuote = quote;
  19089. decimal tdcQuote = quote;
  19090. var view = new
  19091. {
  19092. label = label.ToString(),
  19093. jjcQuote,
  19094. gwcQuote,
  19095. tdcQuote
  19096. };
  19097. return Ok(JsonView(view));
  19098. }
  19099. #endregion
  19100. /// <summary>
  19101. /// 团组模块 - 出入境费用-草稿-移动端 - 创建
  19102. /// </summary>
  19103. /// <returns></returns>
  19104. [HttpPost]
  19105. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19106. public async Task<IActionResult> EnterExitCostDraftMobileCreate(EnterExitCostDraftMobileCreateDto dto)
  19107. {
  19108. if (string.IsNullOrEmpty(dto.DraftName)) return Ok(JsonView(false, "草稿名称为空!"));
  19109. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19110. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  19111. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.DraftName.Equals(dto.DraftName) && it.IsDel == 0);
  19112. if (eecInfo != null) return Ok(JsonView(false, "草稿名称重复!"));
  19113. var rateInfos = await EnterExitCostMobileGetCurrencyInit();
  19114. var info = new Grp_EnterExitCostDraft()
  19115. {
  19116. ProvinceId = dto.ProvinceId,
  19117. DraftName = dto.DraftName,
  19118. CurrencyRemark = CommonFun.GetCurrencyChinaToString(rateInfos),
  19119. CreateUserId = dto.CurrUserId
  19120. };
  19121. _sqlSugar.BeginTran();
  19122. var draftId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  19123. if (draftId < 1)
  19124. {
  19125. _sqlSugar.RollbackTran();
  19126. return Ok(JsonView(false, "草稿创建失败!"));
  19127. }
  19128. //添加默认权限
  19129. await _enterExitCostDraftRep.InitPerm(draftId, dto.CurrUserId);
  19130. _sqlSugar.CommitTran();
  19131. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(draftId, dto.CurrUserId);
  19132. var mobileInfo = new EnterExitCostDraftMobileParentInfoView();
  19133. mobileInfo.Id = draftId;
  19134. mobileInfo.DraftName = dto.DraftName;
  19135. mobileInfo.Currencys = rateInfos;
  19136. mobileInfo.IsAssignPerm = assignPerm;
  19137. return Ok(JsonView(mobileInfo));
  19138. }
  19139. /// <summary>
  19140. /// 出入境费用-草稿-移动端 查看编辑提示消息
  19141. /// </summary>
  19142. private static string _viewPermStr = $"未分配查看权限,如要查看,请联系市场部或国交部负责人!";
  19143. /// <summary>
  19144. /// 团组模块 - 出入境费用-草稿-移动端 - ParentInfo
  19145. /// </summary>
  19146. /// <returns></returns>
  19147. [HttpPost]
  19148. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19149. public async Task<IActionResult> EnterExitCostDraftMobileParentInfo(EnterExitCostDraftMobileParentInfoDto dto)
  19150. {
  19151. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  19152. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19153. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.Id == dto.DraftId && it.IsDel == 0);
  19154. var mobileInfo = new EnterExitCostDraftMobileParentInfoView();
  19155. mobileInfo.Currencys = await EnterExitCostMobileGetCurrencyInit();
  19156. if (eecInfo == null) return Ok(JsonView(mobileInfo));
  19157. //验证查看编辑权限
  19158. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  19159. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  19160. mobileInfo = _mapper.Map<EnterExitCostDraftMobileParentInfoView>(eecInfo);
  19161. mobileInfo.ProvinceId = eecInfo.ProvinceId;
  19162. mobileInfo.IsAssignPerm = assignPerm;
  19163. var dayAndCostData = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  19164. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  19165. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  19166. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId)
  19167. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  19168. {
  19169. ParentId = dac.ParentId,
  19170. SubId = dac.Id,
  19171. Type = dac.Type,
  19172. Days = dac.Days,
  19173. NationalTravelFeeId = dac.NationalTravelFeeId,
  19174. Arae = $"{ntf.Country}-{ntf.City}",
  19175. Cost = dac.Cost,
  19176. Currency = dac.Currency,
  19177. CurrencyName = sd.Name,
  19178. SubTotal = dac.SubTotal,
  19179. })
  19180. .ToList();
  19181. mobileInfo.ChoiceOneTotalCost = eecInfo.InsidePay;
  19182. mobileInfo.ChoiceTwoJJ = eecInfo.SumJJC;
  19183. mobileInfo.ChoiceTwoGW = eecInfo.SumGWC;
  19184. mobileInfo.ChoiceTwoTD = eecInfo.SumTDC;
  19185. mobileInfo.Currencys = !string.IsNullOrEmpty(eecInfo.CurrencyRemark) ? CommonFun.GetCurrencyChinaToList(eecInfo.CurrencyRemark) : mobileInfo.Currencys;
  19186. mobileInfo.ChoiceThreeTotalCost = dayAndCostData.Where(it => it.Type == 1).Sum(x => x.SubTotal); //住宿费 1
  19187. mobileInfo.ChoiceFourTotalCost = dayAndCostData.Where(it => it.Type == 2).Sum(x => x.SubTotal); //伙食费 2
  19188. mobileInfo.ChoiceFiveTotalCost = dayAndCostData.Where(it => it.Type == 3).Sum(x => x.SubTotal); //公杂费 3
  19189. mobileInfo.ChoiceSixTotalCost = dayAndCostData.Where(it => it.Type == 4).Sum(x => x.SubTotal); //培训费 4
  19190. //其他款项
  19191. var otherData = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>()
  19192. .LeftJoin<Sys_SetData>((dop, sd1) => dop.SetDataId == sd1.Id)
  19193. .LeftJoin<Sys_SetData>((dop, sd1, sd2) => dop.Currency == sd2.Id)
  19194. .Where((dop, sd1, sd2) => dop.IsDel == 0 && dop.ParentId == dto.DraftId)
  19195. .OrderBy((dop, sd1, sd2) => dop.Index)
  19196. .Select((dop, sd1, sd2) => new DayOtherPriceDraftMobileInfoView
  19197. {
  19198. ParentId = dop.ParentId,
  19199. SubId = dop.Id,
  19200. Index = dop.Index,
  19201. SetDataId = dop.SetDataId,
  19202. SetDataName = sd1.Name,
  19203. Cost = dop.Cost,
  19204. Currency = dop.Currency,
  19205. CurrencyName = sd2.Remark,
  19206. SubTotal = dop.SubTotal,
  19207. Remark = dop.Remark,
  19208. })
  19209. .ToArray();
  19210. mobileInfo.OtherExpensesTotalCost = otherData.Sum(x => x.SubTotal);
  19211. return Ok(mobileInfo);
  19212. }
  19213. /// <summary>
  19214. /// 团组模块 - 出入境费用-草稿-移动端 - SubInfo
  19215. /// </summary>
  19216. /// <returns></returns>
  19217. [HttpPost]
  19218. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19219. public async Task<IActionResult> EnterExitCostDraftMobileSubInfo(PostEnterExitCostDraftMobileSubInfoDto dto)
  19220. {
  19221. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19222. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  19223. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19224. var subTypes = new List<int>() { 1, 2, 3, 4, 5, 6, 7 };
  19225. if (!subTypes.Contains(dto.SubType)) return Ok(JsonView(false, $"请传入有效的subTypeId!"));
  19226. //验证查看编辑权限
  19227. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  19228. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  19229. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.Id == dto.DraftId && it.IsDel == 0);
  19230. if (eecInfo == null) return Ok(JsonView(false, $"出入境费用明细未录入!"));
  19231. var subType = dto.SubType;
  19232. if (subType == 1) //1:境内费用
  19233. {
  19234. var oneData = new ChoiceOneMobileSubInfoView()
  19235. {
  19236. Id = eecInfo.Id,
  19237. ChoiceOne = eecInfo.ChoiceOne,
  19238. ChoiceOneTotalCost = eecInfo.InsidePay,
  19239. Visa = eecInfo.Visa,
  19240. VisaRemark = eecInfo.VisaRemark,
  19241. YiMiao = eecInfo.YiMiao,
  19242. HeSuan = eecInfo.HeSuan,
  19243. Service = eecInfo.Service,
  19244. Ticket = eecInfo.Ticket,
  19245. Safe = eecInfo.Safe,
  19246. FirstItemRemark = eecInfo.FirstItemRemark
  19247. };
  19248. return Ok(JsonView(oneData));
  19249. }
  19250. else if (subType == 2) //2:国际旅费
  19251. {
  19252. var twoData = new ChoiceTwoMobileSubInfoView()
  19253. {
  19254. Id = eecInfo.Id,
  19255. ChoiceTwoJJ = eecInfo.SumJJC,
  19256. OutsideJJPay = eecInfo.OutsideJJPay,
  19257. ChoiceTwoGW = eecInfo.SumGWC,
  19258. OutsideGWPay = eecInfo.OutsideGWPay,
  19259. ChoiceTwoTD = eecInfo.SumTDC,
  19260. OutsideTDPay = eecInfo.OutsideTDPay,
  19261. AirJJ = eecInfo.AirJJ,
  19262. AirGW = eecInfo.AirGW,
  19263. AirTD = eecInfo.AirTD,
  19264. CityTranffic = eecInfo.CityTranffic,
  19265. CityTranffic1 = eecInfo.CityTranffic1,
  19266. CityTranffic2 = eecInfo.CityTranffic2,
  19267. TwoItemRemark = eecInfo.TwoItemRemark
  19268. };
  19269. return Ok(JsonView(twoData));
  19270. }
  19271. else if (subType == 3) //3:住宿费
  19272. {
  19273. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  19274. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  19275. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  19276. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId && dac.Type == 1)
  19277. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  19278. {
  19279. ParentId = dac.ParentId,
  19280. SubId = dac.Id,
  19281. Type = dac.Type,
  19282. Days = dac.Days,
  19283. NationalTravelFeeId = dac.NationalTravelFeeId,
  19284. Arae = $"{ntf.Country}-{ntf.City}",
  19285. Cost = dac.Cost,
  19286. Currency = dac.Currency,
  19287. CurrencyName = sd.Name,
  19288. SubTotal = dac.SubTotal,
  19289. })
  19290. .ToArray();
  19291. var data = new ChoiceDraftMobileSubInfo3To6View()
  19292. {
  19293. ParentId = eecInfo.Id,
  19294. Choice = eecInfo.ChoiceThree,
  19295. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  19296. Details = dayAndCostDatas
  19297. };
  19298. return Ok(JsonView(data));
  19299. }
  19300. else if (subType == 4) //4:伙食费
  19301. {
  19302. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  19303. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  19304. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  19305. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId && dac.Type == 2)
  19306. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  19307. {
  19308. ParentId = dac.ParentId,
  19309. SubId = dac.Id,
  19310. Type = dac.Type,
  19311. Days = dac.Days,
  19312. NationalTravelFeeId = dac.NationalTravelFeeId,
  19313. Arae = $"{ntf.Country}-{ntf.City}",
  19314. Cost = dac.Cost,
  19315. Currency = dac.Currency,
  19316. CurrencyName = sd.Name,
  19317. SubTotal = dac.SubTotal,
  19318. })
  19319. .ToArray();
  19320. var data = new ChoiceDraftMobileSubInfo3To6View()
  19321. {
  19322. ParentId = eecInfo.Id,
  19323. Choice = eecInfo.ChoiceFour,
  19324. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  19325. Details = dayAndCostDatas
  19326. };
  19327. return Ok(JsonView(data));
  19328. }
  19329. else if (subType == 5) //5:公杂费
  19330. {
  19331. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  19332. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  19333. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  19334. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId && dac.Type == 3)
  19335. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  19336. {
  19337. ParentId = dac.ParentId,
  19338. SubId = dac.Id,
  19339. Type = dac.Type,
  19340. Days = dac.Days,
  19341. NationalTravelFeeId = dac.NationalTravelFeeId,
  19342. Arae = $"{ntf.Country}-{ntf.City}",
  19343. Cost = dac.Cost,
  19344. Currency = dac.Currency,
  19345. CurrencyName = sd.Name,
  19346. SubTotal = dac.SubTotal,
  19347. })
  19348. .ToArray();
  19349. var data = new ChoiceDraftMobileSubInfo3To6View()
  19350. {
  19351. ParentId = eecInfo.Id,
  19352. Choice = eecInfo.ChoiceFive,
  19353. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  19354. Details = dayAndCostDatas
  19355. };
  19356. return Ok(JsonView(data));
  19357. }
  19358. else if (subType == 6) //6:培训费
  19359. {
  19360. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  19361. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  19362. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  19363. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId && dac.Type == 4)
  19364. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  19365. {
  19366. ParentId = dac.ParentId,
  19367. SubId = dac.Id,
  19368. Type = dac.Type,
  19369. Days = dac.Days,
  19370. NationalTravelFeeId = dac.NationalTravelFeeId,
  19371. Arae = $"{ntf.Country}-{ntf.City}",
  19372. Cost = dac.Cost,
  19373. Currency = dac.Currency,
  19374. CurrencyName = sd.Name,
  19375. SubTotal = dac.SubTotal,
  19376. })
  19377. .ToArray();
  19378. var data = new ChoiceDraftMobileSubInfo3To6View()
  19379. {
  19380. ParentId = eecInfo.Id,
  19381. Choice = eecInfo.ChoiceSix,
  19382. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  19383. Details = dayAndCostDatas
  19384. };
  19385. return Ok(JsonView(data));
  19386. }
  19387. else if (subType == 7) //7:其他
  19388. {
  19389. //其他款项
  19390. var otherData = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>()
  19391. .LeftJoin<Sys_SetData>((dop, sd1) => dop.SetDataId == sd1.Id)
  19392. .LeftJoin<Sys_SetData>((dop, sd1, sd2) => dop.Currency == sd2.Id)
  19393. .Where((dop, sd1, sd2) => dop.IsDel == 0 && dop.ParentId == dto.DraftId)
  19394. .OrderBy((dop, sd1, sd2) => dop.Index)
  19395. .Select((dop, sd1, sd2) => new DayOtherPriceDraftMobileInfoView
  19396. {
  19397. ParentId = dop.ParentId,
  19398. SubId = dop.Id,
  19399. Index = dop.Index,
  19400. SetDataId = dop.SetDataId,
  19401. SetDataName = sd1.Name,
  19402. Cost = dop.Cost,
  19403. Currency = dop.Currency,
  19404. CurrencyName = sd2.Name,
  19405. SubTotal = dop.SubTotal,
  19406. Remark = dop.Remark,
  19407. })
  19408. .ToArray();
  19409. var data = new ChoiceSevenDraftMobileSubInfoView()
  19410. {
  19411. ParentId = eecInfo.Id,
  19412. OtherExpenses_Checked = eecInfo.OtherExpenses_Checked,
  19413. OtherExpensesTotalCost = otherData.Sum(x => x.SubTotal),
  19414. Details = otherData
  19415. };
  19416. return Ok(JsonView(data));
  19417. }
  19418. return Ok(JsonView(false));
  19419. }
  19420. #region op
  19421. ///// <summary>
  19422. ///// 移动端更新费用消息通知
  19423. ///// </summary>
  19424. ///// <param name="draftId"></param>
  19425. ///// <param name="id"></param>
  19426. ///// <param name="currUserId"></param>
  19427. //private async Task EnterExitCostDraftMobileOpNotice(int draftId, int id, int currUserId)
  19428. //{
  19429. // try
  19430. // {
  19431. // ////生成默认文件pdf并且通知人员
  19432. // //var fileView = await GeneralMethod.EnterExitCostDownload(new EnterExitCostDownloadDto()
  19433. // //{
  19434. // // DiId = draftId,
  19435. // // ExportType = 1,
  19436. // // SubTypeId = 1005
  19437. // //}, "pdf");
  19438. // ////发送通知
  19439. // //string fileUrl = (string)fileView.Data.GetType().GetProperty("Url").GetValue(fileView.Data, null);
  19440. // //string md5Sign = GeneralMethod.Encrypt($"{id}&fileName={fileUrl}");
  19441. // //string url = string.Format("http://oa.pan-american-intl.com:4399/#/Sankunginfo?sign={0}&fileName={1}", id, fileUrl);
  19442. // //await AppNoticeLibrary.SendUserMsg_GroupShare_ToGM(draftId, new List<string>() { "208", "233", "21" }, currUserId, url);
  19443. // ////汇率信息记录
  19444. // //await GeneralMethod.RateRecordSave(currUserId, id, "出入境费用");
  19445. // }
  19446. // catch (Exception ex)
  19447. // {
  19448. // //记录日志
  19449. // throw;
  19450. // }
  19451. //}
  19452. /// <summary>
  19453. /// 验证出入境费用数据是否存在
  19454. /// 不存在添加
  19455. /// </summary>
  19456. /// <param name="draftId"></param>
  19457. /// <param name="currUserId"></param>
  19458. /// <returns></returns>
  19459. private async Task<int> EnterExitCostDraftVerifyIsNull(int draftId, int currUserId)
  19460. {
  19461. var parentId = 0;
  19462. var info = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.IsDel == 0 && x.Id == draftId).OrderByDescending(x => x.CreateTime).FirstAsync();
  19463. if (info != null) parentId = info.Id;
  19464. else
  19465. {
  19466. var currencys = await EnterExitCostDraftMobileGetCurrencyInit();
  19467. int addId = await _sqlSugar.Insertable(new Grp_EnterExitCostDraft() { CreateUserId = currUserId, CurrencyRemark = JsonConvert.SerializeObject(currencys) }).ExecuteReturnIdentityAsync();
  19468. parentId = addId;
  19469. }
  19470. return parentId;
  19471. }
  19472. /// <summary>
  19473. /// 团组模块 - 出入境费用-草稿-移动端 - 查看权限用户
  19474. /// </summary>
  19475. /// <returns></returns>
  19476. [HttpPost]
  19477. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19478. public async Task<IActionResult> EnterExitCostDraftMobileViewPermissionUsers(EnterExitCostDraftMobileViewPermissionUsersDto dto)
  19479. {
  19480. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  19481. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19482. //验证查看权限
  19483. (bool isView, bool isSet) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  19484. if (!isView) return Ok(JsonView(false, _viewPermStr));
  19485. var userIds = await _sqlSugar
  19486. .Queryable<Grp_EnterExitCostDraftPermission>()
  19487. .Where(x => x.IsDel == 0 && x.DraftId == dto.DraftId)
  19488. .Select(x => x.UserId)
  19489. .ToArrayAsync();
  19490. var perUsers = await _enterExitCostDraftRep.PermissionViewUsersAsync();
  19491. var perUsersView = new List<dynamic>();
  19492. var feeBasePerm = AppSettingsHelper.Get<FeeBasePermView>("FeeBasePerm");
  19493. var viewPermissionData = new List<PermissionViewUserview>();
  19494. if (feeBasePerm.Any())
  19495. {
  19496. foreach (var item in feeBasePerm)
  19497. {
  19498. if (item.Users.Any())
  19499. {
  19500. viewPermissionData.AddRange(item.Users);
  19501. }
  19502. }
  19503. }
  19504. foreach (var item in perUsers)
  19505. {
  19506. bool isView1 = false;
  19507. if (userIds.Any(x => x == item.Id)) isView1 = true;
  19508. else if (viewPermissionData.Any(x => x.Id == dto.CurrUserId) && item.Id == dto.CurrUserId) isView1 = true;
  19509. perUsersView.Add(new { Id = item.Id, Name = item.Name, IsView = isView1 });
  19510. }
  19511. return Ok(JsonView(perUsersView));
  19512. }
  19513. /// <summary>
  19514. /// 团组模块 - 出入境费用-草稿-移动端 - 设置view权限
  19515. /// </summary>
  19516. /// <returns></returns>
  19517. [HttpPost]
  19518. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19519. public async Task<IActionResult> EnterExitCostDraftMobileSetViewPermissiion(EnterExitCostDraftMobileSetViewPermissiionDto dto)
  19520. {
  19521. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19522. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  19523. if (dto.UserIds.Length < 1) return Ok(JsonView(false, "请传入有效的userId;"));
  19524. //验证查看编辑权限
  19525. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  19526. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  19527. var permissions = new List<Grp_EnterExitCostDraftPermission>() { };
  19528. foreach (var userId in dto.UserIds)
  19529. {
  19530. permissions.Add(new Grp_EnterExitCostDraftPermission { Permission = 1, DraftId = dto.DraftId, UserId = userId, CreateUserId = dto.CurrUserId });
  19531. }
  19532. if (permissions.Any())
  19533. {
  19534. if (!permissions.Any(x => x.UserId == dto.CurrUserId))
  19535. {
  19536. permissions.Add(new Grp_EnterExitCostDraftPermission { Permission = 1, DraftId = dto.DraftId, UserId = dto.CurrUserId, CreateUserId = dto.CurrUserId });
  19537. }
  19538. _sqlSugar.BeginTran();
  19539. await _sqlSugar.Deleteable<Grp_EnterExitCostDraftPermission>().Where(it => it.DraftId == dto.DraftId).ExecuteCommandAsync();
  19540. var result = await _sqlSugar.Insertable(permissions).ExecuteCommandAsync();
  19541. if (result < 1)
  19542. {
  19543. _sqlSugar.RollbackTran();
  19544. return Ok(JsonView(false));
  19545. }
  19546. _sqlSugar.CommitTran();
  19547. return Ok(JsonView(true));
  19548. }
  19549. return Ok(JsonView(false));
  19550. }
  19551. /// <summary>
  19552. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 省份
  19553. /// </summary>
  19554. /// <returns></returns>
  19555. [HttpPost]
  19556. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19557. public async Task<IActionResult> EnterExitCostDraftMobileOpProv(EnterExitCostDraftMobileOpProvDto dto)
  19558. {
  19559. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19560. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19561. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19562. if (dto.ProvinceId < 1) return Ok(JsonView(false, "请传入有效的省份Id!"));
  19563. int id = dto.DraftId;
  19564. if (id <= 0) //add
  19565. {
  19566. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  19567. var add = await _sqlSugar.Insertable(new Grp_EnterExitCostDraft() { ProvinceId = dto.ProvinceId, CreateUserId = dto.CurrUserId }).ExecuteCommandAsync();
  19568. if (add < 1) return Ok(JsonView(false));
  19569. id = add;
  19570. }
  19571. else //update
  19572. {
  19573. //验证查看编辑权限
  19574. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  19575. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  19576. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>().SetColumns(x => new Grp_EnterExitCostDraft() { ProvinceId = dto.ProvinceId }).Where(x => x.Id == dto.DraftId).ExecuteCommandAsync();
  19577. if (upd < 1) return Ok(JsonView(false));
  19578. }
  19579. return Ok(JsonView(new { parentId = id }));
  19580. }
  19581. /// <summary>
  19582. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 汇率
  19583. /// </summary>
  19584. /// <returns></returns>
  19585. [HttpPost]
  19586. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19587. public async Task<IActionResult> EnterExitCostDraftMobileOpRate(PostEnterExitCostDraftMobileFeeRateOpDto dto)
  19588. {
  19589. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19590. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19591. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19592. if (dto.Currencys.Length < 1) return Ok(JsonView(false, "请传入有效的汇率信息!"));
  19593. var currencyStr = CommonFun.GetCurrencyChinaToString(dto.Currencys.ToList());
  19594. int id = dto.DraftId;
  19595. if (id <= 0) //add
  19596. {
  19597. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  19598. var add = await _sqlSugar.Insertable(new Grp_EnterExitCostDraft() { ProvinceId = dto.ProvinceId, CurrencyRemark = currencyStr, CreateUserId = dto.CurrUserId }).ExecuteCommandAsync();
  19599. if (add < 1) return Ok(JsonView(false));
  19600. id = add;
  19601. }
  19602. else //update
  19603. {
  19604. //验证查看编辑权限
  19605. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  19606. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  19607. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>().SetColumns(x => new Grp_EnterExitCostDraft() { CurrencyRemark = currencyStr }).Where(x => x.Id == dto.DraftId).ExecuteCommandAsync();
  19608. if (upd < 1) return Ok(JsonView(false));
  19609. }
  19610. #region 汇率变更时更改币种相关费用
  19611. var opDayCosts = new List<Grp_DayAndCostDraft>();
  19612. var opDayOtherCosts = new List<Grp_DayOtherPriceDraft>();
  19613. var eecCurrencys = dto.Currencys.Select(x => x.CurrencyCode.ToUpper()).ToList();
  19614. var dayCosts = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  19615. .LeftJoin<Sys_SetData>((dac, sd) => dac.Currency == sd.Id)
  19616. .Where((dac, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId)
  19617. .Select((dac, sd) => new
  19618. {
  19619. dac.Id,
  19620. dac.ParentId,
  19621. CurrencyCode = sd.Name,
  19622. dac.Cost
  19623. })
  19624. .ToList();
  19625. var dayOtherCosts = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>()
  19626. .LeftJoin<Sys_SetData>((dop, sd) => dop.Currency == sd.Id)
  19627. .Where((dop, sd) => dop.IsDel == 0 && dop.ParentId == dto.DraftId)
  19628. .Select((dop, sd) => new
  19629. {
  19630. dop.Id,
  19631. dop.ParentId,
  19632. CurrencyCode = sd.Name,
  19633. dop.Cost
  19634. })
  19635. .ToList();
  19636. if (dayCosts.Count > 0)
  19637. {
  19638. var new_dayCosts = dayCosts.Where(x => eecCurrencys.Contains(x.CurrencyCode.ToUpper())).GroupBy(x => x.CurrencyCode);
  19639. foreach (var dc in new_dayCosts)
  19640. {
  19641. var thisCurrency = dc.Key.ToUpper();
  19642. var thisRate = dto.Currencys.Where(x => x.CurrencyCode.ToUpper().Equals(thisCurrency)).First()?.Rate ?? 0.00M;
  19643. if (thisRate == 0.00M) continue;
  19644. foreach (var dcSub in dc)
  19645. {
  19646. opDayCosts.Add(new Grp_DayAndCostDraft()
  19647. {
  19648. Id = dcSub.Id,
  19649. ParentId = dcSub.ParentId,
  19650. Cost = dcSub.Cost,
  19651. SubTotal = dcSub.Cost * thisRate,
  19652. Remark = $"[移动端->汇率变更时费用变更][变更信息:currency:{thisCurrency}、opDatetime:{DateTime.Now:yyyy-MM-dd HH:mm:ss}、opUserId:{dto.CurrUserId}]"
  19653. });
  19654. }
  19655. }
  19656. if (opDayCosts.Count > 0)
  19657. {
  19658. await _sqlSugar.Updateable(opDayCosts).UpdateColumns(x => new { x.SubTotal, x.Remark }).WhereColumns(x => new { x.Id }).ExecuteCommandAsync();
  19659. }
  19660. }
  19661. if (dayOtherCosts.Count > 0)
  19662. {
  19663. var new_dayOtherCosts = dayOtherCosts.Where(x => eecCurrencys.Contains(x.CurrencyCode.ToUpper())).GroupBy(x => x.CurrencyCode);
  19664. foreach (var dc in new_dayOtherCosts)
  19665. {
  19666. var thisCurrency = dc.Key.ToUpper();
  19667. var thisRate = dto.Currencys.Where(x => x.CurrencyCode.ToUpper().Equals(thisCurrency)).First()?.Rate ?? 0.00M;
  19668. if (thisRate == 0.00M) continue;
  19669. foreach (var dcSub in dc)
  19670. {
  19671. opDayOtherCosts.Add(new Grp_DayOtherPriceDraft()
  19672. {
  19673. Id = dcSub.Id,
  19674. ParentId = dcSub.ParentId,
  19675. Cost = dcSub.Cost,
  19676. SubTotal = dcSub.Cost * thisRate,
  19677. // Remark = $"[移动端->汇率变更时费用变更][变更信息:currency:{thisCurrency}、opDatetime:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}、opUserId:{dto.CurrUserId}]"
  19678. });
  19679. }
  19680. }
  19681. if (opDayOtherCosts.Count > 0)
  19682. {
  19683. await _sqlSugar.Updateable(opDayOtherCosts).UpdateColumns(x => new { x.SubTotal }).WhereColumns(x => new { x.Id }).ExecuteCommandAsync();
  19684. }
  19685. }
  19686. #endregion
  19687. ////消息通知
  19688. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  19689. ////汇率信息记录
  19690. //await GeneralMethod.RateRecordSave(dto.CurrUserId, id, "出入境费用");
  19691. return Ok(JsonView(new { parentId = id }));
  19692. }
  19693. /// <summary>
  19694. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 复选框
  19695. /// </summary>
  19696. /// <returns></returns>
  19697. [HttpPost]
  19698. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19699. public async Task<IActionResult> EnterExitCostDraftMobileOpCheckbox(PostEnterExitCostDraftMobileFeeOpCheckboxDto dto)
  19700. {
  19701. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19702. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  19703. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19704. var checkboxInfo = _mapper.Map<Grp_EnterExitCostDraft>(dto);
  19705. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  19706. int id = dto.DraftId;
  19707. if (id <= 0) //add
  19708. {
  19709. checkboxInfo.ProvinceId = dto.ProvinceId;
  19710. checkboxInfo.CreateUserId = dto.CurrUserId;
  19711. checkboxInfo.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostDraftMobileGetCurrencyInit());
  19712. var add = await _sqlSugar.Insertable(checkboxInfo).ExecuteCommandAsync();
  19713. if (add < 1) return Ok(JsonView(false));
  19714. }
  19715. else //update
  19716. {
  19717. var upd = await _sqlSugar.Updateable(checkboxInfo)
  19718. .UpdateColumns(x => new
  19719. {
  19720. x.ChoiceOne,
  19721. x.ChoiceTwo,
  19722. x.SumJJC,
  19723. x.SumGWC,
  19724. x.SumTDC,
  19725. x.ChoiceThree,
  19726. x.ChoiceFour,
  19727. x.ChoiceFive,
  19728. x.ChoiceSix,
  19729. x.OtherExpenses_Checked
  19730. })
  19731. .Where(x => x.Id == id)
  19732. .ExecuteCommandAsync();
  19733. if (upd < 1) return Ok(JsonView(false));
  19734. }
  19735. return Ok(JsonView(new { parentId = id }));
  19736. }
  19737. /// <summary>
  19738. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 3-7项复选框单个复选框
  19739. /// </summary>
  19740. /// <returns></returns>
  19741. [HttpPost]
  19742. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19743. public async Task<IActionResult> EnterExitCostDraftMobileOpSingleCheckbox(EnterExitCostDarftMobileOpSingleCheckboxDto dto)
  19744. {
  19745. int itemTypeId = dto.ItemType, currUserId = dto.CurrUserId, draftId = dto.DraftId, isSelected = dto.IsSelected;
  19746. var itemTypes = new List<int>() { 3, 4, 5, 6, 7 };
  19747. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19748. if (draftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  19749. if (currUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19750. if (!itemTypes.Contains(itemTypeId)) return Ok(JsonView(false, $"请传入要修改的项类型;3:住宿费; 4:伙食费; 5:公杂费; 6:培训费;7:其他;"));
  19751. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  19752. var checkboxInfo = new Grp_EnterExitCostDraft()
  19753. {
  19754. Id = draftId,
  19755. ProvinceId = dto.ProvinceId,
  19756. CreateUserId = currUserId
  19757. };
  19758. if (itemTypeId == 3) checkboxInfo.ChoiceThree = isSelected;
  19759. else if (itemTypeId == 4) checkboxInfo.ChoiceFour = isSelected;
  19760. else if (itemTypeId == 5) checkboxInfo.ChoiceFive = isSelected;
  19761. else if (itemTypeId == 6) checkboxInfo.ChoiceSix = isSelected;
  19762. else if (itemTypeId == 7) checkboxInfo.OtherExpenses_Checked = isSelected;
  19763. if (draftId <= 0) //add
  19764. {
  19765. checkboxInfo.CreateUserId = dto.CurrUserId;
  19766. checkboxInfo.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  19767. var add = await _sqlSugar.Insertable(checkboxInfo).ExecuteCommandAsync();
  19768. if (add < 1) return Ok(JsonView(false));
  19769. }
  19770. else //update
  19771. {
  19772. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>()
  19773. .SetColumnsIF(itemTypeId == 3, it => it.ChoiceThree == isSelected)
  19774. .SetColumnsIF(itemTypeId == 4, it => it.ChoiceFour == isSelected)
  19775. .SetColumnsIF(itemTypeId == 5, it => it.ChoiceFive == isSelected)
  19776. .SetColumnsIF(itemTypeId == 6, it => it.ChoiceSix == isSelected)
  19777. .SetColumnsIF(itemTypeId == 7, it => it.OtherExpenses_Checked == isSelected)
  19778. .Where(x => x.Id == draftId)
  19779. .ExecuteCommandAsync();
  19780. if (upd < 1) return Ok(JsonView(false));
  19781. }
  19782. return Ok(JsonView(new { parentId = draftId }));
  19783. }
  19784. /// <summary>
  19785. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 境内费用 Step1
  19786. /// </summary>
  19787. /// <returns></returns>
  19788. [HttpPost]
  19789. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19790. public async Task<IActionResult> EnterExitCostDraftMobileOpStep1(PostEnterExitCostDraftMobileOpStep1Dto dto)
  19791. {
  19792. int id = dto.DraftId, currUserId = dto.CurrUserId;
  19793. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19794. if (id < 1) return Ok(JsonView(false, MsgTips.DiId));
  19795. if (currUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19796. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  19797. var info = _mapper.Map<Grp_EnterExitCostDraft>(dto);
  19798. info.ProvinceId = dto.ProvinceId;
  19799. info.FirstItemRemark = dto.FirstItemRemark;
  19800. info.InsidePay = dto.Visa + dto.Service + dto.Safe + dto.Ticket + dto.HeSuan + dto.YiMiao;
  19801. if (id <= 0) //add
  19802. {
  19803. info.CreateUserId = dto.CurrUserId;
  19804. info.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  19805. var add = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  19806. if (add < 1) return Ok(JsonView(false));
  19807. id = add;
  19808. }
  19809. else //update
  19810. {
  19811. var upd = await _sqlSugar.Updateable(info)
  19812. .UpdateColumns(x => new
  19813. {
  19814. x.ChoiceOne,
  19815. x.InsidePay,
  19816. x.VisaRemark,
  19817. x.Visa,
  19818. x.Service,
  19819. x.Safe,
  19820. x.Ticket,
  19821. x.HeSuan,
  19822. x.YiMiao,
  19823. x.FirstItemRemark
  19824. })
  19825. .Where(x => x.Id == id)
  19826. .ExecuteCommandAsync();
  19827. if (upd < 1) return Ok(JsonView(false));
  19828. }
  19829. ////消息通知
  19830. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  19831. return Ok(JsonView(new { parentId = id, itemTotal = info.InsidePay }));
  19832. }
  19833. /// <summary>
  19834. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 国际旅费 Step2
  19835. /// </summary>
  19836. /// <returns></returns>
  19837. [HttpPost]
  19838. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19839. public async Task<IActionResult> EnterExitCostDraftMobileOpStep2(PostEnterExitCostDraftMobileOpStep2Dto dto)
  19840. {
  19841. int id = dto.DraftId;
  19842. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19843. if (id < 1) return Ok(JsonView(false, MsgTips.DiId));
  19844. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19845. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  19846. var info = _mapper.Map<Grp_EnterExitCostDraft>(dto);
  19847. info.ProvinceId = dto.ProvinceId;
  19848. info.OutsideJJPay = dto.OutsideJJPay;
  19849. info.OutsideGWPay = dto.OutsideGWPay;
  19850. info.OutsideTDPay = dto.OutsideTDPay;
  19851. info.AirJJ = dto.AirJJ;
  19852. info.AirGW = dto.AirGW;
  19853. info.AirTD = dto.AirTD;
  19854. info.CityTranffic = dto.CityTranffic;
  19855. info.CityTranffic1 = dto.CityTranffic1;
  19856. info.CityTranffic2 = dto.CityTranffic2;
  19857. info.TwoItemRemark = dto.TwoItemRemark;
  19858. info.SumJJC = dto.ChoiceTwoJJ;
  19859. info.SumGWC = dto.ChoiceTwoGW;
  19860. info.SumTDC = dto.ChoiceTwoTD;
  19861. decimal jjcItemTotal = 0.00M, gwcItemTotal = 0.00M, tdcItemTotal = 0.00M;
  19862. if (id <= 0) //add
  19863. {
  19864. info.CreateUserId = dto.CurrUserId;
  19865. info.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  19866. var addId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  19867. if (addId <= 0) return Ok(JsonView(false));
  19868. id = addId;
  19869. }
  19870. else //update
  19871. {
  19872. var upd = await _sqlSugar.Updateable(info)
  19873. .UpdateColumns(x => new
  19874. {
  19875. x.SumJJC,
  19876. x.OutsideJJPay,
  19877. x.SumGWC,
  19878. x.OutsideGWPay,
  19879. x.SumTDC,
  19880. x.OutsideTDPay,
  19881. x.AirJJ,
  19882. x.AirGW,
  19883. x.AirTD,
  19884. x.CityTranffic,
  19885. x.CityTranffic1,
  19886. x.CityTranffic2,
  19887. x.TwoItemRemark
  19888. })
  19889. .Where(x => x.Id == id)
  19890. .ExecuteCommandAsync();
  19891. if (upd < 1) return Ok(JsonView(false));
  19892. }
  19893. jjcItemTotal = info.AirJJ + info.CityTranffic;
  19894. gwcItemTotal = info.AirGW + info.CityTranffic;
  19895. tdcItemTotal = info.AirTD + info.CityTranffic;
  19896. ////消息通知
  19897. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  19898. return Ok(JsonView(new
  19899. {
  19900. parentId = id,
  19901. choiceTwoJJ = dto.ChoiceTwoJJ,
  19902. jjcItemTotal = jjcItemTotal,
  19903. choiceTwoGW = dto.ChoiceTwoGW,
  19904. gwcItemTotal = gwcItemTotal,
  19905. choiceTwoTD = dto.ChoiceTwoTD,
  19906. tdcItemTotal = tdcItemTotal
  19907. }));
  19908. }
  19909. /// <summary>
  19910. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 批量(住宿、伙食、公杂、培训) Step3-Step6
  19911. /// </summary>
  19912. /// <returns></returns>
  19913. [HttpPost]
  19914. [ApiExplorerSettings(IgnoreApi = true)]
  19915. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19916. public async Task<IActionResult> EnterExitCostDraftMobileOpBatchStep3To6(PostEnterExitCostDraftMobileOpStep3To6Dto dto)
  19917. {
  19918. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19919. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  19920. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19921. if (dto.Infos.Length < 1) return Ok(JsonView(false, "请传入有效的费用信息!"));
  19922. var feeTypeIds = new List<int>() { 1, 2, 3, 4, };
  19923. if (!feeTypeIds.Contains(dto.FeeType)) return Ok(JsonView(false, "请传入有效的费用类型!"));
  19924. var infos1 = _mapper.Map<List<Grp_DayAndCostDraft>>(dto.Infos);
  19925. var infos = infos1.Select(x => new Grp_DayAndCostDraft
  19926. {
  19927. Id = x.Id,
  19928. ParentId = dto.DraftId,
  19929. Type = dto.FeeType,
  19930. Days = x.Days,
  19931. NationalTravelFeeId = x.NationalTravelFeeId,
  19932. Cost = x.Cost,
  19933. Currency = x.Currency,
  19934. SubTotal = x.SubTotal,
  19935. CreateUserId = dto.CurrUserId
  19936. })
  19937. .ToList();
  19938. var adds = infos.Where(x => x.Id <= 0).ToList();
  19939. var upds = infos.Where(x => x.Id > 0).ToList();
  19940. if (adds.Count > 0)
  19941. {
  19942. var add = await _sqlSugar.Insertable(adds).ExecuteCommandAsync();
  19943. if (add < 1) return Ok(JsonView(false));
  19944. }
  19945. if (upds.Count > 0)
  19946. {
  19947. var upd = await _sqlSugar.Updateable(adds)
  19948. .UpdateColumns(x => new
  19949. {
  19950. x.Days,
  19951. x.NationalTravelFeeId,
  19952. x.Cost,
  19953. x.Currency,
  19954. x.SubTotal
  19955. })
  19956. .WhereColumns(x => new { x.Id })
  19957. .ExecuteCommandAsync();
  19958. if (upd < 1) return Ok(JsonView(false));
  19959. }
  19960. var itemTotal = _sqlSugar.Queryable<Grp_DayAndCostDraft>().Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId && x.Type == dto.FeeType).Sum(x => x.SubTotal);
  19961. ////消息通知
  19962. //var id = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId).First()?.Id ?? 0;
  19963. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  19964. return Ok(JsonView(new { itemTotal = itemTotal }));
  19965. }
  19966. /// <summary>
  19967. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 单条(住宿、伙食、公杂、培训) Step3-Step6
  19968. /// </summary>
  19969. /// <returns></returns>
  19970. [HttpPost]
  19971. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19972. public async Task<IActionResult> EnterExitCostDraftMobileOpSingleStep3To6(PostEnterExitCostDraftMobileOpSingleStep3To6Dto dto)
  19973. {
  19974. var feeTypeIds = new List<int>() { 3, 4, 5, 6 };
  19975. int subId = dto.SubId, feeType = dto.FeeType;
  19976. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19977. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  19978. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19979. if (!feeTypeIds.Contains(dto.FeeType)) return Ok(JsonView(false, "请传入有效的费用类型!"));
  19980. var subInfo = _mapper.Map<Grp_DayAndCostDraft>(dto);
  19981. subInfo.Id = subId;
  19982. subInfo.ParentId = dto.DraftId;
  19983. if (feeType == 3) subInfo.Type = 1;
  19984. else if (feeType == 4) subInfo.Type = 2;
  19985. else if (feeType == 5) subInfo.Type = 3;
  19986. else if (feeType == 6) subInfo.Type = 4;
  19987. subInfo.CreateUserId = dto.CurrUserId;
  19988. int parentId = await EnterExitCostDraftVerifyIsNull(dto.DraftId, dto.CurrUserId); //主表验证
  19989. if (parentId < 1) return Ok(JsonView(false));
  19990. //子表op
  19991. if (subId < 1)
  19992. {
  19993. var subAdd = await _sqlSugar.Insertable(subInfo).ExecuteCommandAsync();
  19994. if (subAdd < 1) return Ok(JsonView(false));
  19995. }
  19996. else
  19997. {
  19998. var subUpd = await _sqlSugar.Updateable(subInfo)
  19999. .UpdateColumns(x => new
  20000. {
  20001. x.Days,
  20002. x.NationalTravelFeeId,
  20003. x.Cost,
  20004. x.Currency,
  20005. x.SubTotal
  20006. })
  20007. .WhereColumns(x => new { x.Id })
  20008. .ExecuteCommandAsync();
  20009. if (subUpd < 1) return Ok(JsonView(false));
  20010. }
  20011. var itemTotal = _sqlSugar.Queryable<Grp_DayAndCostDraft>().Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId && x.Type == feeType).Sum(x => x.SubTotal);
  20012. return Ok(JsonView(new { parentId = parentId, itemTotal = itemTotal }));
  20013. }
  20014. /// <summary>
  20015. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 其他费用-批量 Step7
  20016. /// </summary>
  20017. /// <returns></returns>
  20018. [HttpPost]
  20019. [ApiExplorerSettings(IgnoreApi = true)]
  20020. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20021. public async Task<IActionResult> EnterExitCostDraftMobileOpBatchStep7(PostEnterExitCostDraftMobileOpStep7Dto dto)
  20022. {
  20023. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  20024. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  20025. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20026. var infos1 = _mapper.Map<List<Grp_DayOtherPriceDraft>>(dto.Infos);
  20027. var infos = infos1.Select(x => new Grp_DayOtherPriceDraft()
  20028. {
  20029. Id = x.Id,
  20030. ParentId = dto.DraftId,
  20031. SetDataId = x.SetDataId,
  20032. Index = x.Index,
  20033. Cost = x.Cost,
  20034. Currency = x.Currency,
  20035. SubTotal = x.SubTotal,
  20036. CreateUserId = dto.CurrUserId,
  20037. Remark = x.Remark
  20038. }).ToList();
  20039. var adds = infos.Where(x => x.Id <= 0).ToList();
  20040. var upds = infos.Where(x => x.Id > 0).ToList();
  20041. if (adds.Count > 0)
  20042. {
  20043. var add = await _sqlSugar.Insertable(adds).ExecuteCommandAsync();
  20044. if (add < 1) return Ok(JsonView(false));
  20045. }
  20046. if (upds.Count > 0)
  20047. {
  20048. var upd = await _sqlSugar.Updateable(adds)
  20049. .UpdateColumns(x => new
  20050. {
  20051. x.Index,
  20052. x.SetDataId,
  20053. x.Cost,
  20054. x.Currency,
  20055. x.SubTotal,
  20056. x.Remark
  20057. })
  20058. .WhereColumns(x => new { x.Id })
  20059. .ExecuteCommandAsync();
  20060. if (upd < 1) return Ok(JsonView(false));
  20061. }
  20062. var itemTotal = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>().Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId).Sum(x => x.SubTotal);
  20063. //消息通知
  20064. //var id = _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.IsDel == 0 && x.Id == dto.DraftId).First()?.Id ?? 0;
  20065. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  20066. return Ok(JsonView(new { itemTotal = itemTotal }));
  20067. }
  20068. /// <summary>
  20069. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 其他费用-单条 Step7
  20070. /// </summary>
  20071. /// <returns></returns>
  20072. [HttpPost]
  20073. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20074. public async Task<IActionResult> EnterExitCostDraftMobileOpSingleStep7(PostEnterExitCostDraftMobileOpSingleStep7Dto dto)
  20075. {
  20076. int subId = dto.SubId, id = dto.DraftId;
  20077. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  20078. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  20079. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20080. var subInfo = _mapper.Map<Grp_DayOtherPriceDraft>(dto);
  20081. subInfo.Id = subId;
  20082. subInfo.ParentId = id;
  20083. subInfo.CreateUserId = dto.CurrUserId;
  20084. int parentId = await EnterExitCostDraftVerifyIsNull(id, dto.CurrUserId); //主表验证
  20085. if (parentId < 1) return Ok(JsonView(false));
  20086. #region 子表op
  20087. if (subId < 1)//add
  20088. {
  20089. var subAdd = await _sqlSugar.Insertable(subInfo).ExecuteCommandAsync();
  20090. if (subAdd < 1) return Ok(JsonView(false));
  20091. }
  20092. else //upd
  20093. {
  20094. var subUpd = await _sqlSugar.Updateable(subInfo)
  20095. .UpdateColumns(x => new
  20096. {
  20097. x.Index,
  20098. x.SetDataId,
  20099. x.Cost,
  20100. x.Currency,
  20101. x.SubTotal,
  20102. x.Remark
  20103. })
  20104. .WhereColumns(x => new { x.Id })
  20105. .ExecuteCommandAsync();
  20106. if (subUpd < 1) return Ok(JsonView(false));
  20107. }
  20108. #endregion
  20109. var itemTotal = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>().Where(x => x.IsDel == 0 && x.ParentId == id).Sum(x => x.SubTotal);
  20110. ////消息通知
  20111. //await EnterExitCostMobileOpNotice(dto.Diid, parentId, dto.CurrUserId);
  20112. return Ok(JsonView(new { parentId = parentId, itemTotal = itemTotal }));
  20113. }
  20114. /// <summary>
  20115. /// 团组模块 - 出入境费用-草稿-移动端 - 3-6子项删除
  20116. /// </summary>
  20117. /// <returns></returns>
  20118. [HttpPost]
  20119. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20120. public async Task<IActionResult> EnterExitCostDraftMobileSubItemDel(EnterExitCostDraftSubItemDelDto dto)
  20121. {
  20122. var data = await _enterExitCostDraftRep.EnterExitCostDraftSubItemDel(dto);
  20123. if (data.Code != 0)
  20124. {
  20125. return Ok(JsonView(false, data.Msg));
  20126. }
  20127. return Ok(JsonView(true, "操作成功!", data.Data));
  20128. }
  20129. /// <summary>
  20130. /// 团组模块 - 出入境费用-草稿-移动端 - 其他费用删除
  20131. /// </summary>
  20132. /// <param name="dto"></param>
  20133. /// <returns></returns>
  20134. [HttpPost]
  20135. public IActionResult EnterExitCostDraftMobileOtherFeeDel(EnterExitCostDraftSubItemDelDto dto)
  20136. {
  20137. var data = new Grp_DayOtherPriceDraft()
  20138. {
  20139. Id = dto.Id,
  20140. IsDel = 1,
  20141. DeleteUserId = dto.DeleteUserId,
  20142. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  20143. };
  20144. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  20145. if (del > 0) return Ok(JsonView(true, "删除成功!"));
  20146. return Ok(JsonView(false, "删除失败!"));
  20147. }
  20148. #endregion
  20149. #endregion
  20150. #region 团组经理模块 出入境费用报价表
  20151. /// <summary>
  20152. /// 团组模块 - 出入境费用报价表 - 初始化数据源(币种类型)
  20153. /// </summary>
  20154. /// <returns></returns>
  20155. [HttpPost]
  20156. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20157. public async Task<IActionResult> EnterExitCostQuoteInitData(PortDtoBase dto)
  20158. {
  20159. var initRates = await GeneralMethod.EnterExitCostInitRate();
  20160. var liveRates = await GeneralMethod.EnterExitCostLiveRate();
  20161. var cnyInfo = new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.0000M };
  20162. initRates.Insert(0, cnyInfo);
  20163. liveRates.Insert(0, cnyInfo);
  20164. return Ok(JsonView(true, "查询成功!", new
  20165. {
  20166. InitRates = initRates,
  20167. LiveRates = liveRates
  20168. }));
  20169. }
  20170. /// <summary>
  20171. /// 团组模块 - 出入境费用报价表 - 报价表名称列表
  20172. /// </summary>
  20173. /// <returns></returns>
  20174. [HttpPost]
  20175. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20176. public async Task<IActionResult> EnterExitCostQuoteNameList(EnterExitCostQuoteNameListDto dto)
  20177. {
  20178. return Ok(await _enterExitCostQuoteRep.QuoteNameListAsync(dto));
  20179. }
  20180. /// <summary>
  20181. /// 团组模块 - 出入境费用报价表 - 团组名称列表
  20182. /// </summary>
  20183. /// <returns></returns>
  20184. [HttpPost]
  20185. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20186. public async Task<IActionResult> EnterExitCostQuoteGroupNameList(EnterExitCostQuoteGroupNameListDto dto)
  20187. {
  20188. return Ok(await _enterExitCostQuoteRep.GroupNameListAsync(dto));
  20189. }
  20190. /// <summary>
  20191. /// 团组模块 - 出入境费用报价表 - 根据团组Id获出入境费用相关信息
  20192. /// </summary>
  20193. /// <returns></returns>
  20194. [HttpPost]
  20195. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20196. public async Task<IActionResult> EnterExitCostQuoteEntryExitCosts(EnterExitCostInfobyDiIdDto dto)
  20197. {
  20198. int groupId = dto.DiId,
  20199. currUserId = dto.CurrUserId;
  20200. if (groupId < 1) return Ok(JsonView(false, "请传入有效的GroupId;"));
  20201. if (currUserId < 1) return Ok(JsonView(false, "请传入有效的CurrUserId;"));
  20202. //验证报价数据是否存在
  20203. var isNull = await _sqlSugar.Queryable<Grp_EnterExitCostQuote>().FirstAsync(x => x.IsDel == 0 && x.GroupId == dto.DiId);
  20204. if (isNull != null)
  20205. {
  20206. var info1 = await _enterExitCostQuoteRep.InfoAsync(new EnterExitCostQuoteInfoDto() { Id = isNull.Id });
  20207. if (!info1.Rates.Any())
  20208. {
  20209. var rates = await GeneralMethod.EnterExitCostInitRate();
  20210. rates.Insert(0, new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
  20211. info1.Rates = rates.ToArray();
  20212. }
  20213. return Ok(JsonView(info1));
  20214. }
  20215. var result = await _enterExitCostQuoteRep.InfoByGroupIdAsync(dto.DiId);
  20216. result.GroupId = groupId;
  20217. //处理报价名称
  20218. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.DiId && x.IsDel == 0);
  20219. if (groupInfo != null)
  20220. {
  20221. var visitCountry = groupInfo.VisitCountry;
  20222. if (!string.IsNullOrEmpty(visitCountry))
  20223. {
  20224. string quoteName = string.Empty;
  20225. if (visitCountry.Contains("|"))
  20226. {
  20227. var countrys = visitCountry.Split("|");
  20228. quoteName = string.Join("、", countrys);
  20229. }
  20230. else quoteName = visitCountry;
  20231. quoteName += $"团组报价表";
  20232. result.Name = quoteName;
  20233. }
  20234. }
  20235. var info = await _enterExitCostRep.GetEnterExitCostInfoByDiId(dto);
  20236. if (info.Code != StatusCodes.Status200OK)
  20237. {
  20238. if (!result.Rates.Any())
  20239. {
  20240. var rates = await GeneralMethod.EnterExitCostInitRate();
  20241. result.Rates = rates.ToArray();
  20242. }
  20243. return Ok(JsonView(true, $"出入境费用明细未填写!", result));
  20244. }
  20245. var infoView = info.Data as EnterExitCostInfoView;
  20246. if (infoView == null) return Ok(JsonView(false, "数据类型转换失败!;"));
  20247. var countryFees = await _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x => x.IsDel == 0).ToListAsync();
  20248. var cityFilter = new List<string>() { "全部城市", "其他城市" };
  20249. var currencys = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToListAsync();
  20250. var eecRates = infoView.Currencys;
  20251. //默认添加人名币
  20252. if (!eecRates.Any(x => x.CurrencyCode.Equals("CNY")))
  20253. {
  20254. eecRates.Insert(0, new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
  20255. }
  20256. //处理团组人数
  20257. int pplNum = 1;
  20258. if (groupInfo != null) pplNum = groupInfo.VisitPNumber;
  20259. var views = new List<QuoteSubItemInfo>();
  20260. #region 数据填充
  20261. var intTravelCosts = new List<QuoteSubItemInfo>();
  20262. #region 机票费用 1354
  20263. int intTravelIndex = 1;
  20264. if (infoView.SumJJC == 1)
  20265. {
  20266. intTravelCosts.Add(new QuoteSubItemInfo
  20267. {
  20268. ItemId = 1354,
  20269. Index = intTravelIndex,
  20270. FeeName = "经济舱",
  20271. UnitPrice = infoView.AirJJ,
  20272. Currency = "CNY",
  20273. Quantity = 1,
  20274. PplNum = 1,
  20275. TotalAmt = infoView.AirJJ,
  20276. Remark = "",
  20277. });
  20278. intTravelIndex++;
  20279. }
  20280. if (infoView.SumGWC == 1)
  20281. {
  20282. intTravelCosts.Add(new QuoteSubItemInfo
  20283. {
  20284. ItemId = 1354,
  20285. Index = intTravelIndex,
  20286. FeeName = "公务舱",
  20287. UnitPrice = infoView.AirGW,
  20288. Currency = "CNY",
  20289. Quantity = 1,
  20290. PplNum = 1,
  20291. TotalAmt = infoView.AirGW,
  20292. Remark = "",
  20293. });
  20294. intTravelIndex++;
  20295. }
  20296. if (infoView.SumTDC == 1)
  20297. {
  20298. intTravelCosts.Add(new QuoteSubItemInfo
  20299. {
  20300. ItemId = 1354,
  20301. Index = intTravelIndex,
  20302. FeeName = "头等舱",
  20303. UnitPrice = infoView.AirTD,
  20304. Currency = "CNY",
  20305. Quantity = 1,
  20306. PplNum = 1,
  20307. TotalAmt = infoView.AirTD,
  20308. Remark = "",
  20309. });
  20310. intTravelIndex++;
  20311. }
  20312. intTravelCosts.Add(new QuoteSubItemInfo
  20313. {
  20314. ItemId = 1354,
  20315. Index = intTravelIndex,
  20316. FeeName = "城市间交通费用(经济舱)",
  20317. UnitPrice = infoView.CityTranffic,
  20318. Currency = "CNY",
  20319. Quantity = 1,
  20320. PplNum = pplNum,
  20321. TotalAmt = infoView.CityTranffic * pplNum,
  20322. Remark = "",
  20323. });
  20324. intTravelCosts.Add(new QuoteSubItemInfo
  20325. {
  20326. ItemId = 1354,
  20327. Index = intTravelIndex,
  20328. FeeName = "城市间交通费用(公务舱)",
  20329. UnitPrice = infoView.CityTranffic1,
  20330. Currency = "CNY",
  20331. Quantity = 1,
  20332. PplNum = pplNum,
  20333. TotalAmt = infoView.CityTranffic1 * pplNum,
  20334. Remark = "",
  20335. });
  20336. intTravelCosts.Add(new QuoteSubItemInfo
  20337. {
  20338. ItemId = 1354,
  20339. Index = intTravelIndex,
  20340. FeeName = "城市间交通费用(头等舱)",
  20341. UnitPrice = infoView.CityTranffic2,
  20342. Currency = "CNY",
  20343. Quantity = 1,
  20344. PplNum = pplNum,
  20345. TotalAmt = infoView.CityTranffic2 * pplNum,
  20346. Remark = "",
  20347. });
  20348. views.AddRange(intTravelCosts);
  20349. #endregion
  20350. var accomCosts = new List<QuoteSubItemInfo>();
  20351. #region 住宿费 1355
  20352. if (infoView.QuarterageData.Any())
  20353. {
  20354. int accomIndex = 1;
  20355. int accomItemTypeId = 1355;
  20356. var groupData = infoView.QuarterageData.GroupBy(x => x.NationalTravelFeeId);
  20357. foreach (var item in groupData)
  20358. {
  20359. string feeName = string.Empty;
  20360. var countryInfo = countryFees.FirstOrDefault(x => x.Id == item.Key);
  20361. if (countryInfo != null)
  20362. {
  20363. feeName = countryInfo.Country;
  20364. var city = countryInfo.City;
  20365. if (!string.IsNullOrEmpty(city) && cityFilter.Any(x => !x.Contains(city)))
  20366. {
  20367. feeName += $"-{city}";
  20368. }
  20369. }
  20370. var hotelInfo = item.FirstOrDefault();
  20371. if (hotelInfo == null) continue;
  20372. var thisCurrency = currencys.FirstOrDefault(x => x.Id == hotelInfo.Currency)?.Name ?? "nuknow";
  20373. var thisRate = eecRates.FirstOrDefault(x => x.CurrencyCode.Equals(thisCurrency))?.Rate ?? 1.0000M;
  20374. int quantity = item.ToList().Count;
  20375. accomCosts.Add(new QuoteSubItemInfo
  20376. {
  20377. ItemId = accomItemTypeId,
  20378. Index = accomIndex,
  20379. FeeName = feeName,
  20380. UnitPrice = hotelInfo.Cost,
  20381. Currency = thisCurrency,
  20382. Quantity = quantity,
  20383. PplNum = pplNum,
  20384. TotalAmt = hotelInfo.Cost * thisRate * quantity * pplNum,
  20385. Remark = "",
  20386. });
  20387. accomIndex++;
  20388. }
  20389. views.AddRange(accomCosts);
  20390. }
  20391. #endregion
  20392. var mealCosts = new List<QuoteSubItemInfo>();
  20393. #region 餐饮费 1356
  20394. if (infoView.BoardWagesData.Any())
  20395. {
  20396. var mealIndex = 1;
  20397. int mealItemTypeId = 1356;
  20398. var groupData = infoView.BoardWagesData.GroupBy(x => x.NationalTravelFeeId);
  20399. foreach (var item in groupData)
  20400. {
  20401. string feeName = string.Empty;
  20402. var countryInfo = countryFees.FirstOrDefault(x => x.Id == item.Key);
  20403. if (countryInfo != null)
  20404. {
  20405. feeName = countryInfo.Country;
  20406. var city = countryInfo.City;
  20407. if (!string.IsNullOrEmpty(city) && cityFilter.Any(x => !x.Contains(city)))
  20408. {
  20409. feeName += $"-{city}";
  20410. }
  20411. }
  20412. var mealInfo = item.FirstOrDefault();
  20413. if (mealInfo == null) continue;
  20414. var thisCurrency = currencys.FirstOrDefault(x => x.Id == mealInfo.Currency)?.Name ?? "nuknow";
  20415. var thisRate = eecRates.FirstOrDefault(x => x.CurrencyCode.Equals(thisCurrency))?.Rate ?? 1.0000M;
  20416. int quantity = item.ToList().Count;
  20417. mealCosts.Add(new QuoteSubItemInfo
  20418. {
  20419. ItemId = mealItemTypeId,
  20420. Index = mealIndex,
  20421. FeeName = feeName,
  20422. UnitPrice = mealInfo.Cost,
  20423. Currency = thisCurrency,
  20424. Quantity = quantity,
  20425. PplNum = pplNum,
  20426. TotalAmt = mealInfo.Cost * thisRate * quantity * pplNum,
  20427. Remark = "",
  20428. });
  20429. mealIndex++;
  20430. }
  20431. views.AddRange(mealCosts);
  20432. }
  20433. #endregion
  20434. var miscCosts = new List<QuoteSubItemInfo>();
  20435. #region 公杂费 1364
  20436. if (infoView.MiscellaneousFeeData.Any())
  20437. {
  20438. var miscIndex = 1;
  20439. int miscItemTypeId = 1364;
  20440. var groupData = infoView.MiscellaneousFeeData.GroupBy(x => x.NationalTravelFeeId);
  20441. foreach (var item in groupData)
  20442. {
  20443. string feeName = string.Empty;
  20444. var countryInfo = countryFees.FirstOrDefault(x => x.Id == item.Key);
  20445. if (countryInfo != null)
  20446. {
  20447. feeName = countryInfo.Country;
  20448. var city = countryInfo.City;
  20449. if (!string.IsNullOrEmpty(city) && cityFilter.Any(x => !x.Contains(city)))
  20450. {
  20451. feeName += $"-{city}";
  20452. }
  20453. }
  20454. var miscInfo = item.FirstOrDefault();
  20455. if (miscInfo == null) continue;
  20456. var thisCurrency = currencys.FirstOrDefault(x => x.Id == miscInfo.Currency)?.Name ?? "nuknow";
  20457. var thisRate = eecRates.FirstOrDefault(x => x.CurrencyCode.Equals(thisCurrency))?.Rate ?? 1.0000M;
  20458. int quantity = item.ToList().Count;
  20459. miscCosts.Add(new QuoteSubItemInfo
  20460. {
  20461. ItemId = miscItemTypeId,
  20462. Index = miscIndex,
  20463. FeeName = feeName,
  20464. UnitPrice = miscInfo.Cost,
  20465. Currency = thisCurrency,
  20466. Quantity = quantity,
  20467. PplNum = pplNum,
  20468. TotalAmt = miscInfo.Cost * thisRate * quantity * pplNum,
  20469. Remark = "",
  20470. });
  20471. miscIndex++;
  20472. }
  20473. views.AddRange(miscCosts);
  20474. }
  20475. #endregion
  20476. #region 签证+保险 1362
  20477. int visaInsIndex = 1;
  20478. int visaInsItemTypeId = 1362;
  20479. if (infoView.Visa > 0)
  20480. {
  20481. views.Add(new QuoteSubItemInfo()
  20482. {
  20483. ItemId = visaInsItemTypeId,
  20484. Index = visaInsIndex,
  20485. FeeName = $"签证",
  20486. UnitPrice = infoView.Visa,
  20487. Currency = $"CNY",
  20488. Quantity = 1,
  20489. PplNum = pplNum,
  20490. TotalAmt = infoView.Visa * pplNum,
  20491. Remark = "",
  20492. });
  20493. visaInsIndex++;
  20494. }
  20495. if (infoView.Safe > 0)
  20496. {
  20497. views.Add(new QuoteSubItemInfo()
  20498. {
  20499. ItemId = visaInsItemTypeId,
  20500. Index = visaInsIndex,
  20501. FeeName = $"保险",
  20502. UnitPrice = infoView.Safe,
  20503. Currency = $"CNY",
  20504. Quantity = 1,
  20505. PplNum = pplNum,
  20506. TotalAmt = infoView.Safe * pplNum,
  20507. Remark = "",
  20508. });
  20509. }
  20510. #endregion
  20511. #region 服务费 1363
  20512. int serviceFeeIndex = 1;
  20513. int serviceFeeItemTypeId = 1363;
  20514. if (infoView.Service > 0)
  20515. {
  20516. views.Add(new QuoteSubItemInfo()
  20517. {
  20518. ItemId = serviceFeeItemTypeId,
  20519. Index = serviceFeeIndex,
  20520. FeeName = $"服务费",
  20521. UnitPrice = infoView.Service,
  20522. Currency = $"CNY",
  20523. Quantity = 1,
  20524. PplNum = pplNum,
  20525. TotalAmt = infoView.Service * pplNum,
  20526. Remark = "",
  20527. });
  20528. }
  20529. #endregion
  20530. #endregion
  20531. if (result.FeeItems.Any())
  20532. {
  20533. result.FeeItems.Select(x =>
  20534. {
  20535. var feeInfos = views.Where(y => y.ItemId == x.ItemId).OrderBy(y => y.Index).ToArray();
  20536. if (feeInfos.Any()) x.Infos = feeInfos;
  20537. return x;
  20538. }
  20539. ).OrderBy(x => x.Index)
  20540. .ToList();
  20541. if (!result.Rates.Any())
  20542. {
  20543. if (eecRates.Any()) result.Rates = eecRates?.ToArray() ?? Array.Empty<CurrencyInfo>();
  20544. else
  20545. {
  20546. var rates = await GeneralMethod.EnterExitCostInitRate();
  20547. rates.Insert(0, new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
  20548. result.Rates = rates.ToArray();
  20549. }
  20550. }
  20551. }
  20552. return Ok(JsonView(result));
  20553. }
  20554. /// <summary>
  20555. /// 团组模块 - 出入境费用报价表 - Info
  20556. /// </summary>
  20557. /// <returns></returns>
  20558. [HttpPost]
  20559. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20560. public async Task<IActionResult> EnterExitCostQuoteInfo(EnterExitCostQuoteInfoDto dto)
  20561. {
  20562. var info = await _enterExitCostQuoteRep.InfoAsync(dto);
  20563. if (!info.Rates.Any())
  20564. {
  20565. var rates = await GeneralMethod.EnterExitCostInitRate();
  20566. rates.Add(new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
  20567. info.Rates = rates.ToArray();
  20568. }
  20569. return Ok(JsonView(info));
  20570. }
  20571. /// <summary>
  20572. /// 团组模块 - 出入境费用报价表 - OP
  20573. /// </summary>
  20574. /// <returns></returns>
  20575. [HttpPost]
  20576. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20577. public async Task<IActionResult> EnterExitCostQuoteOp(EnterExitCostQuoteOpDto dto)
  20578. {
  20579. return Ok(await _enterExitCostQuoteRep.OpAsync(dto));
  20580. }
  20581. /// <summary>
  20582. /// 团组模块 - 出入境费用报价表 - 删除 项
  20583. /// </summary>
  20584. /// <returns></returns>
  20585. [HttpPost]
  20586. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20587. public async Task<IActionResult> EnterExitCostQuoteItemDel(EnterExitCostQuoteItemDelDto dto)
  20588. {
  20589. if (dto.Id < 1) return Ok(JsonView(false, MsgTips.Id));
  20590. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20591. return Ok(await _enterExitCostQuoteRep.ItemDelAsync(dto));
  20592. }
  20593. /// <summary>
  20594. /// 团组模块 - 出入境费用报价表 - 导出
  20595. /// </summary>
  20596. /// <returns></returns>
  20597. [HttpPost]
  20598. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20599. public async Task<IActionResult> EnterExitCostQuoteExcelExport(EnterExitCostQuoteExcelExportDto dto)
  20600. {
  20601. if (dto.Id < 1) return Ok(JsonView(false, MsgTips.Id));
  20602. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20603. var info = await _enterExitCostQuoteRep.InfoAsync(new EnterExitCostQuoteInfoDto() { Id = dto.Id });
  20604. if (info == null) return Ok(JsonView(false, "报价信息未填写!"));
  20605. var rates = info.Rates;
  20606. var intTravelCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1354);//国际旅费
  20607. var accomCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1355); //住宿费
  20608. var mealCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1356); //餐饮费
  20609. var vehArranges = info.FeeItems.FirstOrDefault(x => x.ItemId == 1357); //车辆安排
  20610. var inviteTo = info.FeeItems.FirstOrDefault(x => x.ItemId == 1358); //邀请函发放对象
  20611. var inviteCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1359); //邀请函费用
  20612. var inviteTime = info.FeeItems.FirstOrDefault(x => x.ItemId == 1360); //邀请函发放时间
  20613. var officialActs = info.FeeItems.FirstOrDefault(x => x.ItemId == 1361); //公务活动
  20614. var visaIns = info.FeeItems.FirstOrDefault(x => x.ItemId == 1362); //签证+保险
  20615. var serviceCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1363); //服务费
  20616. var pubMiscs = info.FeeItems.FirstOrDefault(x => x.ItemId == 1364); //公杂费
  20617. var taxCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1365); //税费
  20618. //获取模板
  20619. string tempPath = AppSettingsHelper.Get("ExcelBasePath") + "Template/出入境费用明细报价表模板.xlsx";
  20620. var designer = new WorkbookDesigner();
  20621. designer.Workbook = new Workbook(tempPath);
  20622. designer.SetDataSource("QuoteName", info.Name);
  20623. designer.SetDataSource("CompanyTitle", "公司名称");
  20624. designer.SetDataSource("CompanyLabel", "");
  20625. #region 国际旅费
  20626. designer.SetDataSource("IntTravelTitle", intTravelCosts?.ItemWrapName ?? "国际旅费\r\n(公务舱和经济舱分别罗列)");
  20627. if (intTravelCosts != null && intTravelCosts.Infos.Any())
  20628. {
  20629. var cabClassFilter = new string[] { "经济舱", "公务舱", "头等舱" };
  20630. var label = new StringBuilder();
  20631. var infos = intTravelCosts.Infos.Where(x => cabClassFilter.Contains(x.FeeName)).ToArray();
  20632. if (infos.Any())
  20633. {
  20634. label.Append(infos.Sum(x => x.PplNum));
  20635. label.Append("人全程机票:");
  20636. label.Append(infos.Sum(x => x.TotalAmt).TruncDecimals(2));
  20637. label.AppendLine("元");
  20638. }
  20639. foreach (var item in intTravelCosts.Infos)
  20640. {
  20641. label.Append(item.FeeName);
  20642. label.Append(":");
  20643. label.Append(item.UnitPrice.TruncDecimals(2));
  20644. label.Append("元/人*");
  20645. label.Append(item.PplNum);
  20646. label.AppendLine("人");
  20647. }
  20648. if (label.HasValue())
  20649. {
  20650. label.Append("\r\n以上小计:");
  20651. label.Append(intTravelCosts.TotalAmt.TruncDecimals(2));
  20652. label.Append("元");
  20653. }
  20654. designer.SetDataSource("IntTravelLabel", label.ToString());
  20655. }
  20656. #endregion
  20657. #region 住宿费
  20658. designer.SetDataSource("AccomTitle", accomCosts?.ItemWrapName ?? "住宿费\r\n(请备注明酒店星级)");
  20659. if (accomCosts != null && accomCosts.Infos.Any())
  20660. {
  20661. string currencyName = string.Empty,
  20662. countryName = string.Empty;
  20663. decimal rate = 1.0000M;
  20664. var label = new StringBuilder();
  20665. label.AppendLine("全程五星酒店,每人1间房");
  20666. foreach (var item in accomCosts.Infos)
  20667. {
  20668. //乌兹别克斯坦: 塔什干:120美金/间/晚*2*6人
  20669. string name = string.Empty, thisCountryName = string.Empty;
  20670. if (item.FeeName.Contains('-'))
  20671. {
  20672. var feeName = item.FeeName.Split('-');
  20673. thisCountryName = feeName[0];
  20674. if (!thisCountryName.Equals(countryName)) countryName = feeName[0];
  20675. name = feeName[1];
  20676. }
  20677. else name = item.FeeName;
  20678. string thisFeeName = string.Empty;
  20679. if (!thisCountryName.Equals(countryName)) thisFeeName = $"{countryName}:\r\n{name}:";
  20680. else thisFeeName = $"\r\n{name}:";
  20681. var rateInfo = rates.FirstOrDefault(x => item.Currency.Equals(x.CurrencyCode));
  20682. currencyName = rateInfo?.CurrencyName ?? "UnKnow";
  20683. rate = rateInfo?.Rate ?? 1.0000M;
  20684. string subLabel = string.Format("{0}{1}{2}/间/晚*{3}*{4}人", thisFeeName, item.UnitPrice.TruncDecimals(2), currencyName, item.Quantity.ToString("#0"), item.PplNum.ToString("#0"));
  20685. label.AppendLine(subLabel);
  20686. }
  20687. if (label.HasValue())
  20688. {
  20689. //以上小计:52440元(美金汇率:7.5 )
  20690. string subLabel = string.Format("\r\n以上小计:{0}元({1}汇率:{2})", accomCosts.TotalAmt.TruncDecimals(2), currencyName, rate.TruncDecimals(4));
  20691. label.AppendLine(subLabel);
  20692. }
  20693. designer.SetDataSource("AccomLabel", label.ToString());
  20694. }
  20695. #endregion
  20696. #region 餐饮费
  20697. designer.SetDataSource("MealTitle", mealCosts?.ItemWrapName ?? "餐饮费");
  20698. if (mealCosts != null && mealCosts.Infos.Any())
  20699. {
  20700. string currencyName = string.Empty;
  20701. decimal rate = 1.0000M;
  20702. var label = new StringBuilder();
  20703. label.Append("全程酒店含早,\r\n若因航班过早,\r\n酒店准备路早。\r\n\r\n");
  20704. foreach (var item in mealCosts.Infos)
  20705. {
  20706. string name = string.Empty;
  20707. if (item.FeeName.Contains('-'))
  20708. {
  20709. var feeName = item.FeeName.Split('-');
  20710. name = $"\r\n{feeName[0]}:\r\n{feeName[1]}:";
  20711. }
  20712. else name = $"\r\n{item.FeeName}:";
  20713. var rateInfo = rates.FirstOrDefault(x => item.Currency.Equals(x.CurrencyCode));
  20714. currencyName = rateInfo?.CurrencyName ?? "UnKnow";
  20715. rate = rateInfo?.Rate ?? 1.0000M;
  20716. label.Append(name);
  20717. label.Append(item.UnitPrice.TruncDecimals(2));
  20718. label.Append(currencyName);
  20719. label.Append("/天*");
  20720. label.Append(item.Quantity.ToString("#0"));
  20721. label.Append('*');
  20722. label.Append(item.PplNum);
  20723. label.Append("人\r\n");
  20724. }
  20725. if (label.HasValue())
  20726. {
  20727. label.Append("\r\n以上小计:");
  20728. label.Append(accomCosts.TotalAmt.TruncDecimals(2));
  20729. label.Append("元\r\n(");
  20730. label.Append("汇率:");
  20731. label.Append(rate.TruncDecimals(4));
  20732. label.Append(')');
  20733. }
  20734. designer.SetDataSource("MealLabel", label.ToString());
  20735. }
  20736. #endregion
  20737. #region 车辆安排
  20738. designer.SetDataSource("VehArrangeTitle", vehArranges?.ItemWrapName ?? "车辆安排\r\n(司兼导分开的情况下,车辆品牌、座位及费用)");
  20739. if (vehArranges != null && vehArranges.Infos.Any())
  20740. {
  20741. string currencyName = string.Empty;
  20742. //decimal rate = 1.0000M;
  20743. var label = new StringBuilder();
  20744. foreach (var item in vehArranges.Infos)
  20745. {
  20746. label.AppendLine();
  20747. label.AppendLine();
  20748. label.Append(item.FeeName);
  20749. label.Append($"\r\n\r\n费用:{item.TotalAmt.TruncDecimals(2)}元");
  20750. }
  20751. designer.SetDataSource("VehArrangeLabel", label.ToString());
  20752. }
  20753. #endregion
  20754. #region 邀请函发放对象
  20755. designer.SetDataSource("InviteToTitle", inviteTo?.ItemWrapName ?? "邀请函发放对象");
  20756. designer.SetDataSource("InviteToContent", "");
  20757. #endregion
  20758. #region 邀请函费
  20759. designer.SetDataSource("InviteCostTitle", inviteCosts?.ItemWrapName ?? "邀请函费用");
  20760. var is_label = new StringBuilder();
  20761. if (inviteCosts != null && inviteCosts.Infos.Any())
  20762. {
  20763. string currencyName = string.Empty;
  20764. decimal rate = 1.0000M;
  20765. foreach (var item in inviteCosts.Infos)
  20766. {
  20767. //乌兹别克斯坦:2000美金
  20768. currencyName = item.Currency;
  20769. rate = rates.FirstOrDefault(x => currencyName.Equals(x.CurrencyCode))?.Rate ?? 1.0000M;
  20770. string label = string.Format("{0}:{1}{2}", item.FeeName, item.UnitPrice.TruncDecimals(2), currencyName);
  20771. is_label.AppendLine(label);
  20772. }
  20773. if (is_label.HasValue())
  20774. {
  20775. //以上小计:28500元(美金汇率:7.5)
  20776. string label = string.Format("以上小计:{0}{1}({2}汇率:{3})", inviteCosts.TotalAmt.TruncDecimals(2), "元", currencyName, rate.TruncDecimals(4));
  20777. is_label.AppendLine(label);
  20778. }
  20779. }
  20780. designer.SetDataSource("InviteCostContent", is_label.ToString());
  20781. #endregion
  20782. #region 邀请函发放时间
  20783. designer.SetDataSource("InviteToTimeTitle", inviteTime?.ItemWrapName ?? "邀请函发放时间");
  20784. designer.SetDataSource("InviteToTimeContent", "拿到团员名单10-15工作日");
  20785. #endregion
  20786. #region 公务活动(含翻译)
  20787. designer.SetDataSource("OfficialActsTitle", officialActs?.ItemWrapName ?? "公务活动(含翻译)");
  20788. var oa_label = new StringBuilder();
  20789. if (officialActs != null && officialActs.Infos.Any())
  20790. {
  20791. string currencyName = string.Empty;
  20792. decimal rate = 1.0000M;
  20793. string label_title = string.Empty, label_content = "超出报价部分需额付费:\r\n";
  20794. foreach (var item in officialActs.Infos)
  20795. {
  20796. //乌兹别克斯坦:1000美金/场
  20797. currencyName = item.Currency;
  20798. rate = rates.FirstOrDefault(x => currencyName.Equals(x.CurrencyCode))?.Rate ?? 1.0000M;
  20799. string label_remark = string.Empty;
  20800. if (!string.IsNullOrEmpty(item.Remark)) label_remark = $"({item.Remark})";
  20801. label_content += string.Format("{0}:{1}{2}/场{3}\r\n", item.FeeName, item.UnitPrice.TruncDecimals(2), currencyName, label_remark);
  20802. }
  20803. label_content += "*总费用中未含超出公务活动价格";
  20804. //8场公务活动(以上小计:60000元)
  20805. var quantity = officialActs.Infos.Sum(x => x.Quantity);
  20806. label_title = string.Format("{0}场公务活动(以上小计:{1}元)", quantity, officialActs.TotalAmt.TruncDecimals(2));
  20807. oa_label.AppendLine(label_title);
  20808. oa_label.AppendLine(label_content);
  20809. }
  20810. designer.SetDataSource("OfficialActsContent", oa_label.ToString());
  20811. #endregion
  20812. #region 签证+保险
  20813. designer.SetDataSource("VisaInsTitle", visaIns?.ItemWrapName ?? "签证+保险\r\n(单位:元)");
  20814. var vi_label = new StringBuilder();
  20815. if (visaIns != null && visaIns.Infos.Any())
  20816. {
  20817. foreach (var item in visaIns.Infos)
  20818. {
  20819. //签证:500元/人
  20820. string label = string.Format("{0}:{1}元/人*{2}人", item.FeeName, item.UnitPrice.TruncDecimals(2), item.PplNum);
  20821. vi_label.AppendLine(label);
  20822. }
  20823. if (vi_label.HasValue())
  20824. {
  20825. //以上小计:6000元
  20826. string label = string.Format("以上小计:{0}元", visaIns.TotalAmt.TruncDecimals(2));
  20827. vi_label.AppendLine(label);
  20828. }
  20829. }
  20830. designer.SetDataSource("VisaInsContent", vi_label.ToString());
  20831. #endregion
  20832. #region 服务费
  20833. designer.SetDataSource("ServiceCostTitle", serviceCosts?.ItemWrapName ?? "服务费");
  20834. designer.SetDataSource("ServiceCostContent", serviceCosts?.TotalAmt.TruncDecimals(2) ?? 0.00M);
  20835. #endregion
  20836. #region 公杂费
  20837. designer.SetDataSource("PubMiscsTitle", pubMiscs?.ItemWrapName ?? "公杂费\r\n(发给团组成员)");
  20838. var pm_label = new StringBuilder();
  20839. if (pubMiscs != null && pubMiscs.Infos.Any())
  20840. {
  20841. string currencyName = string.Empty,
  20842. countryName = string.Empty;
  20843. decimal rate = 1.0000M;
  20844. foreach (var item in pubMiscs.Infos)
  20845. {
  20846. //乌兹别克斯坦:塔什干:32美金 / 天 * 3 * 6人
  20847. string name = string.Empty, thisCountryName = string.Empty;
  20848. if (item.FeeName.Contains('-'))
  20849. {
  20850. var feeName = item.FeeName.Split('-');
  20851. thisCountryName = feeName[0];
  20852. if (!thisCountryName.Equals(countryName)) countryName = feeName[0];
  20853. name = feeName[1];
  20854. }
  20855. else name = item.FeeName;
  20856. string thisFeeName = string.Empty;
  20857. if (!thisCountryName.Equals(countryName)) thisFeeName = $"{countryName}:\r\n{name}:";
  20858. else thisFeeName = $"\r\n{name}:";
  20859. var rateInfo = rates.FirstOrDefault(x => item.Currency.Equals(x.CurrencyCode));
  20860. currencyName = rateInfo?.CurrencyName ?? "UnKnow";
  20861. rate = rateInfo?.Rate ?? 1.0000M;
  20862. string label = string.Format("{0}:{1}{2}/天*{3}*{4}人", thisFeeName, item.UnitPrice.TruncDecimals(2), currencyName, item.Quantity, item.PplNum);
  20863. pm_label.AppendLine(label);
  20864. }
  20865. if (pm_label.HasValue())
  20866. {
  20867. //以上小计:13497.6元\r\n(美金汇率:7.5 )\r\n部分发放成员
  20868. pm_label.AppendLine(string.Format("以上小计:{0}元", pubMiscs.TotalAmt.TruncDecimals(2)));
  20869. pm_label.AppendLine(string.Format("({0}汇率:{1})", currencyName, rate.TruncDecimals(4)));
  20870. pm_label.AppendLine(string.Format("部分发放成员"));
  20871. }
  20872. }
  20873. designer.SetDataSource("PubMiscsContent", pm_label.ToString());
  20874. #endregion
  20875. #region 税费
  20876. designer.SetDataSource("TaxCostTitle", taxCosts?.ItemWrapName ?? "税费");
  20877. designer.SetDataSource("TaxCostContent", taxCosts?.TotalAmt.TruncDecimals(2) ?? 0.00M);
  20878. #endregion
  20879. #region 合计(单位:元)
  20880. designer.SetDataSource("CostTotalTitle", "合计\r\n(单位:元)");
  20881. designer.SetDataSource("CostTotalContent", info.FeeItems.Sum(x => x.TotalAmt).TruncDecimals(2));
  20882. #endregion
  20883. #region 汇率 Remark
  20884. var rate_label = new StringBuilder();
  20885. var rateGroups = rates.GroupBy(x => x.CurrencyName);
  20886. foreach (var item in rateGroups)
  20887. {
  20888. //美元汇率按\r\n1:7.5
  20889. string label = string.Format("{0}汇率按\r\n1:{1}", item.Key, item.FirstOrDefault()?.Rate.TruncDecimals(4) ?? 0.0000M);
  20890. rate_label.AppendLine(label);
  20891. }
  20892. designer.SetDataSource("RateLabel", rate_label.ToString());
  20893. #endregion
  20894. designer.Process();
  20895. //文件名
  20896. string fileName = $"{info.Name}{DateTime.Now:yyyyMMddHHmmss}.xls";
  20897. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + "EnterExitCostQuote/" + fileName);
  20898. string url = AppSettingsHelper.Get("ExcelBaseUrl") + "Office/Excel/EnterExitCostQuote/" + fileName;
  20899. return Ok(JsonView(true, "成功", url));
  20900. }
  20901. #endregion
  20902. #region 签证费用录入
  20903. /// <summary>
  20904. /// 根据diid查询签证费用列表
  20905. /// </summary>
  20906. /// <param name="dto"></param>
  20907. /// <returns></returns>
  20908. [HttpPost]
  20909. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20910. public async Task<IActionResult> QueryVisaByDiId(VisaPriceDto dto)
  20911. {
  20912. Result groupData = await _visaPriceRep.PostVisaByDiId(dto);
  20913. if (groupData.Code != 0)
  20914. {
  20915. return Ok(JsonView(false, groupData.Msg));
  20916. }
  20917. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  20918. }
  20919. /// <summary>
  20920. /// 根据签证费用Id查询单条数据及c表数据
  20921. /// </summary>
  20922. /// <param name="dto"></param>
  20923. /// <returns></returns>
  20924. [HttpPost]
  20925. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20926. public async Task<IActionResult> QueryVisaById(PostVisaByIdDto dto)
  20927. {
  20928. Result groupData = await _visaPriceRep.PostVisaById(dto);
  20929. if (groupData.Code != 0)
  20930. {
  20931. return Ok(JsonView(false, groupData.Msg));
  20932. }
  20933. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  20934. }
  20935. /// <summary>
  20936. /// 签证费用删除
  20937. /// </summary>
  20938. /// <param name="dto"></param>
  20939. /// <returns></returns>
  20940. [HttpPost]
  20941. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20942. public async Task<IActionResult> DelVisaPrice(DelBaseDto dto)
  20943. {
  20944. _sqlSugar.BeginTran();
  20945. //验证
  20946. (bool vaild, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 80);
  20947. if (!vaild)
  20948. {
  20949. _sqlSugar.RollbackTran();
  20950. return Ok(JsonView(false, msg));
  20951. }
  20952. var res = await _visaPriceRep.SoftDeleteByIdAsync<Grp_VisaInfo>(dto.Id.ToString(), dto.DeleteUserId);
  20953. if (!res)
  20954. {
  20955. _sqlSugar.RollbackTran();
  20956. return Ok(JsonView(false, "删除失败"));
  20957. }
  20958. var resSub = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  20959. .Where(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 80)
  20960. .SetColumns(a => new Grp_CreditCardPayment()
  20961. {
  20962. IsDel = 1,
  20963. DeleteUserId = dto.DeleteUserId,
  20964. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  20965. })
  20966. .ExecuteCommand();
  20967. if (resSub < 1)
  20968. {
  20969. _sqlSugar.RollbackTran();
  20970. return Ok(JsonView(false, "删除失败"));
  20971. }
  20972. _sqlSugar.CommitTran();
  20973. return Ok(JsonView(true, "删除成功!"));
  20974. }
  20975. /// <summary>
  20976. /// 签证费用录入下拉框初始化
  20977. /// </summary>
  20978. /// <returns></returns>
  20979. [HttpPost]
  20980. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20981. public async Task<IActionResult> VisaPriceAddSelect()
  20982. {
  20983. //支付方式
  20984. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  20985. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  20986. //币种
  20987. List<Sys_SetData> CurrencyList = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 66 && a.IsDel == 0).ToList();
  20988. List<SetDataInfoView> _CurrencyList = _mapper.Map<List<SetDataInfoView>>(CurrencyList);
  20989. //乘客类型
  20990. List<Sys_SetData> PassengerType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 69 && a.IsDel == 0).ToList();
  20991. List<SetDataInfoView> _PassengerType = _mapper.Map<List<SetDataInfoView>>(PassengerType);
  20992. //卡类型
  20993. List<Sys_SetData> BankCard = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  20994. List<SetDataInfoView> _BankCard = _mapper.Map<List<SetDataInfoView>>(BankCard);
  20995. //代办费类型
  20996. var agencyFeeTypeData = new List<dynamic>() {
  20997. new { id = 0 , Text = "未选择" },
  20998. new { id = 1 , Text = "小公务" },
  20999. new { id = 2 , Text = "大公务" },
  21000. };
  21001. //签证费用标准国家Data
  21002. var visaSql = string.Format(@"select
  21003. id,
  21004. case
  21005. when FeeType = 0 then Country+'(因公)'
  21006. when FeeType = 1 then Country+'(因私)'
  21007. else Country+'(未设置)'
  21008. end as 'country'
  21009. from Res_VisaFeeStandard where isdel = 0");
  21010. var visaCountryFeeData = _sqlSugar.SqlQueryable<dynamic>(visaSql).ToList();
  21011. var data = new
  21012. {
  21013. Payment = _Payment,
  21014. CurrencyList = _CurrencyList,
  21015. PassengerType = _PassengerType,
  21016. BankCard = _BankCard,
  21017. AgencyFeeType = agencyFeeTypeData,
  21018. CountryFeeData = visaCountryFeeData
  21019. };
  21020. return Ok(JsonView(true, "查询成功!", data));
  21021. }
  21022. /// <summary>
  21023. /// 签证费用录入操作(Status:1.新增,2.修改)
  21024. /// </summary>
  21025. /// <param name="dto"></param>
  21026. /// <returns></returns>
  21027. [HttpPost]
  21028. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21029. public async Task<IActionResult> OpVisaPrice(OpVisaPriceDto dto)
  21030. {
  21031. //修改验证
  21032. if (dto.Status == 2)
  21033. {
  21034. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 80);
  21035. if (!valid) return Ok(JsonView(false, msg));
  21036. }
  21037. Result groupData = await _visaPriceRep.OpVisaPrice(dto);
  21038. if (groupData.Code != 0)
  21039. {
  21040. return Ok(JsonView(false, groupData.Msg));
  21041. }
  21042. #region 应用推送
  21043. try
  21044. {
  21045. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  21046. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  21047. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  21048. //2024-10-21 新增LZ UID
  21049. var userIds = new List<int>() { 21 };
  21050. string title = $"系统通知";
  21051. string content = "";
  21052. var diId = dto.DiId;
  21053. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  21054. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  21055. if (dto.Status == 1) content = $"[新增-签证费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate):#0.00} CNY;";
  21056. else if (dto.Status == 2) content = $"[更新-签证费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate):#0.00} CNY;";
  21057. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  21058. var h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "80" };
  21059. await APNsTools.iOS_PushNotifications1("051", $"签证费用审核", "", content, true, "ExpenseAuditWebView", h5);
  21060. }
  21061. catch (Exception ex)
  21062. {
  21063. }
  21064. #endregion
  21065. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  21066. }
  21067. #endregion
  21068. #region 签证提成录入
  21069. /// <summary>
  21070. /// 签证提成录入
  21071. /// 基础数据
  21072. /// </summary>
  21073. /// <returns></returns>
  21074. [HttpGet]
  21075. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21076. public async Task<IActionResult> VisaCommissionInit()
  21077. {
  21078. return Ok(await _visaCommissionRep.Init());
  21079. }
  21080. /// <summary>
  21081. /// 签证提成录入
  21082. /// Item
  21083. /// </summary>
  21084. /// <param name="_dto"></param>
  21085. /// <returns></returns>
  21086. [HttpPost]
  21087. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21088. public async Task<IActionResult> VisaCommissionItem(VisaCommissionItemDto _dto)
  21089. {
  21090. var validator = new VisaCommissionItemDtoValidator();
  21091. var validatorRes = await validator.ValidateAsync(_dto);
  21092. if (!validatorRes.IsValid)
  21093. {
  21094. var sb = new StringBuilder();
  21095. foreach (var item in validatorRes.Errors)
  21096. {
  21097. sb.AppendLine(item.ErrorMessage);
  21098. }
  21099. return Ok(JsonView(false, sb.ToString()));
  21100. }
  21101. return Ok(await _visaCommissionRep.Item(_dto));
  21102. }
  21103. /// <summary>
  21104. /// 签证提成录入
  21105. /// Save
  21106. /// </summary>
  21107. /// <param name="_dto"></param>
  21108. /// <returns></returns>
  21109. [HttpPost]
  21110. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21111. public async Task<IActionResult> VisaCommissionSave(VisaCommissionSaveDto _dto)
  21112. {
  21113. //参数验证
  21114. if (_dto.Items.Length < 1) return Ok(JsonView(false, "请输入有效的请求!"));
  21115. foreach (var item in _dto.Items)
  21116. {
  21117. if (item.CurrUserId < 1) return Ok(JsonView(false, "请输入有效的CurrUserId!"));
  21118. if (item.DiId < 1) return Ok(JsonView(false, "请输入有效的DiId!"));
  21119. if (string.IsNullOrEmpty(item.Country)) return Ok(JsonView(false, "国家为空!"));
  21120. //if (item.Quantity < 1) return Ok(JsonView(false, "请输入有效的Qauntity!"));
  21121. }
  21122. return Ok(await _visaCommissionRep.Save(_dto));
  21123. }
  21124. /// <summary>
  21125. /// 签证提成录入
  21126. /// Create
  21127. /// </summary>
  21128. /// <param name="_dto"></param>
  21129. /// <returns></returns>
  21130. [HttpPost]
  21131. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21132. public async Task<IActionResult> VisaCommissionCreate(VisaCommissionCreateDto _dto)
  21133. {
  21134. var validator = new VisaCommissionCreateDtoValidator();
  21135. var validatorRes = await validator.ValidateAsync(_dto);
  21136. if (!validatorRes.IsValid)
  21137. {
  21138. var sb = new StringBuilder();
  21139. foreach (var item in validatorRes.Errors)
  21140. {
  21141. sb.AppendLine(item.ErrorMessage);
  21142. }
  21143. return Ok(JsonView(false, sb.ToString()));
  21144. }
  21145. return Ok(await _visaCommissionRep.Create(_dto));
  21146. }
  21147. /// <summary>
  21148. /// 签证提成录入
  21149. /// Put(编辑)
  21150. /// </summary>
  21151. /// <param name="id"></param>
  21152. /// <param name="_dto"></param>
  21153. /// <returns></returns>
  21154. [HttpPut]
  21155. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21156. public async Task<IActionResult> VisaCommissionEdit(int id, VisaCommissionCreateDto _dto)
  21157. {
  21158. if (id < 1) return Ok(JsonView(false, "请输入正确的id参数!"));
  21159. var validator = new VisaCommissionCreateDtoValidator();
  21160. var validatorRes = await validator.ValidateAsync(_dto);
  21161. if (!validatorRes.IsValid)
  21162. {
  21163. var sb = new StringBuilder();
  21164. foreach (var item in validatorRes.Errors)
  21165. {
  21166. sb.AppendLine(item.ErrorMessage);
  21167. }
  21168. return Ok(JsonView(false, sb.ToString()));
  21169. }
  21170. return Ok(await _visaCommissionRep.Edit(id, _dto));
  21171. }
  21172. /// <summary>
  21173. /// 签证提成录入
  21174. /// Del
  21175. /// </summary>
  21176. /// <param name="id"></param>
  21177. /// <param name="currUserId"></param>
  21178. /// <returns></returns>
  21179. [HttpPost]
  21180. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21181. public async Task<IActionResult> VisaCommissionDel(int id, int currUserId)
  21182. {
  21183. if (id < 1) return Ok(JsonView(false, "请输入正确的id参数!"));
  21184. if (currUserId < 1) return Ok(JsonView(false, "请输入正确的currUserId参数!"));
  21185. return Ok(await _visaCommissionRep.Del(id, currUserId));
  21186. }
  21187. #endregion
  21188. #region op费用录入
  21189. /// <summary>
  21190. /// 根据diid查询op费用列表
  21191. /// </summary>
  21192. /// <param name="dto"></param>
  21193. /// <returns></returns>
  21194. [HttpPost]
  21195. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21196. public async Task<IActionResult> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  21197. {
  21198. Result groupData = await _carTouristGuideGroundRep.QueryCarTouristGuideGroundByDiId(dto);
  21199. if (groupData.Code != 0)
  21200. {
  21201. return Ok(JsonView(false, groupData.Msg));
  21202. }
  21203. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  21204. }
  21205. /// <summary>
  21206. /// 根据op费用Id查询单条数据及c表数据
  21207. /// </summary>
  21208. /// <param name="dto"></param>
  21209. /// <returns></returns>
  21210. [HttpPost]
  21211. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21212. public async Task<IActionResult> QueryCarTouristGuideGroundById(CarTouristGuideGroundIdDto dto)
  21213. {
  21214. try
  21215. {
  21216. Grp_CarTouristGuideGroundReservations _groupData = await _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().FirstAsync(a => a.Id == dto.Id && a.IsDel == 0);
  21217. Grp_CreditCardPayment _creditCardPayment = await _sqlSugar.Queryable<Grp_CreditCardPayment>().FirstAsync(a => a.CId == dto.Id && a.CTable == 79 && a.IsDel == 0);
  21218. var data = new
  21219. {
  21220. CarTouristGuideGround = _groupData,
  21221. CreditCardPayment = _creditCardPayment
  21222. };
  21223. return Ok(JsonView(true, "查询成功!", data));
  21224. }
  21225. catch (Exception ex)
  21226. {
  21227. return Ok(JsonView(false, "程序错误!"));
  21228. }
  21229. }
  21230. /// <summary>
  21231. /// op费用删除
  21232. /// </summary>
  21233. /// <param name="dto"></param>
  21234. /// <returns></returns>
  21235. [HttpPost]
  21236. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21237. public async Task<IActionResult> DelCarTouristGuideGround(DelBaseDto dto)
  21238. {
  21239. try
  21240. {
  21241. _sqlSugar.BeginTran();
  21242. //验证
  21243. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 79);
  21244. if (!valid)
  21245. {
  21246. _sqlSugar.RollbackTran();
  21247. return Ok(JsonView(false, msg));
  21248. }
  21249. var res = await _carTouristGuideGroundRep.SoftDeleteByIdAsync<Grp_CarTouristGuideGroundReservations>(dto.Id.ToString(), dto.DeleteUserId);
  21250. if (!res)
  21251. {
  21252. _sqlSugar.RollbackTran();
  21253. return Ok(JsonView(false, "删除失败"));
  21254. }
  21255. var result = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.CTGGRId == dto.Id && a.IsDel == 0).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent()
  21256. {
  21257. IsDel = 1,
  21258. DeleteUserId = dto.DeleteUserId,
  21259. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  21260. }).ExecuteCommandAsync();
  21261. var resultC = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79).SetColumns(a => new Grp_CreditCardPayment()
  21262. {
  21263. IsDel = 1,
  21264. DeleteUserId = dto.DeleteUserId,
  21265. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  21266. }).ExecuteCommandAsync();
  21267. #region 删除超支相关数据
  21268. //删除导入的超支数据
  21269. var ids = _sqlSugar.Queryable<Fin_LocalGuideRelevancyOverspend>().Where(x => x.LocalGuideId == dto.Id && x.IsDel == 0).Select(x => x.OverspendId).ToList();
  21270. var count = _sqlSugar.Updateable<Fin_GroupExtraCost>().Where(x => ids.Contains(x.Id) && x.IsDel == 0).SetColumns(x => new Fin_GroupExtraCost
  21271. {
  21272. IsDel = 1,
  21273. DeleteUserId = dto.DeleteUserId,
  21274. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  21275. }).ExecuteCommand();
  21276. count = _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(x => x.CTable == 1015 && x.IsDel == 0 && ids.Contains(x.CId)).SetColumns(x => new Grp_CreditCardPayment
  21277. {
  21278. IsDel = 1,
  21279. DeleteUserId = dto.DeleteUserId,
  21280. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  21281. }).ExecuteCommand();
  21282. count = _sqlSugar.Updateable<Fin_LocalGuideRelevancyOverspend>().Where(x => x.IsDel == 0 && x.LocalGuideId == dto.Id).SetColumns(x => new Fin_LocalGuideRelevancyOverspend
  21283. {
  21284. IsDel = 1,
  21285. DeleteUserId = dto.DeleteUserId,
  21286. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  21287. }).ExecuteCommand();
  21288. #endregion
  21289. _sqlSugar.CommitTran();
  21290. return Ok(JsonView(true, "删除成功!"));
  21291. }
  21292. catch (Exception ex)
  21293. {
  21294. _sqlSugar.RollbackTran();
  21295. return Ok(JsonView(false, "程序错误!" + ex.Message));
  21296. }
  21297. }
  21298. /// <summary>
  21299. /// op费用录入操作(Status:1.新增,2.修改)
  21300. /// </summary>
  21301. /// <param name="dto"></param>
  21302. /// <returns></returns>
  21303. [HttpPost]
  21304. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21305. public async Task<IActionResult> OpCarTouristGuideGround(OpCarTouristGuideGroundDto dto)
  21306. {
  21307. Result groupData = await _carTouristGuideGroundRep.OpCarTouristGuideGround(dto);
  21308. if (groupData.Code != 0)
  21309. {
  21310. return Ok(JsonView(false, groupData.Msg));
  21311. }
  21312. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  21313. }
  21314. /// <summary>
  21315. /// 填写费用详细页面初始化绑定
  21316. /// </summary>
  21317. /// <param name="dto"></param>
  21318. /// <returns></returns>
  21319. [HttpPost]
  21320. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21321. public IActionResult CarTouristGuideGroundContentInitialize(CarTouristGuideGroundContentDto dto)
  21322. {
  21323. try
  21324. {
  21325. Result groupData = _carTouristGuideGroundRep.CarTouristGuideGroundContent(dto);
  21326. if (groupData.Code != 0)
  21327. {
  21328. return Ok(JsonView(false, groupData.Msg));
  21329. }
  21330. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  21331. }
  21332. catch (Exception ex)
  21333. {
  21334. return Ok(JsonView(false, ex.Message));
  21335. }
  21336. }
  21337. /// <summary>
  21338. /// 根据op费用Id查询详细数据
  21339. /// </summary>
  21340. /// <param name="dto"></param>
  21341. /// <returns></returns>
  21342. [HttpPost]
  21343. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21344. public IActionResult OpCarTouristGuideGroundContentById(CarTouristGuideGroundIdDto dto)
  21345. {
  21346. try
  21347. {
  21348. Result groupData = _carTouristGuideGroundRep.OpCarTouristGuideGroundContentById(dto);
  21349. if (groupData.Code != 0)
  21350. {
  21351. return Ok(JsonView(false, groupData.Msg));
  21352. }
  21353. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  21354. }
  21355. catch (Exception ex)
  21356. {
  21357. return Ok(JsonView(false, ex.Message));
  21358. }
  21359. }
  21360. /// <summary>
  21361. /// OP费用录入填写详情
  21362. /// </summary>
  21363. /// <param name="dto"></param>
  21364. /// <returns></returns>
  21365. [HttpPost]
  21366. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21367. public async Task<IActionResult> OpCarTouristGuideGroundContent(OpCarTouristGuideGroundContentDto dto)
  21368. {
  21369. try
  21370. {
  21371. #region 参数校验
  21372. if (dto.Currency <= 0) return Ok(JsonView(false, "币种错误!"));
  21373. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.DiId && x.IsDel == 0);
  21374. if (di == null) return Ok(JsonView(false, "团组错误!"));
  21375. #endregion
  21376. //验证
  21377. // (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.CTGGRId, 79);
  21378. // if (!valid)
  21379. // {
  21380. // _sqlSugar.RollbackTran();
  21381. // return Ok(JsonView(false, msg));
  21382. // }
  21383. Result groupData = await _carTouristGuideGroundRep.OpCarTouristGuideGroundContent(dto);
  21384. if (groupData.Code != 0)
  21385. {
  21386. return Ok(JsonView(false, groupData.Msg));
  21387. }
  21388. //自动审核
  21389. await _feeAuditRep.FeeAutomaticAudit(2, dto.DiId, dto.CTGGRId);
  21390. #region 尾款自动审核
  21391. var opinfos = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  21392. .First(x => x.IsDel == 0 && x.DiId == dto.DiId && x.Id == dto.CTGGRId);
  21393. if (opinfos.PriceType == 1062)
  21394. {
  21395. var isAuto = false;
  21396. //找对应的首付款
  21397. var firstPrice = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  21398. .InnerJoin<Grp_CreditCardPayment>((x, a) => a.IsDel == 0 && a.CTable == 79 && a.CId == x.Id && a.DIId == x.DiId && (a.IsAuditGM == 1 || a.IsAuditGM == 3))
  21399. .First(x => x.IsDel == 0 && x.DiId == dto.DiId && x.PriceName == opinfos.PriceName &&
  21400. x.ServiceStartTime == opinfos.ServiceStartTime && x.ServiceEndTime == opinfos.ServiceEndTime && x.Area == opinfos.Area &&
  21401. x.PriceType == 1061 && x.DiId == dto.DiId);
  21402. if (firstPrice != null && !(opinfos.SelectCheck.Contains("超时") || opinfos.SelectCheck.Contains("超支")) && firstPrice.CId == opinfos.CId)
  21403. {
  21404. var cprice = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(x => x.IsDel == 0 && x.CId == firstPrice.Id && x.CTable == 79);
  21405. var balance = firstPrice.ServiceQuotedPrice * (100 - cprice.PayPercentage) / 100;
  21406. //合计中排除城市税
  21407. var cityPrice = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>()
  21408. .Where(x => x.SId == 1452 && x.IsDel == 0 && x.DiId == dto.DiId && x.CTGGRId == dto.CTGGRId)
  21409. .Sum(x => x.Price * x.Count);
  21410. opinfos.ServiceQuotedPrice = opinfos.ServiceQuotedPrice - cityPrice;
  21411. if (balance >= opinfos.ServiceQuotedPrice)
  21412. {
  21413. isAuto = true;
  21414. }
  21415. }
  21416. if (isAuto)
  21417. {
  21418. var execCount = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  21419. .SetColumns(a => new Grp_CreditCardPayment
  21420. {
  21421. IsAuditGM = 3, //自动审核通过
  21422. AuditGMOperate = 4,
  21423. AuditGMDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  21424. })
  21425. .Where(a => a.CId == dto.CTGGRId && a.CTable == 79 && a.DIId == dto.DiId)
  21426. .ExecuteCommand();
  21427. }
  21428. }
  21429. #endregion
  21430. #region 应用推送
  21431. try
  21432. {
  21433. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  21434. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  21435. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  21436. //2024-10-21 新增LZ UID
  21437. var userIds = new List<int>() { 21 };
  21438. string title = $"系统通知";
  21439. var diId = dto.DiId;
  21440. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  21441. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  21442. string content = $"[更新-OP费用录入填写详情({groupInfo?.TeamName ?? "-"})]一项费用:{(((ccpInfo.PayMoney * ccpInfo.DayRate) / 100) * ccpInfo.PayPercentage):#0.00} CNY;";
  21443. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  21444. var h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "79" };
  21445. await APNsTools.iOS_PushNotifications1("051", $"OP费用审核", "", content, true, "ExpenseAuditWebView", h5);
  21446. }
  21447. catch (Exception ex)
  21448. {
  21449. }
  21450. #endregion
  21451. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  21452. }
  21453. catch (Exception ex)
  21454. {
  21455. return Ok(JsonView(false, ex.Message));
  21456. }
  21457. }
  21458. /// <summary>
  21459. /// 获取三公详细所有城市
  21460. /// </summary>
  21461. /// <returns></returns>
  21462. [HttpGet]
  21463. public IActionResult OpCarCityResult()
  21464. {
  21465. var jw = JsonView(false);
  21466. var data = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x => x.IsDel == 0).Select(x => new
  21467. {
  21468. x.Id,
  21469. x.Country,
  21470. x.City,
  21471. }).ToList();
  21472. if (data.Count > 0)
  21473. {
  21474. jw = JsonView(true, "获取成功!", data);
  21475. }
  21476. else
  21477. {
  21478. jw.Msg = "城市数据为空!";
  21479. jw.Data = Array.Empty<string>();
  21480. }
  21481. return Ok(jw);
  21482. }
  21483. /// <summary>
  21484. /// 导出地接费用明细
  21485. /// </summary>
  21486. /// <param name="dto"></param>
  21487. /// <returns></returns>
  21488. [HttpPost]
  21489. public IActionResult ExportLocalGuidePriceDetail(ExportLocalGuidePriceDetailDto dto)
  21490. {
  21491. var jw = JsonView(false);
  21492. if (dto.Diid < 1)
  21493. {
  21494. jw.Msg = "请输入正确的diid!";
  21495. return Ok(jw);
  21496. }
  21497. var group = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  21498. if (group == null)
  21499. {
  21500. jw.Msg = "未找到团组信息!";
  21501. return Ok(jw);
  21502. }
  21503. var localGuideArr = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(x => x.DiId == dto.Diid && x.IsDel == 0).ToList();
  21504. if (localGuideArr.Count == 0)
  21505. {
  21506. jw.Msg = "该团组暂无地接信息!";
  21507. return Ok(jw);
  21508. }
  21509. var localGroup = localGuideArr.GroupBy(x => x.Area).ToList();
  21510. var overspendSoure = new Dictionary<int, int>
  21511. {
  21512. { 91, 982 }, //车
  21513. { 92 , 1059} ,//导游
  21514. { 994 , 1073}, //翻译
  21515. { 988 , 1074 }, //早餐
  21516. { 93 , 1075 }, //午餐
  21517. { 989 , 1076 }, //晚餐
  21518. };
  21519. var Zips = new Dictionary<string, Stream>();
  21520. foreach (var groupArr in localGroup)
  21521. {
  21522. var keyValue = groupArr.Key;
  21523. if (int.TryParse(keyValue, out int cityid))
  21524. {
  21525. var city = _sqlSugar.Queryable<Grp_NationalTravelFee>().First(x => x.Id == cityid && x.IsDel == 0);
  21526. keyValue = city == null ? keyValue : city.Country + "-" + city.City;
  21527. }
  21528. var contentArr = new List<List<Grp_CarTouristGuideGroundReservationsContentExtend>>();
  21529. foreach (var item in groupArr)
  21530. {
  21531. var content = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent, Sys_SetData>((a, b) => a.SId == b.Id
  21532. ).Where((a, b) => a.CTGGRId == item.Id && a.Price != 0M && a.IsDel == 0 && b.IsDel == 0).Select((a, b) =>
  21533. new Grp_CarTouristGuideGroundReservationsContentExtend
  21534. {
  21535. Count = a.Count,
  21536. CreateTime = a.CreateTime,
  21537. CreateUserId = a.CreateUserId,
  21538. CTGGRId = a.CTGGRId,
  21539. Currency = a.Currency,
  21540. DatePrice = a.DatePrice,
  21541. DeleteTime = a.DeleteTime,
  21542. DeleteUserId = a.DeleteUserId,
  21543. DiId = a.DiId,
  21544. Id = a.Id,
  21545. IsDel = a.IsDel,
  21546. Price = a.Price,
  21547. PriceContent = a.PriceContent,
  21548. Remark = a.Remark,
  21549. SId = a.SId,
  21550. SidName = b.Name,
  21551. Units = a.Units,
  21552. }
  21553. ).ToList();
  21554. if (content.Count > 0)
  21555. {
  21556. contentArr.Add(content);
  21557. }
  21558. }
  21559. //open excel
  21560. //set excel
  21561. //save excel
  21562. try
  21563. {
  21564. string filePath = AppSettingsHelper.Get("ExcelBasePath") + "\\Template\\地接费用明细.xlsx";
  21565. IWorkbook workbook;
  21566. if (Path.GetExtension(filePath).ToLower() == ".xls")
  21567. {
  21568. workbook = new NPOI.HSSF.UserModel.HSSFWorkbook(new FileStream(filePath, FileMode.Open, FileAccess.Read));
  21569. }
  21570. else
  21571. {
  21572. workbook = new XSSFWorkbook(new FileStream(filePath, FileMode.Open, FileAccess.Read));
  21573. }
  21574. ISheet sheet = workbook.GetSheetAt(0);
  21575. var rowStartIndex = 2;
  21576. var clounmCount = 10;
  21577. var initStyleRow = sheet.GetRow(2);
  21578. var arr = contentArr.SelectMany(x => x).OrderBy(x => x.SId).ToList();
  21579. //var overspendArrDetail =
  21580. var existsId = new List<CarCompare>();
  21581. var lastElem = arr.Last();
  21582. var thisSid = -1;
  21583. var curr = arr.Count > 0 ? arr[0].Currency : -1;
  21584. var currObj = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == curr && x.IsDel == 0) ?? new Sys_SetData
  21585. {
  21586. Name = "未知币种!",
  21587. Remark = "未知币种!",
  21588. };
  21589. sheet.GetRow(0).GetCell(1).SetCellValue($"{keyValue}费用明细(货币:{currObj.Remark})");
  21590. Action cloneRowFn = () =>
  21591. {
  21592. rowStartIndex++;
  21593. var cloneRow = sheet.CreateRow(rowStartIndex);
  21594. // 复制样式
  21595. for (int i = initStyleRow.FirstCellNum; i < initStyleRow.LastCellNum; i++)
  21596. {
  21597. ICell sourceCell = initStyleRow.GetCell(i);
  21598. ICell targetCell = cloneRow.GetCell(i) ?? cloneRow.CreateCell(i);
  21599. // 确保单元格存在样式
  21600. if (sourceCell.CellStyle != null)
  21601. {
  21602. targetCell.CellStyle = sourceCell.CellStyle;
  21603. }
  21604. }
  21605. };
  21606. var mergeRow = () =>
  21607. {
  21608. for (int i = 2; i < sheet.LastRowNum; i++)
  21609. {
  21610. var row = sheet.GetRow(i);
  21611. var cellFirst = row.GetCell(0);
  21612. var thisIndex = i + 1;
  21613. while (thisIndex < sheet.LastRowNum)
  21614. {
  21615. var nextRow = sheet.GetRow(thisIndex);
  21616. var nextCellFirst = nextRow.GetCell(0);
  21617. if (cellFirst != null && nextCellFirst != null && cellFirst.ToString().Trim() == nextCellFirst.ToString().Trim())
  21618. {
  21619. thisIndex++;
  21620. }
  21621. else
  21622. {
  21623. break;
  21624. }
  21625. }
  21626. thisIndex--;
  21627. if (thisIndex != i)
  21628. {
  21629. //合并row
  21630. var cellRangeAddress = new CellRangeAddress(
  21631. i, // 起始行索引(0-based)
  21632. thisIndex, // 结束行索引(0-based)
  21633. 0, // 起始列索引(0-based)
  21634. 0 // 结束列索引(0-based)
  21635. );
  21636. sheet.AddMergedRegion(cellRangeAddress);
  21637. i = thisIndex;
  21638. }
  21639. }
  21640. };
  21641. var chaoshiNumber = 0;
  21642. var totalNumber = 0.00M;
  21643. string lastStr = "";
  21644. var queryCarArrByCityAndDiid = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations, Grp_CreditCardPayment>((x, b) => x.Id == b.CId && b.IsDel == 0 && b.CTable == 79)
  21645. .Where(x => x.DiId == dto.Diid && x.Area == groupArr.Key).Select((x, b) => new
  21646. {
  21647. b.IsAuditGM,
  21648. x.Id,
  21649. x.Area,
  21650. b.PayPercentage,
  21651. b.PayMoney,
  21652. }).ToList();
  21653. string yesPayment = "", noPayment = "";
  21654. foreach (var item in queryCarArrByCityAndDiid)
  21655. {
  21656. if (item.IsAuditGM == 1)
  21657. {
  21658. yesPayment += $"已支付团款({(int)item.PayPercentage}%):{item.PayMoney} {currObj.Remark}(如有需要,请在此处填写明细)\r\n";
  21659. }
  21660. else
  21661. {
  21662. noPayment += $"剩余团款:{item.PayMoney}{currObj.Remark}(如有需要,请在此处填写明细)\r\n";
  21663. }
  21664. }
  21665. lastStr = yesPayment + noPayment;
  21666. foreach (var item in arr)
  21667. {
  21668. if (existsId.FirstOrDefault(x => x.Sid == item.SId && DateTime.Compare(x.DataPrice, item.DatePrice.ObjToDate()) == 0) == null && !overspendSoure.ContainsValue(item.SId))
  21669. {
  21670. if (thisSid != item.SId)
  21671. {
  21672. if (thisSid == -1)
  21673. {
  21674. thisSid = item.SId;
  21675. }
  21676. else
  21677. {
  21678. //合并小计行
  21679. //创建合并区域的实例
  21680. var cellRangeAddress = new CellRangeAddress(
  21681. rowStartIndex, // 起始行索引(0-based)
  21682. rowStartIndex, // 结束行索引(0-based)
  21683. 0, // 起始列索引(0-based)
  21684. 3 // 结束列索引(0-based)
  21685. );
  21686. sheet.AddMergedRegion(cellRangeAddress);
  21687. var CellStyle = workbook.CreateCellStyle();
  21688. CellStyle.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(0).CellStyle);
  21689. CellStyle.FillForegroundColor = IndexedColors.Yellow.Index; // 选择填充颜色
  21690. CellStyle.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground; // 填充方式
  21691. for (int i = 0; i <= clounmCount; i++)
  21692. {
  21693. if (i > 6)
  21694. {
  21695. var CellStyle1 = workbook.CreateCellStyle();
  21696. CellStyle1.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(0).CellStyle);
  21697. IFont Font = workbook.CreateFont(); // 创建字体
  21698. Font.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(i).CellStyle.GetFont(workbook));
  21699. Font.Color = IndexedColors.Red.Index; // 选择字体颜色
  21700. CellStyle1.SetFont(Font);
  21701. sheet.GetRow(rowStartIndex).GetCell(i).CellStyle = CellStyle1;
  21702. }
  21703. else
  21704. {
  21705. sheet.GetRow(rowStartIndex).GetCell(i).CellStyle = CellStyle;
  21706. }
  21707. }
  21708. sheet.GetRow(rowStartIndex).GetCell(0).SetCellValue("合计:");
  21709. sheet.GetRow(rowStartIndex).GetCell(4).SetCellValue(arr.Where(x => x.SId == thisSid).Sum(x => x.Count * x.Price).ToString("F2"));
  21710. //超时合计
  21711. sheet.GetRow(rowStartIndex).GetCell(7).SetCellValue("超时合计:");
  21712. //超时数
  21713. sheet.GetRow(rowStartIndex).GetCell(8).SetCellValue(chaoshiNumber == 0 ? "" : chaoshiNumber.ToString());
  21714. //超时合计费用
  21715. sheet.GetRow(rowStartIndex).GetCell(9).SetCellValue(totalNumber == 0 ? "" : totalNumber.ToString());
  21716. thisSid = item.SId;
  21717. cloneRowFn();
  21718. chaoshiNumber = 0;
  21719. totalNumber = 0;
  21720. }
  21721. }
  21722. IRow row = sheet.GetRow(rowStartIndex);
  21723. var whereForResult = arr.Where(x => x.SId == item.SId && DateTime.Compare(x.DatePrice.ObjToDate(), item.DatePrice.ObjToDate()) == 0).ToList();
  21724. var isOpenOverspendSoure = overspendSoure.ContainsKey(item.SId);
  21725. List<Grp_CarTouristGuideGroundReservationsContentExtend> overspendWhereForResult = null;
  21726. if (isOpenOverspendSoure)
  21727. {
  21728. overspendWhereForResult = arr.Where(x => x.SId == overspendSoure[item.SId] && DateTime.Compare(x.DatePrice.ObjToDate(), item.DatePrice.ObjToDate()) == 0).ToList();
  21729. chaoshiNumber += overspendWhereForResult.Sum(x => x.Count);
  21730. totalNumber += overspendWhereForResult.Sum(x => x.Count * x.Price);
  21731. }
  21732. for (int i = 0; i <= clounmCount; i++)
  21733. {
  21734. var cell = row.GetCell(i);
  21735. var setCellValue = InIndexOutFunction(i, whereForResult, overspendWhereForResult);
  21736. if (cell == null)
  21737. {
  21738. cell = row.CreateCell(i);
  21739. }
  21740. var fontRed = workbook.CreateCellStyle(); // 创建单元格样式
  21741. fontRed.CloneStyleFrom(cell.CellStyle);
  21742. IFont Font = workbook.CreateFont(); // 创建字体
  21743. Font.CloneStyleFrom(cell.CellStyle.GetFont(workbook));
  21744. Font.Color = IndexedColors.Red.Index; // 选择字体颜色
  21745. fontRed.SetFont(Font);
  21746. byte[] rgb = new byte[3] { 255, 242, 204 };
  21747. var BackgroundColor255_242_204 = workbook.CreateCellStyle();
  21748. BackgroundColor255_242_204.CloneStyleFrom(cell.CellStyle);
  21749. byte[] rgb1 = new byte[3] { 189, 215, 238 };
  21750. if (workbook is XSSFWorkbook)
  21751. {
  21752. BackgroundColor255_242_204.FillForegroundColor = 0;
  21753. ((XSSFColor)BackgroundColor255_242_204.FillForegroundColorColor).SetRgb(rgb);
  21754. BackgroundColor255_242_204.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
  21755. }
  21756. else
  21757. {
  21758. BackgroundColor255_242_204.FillForegroundColor = (((NPOI.HSSF.UserModel.HSSFWorkbook)workbook).GetCustomPalette().FindSimilarColor(rgb[0], rgb[1], rgb[2])).Indexed;
  21759. }
  21760. if (i == 1 || i > 6)
  21761. {
  21762. if (i > 6)
  21763. {
  21764. fontRed.FillForegroundColor = 0;
  21765. ((XSSFColor)fontRed.FillForegroundColorColor).SetRgb(rgb1);
  21766. fontRed.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
  21767. }
  21768. cell.CellStyle = fontRed;
  21769. }
  21770. if (i > 2 && i < 7)
  21771. {
  21772. cell.CellStyle = BackgroundColor255_242_204;
  21773. }
  21774. cell.SetCellValue(setCellValue); //写入单元格
  21775. }
  21776. if (overspendSoure.ContainsKey(thisSid))
  21777. {
  21778. var overspendId = overspendSoure[thisSid];
  21779. whereForResult = arr.Where(x => x.SId == item.SId && DateTime.Compare(x.DatePrice.ObjToDate(), item.DatePrice.ObjToDate()) == 0).ToList();
  21780. }
  21781. cloneRowFn();
  21782. existsId.Add(new CarCompare
  21783. {
  21784. DataPrice = item.DatePrice.ObjToDate(),
  21785. Sid = item.SId
  21786. });
  21787. }
  21788. if (item.Equals(lastElem))
  21789. {
  21790. //合并小计行
  21791. //创建合并区域的实例
  21792. var cellRangeAddress = new CellRangeAddress(
  21793. rowStartIndex, // 起始行索引(0-based)
  21794. rowStartIndex, // 结束行索引(0-based)
  21795. 0, // 起始列索引(0-based)
  21796. 3 // 结束列索引(0-based)
  21797. );
  21798. sheet.AddMergedRegion(cellRangeAddress);
  21799. var CellStyle = workbook.CreateCellStyle();
  21800. CellStyle.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(0).CellStyle);
  21801. CellStyle.FillForegroundColor = IndexedColors.Yellow.Index; // 选择填充颜色
  21802. CellStyle.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground; // 填充方式
  21803. for (int i = 0; i <= clounmCount; i++)
  21804. {
  21805. if (i > 6)
  21806. {
  21807. var CellStyle1 = workbook.CreateCellStyle();
  21808. CellStyle1.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(0).CellStyle);
  21809. IFont Font = workbook.CreateFont(); // 创建字体
  21810. Font.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(i).CellStyle.GetFont(workbook));
  21811. Font.Color = IndexedColors.Red.Index; // 选择字体颜色
  21812. CellStyle1.SetFont(Font);
  21813. sheet.GetRow(rowStartIndex).GetCell(i).CellStyle = CellStyle1;
  21814. }
  21815. else
  21816. {
  21817. sheet.GetRow(rowStartIndex).GetCell(i).CellStyle = CellStyle;
  21818. }
  21819. }
  21820. sheet.GetRow(rowStartIndex).GetCell(0).SetCellValue("合计:");
  21821. sheet.GetRow(rowStartIndex).GetCell(4).SetCellValue(arr.Where(x => x.SId == thisSid).Sum(x => x.Count * x.Price).ToString("F2"));
  21822. //超时合计
  21823. sheet.GetRow(rowStartIndex).GetCell(7).SetCellValue("超时合计:");
  21824. //超时数
  21825. sheet.GetRow(rowStartIndex).GetCell(8).SetCellValue(chaoshiNumber == 0 ? "" : chaoshiNumber.ToString());
  21826. //超时合计费用
  21827. sheet.GetRow(rowStartIndex).GetCell(9).SetCellValue(totalNumber == 0 ? "" : totalNumber.ToString());
  21828. cloneRowFn();
  21829. // 创建合并区域的实例
  21830. cellRangeAddress = new CellRangeAddress(
  21831. rowStartIndex, // 起始行索引(0-based)
  21832. rowStartIndex, // 结束行索引(0-based)
  21833. 0, // 起始列索引(0-based)
  21834. initStyleRow.LastCellNum - 1 // 结束列索引(0-based)
  21835. );
  21836. // 添加合并区域
  21837. sheet.AddMergedRegion(cellRangeAddress);
  21838. sheet.GetRow(rowStartIndex).Height = 30 * 30;
  21839. sheet.GetRow(rowStartIndex).GetCell(0).SetCellValue(lastStr);
  21840. }
  21841. }
  21842. mergeRow();
  21843. // 保存修改后的Excel文件到新文件
  21844. //string newFilePath = Path.Combine(Path.GetDirectoryName(filePath), keyValue +"_" + Path.GetFileName(filePath));
  21845. // new FileStream(newFilePath, FileMode.CreateNew)
  21846. using (var stream = new MemoryStream())
  21847. {
  21848. workbook.Write(stream, true);
  21849. stream.Flush();
  21850. stream.Seek(0, SeekOrigin.Begin);
  21851. var memoryStream = new MemoryStream();
  21852. stream.CopyTo(memoryStream);
  21853. memoryStream.Seek(0, SeekOrigin.Begin);
  21854. Zips.Add(keyValue + "_" + "费用明细表.xlsx", memoryStream);
  21855. }
  21856. workbook.Close();
  21857. workbook.Dispose();
  21858. }
  21859. catch (Exception ex)
  21860. {
  21861. jw.Msg = "出现异常!" + ex.Message;
  21862. return Ok(jw);
  21863. }
  21864. }
  21865. if (Zips.Count > 0)
  21866. {
  21867. var io = new IOOperatorHelper();
  21868. var byts = io.ConvertZipStream(Zips);
  21869. io.ByteToFile(byts, AppSettingsHelper.Get("ExcelBasePath") + $"\\ExportLocalGuidePriceDetail\\{group.TeamName}_地接费用明细.zip");
  21870. //http://132.232.92.186:24/Office/Word/EnterExitCost/File/
  21871. jw = JsonView(true, "success", new { url = AppSettingsHelper.Get("OfficeBaseUrl") + $"\\Office\\Excel\\ExportLocalGuidePriceDetail\\{group.TeamName}_地接费用明细.zip" });
  21872. }
  21873. else
  21874. {
  21875. jw.Msg = "暂无生成文件!";
  21876. }
  21877. return Ok(jw);
  21878. }
  21879. private string InIndexOutFunction(int i, List<Grp_CarTouristGuideGroundReservationsContentExtend> arr, List<Grp_CarTouristGuideGroundReservationsContentExtend> arrOverspendSoure)
  21880. {
  21881. string outStr = string.Empty;
  21882. switch (i)
  21883. {
  21884. case 0:
  21885. outStr = arr[0].SidName;
  21886. break;
  21887. case 1:
  21888. outStr = arr[0].DataPriceStr;
  21889. break;
  21890. case 2:
  21891. outStr = string.Join("-", arr.Select(x => x.PriceContent));
  21892. break;
  21893. case 4:
  21894. outStr = arr.Sum(x => x.Subtotal).ToString("F2");
  21895. break;
  21896. case 7:
  21897. if (arrOverspendSoure != null && arrOverspendSoure.Count > 0)
  21898. {
  21899. var curr = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == arrOverspendSoure[0].Currency && x.IsDel == 0);
  21900. var unit = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == arrOverspendSoure[0].Units && x.IsDel == 0);
  21901. outStr = arrOverspendSoure.Sum(x => x.Price).ToString("F2") + curr?.Remark + "/" + unit?.Name;
  21902. }
  21903. break;
  21904. case 8:
  21905. if (arrOverspendSoure != null && arrOverspendSoure.Count > 0)
  21906. {
  21907. outStr = arrOverspendSoure.Sum(x => x.Count).ToString();
  21908. }
  21909. break;
  21910. case 9:
  21911. if (arrOverspendSoure != null && arrOverspendSoure.Count > 0)
  21912. {
  21913. outStr = arrOverspendSoure.Sum(x => x.Count * x.Price).ToString();
  21914. }
  21915. break;
  21916. case 10:
  21917. if (arrOverspendSoure != null && arrOverspendSoure.Count > 0)
  21918. {
  21919. outStr = string.Join("-", arrOverspendSoure.Select(x => x.PriceContent));
  21920. }
  21921. break;
  21922. }
  21923. return outStr;
  21924. }
  21925. #region OP行程单
  21926. /// <summary>
  21927. /// OP行程单初始化
  21928. /// </summary>
  21929. /// <param name="dto"></param>
  21930. /// <returns></returns>
  21931. [HttpPost]
  21932. public IActionResult InitOpTravel(InitOpTravelDto dto)
  21933. {
  21934. var jw = JsonView(false);
  21935. var groupList = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0).OrderByDescending(x => x.VisitStartDate).ToList();
  21936. var group = groupList.First();
  21937. var diid = dto.Diid == -1 ? group?.Id : dto.Diid;
  21938. if (group == null)
  21939. {
  21940. jw.Msg = "暂无团组!";
  21941. return Ok(jw);
  21942. }
  21943. group = groupList.Find(x => x.Id == diid);
  21944. if (group == null)
  21945. {
  21946. jw.Msg = "请输入正确的团组ID!";
  21947. return Ok(jw);
  21948. }
  21949. string city = string.Empty;
  21950. var blackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && x.DiId == diid).ToList();
  21951. if (blackCode.Count > 0)
  21952. {
  21953. var black = blackCode.First();
  21954. black.BlackCode = black.BlackCode ?? "";
  21955. var blackSp = Regex.Split(black.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  21956. if (blackSp.Length > 0)
  21957. {
  21958. try
  21959. {
  21960. var cityArrCode = new List<string>(20);
  21961. foreach (var item in blackSp)
  21962. {
  21963. var itemSp = item.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  21964. var IndexSelect = itemSp[2];
  21965. var cityArrCodeLength = cityArrCode.Count - 1;
  21966. var startCity = IndexSelect.Substring(0, 3);
  21967. if (cityArrCodeLength > 0)
  21968. {
  21969. var arrEndCity = cityArrCode[cityArrCodeLength];
  21970. if (arrEndCity != startCity)
  21971. {
  21972. cityArrCode.Add(startCity.ToUpper());
  21973. }
  21974. }
  21975. else
  21976. {
  21977. cityArrCode.Add(startCity.ToUpper());
  21978. }
  21979. var endCity = IndexSelect.Substring(3, 3);
  21980. cityArrCode.Add(endCity.ToUpper());
  21981. }
  21982. var cityThree = string.Empty;
  21983. cityArrCode.ForEach(x => cityThree += "'" + x + "',");
  21984. cityThree = cityThree.TrimEnd(',');
  21985. if (string.IsNullOrWhiteSpace(cityThree))
  21986. {
  21987. throw new
  21988. Exception("error");
  21989. }
  21990. string sql = $"SELECT * FROM Res_ThreeCode rtc WHERE UPPER(rtc.Three) in ({cityThree}) ";
  21991. var cityArr = _sqlSugar.SqlQueryable<Res_ThreeCode>(sql).ToList();
  21992. foreach (var item in cityArrCode)
  21993. {
  21994. var find = cityArr.Find(x => x.Three.ToUpper() == item.ToUpper());
  21995. if (find != null)
  21996. {
  21997. city += find.City + "/";
  21998. }
  21999. else
  22000. {
  22001. city += item + "三字码未收入/";
  22002. }
  22003. }
  22004. city = city.TrimEnd('/');
  22005. }
  22006. catch (Exception e)
  22007. {
  22008. city = "黑屏代码格式不正确!";
  22009. }
  22010. }
  22011. }
  22012. else
  22013. {
  22014. city = "未录入黑屏代码";
  22015. }
  22016. var OpTravelList = _sqlSugar.Queryable<Grp_TravelList>().Where(x => x.Diid == diid && x.IsDel == 0).OrderBy(x => x.Days).Select(x => new TravelArrView
  22017. {
  22018. Date = x.Date,
  22019. Days = x.Days,
  22020. Diffgroup = x.Diffgroup,
  22021. Diid = x.Diid,
  22022. Traffic_First = x.Traffic_First,
  22023. Traffic_Second = x.Traffic_Second,
  22024. Trip = x.Trip,
  22025. WeekDay = x.WeekDay,
  22026. Id = x.Id
  22027. }).ToList();
  22028. jw.Data = new
  22029. {
  22030. groupList = groupList.Select(x => new
  22031. {
  22032. x.Id,
  22033. x.TeamName,
  22034. x.TourCode
  22035. }).ToList(),
  22036. groupInfo = new
  22037. {
  22038. group.VisitDays,
  22039. group.TourCode,
  22040. group.VisitPNumber,
  22041. group.TeamName,
  22042. city
  22043. },
  22044. OpTravelList
  22045. };
  22046. jw.Code = 200;
  22047. jw.Msg = "操作成功!";
  22048. return Ok(jw);
  22049. }
  22050. /// <summary>
  22051. /// 删除团组行程单
  22052. /// </summary>
  22053. /// <returns></returns>
  22054. [HttpPost]
  22055. public IActionResult DelTravel(DelOpTravelDto dto)
  22056. {
  22057. var jw = JsonView(false);
  22058. if (dto.UserId <= 0 || dto.Diid <= 0)
  22059. {
  22060. jw.Msg = "请输入正确的参数!";
  22061. return Ok(jw);
  22062. }
  22063. var isTrue = _sqlSugar.Updateable<Grp_TravelList>().Where(x => x.Diid == dto.Diid && x.IsDel == 0)
  22064. .SetColumns(x => new Grp_TravelList
  22065. {
  22066. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  22067. DeleteUserId = dto.UserId,
  22068. IsDel = 1,
  22069. }).ExecuteCommand();
  22070. jw = JsonView(true);
  22071. return Ok(jw);
  22072. }
  22073. /// <summary>
  22074. /// 行程单保存
  22075. /// </summary>
  22076. /// <returns></returns>
  22077. [HttpPost]
  22078. public IActionResult TravelSave(TravelSaveDto dto)
  22079. {
  22080. var jw = JsonView(false);
  22081. if (dto.Arr.Count > 0)
  22082. {
  22083. try
  22084. {
  22085. var travelList_DB = _sqlSugar.Queryable<Grp_TravelList>()
  22086. .Where(x => dto.Arr.Select(x => x.Id).Contains(x.Id))
  22087. .ToList();
  22088. _sqlSugar.BeginTran();
  22089. foreach (var item in dto.Arr)
  22090. {
  22091. if (item.Id == 0)
  22092. {
  22093. throw new Exception("请传入正确的Id");
  22094. }
  22095. //比较上一次的差异
  22096. var findTravel = travelList_DB.Find(x => x.Id == item.Id);
  22097. if (findTravel != null)
  22098. {
  22099. item.Trip = item.Trip.Replace("[++]", string.Empty);
  22100. findTravel.Trip = findTravel.Trip.Replace("[++]", string.Empty);
  22101. item.Trip = CheckStr(findTravel.Trip, item.Trip);
  22102. }
  22103. _sqlSugar.Updateable<Grp_TravelList>().Where(x => x.Id == item.Id)
  22104. .SetColumns(x => new Grp_TravelList
  22105. {
  22106. Trip = item.Trip
  22107. }).ExecuteCommand();
  22108. }
  22109. _sqlSugar.CommitTran();
  22110. jw = JsonView(true);
  22111. }
  22112. catch (Exception ex)
  22113. {
  22114. _sqlSugar.RollbackTran();
  22115. jw.Msg = "程序异常!" + ex.Message;
  22116. }
  22117. }
  22118. else
  22119. {
  22120. jw.Msg = "请传入正确的参数!";
  22121. }
  22122. return Ok(jw);
  22123. }
  22124. private static string CheckStr(string original, string changed)
  22125. {
  22126. // 创建diff_match_patch对象
  22127. var dmp = new diff_match_patch();
  22128. // 计算差异
  22129. List<Diff> diffs = dmp.diff_main(original, changed);
  22130. // 清理和合并差异
  22131. dmp.diff_cleanupSemantic(diffs);
  22132. // 使用StringBuilder构建最终的字符串
  22133. var finalString = new StringBuilder();
  22134. // 输出差异结果,并构建变动后的字符串
  22135. foreach (Diff diff in diffs)
  22136. {
  22137. switch (diff.operation)
  22138. {
  22139. case Operation.EQUAL:
  22140. // 相等的部分,直接添加到最终字符串
  22141. finalString.Append(diff.text);
  22142. break;
  22143. case Operation.INSERT:
  22144. // 插入的部分,添加标记并添加到最终字符串
  22145. finalString.Append("[++]" + diff.text + "[++]");
  22146. break;
  22147. case Operation.DELETE:
  22148. // 删除的部分,不添加到最终字符串
  22149. //finalString.Append("[++]" + diff.text + "[++]");
  22150. break;
  22151. }
  22152. }
  22153. // 输出变动后的字符串
  22154. return finalString.ToString();
  22155. }
  22156. private class tagContent
  22157. {
  22158. public DateTime Date { get; set; }
  22159. public string StartTag { get; set; }
  22160. public string EndTag { get; set; }
  22161. public string Content { get; set; }
  22162. public static int tagLength { get { return 3; } }
  22163. public static Tuple<string, string> TagFormat { get { return new Tuple<string, string>("【#", "#】"); } }
  22164. public string QueryTag { get { return this.StartTag + this.EndTag; } }
  22165. public bool IsFinally { get; set; }
  22166. }
  22167. private static List<string> ExtractContentBetweenTags(string input, string tag)
  22168. {
  22169. var results = new List<string>();
  22170. // 构造正则表达式,匹配形如 [++]内容[++] 的部分
  22171. string pattern = $@"{Regex.Escape(tag)}(.*?){Regex.Escape(tag)}";
  22172. // 添加 RegexOptions.Singleline 选项使 . 匹配包括换行符在内的所有字符
  22173. MatchCollection matches = Regex.Matches(input, pattern, RegexOptions.Singleline);
  22174. string[] strValueArr = new string[1];
  22175. foreach (System.Text.RegularExpressions.Match match in matches)
  22176. {
  22177. var strValue = match.Groups[1].Value;
  22178. strValueArr = Regex.Split(strValue, @"\r\n|\n");
  22179. }
  22180. results.AddRange(strValueArr.Where(x => !string.IsNullOrWhiteSpace(x)));
  22181. return results;
  22182. }
  22183. /// <summary>
  22184. /// 导出行程单
  22185. /// </summary>
  22186. /// <param name="dto"></param>
  22187. /// <returns></returns>
  22188. [HttpPost]
  22189. public IActionResult ExportTravel(ExportTravelDto dto)
  22190. {
  22191. var jw = JsonView(false);
  22192. jw.Data = "";
  22193. int diid = 0;
  22194. var Find = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid);
  22195. if (Find == null)
  22196. {
  22197. jw.Msg = "请选择正确的团组!";
  22198. return Ok(jw);
  22199. }
  22200. else
  22201. {
  22202. diid = Find.Id;
  22203. }
  22204. //数据源
  22205. var _travelList = new List<Grp_TravelList>();
  22206. DataTable dtBlack = null;
  22207. try
  22208. {
  22209. dtBlack = GeneralMethod.GetTableByBlackCode(diid);
  22210. }
  22211. catch (Exception)
  22212. {
  22213. jw.Msg = "机票黑屏代码有误!";
  22214. return Ok(jw);
  22215. }
  22216. string CityStr = string.Empty;
  22217. if (dtBlack.Rows.Count == 0)
  22218. {
  22219. jw.Msg = "机票黑屏代码有误!";
  22220. return Ok(jw);
  22221. }
  22222. else
  22223. {
  22224. foreach (DataRow row in dtBlack.Rows)
  22225. {
  22226. if (!string.IsNullOrWhiteSpace(row["Error"].ToString()))
  22227. {
  22228. jw.Msg = "机票黑屏代码有误!" + row["Error"].ToString();
  22229. return Ok(jw);
  22230. }
  22231. }
  22232. CityStr = GeneralMethod.GetGroupCityLine(diid, "/");
  22233. _travelList = _sqlSugar.Queryable<Grp_TravelList>().Where(x => x.Diid == diid && x.IsDel == 0 && x.Issel == 1).ToList();
  22234. }
  22235. // 指定的文字
  22236. var targetTextDic = new Dictionary<string, List<string>>();
  22237. //创建数据源Table
  22238. var dtSource = new DataTable();
  22239. dtSource.Columns.Add("Days", typeof(string));
  22240. dtSource.Columns.Add("Date", typeof(string));
  22241. dtSource.Columns.Add("Week", typeof(string));
  22242. dtSource.Columns.Add("Traffic", typeof(string));
  22243. dtSource.Columns.Add("Trip", typeof(string));
  22244. //获取数据,放到datatable
  22245. foreach (var item in _travelList)
  22246. {
  22247. targetTextDic.Add(item.Date, ExtractContentBetweenTags(item.Trip, "[++]"));
  22248. item.Trip = item.Trip.Replace(tagContent.TagFormat.Item1, string.Empty)
  22249. .Replace(tagContent.TagFormat.Item2, string.Empty)
  22250. .Replace("[++]", string.Empty);
  22251. DataRow dr = dtSource.NewRow();
  22252. dr["Days"] = item.Days;
  22253. dr["Date"] = item.Date;
  22254. dr["Week"] = item.WeekDay;
  22255. dr["Traffic"] = item.Traffic_First
  22256. + "\r\n"
  22257. + item.Traffic_Second;
  22258. dr["Trip"] = item.Trip;
  22259. dtSource.Rows.Add(dr);
  22260. }
  22261. var dic = new Dictionary<string, string>
  22262. {
  22263. { "Dele", Find.TeamName.ToString() + GetNum(Find.VisitDays.ToString()) },
  22264. { "City", CityStr },
  22265. { "Days", Find.VisitDays.ToString() },
  22266. { "DeleCode", Find.TourCode },
  22267. { "Pnum", Find.VisitPNumber.ToString() }
  22268. };
  22269. //模板路径
  22270. string tempPath = AppSettingsHelper.Get("WordBasePath") + "Travel/日行程3.docx";
  22271. //载入模板
  22272. Document doc = null;
  22273. DocumentBuilder builder = null;
  22274. try
  22275. {
  22276. //载入模板
  22277. doc = new Document(tempPath);
  22278. builder = new DocumentBuilder(doc);
  22279. }
  22280. catch (Exception)
  22281. {
  22282. jw.Msg = "模板位置不存在!";
  22283. return Ok(jw);
  22284. }
  22285. foreach (var key in dic.Keys)
  22286. {
  22287. Bookmark bookmark = doc.Range.Bookmarks[key];
  22288. if (bookmark != null)
  22289. {
  22290. builder.MoveToBookmark(key);
  22291. builder.Write(dic[key]);
  22292. }
  22293. }
  22294. //获取word里所有表格
  22295. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  22296. //获取所填表格的序数
  22297. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  22298. try
  22299. {
  22300. //循环赋值
  22301. for (int i = 0; i < dtSource.Rows.Count; i++)
  22302. {
  22303. builder.MoveToCell(0, i + 1, 0, 0);
  22304. builder.Write(dtSource.Rows[i]["Days"].ToString());
  22305. builder.MoveToCell(0, i + 1, 1, 0);
  22306. builder.Write(dtSource.Rows[i]["Date"].ToString() + "\r\n" + dtSource.Rows[i]["Week"].ToString());
  22307. builder.MoveToCell(0, i + 1, 2, 0);
  22308. builder.Write(dtSource.Rows[i]["Traffic"].ToString());
  22309. var trip = dtSource.Rows[i]["Trip"].ToString();
  22310. builder.MoveToCell(0, i + 1, 3, 0);
  22311. builder.Write(trip);
  22312. var cell = (Aspose.Words.Tables.Cell)doc.GetChild(NodeType.Cell, ((i + 2) * 4) - 1, true);
  22313. var paragraphs = cell.GetChildNodes(NodeType.Paragraph, true);
  22314. // 获取特定索引的段落
  22315. Paragraph paragraph = (Paragraph)paragraphs[0];
  22316. Run run = paragraph.Runs[0];
  22317. Aspose.Words.Font font = run.Font;
  22318. font.Name = "黑体";
  22319. //设置双休红色
  22320. cell = (Aspose.Words.Tables.Cell)doc.GetChild(NodeType.Cell, ((i + 2) * 4) - 3, true);
  22321. paragraphs = cell.GetChildNodes(NodeType.Paragraph, true);
  22322. paragraph = (Paragraph)paragraphs[1];
  22323. if (paragraph.GetText().Contains("星期六") || paragraph.GetText().Contains("星期日"))
  22324. {
  22325. run = paragraph.Runs[0];
  22326. font = run.Font;
  22327. font.Color = Color.Red;
  22328. }
  22329. }
  22330. }
  22331. catch (Exception ex)
  22332. {
  22333. }
  22334. //删除多余行
  22335. while (tableOne.Rows.Count > 1 + dtSource.Rows.Count)
  22336. {
  22337. tableOne.Rows.RemoveAt(1 + dtSource.Rows.Count);//(1+dtSource.Rows.Count + 1)-1
  22338. }
  22339. var targetTextList = new List<string>();
  22340. // 遍历文档中的表格
  22341. foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
  22342. {
  22343. foreach (Aspose.Words.Tables.Row row in table.Rows)
  22344. {
  22345. var cellIndex = 0;
  22346. foreach (Cell cell in row.Cells)
  22347. {
  22348. if (cellIndex == 1 && row.Cells.Count == 4)
  22349. {
  22350. foreach (var target in targetTextDic.Keys)
  22351. {
  22352. if (cell.GetText().Contains(target))
  22353. {
  22354. targetTextList = targetTextDic[target];
  22355. break;
  22356. }
  22357. }
  22358. }
  22359. // 遍历单元格中的所有段落
  22360. foreach (Paragraph paragraph in cell.Paragraphs)
  22361. {
  22362. // 使用临时列表存储原始 Runs,避免修改时影响遍历
  22363. var runs = new List<Run>();
  22364. foreach (Run run in paragraph.Runs)
  22365. {
  22366. runs.Add(run);
  22367. }
  22368. foreach (Run run in runs)
  22369. {
  22370. foreach (var targetText in targetTextList)
  22371. {
  22372. // 检查文字是否包含指定文字
  22373. if (run.Text.Contains(targetText))
  22374. {
  22375. // 将包含的部分设置为红色
  22376. HighlightText(run, targetText, Color.Red);
  22377. }
  22378. }
  22379. }
  22380. }
  22381. cellIndex++;
  22382. }
  22383. }
  22384. }
  22385. string savePath = AppSettingsHelper.Get("WordBasePath") + "Travel/export/";
  22386. if (!Directory.Exists(savePath))
  22387. {
  22388. try
  22389. {
  22390. Directory.CreateDirectory(savePath);
  22391. }
  22392. catch
  22393. {
  22394. }
  22395. }
  22396. string path = savePath + Find.TeamName + "出访日程";
  22397. string ftpPath = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + "Travel/export/" + Find.TeamName + "出访日程";
  22398. try
  22399. {
  22400. Aspose.Words.SaveFormat saveFormat = Aspose.Words.SaveFormat.Doc;
  22401. string postfix = ".docx";
  22402. if (dto.IsPDF == 1)
  22403. {
  22404. saveFormat = Aspose.Words.SaveFormat.Pdf;
  22405. postfix = ".pdf";
  22406. }
  22407. doc.Save(path + postfix, saveFormat);
  22408. jw = JsonView(true, "导出成功", ftpPath + postfix);
  22409. }
  22410. catch (Exception)
  22411. {
  22412. jw = JsonView(false);
  22413. }
  22414. return Ok(jw);
  22415. }
  22416. /// <summary>
  22417. /// 根据大写数字返回小写数字或根据小写数字返回大写数字
  22418. /// </summary>
  22419. /// <param name="num"></param>
  22420. /// <returns></returns>
  22421. static string GetNum(string num)
  22422. {
  22423. string str = "";
  22424. switch (num)
  22425. {
  22426. case "1":
  22427. str = "一";
  22428. break;
  22429. case "2":
  22430. str = "二";
  22431. break;
  22432. case "3":
  22433. str = "三";
  22434. break;
  22435. case "4":
  22436. str = "四";
  22437. break;
  22438. case "5":
  22439. str = "五";
  22440. break;
  22441. case "6":
  22442. str = "六";
  22443. break;
  22444. case "7":
  22445. str = "七";
  22446. break;
  22447. case "8":
  22448. str = "八";
  22449. break;
  22450. case "9":
  22451. str = "九";
  22452. break;
  22453. case "10":
  22454. str = "十";
  22455. break;
  22456. case "11":
  22457. str = "十一";
  22458. break;
  22459. case "12":
  22460. str = "十二";
  22461. break;
  22462. case "一":
  22463. str = "1";
  22464. break;
  22465. case "二":
  22466. str = "2";
  22467. break;
  22468. case "三":
  22469. str = "3";
  22470. break;
  22471. case "四":
  22472. str = "4";
  22473. break;
  22474. case "五":
  22475. str = "5";
  22476. break;
  22477. case "六":
  22478. str = "6";
  22479. break;
  22480. case "七":
  22481. str = "7";
  22482. break;
  22483. case "八":
  22484. str = "8";
  22485. break;
  22486. case "九":
  22487. str = "9";
  22488. break;
  22489. case "十":
  22490. str = "10";
  22491. break;
  22492. case "十一":
  22493. str = "11";
  22494. break;
  22495. case "十二":
  22496. str = "12";
  22497. break;
  22498. }
  22499. return str;
  22500. }
  22501. /// <summary>
  22502. /// 高亮包含指定文字的部分
  22503. /// </summary>
  22504. /// <param name="run"></param>
  22505. /// <param name="targetText"></param>
  22506. /// <param name="color"></param>
  22507. static void HighlightText(Run run, string targetText, Color color)
  22508. {
  22509. string text = run.Text;
  22510. int startIndex = text.IndexOf(targetText, StringComparison.Ordinal);
  22511. if (startIndex >= 0)
  22512. {
  22513. Paragraph parentParagraph = (Paragraph)run.ParentNode;
  22514. // 前部分
  22515. if (startIndex > 0)
  22516. {
  22517. Run beforeRun = (Run)run.Clone(true);
  22518. beforeRun.Text = text.Substring(0, startIndex);
  22519. parentParagraph.InsertBefore(beforeRun, run);
  22520. }
  22521. // 匹配部分
  22522. Run matchRun = (Run)run.Clone(true);
  22523. matchRun.Text = text.Substring(startIndex, targetText.Length);
  22524. matchRun.Font.Color = color;
  22525. parentParagraph.InsertBefore(matchRun, run);
  22526. // 后部分
  22527. if (startIndex + targetText.Length < text.Length)
  22528. {
  22529. Run afterRun = (Run)run.Clone(true);
  22530. afterRun.Text = text.Substring(startIndex + targetText.Length);
  22531. parentParagraph.InsertBefore(afterRun, run);
  22532. }
  22533. // 删除原始Run
  22534. run.Remove();
  22535. }
  22536. }
  22537. #endregion
  22538. #endregion
  22539. #region 团组成本
  22540. /// <summary>
  22541. /// 团组成本数据初始化
  22542. /// </summary>
  22543. /// <param name="dto"></param>
  22544. /// <returns></returns>
  22545. [HttpPost]
  22546. public async Task<IActionResult> GroupCostInit(GroupCostInItDto dto)
  22547. {
  22548. var groupList = _sqlSugar.SqlQueryable<DelegationInfoAndIsTrueView>($@"
  22549. Select a.Id,TeamName GroupName,b.isTrue From Grp_DelegationInfo a left join (select top 100 percent Diid, CASE
  22550. WHEN COUNT(*) >= 0 THEN 'True'
  22551. ELSE 'False' END as isTrue from Grp_GroupCost where Isdel = 0 and date != '' group by Diid) b on a.Id = b.Diid
  22552. Where TeamName != '' And IsDel = 0 Order By a.VisitStartDate Desc
  22553. ").ToList(); //团组列表
  22554. int diid = dto.Diid == -1 ? groupList.First().Id : dto.Diid;
  22555. var groupInfo = await _groupRepository.PostShareGroupInfo(new ShareGroupInfoDto { PortType = 1, Id = diid }); //团组信息
  22556. var visaCountryInfoArr = new ArrayList();
  22557. var groupinfoValue = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == diid && x.IsDel == 0);
  22558. if (groupinfoValue != null)
  22559. {
  22560. var countryArr = groupinfoValue.VisitCountry ??= string.Empty;
  22561. var dicity = _sqlSugar.Queryable<Sys_Cities>().First(x => x.IsDel == 0 && x.Id == groupinfoValue.CityId);
  22562. dicity ??= new Sys_Cities()
  22563. {
  22564. ParentId = 122
  22565. };
  22566. var diparent = _sqlSugar.Queryable<Sys_Cities>().First(x => x.IsDel == 0 && x.Id == dicity.ParentId);
  22567. var spArr = new string[1] { countryArr };
  22568. if (countryArr.Contains("|"))
  22569. {
  22570. spArr = countryArr.Split("|");
  22571. }
  22572. else if (countryArr.Contains("、"))
  22573. {
  22574. spArr = countryArr.Split("、");
  22575. }
  22576. foreach (var item in spArr.Where(x => !string.IsNullOrWhiteSpace(x)).ToList())
  22577. {
  22578. try
  22579. {
  22580. var visa = _sqlSugar.Queryable<Res_VisaFeeStandard>()
  22581. .Where(x => x.IsDel == 0 && x.Country == item)
  22582. .ToList();
  22583. if (!visa.Any())
  22584. {
  22585. visa = _sqlSugar.Queryable<Res_VisaFeeStandard>()
  22586. .Where(x => x.IsDel == 0 && x.Country.Contains(item))
  22587. .ToList();
  22588. }
  22589. if (visa.Any())
  22590. {
  22591. var visainfo = _sqlSugar.Queryable<Res_VisaFeeStandardDetails>()
  22592. .LeftJoin<Res_VisaFeeStandard>((x, y) => x.ParentId == y.Id && y.IsDel == 0)
  22593. .Where(x => x.IsDel == 0 && visa.Select(x => x.Id).Contains(x.ParentId))
  22594. .Select((x, y) => new
  22595. {
  22596. x.Id,
  22597. x.ParentId,
  22598. x.ProvinceId,
  22599. x.VisaAddress,
  22600. x.IsVisaOnArrival,
  22601. x.IsElectronicSign,
  22602. x.VisaTime,
  22603. x.IsVisaExemptionLarge,
  22604. x.LargeVisaPrice,
  22605. x.LargeAgencyFee,
  22606. x.IsVisaExemptionSmall,
  22607. x.SmallVisaPrice,
  22608. x.SmallAgencyFee,
  22609. x.NormExtFee,
  22610. x.UrgExtFee,
  22611. x.IsUrgent,
  22612. x.UrgentTime,
  22613. x.UrgentPrice,
  22614. x.UrgentPriceDesc,
  22615. y.FeeType,
  22616. x.Remark
  22617. })
  22618. .ToList();
  22619. var visaMain = visainfo.FirstOrDefault(x => x.ProvinceId == diparent.Id && x.FeeType == 0);
  22620. var visayinsiValue = visainfo.FirstOrDefault(x => x.ParentId == visa.FirstOrDefault(x => x.FeeType == 1)?.Id);
  22621. visaCountryInfoArr.Add(new
  22622. {
  22623. country = item,
  22624. yinsi = new
  22625. {
  22626. Id = visayinsiValue.Id,
  22627. value = visayinsiValue.SmallVisaPrice
  22628. },
  22629. visaMain = new
  22630. {
  22631. Id = visaMain.Id,
  22632. IsVisaOnArrival = visaMain.IsVisaOnArrival ? "是" : "否",
  22633. IsElectronicSign = visaMain.IsElectronicSign ? "是" : "否",
  22634. VisaTime = visaMain.VisaTime,
  22635. IsVisaExemptionLarge = visaMain.IsVisaExemptionLarge ? "是" : "否",
  22636. LargeVisaPrice = visaMain.LargeVisaPrice,
  22637. LargeAgencyFee = visaMain.LargeAgencyFee,
  22638. IsVisaExemptionSmall = visaMain.IsVisaExemptionSmall ? "是" : "否",
  22639. SmallVisaPrice = visaMain.SmallVisaPrice,
  22640. SmallAgencyFee = visaMain.SmallAgencyFee,
  22641. NormExtFee = visaMain.NormExtFee,
  22642. UrgExtFee = visaMain.UrgExtFee,
  22643. IsUrgent = visaMain.IsUrgent ? "是" : "否",
  22644. UrgentTime = visaMain.UrgentTime,
  22645. UrgentPrice = visaMain.UrgentPrice,
  22646. UrgentPriceDesc = visaMain.UrgentPriceDesc,
  22647. Remark = visaMain.Remark,
  22648. }
  22649. });
  22650. }
  22651. }
  22652. catch (Exception ex)
  22653. {
  22654. //写入日志
  22655. _logger.LogError(ex, "团组成本解析签证异常!");
  22656. }
  22657. }
  22658. }
  22659. var groupChecks = _checkBoxs.GetCheckBoxsByDiid(diid); //团组选中信息 可枚举
  22660. var groupCost = _GroupCostRepository.GetAllByDiid(diid); //团组列表信息
  22661. #region 屏蔽黑屏代码生成
  22662. //var create = _GroupCostRepository.
  22663. // CreateGroupCostByBlackCode(dto.Diid);
  22664. //if (groupCost.Count == 0 && create.Code == 0)
  22665. //{
  22666. // groupCost = (create.Data as List<Grp_GroupCost>) ?? new List<Grp_GroupCost>();
  22667. //}
  22668. #endregion
  22669. var groupCostMap = _mapper.Map<List<Grp_GroupCostDto>>(groupCost);
  22670. var hotelNumber = _CostTypeHotelNumberRepository.GetCostTypeHotelNumberByDiid(diid); //酒店数量 可枚举
  22671. var GroupCostParameter = _GroupCostParameterRepository.GetGroupCostParameterListByDiid(diid); //成本系数 可枚举
  22672. groupCostMap = groupCostMap.Select(x =>
  22673. {
  22674. if (DateTime.TryParse(x.Date, out DateTime dataForamt))
  22675. {
  22676. x.Date = dataForamt.ToString("yyyy-MM-dd");
  22677. }
  22678. return x;
  22679. }).ToList();
  22680. //GroupCostParameter.Add(new
  22681. // Grp_GroupCostParameter());
  22682. var GroupCostParameterMap = _mapper.Map<List<Grp_GroupCostParameterDto>>(GroupCostParameter);
  22683. bool hotelIsTrue = _sqlSugar.Queryable<Grp_HotelInquiry>().Where(x => x.DiId == diid && x.IsDel == 0).Count() > 0;
  22684. var groupModuleOperators = GeneralMethod.GetGroupModuleOperators(diid);
  22685. return Ok(JsonView(new
  22686. {
  22687. groupList,
  22688. groupInfo,
  22689. groupChecks,
  22690. groupCost = groupCostMap,
  22691. hotelNumber,
  22692. GroupCostParameter = GroupCostParameterMap,
  22693. visaCountryInfoArr = visaCountryInfoArr,
  22694. baoPi = _GroupCostParameterRepository.GetBaoPi(diid),
  22695. blackCodeIsTrue = _sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && x.DiId == diid).Any(), //create.Code == 0 ? true : false,
  22696. hotelIsTrue,
  22697. groupModuleOperators
  22698. }));
  22699. }
  22700. /// <summary>
  22701. /// 团组成本信息保存
  22702. /// </summary>
  22703. /// <param name="dto"></param>
  22704. /// <returns></returns>
  22705. [HttpPost]
  22706. public async Task<IActionResult> SaveGroupCost(GroupCostSavaDto dto)
  22707. {
  22708. if (dto.Diid <= 0 || dto.Userid <= 0)
  22709. {
  22710. return Ok(JsonView(false));
  22711. }
  22712. JsonView jw = null;
  22713. bool isTrue = false;
  22714. #region 复制团组成本
  22715. //if (dto.Diid == 2581)
  22716. //{
  22717. // dto.Diid = 2599;
  22718. // dto.CheckBoxs.ForEach(x =>
  22719. // {
  22720. // x.Diid = 2599;
  22721. // });
  22722. // dto.GroupCosts.ForEach(x =>
  22723. // {
  22724. // x.Diid = 2599;
  22725. // });
  22726. // dto.CostTypeHotelNumbers.ForEach(x =>
  22727. // {
  22728. // x.Diid = 2599;
  22729. // });
  22730. // dto.GroupCostParameters.ForEach(x =>
  22731. // {
  22732. // x.DiId = 2599;
  22733. // });
  22734. //}
  22735. #endregion
  22736. var Grp_groups = _mapper.Map<List<Grp_GroupCost>>(dto.GroupCosts);
  22737. Grp_groups.ForEach(x => { x.CreateUserId = dto.Userid; x.CreateTime = DateTime.Now; }); //.ToString("yyyy-MM-dd HH:mm:ss")
  22738. var Grp_CheckBoxs = _mapper.Map<List<Grp_CheckBoxs>>(dto.CheckBoxs);
  22739. Grp_CheckBoxs.ForEach(x => { x.CreateUserId = dto.Userid; x.CreateTime = DateTime.Now; });
  22740. var Grp_HotelNumber = _mapper.Map<List<Grp_CostTypeHotelNumber>>(dto.CostTypeHotelNumbers);
  22741. var Grp_CostParameters = _mapper.Map<List<Grp_GroupCostParameter>>(dto.GroupCostParameters);
  22742. try
  22743. {
  22744. _sqlSugar.BeginTran();
  22745. isTrue = await _GroupCostRepository.
  22746. SaveGroupCostList(Grp_groups, dto.Diid, dto.Userid); //列表
  22747. isTrue = await _checkBoxs.SaveCheckBoxs(Grp_CheckBoxs, dto.Diid); //选中项
  22748. isTrue = await _CostTypeHotelNumberRepository.SaveHotelNumber(Grp_HotelNumber, dto.Userid, dto.Diid); //酒店房间数量
  22749. isTrue = await _GroupCostParameterRepository.SaveAsync(Grp_CostParameters, dto.Userid, dto.Diid); //系数
  22750. _sqlSugar.CommitTran();
  22751. jw = JsonView(true, "保存成功!", isTrue);
  22752. }
  22753. catch (Exception)
  22754. {
  22755. _sqlSugar.RollbackTran();
  22756. jw = JsonView(false);
  22757. }
  22758. return Ok(jw);
  22759. }
  22760. /// <summary>
  22761. /// 复制团组成本信息
  22762. /// </summary>
  22763. /// <param name="dto"></param>
  22764. /// <returns></returns>
  22765. [HttpPost]
  22766. public async Task<IActionResult> CopyGroupCost(CopyGroupCostDto dto)
  22767. {
  22768. if (dto.Diid <= 0 || dto.Userid <= 0 || dto.ToGroupId <= 0)
  22769. {
  22770. return Ok(JsonView(false, "参数有误!"));
  22771. }
  22772. #region 复制团组成本
  22773. dto.Diid = dto.ToGroupId;
  22774. dto.CheckBoxs.ForEach(x =>
  22775. {
  22776. x.Diid = dto.ToGroupId;
  22777. });
  22778. dto.GroupCosts.ForEach(x =>
  22779. {
  22780. x.Diid = dto.ToGroupId;
  22781. });
  22782. dto.CostTypeHotelNumbers.ForEach(x =>
  22783. {
  22784. x.Diid = dto.ToGroupId;
  22785. });
  22786. dto.GroupCostParameters.ForEach(x =>
  22787. {
  22788. x.DiId = dto.ToGroupId;
  22789. });
  22790. #endregion
  22791. JsonView jw = null;
  22792. bool isTrue = false;
  22793. var Grp_groups = _mapper.Map<List<Grp_GroupCost>>(dto.GroupCosts);
  22794. Grp_groups.ForEach(x => { x.CreateUserId = dto.Userid; x.CreateTime = DateTime.Now; }); //.ToString("yyyy-MM-dd HH:mm:ss")
  22795. var Grp_CheckBoxs = _mapper.Map<List<Grp_CheckBoxs>>(dto.CheckBoxs);
  22796. Grp_CheckBoxs.ForEach(x => { x.CreateUserId = dto.Userid; x.CreateTime = DateTime.Now; });
  22797. var Grp_HotelNumber = _mapper.Map<List<Grp_CostTypeHotelNumber>>(dto.CostTypeHotelNumbers);
  22798. var Grp_CostParameters = _mapper.Map<List<Grp_GroupCostParameter>>(dto.GroupCostParameters);
  22799. try
  22800. {
  22801. _sqlSugar.BeginTran();
  22802. isTrue = await _GroupCostRepository.
  22803. SaveGroupCostList(Grp_groups, dto.Diid, dto.Userid); //列表
  22804. isTrue = await _checkBoxs.SaveCheckBoxs(Grp_CheckBoxs, dto.Diid); //选中项
  22805. isTrue = await _CostTypeHotelNumberRepository.SaveHotelNumber(Grp_HotelNumber, dto.Userid, dto.Diid); //酒店房间数量
  22806. isTrue = await _GroupCostParameterRepository.SaveAsync(Grp_CostParameters, dto.Userid, dto.Diid); //系数
  22807. _sqlSugar.CommitTran();
  22808. jw = JsonView(true, "保存成功!", isTrue);
  22809. }
  22810. catch (Exception)
  22811. {
  22812. _sqlSugar.RollbackTran();
  22813. jw = JsonView(false);
  22814. }
  22815. return Ok(jw);
  22816. }
  22817. /// <summary>
  22818. /// 司兼导数据
  22819. /// </summary>
  22820. /// <param name="dto"></param>
  22821. /// <returns></returns>
  22822. [HttpPost]
  22823. public IActionResult GetCarGuides(CarGuidesDto dto)
  22824. {
  22825. var Data = _sqlSugar.SqlQueryable<Grp_CarGuides>($@" select * from Grp_CarGuides where isdel = 0 ").ToList();
  22826. return Ok(JsonView(true, "获取成功!", Data));
  22827. }
  22828. /// <summary>
  22829. /// 导游数据
  22830. /// </summary>
  22831. /// <param name="dto"></param>
  22832. /// <returns></returns>
  22833. [HttpPost]
  22834. public IActionResult GetGuidesInfo(CarGuidesDto dto)
  22835. {
  22836. //var Data = _sqlSugar.SqlQueryable<Grp_GuidesInfo>($@" SELECT* FROM (
  22837. // SELECT*,ROW_NUMBER() OVER (ORDER BY Id) AS RowNumber FROM Grp_GuidesInfo where (city like '%{dto.City}%' or country like '%{dto.City}%' ) and isdel = 0 ) as b
  22838. // where RowNumber BETWEEN {(dto.Page - 1) * dto.Size + 1} and {(dto.Page) * dto.Size}").ToList();
  22839. var Data = _sqlSugar.SqlQueryable<Grp_GuidesInfo>($@" select * from Grp_GuidesInfo where isdel = 0 ").ToList();
  22840. return Ok(JsonView(true, "获取成功!", Data));
  22841. }
  22842. /// <summary>
  22843. /// 成本车数据
  22844. /// </summary>
  22845. /// <param name="dto"></param>
  22846. /// <returns></returns>
  22847. [HttpPost]
  22848. public IActionResult GetCarInfo(CarGuidesDto dto)
  22849. {
  22850. var Data = _sqlSugar.SqlQueryable<Grp_CarInfo>($@" select * from Grp_CarInfo where isdel = 0 ").ToList();
  22851. return Ok(JsonView(true, "获取成功!", Data));
  22852. }
  22853. /// <summary>
  22854. /// 景点数据
  22855. /// </summary>
  22856. /// <param name="dto"></param>
  22857. /// <returns></returns>
  22858. [HttpPost]
  22859. public IActionResult GetScenicSpotInfo(CarGuidesDto dto)
  22860. {
  22861. var Data = _sqlSugar.SqlQueryable<Grp_ScenicSpotInfo>($@" select * from Grp_ScenicSpotInfo where isdel = 0 ").ToList();
  22862. return Ok(JsonView(true, "获取成功!", Data));
  22863. }
  22864. /// <summary>
  22865. /// 成本通知
  22866. /// </summary>
  22867. /// <param name="dto"></param>
  22868. /// <returns></returns>
  22869. [HttpPost]
  22870. public async Task<IActionResult> GroupIsShare(GroupIsShareDto dto)
  22871. {
  22872. if (dto.Diid < 0)
  22873. {
  22874. return Ok(JsonView(false));
  22875. }
  22876. JsonView jw;
  22877. var GroupCostParameter = _GroupCostParameterRepository.GetGroupCostParameterMainByDiid(dto.Diid);
  22878. if (GroupCostParameter != null)
  22879. {
  22880. int IsShare = 0;
  22881. if (GroupCostParameter.IsShare == 0) IsShare = 1;
  22882. else if (GroupCostParameter.IsShare == 1) IsShare = 0;
  22883. bool isTrue = await _GroupCostParameterRepository.UpdateIsShareById(GroupCostParameter.Id, IsShare);
  22884. string msg = string.Empty;
  22885. if (isTrue)
  22886. {
  22887. if (IsShare == 0)
  22888. {
  22889. msg = "禁止通知,其他模块操作人员不可见此成本信息!";
  22890. }
  22891. else
  22892. {
  22893. #region 企微通知对应岗位用户
  22894. try
  22895. {
  22896. await AppNoticeLibrary.SendUserMsg_GroupShare_ToJob(dto.Diid);
  22897. //机票预算群通知
  22898. await AppNoticeLibrary.SendChatMsg_AirCostChat(dto.Diid, QiyeWeChatEnum.AirCostChat01);
  22899. }
  22900. catch (Exception)
  22901. {
  22902. }
  22903. #endregion
  22904. msg = "通知成功,其他模块操作人员可见此成本信息!";
  22905. }
  22906. jw = JsonView(isTrue, msg, new { IsShare });
  22907. }
  22908. else
  22909. {
  22910. msg = "修改失败!";
  22911. jw = JsonView(isTrue, msg);
  22912. }
  22913. }
  22914. else
  22915. {
  22916. jw = JsonView(false, "该团没有数据,请添加数据,保存后再操作!");
  22917. }
  22918. return Ok(jw);
  22919. }
  22920. /// <summary>
  22921. /// 导出报价单
  22922. /// </summary>
  22923. /// <param name="dto"></param>
  22924. /// <returns></returns>
  22925. [HttpPost]
  22926. public async Task<IActionResult> ExportPriceCheckWordFile(GroupCostExportWordFile dto)
  22927. {
  22928. if (dto.Diid == 0)
  22929. {
  22930. return Ok(JsonView(false, "请传递团组id"));
  22931. }
  22932. var deleInfo = await _groupRepository.PostGroupInfo(new GroupInfoDto { Id = dto.Diid, PortType = 1 });
  22933. if (deleInfo.Code != 0)
  22934. {
  22935. return Ok(JsonView(false, "团组信息查询失败!"));
  22936. }
  22937. var di = deleInfo.Data as DelegationInfoWebView;
  22938. if (di != null)
  22939. {
  22940. di.TeamName = di.TeamName.Replace("|", "、");
  22941. di.VisitCountry = di.VisitCountry.Replace("|", "、");
  22942. //文件名
  22943. string strFileName = di.TeamName + "-收款账单.doc";
  22944. //获取模板
  22945. string tmppath = (AppSettingsHelper.Get("WordBasePath") + "Template/收款账单(四川)模板.doc");
  22946. //载入模板
  22947. Document doc = new Document(tmppath);
  22948. decimal TotalPrice = 0.00M;
  22949. string itemStr = string.Empty;
  22950. Dictionary<string, string> airSouer = new Dictionary<string, string>();
  22951. //airSouer.Add("JJCTBR", "经济舱及酒店双人间");
  22952. airSouer.Add("JJCTBR", "经济舱及酒店双人间");
  22953. airSouer.Add("JJCSGR", "经济舱及酒店单人间");
  22954. airSouer.Add("GWCSGR", "公务舱及酒店单人间");
  22955. airSouer.Add("GWCJSES", "公务舱及酒店小套房");
  22956. airSouer.Add("GWCSUITE", "公务舱及酒店套房");
  22957. airSouer.Add("JJCSUITE", "经济舱及酒店套房");
  22958. var groupCostType = dto.airs.GroupBy(x => x.costType).OrderBy(x => x.Key);
  22959. foreach (var cost in groupCostType)
  22960. {
  22961. var List = cost.ToList();
  22962. if (cost.Key == "A")
  22963. {
  22964. foreach (var ListItem in List)
  22965. {
  22966. if (ListItem.number > 0)
  22967. {
  22968. if (ListItem.code.Contains("TBR"))
  22969. {
  22970. itemStr += "团费(" + airSouer[ListItem.code] + ") RMB " + ListItem.price.ToString("F2") + "/人*" + ListItem.number + "(" + (ListItem.number / 2) + "间) ............合计 RMB " + (ListItem.number * ListItem.price).ToString("#0.00") + "\n";
  22971. }
  22972. else
  22973. {
  22974. itemStr += "团费(" + airSouer[ListItem.code] + ") RMB " + ListItem.price.ToString("F2") + "/人*" + ListItem.number + "(" + ListItem.number + "间) ............合计 RMB " + (ListItem.number * ListItem.price).ToString("#0.00") + "\n";
  22975. }
  22976. TotalPrice += (ListItem.number * ListItem.price);
  22977. }
  22978. }
  22979. }
  22980. else
  22981. {
  22982. itemStr = itemStr.Insert(0, "A段\r\n");
  22983. itemStr += "B段\r\n";
  22984. foreach (var ListItem in List)
  22985. {
  22986. if (ListItem.number > 0)
  22987. {
  22988. if (ListItem.code.Contains("TBR"))
  22989. {
  22990. itemStr += "团费(" + airSouer[ListItem.code] + ") RMB " + ListItem.price.ToString("F2") + "/人*" + ListItem.number + "(" + (ListItem.number / 2) + "间) ............合计 RMB " + (ListItem.number * ListItem.price).ToString("#0.00") + "\n";
  22991. }
  22992. else
  22993. {
  22994. itemStr += "团费(" + airSouer[ListItem.code] + ") RMB " + ListItem.price.ToString("F2") + "/人*" + ListItem.number + "(" + ListItem.number + "间) ............合计 RMB " + (ListItem.number * ListItem.price).ToString("#0.00") + "\n";
  22995. }
  22996. TotalPrice += (ListItem.number * ListItem.price);
  22997. }
  22998. }
  22999. }
  23000. }
  23001. #region 替换Word模板书签内容
  23002. Dictionary<string, string> marks = new Dictionary<string, string>();
  23003. marks.Add("To", di.ClientUnit);//付款方
  23004. marks.Add("ToTel", di.TellPhone);//付款方电话
  23005. marks.Add("Date", DateTime.Now.ToString("yyyy-MM-dd"));//导出时间
  23006. marks.Add("Team", di.VisitCountry.Replace(" ", "、"));//团队名称
  23007. marks.Add("TontractTime", (di.VisitDate).ToString("yyyy年MM月dd日"));//付款日期
  23008. marks.Add("PayDay", (di.PayDay).ToString());//付款预期
  23009. marks.Add("PaymentMoney", (di.PaymentMoney).ToString("#0.00"));//付款金额
  23010. marks.Add("WeChat", di.WeChatNo ?? "");//微信号
  23011. marks.Add("PayItemContent", itemStr);//详细信息
  23012. marks.Add("Total", TotalPrice.ToString("F2"));//合计
  23013. #endregion
  23014. ////注
  23015. //if (doc.Range.Bookmarks["Attention"] != null)
  23016. //{
  23017. // Bookmark mark = doc.Range.Bookmarks["Attention"];
  23018. // mark.Text = frList[0].Attention;
  23019. //}
  23020. foreach (var item in marks.Keys)
  23021. {
  23022. if (doc.Range.Bookmarks[item] != null)
  23023. {
  23024. Bookmark mark = doc.Range.Bookmarks[item];
  23025. mark.Text = marks[item];
  23026. }
  23027. }
  23028. byte[] bytes = null;
  23029. using (MemoryStream stream = new MemoryStream())
  23030. {
  23031. doc.Save(stream, Aspose.Words.SaveFormat.Doc);
  23032. bytes = stream.ToArray();
  23033. }
  23034. //doc.Save((AppSettingsHelper.Get("WordBasePath") + "Template/") + strFileName);
  23035. return Ok(JsonView(true, "", new
  23036. {
  23037. Data = bytes,
  23038. strFileName,
  23039. }));
  23040. }
  23041. else
  23042. {
  23043. return Ok(JsonView(false, "团组信息不存在!"));
  23044. }
  23045. }
  23046. /// <summary>
  23047. /// 导出团组成本
  23048. /// </summary>
  23049. /// <param name="dto"></param>
  23050. /// <returns></returns>
  23051. [HttpPost]
  23052. public async Task<IActionResult> ExportGroupCostExcelFile(GroupCostExportExcelFile dto)
  23053. {
  23054. var jw = JsonView(false);
  23055. if (dto.Diid == 0)
  23056. {
  23057. return Ok(JsonView(false, "请传递团组id"));
  23058. }
  23059. var deleInfo = await _groupRepository.PostGroupInfo(new GroupInfoDto { Id = dto.Diid, PortType = 1 });
  23060. if (deleInfo.Code != 0)
  23061. {
  23062. return Ok(JsonView(false, "团组信息查询失败!"));
  23063. }
  23064. var di = deleInfo.Data as DelegationInfoWebView;
  23065. if (di == null)
  23066. {
  23067. return Ok(JsonView(false, "团组信息查询失败!"));
  23068. }
  23069. List<GroupCost_Excel> List_GC1 = new List<GroupCost_Excel>();
  23070. WorkbookDesigner designer = new WorkbookDesigner();
  23071. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + ("Template/团组-成本.xls"));
  23072. var List_GC = _GroupCostRepository.GetAllByDiid(dto.Diid);
  23073. List<int> hideColumnList = new List<int>();
  23074. var ColumnSetting = new[]
  23075. {
  23076. new { tag = "VF", Index = 4, P = "CarCost" },
  23077. new { tag = "VN", Index = 5, P = "CarNumber" },
  23078. new { tag = "VRD", Index = 6, P = "CarTiming" },
  23079. new { tag = "T/G S", Index = 7, P = "TGS" },
  23080. new { tag = "TGWH", Index = 8, P = "TGWH" },
  23081. new { tag = "T/G OF", Index = 9, P = "TGOF" },
  23082. new { tag = "T/G M", Index = 10, P = "TGM" },
  23083. new { tag = "T/G A", Index = 11, P = "TGA" },
  23084. new { tag = "T/G TF", Index = 12, P = "TGTF" },
  23085. new { tag = "T/G EF", Index = 13, P = "TGEF" },
  23086. new { tag = "C/F S", Index = 14, P = "CFS" },
  23087. new { tag = "C/F M", Index = 15, P = "CFM" },
  23088. new { tag = "C/F OF", Index = 16, P = "CFOF" },
  23089. new { tag = "B", Index = 17, P = "B" },
  23090. new { tag = "L", Index = 18, P = "L" },
  23091. new { tag = "D", Index = 19, P = "D" },
  23092. new { tag = "TBR", Index = 20, P = "TBR" },
  23093. new { tag = "SGR", Index = 21, P = "SGR" },
  23094. new { tag = "JS/ES", Index = 22, P = "JS_ES" },
  23095. new { tag = "Suite", Index = 23, P = "Suite" },
  23096. new { tag = "ACCO N", Index = 24, P = "ACCON" },
  23097. new { tag = "T/V", Index = 25, P = "TV" },
  23098. new { tag = "1/L", Index = 26, P = "iL" },
  23099. new { tag = "I/F", Index = 27, P = "IF" },
  23100. new { tag = "EF", Index = 28, P = "EF" },
  23101. new { tag = "B/R/F", Index = 29, P = "B_R_F" },
  23102. new { tag = "TE", Index = 30, P = "TE" },
  23103. new { tag = "T/G T", Index = 31, P = "TGTips" },
  23104. new { tag = "DRV T", Index = 32, P = "DRVTips" },
  23105. new { tag = "P/C", Index = 33, P = "PC" },
  23106. new { tag = "T/L F", Index = 34, P = "TLF" },
  23107. new { tag = "E/C T", Index = 35, P = "ECT" }
  23108. };
  23109. Func<string, bool> isEmpty = (str) =>
  23110. {
  23111. if (decimal.TryParse(str, out decimal str_De) && str_De == 0)
  23112. {
  23113. return true;
  23114. }
  23115. if (string.IsNullOrWhiteSpace(str))
  23116. {
  23117. return true;
  23118. }
  23119. return false;
  23120. };
  23121. for (int i = 0; i < List_GC.Count; i++)
  23122. {
  23123. GroupCost_Excel gc = new GroupCost_Excel();
  23124. gc.Id = List_GC[i].Id;
  23125. gc.Diid = List_GC[i].Diid.ToString();
  23126. gc.DAY = List_GC[i].DAY;
  23127. string week = "";
  23128. if (!string.IsNullOrEmpty(List_GC[i].Date.Trim()))
  23129. week = CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(Convert.ToDateTime(List_GC[i].Date).DayOfWeek);
  23130. gc.Date = (List_GC[i].Date + "\n" + week).ToString();
  23131. gc.ITIN = List_GC[i].ITIN;
  23132. gc.CarType = List_GC[i].CarType;
  23133. gc.CarTiming = isEmpty(List_GC[i].CarTiming.ToString()) ? "" : List_GC[i].CarTiming.ToString();
  23134. gc.CarCost = isEmpty(List_GC[i].CarCost.ToString()) ? "" : List_GC[i].CarCost.ToString();
  23135. gc.CarNumber = isEmpty(List_GC[i].CarNumber.ToString()) ? "" : List_GC[i].CarNumber.ToString();
  23136. gc.TGS = isEmpty(List_GC[i].TGS.ToString()) ? "" : List_GC[i].TGS.ToString();
  23137. gc.TGWH = isEmpty(List_GC[i].TGWH.ToString()) ? "" : List_GC[i].TGWH.ToString();
  23138. gc.TGN = isEmpty(List_GC[i].TGN.ToString()) ? "" : List_GC[i].TGN.ToString();
  23139. gc.TGOF = isEmpty(List_GC[i].TGOF.ToString()) ? "" : List_GC[i].TGOF.ToString();
  23140. gc.TGM = isEmpty(List_GC[i].TGM.ToString()) ? "" : List_GC[i].TGM.ToString();
  23141. gc.TGA = isEmpty(List_GC[i].TGA.ToString()) ? "" : List_GC[i].TGA.ToString();
  23142. gc.TGTF = isEmpty(List_GC[i].TGTF.ToString()) ? "" : List_GC[i].TGTF.ToString();
  23143. gc.TGEF = isEmpty(List_GC[i].TGEF.ToString()) ? "" : List_GC[i].TGEF.ToString();
  23144. gc.CFS = isEmpty(List_GC[i].CFS.ToString()) ? "" : List_GC[i].CFS.ToString();
  23145. gc.CFM = isEmpty(List_GC[i].CFM.ToString()) ? "" : List_GC[i].CFM.ToString();
  23146. gc.CFOF = isEmpty(List_GC[i].CFOF.ToString()) ? "" : List_GC[i].CFOF.ToString();
  23147. gc.B = isEmpty(List_GC[i].B.ToString()) ? "" : List_GC[i].B.ToString();
  23148. gc.L = isEmpty(List_GC[i].L.ToString()) ? "" : List_GC[i].L.ToString();
  23149. gc.D = isEmpty(List_GC[i].D.ToString()) ? "" : List_GC[i].D.ToString();
  23150. gc.TBR = isEmpty(List_GC[i].TBR.ToString()) ? "" : List_GC[i].TBR.ToString();
  23151. gc.SGR = isEmpty(List_GC[i].SGR.ToString()) ? "" : List_GC[i].SGR.ToString();
  23152. gc.JS_ES = isEmpty(List_GC[i].JS_ES.ToString()) ? "" : List_GC[i].JS_ES.ToString();
  23153. gc.Suite = isEmpty(List_GC[i].Suite.ToString()) ? "" : List_GC[i].Suite.ToString();
  23154. gc.ACCON = isEmpty(List_GC[i].ACCON.ToString()) ? "" : List_GC[i].ACCON.ToString();
  23155. gc.TV = isEmpty(List_GC[i].TV.ToString()) ? "" : List_GC[i].TV.ToString();
  23156. gc.iL = isEmpty(List_GC[i].iL.ToString()) ? "" : List_GC[i].iL.ToString();
  23157. gc.IF = isEmpty(List_GC[i].IF.ToString()) ? "" : List_GC[i].IF.ToString();
  23158. gc.EF = isEmpty(List_GC[i].EF.ToString()) ? "" : List_GC[i].EF.ToString();
  23159. gc.B_R_F = isEmpty(List_GC[i].B_R_F.ToString()) ? "" : List_GC[i].B_R_F.ToString();
  23160. gc.TE = isEmpty(List_GC[i].TE.ToString()) ? "" : List_GC[i].TE.ToString();
  23161. gc.TGTips = isEmpty(List_GC[i].TGTips.ToString()) ? "" : List_GC[i].TGTips.ToString();
  23162. gc.DRVTips = isEmpty(List_GC[i].DRVTips.ToString()) ? "" : List_GC[i].DRVTips.ToString();
  23163. gc.PC = isEmpty(List_GC[i].PC.ToString()) ? "" : List_GC[i].PC.ToString();
  23164. gc.TLF = isEmpty(List_GC[i].TLF.ToString()) ? "" : List_GC[i].TLF.ToString();
  23165. gc.ECT = isEmpty(List_GC[i].ECT.ToString()) ? "" : List_GC[i].ECT.ToString();
  23166. gc.EFR = List_GC[i].EFR;
  23167. List_GC1.Add(gc);
  23168. }
  23169. if (List_GC1.Count > 0)
  23170. {
  23171. var p = List_GC1[0];
  23172. var prs = p.GetType().GetProperties();
  23173. foreach (var item in prs)
  23174. {
  23175. var tp = item.PropertyType;
  23176. if (tp == typeof(int))
  23177. {
  23178. var val = List_GC1.Sum(x =>
  23179. {
  23180. var raw = x.GetType().GetProperty(item.Name).GetValue(x);
  23181. return raw == null ? 0 : (int)raw;
  23182. });
  23183. if (val == 0)
  23184. {
  23185. var columnSetting = ColumnSetting.FirstOrDefault(x => x.P == item.Name);
  23186. if (columnSetting != null)
  23187. {
  23188. hideColumnList.Add(columnSetting.Index);
  23189. }
  23190. }
  23191. }
  23192. if (tp == typeof(decimal))
  23193. {
  23194. var val = List_GC1.Sum(x =>
  23195. {
  23196. var raw = x.GetType().GetProperty(item.Name).GetValue(x);
  23197. return raw == null ? 0m : (decimal)raw;
  23198. });
  23199. if (val == 0)
  23200. {
  23201. var columnSetting = ColumnSetting.FirstOrDefault(x => x.P == item.Name);
  23202. if (columnSetting != null)
  23203. {
  23204. hideColumnList.Add(columnSetting.Index);
  23205. }
  23206. }
  23207. }
  23208. if (tp == typeof(string))
  23209. {
  23210. var val = List_GC1.Sum(x =>
  23211. {
  23212. var str = (string)x.GetType().GetProperty(item.Name).GetValue(x);
  23213. if (decimal.TryParse(str, out decimal str_De))
  23214. {
  23215. return str_De;
  23216. }
  23217. else
  23218. {
  23219. return string.IsNullOrEmpty((string)x.GetType().GetProperty(item.Name).GetValue(x)) ? 0 : 1;
  23220. }
  23221. });
  23222. if (val == 0)
  23223. {
  23224. var columnSetting = ColumnSetting.FirstOrDefault(x => x.P == item.Name);
  23225. if (columnSetting != null)
  23226. {
  23227. hideColumnList.Add(columnSetting.Index);
  23228. }
  23229. }
  23230. }
  23231. }
  23232. }
  23233. var dt = CommonFun.GetDataTableFromIList(List_GC1);
  23234. dt.TableName = "TB";
  23235. //报表标题等不用dt的值
  23236. designer.SetDataSource("TeamName", dto.title.TeamName);
  23237. designer.SetDataSource("Pnumber", dto.title.GroupNumber);
  23238. designer.SetDataSource("Tax", dto.title.Tax);
  23239. //designer.SetDataSource("FFYS", lblHotelCB.Text);
  23240. designer.SetDataSource("Currency", dto.title.Currency);
  23241. //designer.SetDataSource("HotelXS", txtHotelXS.Text);
  23242. designer.SetDataSource("Rate", dto.title.Rate);
  23243. var hotels = _CostTypeHotelNumberRepository.GetCostTypeHotelNumberByDiid(dto.Diid);
  23244. var Aparams = hotels.Find(x => x.Type == "Default");
  23245. if (Aparams == null)
  23246. {
  23247. return Ok(jw);
  23248. }
  23249. //酒店数量
  23250. var txtSGRNumber = Aparams.SGR.ToString();
  23251. var txtTBRNumber = Aparams.TBR.ToString();
  23252. var txtJSESNumber = Aparams.JSES.ToString();
  23253. var txtSUITENumbe = Aparams.SUITE.ToString();
  23254. if (dto.costType == "B")
  23255. {
  23256. Aparams = hotels.Find(x => x.Type == "A");
  23257. var Bparams = hotels.Find(x => x.Type == "B");
  23258. if (Aparams == null || Bparams == null)
  23259. {
  23260. return Ok(jw);
  23261. }
  23262. txtSGRNumber = "A段人数:" + Aparams.SGR.ToString() + " B段人数:" + Bparams.SGR.ToString();
  23263. txtTBRNumber = "A段人数:" + Aparams.TBR.ToString() + " B段人数:" + Bparams.TBR.ToString();
  23264. txtJSESNumber = "A段人数:" + Aparams.JSES.ToString() + " B段人数:" + Bparams.JSES.ToString();
  23265. txtSUITENumbe = "A段人数:" + Aparams.SUITE.ToString() + " B段人数:" + Bparams.SUITE.ToString();
  23266. }
  23267. designer.SetDataSource("SGRNumber", txtSGRNumber);
  23268. designer.SetDataSource("TBRNumber", txtTBRNumber);
  23269. designer.SetDataSource("JSESNumber", txtJSESNumber);
  23270. designer.SetDataSource("SUITENumber", txtSUITENumbe);
  23271. var ws = designer.Workbook.Worksheets[1];
  23272. int Row = List_GC.Count;
  23273. int startIndex = 0;
  23274. int HideRows = 0;
  23275. Row = 0;
  23276. List<int> hideRowsList = new List<int>();
  23277. decimal TzZCB2 = 0.00M, TzZLR2 = 0.00M, TzZBJ2 = 0.00M;
  23278. #region A段left数据
  23279. var left = dto.leftInfo.Find(x => x.Type == "A");
  23280. if (left == null)
  23281. {
  23282. return Ok(jw);
  23283. }
  23284. var leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("签证"));
  23285. if (leftBindData != null)
  23286. {
  23287. designer.SetDataSource("VisaDRCB", leftBindData.cb);
  23288. designer.SetDataSource("VisaRS", leftBindData.rs);
  23289. designer.SetDataSource("VisaXS", leftBindData.xs);
  23290. designer.SetDataSource("VisaZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23291. designer.SetDataSource("VisaDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23292. designer.SetDataSource("VisaZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23293. designer.SetDataSource("VisaDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23294. designer.SetDataSource("VisaZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23295. }
  23296. else
  23297. {
  23298. hideRowsList.Add(Row + startIndex + HideRows);
  23299. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  23300. }
  23301. HideRows += 2;
  23302. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("保险"));
  23303. if (leftBindData != null)
  23304. {
  23305. designer.SetDataSource("BXDRCB", leftBindData.cb);
  23306. designer.SetDataSource("BXRS", leftBindData.rs);
  23307. designer.SetDataSource("BXXS", leftBindData.xs);
  23308. designer.SetDataSource("BXZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23309. designer.SetDataSource("BXDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23310. designer.SetDataSource("BXZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23311. designer.SetDataSource("BXDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23312. designer.SetDataSource("BXZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23313. }
  23314. else
  23315. {
  23316. hideRowsList.Add(Row + startIndex + HideRows);
  23317. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  23318. }
  23319. HideRows += 2;
  23320. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("核酸"));
  23321. if (leftBindData != null)
  23322. {
  23323. designer.SetDataSource("HSDRCB", leftBindData.cb);
  23324. designer.SetDataSource("HSRS", leftBindData.rs);
  23325. designer.SetDataSource("HSXS", leftBindData.xs);
  23326. designer.SetDataSource("HSZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23327. designer.SetDataSource("HSDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23328. designer.SetDataSource("HSZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23329. designer.SetDataSource("HSDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23330. designer.SetDataSource("HSZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23331. }
  23332. else
  23333. {
  23334. hideRowsList.Add(Row + startIndex + HideRows);
  23335. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  23336. }
  23337. HideRows += 2;
  23338. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("经济舱"));
  23339. if (leftBindData != null)
  23340. {
  23341. designer.SetDataSource("JPJJCCB", leftBindData.cb);
  23342. designer.SetDataSource("JPJJCPnum", leftBindData.rs);
  23343. designer.SetDataSource("JPJJCXS", leftBindData.xs);
  23344. designer.SetDataSource("JPJJCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23345. designer.SetDataSource("JPJJCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23346. designer.SetDataSource("JPJJCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23347. designer.SetDataSource("JPJJCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23348. designer.SetDataSource("JPJJCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23349. }
  23350. else
  23351. {
  23352. hideRowsList.Add(Row + startIndex + HideRows);
  23353. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  23354. }
  23355. HideRows += 2;
  23356. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("公务舱"));
  23357. if (leftBindData != null)
  23358. {
  23359. designer.SetDataSource("JPGWCCB", leftBindData.cb);
  23360. designer.SetDataSource("JPGWCPNum", leftBindData.rs);
  23361. designer.SetDataSource("JPGWCXS", leftBindData.xs);
  23362. designer.SetDataSource("JPGWCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23363. designer.SetDataSource("JPGWCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23364. designer.SetDataSource("JPGWCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23365. designer.SetDataSource("JPGWCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23366. designer.SetDataSource("JPGWCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23367. }
  23368. else
  23369. {
  23370. hideRowsList.Add(Row + startIndex + HideRows);
  23371. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  23372. }
  23373. HideRows += 2;
  23374. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("头等舱"));
  23375. if (leftBindData != null)
  23376. {
  23377. designer.SetDataSource("JPTDCCB", leftBindData.cb);
  23378. designer.SetDataSource("JPTDCPNum", leftBindData.rs);
  23379. designer.SetDataSource("JPTDCXS", leftBindData.xs);
  23380. designer.SetDataSource("JPTDCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23381. designer.SetDataSource("JPTDCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23382. designer.SetDataSource("JPTDCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23383. designer.SetDataSource("JPTDCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23384. designer.SetDataSource("JPTDCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23385. }
  23386. else
  23387. {
  23388. hideRowsList.Add(Row + startIndex + HideRows);
  23389. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  23390. }
  23391. HideRows += 2;
  23392. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("TBR"));
  23393. if (leftBindData != null)
  23394. {
  23395. ////TBR
  23396. designer.SetDataSource("HotelTBRDRCB", leftBindData.cb);
  23397. designer.SetDataSource("HotelTBRRS", leftBindData.rs);
  23398. designer.SetDataSource("HotelTBRXS", leftBindData.xs);
  23399. designer.SetDataSource("HotelTBRCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23400. designer.SetDataSource("HotelTBRDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23401. designer.SetDataSource("HotelTBRZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23402. designer.SetDataSource("HotelTBRDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23403. designer.SetDataSource("HotelTBRZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23404. }
  23405. else
  23406. {
  23407. hideRowsList.Add(Row + startIndex + HideRows);
  23408. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  23409. }
  23410. HideRows += 2;
  23411. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("SGR"));
  23412. if (leftBindData != null)
  23413. {
  23414. ////SGR
  23415. designer.SetDataSource("HotelSGRDRCB", leftBindData.cb);
  23416. designer.SetDataSource("HotelSGRRS", leftBindData.rs);
  23417. designer.SetDataSource("HotelSGRXS", leftBindData.xs);
  23418. designer.SetDataSource("HotelSGRCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23419. designer.SetDataSource("HotelSGRDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23420. designer.SetDataSource("HotelSGRZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23421. designer.SetDataSource("HotelSGRDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23422. designer.SetDataSource("HotelSGRZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23423. }
  23424. else
  23425. {
  23426. hideRowsList.Add(Row + startIndex + HideRows);
  23427. // ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  23428. }
  23429. HideRows += 2;
  23430. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("JSES"));
  23431. if (leftBindData != null)
  23432. {
  23433. ////JS/ES
  23434. designer.SetDataSource("HotelJSESDRCB", leftBindData.cb);
  23435. designer.SetDataSource("HotelJSESRS", leftBindData.rs);
  23436. designer.SetDataSource("HotelJSESXS", leftBindData.xs);
  23437. designer.SetDataSource("HotelJSESCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23438. designer.SetDataSource("HotelJSESDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23439. designer.SetDataSource("HotelJSESZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23440. designer.SetDataSource("HotelJSESDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23441. designer.SetDataSource("HotelJSESZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23442. }
  23443. else
  23444. {
  23445. hideRowsList.Add(Row + startIndex + HideRows);
  23446. // ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  23447. }
  23448. HideRows += 2;
  23449. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("SUITE"));
  23450. if (leftBindData != null)
  23451. {
  23452. ////SUITE
  23453. designer.SetDataSource("HotelSUITEDRCB", leftBindData.cb);
  23454. designer.SetDataSource("HotelSUITERS", leftBindData.rs);
  23455. designer.SetDataSource("HotelSUITEXS", leftBindData.xs);
  23456. designer.SetDataSource("HotelSUITECB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23457. designer.SetDataSource("HotelSUITEDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23458. designer.SetDataSource("HotelSUITEZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23459. designer.SetDataSource("HotelSUITEDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23460. designer.SetDataSource("HotelSUITEZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23461. }
  23462. else
  23463. {
  23464. hideRowsList.Add(Row + startIndex + HideRows);
  23465. // ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  23466. }
  23467. HideRows += 2;
  23468. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("地接"));
  23469. if (leftBindData != null)
  23470. {
  23471. designer.SetDataSource("DJDRCB", leftBindData.cb);
  23472. designer.SetDataSource("DJRS", leftBindData.rs);
  23473. designer.SetDataSource("DJXS", leftBindData.xs);
  23474. designer.SetDataSource("DJCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23475. designer.SetDataSource("DJDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23476. designer.SetDataSource("DJZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23477. designer.SetDataSource("DJDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23478. designer.SetDataSource("DJZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23479. }
  23480. else
  23481. {
  23482. hideRowsList.Add(Row + startIndex + HideRows);
  23483. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  23484. }
  23485. HideRows += 2;
  23486. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("火车票"));
  23487. if (leftBindData != null)
  23488. {
  23489. designer.SetDataSource("HCPCB", leftBindData.cb);
  23490. designer.SetDataSource("HCPRS", leftBindData.rs);
  23491. designer.SetDataSource("HCPXS", leftBindData.xs);
  23492. designer.SetDataSource("HCPZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23493. designer.SetDataSource("HCPDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23494. designer.SetDataSource("HCPZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23495. designer.SetDataSource("HCPDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23496. designer.SetDataSource("HCPZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23497. }
  23498. else
  23499. {
  23500. hideRowsList.Add(Row + startIndex + HideRows);
  23501. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  23502. }
  23503. HideRows += 2;
  23504. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("船票"));
  23505. if (leftBindData != null)
  23506. {
  23507. designer.SetDataSource("CPCB", leftBindData.cb);
  23508. designer.SetDataSource("CPRS", leftBindData.rs);
  23509. designer.SetDataSource("CPXS", leftBindData.xs);
  23510. designer.SetDataSource("CPZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23511. designer.SetDataSource("CPDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23512. designer.SetDataSource("CPZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23513. designer.SetDataSource("CPDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23514. designer.SetDataSource("CPZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23515. }
  23516. else
  23517. {
  23518. hideRowsList.Add(Row + startIndex + HideRows);
  23519. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  23520. }
  23521. HideRows += 2;
  23522. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("公务单人"));
  23523. if (leftBindData != null)
  23524. {
  23525. designer.SetDataSource("GWDRCD", leftBindData.cb);
  23526. designer.SetDataSource("GWRS", leftBindData.rs);
  23527. designer.SetDataSource("GWXS", leftBindData.xs);
  23528. designer.SetDataSource("GWCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23529. designer.SetDataSource("GWDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23530. designer.SetDataSource("GWZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23531. designer.SetDataSource("GWDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23532. designer.SetDataSource("GWZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23533. }
  23534. else
  23535. {
  23536. hideRowsList.Add(Row + startIndex + HideRows);
  23537. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  23538. }
  23539. HideRows += 2;
  23540. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("零用金"));
  23541. if (leftBindData != null)
  23542. {
  23543. designer.SetDataSource("LYJDRCB", leftBindData.cb);
  23544. designer.SetDataSource("LYJRS", leftBindData.rs);
  23545. designer.SetDataSource("LYJXS", leftBindData.xs);
  23546. designer.SetDataSource("LYJCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23547. designer.SetDataSource("LYJDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23548. designer.SetDataSource("LYJZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23549. designer.SetDataSource("LYJDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23550. designer.SetDataSource("LYJZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23551. }
  23552. else
  23553. {
  23554. hideRowsList.Add(Row + startIndex + HideRows);
  23555. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  23556. }
  23557. #endregion
  23558. #region A段Right信息
  23559. var right = dto.rightInfo.Find(x => x.Type == "A");
  23560. if (right == null)
  23561. {
  23562. return Ok(jw);
  23563. }
  23564. HideRows += 4;
  23565. var rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 TBR"));
  23566. if (rightBindData != null)
  23567. {
  23568. //经济舱 + 双人间 TBR
  23569. designer.SetDataSource("lblJJCTBRDRCB", rightBindData.cb);
  23570. designer.SetDataSource("txtJJCTBRRS", rightBindData.rs);
  23571. designer.SetDataSource("lblJJCTBRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  23572. designer.SetDataSource("lblJJCTBRDRBJ", rightBindData.bj);
  23573. designer.SetDataSource("lblJJCTBRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  23574. designer.SetDataSource("lblJJCTBRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  23575. designer.SetDataSource("lblJJCTBRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  23576. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  23577. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  23578. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  23579. }
  23580. else
  23581. {
  23582. hideRowsList.Add(Row + startIndex + HideRows);
  23583. }
  23584. HideRows += 2;
  23585. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 SGR"));
  23586. if (rightBindData != null)
  23587. {
  23588. //经济舱 + 单人间 SGR
  23589. designer.SetDataSource("lblJJCSGRDRCB", rightBindData.cb);
  23590. designer.SetDataSource("txtJJCSGRRS", rightBindData.rs);
  23591. designer.SetDataSource("lblJJCSGRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  23592. designer.SetDataSource("lblJJCSGRDRBJ", rightBindData.bj);
  23593. designer.SetDataSource("lblJJCSGRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  23594. designer.SetDataSource("lblJJCSGRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  23595. designer.SetDataSource("lblJJCSGRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  23596. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  23597. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  23598. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  23599. }
  23600. else
  23601. {
  23602. hideRowsList.Add(Row + startIndex + HideRows);
  23603. }
  23604. HideRows += 2;
  23605. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 SGR"));
  23606. if (rightBindData != null)
  23607. {
  23608. //公务舱 + 单人间 SGR
  23609. designer.SetDataSource("lblGWCSGRCB", rightBindData.cb);
  23610. designer.SetDataSource("lblGWCSGRRS", rightBindData.rs);
  23611. designer.SetDataSource("lblGWCSGRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  23612. designer.SetDataSource("lblGWCSGRDRBJ", rightBindData.bj);
  23613. designer.SetDataSource("lblGWCSGRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  23614. designer.SetDataSource("lblGWCSGRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  23615. designer.SetDataSource("lblGWCSGRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  23616. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  23617. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  23618. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  23619. }
  23620. else
  23621. {
  23622. hideRowsList.Add(Row + startIndex + HideRows);
  23623. }
  23624. HideRows += 2;
  23625. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 JS/ES"));
  23626. if (rightBindData != null)
  23627. {
  23628. //公务舱 + 小套房 JSES
  23629. designer.SetDataSource("lblGWCJSESDRCB", rightBindData.cb);
  23630. designer.SetDataSource("txtGWCJSESRS", rightBindData.rs);
  23631. designer.SetDataSource("lblGWCJSESZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  23632. designer.SetDataSource("lblGWCJSESDRBJ", rightBindData.bj);
  23633. designer.SetDataSource("lblGWCJSESZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  23634. designer.SetDataSource("lblGWCJSESDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  23635. designer.SetDataSource("lblGWCJSESZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  23636. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  23637. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  23638. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  23639. }
  23640. else
  23641. {
  23642. hideRowsList.Add(Row + startIndex + HideRows);
  23643. }
  23644. HideRows += 2;
  23645. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 SUITE"));
  23646. if (rightBindData != null)
  23647. {
  23648. //公务舱 + 小套房 JSES
  23649. designer.SetDataSource("lblGWCSUITEDRCB", rightBindData.cb);
  23650. designer.SetDataSource("txtGWCSUITERS", rightBindData.rs);
  23651. designer.SetDataSource("lblGWCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  23652. designer.SetDataSource("lblGWCSUITEDRBJ", rightBindData.bj);
  23653. designer.SetDataSource("lblGWCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  23654. designer.SetDataSource("lblGWCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  23655. designer.SetDataSource("lblGWCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  23656. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  23657. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  23658. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  23659. }
  23660. else
  23661. {
  23662. hideRowsList.Add(Row + startIndex + HideRows);
  23663. }
  23664. HideRows += 2;
  23665. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 SUITE"));
  23666. if (rightBindData != null)
  23667. {
  23668. //经济舱 + 大套房
  23669. designer.SetDataSource("lblJJCSUITEDRCB", rightBindData.cb);
  23670. designer.SetDataSource("txtJJCSUITERS", rightBindData.rs);
  23671. designer.SetDataSource("lblJJCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  23672. designer.SetDataSource("lblJJCSUITEDRBJ", rightBindData.bj);
  23673. designer.SetDataSource("lblJJCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  23674. designer.SetDataSource("lblJJCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  23675. designer.SetDataSource("lblJJCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  23676. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  23677. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  23678. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  23679. }
  23680. else
  23681. {
  23682. hideRowsList.Add(Row + startIndex + HideRows);
  23683. }
  23684. HideRows += 2;
  23685. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("头等舱 JS/ES"));
  23686. if (rightBindData != null)
  23687. {
  23688. //头等舱 + 小套房 JSES
  23689. designer.SetDataSource("lblTDCJSESDRCB", rightBindData.cb);
  23690. designer.SetDataSource("txtTDCJSESRS", rightBindData.rs);
  23691. designer.SetDataSource("lblTDCJSESZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  23692. designer.SetDataSource("lblTDCJSESDRBJ", rightBindData.bj);
  23693. designer.SetDataSource("lblTDCJSESZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  23694. designer.SetDataSource("lblTDCJSESDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  23695. designer.SetDataSource("lblTDCJSESZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  23696. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  23697. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  23698. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  23699. }
  23700. else
  23701. {
  23702. hideRowsList.Add(Row + startIndex + HideRows);
  23703. }
  23704. HideRows += 2;
  23705. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("头等舱 SUITE"));
  23706. if (rightBindData != null)
  23707. {
  23708. //头等舱 + 大套房
  23709. designer.SetDataSource("lblTDCSUITEDRCB", rightBindData.cb);
  23710. designer.SetDataSource("txtTDCSUITERS", rightBindData.rs);
  23711. designer.SetDataSource("lblTDCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  23712. designer.SetDataSource("lblTDCSUITEDRBJ", rightBindData.bj);
  23713. designer.SetDataSource("lblTDCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  23714. designer.SetDataSource("lblTDCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  23715. designer.SetDataSource("lblTDCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  23716. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  23717. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  23718. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  23719. }
  23720. else
  23721. {
  23722. hideRowsList.Add(Row + startIndex + HideRows);
  23723. }
  23724. #endregion
  23725. #region B段标题清空
  23726. designer.SetDataSource("CostBDRCB", "");
  23727. designer.SetDataSource("CostBRS", "");
  23728. designer.SetDataSource("CostBXS", "");
  23729. designer.SetDataSource("CostBZCB", "");
  23730. designer.SetDataSource("CostBDRBJ", "");
  23731. designer.SetDataSource("CostBZBJ", "");
  23732. designer.SetDataSource("CostBDRLR", "");
  23733. designer.SetDataSource("CostBZLR", "");
  23734. designer.SetDataSource("CostBDRCBOM", "");
  23735. designer.SetDataSource("CostBRSOM", "");
  23736. designer.SetDataSource("CostBZCBOM", "");
  23737. designer.SetDataSource("CostBDRBJOM", "");
  23738. designer.SetDataSource("CostBZBJOM", "");
  23739. designer.SetDataSource("CostBDRLROM", "");
  23740. designer.SetDataSource("CostBZLROM", "");
  23741. #endregion
  23742. designer.SetDataSource("HotelTBRName", "酒店TBR单间成本(CNY)");
  23743. designer.SetDataSource("HotelSGRName", "酒店SGR单间成本(CNY)");
  23744. designer.SetDataSource("HotelJSESName", "酒店JSES单间成本(CNY)");
  23745. designer.SetDataSource("HotelSUITEName", "酒店SUITE单间成本(CNY)");
  23746. designer.SetDataSource("DJName", "地接(CNY)");
  23747. designer.SetDataSource("HCPName", "地接-火车票(CNY)");
  23748. designer.SetDataSource("CPName", "地接-船票(CNY)");
  23749. designer.SetDataSource("GWName", "公务(CNY)");
  23750. designer.SetDataSource("YQHName", "邀请函(CNY)");
  23751. designer.SetDataSource("LYJName", "零用金(CNY)");
  23752. designer.SetDataSource("HSName", "核酸检测(CNY)");
  23753. designer.SetDataSource("AirGWCName", "机票-公务舱(CNY)");
  23754. designer.SetDataSource("AirJJCName", "机票-经济舱(CNY)");
  23755. designer.SetDataSource("AirTDCName", "机票-头等舱(CNY)");
  23756. designer.SetDataSource("BXName", "保险(CNY)");
  23757. designer.SetDataSource("VisaName", "签证(CNY)");
  23758. #region B段基本数据
  23759. if (dto.costType == "B")
  23760. {
  23761. left = dto.leftInfo.Find(x => x.Type == "B");
  23762. if (left == null)
  23763. {
  23764. return Ok(jw);
  23765. }
  23766. #region B段left数据
  23767. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("核酸"));
  23768. if (leftBindData != null)
  23769. {
  23770. designer.SetDataSource("BHSDRCB", leftBindData.cb);
  23771. designer.SetDataSource("BHSRS", leftBindData.rs);
  23772. designer.SetDataSource("BHSXS", leftBindData.xs);
  23773. designer.SetDataSource("BHSZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23774. designer.SetDataSource("BHSDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23775. designer.SetDataSource("BHSZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23776. designer.SetDataSource("BHSDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23777. designer.SetDataSource("BHSZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23778. }
  23779. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("经济舱"));
  23780. if (leftBindData != null)
  23781. {
  23782. designer.SetDataSource("BJPJJCCB", leftBindData.cb);
  23783. designer.SetDataSource("BJPJJCPnum", leftBindData.rs);
  23784. designer.SetDataSource("BJPJJCXS", leftBindData.xs);
  23785. designer.SetDataSource("BJPJJCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23786. designer.SetDataSource("BJPJJCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23787. designer.SetDataSource("BJPJJCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23788. designer.SetDataSource("BJPJJCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23789. designer.SetDataSource("BJPJJCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23790. }
  23791. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("公务舱"));
  23792. if (leftBindData != null)
  23793. {
  23794. designer.SetDataSource("BJPGWCCB", leftBindData.cb);
  23795. designer.SetDataSource("BJPGWCPNum", leftBindData.rs);
  23796. designer.SetDataSource("BJPGWCXS", leftBindData.xs);
  23797. designer.SetDataSource("BJPGWCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23798. designer.SetDataSource("BJPGWCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23799. designer.SetDataSource("BJPGWCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23800. designer.SetDataSource("BJPGWCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23801. designer.SetDataSource("BJPGWCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23802. }
  23803. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("头等舱"));
  23804. if (leftBindData != null)
  23805. {
  23806. designer.SetDataSource("BJPTDCCB", leftBindData.cb);
  23807. designer.SetDataSource("BJPTDCPNum", leftBindData.rs);
  23808. designer.SetDataSource("BJPTDCXS", leftBindData.xs);
  23809. designer.SetDataSource("BJPTDCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23810. designer.SetDataSource("BJPTDCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23811. designer.SetDataSource("BJPTDCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23812. designer.SetDataSource("BJPTDCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23813. designer.SetDataSource("BJPTDCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23814. }
  23815. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("火车票"));
  23816. if (leftBindData != null)
  23817. {
  23818. designer.SetDataSource("BHCPCB", leftBindData.cb);
  23819. designer.SetDataSource("BHCPRS", leftBindData.rs);
  23820. designer.SetDataSource("BHCPXS", leftBindData.xs);
  23821. designer.SetDataSource("BHCPZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23822. designer.SetDataSource("BHCPDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23823. designer.SetDataSource("BHCPZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23824. designer.SetDataSource("BHCPDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23825. designer.SetDataSource("BHCPZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23826. }
  23827. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("船票"));
  23828. if (leftBindData != null)
  23829. {
  23830. designer.SetDataSource("BCPCB", leftBindData.cb);
  23831. designer.SetDataSource("BCPRS", leftBindData.rs);
  23832. designer.SetDataSource("BCPXS", leftBindData.xs);
  23833. designer.SetDataSource("BCPZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23834. designer.SetDataSource("BCPDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23835. designer.SetDataSource("BCPZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23836. designer.SetDataSource("BCPDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23837. designer.SetDataSource("BCPZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23838. }
  23839. //TBR
  23840. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("TBR"));
  23841. if (leftBindData != null)
  23842. {
  23843. designer.SetDataSource("BHotelTBRDRCB", leftBindData.cb);
  23844. designer.SetDataSource("BHotelTBRRS", leftBindData.rs);
  23845. designer.SetDataSource("BHotelTBRXS", leftBindData.xs);
  23846. designer.SetDataSource("BHotelTBRCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23847. designer.SetDataSource("BHotelTBRDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23848. designer.SetDataSource("BHotelTBRZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23849. designer.SetDataSource("BHotelTBRDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23850. designer.SetDataSource("BHotelTBRZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23851. }
  23852. //SGR
  23853. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("SGR"));
  23854. if (leftBindData != null)
  23855. {
  23856. designer.SetDataSource("BHotelSGRDRCB", leftBindData.cb);
  23857. designer.SetDataSource("BHotelSGRRS", leftBindData.rs);
  23858. designer.SetDataSource("BHotelSGRXS", leftBindData.xs);
  23859. designer.SetDataSource("BHotelSGRCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23860. designer.SetDataSource("BHotelSGRDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23861. designer.SetDataSource("BHotelSGRZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23862. designer.SetDataSource("BHotelSGRDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23863. designer.SetDataSource("BHotelSGRZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23864. }
  23865. //JS/ES
  23866. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("JSES"));
  23867. if (leftBindData != null)
  23868. {
  23869. designer.SetDataSource("BHotelJSESDRCB", leftBindData.cb);
  23870. designer.SetDataSource("BHotelJSESRS", leftBindData.rs);
  23871. designer.SetDataSource("BHotelJSESXS", leftBindData.xs);
  23872. designer.SetDataSource("BHotelJSESCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23873. designer.SetDataSource("BHotelJSESDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23874. designer.SetDataSource("BHotelJSESZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23875. designer.SetDataSource("BHotelJSESDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23876. designer.SetDataSource("BHotelJSESZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23877. }
  23878. //SUITE
  23879. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("SUITE"));
  23880. if (leftBindData != null)
  23881. {
  23882. designer.SetDataSource("BHotelSUITEDRCB", leftBindData.cb);
  23883. designer.SetDataSource("BHotelSUITERS", leftBindData.rs);
  23884. designer.SetDataSource("BHotelSUITEXS", leftBindData.xs);
  23885. designer.SetDataSource("BHotelSUITECB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23886. designer.SetDataSource("BHotelSUITEDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23887. designer.SetDataSource("BHotelSUITEZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23888. designer.SetDataSource("BHotelSUITEDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23889. designer.SetDataSource("BHotelSUITEZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23890. }
  23891. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("地接"));
  23892. if (leftBindData != null)
  23893. {
  23894. designer.SetDataSource("BDJDRCB", leftBindData.cb);
  23895. designer.SetDataSource("BDJRS", leftBindData.rs);
  23896. designer.SetDataSource("BDJXS", leftBindData.xs);
  23897. designer.SetDataSource("BDJCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23898. designer.SetDataSource("BDJDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23899. designer.SetDataSource("BDJZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23900. designer.SetDataSource("BDJDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23901. designer.SetDataSource("BDJZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23902. }
  23903. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("公务单人"));
  23904. if (leftBindData != null)
  23905. {
  23906. designer.SetDataSource("BGWDRCD", leftBindData.cb);
  23907. designer.SetDataSource("BGWRS", leftBindData.rs);
  23908. designer.SetDataSource("BGWXS", leftBindData.xs);
  23909. designer.SetDataSource("BGWCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23910. designer.SetDataSource("BGWDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23911. designer.SetDataSource("BGWZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23912. designer.SetDataSource("BGWDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23913. designer.SetDataSource("BGWZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23914. }
  23915. #region 优化方案
  23916. //Dictionary<string, object> excelBind = new Dictionary<string, object>();
  23917. //excelBind.Add("零用金", new {
  23918. //cb="",
  23919. //rs="",
  23920. //xs ="",
  23921. //zcb = "",
  23922. //});
  23923. #endregion
  23924. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("零用金"));
  23925. if (leftBindData != null)
  23926. {
  23927. designer.SetDataSource("BLYJDRCB", leftBindData.cb);
  23928. designer.SetDataSource("BLYJRS", leftBindData.rs);
  23929. designer.SetDataSource("BLYJXS", leftBindData.xs);
  23930. designer.SetDataSource("BLYJCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23931. designer.SetDataSource("BLYJDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23932. designer.SetDataSource("BLYJZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23933. designer.SetDataSource("BLYJDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23934. designer.SetDataSource("BLYJZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23935. }
  23936. #endregion
  23937. #region B段Right信息
  23938. right = dto.rightInfo.Find(x => x.Type == "B");
  23939. if (right == null)
  23940. {
  23941. return Ok(jw);
  23942. }
  23943. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 TBR"));
  23944. if (rightBindData != null)
  23945. {
  23946. //经济舱 + 双人间 TBR
  23947. designer.SetDataSource("BlblJJCTBRDRCB", rightBindData.cb);
  23948. designer.SetDataSource("BtxtJJCTBRRS", rightBindData.rs);
  23949. designer.SetDataSource("BlblJJCTBRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  23950. designer.SetDataSource("BlblJJCTBRDRBJ", rightBindData.bj);
  23951. designer.SetDataSource("BlblJJCTBRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  23952. designer.SetDataSource("BlblJJCTBRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  23953. designer.SetDataSource("BlblJJCTBRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  23954. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  23955. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  23956. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  23957. }
  23958. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 SGR"));
  23959. if (rightBindData != null)
  23960. {
  23961. //经济舱 + 单人间 SGR
  23962. designer.SetDataSource("BlblJJCSGRDRCB", rightBindData.cb);
  23963. designer.SetDataSource("BtxtJJCSGRRS", rightBindData.rs);
  23964. designer.SetDataSource("BlblJJCSGRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  23965. designer.SetDataSource("BlblJJCSGRDRBJ", rightBindData.bj);
  23966. designer.SetDataSource("BlblJJCSGRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  23967. designer.SetDataSource("BlblJJCSGRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  23968. designer.SetDataSource("BlblJJCSGRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  23969. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  23970. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  23971. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  23972. }
  23973. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 SGR"));
  23974. if (rightBindData != null)
  23975. {
  23976. //公务舱 + 单人间 SGR
  23977. designer.SetDataSource("BlblGWCSGRCB", rightBindData.cb);
  23978. designer.SetDataSource("BlblGWCSGRRS", rightBindData.rs);
  23979. designer.SetDataSource("BlblGWCSGRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  23980. designer.SetDataSource("BlblGWCSGRDRBJ", rightBindData.bj);
  23981. designer.SetDataSource("BlblGWCSGRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  23982. designer.SetDataSource("BlblGWCSGRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  23983. designer.SetDataSource("BlblGWCSGRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  23984. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  23985. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  23986. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  23987. }
  23988. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 JS/ES"));
  23989. if (rightBindData != null)
  23990. {
  23991. //公务舱 + 小套房 JSES
  23992. designer.SetDataSource("BlblGWCJSESDRCB", rightBindData.cb);
  23993. designer.SetDataSource("BtxtGWCJSESRS", rightBindData.rs);
  23994. designer.SetDataSource("BlblGWCJSESZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  23995. designer.SetDataSource("BlblGWCJSESDRBJ", rightBindData.bj);
  23996. designer.SetDataSource("BlblGWCJSESZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  23997. designer.SetDataSource("BlblGWCJSESDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  23998. designer.SetDataSource("BlblGWCJSESZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  23999. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24000. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24001. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24002. }
  24003. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 SUITE"));
  24004. if (rightBindData != null)
  24005. {
  24006. //公务舱 + 小套房 JSES
  24007. designer.SetDataSource("BlblGWCSUITEDRCB", rightBindData.cb);
  24008. designer.SetDataSource("BtxtGWCSUITERS", rightBindData.rs);
  24009. designer.SetDataSource("BlblGWCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24010. designer.SetDataSource("BlblGWCSUITEDRBJ", rightBindData.bj);
  24011. designer.SetDataSource("BlblGWCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24012. designer.SetDataSource("BlblGWCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24013. designer.SetDataSource("BlblGWCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24014. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24015. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24016. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24017. }
  24018. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 SUITE"));
  24019. if (rightBindData != null)
  24020. {
  24021. //经济舱 + 大套房
  24022. designer.SetDataSource("BlblJJCSUITEDRCB", rightBindData.cb);
  24023. designer.SetDataSource("BtxtJJCSUITERS", rightBindData.rs);
  24024. designer.SetDataSource("BlblJJCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24025. designer.SetDataSource("BlblJJCSUITEDRBJ", rightBindData.bj);
  24026. designer.SetDataSource("BlblJJCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24027. designer.SetDataSource("BlblJJCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24028. designer.SetDataSource("BlblJJCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24029. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24030. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24031. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24032. }
  24033. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("头等舱 JS/ES"));
  24034. if (rightBindData != null)
  24035. {
  24036. //头等舱 + 小套房 JSES
  24037. designer.SetDataSource("BlblTDCJSESDRCB", rightBindData.cb);
  24038. designer.SetDataSource("BtxtTDCJSESRS", rightBindData.rs);
  24039. designer.SetDataSource("BlblTDCJSESZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24040. designer.SetDataSource("BlblTDCJSESDRBJ", rightBindData.bj);
  24041. designer.SetDataSource("BlblTDCJSESZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24042. designer.SetDataSource("BlblTDCJSESDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24043. designer.SetDataSource("BlblTDCJSESZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24044. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24045. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24046. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24047. }
  24048. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("头等舱 SUITE"));
  24049. if (rightBindData != null)
  24050. {
  24051. //头等舱 + 大套房
  24052. designer.SetDataSource("BlblTDCSUITEDRCB", rightBindData.cb);
  24053. designer.SetDataSource("BtxtTDCSUITERS", rightBindData.rs);
  24054. designer.SetDataSource("BlblTDCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24055. designer.SetDataSource("BlblTDCSUITEDRBJ", rightBindData.bj);
  24056. designer.SetDataSource("BlblTDCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24057. designer.SetDataSource("BlblTDCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24058. designer.SetDataSource("BlblTDCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24059. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24060. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24061. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24062. }
  24063. #endregion
  24064. #region 标题
  24065. designer.SetDataSource("CostBDRCB", "单人成本");
  24066. designer.SetDataSource("CostBRS", "人数");
  24067. designer.SetDataSource("CostBXS", "系数");
  24068. designer.SetDataSource("CostBZCB", "总成本");
  24069. designer.SetDataSource("CostBDRBJ", "单人报价");
  24070. designer.SetDataSource("CostBZBJ", "总报价");
  24071. designer.SetDataSource("CostBDRLR", "单人利润");
  24072. designer.SetDataSource("CostBZLR", "总利润");
  24073. designer.SetDataSource("CostBDRCBOM", "单人成本");
  24074. designer.SetDataSource("CostBRSOM", "人数");
  24075. designer.SetDataSource("CostBZCBOM", "总成本");
  24076. designer.SetDataSource("CostBDRBJOM", "单人报价");
  24077. designer.SetDataSource("CostBZBJOM", "总报价");
  24078. designer.SetDataSource("CostBDRLROM", "单人利润");
  24079. designer.SetDataSource("CostBZLROM", "总利润");
  24080. #endregion
  24081. }
  24082. #endregion
  24083. designer.SetDataSource("TzZCB2", TzZCB2);
  24084. designer.SetDataSource("TzZBJ2", TzZBJ2);
  24085. designer.SetDataSource("TzZLR2", TzZLR2);
  24086. string[] dataSourceKeys = new string[]
  24087. {
  24088. "VF",
  24089. "TGS",
  24090. "TGOF",
  24091. "TGM",
  24092. "TGA",
  24093. "TGTF",
  24094. "TGEF",
  24095. "CFM",
  24096. "CFOF",
  24097. "B",
  24098. "L",
  24099. "D",
  24100. "TBR",
  24101. "SGR",
  24102. "JSES",
  24103. "Suite",
  24104. "TV",
  24105. "1L",
  24106. "IF",
  24107. "EF",
  24108. "BRF",
  24109. "TE",
  24110. "TGT",
  24111. "DRVT",
  24112. "PC",
  24113. "TLF",
  24114. "ECT"
  24115. };
  24116. foreach (var item in dataSourceKeys)
  24117. {
  24118. Func<TitleModel, bool> expr = x => x.label.Replace(" ", "").Replace("/", "") == item
  24119. || x.label.Replace(" ", "").Replace("/", "").ToUpper() == item.ToUpper();
  24120. var find = dto.titleModel.FirstOrDefault(expr);
  24121. if (find != null)
  24122. {
  24123. designer.SetDataSource(item, find.text);
  24124. }
  24125. else
  24126. {
  24127. designer.SetDataSource(item, 0);
  24128. }
  24129. }
  24130. designer.SetDataSource(dt);
  24131. //根据数据源处理生成报表内容
  24132. designer.Process();
  24133. designer.Workbook.Worksheets[0].Name = "费用明细";
  24134. designer.Workbook.Worksheets[1].Name = "费用总核算";
  24135. Worksheet sheet = designer.Workbook.Worksheets[0];
  24136. #region 隐藏舱位
  24137. var settingAir = new[]
  24138. {
  24139. new { key = "经济舱", index = 7 },
  24140. new { key = "公务舱", index = 19 },
  24141. new { key = "头等舱", index = 11 }
  24142. };
  24143. var airType = _sqlSugar.Queryable<Grp_TourClientList>()
  24144. .LeftJoin<Sys_SetData>((c, s) => s.IsDel == 0 && c.ShippingSpaceTypeId == s.Id)
  24145. .Where((c, s) => c.IsDel == 0 && c.DiId == di.Id)
  24146. .Select((c, s) => s.Name)
  24147. .ToList()
  24148. .GroupBy(x => x)
  24149. .Select(x => x.Key);
  24150. foreach (var item in settingAir)
  24151. {
  24152. if (!airType.Contains(item.key))
  24153. {
  24154. hideRowsList.Add(item.index);
  24155. }
  24156. }
  24157. #endregion
  24158. foreach (var Rowindex in hideRowsList)
  24159. {
  24160. ws.Cells.HideRows(Rowindex, 2);
  24161. }
  24162. ws = designer.Workbook.Worksheets[0];
  24163. foreach (var Column in hideColumnList)
  24164. {
  24165. ws.Cells.HideColumns(Column, 1);
  24166. }
  24167. byte[] bytes = null;
  24168. string strFileName = di.TeamName + "-团组-成本.xls";
  24169. using (MemoryStream stream = new MemoryStream())
  24170. {
  24171. designer.Workbook.Save(stream, Aspose.Cells.SaveFormat.Xlsx);
  24172. bytes = stream.ToArray();
  24173. }
  24174. return Ok(JsonView(true, "", new
  24175. {
  24176. Data = bytes,
  24177. strFileName,
  24178. }));
  24179. }
  24180. /// <summary>
  24181. /// 导出客户报表
  24182. /// </summary>
  24183. /// <returns></returns>
  24184. [HttpPost]
  24185. public async Task<IActionResult> ExportClientWordFile(ExportClientWordFileDto dto)
  24186. {
  24187. var jw = JsonView(false);
  24188. if (dto.Diid == 0)
  24189. {
  24190. return Ok(JsonView(false, "请传递团组id"));
  24191. }
  24192. var deleInfo = await _groupRepository.PostGroupInfo(new GroupInfoDto { Id = dto.Diid, PortType = 1 });
  24193. if (deleInfo.Code != 0)
  24194. {
  24195. return Ok(JsonView(false, "团组信息查询失败!"));
  24196. }
  24197. var di = deleInfo.Data as DelegationInfoWebView;
  24198. if (di == null)
  24199. {
  24200. return Ok(JsonView(false, "团组信息查询失败!"));
  24201. }
  24202. //文件名
  24203. //string strFileName = di.TeamName + "-团组-客户报价.doc";
  24204. //获取模板
  24205. string tmppath = (AppSettingsHelper.Get("WordBasePath") + "Template/团组-客户报价.doc");
  24206. //载入模板
  24207. Document doc = new Document(tmppath);
  24208. Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
  24209. Dictionary<string, string> DickeyValue = new Dictionary<string, string>();
  24210. DickeyValue.Add("DickeyValue", di.TeamName); //团组名
  24211. var ParameterList = _GroupCostParameterRepository.GetGroupCostParameterListByDiid(dto.Diid);
  24212. var AParameter = ParameterList.Find(x => x.CostType == "A");
  24213. var BParameter = ParameterList.Find(x => x.CostType == "B");
  24214. if (AParameter == null)
  24215. {
  24216. return Ok(JsonView(false, "系数不存在!"));
  24217. }
  24218. string CarGuides, TzNumber, CarGuides1, Meal, SubsidizedMeals, NightRepair, AttractionsTickets, MiscellaneousFees, ATip, TzHotelDesc, Offcial, PettyCash, Visa, TrainTicket, TicketPrice
  24219. , TzAirDesc, TzZCost;
  24220. CarGuides = TzNumber = CarGuides1 = Meal = SubsidizedMeals = NightRepair = AttractionsTickets = MiscellaneousFees = ATip = TzHotelDesc = Offcial = PettyCash = Visa = TrainTicket = TicketPrice
  24221. = TzAirDesc = TzZCost = string.Empty;
  24222. TzNumber = AParameter.CostTypenumber.ToString();
  24223. CarGuides = "RMB " + (AParameter.DJCB * AParameter.DJXS).ToString("#0.00");
  24224. CarGuides1 = dto.CarGuides1;
  24225. Meal = dto.Meal;
  24226. SubsidizedMeals = dto.SubsidizedMeals;
  24227. NightRepair = dto.NightRepair;
  24228. AttractionsTickets = dto.AttractionsTickets;
  24229. MiscellaneousFees = dto.MiscellaneousFees;
  24230. ATip = dto.ATip;
  24231. TzHotelDesc = "";
  24232. Offcial = "RMB " + (AParameter.GWCB * AParameter.GWXS).ToString("#0.00");
  24233. PettyCash = "RMB " + (AParameter.LYJCB * AParameter.LYJXS).ToString("#0.00");
  24234. Visa = "RMB " + (AParameter.VisaCB * AParameter.VisaXS + AParameter.HSCB * AParameter.HSXS + AParameter.BXCB * AParameter.BXXS).ToString("#0.00");
  24235. TrainTicket = "RMB " + (AParameter.HCPCB * AParameter.HCPXS).ToString("#0.00");
  24236. TicketPrice = "RMB " + (AParameter.CPCB * AParameter.CPXS).ToString("#0.00");
  24237. TzAirDesc = "";
  24238. TzZCost = dto.TzZCost;
  24239. var TzHotelDescArr = new string[] { "SGR", "JSES", "SUITE", "TBR" };
  24240. var TzAirDescArr = new string[] { "经济舱", "公务舱" };
  24241. var index = 1;
  24242. var AinfoArr = dto.leftInfo.Find(x => x.Type == "A");
  24243. foreach (var item in TzHotelDescArr)
  24244. {
  24245. if (AinfoArr != null)
  24246. {
  24247. var Ainfo = AinfoArr.leftinfoNumber.Find(x => x.title.Contains(item));
  24248. if (Ainfo != null)
  24249. {
  24250. if (int.Parse(Ainfo.rs) <= 0)
  24251. {
  24252. continue;
  24253. }
  24254. var hotelText = string.Empty;
  24255. switch (item)
  24256. {
  24257. case "SGR":
  24258. hotelText = "单人间";
  24259. break;
  24260. case "JSES":
  24261. hotelText = "小套房";
  24262. break;
  24263. case "SUITE":
  24264. hotelText = "套房";
  24265. break;
  24266. case "TBR":
  24267. hotelText = "双人间";
  24268. break;
  24269. }
  24270. if (item != "TBR")
  24271. {
  24272. TzHotelDesc += "(" + index + ".) " + hotelText + " " + Ainfo.rs + "间 共" + Ainfo.rs + " " + (decimal.Parse(Ainfo.cb) * decimal.Parse(Ainfo.xs)).ToString("#0.00") + "/人........共RMB " + (decimal.Parse(Ainfo.cb) * decimal.Parse(Ainfo.xs) * decimal.Parse(Ainfo.rs)).ToString("#0.00") + "\n";
  24273. }
  24274. else
  24275. {
  24276. TzHotelDesc += "(" + index + ".) " + hotelText + " " + (int.Parse(Ainfo.rs) / 2) + "间 共" + Ainfo.rs + " " + (decimal.Parse(Ainfo.cb) * decimal.Parse(Ainfo.xs)).ToString("#0.00") + "/人........共RMB " + (decimal.Parse(Ainfo.cb) * decimal.Parse(Ainfo.xs) * decimal.Parse(Ainfo.rs)).ToString("#0.00") + "\n";
  24277. }
  24278. index++;
  24279. }
  24280. }
  24281. }
  24282. index = 1;
  24283. foreach (var item in TzAirDescArr)
  24284. {
  24285. if (AinfoArr != null)
  24286. {
  24287. var Ainfo = AinfoArr.leftinfoNumber.Find(x => x.title.Contains(item));
  24288. if (Ainfo != null)
  24289. {
  24290. if (int.Parse(Ainfo.rs) <= 0)
  24291. {
  24292. continue;
  24293. }
  24294. TzAirDesc += "(" + index + ".) " + item + " " + (decimal.Parse(Ainfo.cb) * decimal.Parse(Ainfo.xs)).ToString("#0.00") + "/人 共" + Ainfo.rs + " ........小计RMB " + (decimal.Parse(Ainfo.cb) * decimal.Parse(Ainfo.xs) * decimal.Parse(Ainfo.rs)).ToString("#0.00") + "\n";
  24295. index++;
  24296. }
  24297. }
  24298. }
  24299. if (dto.costType == "B")
  24300. {
  24301. if (BParameter == null)
  24302. {
  24303. return Ok(JsonView(false, "B段系数不存在!"));
  24304. }
  24305. CarGuides = CarGuides.Insert(0, "A段 ") + " B段 RMB" + (BParameter.DJCB * BParameter.DJXS).ToString("#0.00");
  24306. Offcial = Offcial.Insert(0, "A段 ") + " B段 RMB " + (BParameter.GWCB * BParameter.GWXS).ToString("#0.00");
  24307. PettyCash = PettyCash.Insert(0, "A段 ") + " B段 RMB " + (BParameter.LYJCB * BParameter.LYJXS).ToString("#0.00");
  24308. Visa = Visa.Insert(0, "A段 ") + " B段 RMB " + (BParameter.VisaCB * BParameter.VisaXS + BParameter.HSCB * BParameter.HSXS + BParameter.BXCB * BParameter.BXXS).ToString("#0.00");
  24309. TrainTicket = TrainTicket.Insert(0, "A段 ") + " B段 RMB " + (BParameter.HCPCB * BParameter.HCPXS).ToString("#0.00");
  24310. TicketPrice = TicketPrice.Insert(0, "A段 ") + " B段 RMB " + (BParameter.CPCB * BParameter.CPXS).ToString("#0.00");
  24311. AinfoArr = dto.leftInfo.Find(x => x.Type == "B");
  24312. foreach (var item in TzHotelDescArr)
  24313. {
  24314. if (AinfoArr != null)
  24315. {
  24316. TzHotelDesc += "B段信息 \r\n";
  24317. var Ainfo = AinfoArr.leftinfoNumber.Find(x => x.title.Contains(item));
  24318. if (Ainfo != null)
  24319. {
  24320. if (int.Parse(Ainfo.rs) <= 0)
  24321. {
  24322. continue;
  24323. }
  24324. var hotelText = string.Empty;
  24325. switch (item)
  24326. {
  24327. case "SGR":
  24328. hotelText = "单人间";
  24329. break;
  24330. case "JSES":
  24331. hotelText = "小套房";
  24332. break;
  24333. case "SUITE":
  24334. hotelText = "套房";
  24335. break;
  24336. case "TBR":
  24337. hotelText = "双人间";
  24338. break;
  24339. }
  24340. if (item != "TBR")
  24341. {
  24342. TzHotelDesc += "(" + index + ".) " + hotelText + " " + Ainfo.rs + "间 共" + Ainfo.rs + " " + (decimal.Parse(Ainfo.cb) * decimal.Parse(Ainfo.xs)).ToString("#0.00") + "/人........共RMB " + (decimal.Parse(Ainfo.cb) * decimal.Parse(Ainfo.xs) * decimal.Parse(Ainfo.rs)).ToString("#0.00") + "\n";
  24343. }
  24344. else
  24345. {
  24346. TzHotelDesc += "(" + index + ".) " + hotelText + " " + (int.Parse(Ainfo.rs) / 2) + "间 共" + Ainfo.rs + " " + (decimal.Parse(Ainfo.cb) * decimal.Parse(Ainfo.xs)).ToString("#0.00") + "/人........共RMB " + (decimal.Parse(Ainfo.cb) * decimal.Parse(Ainfo.xs) * decimal.Parse(Ainfo.rs)).ToString("#0.00") + "\n";
  24347. }
  24348. index++;
  24349. }
  24350. TzHotelDesc = TzHotelDesc.Insert(0, "A段信息 \r\n");
  24351. }
  24352. }
  24353. index = 1;
  24354. foreach (var item in TzAirDescArr)
  24355. {
  24356. if (AinfoArr != null)
  24357. {
  24358. var Ainfo = AinfoArr.leftinfoNumber.Find(x => x.title.Contains(item));
  24359. if (Ainfo != null)
  24360. {
  24361. if (int.Parse(Ainfo.rs) <= 0)
  24362. {
  24363. continue;
  24364. }
  24365. TzAirDesc += "(" + index + ".) " + item + " " + (decimal.Parse(Ainfo.cb) * decimal.Parse(Ainfo.xs)).ToString("#0.00") + "/人 共" + Ainfo.rs + " ........小计RMB " + (decimal.Parse(Ainfo.cb) * decimal.Parse(Ainfo.xs) * decimal.Parse(Ainfo.rs)).ToString("#0.00") + "\n";
  24366. index++;
  24367. }
  24368. }
  24369. }
  24370. }
  24371. Visa = Visa.Insert(0, "签证及保险(含核酸检测): ");
  24372. DickeyValue.Add("TzNumber", TzNumber); //团组人数
  24373. DickeyValue.Add("CarGuides", CarGuides); //地接单人报价
  24374. DickeyValue.Add("CarGuides1", CarGuides1); // 地接 - 车导费
  24375. DickeyValue.Add("Meal", Meal); // 地接 - 餐费
  24376. DickeyValue.Add("SubsidizedMeals", SubsidizedMeals);// 地接 - 餐补
  24377. DickeyValue.Add("NightRepair", NightRepair); // 地接 - 宿补
  24378. DickeyValue.Add("AttractionsTickets", AttractionsTickets); // 地接 - 景点
  24379. DickeyValue.Add("MiscellaneousFees", MiscellaneousFees); // 地接 - 杂费
  24380. DickeyValue.Add("ATip", ATip); // 地接 - 小费
  24381. DickeyValue.Add("TzHotelDesc", TzHotelDesc); //酒店
  24382. DickeyValue.Add("Offcial", Offcial); // 公务单人报价
  24383. DickeyValue.Add("PettyCash", PettyCash); // 零用金单人报价
  24384. DickeyValue.Add("Visa", Visa); // 签证单人报价
  24385. DickeyValue.Add("TrainTicket", TrainTicket); //火车票
  24386. DickeyValue.Add("TicketPrice", TicketPrice); //船票
  24387. DickeyValue.Add("TzAirDesc", TzAirDesc); //机票
  24388. DickeyValue.Add("TzZCost", TzZCost);
  24389. foreach (var key in DickeyValue.Keys)
  24390. {
  24391. if (doc.Range.Bookmarks[key] != null)
  24392. {
  24393. Bookmark mark = doc.Range.Bookmarks[key];
  24394. mark.Text = DickeyValue[key];
  24395. }
  24396. }
  24397. byte[] bytes = null;
  24398. string strFileName = di.TeamName + "-客户报价.doc";
  24399. using (MemoryStream stream = new MemoryStream())
  24400. {
  24401. doc.Save(stream, Aspose.Words.SaveFormat.Doc);
  24402. bytes = stream.ToArray();
  24403. }
  24404. return Ok(JsonView(true, "", new
  24405. {
  24406. Data = bytes,
  24407. strFileName,
  24408. }));
  24409. }
  24410. /// <summary>
  24411. /// 团组成本 各模块(酒店,地接,机票)成本提示
  24412. /// </summary>
  24413. /// <param name="dto"></param>
  24414. /// <returns></returns>
  24415. [HttpPost]
  24416. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24417. public async Task<IActionResult> PostGroupCostModulePrompt(GroupCostModulePromptDto dto)
  24418. {
  24419. try
  24420. {
  24421. #region 参数验证
  24422. if (dto.DiId < 0)
  24423. {
  24424. return Ok(JsonView(false, "请传入有效的DiId参数!"));
  24425. }
  24426. List<int> cTableIds = new List<int>() {
  24427. 76 ,//酒店预订
  24428. 77 ,//行程
  24429. 79 ,//车/导游地接
  24430. 80 ,//签证
  24431. 81 ,//邀请/公务活
  24432. 82 ,//团组客户保险
  24433. 85 ,//机票预订
  24434. 98 ,//其他款项
  24435. 285 ,//收款退还
  24436. 751 ,//酒店早餐
  24437. 1015 // 超支费用
  24438. };
  24439. if (dto.CTable < 0 && !cTableIds.Contains(dto.CTable))
  24440. {
  24441. return Ok(JsonView(false, "请传入有效的CTable参数!"));
  24442. }
  24443. #endregion
  24444. //Grp_GroupCostParameter 预算表 Grp_GroupCost 详细费用列表
  24445. var _GroupCostParameters = _usersRep._sqlSugar.Queryable<Grp_GroupCostParameter>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).ToList();
  24446. if (_GroupCostParameters.Count <= 0)
  24447. {
  24448. return Ok(JsonView(false, "暂无该团组成本信息!", new List<dynamic>()));
  24449. }
  24450. if (_GroupCostParameters[0].IsShare == 0)
  24451. {
  24452. return Ok(JsonView(false, "该团组成本未完成!", new List<dynamic>()));
  24453. }
  24454. var _GroupCosts = _usersRep._sqlSugar.Queryable<Grp_GroupCost>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  24455. //处理date为空问题
  24456. if (_GroupCosts.Count > 0)
  24457. {
  24458. for (int i = 0; i < _GroupCosts.Count; i++)
  24459. {
  24460. if (string.IsNullOrEmpty(_GroupCosts[i].Date))
  24461. {
  24462. if (i > 0)
  24463. {
  24464. _GroupCosts[i].Date = _GroupCosts[i - 1].Date;
  24465. }
  24466. }
  24467. }
  24468. }
  24469. GroupCostModulePromptView _view = new GroupCostModulePromptView();
  24470. List<GroupCostModulePromptInfo> _ModulePromptInfos = new List<GroupCostModulePromptInfo>(); //机票存储多段
  24471. var currDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  24472. string currCode = "";
  24473. #region currCode 验证
  24474. bool isInt = int.TryParse(_GroupCostParameters[0].Currency, out int intCurrency);
  24475. if (isInt)
  24476. {
  24477. var currData = currDatas.Find(it => it.Id == intCurrency);
  24478. if (currData != null)
  24479. {
  24480. currCode = currData.Name;
  24481. }
  24482. }
  24483. else
  24484. {
  24485. currCode = _GroupCostParameters[0].Currency.Trim();
  24486. }
  24487. #endregion
  24488. //op,酒店单段模式存储
  24489. GroupCostModulePromptInfo _ModulePromptInfo = new GroupCostModulePromptInfo()
  24490. {
  24491. CurrencyCode = currCode,
  24492. Rate = _GroupCostParameters[0].Rate,
  24493. CostType = _GroupCostParameters[0].CostType,
  24494. CostTypeStartTime = Convert.ToDateTime(_GroupCostParameters[0].CostTypeStartTime).ToString("yyyy-MM-dd"),
  24495. CostTypeEndTime = Convert.ToDateTime(_GroupCostParameters[0].CostTypeendTime).ToString("yyyy-MM-dd"),
  24496. CostTypeNumber = _GroupCostParameters[0].CostTypenumber
  24497. };
  24498. List<dynamic> _ModuleSubPromptInfo = new List<dynamic>(); // 存储CTbale != 85 的动态数据
  24499. if (_GroupCostParameters.Count == 2)
  24500. {
  24501. _ModulePromptInfo.CostTypeEndTime = Convert.ToDateTime(_GroupCostParameters[1].CostTypeendTime).ToString("yyyy-MM-dd");
  24502. }
  24503. foreach (var item in _GroupCostParameters)
  24504. {
  24505. decimal _rate = 1;
  24506. decimal _rate1 = item.Rate;
  24507. decimal _scale = 1;
  24508. //decimal _scale = 0.95M; 雷怡 2024-06-11 10:06:08 屏蔽
  24509. #region 处理地接价格比例 总经理 国交部经理 主管 不下调 其他人 下调 5%
  24510. //var userInfo = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.Id == dto.UserId).First();
  24511. //if (userInfo != null)
  24512. //{
  24513. // if (userInfo.DepId == 1 || userInfo.DepId == 7)
  24514. // {
  24515. // if (userInfo.JobPostId == 1 || userInfo.JobPostId == 22 || userInfo.JobPostId == 32)
  24516. // {
  24517. // _scale = 1.00M;
  24518. // }
  24519. // }
  24520. //}
  24521. #endregion
  24522. GroupCostModulePromptInfo modulePromptInfo = new GroupCostModulePromptInfo()
  24523. {
  24524. CurrencyCode = currCode,
  24525. Rate = _rate1,
  24526. CostType = item.CostType,
  24527. CostTypeStartTime = Convert.ToDateTime(item.CostTypeStartTime).ToString("yyyy-MM-dd"),
  24528. CostTypeEndTime = Convert.ToDateTime(item.CostTypeendTime).ToString("yyyy-MM-dd"),
  24529. CostTypeNumber = item.CostTypenumber
  24530. };
  24531. if (_GroupCostParameters.Count > 1)
  24532. {
  24533. modulePromptInfo.CostTypeNumber = item.CostTypenumber;
  24534. }
  24535. else
  24536. {
  24537. modulePromptInfo.CostTypeNumber = item.LYJRS;
  24538. }
  24539. if (dto.CTable == 79)//
  24540. {
  24541. modulePromptInfo.IndividualCost = item.DJCB / modulePromptInfo.CostTypeNumber;
  24542. modulePromptInfo.TotalCost = item.DJCB;
  24543. }
  24544. List<string> costTypes = new List<string>() { "A", "B" };
  24545. List<Grp_GroupCost> _GroupCostsTypeData = new List<Grp_GroupCost>();
  24546. var _GroupCostsDuplicates = _GroupCostParameters.GroupBy(x => x.CostType).Select(y => y.FirstOrDefault());
  24547. if (_GroupCostsDuplicates.Count() == 1)
  24548. {
  24549. _GroupCostsTypeData = _GroupCosts;
  24550. }
  24551. else
  24552. {
  24553. _GroupCostsTypeData = _GroupCosts.Where(it => Convert.ToDateTime(it.Date) >= Convert.ToDateTime(item.CostTypeStartTime) &&
  24554. Convert.ToDateTime(it.Date) <= Convert.ToDateTime(item.CostTypeendTime)).ToList();
  24555. }
  24556. /*
  24557. * 76 酒店预订
  24558. * 77 行程
  24559. * 79 车/导游地接
  24560. * 80 签证
  24561. * 81 邀请/公务活动
  24562. * 82 团组客户保险
  24563. * 85 机票预订
  24564. * 98 其他款项
  24565. * 285 收款退还
  24566. * 751 酒店早餐
  24567. * 1015 超支费用
  24568. */
  24569. switch (dto.CTable)
  24570. {
  24571. case 76: // 酒店预订
  24572. _ModuleSubPromptInfo.AddRange(
  24573. _GroupCostsTypeData.Select(it => new
  24574. {
  24575. it.DAY,
  24576. it.Date,
  24577. it.ACCON,
  24578. it.ITIN,
  24579. it.SGR,
  24580. it.TBR,
  24581. it.JS_ES,
  24582. it.Suite
  24583. })
  24584. );
  24585. break;
  24586. case 79: // 车/导游地接
  24587. _ModuleSubPromptInfo.AddRange(
  24588. _GroupCostsTypeData.Select(it => new
  24589. {
  24590. Date = it.Date, //日期
  24591. CarFee = it.CarCost * _rate * _scale, //车费用
  24592. CarType = it.CarType, //车型
  24593. DriverFee = it.CFS * _rate * _scale, //司机工资
  24594. DriverTipsFee = it.DRVTips * _rate * _scale, //司机小费
  24595. DriverMealSubsidy = it.CFM * _rate * _scale, //司机餐补
  24596. DriverOvertimeFee = it.CFOF * _rate * _scale, //司机超时费用
  24597. GuideFee = it.TGS * _rate * _scale, //导游费用
  24598. GuideOvertimeFee = it.TGOF * _rate * _scale, //导游超时费用
  24599. GuideMealSubsidy = it.TGM * _rate * _scale, //导游餐补
  24600. GuideRoomSubsidy = it.TGA * _rate * _scale, //导游房补
  24601. GuideCarFare = it.TGTF * _rate * _scale, //导游交通费
  24602. GuideSpotFee = it.TGEF * _rate * _scale, //导游景点费
  24603. GuideTipsFee = it.TGTips * _rate * _scale, //导游小费
  24604. Breakfast = it.B * _rate * _scale, //早餐费
  24605. Lunch = it.L * _rate * _scale, //午餐费
  24606. Dinner = it.D * _rate * _scale, //晚餐费
  24607. OfficialActivitiesFee = it.TV * _rate * _scale,//会务活动费 --新加
  24608. OfficialTransFee = it.IF * _rate * _scale, //公务翻译费 --新加
  24609. InvitationFee = it.iL * _rate * _scale, //邀请函费用 --新加
  24610. TicketFee = it.EF * _rate * _scale, //门票费
  24611. TicketRemark = it.EFR, //门票费描述
  24612. DrinksSnacksFruitFee = it.B_R_F * _rate * _scale, //饮料零食水果
  24613. TravelSupplies = it.TE * _rate * _scale, //出行物资
  24614. SpentCash = it.PC * _rate * _scale, //零用金
  24615. LeadersFee = it.TLF * _rate * _scale, //领队费
  24616. ActivitiesFee = it.ECT * _rate * _scale, //会务费 --新加
  24617. })
  24618. );
  24619. break;
  24620. case 85: // 机票
  24621. List<dynamic> datas = new List<dynamic>();
  24622. datas.Add(
  24623. new
  24624. {
  24625. AirType = "经济舱",
  24626. AirNum = item.JJCRS,
  24627. AirDRCB = item.JJCCB,
  24628. AirZCB = (item.JJCRS * item.JJCCB)
  24629. }
  24630. );
  24631. datas.Add(
  24632. new
  24633. {
  24634. AirType = "公务舱",
  24635. AirNum = item.GWCRS,
  24636. AirDRCB = item.GWCCB,
  24637. AirZCB = (item.GWCRS * item.GWCCB)
  24638. }
  24639. );
  24640. var groupCosts = _usersRep._sqlSugar.Queryable<Grp_GroupCost>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  24641. var initDatas = groupCosts.Select(it => new { date = it.Date, week = it.Date.GetWeek() == "" ? "-" : it.Date.GetWeek(), itinerary = it.ITIN }).ToList();
  24642. modulePromptInfo.Data = new
  24643. {
  24644. airFeeData = datas,
  24645. airInitData = initDatas
  24646. };
  24647. _ModulePromptInfos.Add(modulePromptInfo);
  24648. break;
  24649. default:
  24650. break;
  24651. }
  24652. }
  24653. if (dto.CTable != 85)
  24654. {
  24655. _ModulePromptInfo.Data = _ModuleSubPromptInfo;
  24656. _ModulePromptInfos.Add(_ModulePromptInfo);
  24657. }
  24658. _view.ModulePromptInfos = _ModulePromptInfos;
  24659. return Ok(JsonView(true, "操作成功!", _view));
  24660. }
  24661. catch (Exception ex)
  24662. {
  24663. return Ok(JsonView(false, ex.Message));
  24664. }
  24665. }
  24666. /// <summary>
  24667. /// 根据黑屏代码重新生成行程
  24668. /// </summary>
  24669. /// <param name="dto"></param>
  24670. /// <returns></returns>
  24671. [HttpPost]
  24672. public IActionResult CraeteGroupCostTravel(GroupCostInItDto dto)
  24673. {
  24674. var jw = JsonView(false, "Error");
  24675. var Create = _sqlSugar.Queryable<Air_TicketBlackCode>()
  24676. .Where(x => x.IsDel == 0 && x.DiId == dto.Diid)
  24677. .Select(x => new
  24678. {
  24679. x.Id,
  24680. x.Title
  24681. })
  24682. .ToList();
  24683. if (Create.Any())
  24684. {
  24685. jw.Msg = "获取成功!";
  24686. jw.Code = 200;
  24687. jw.Data = new
  24688. {
  24689. BlackCodeListSelect = Create,
  24690. blackCodeIsTrue = true
  24691. };
  24692. }
  24693. else
  24694. {
  24695. jw.Code = 400;
  24696. jw.Data = new
  24697. {
  24698. BlackCodeListSelect = Create,
  24699. blackCodeIsTrue = false,
  24700. };
  24701. }
  24702. return Ok(jw);
  24703. }
  24704. /// <summary>
  24705. /// 根据黑屏代码Id重新生成行程
  24706. /// </summary>
  24707. /// <param name="dto"></param>
  24708. /// <returns></returns>
  24709. [HttpPost]
  24710. public IActionResult CraeteGroupCostTravelById(CraeteGroupCostTravelByIdDto dto)
  24711. {
  24712. var jw = JsonView(false, "Error");
  24713. var result = _GroupCostRepository.CreateGroupCostByBlackCode(dto.DiId, dto.BlackCodeId);
  24714. if (result.Code == 0)
  24715. {
  24716. jw.Msg = "获取成功!";
  24717. jw.Code = 200;
  24718. jw.Data = new
  24719. {
  24720. groupCost = result.Data,
  24721. blackCodeIsTrue = true
  24722. };
  24723. }
  24724. else
  24725. {
  24726. jw.Code = 400;
  24727. jw.Data = new
  24728. {
  24729. groupCost = result.Data,
  24730. blackCodeIsTrue = false,
  24731. };
  24732. }
  24733. return Ok(jw);
  24734. }
  24735. /// <summary>
  24736. /// 成本获取OP历史车费用
  24737. /// </summary>
  24738. /// <param name="dto"></param>
  24739. /// <returns></returns>
  24740. [HttpPost]
  24741. public async Task<IActionResult> GetHistoryCarData(HistoryCarDataDto dto)
  24742. {
  24743. var jw = JsonView(false);
  24744. try
  24745. {
  24746. List<HistoryCarDataView> dbResult = new List<HistoryCarDataView>();
  24747. //获取现有所有车的数据
  24748. if (!dto.Param.IsNullOrWhiteSpace())
  24749. {
  24750. string sql = $@"
  24751. SELECT gdi.TeamName , gctggr.Area, gctggr.PriceName , gctggrc.Id ,gctggrc.Price , gctggrc.DatePrice , gctggrc.PriceContent , gctggrc.Currency , gctggr.ServiceStartTime , gctggr.ServiceEndTime
  24752. FROM Grp_CarTouristGuideGroundReservationsContent gctggrc inner join Grp_CarTouristGuideGroundReservations gctggr on
  24753. gctggrc.CTGGRId = gctggr.Id inner JOIN Grp_DelegationInfo gdi on gctggr.DiId = gdi.Id LEFT JOIN Sys_SetData ssd on ssd.Id = gctggr.PriceType
  24754. WHERE gctggr.IsDel = 0 and gctggrc.SId = 91 AND gdi.IsDel = 0 AND gctggrc.Price != 0 AND (ssd.Id in (1061,1069) or ssd.Id is NULL) AND gctggr.ServiceStartTime is not null
  24755. AND gctggr.ServiceEndTime is not NULL
  24756. ORDER by gctggrc.id DESC
  24757. ";
  24758. dbResult = await _sqlSugar.SqlQueryable<HistoryCarDataView>(sql).ToListAsync();
  24759. var numeberResult = await Task.Run(() =>
  24760. {
  24761. var numberArr = dbResult.Where(x => int.TryParse(x.Area, out int number)).ToList();
  24762. _ = dbResult.RemoveAll(x => int.TryParse(x.Area, out int number));
  24763. return numberArr;
  24764. });
  24765. var cityArr = await _sqlSugar.Queryable<Grp_NationalTravelFee>().ToListAsync();
  24766. foreach (var item in numeberResult)
  24767. {
  24768. var find = cityArr.Find(x => x.Id == int.Parse(item.Area)) ?? new Grp_NationalTravelFee
  24769. {
  24770. Country = "数据异常!",
  24771. City = string.Empty,
  24772. };
  24773. item.Area = find.Country + " " + find.City;
  24774. }
  24775. dbResult.AddRange(numeberResult);
  24776. if (dto.Param.Contains("、"))
  24777. {
  24778. var sp = dto.Param.Split("、");
  24779. dbResult = dbResult.AsParallel().WithDegreeOfParallelism(Environment.ProcessorCount)
  24780. .Where(x =>
  24781. {
  24782. return System.Array.Exists(sp, e =>
  24783. {
  24784. bool where = false;
  24785. if (x.Area != null)
  24786. {
  24787. where = x.Area.Contains(e);
  24788. if (x.Area.Contains("尾款") || x.PriceName.Contains("尾款"))
  24789. {
  24790. return false;
  24791. }
  24792. }
  24793. if (x.PriceName != null && !where)
  24794. {
  24795. where = x.PriceName.Contains(e);
  24796. if (x.PriceName.Contains("尾款") || x.PriceName.Contains("尾款"))
  24797. {
  24798. return false;
  24799. }
  24800. }
  24801. return where;
  24802. });
  24803. }).ToList();
  24804. }
  24805. else
  24806. {
  24807. dbResult = dbResult.AsParallel().WithDegreeOfParallelism(Environment.ProcessorCount)
  24808. .Where(x =>
  24809. {
  24810. bool where = false;
  24811. if (x.Area != null)
  24812. {
  24813. where = x.Area.Contains(dto.Param);
  24814. if (x.Area.Contains("尾款") || x.PriceName.Contains("尾款"))
  24815. {
  24816. return false;
  24817. }
  24818. }
  24819. if (x.PriceName != null && !where)
  24820. {
  24821. where = x.PriceName.Contains(dto.Param);
  24822. if (x.PriceName.Contains("尾款") || x.PriceName.Contains("尾款"))
  24823. {
  24824. return false;
  24825. }
  24826. }
  24827. return where;
  24828. }
  24829. )
  24830. .ToList();
  24831. }
  24832. }
  24833. var view = dbResult.Select(x =>
  24834. {
  24835. decimal dp = 0.00M;
  24836. var startB = DateTime.TryParse(x.Start.ToString(), out DateTime startD);
  24837. var endB = DateTime.TryParse(x.End.ToString(), out DateTime endD);
  24838. if (string.IsNullOrWhiteSpace(x.DatePrice))
  24839. {
  24840. if (startB && endB)
  24841. {
  24842. var timesp = endD.Subtract(startD);
  24843. if ((timesp.Days + 1) != 0)
  24844. {
  24845. dp = x.Price / (timesp.Days + 1);
  24846. }
  24847. }
  24848. }
  24849. else
  24850. {
  24851. dp = x.Price;
  24852. }
  24853. return new
  24854. {
  24855. start = startB ? startD.ToString("yyyy-MM-dd") : "",
  24856. end = endB ? endD.ToString("yyyy-MM-dd") : "",
  24857. x.Area,
  24858. x.id,
  24859. price = x.Price.ToString("F2"),
  24860. x.PriceName,
  24861. x.PriceContent,
  24862. x.TeamName,
  24863. x.DatePrice,
  24864. dayPrice = dp.ToString("F2"),
  24865. };
  24866. }).OrderByDescending(x => x.id).ToList();
  24867. jw = JsonView(true, "获取成功!", view);
  24868. }
  24869. catch (Exception e)
  24870. {
  24871. jw = JsonView(false, e.Message);
  24872. }
  24873. return Ok(jw);
  24874. }
  24875. [HttpPost]
  24876. public async Task<IActionResult> SearchGroupByKeyword(SearchGroupByKeywordDto dto)
  24877. {
  24878. var jw = JsonView(true);
  24879. List<DelegationInfoAndIsTrueView> matches = new List<DelegationInfoAndIsTrueView>();
  24880. #region SQL语句
  24881. //if (string.IsNullOrWhiteSpace(dto.Keyword))
  24882. //{
  24883. // matches = _sqlSugar.SqlQueryable<DelegationInfoAndIsTrueView>($@"
  24884. // Select a.Id,TeamName GroupName,b.isTrue From Grp_DelegationInfo a left join (select top 100 percent Diid, CASE
  24885. // WHEN COUNT(*) >= 0 THEN 'True'
  24886. // ELSE 'False' END as isTrue from Grp_GroupCost where Isdel = 0 and date != '' group by Diid) b on a.Id = b.Diid
  24887. // Where TeamName != '' And IsDel = 0 Order By a.VisitStartDate Desc
  24888. // ")
  24889. // .ToList();
  24890. //}
  24891. //else
  24892. //{
  24893. // string likeKey = string.Empty;
  24894. // foreach (var item in dto.Keyword)
  24895. // {
  24896. // likeKey += "%" + item;
  24897. // }
  24898. // likeKey += "%";
  24899. // matches = _sqlSugar.SqlQueryable<DelegationInfoAndIsTrueView>($@"
  24900. // Select a.Id,TeamName GroupName,b.isTrue From Grp_DelegationInfo a left join (select top 100 percent Diid, CASE
  24901. // WHEN COUNT(*) >= 0 THEN 'True'
  24902. // ELSE 'False' END as isTrue from Grp_GroupCost where Isdel = 0 and date != '' group by Diid) b on a.Id = b.Diid
  24903. // Where TeamName != '' And IsDel = 0 And TeamName LIKE '{likeKey}' Order By a.VisitStartDate Desc
  24904. // ")
  24905. // .ToList();
  24906. //}
  24907. #endregion
  24908. var table = _sqlSugar.Ado.UseStoredProcedure().GetDataTable("SearchGroupByKeyword", new
  24909. {
  24910. @KeyWord = dto.Keyword
  24911. });
  24912. if (table != null && table.Rows.Count > 0)
  24913. {
  24914. foreach (DataRow row in table.Rows)
  24915. {
  24916. matches.Add(new DelegationInfoAndIsTrueView
  24917. {
  24918. Id = row.Field<int>("Id"),
  24919. GroupName = row.Field<string>("GroupName"),
  24920. isTrue = row.Field<string>("isTrue")
  24921. });
  24922. }
  24923. }
  24924. if (matches.Any())
  24925. {
  24926. jw.Data = matches;
  24927. }
  24928. else
  24929. {
  24930. jw.Code = 201;
  24931. jw.Msg = "empty list";
  24932. jw.Data = new List<string>(1);
  24933. }
  24934. return Ok(jw);
  24935. }
  24936. /// <summary>
  24937. /// 报价Word下载
  24938. /// </summary>
  24939. /// <param name="dto"></param>
  24940. /// <returns></returns>
  24941. [HttpPost]
  24942. public async Task<IActionResult> GroupQuotationsFileDown(GroupQuotationsFileDownDto dto)
  24943. {
  24944. var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  24945. .FirstAsync(x => x.Id == dto.Diid && x.IsDel == 0);
  24946. if (di == null)
  24947. {
  24948. return Ok(JsonView(false, "团组不存在!"));
  24949. }
  24950. var mainPrice = _GroupCostParameterRepository.GetGroupCostParameterMainByDiid(dto.Diid);
  24951. if (mainPrice == null || mainPrice.IsShare == 0)
  24952. {
  24953. return Ok(JsonView(false, "团组成本不存在!"));
  24954. }
  24955. var costTypeHotelNumbers = await _sqlSugar.Queryable<Grp_CostTypeHotelNumber>()
  24956. .FirstAsync(x => x.Type == "Default" && x.Diid == dto.Diid && x.IsDel == 0);
  24957. if (costTypeHotelNumbers == null)
  24958. {
  24959. return Ok(JsonView(false, "团组成本不存在!"));
  24960. }
  24961. //文件名
  24962. string strFileName = di.TeamName + "-收款账单.doc";
  24963. //获取模板
  24964. string tmppath = (AppSettingsHelper.Get("WordBasePath") + "Template/收款账单(四川)模板.doc");
  24965. //载入模板
  24966. Document doc = new Document(tmppath);
  24967. decimal allPrice = 0.00M;
  24968. string itemStr = string.Empty;
  24969. Dictionary<string, string> airSouer = new Dictionary<string, string>();
  24970. airSouer.Add("经济舱TBR", "经济舱及酒店双人间");
  24971. airSouer.Add("经济舱SGR", "经济舱及酒店单人间");
  24972. airSouer.Add("公务舱SGR", "公务舱及酒店单人间");
  24973. airSouer.Add("公务舱JSES", "公务舱及酒店小套房");
  24974. airSouer.Add("公务舱SUITE", "公务舱及酒店套房");
  24975. airSouer.Add("经济舱SUITE", "经济舱及酒店套房");
  24976. airSouer.Add("头等舱JSES", "头等舱及酒店小套房");
  24977. airSouer.Add("头等舱SUITE", "头等舱及酒店套房");
  24978. airSouer.Add("经济舱JSES", "经济舱及酒店小套房");
  24979. var priceDataList = new List<(string rsName, string cbName, string xsName, string prefix)>
  24980. {
  24981. ("VisaRS", "VisaCB", "VisaXS", "qz"),
  24982. ("BXRS", "BXCB", "BXXS", "bx"),
  24983. ("HCPRS", "HCPCB", "HCPXS", "hcp"),
  24984. ("JJCRS", "JJCCB", "JJCXS", "jjc"),
  24985. ("GWCRS", "GWCCB", "GWCXS", "gwc"),
  24986. ("TDCRS", "TDCCB", "TDCXS", "tdc"),
  24987. ("CPRS", "CPCB", "CPXS", "cp"),
  24988. ("HSRS", "HSCB", "HSXS", "hsjc"),
  24989. ("TBRNumber", "TBRCB", "TBRXS", "tbr"),
  24990. ("SGRNumber", "SGRCB", "SGRXS", "sgr"),
  24991. ("JSESNumber", "JSESCB", "JSESXS", "jses"),
  24992. ("SUITENumber", "SUITECB", "SUITEXS", "suite"),
  24993. ("DJRS", "DJCB", "DJXS", "dj"),
  24994. ("GWRS", "GWCB", "GWXS", "gw"),
  24995. ("LYJRS", "LYJCB", "LYJXS", "lyj"),
  24996. };
  24997. var OtherCostPropertyBJ = new string[] { "qz", "hcp", "cp", "bx", "hsjc", "dj", "gw", "lyj" };
  24998. var rightSum = 0.00M;
  24999. foreach (var (rsName, cbName, xsName, prefix) in priceDataList)
  25000. {
  25001. var rsValue = (int)mainPrice.GetType().GetProperty(rsName).GetValue(mainPrice);
  25002. var cbValue = (decimal)mainPrice.GetType().GetProperty(cbName).GetValue(mainPrice);
  25003. var xsValue = (decimal)mainPrice.GetType().GetProperty(xsName).GetValue(mainPrice);
  25004. if (prefix == "tbr")
  25005. {
  25006. rsValue *= 2;
  25007. cbValue /= 2;
  25008. }
  25009. if (OtherCostPropertyBJ.Contains(prefix))
  25010. {
  25011. rightSum += cbValue * xsValue;
  25012. }
  25013. }
  25014. var hotelRooms = new Dictionary<string, int>
  25015. {
  25016. { "SGR", costTypeHotelNumbers.SGR },
  25017. { "TBR", costTypeHotelNumbers.TBR },
  25018. { "JSES", costTypeHotelNumbers.JSES },
  25019. { "SUITE", costTypeHotelNumbers.SUITE }
  25020. };
  25021. var flights = new Dictionary<string, int>
  25022. {
  25023. { "经济舱", mainPrice.JJCRS },
  25024. { "公务舱", mainPrice.GWCRS },
  25025. { "头等舱", mainPrice.TDCRS }
  25026. };
  25027. var flightRoomMatchingRules = new Dictionary<string, string[]>
  25028. {
  25029. { "经济舱", new[] { "TBR", "SGR", "JSES", "SUITE" } },
  25030. { "公务舱", new[] { "SUITE", "JSES", "SGR" } },
  25031. { "头等舱", new[] { "SUITE", "JSES" } }
  25032. };
  25033. var result = new Dictionary<string, int>();
  25034. List<AirHotelPrice> airHotelPriceList = new List<AirHotelPrice>();
  25035. foreach (var flight in flights.Keys)
  25036. {
  25037. // 获取当前舱位的匹配规则
  25038. if (flightRoomMatchingRules.TryGetValue(flight, out string[] roomTypes))
  25039. {
  25040. MatchRooms(ref hotelRooms, ref flights, roomTypes, flight, ref result);
  25041. }
  25042. }
  25043. #region right计算
  25044. if (result.Keys.Contains("经济舱TBR") && result["经济舱TBR"] > 0)
  25045. {
  25046. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  25047. var hotel = (mainPrice.TBRCB * mainPrice.TBRXS) / 2;
  25048. airHotelPriceList.Add(new
  25049. AirHotelPrice
  25050. {
  25051. Name = "经济舱TBR",
  25052. Price = rightSum + air + hotel,
  25053. Count = result["经济舱TBR"] * 2
  25054. });
  25055. allPrice += (rightSum + air + hotel) * result["经济舱TBR"] * 2;
  25056. }
  25057. if (result.Keys.Contains("经济舱SGR") && result["经济舱SGR"] > 0)
  25058. {
  25059. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  25060. var hotel = mainPrice.SGRCB * mainPrice.SGRXS;
  25061. airHotelPriceList.Add(new
  25062. AirHotelPrice
  25063. {
  25064. Name = "经济舱SGR",
  25065. Price = rightSum + air + hotel,
  25066. Count = result["经济舱SGR"]
  25067. });
  25068. allPrice += (rightSum + air + hotel) * result["经济舱SGR"];
  25069. }
  25070. if (result.Keys.Contains("公务舱SGR") && result["公务舱SGR"] > 0)
  25071. {
  25072. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  25073. var hotel = mainPrice.SGRCB * mainPrice.SGRXS;
  25074. airHotelPriceList.Add(new
  25075. AirHotelPrice
  25076. {
  25077. Name = "公务舱SGR",
  25078. Price = rightSum + air + hotel,
  25079. Count = result["公务舱SGR"]
  25080. });
  25081. allPrice += (rightSum + air + hotel) * result["公务舱SGR"];
  25082. }
  25083. if (result.Keys.Contains("公务舱JSES") && result["公务舱JSES"] > 0)
  25084. {
  25085. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  25086. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  25087. airHotelPriceList.Add(new
  25088. AirHotelPrice
  25089. {
  25090. Name = "公务舱JSES",
  25091. Price = rightSum + air + hotel,
  25092. Count = result["公务舱JSES"]
  25093. });
  25094. allPrice += (rightSum + air + hotel) * result["公务舱JSES"];
  25095. }
  25096. if (result.Keys.Contains("公务舱SUITE") && result["公务舱SUITE"] > 0)
  25097. {
  25098. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  25099. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  25100. airHotelPriceList.Add(new
  25101. AirHotelPrice
  25102. {
  25103. Name = "公务舱SUITE",
  25104. Price = rightSum + air + hotel,
  25105. Count = result["公务舱SUITE"]
  25106. });
  25107. allPrice += (rightSum + air + hotel) * result["公务舱SUITE"];
  25108. }
  25109. if (result.Keys.Contains("经济舱SUITE") && result["经济舱SUITE"] > 0)
  25110. {
  25111. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  25112. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  25113. airHotelPriceList.Add(new
  25114. AirHotelPrice
  25115. {
  25116. Name = "经济舱SUITE",
  25117. Price = rightSum + air + hotel,
  25118. Count = result["经济舱SUITE"]
  25119. });
  25120. allPrice += (rightSum + air + hotel) * result["经济舱SUITE"];
  25121. }
  25122. if (result.Keys.Contains("头等舱JSES") && result["头等舱JSES"] > 0)
  25123. {
  25124. var air = mainPrice.TDCCB * mainPrice.TDCXS;
  25125. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  25126. airHotelPriceList.Add(new
  25127. AirHotelPrice
  25128. {
  25129. Name = "头等舱JSES",
  25130. Price = rightSum + air + hotel,
  25131. Count = result["头等舱JSES"]
  25132. });
  25133. allPrice += (rightSum + air + hotel) * result["头等舱JSES"];
  25134. }
  25135. if (result.Keys.Contains("头等舱SUITE") && result["头等舱SUITE"] > 0)
  25136. {
  25137. var air = mainPrice.TDCCB * mainPrice.TDCXS;
  25138. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  25139. airHotelPriceList.Add(new
  25140. AirHotelPrice
  25141. {
  25142. Name = "头等舱SUITE",
  25143. Price = rightSum + air + hotel,
  25144. Count = result["头等舱SUITE"]
  25145. });
  25146. allPrice += (rightSum + air + hotel) * result["头等舱SUITE"];
  25147. }
  25148. if (result.Keys.Contains("经济舱JSES") && result["经济舱JSES"] > 0)
  25149. {
  25150. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  25151. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  25152. airHotelPriceList.Add(new
  25153. AirHotelPrice
  25154. {
  25155. Name = "经济舱JSES",
  25156. Price = rightSum + air + hotel,
  25157. Count = result["经济舱JSES"]
  25158. });
  25159. allPrice += (rightSum + air + hotel) * result["经济舱JSES"];
  25160. }
  25161. #endregion
  25162. foreach (var item in airSouer.Keys)
  25163. {
  25164. var find = airHotelPriceList.FirstOrDefault(x => x.Name == item);
  25165. if (find != null && find.Count > 0)
  25166. {
  25167. if (item.Contains("TBR"))
  25168. {
  25169. itemStr += "团费(" + airSouer[item] + ") RMB " + find.Price.ToString("F2") + "/人*" + find.Count + "(" + (find.Count / 2) + "间) ............合计 RMB " + (find.Count * find.Price).ToString("#0.00") + "\n";
  25170. }
  25171. else
  25172. {
  25173. itemStr += "团费(" + airSouer[item] + ") RMB " + find.Price.ToString("F2") + "/人*" + find.Count + "(" + find.Count + "间) ............合计 RMB " + (find.Count * find.Price).ToString("#0.00") + "\n";
  25174. }
  25175. }
  25176. }
  25177. #region 替换Word模板书签内容
  25178. Dictionary<string, string> marks = new Dictionary<string, string>();
  25179. marks.Add("To", di.ClientUnit);//付款方
  25180. marks.Add("ToTel", di.TellPhone);//付款方电话
  25181. marks.Add("Date", DateTime.Now.ToString("yyyy-MM-dd"));//导出时间
  25182. marks.Add("Team", di.VisitCountry.Replace(" ", "、"));//团队名称
  25183. marks.Add("TontractTime", (di.VisitDate).ToString("yyyy年MM月dd日"));//付款日期
  25184. marks.Add("PayDay", (di.PayDay).ToString());//付款预期
  25185. marks.Add("PaymentMoney", (di.PaymentMoney).ToString("#0.00"));//付款金额
  25186. marks.Add("WeChat", di.WeChatNo ?? "");//微信号
  25187. marks.Add("PayItemContent", itemStr);//详细信息
  25188. marks.Add("Total", allPrice.ToString("F2"));//合计
  25189. #endregion
  25190. foreach (var item in marks.Keys)
  25191. {
  25192. if (doc.Range.Bookmarks[item] != null)
  25193. {
  25194. Bookmark mark = doc.Range.Bookmarks[item];
  25195. mark.Text = marks[item];
  25196. }
  25197. }
  25198. string savePaht = $"{AppSettingsHelper.Get("WordBasePath")}GroupCostQuotations/{di.TeamName}_报批费用.doc";
  25199. doc.Save(savePaht);
  25200. var jw = new JsonView();
  25201. jw.Msg = "生成成功!";
  25202. jw.Code = 200;
  25203. jw.Data = new { Url = AppSettingsHelper.Get("WordBaseUrl") + savePaht.Replace(AppSettingsHelper.Get("WordBasePath"), AppSettingsHelper.Get("WordFtpPath")) };
  25204. return Ok(jw);
  25205. }
  25206. /// <summary>
  25207. /// 详细报价费用Excel下载
  25208. /// </summary>
  25209. /// <param name="dto"></param>
  25210. /// <returns></returns>
  25211. [HttpPost]
  25212. public async Task<IActionResult> GroupQuotationsDetailFileDown(GroupQuotationsFileDownDto dto)
  25213. {
  25214. var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  25215. .FirstAsync(x => x.Id == dto.Diid && x.IsDel == 0);
  25216. if (di == null)
  25217. {
  25218. return Ok(JsonView(false, "团组不存在!"));
  25219. }
  25220. var mainPrice = _GroupCostParameterRepository.GetGroupCostParameterMainByDiid(dto.Diid);
  25221. if (mainPrice == null || mainPrice.IsShare == 0)
  25222. {
  25223. return Ok(JsonView(false, "团组成本不存在!"));
  25224. }
  25225. var costTypeHotelNumbers = await _sqlSugar.Queryable<Grp_CostTypeHotelNumber>()
  25226. .FirstAsync(x => x.Type == "Default" && x.Diid == dto.Diid && x.IsDel == 0);
  25227. if (costTypeHotelNumbers == null)
  25228. {
  25229. return Ok(JsonView(false, "团组成本不存在!"));
  25230. }
  25231. WorkbookDesigner designer = new WorkbookDesigner();
  25232. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + ("Template/报价详细表.xls"));
  25233. List<int> hideRowsList = new List<int>();
  25234. int conterStartIndex = 3;
  25235. int rowIndex = conterStartIndex;
  25236. designer.SetDataSource("GroupName", di.TeamName);
  25237. var priceDataList = new List<(string rsName, string cbName, string xsName, string prefix)>
  25238. {
  25239. ("VisaRS", "VisaCB", "VisaXS", "qz"),
  25240. ("BXRS", "BXCB", "BXXS", "bx"),
  25241. ("HCPRS", "HCPCB", "HCPXS", "hcp"),
  25242. ("JJCRS", "JJCCB", "JJCXS", "jjc"),
  25243. ("GWCRS", "GWCCB", "GWCXS", "gwc") ,
  25244. ("TDCRS", "TDCCB", "TDCXS", "tdc") ,
  25245. ("CPRS", "CPCB", "CPXS", "cp") ,
  25246. ("HSRS", "HSCB", "HSXS", "hsjc") ,
  25247. ("TBRNumber", "TBRCB", "TBRXS", "tbr") ,
  25248. ("SGRNumber", "SGRCB", "SGRXS", "sgr") ,
  25249. ("JSESNumber", "JSESCB", "JSESXS", "jses") ,
  25250. ("SUITENumber", "SUITECB", "SUITEXS", "suite") ,
  25251. ("DJRS", "DJCB", "DJXS", "dj") ,
  25252. ("GWRS", "GWCB", "GWXS", "gw") ,
  25253. ("LYJRS", "LYJCB", "LYJXS", "lyj") ,
  25254. };
  25255. var OtherCostPropertyBJ = new string[] { "qz", "hcp", "cp", "bx", "hsjc", "dj", "gw", "lyj" };
  25256. var rightSum = 0.00M;
  25257. foreach (var (rsName, cbName, xsName, prefix) in priceDataList)
  25258. {
  25259. var rsValue = (int)mainPrice.GetType().GetProperty(rsName).GetValue(mainPrice);
  25260. var cbValue = (decimal)mainPrice.GetType().GetProperty(cbName).GetValue(mainPrice);
  25261. var xsValue = (decimal)mainPrice.GetType().GetProperty(xsName).GetValue(mainPrice);
  25262. if (prefix == "tbr")
  25263. {
  25264. rsValue *= 2;
  25265. cbValue /= 2;
  25266. }
  25267. if (OtherCostPropertyBJ.Contains(prefix))
  25268. {
  25269. rightSum += cbValue * xsValue;
  25270. }
  25271. if (rsValue == 0)
  25272. {
  25273. hideRowsList.Add(rowIndex);
  25274. }
  25275. else
  25276. {
  25277. designer.SetDataSource($"{prefix}rs", rsValue);
  25278. designer.SetDataSource($"{prefix}bj", cbValue * xsValue);
  25279. designer.SetDataSource($"{prefix}zbj", cbValue * xsValue * rsValue);
  25280. }
  25281. rowIndex += 2;
  25282. }
  25283. var hotelRooms = new Dictionary<string, int>
  25284. {
  25285. { "SGR", costTypeHotelNumbers.SGR },
  25286. { "TBR", costTypeHotelNumbers.TBR },
  25287. { "JSES", costTypeHotelNumbers.JSES },
  25288. { "SUITE", costTypeHotelNumbers.SUITE }
  25289. };
  25290. var flights = new Dictionary<string, int>
  25291. {
  25292. { "经济舱", mainPrice.JJCRS },
  25293. { "公务舱", mainPrice.GWCRS },
  25294. { "头等舱", mainPrice.TDCRS }
  25295. };
  25296. var flightRoomMatchingRules = new Dictionary<string, string[]>
  25297. {
  25298. { "经济舱", new[] { "TBR", "SGR", "JSES", "SUITE" } },
  25299. { "公务舱", new[] { "SUITE", "JSES", "SGR" } },
  25300. { "头等舱", new[] { "SUITE", "JSES" } }
  25301. };
  25302. var result = new Dictionary<string, int>();
  25303. foreach (var flight in flights.Keys)
  25304. {
  25305. // 获取当前舱位的匹配规则
  25306. if (flightRoomMatchingRules.TryGetValue(flight, out string[] roomTypes))
  25307. {
  25308. MatchRooms(ref hotelRooms, ref flights, roomTypes, flight, ref result);
  25309. }
  25310. }
  25311. var allPrice = 0.00M;
  25312. #region right计算
  25313. int airRowIndex = 35;
  25314. if (result.Keys.Contains("经济舱TBR") && result["经济舱TBR"] > 0)
  25315. {
  25316. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  25317. var hotel = (mainPrice.TBRCB * mainPrice.TBRXS) / 2;
  25318. designer.SetDataSource("jjctbrrs", result["经济舱TBR"] * 2);
  25319. designer.SetDataSource("jjctbrbj", rightSum + air + hotel);
  25320. designer.SetDataSource("jjctbrzbj", (rightSum + air + hotel) * result["经济舱TBR"] * 2);
  25321. allPrice += (rightSum + air + hotel) * result["经济舱TBR"] * 2;
  25322. }
  25323. else
  25324. {
  25325. hideRowsList.Add(airRowIndex);
  25326. }
  25327. airRowIndex += 2;
  25328. if (result.Keys.Contains("经济舱SGR") && result["经济舱SGR"] > 0)
  25329. {
  25330. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  25331. var hotel = mainPrice.SGRCB * mainPrice.SGRXS;
  25332. designer.SetDataSource("jjcsgrrs", result["经济舱SGR"]);
  25333. designer.SetDataSource("jjcsgrbj", rightSum + air + hotel);
  25334. designer.SetDataSource("jjcsgrzbj", (rightSum + air + hotel) * result["经济舱SGR"]);
  25335. allPrice += (rightSum + air + hotel) * result["经济舱SGR"];
  25336. }
  25337. else
  25338. {
  25339. hideRowsList.Add(airRowIndex);
  25340. }
  25341. airRowIndex += 2;
  25342. if (result.Keys.Contains("公务舱SGR") && result["公务舱SGR"] > 0)
  25343. {
  25344. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  25345. var hotel = mainPrice.SGRCB * mainPrice.SGRXS;
  25346. designer.SetDataSource("gwcsgrrs", result["公务舱SGR"]);
  25347. designer.SetDataSource("gwcsgrbj", rightSum + air + hotel);
  25348. designer.SetDataSource("gwcsgrzbj", (rightSum + air + hotel) * result["公务舱SGR"]);
  25349. allPrice += (rightSum + air + hotel) * result["公务舱SGR"];
  25350. }
  25351. else
  25352. {
  25353. hideRowsList.Add(airRowIndex);
  25354. }
  25355. airRowIndex += 2;
  25356. if (result.Keys.Contains("公务舱JSES") && result["公务舱JSES"] > 0)
  25357. {
  25358. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  25359. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  25360. designer.SetDataSource("gwcjsesrs", result["公务舱JSES"]);
  25361. designer.SetDataSource("gwcjsesbj", rightSum + air + hotel);
  25362. designer.SetDataSource("gwcjseszbj", (rightSum + air + hotel) * result["公务舱JSES"]);
  25363. allPrice += (rightSum + air + hotel) * result["公务舱JSES"];
  25364. }
  25365. else
  25366. {
  25367. hideRowsList.Add(airRowIndex);
  25368. }
  25369. airRowIndex += 2;
  25370. if (result.Keys.Contains("公务舱SUITE") && result["公务舱SUITE"] > 0)
  25371. {
  25372. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  25373. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  25374. designer.SetDataSource("gwcsuiters", result["公务舱SUITE"]);
  25375. designer.SetDataSource("gwcsuitebj", rightSum + air + hotel);
  25376. designer.SetDataSource("gwcsuitezbj", (rightSum + air + hotel) * result["公务舱SUITE"]);
  25377. allPrice += (rightSum + air + hotel) * result["公务舱SUITE"];
  25378. }
  25379. else
  25380. {
  25381. hideRowsList.Add(airRowIndex);
  25382. }
  25383. airRowIndex += 2;
  25384. if (result.Keys.Contains("经济舱SUITE") && result["经济舱SUITE"] > 0)
  25385. {
  25386. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  25387. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  25388. designer.SetDataSource("jjcsuiters", result["经济舱SUITE"]);
  25389. designer.SetDataSource("jjcsuitebj", rightSum + air + hotel);
  25390. designer.SetDataSource("jjcsuitezbj", (rightSum + air + hotel) * result["经济舱SUITE"]);
  25391. allPrice += (rightSum + air + hotel) * result["经济舱SUITE"];
  25392. }
  25393. else
  25394. {
  25395. hideRowsList.Add(airRowIndex);
  25396. }
  25397. airRowIndex += 2;
  25398. if (result.Keys.Contains("头等舱JSES") && result["头等舱JSES"] > 0)
  25399. {
  25400. var air = mainPrice.TDCCB * mainPrice.TDCXS;
  25401. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  25402. designer.SetDataSource("tdcjsesrs", result["头等舱JSES"]);
  25403. designer.SetDataSource("tdcjsesbj", rightSum + air + hotel);
  25404. designer.SetDataSource("tdcjseszbj", (rightSum + air + hotel) * result["头等舱JSES"]);
  25405. allPrice += (rightSum + air + hotel) * result["头等舱JSES"];
  25406. }
  25407. else
  25408. {
  25409. hideRowsList.Add(airRowIndex);
  25410. }
  25411. airRowIndex += 2;
  25412. if (result.Keys.Contains("头等舱SUITE") && result["头等舱SUITE"] > 0)
  25413. {
  25414. var air = mainPrice.TDCCB * mainPrice.TDCXS;
  25415. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  25416. designer.SetDataSource("tdcsuiters", result["头等舱SUITE"]);
  25417. designer.SetDataSource("tdcsuitebj", rightSum + air + hotel);
  25418. designer.SetDataSource("tdcsuitezbj", (rightSum + air + hotel) * result["头等舱SUITE"]);
  25419. allPrice += (rightSum + air + hotel) * result["头等舱SUITE"];
  25420. }
  25421. else
  25422. {
  25423. hideRowsList.Add(airRowIndex);
  25424. }
  25425. airRowIndex += 2;
  25426. if (result.Keys.Contains("经济舱JSES") && result["经济舱JSES"] > 0)
  25427. {
  25428. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  25429. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  25430. designer.SetDataSource("jjcjsesrs", result["经济舱JSES"]);
  25431. designer.SetDataSource("jjcjsesbj", rightSum + air + hotel);
  25432. designer.SetDataSource("jjcjseszbj", (rightSum + air + hotel) * result["经济舱JSES"]);
  25433. allPrice += (rightSum + air + hotel) * result["经济舱JSES"];
  25434. }
  25435. else
  25436. {
  25437. hideRowsList.Add(airRowIndex);
  25438. }
  25439. #endregion
  25440. designer.SetDataSource("AllPrice", "总金额:" + allPrice.ToString("#0.00"));
  25441. string savePaht = AppSettingsHelper.Get("ExcelBasePath") + "GroupCostQuotations/" + di.TeamName + "_详细报批费用.xls";
  25442. var ws = designer.Workbook.Worksheets[0];
  25443. foreach (var Rowindex in hideRowsList)
  25444. {
  25445. ws.Cells.HideRows(Rowindex, 2);
  25446. }
  25447. designer.Process();
  25448. designer.Workbook.Save(savePaht);
  25449. return Ok(JsonView(true, "生成成功!", new
  25450. {
  25451. Url = AppSettingsHelper.Get("ExcelBaseUrl") + savePaht.Replace(AppSettingsHelper.Get("ExcelBasePath"), AppSettingsHelper.Get("ExcelFtpPath"))
  25452. }));
  25453. }
  25454. private void MatchRooms(ref Dictionary<string, int> hotelRooms, ref Dictionary<string, int> flights, string[] roomTypes, string flightType, ref Dictionary<string, int> result)
  25455. {
  25456. foreach (var roomType in roomTypes)
  25457. {
  25458. while (hotelRooms[roomType] > 0 && flights[flightType] > 0)
  25459. {
  25460. hotelRooms[roomType]--;
  25461. flights[flightType]--;
  25462. if (roomType == "TBR")
  25463. {
  25464. flights[flightType]--; // 双人间在减少1
  25465. }
  25466. string key = flightType + roomType;
  25467. if (result.Keys.Contains(key))
  25468. {
  25469. result[key]++;
  25470. }
  25471. else
  25472. {
  25473. result.Add(key, 1);
  25474. }
  25475. }
  25476. }
  25477. }
  25478. private class AirHotelPrice
  25479. {
  25480. public string Name { get; set; }
  25481. public decimal Price { get; set; }
  25482. public int Count { get; set; }
  25483. }
  25484. /// <summary>
  25485. /// 团组系数设置
  25486. /// </summary>
  25487. /// <param name="dto"></param>
  25488. /// <returns></returns>
  25489. [HttpPost]
  25490. public async Task<IActionResult> QueryGroupCostCoefficient(QueryGroupCostCoefficientDto dto)
  25491. {
  25492. var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  25493. .FirstAsync(x => x.Id == dto.Diid && x.IsDel == 0);
  25494. if (di == null)
  25495. {
  25496. return Ok(JsonView(false, "团组不存在!"));
  25497. }
  25498. //var firstExpression = Expressionable.Create<Grp_GroupCostParameter>()
  25499. // .And(x => x.CostType == "A" && x.DiId == di.Id && x.IsDel == 0);
  25500. //var groupCostMainPrice = await _sqlSugar.Queryable<Grp_GroupCostParameter>().
  25501. // FirstAsync(firstExpression.ToExpression());
  25502. #region JSON
  25503. string hcpJson = @"
  25504. [
  25505. {
  25506. ""min"": 1,
  25507. ""max"": 500,
  25508. ""value"": 1.50
  25509. },
  25510. {
  25511. ""min"": 501,
  25512. ""max"": 1000,
  25513. ""value"": 1.40
  25514. },
  25515. {
  25516. ""min"": 1001,
  25517. ""max"": 2000,
  25518. ""value"": 1.35
  25519. }
  25520. ]";
  25521. #endregion
  25522. var hcpPriceRange = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PriceRange>>(hcpJson);
  25523. List<(Predicate<decimal>, decimal)> hcpSwitchDictionary = hcpPriceRange
  25524. .Select(pr => (new Predicate<decimal>(x => x >= pr.Min && x <= pr.Max), pr.Value))
  25525. .ToList();
  25526. List<(Predicate<decimal>, List<(Predicate<decimal>, decimal)>)> jjcSwitchDictionary =
  25527. new List<(Predicate<decimal>, List<(Predicate<decimal>, decimal)>)>();
  25528. //jjcSwitchDictionary.Add((new Predicate<decimal>(x => x >= 1 && x <= 3),
  25529. // new List<(Predicate<decimal>, decimal)>()
  25530. // {
  25531. // (new Predicate<decimal>(y => y >= 1000 && y <= 3000), 2.6M),
  25532. // (new Predicate<decimal>(y => y > 3000), 2.5M)
  25533. // }
  25534. // ));
  25535. #region 签证系数
  25536. var visaXS = 0.00M;
  25537. switch (dto.VisaCB)
  25538. {
  25539. case decimal n when (n > 1 && n < 500):
  25540. switch (dto.VisaRS)
  25541. {
  25542. case 2 or 3:
  25543. visaXS = 1.35M;
  25544. break;
  25545. case 4 or 5:
  25546. visaXS = 1.30M;
  25547. break;
  25548. case 6 or 7:
  25549. visaXS = 1.25M;
  25550. break;
  25551. case 8 or 9 or 10:
  25552. visaXS = 1.20M;
  25553. break;
  25554. case > 10:
  25555. visaXS = 1.15M;
  25556. break;
  25557. default:
  25558. visaXS = 0.00M;
  25559. break;
  25560. }
  25561. break;
  25562. case decimal n when (n >= 500 && n < 1000):
  25563. switch (dto.VisaRS)
  25564. {
  25565. case 2 or 3 or 4:
  25566. visaXS = 1.30M;
  25567. break;
  25568. case 5 or 6 or 7 or 8:
  25569. visaXS = 1.25M;
  25570. break;
  25571. case 9 or 10:
  25572. visaXS = 1.20M;
  25573. break;
  25574. case > 10:
  25575. visaXS = 1.15M;
  25576. break;
  25577. default:
  25578. visaXS = 0.00M;
  25579. break;
  25580. }
  25581. break;
  25582. default:
  25583. switch (dto.VisaRS)
  25584. {
  25585. case 2 or 3 or 4:
  25586. visaXS = 1.30M;
  25587. break;
  25588. case 5 or 6 or 7 or 8:
  25589. visaXS = 1.25M;
  25590. break;
  25591. case 9 or 10:
  25592. visaXS = 1.20M;
  25593. break;
  25594. case > 10:
  25595. visaXS = 1.15M;
  25596. break;
  25597. default:
  25598. visaXS = 0.00M;
  25599. break;
  25600. }
  25601. break;
  25602. }
  25603. #endregion
  25604. #region 火车系数
  25605. var hcpXS = 0.00M;
  25606. foreach (var (condition, result) in hcpSwitchDictionary)
  25607. {
  25608. if (condition(dto.HCPCB))
  25609. {
  25610. hcpXS = result;
  25611. break;
  25612. }
  25613. }
  25614. #endregion
  25615. #region 机票系数
  25616. #region 经济舱系数
  25617. var jjcXS = 0.00M;
  25618. switch (dto.JJCCB)
  25619. {
  25620. case decimal x when (x >= 1000 && x <= 3000):
  25621. jjcXS = 2.6M;
  25622. break;
  25623. case decimal x when (x >= 3001 && x <= 8000):
  25624. jjcXS = 2.3M;
  25625. break;
  25626. case decimal x when (x >= 8001 && x <= 15000):
  25627. jjcXS = 2.1M;
  25628. break;
  25629. case decimal x when (x >= 15001 && x <= 30000):
  25630. jjcXS = 1.95M;
  25631. break;
  25632. case > 30000:
  25633. jjcXS = 1.8M;
  25634. break;
  25635. default:
  25636. break;
  25637. }
  25638. #endregion
  25639. #region 公务舱系数
  25640. var gwcXS = 0.00M;
  25641. switch (dto.GWCCB)
  25642. {
  25643. case decimal x when (x >= 1000 && x <= 3000):
  25644. gwcXS = 2.5M;
  25645. break;
  25646. case decimal x when (x >= 3001 && x <= 8000):
  25647. gwcXS = 2.2M;
  25648. break;
  25649. case decimal x when (x >= 8001 && x <= 15000):
  25650. gwcXS = 2.0M;
  25651. break;
  25652. case decimal x when (x >= 15001 && x <= 30000):
  25653. gwcXS = 1.85M;
  25654. break;
  25655. case > 30000:
  25656. gwcXS = 1.7M;
  25657. break;
  25658. default:
  25659. break;
  25660. }
  25661. #endregion
  25662. #region 头等舱系数
  25663. var tdcXS = 0.00M;
  25664. switch (dto.TDCCB)
  25665. {
  25666. case > 70000:
  25667. tdcXS = 1.5M;
  25668. break;
  25669. default:
  25670. tdcXS = 1.9M;
  25671. break;
  25672. }
  25673. #endregion
  25674. #endregion
  25675. #region 酒店系数
  25676. Dictionary<decimal, List<string>> dic = new Dictionary<decimal, List<string>>()
  25677. {
  25678. {1.6M, new List<string>(){"新西兰","澳大利亚" }},
  25679. {1.5M, new List<string>(){"越南社会主义共和国",
  25680. "老挝",
  25681. "柬埔寨",
  25682. "泰国",
  25683. "缅甸",
  25684. "马来西亚",
  25685. //"新加坡",
  25686. "文莱达鲁萨兰",
  25687. "印度尼西亚",
  25688. "东帝汶"}},
  25689. {1.2M, new List<string>(){ "日本","新加坡","法国","意大利","荷兰"}},
  25690. };
  25691. #region SGR
  25692. var sgrXS = 1.25M;
  25693. #endregion
  25694. #region TBR
  25695. var tbrXS = 1.25M;
  25696. #endregion
  25697. #region JSES
  25698. var jsesXS = 1.25M;
  25699. #endregion
  25700. #region SUITE
  25701. var suiteXS = 1.25M;
  25702. #endregion
  25703. var countryArr = di.VisitCountry.Split("|");
  25704. foreach (var item in dic)
  25705. {
  25706. var extsisCount = item.Value.Where(x => countryArr.Contains(x))
  25707. .Count();
  25708. if (extsisCount > 0)
  25709. {
  25710. jsesXS = item.Key;
  25711. sgrXS = item.Key;
  25712. tbrXS = item.Key;
  25713. suiteXS = item.Key;
  25714. }
  25715. }
  25716. #endregion
  25717. #region 地接系数
  25718. var djXS = 0.00M;
  25719. switch (dto.DJRS)
  25720. {
  25721. case 2 or 3:
  25722. djXS = 2.65M;
  25723. break;
  25724. case 4:
  25725. djXS = 2.6M;
  25726. break;
  25727. case 5 or 6:
  25728. djXS = 2.5M;
  25729. break;
  25730. case 7 or 8:
  25731. djXS = 2.4M;
  25732. break;
  25733. case 9 or 10:
  25734. djXS = 2.3M;
  25735. break;
  25736. case 11:
  25737. djXS = 2.2M;
  25738. break;
  25739. case 12:
  25740. djXS = 2.1M;
  25741. break;
  25742. case 13 or 14:
  25743. djXS = 2M;
  25744. break;
  25745. case 15:
  25746. djXS = 1.9M;
  25747. break;
  25748. case 16 or 17 or 18:
  25749. djXS = 1.8M;
  25750. break;
  25751. case 19 or 20:
  25752. djXS = 1.7M;
  25753. break;
  25754. }
  25755. #endregion
  25756. #region 零用金系数
  25757. var lyjXS = 0.00M;
  25758. switch (dto.LYJRS)
  25759. {
  25760. case 2:
  25761. lyjXS = 1.25M;
  25762. break;
  25763. case 3 or 4 or 5:
  25764. lyjXS = 1.2M;
  25765. break;
  25766. case int number when (number > 5 && number < 10):
  25767. lyjXS = 1.15M;
  25768. break;
  25769. case > 10:
  25770. lyjXS = 1.1M;
  25771. break;
  25772. default:
  25773. break;
  25774. }
  25775. #endregion
  25776. return Ok(JsonView(true, "查询成功", new ArrayList()
  25777. {
  25778. new { label = "火车票系数", value = hcpXS, key = "hcpXS" },
  25779. new { label = "经济舱系数", value = jjcXS, key = "jjcXS" },
  25780. new { label = "公务舱系数", value = gwcXS, key = "gwcXS" },
  25781. new { label = "头等舱系数", value = tdcXS, key = "tdcXS" },
  25782. new { label = "SGR系数", value = sgrXS, key = "sgrXS" },
  25783. new { label = "TBR系数", value = tbrXS, key = "tbrXS" },
  25784. new { label = "JSES系数", value = jsesXS, key = "jsesXS" },
  25785. new { label = "SUITE系数", value = suiteXS, key = "suiteXS" },
  25786. new { label = "地接系数", value = djXS, key = "djXS" },
  25787. new { label = "零用金系数", value = lyjXS, key = "lyjXS" },
  25788. new { label = "公务系数", value = 2M, key = "gwXS" }
  25789. }));
  25790. }
  25791. #endregion
  25792. #region 酒店预订 New 2023-12-28 17:45
  25793. /// <summary>
  25794. /// 酒店预订
  25795. /// 酒店费用列表 根据团组Id查询
  25796. /// </summary>
  25797. /// <param name="_dto"></param>
  25798. /// <returns></returns>
  25799. [HttpPost]
  25800. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25801. public async Task<IActionResult> PostHotelReservationsItemsByDiId(HotelReservationItemDto _dto)
  25802. {
  25803. #region 参数验证
  25804. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  25805. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  25806. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  25807. #region 团组操作权限验证 76 酒店预定模块
  25808. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  25809. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  25810. #endregion
  25811. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  25812. #region 页面操作权限验证
  25813. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  25814. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  25815. #endregion
  25816. #endregion
  25817. return Ok(await _hotelPriceRep.ItemsByDiId(_dto.PortType, _dto.DiId));
  25818. }
  25819. /// <summary>
  25820. /// 酒店预订
  25821. /// 基础数据
  25822. /// </summary>
  25823. /// <param name="_dto"></param>
  25824. /// <returns></returns>
  25825. [HttpPost]
  25826. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25827. public async Task<IActionResult> PostHotelReservationsBasicsDataInit(HotelReservationBasicsDataInitDto _dto)
  25828. {
  25829. #region 参数验证
  25830. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  25831. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  25832. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  25833. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  25834. #region 页面操作权限验证
  25835. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  25836. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  25837. #endregion
  25838. #region 团组操作权限验证 76 酒店预定模块
  25839. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  25840. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  25841. #endregion
  25842. #endregion
  25843. return Ok(await _hotelPriceRep.BasicsDataInit(_dto.PortType, _dto.DiId));
  25844. }
  25845. /// <summary>
  25846. /// 酒店预订
  25847. /// 创建 入住卷号码
  25848. /// </summary>
  25849. /// <param name="_dto"></param>
  25850. /// <returns></returns>
  25851. [HttpPost]
  25852. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25853. public async Task<IActionResult> PostHotelReservationsCreateCheckVolumeNo(HotelReservationBasicsDataInitDto _dto)
  25854. {
  25855. #region 参数验证
  25856. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  25857. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  25858. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  25859. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  25860. #region 页面操作权限验证
  25861. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  25862. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  25863. #endregion
  25864. #region 团组操作权限验证 76 酒店预定模块
  25865. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  25866. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  25867. #endregion
  25868. #endregion
  25869. Result data = await _hotelPriceRep.CreateCheckVolumeNo(_dto.DiId);
  25870. if (data.Code != 0)
  25871. {
  25872. return Ok(JsonView(false, data.Msg));
  25873. }
  25874. return Ok(JsonView(true, data.Msg, data.Data));
  25875. }
  25876. /// <summary>
  25877. /// 酒店预订
  25878. /// 详情
  25879. /// </summary>
  25880. /// <param name="_dto"></param>
  25881. /// <returns></returns>
  25882. [HttpPost]
  25883. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25884. public async Task<IActionResult> PostHotelReservationsDetails(HotelReservationsDetailsDto _dto)
  25885. {
  25886. #region 参数验证
  25887. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入正确的UserId参数"));
  25888. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  25889. if (_dto.DiId < 1) return Ok(JsonView(false, "请传入正确的DiId参数"));
  25890. #region 团组操作权限验证 76 酒店预定模块
  25891. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  25892. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  25893. #endregion
  25894. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  25895. #region 页面操作权限验证
  25896. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  25897. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  25898. #endregion
  25899. #endregion
  25900. return Ok(await _hotelPriceRep.Details(_dto.PortType, _dto.Id));
  25901. }
  25902. /// <summary>
  25903. /// 酒店预订
  25904. /// Add Or Edit
  25905. /// </summary>
  25906. /// <param name="_dto"></param>
  25907. /// <returns></returns>
  25908. [HttpPost]
  25909. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25910. public async Task<IActionResult> PostHotelReservationsAddOrEdit(HotelReservationsAddOrEditDto _dto)
  25911. {
  25912. #region 参数验证
  25913. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  25914. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  25915. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  25916. #region 团组操作权限验证 76 酒店预定模块
  25917. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  25918. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  25919. #endregion
  25920. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  25921. #region 页面操作权限验证
  25922. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  25923. if (_dto.Id == 0) // Add
  25924. {
  25925. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
  25926. }
  25927. else if (_dto.Id > 1) // Edit
  25928. {
  25929. if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
  25930. }
  25931. else return Ok(JsonView(false, "请输入正确的数据Id!"));
  25932. #endregion
  25933. #endregion
  25934. //验证:团回归30天后不能更改
  25935. if (_dto.Id > 0)
  25936. {
  25937. //// 审核、付款 验证
  25938. //(bool valid, string msg) = await GeneralMethod.FeeOpValid(_dto.Id, 76);
  25939. //if (!valid) return Ok(JsonView(false, msg));
  25940. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  25941. .Where(x => x.Id == _dto.DiId && x.IsDel == 0)
  25942. .FirstAsync();
  25943. if (groupInfo == null)
  25944. {
  25945. return Ok(JsonView(false, "团组信息不存在"));
  25946. }
  25947. // 截止日期:团回归日期+30天
  25948. var deadline = groupInfo.VisitEndDate.AddDays(30).Date;
  25949. // 当前日期
  25950. var currDate = DateTime.Today;
  25951. if (currDate > deadline)
  25952. {
  25953. return Ok(JsonView(false, "当前日期已超过截止日期(团回归日期+30天),不可编辑。"));
  25954. }
  25955. }
  25956. JsonView _view = await _hotelPriceRep.AddOrEdit(_dto);
  25957. if (_view.Code != 200)
  25958. {
  25959. return Ok(_view);
  25960. }
  25961. #region 成本无酒店价格数据进入超支
  25962. _sqlSugar.BeginTran();
  25963. var start_Bool = DateTime.TryParse(_dto.CheckInDate, out DateTime start_Time);
  25964. var end_Bool = DateTime.TryParse(_dto.CheckOutDate, out DateTime end_Time);
  25965. var groupCost = _sqlSugar.Queryable<Grp_GroupCost>().Where(x => x.Diid == _dto.DiId && x.IsDel == 0).ToList();
  25966. for (int i = 0; i < groupCost.Count; i++)
  25967. {
  25968. if (groupCost[i].Date.IsNullOrWhiteSpace() && i != 0)
  25969. {
  25970. groupCost[i].Date = groupCost[i - 1].Date;
  25971. }
  25972. }
  25973. var groupCost_Grp = groupCost.GroupBy(x => x.Date).ToList();
  25974. List<Fin_GroupExtraCostDto_OP> extraCostList = new
  25975. List<Fin_GroupExtraCostDto_OP>();
  25976. if (start_Bool && end_Bool)
  25977. {
  25978. while (start_Time < end_Time)
  25979. {
  25980. foreach (var item in groupCost_Grp)
  25981. {
  25982. if (DateTime.TryParse(item.Key, out DateTime cost_Time))
  25983. {
  25984. if (DateTime.Compare(start_Time, cost_Time) == 0 && item.Sum(x => x.SGR + x.Suite + x.TBR + x.JS_ES) == 0)
  25985. {
  25986. extraCostList.Add(new
  25987. Fin_GroupExtraCostDto_OP
  25988. {
  25989. Area = _dto.AreaId,
  25990. coefficient = 1.5M,
  25991. createUser = _dto.UserId,
  25992. currency = _dto.CardPriceCurrency,
  25993. diId = _dto.DiId,
  25994. ManagerConfirm = 0,
  25995. SupervisorConfirm = 0,
  25996. SYsupervisorConfirm = 0,
  25997. editType = 1,
  25998. PortType = 1,
  25999. price = _dto.CardPrice,
  26000. PriceCount = 1,
  26001. priceType = 1027,
  26002. priceDetailType = 1044,
  26003. PriceDt = start_Time.ToString("yyyy-MM-dd"),
  26004. priceName = $"酒店超支费用-酒店导入-({start_Time.ToString("yyyy/MM/dd")})",
  26005. });
  26006. }
  26007. }
  26008. }
  26009. start_Time = start_Time.AddDays(1);
  26010. }
  26011. }
  26012. if (extraCostList.Any())
  26013. {
  26014. await _carTouristGuideGroundRep.GroupExtraCost_OperatorList(extraCostList);
  26015. }
  26016. _sqlSugar.CommitTran();
  26017. #endregion
  26018. #region 应用推送
  26019. try
  26020. {
  26021. //int ccpId = (int)_view.Data.GetType().GetProperty("ccpId").GetValue(_view.Data, null);
  26022. //int sign = (int)_view.Data.GetType().GetProperty("sign").GetValue(_view.Data, null);
  26023. //int hotelId = (int)_view.Data.GetType().GetProperty("hotelId").GetValue(_view.Data, null);
  26024. int ccpId = Convert.ToInt32(_view.Data.GetType().GetProperty("ccpId").GetValue(_view.Data, null) ?? 0);
  26025. int sign = Convert.ToInt32(_view.Data.GetType().GetProperty("sign").GetValue(_view.Data, null) ?? 0);
  26026. int hotelId = Convert.ToInt32(_view.Data.GetType().GetProperty("hotelId").GetValue(_view.Data, null) ?? 0);
  26027. var diId = _dto.DiId;
  26028. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  26029. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  26030. #region 操作记录
  26031. var opInfo = new Crm_TableOperationRecord()
  26032. {
  26033. TableName = "Grp_HotelReservations",
  26034. PortType = _dto.PortType,
  26035. DataId = hotelId,
  26036. CreateUserId = _dto.UserId
  26037. };
  26038. //var opStatus = OperationEnum.NoOperation;
  26039. if (_dto.Id < 1) //添加操作
  26040. {
  26041. opInfo.OperationItem = OperationEnum.Add;
  26042. }
  26043. else if (_dto.Id > 0)
  26044. {
  26045. opInfo.OperationItem = OperationEnum.Edit;
  26046. }
  26047. string opRemark = string.Empty;
  26048. if (ccpInfo != null)
  26049. {
  26050. // USD 1211.86、 CNY 8761.75、汇率:7.2300
  26051. var currency = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.Id == ccpInfo.PaymentCurrency).First()?.Name;
  26052. var cnyPrice = ccpInfo.PayMoney * ccpInfo.DayRate;
  26053. opRemark = $"{currency} {ccpInfo.PayMoney.ToString("#0.00")}、CNY {cnyPrice.ToString("#0.00")}、汇率:{ccpInfo.DayRate.ToString("#0.0000")}";
  26054. }
  26055. opInfo.Remark = opRemark;
  26056. await _tableorRep.AddAsync(opInfo);
  26057. #endregion
  26058. _logger.LogInformation($"【iOS推送通知Exception】Begin");
  26059. //2024-10-21 新增LZ UID
  26060. var userIds = new List<int>() { 21 };
  26061. string title = $"费用审核";
  26062. string content = "";
  26063. if (_dto.Id == 0) content = $"[新增-酒店费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  26064. else if (_dto.Id > 0) content = $"[更新-酒店费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  26065. try
  26066. {
  26067. PageParam_PriceAuditH5 h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "76" };
  26068. await APNsTools.iOS_PushNotifications1("051", title, "", content, true, "ExpenseAuditWebView", h5);
  26069. //Logs($"【iOS推送通知PostHotelReservationsAddOrEdit】Start");
  26070. //var iosRes = await APNsTools.iOS_PushNotifications("051", title, "", content);
  26071. //Logs($"【iOS推送通知PostHotelReservationsAddOrEdit】End Response:[{JsonConvert.SerializeObject(iosRes)}]");
  26072. }
  26073. catch (Exception ex)
  26074. {
  26075. Logs($"【iOS推送通知-PostHotelReservationsAddOrEdit-Exception】[{ex.Message}]");
  26076. }
  26077. }
  26078. catch (Exception ex)
  26079. {
  26080. Logs($"【iOS推送通知Exception】【{ex.Message}】");
  26081. }
  26082. try
  26083. {
  26084. //int ccpId = (int)_view.Data.GetType().GetProperty("ccpId").GetValue(_view.Data, null);
  26085. //int sign = (int)_view.Data.GetType().GetProperty("sign").GetValue(_view.Data, null);
  26086. //int hotelId = (int)_view.Data.GetType().GetProperty("hotelId").GetValue(_view.Data, null);
  26087. int ccpId = Convert.ToInt32(_view.Data.GetType().GetProperty("ccpId").GetValue(_view.Data, null) ?? 0);
  26088. int sign = Convert.ToInt32(_view.Data.GetType().GetProperty("sign").GetValue(_view.Data, null) ?? 0);
  26089. int hotelId = Convert.ToInt32(_view.Data.GetType().GetProperty("hotelId").GetValue(_view.Data, null) ?? 0);
  26090. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  26091. //自动审核
  26092. var autoAdit = await _feeAuditRep.FeeAutomaticAudit(1, _dto.DiId, hotelId);
  26093. //if (autoAdit.Code != 200) _view.Msg += $"\r\n{autoAdit.Msg}";
  26094. _logger.LogInformation($"【酒店自动审核】【{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}】执行调用 调用结果:{JsonConvert.SerializeObject(autoAdit)}");
  26095. //2024-10-21 新增LZ UID
  26096. var userIds = new List<int>() { 21 };
  26097. string title = $"系统通知";
  26098. var diId = _dto.DiId;
  26099. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  26100. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  26101. string content = "";
  26102. if (_dto.Id == 0) content = $"[新增-酒店费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  26103. else if (_dto.Id > 0) content = $"[更新-酒店费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  26104. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  26105. }
  26106. catch (Exception ex)
  26107. {
  26108. }
  26109. #endregion
  26110. return Ok(_view);
  26111. }
  26112. /// <summary>
  26113. /// 酒店自动审核测试
  26114. /// Add Or Edit
  26115. /// </summary>
  26116. /// <param name="diid"></param>
  26117. /// <param name="dataId"></param>
  26118. /// <returns></returns>
  26119. [HttpPost]
  26120. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26121. public async Task<IActionResult> PostHotelAutoAuditTest(int diid, int dataId)
  26122. {
  26123. #region 应用推送
  26124. try
  26125. {
  26126. //自动审核
  26127. await _feeAuditRep.FeeAutomaticAudit(1, diid, dataId);
  26128. }
  26129. catch (Exception ex)
  26130. {
  26131. return Ok(JsonView(false, ex.Message));
  26132. }
  26133. #endregion
  26134. return Ok(JsonView(false, "操作成功"));
  26135. }
  26136. /// <summary>
  26137. /// 酒店预订
  26138. /// Del
  26139. /// </summary>
  26140. /// <param name="_dto"></param>
  26141. /// <returns></returns>
  26142. [HttpPost]
  26143. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26144. public async Task<IActionResult> PostHotelReservationsDel(HotelReservationsDelDto _dto)
  26145. {
  26146. #region 参数验证
  26147. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  26148. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  26149. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  26150. #region 团组操作权限验证 76 酒店预定模块
  26151. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  26152. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  26153. #endregion
  26154. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  26155. #region 页面操作权限验证
  26156. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  26157. if (pageFunAuthView.DeleteAuth == 0) return Ok(JsonView(false, "您没有删除权限!"));
  26158. #endregion
  26159. #endregion
  26160. //验证
  26161. (bool valid, string msg) = await GeneralMethod.FeeOpValid(_dto.Id, 76);
  26162. if (!valid) return Ok(JsonView(false, msg));
  26163. var data = await _hotelPriceRep.Del(_dto.Id, _dto.UserId);
  26164. #region 操作记录
  26165. await _tableorRep.AddAsync(new Crm_TableOperationRecord()
  26166. {
  26167. TableName = "Grp_HotelReservations",
  26168. PortType = _dto.PortType,
  26169. OperationItem = OperationEnum.Del,
  26170. DataId = _dto.Id,
  26171. CreateUserId = _dto.UserId
  26172. });
  26173. #endregion
  26174. return Ok(data);
  26175. }
  26176. /// <summary>
  26177. /// 酒店预订
  26178. /// 生成VOUCHER
  26179. /// 2024.05.06 之前版本
  26180. /// </summary>
  26181. /// <param name="_dto"></param>
  26182. /// <returns></returns>
  26183. [HttpPost]
  26184. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26185. public async Task<IActionResult> PostHotelReservationsCreateVoucherOld(HotelReservationsCreateVoucherDto _dto)
  26186. {
  26187. try
  26188. {
  26189. #region 参数验证
  26190. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  26191. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  26192. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  26193. if (_dto.Id < 1) return Ok(JsonView(false, "Id为空"));
  26194. #region 团组操作权限验证 76 酒店预定模块
  26195. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  26196. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  26197. #endregion
  26198. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  26199. #region 页面操作权限验证
  26200. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  26201. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  26202. #endregion
  26203. #endregion
  26204. Grp_HotelReservations hr = await _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && it.Id == _dto.Id).FirstAsync();
  26205. //判断数据是否完整
  26206. if (hr != null)
  26207. {
  26208. if (!string.IsNullOrEmpty(hr.DetermineNo))
  26209. {
  26210. string strFileName = "HotelStatement/";
  26211. Grp_DelegationInfo dele = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == _dto.DiId).FirstAsync();
  26212. if (dele != null)
  26213. strFileName += dele.TourCode;
  26214. //载入模板
  26215. string sss = AppSettingsHelper.Get("WordBasePath") + "Template/酒店预订模板.doc";
  26216. Document doc = new Document(sss);
  26217. DocumentBuilder builder = new DocumentBuilder(doc);
  26218. #region 替换Word模板书签内容
  26219. //这里可以创建个DataTable循环添加书签的值,这里提示一下就不多做修改了
  26220. //入住卷预定号码
  26221. if (doc.Range.Bookmarks["VNO"] != null)
  26222. {
  26223. Bookmark mark = doc.Range.Bookmarks["VNO"];
  26224. mark.Text = hr.CheckNumber;
  26225. }
  26226. //酒店时间
  26227. if (doc.Range.Bookmarks["Date"] != null)
  26228. {
  26229. Bookmark mark = doc.Range.Bookmarks["Date"];
  26230. mark.Text = Convert.ToDateTime(hr.CreateTime).ToString("yyyy-MM-dd");
  26231. }
  26232. //团号
  26233. if (doc.Range.Bookmarks["TNo"] != null)
  26234. {
  26235. Bookmark mark = doc.Range.Bookmarks["TNo"];
  26236. mark.Text = dele.TourCode;
  26237. }
  26238. //预定号码
  26239. if (doc.Range.Bookmarks["BookingId"] != null)
  26240. {
  26241. Bookmark mark = doc.Range.Bookmarks["BookingId"];
  26242. mark.Text = hr.ReservationsNo;
  26243. }
  26244. if (doc.Range.Bookmarks["HotelConfirmNo"] != null)
  26245. {
  26246. Bookmark mark = doc.Range.Bookmarks["HotelConfirmNo"];
  26247. mark.Text = hr.DetermineNo;
  26248. }
  26249. //酒店城市
  26250. if (doc.Range.Bookmarks["City"] != null)
  26251. {
  26252. Bookmark mark = doc.Range.Bookmarks["City"];
  26253. mark.Text = hr.City;
  26254. }
  26255. //酒店名称
  26256. if (doc.Range.Bookmarks["HName"] != null)
  26257. {
  26258. Bookmark mark = doc.Range.Bookmarks["HName"];
  26259. mark.Text = hr.HotelName;
  26260. }
  26261. //酒店地址
  26262. if (doc.Range.Bookmarks["Address"] != null)
  26263. {
  26264. Bookmark mark = doc.Range.Bookmarks["Address"];
  26265. mark.Text = hr.HotelAddress;
  26266. }
  26267. //酒店电话
  26268. if (doc.Range.Bookmarks["Tel"] != null)
  26269. {
  26270. Bookmark mark = doc.Range.Bookmarks["Tel"];
  26271. mark.Text = hr.HotelTel;
  26272. }
  26273. //酒店传真
  26274. if (doc.Range.Bookmarks["Fax"] != null)
  26275. {
  26276. Bookmark mark = doc.Range.Bookmarks["Fax"];
  26277. if (!string.IsNullOrWhiteSpace(hr.HotelFax))
  26278. {
  26279. mark.Text = hr.HotelFax;
  26280. }
  26281. }
  26282. //入住时间
  26283. if (doc.Range.Bookmarks["CIn"] != null)
  26284. {
  26285. DateTime dtCheckIn = Convert.ToDateTime(hr.CheckInDate);
  26286. Bookmark mark = doc.Range.Bookmarks["CIn"];
  26287. mark.Text = dtCheckIn.Day + " " + dtCheckIn.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckIn.Year;
  26288. }
  26289. //退房时间
  26290. if (doc.Range.Bookmarks["COut"] != null)
  26291. {
  26292. DateTime dtCheckOut = Convert.ToDateTime(hr.CheckOutDate);
  26293. Bookmark mark = doc.Range.Bookmarks["COut"];
  26294. mark.Text = dtCheckOut.Day + " " + dtCheckOut.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckOut.Year;
  26295. }
  26296. //客户名称
  26297. if (doc.Range.Bookmarks["GName"] != null)
  26298. {
  26299. string guestName = "";
  26300. string[] clients = Array.Empty<string>();
  26301. if (hr.GuestName.Contains(","))
  26302. {
  26303. clients = hr.GuestName.Split(",");
  26304. }
  26305. else
  26306. {
  26307. clients = new string[] { hr.GuestName };
  26308. }
  26309. List<int> clientIds_int = new List<int>();
  26310. if (clients.Length > 0)
  26311. {
  26312. foreach (var item in clients)
  26313. {
  26314. if (item.IsNumeric())
  26315. {
  26316. clientIds_int.Add(int.Parse(item));
  26317. }
  26318. }
  26319. }
  26320. if (clientIds_int.Count > 0)
  26321. {
  26322. var _clientDatas = _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0 && clientIds_int.Contains(it.Id)).ToList();
  26323. foreach (var client in _clientDatas)
  26324. {
  26325. //男
  26326. if (client.Sex == 0) guestName += $"Mr.";
  26327. //女
  26328. else if (client.Sex == 1) guestName += $"Ms.";
  26329. if (!String.IsNullOrEmpty(client.FirstName + client.LastName))
  26330. {
  26331. guestName += $"{string.Join("", client.FirstName.GetTotalPingYin()).ToUpper()} {string.Join("", client.LastName.GetTotalPingYin()).ToUpper()},";
  26332. }
  26333. //guestName += $"{client.Pinyin},";
  26334. }
  26335. if (guestName.Length > 0)
  26336. {
  26337. guestName = guestName.Substring(0, guestName.Length - 1);
  26338. }
  26339. }
  26340. else
  26341. {
  26342. guestName = hr.GuestName;
  26343. }
  26344. Bookmark mark = doc.Range.Bookmarks["GName"];
  26345. mark.Text = guestName;
  26346. }
  26347. //房间介绍
  26348. if (doc.Range.Bookmarks["ROOM"] != null)
  26349. {
  26350. Bookmark mark = doc.Range.Bookmarks["ROOM"];
  26351. mark.Text = hr.RoomExplanation;
  26352. }
  26353. //报价描述
  26354. if (doc.Range.Bookmarks["NOTE"] != null)
  26355. {
  26356. Bookmark mark = doc.Range.Bookmarks["NOTE"];
  26357. Sys_SetData ss = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == hr.ReservationsWebsite);
  26358. if (ss != null)
  26359. mark.Text = ss.Name;
  26360. }
  26361. //入住时间
  26362. if (doc.Range.Bookmarks["CheckIn"] != null)
  26363. {
  26364. DateTime dtCheckIn = Convert.ToDateTime(hr.CheckInDate);
  26365. Bookmark mark = doc.Range.Bookmarks["CheckIn"];
  26366. mark.Text = dtCheckIn.Day + " " + dtCheckIn.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckIn.Year + " ";
  26367. }
  26368. //退房时间
  26369. if (doc.Range.Bookmarks["CheckOut"] != null)
  26370. {
  26371. DateTime dtCheckOut = Convert.ToDateTime(hr.CheckOutDate);
  26372. Bookmark mark = doc.Range.Bookmarks["CheckOut"];
  26373. mark.Text = " " + dtCheckOut.Day + " " + dtCheckOut.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckOut.Year;
  26374. }
  26375. //日期
  26376. if (doc.Range.Bookmarks["DT"] != null)
  26377. {
  26378. Bookmark mark = doc.Range.Bookmarks["DT"];
  26379. mark.Text = Convert.ToDateTime(hr.CreateTime).ToString("yyyy-MM-dd");
  26380. }
  26381. //名称
  26382. if (doc.Range.Bookmarks["VName"] != null)
  26383. {
  26384. Bookmark mark = doc.Range.Bookmarks["VName"];
  26385. mark.Text = hr.HotelName;
  26386. }
  26387. //号码
  26388. if (doc.Range.Bookmarks["VOUCHERNO"] != null)
  26389. {
  26390. Bookmark mark = doc.Range.Bookmarks["VOUCHERNO"];
  26391. mark.Text = hr.CheckNumber;
  26392. }
  26393. #endregion
  26394. strFileName += "VOUCHER.doc";
  26395. var fileDir = AppSettingsHelper.Get("WordBasePath") + strFileName;
  26396. doc.Save(fileDir);
  26397. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/" + strFileName;
  26398. return Ok(JsonView(true, "操作成功!", Url));
  26399. }
  26400. else
  26401. {
  26402. return Ok(JsonView(false, "酒店确定号码未填写,无法生成Voucher!"));
  26403. }
  26404. }
  26405. else
  26406. {
  26407. return Ok(JsonView(false, "该条数据已删除或不存在!"));
  26408. }
  26409. }
  26410. catch (Exception ex)
  26411. {
  26412. return Ok(JsonView(false, ex.Message));
  26413. }
  26414. }
  26415. /// <summary>
  26416. /// 酒店预订
  26417. /// 生成VOUCHER
  26418. /// 2024.05.06 之后版本
  26419. /// </summary>
  26420. /// <param name="_dto"></param>
  26421. /// <returns></returns>
  26422. [HttpPost]
  26423. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26424. public async Task<IActionResult> PostHotelReservationsCreateVoucher(HotelReservationsCreateVoucherDto _dto)
  26425. {
  26426. #region 参数验证
  26427. if (_dto.UserId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "员工Id为空", ""));
  26428. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  26429. if (_dto.DiId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组Id为空", ""));
  26430. #region 团组操作权限验证 76 酒店预定模块
  26431. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  26432. if (groupAuthView.Code != 0) return Ok(JsonView(StatusCodes.Status400BadRequest, groupAuthView.Msg, ""));
  26433. #endregion
  26434. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  26435. #region 页面操作权限验证
  26436. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  26437. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  26438. #endregion
  26439. #endregion
  26440. List<Grp_HotelReservations> hrDtas = await _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && it.DiId == _dto.DiId).ToListAsync();
  26441. //判断数据是否完整
  26442. if (hrDtas.Count < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "请先录入酒店预订信息!", ""));
  26443. hrDtas = hrDtas.OrderBy(it => it.CheckInDate).ToList();
  26444. string strFileName = "HotelStatement/";
  26445. string guestNames = ""; //格式Mr.xxx Ms.xxx
  26446. List<HotelVoucherInfoView> vouchers = new List<HotelVoucherInfoView>();
  26447. #region 数据处理
  26448. List<int> guestIds = new List<int>();
  26449. //int index = 0;
  26450. foreach (var item in hrDtas)
  26451. {
  26452. if (item.GuestName.Contains(","))
  26453. {
  26454. string[] guestIdArr = item.GuestName.Split(',');
  26455. foreach (var guestIdStr in guestIdArr)
  26456. {
  26457. bool guestBool = int.TryParse(guestIdStr, out int guestId);
  26458. if (guestBool)
  26459. {
  26460. guestIds.Add(guestId);
  26461. }
  26462. }
  26463. }
  26464. else guestNames += item.GuestName;
  26465. var voucherInfo = new HotelVoucherInfoView()
  26466. {
  26467. HotelName = item.HotelName,
  26468. CheckInDate = item.CheckInDate,
  26469. CheckOutDate = item.CheckOutDate,
  26470. ConfirmationNumber = item.DetermineNo.Trim(),
  26471. RoomType = item.RoomExplanation
  26472. };
  26473. vouchers.Add(voucherInfo);
  26474. }
  26475. if (guestIds.Count > 0)
  26476. {
  26477. guestIds = guestIds.Distinct().ToList();
  26478. var guestDatas = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0 && guestIds.Contains(it.Id)).ToListAsync();
  26479. if (guestDatas.Count > 0)
  26480. {
  26481. guestNames = "";
  26482. foreach (var guest in guestDatas)
  26483. {
  26484. string guestName = "";
  26485. if (guest.Sex == 0) guestName += @"MR.";
  26486. else if (guest.Sex == 1) guestName += @"MS.";
  26487. if (guest.Pinyin == null) guestName += $"{string.Join("", guest.LastName.GetTotalPingYin()).ToUpper()}/{string.Join("", guest.FirstName.GetTotalPingYin()).ToUpper()}";
  26488. else guestName += @$"{guest.Pinyin.Replace(" ", "")}";
  26489. guestNames += @$"{guestName.Trim()}、";
  26490. }
  26491. if (guestNames.Length > 0)
  26492. {
  26493. guestNames = guestNames.Substring(0, guestNames.Length - 1);
  26494. }
  26495. }
  26496. }
  26497. #endregion
  26498. //载入模板
  26499. string sss = AppSettingsHelper.Get("WordBasePath") + "Template/Voucher-2024Versions.docx";
  26500. Document doc = new Document(sss);
  26501. DocumentBuilder builder = new DocumentBuilder(doc);
  26502. if (doc.Range.Bookmarks["GuestName"] != null)
  26503. {
  26504. Bookmark mark = doc.Range.Bookmarks["GuestName"];
  26505. mark.Text = guestNames;
  26506. }
  26507. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  26508. Aspose.Words.Tables.Table table = allTables[0] as Aspose.Words.Tables.Table;
  26509. vouchers = vouchers.OrderBy(it => it.CheckInDate).ToList();
  26510. for (int i = 1; i <= vouchers.Count; i++)
  26511. {
  26512. HotelVoucherInfoView hviv = vouchers[i - 1];
  26513. builder.MoveToCell(0, i, 0, 0);
  26514. builder.Write(hviv.HotelName);
  26515. builder.MoveToCell(0, i, 1, 0);
  26516. builder.Write(hviv.CheckInDate);
  26517. builder.MoveToCell(0, i, 2, 0);
  26518. builder.Write(hviv.CheckOutDate);
  26519. builder.MoveToCell(0, i, 3, 0);
  26520. builder.Write(hviv.RoomType);
  26521. builder.MoveToCell(0, i, 4, 0);
  26522. builder.Write(hviv.ConfirmationNumber);
  26523. }
  26524. //删除多余行
  26525. int currRowIndex = vouchers.Count + 1;
  26526. int delRows = 21 - currRowIndex;
  26527. if (delRows > 0)
  26528. {
  26529. for (int i = 0; i < delRows; i++)
  26530. {
  26531. table.Rows.RemoveAt(currRowIndex);
  26532. //cultivateRowIndex++;
  26533. }
  26534. }
  26535. strFileName += "VOUCHER.docx";
  26536. var fileDir = AppSettingsHelper.Get("WordBasePath") + strFileName;
  26537. doc.Save(fileDir);
  26538. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/" + strFileName;
  26539. return Ok(JsonView(true, "操作成功!", Url));
  26540. }
  26541. /// <summary>
  26542. /// 酒店预订
  26543. /// 生成VOUCHER 批量生成
  26544. /// New
  26545. /// </summary>
  26546. /// <param name="_dto"></param>
  26547. /// <returns></returns>
  26548. [HttpPost]
  26549. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26550. public async Task<IActionResult> PostHotelReservationsCreateVoucherBatchNew(HotelReservationsCreateVoucherDto _dto)
  26551. {
  26552. #region 参数验证
  26553. if (_dto.UserId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "员工Id为空", ""));
  26554. if (_dto.PageId < 1) _dto.PageId = 28;
  26555. if (_dto.DiId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组Id为空", ""));
  26556. #region 团组操作权限验证 76 酒店预定模块
  26557. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  26558. if (groupAuthView.Code != 0) return Ok(JsonView(StatusCodes.Status400BadRequest, groupAuthView.Msg, ""));
  26559. #endregion
  26560. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  26561. #region 页面操作权限验证
  26562. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  26563. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  26564. #endregion
  26565. #endregion
  26566. var hrDtas = await _sqlSugar.Queryable<Grp_HotelReservations>()
  26567. .Where(it => it.IsDel == 0 && it.DiId == _dto.DiId)
  26568. .OrderBy(x => x.CheckInDate)
  26569. .ToListAsync();
  26570. //判断数据是否完整
  26571. if (hrDtas.Count < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "请先录入酒店预订信息!", ""));
  26572. string strFileName = "HotelStatement/";
  26573. var dele = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == _dto.DiId).FirstAsync();
  26574. if (dele != null)
  26575. strFileName += $"{dele?.TeamName ?? ""}_{dele.TourCode}_";
  26576. var guestDatas = await _sqlSugar.Queryable<Crm_DeleClient>()
  26577. .Select(x => new Crm_DeleClient { Id = x.Id, FirstName = x.FirstName, LastName = x.LastName, Pinyin = x.Pinyin })
  26578. .Where(it => it.IsDel == 0)
  26579. .ToListAsync();
  26580. foreach (var item in guestDatas) EncryptionProcessor.DecryptProperties(item);
  26581. for (int i = 0; i < hrDtas.Count; i++)
  26582. {
  26583. string guestNames = string.Empty;
  26584. List<int> guestIds = new List<int>();
  26585. var item = hrDtas[i];
  26586. //处理客户姓名
  26587. if (item.GuestName.Contains(","))
  26588. {
  26589. string[] guestIdArr = item.GuestName.Split(',');
  26590. foreach (var guestIdStr in guestIdArr)
  26591. if (int.TryParse(guestIdStr, out int guestId))
  26592. guestIds.Add(guestId);
  26593. }
  26594. else
  26595. {
  26596. bool guestIdBool = int.TryParse(item.GuestName, out int guestId);
  26597. if (guestIdBool)
  26598. {
  26599. guestIds.Add(guestId);
  26600. }
  26601. //NaN
  26602. if (item.GuestName.Contains("NaN"))
  26603. {
  26604. guestNames += item.GuestName.Replace("NaN", "").Replace(",", "");
  26605. }
  26606. }
  26607. if (guestIds.Count > 0)
  26608. {
  26609. guestIds = guestIds.Distinct().ToList();
  26610. var guestDatas1 = guestDatas.Where(it => guestIds.Contains(it.Id)).ToList();
  26611. if (guestDatas1.Count > 0)
  26612. {
  26613. guestNames = "";
  26614. foreach (var guest in guestDatas1)
  26615. {
  26616. string guestName = "";
  26617. if (guest.Sex == 0) guestName += @"MR.";
  26618. else if (guest.Sex == 1) guestName += @"MS.";
  26619. if (guest.Pinyin == null) guestName += $"{string.Join("", guest.LastName.GetTotalPingYin()).ToUpper()}/{string.Join("", guest.FirstName.GetTotalPingYin()).ToUpper()}";
  26620. else guestName += @$"{guest.Pinyin.Replace(" ", "")}";
  26621. guestNames += @$"{guestName.Trim()}、";
  26622. }
  26623. if (guestNames.Length > 0)
  26624. {
  26625. guestNames = guestNames.Substring(0, guestNames.Length - 1);
  26626. }
  26627. }
  26628. }
  26629. //if (!string.IsNullOrEmpty(guestNames))
  26630. //{
  26631. hrDtas[i].GuestName = guestNames;
  26632. //}
  26633. }
  26634. strFileName += $"VOUCHER_{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
  26635. Document doc = new Document();
  26636. DocumentBuilder builder = new DocumentBuilder(doc);
  26637. try
  26638. {
  26639. builder.MoveToDocumentStart();
  26640. foreach (var item in hrDtas)
  26641. {
  26642. //标题
  26643. builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Title;
  26644. builder.ParagraphFormat.LineSpacing = 1;
  26645. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26646. builder.ParagraphFormat.Style.Font.Size = 9;
  26647. builder.ParagraphFormat.Style.Font.Bold = true;
  26648. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  26649. builder.Writeln(@$"ACCOMMODATION VOUCHER");
  26650. builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Title;
  26651. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  26652. builder.ParagraphFormat.LineSpacing = 1;
  26653. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26654. builder.ParagraphFormat.Style.Font.Size = 9;
  26655. builder.ParagraphFormat.Style.Font.Bold = true;
  26656. builder.Writeln(@$"VOUCHER No:{item.CheckNumber} DATE: {item.CreateTime.ToString("yyyy-MM-dd")}");
  26657. builder.StartTable();
  26658. // 设置边框颜色
  26659. builder.CellFormat.Borders.Top.Color = System.Drawing.Color.Black;
  26660. //设置边框样式
  26661. builder.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.Dot;
  26662. //表格
  26663. #region 第一行
  26664. builder.InsertCell();
  26665. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  26666. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26667. //builder.CellFormat.AllowAutoFit = false;
  26668. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26669. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26670. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26671. builder.CellFormat.WrapText = true; //自动换行
  26672. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  26673. builder.RowFormat.AllowBreakAcrossPages = false; //文字自适应大小
  26674. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26675. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26676. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26677. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26678. builder.Write("TOUR NO:");
  26679. builder.InsertCell();
  26680. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  26681. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26682. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26683. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26684. builder.ParagraphFormat.Style.Font.Bold = false;
  26685. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26686. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  26687. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26688. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26689. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26690. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26691. builder.Write($"{dele?.TourCode ?? "-"}");
  26692. builder.InsertCell();
  26693. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  26694. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26695. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26696. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26697. builder.ParagraphFormat.Style.Font.Bold = false;
  26698. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26699. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  26700. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26701. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26702. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26703. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26704. builder.Write($"CITY:");
  26705. builder.InsertCell();
  26706. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  26707. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26708. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26709. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26710. builder.ParagraphFormat.Style.Font.Bold = false;
  26711. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26712. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  26713. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26714. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26715. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26716. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26717. builder.Write($"{item.City}");
  26718. builder.EndRow();
  26719. #endregion
  26720. #region 第二行
  26721. builder.InsertCell();
  26722. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  26723. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26724. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26725. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26726. builder.ParagraphFormat.Style.Font.Bold = false;
  26727. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26728. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  26729. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26730. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26731. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26732. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26733. builder.Write("CONFIRMATION NO:");
  26734. builder.InsertCell();
  26735. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  26736. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26737. builder.ParagraphFormat.Style.Font.Size = 8;
  26738. builder.ParagraphFormat.Style.Font.Bold = false;
  26739. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26740. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26741. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  26742. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26743. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26744. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26745. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26746. builder.CellFormat.HorizontalMerge = CellMerge.First;
  26747. builder.Write($"{item.DetermineNo}");
  26748. builder.InsertCell();
  26749. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  26750. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  26751. builder.InsertCell();
  26752. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  26753. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  26754. builder.EndRow();
  26755. #endregion
  26756. #region 第三行
  26757. builder.InsertCell();
  26758. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  26759. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26760. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26761. builder.ParagraphFormat.Style.Font.Bold = false;
  26762. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26763. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26764. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  26765. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26766. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26767. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26768. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26769. builder.Write($"HOTEL NAME:");
  26770. builder.InsertCell();
  26771. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  26772. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26773. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26774. builder.ParagraphFormat.Style.Font.Bold = false;
  26775. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26776. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26777. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  26778. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26779. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26780. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26781. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26782. builder.CellFormat.HorizontalMerge = CellMerge.First;
  26783. builder.Write($"{item.HotelName}");
  26784. builder.InsertCell();
  26785. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  26786. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  26787. builder.InsertCell();
  26788. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  26789. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  26790. builder.EndRow();
  26791. #endregion
  26792. #region 第四行
  26793. builder.InsertCell();
  26794. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  26795. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26796. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26797. builder.ParagraphFormat.Style.Font.Bold = false;
  26798. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26799. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26800. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  26801. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26802. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26803. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26804. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26805. builder.Write($"HOTEL ADDRESS:");
  26806. builder.InsertCell();
  26807. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  26808. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26809. builder.ParagraphFormat.Style.Font.Size = 8;
  26810. builder.ParagraphFormat.Style.Font.Bold = false;
  26811. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26812. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26813. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  26814. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26815. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26816. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26817. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26818. builder.CellFormat.HorizontalMerge = CellMerge.First;
  26819. builder.Write($"{item.HotelAddress}");
  26820. builder.InsertCell();
  26821. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  26822. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  26823. builder.InsertCell();
  26824. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  26825. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  26826. builder.EndRow();
  26827. #endregion
  26828. #region 第五行
  26829. builder.InsertCell();
  26830. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  26831. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26832. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26833. builder.ParagraphFormat.Style.Font.Bold = false;
  26834. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26835. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26836. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  26837. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26838. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26839. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26840. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26841. builder.Write("TEL:");
  26842. builder.InsertCell();
  26843. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  26844. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26845. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26846. builder.ParagraphFormat.Style.Font.Bold = false;
  26847. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26848. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26849. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  26850. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26851. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26852. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26853. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26854. builder.Write($"{item.HotelTel}");
  26855. builder.InsertCell();
  26856. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  26857. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26858. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26859. builder.ParagraphFormat.Style.Font.Bold = false;
  26860. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26861. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26862. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  26863. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26864. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26865. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26866. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26867. builder.Write($"FAX:");
  26868. builder.InsertCell();
  26869. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  26870. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26871. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26872. builder.ParagraphFormat.Style.Font.Bold = false;
  26873. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26874. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26875. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  26876. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26877. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26878. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26879. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26880. builder.Write($"{item.HotelFax}");
  26881. builder.EndRow();
  26882. #endregion
  26883. #region 第六行
  26884. builder.InsertCell();
  26885. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  26886. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26887. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26888. builder.ParagraphFormat.Style.Font.Bold = false;
  26889. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26890. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26891. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  26892. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26893. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26894. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26895. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26896. builder.Write("CHECK IN:");
  26897. builder.InsertCell();
  26898. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  26899. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26900. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26901. builder.ParagraphFormat.Style.Font.Bold = false;
  26902. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26903. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26904. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  26905. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26906. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26907. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26908. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26909. DateTime dtCheckIn = Convert.ToDateTime(item.CheckInDate);
  26910. string checkInStr = dtCheckIn.Day + " " + dtCheckIn.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckIn.Year + " ";
  26911. builder.Write($"{checkInStr}");
  26912. builder.InsertCell();
  26913. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  26914. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26915. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26916. builder.ParagraphFormat.Style.Font.Bold = false;
  26917. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26918. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26919. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  26920. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26921. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26922. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26923. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26924. builder.Write($"CHECK OUT:");
  26925. builder.InsertCell();
  26926. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  26927. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26928. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26929. builder.ParagraphFormat.Style.Font.Bold = false;
  26930. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26931. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26932. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  26933. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26934. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26935. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26936. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26937. DateTime dtCheckOut = Convert.ToDateTime(item.CheckOutDate);
  26938. string checkOutStr = dtCheckOut.Day + " " + dtCheckOut.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckOut.Year + " ";
  26939. builder.Write($"{checkOutStr}");
  26940. builder.EndRow();
  26941. #endregion
  26942. #region 第七行
  26943. builder.InsertCell();
  26944. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  26945. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26946. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26947. builder.ParagraphFormat.Style.Font.Bold = false;
  26948. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26949. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26950. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  26951. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26952. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26953. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26954. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26955. builder.Write($"GUEST NAME:");
  26956. builder.InsertCell();
  26957. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  26958. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26959. builder.ParagraphFormat.Style.Font.Size = 8;
  26960. builder.ParagraphFormat.Style.Font.Bold = false;
  26961. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26962. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26963. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  26964. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26965. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26966. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26967. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26968. builder.CellFormat.HorizontalMerge = CellMerge.First;
  26969. builder.Write($"{item.GuestName.Trim()}");
  26970. builder.InsertCell();
  26971. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  26972. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  26973. builder.InsertCell();
  26974. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  26975. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  26976. builder.EndRow();
  26977. #endregion
  26978. #region 第八行
  26979. builder.InsertCell();
  26980. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  26981. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26982. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26983. builder.ParagraphFormat.Style.Font.Bold = false;
  26984. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26985. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26986. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  26987. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  26988. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  26989. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  26990. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  26991. builder.Write($"ROOM TYPE:");
  26992. builder.InsertCell();
  26993. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  26994. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  26995. builder.ParagraphFormat.Style.Font.Size = 7.5;
  26996. builder.ParagraphFormat.Style.Font.Bold = false;
  26997. builder.CellFormat.HorizontalMerge = CellMerge.None;
  26998. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  26999. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  27000. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27001. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27002. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27003. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27004. builder.CellFormat.HorizontalMerge = CellMerge.First;
  27005. builder.Write($"{item.RoomExplanation}");
  27006. builder.InsertCell();
  27007. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27008. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  27009. builder.InsertCell();
  27010. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27011. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  27012. builder.EndRow();
  27013. #endregion
  27014. #region 第九行
  27015. builder.InsertCell();
  27016. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27017. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27018. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27019. builder.ParagraphFormat.Style.Font.Bold = false;
  27020. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27021. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27022. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  27023. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27024. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27025. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27026. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27027. builder.Write($"NOTE:");
  27028. builder.InsertCell();
  27029. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27030. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27031. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27032. builder.ParagraphFormat.Style.Font.Bold = false;
  27033. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27034. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27035. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  27036. builder.CellFormat.HorizontalMerge = CellMerge.First;
  27037. builder.Write($"ROOM WITH BREAKFAST AND TAX ONLY.\r\nTHIS SERVICE IS PAYABLE BY C-TRIP. FOR EXTRA CHARGE TO BE COLLECTED FROM THE GUEST.");
  27038. builder.InsertCell();
  27039. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27040. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  27041. builder.InsertCell();
  27042. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27043. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  27044. builder.EndRow();
  27045. #endregion
  27046. builder.EndTable();
  27047. //换行
  27048. builder.Writeln("");
  27049. builder.Writeln("");
  27050. }
  27051. #region 获取文档中的所有表格 设置文字自适应
  27052. // 获取文档中的所有表格。
  27053. foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
  27054. {
  27055. // 遍历表格中的所有行。
  27056. foreach (Aspose.Words.Tables.Row row in table.Rows)
  27057. {
  27058. foreach (Cell cell in row.Cells)
  27059. {
  27060. Aspose.Words.Tables.CellFormat cellFormat = cell.CellFormat;
  27061. cellFormat.Width = 0;
  27062. }
  27063. }
  27064. }
  27065. #endregion
  27066. #region 设置页眉
  27067. builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
  27068. string voucherHeaderPath = $"./Images/VoucherHeader.png";
  27069. if (System.IO.File.Exists(voucherHeaderPath))
  27070. {
  27071. byte[] imageBytes = System.IO.File.ReadAllBytes(voucherHeaderPath);
  27072. //Image image = Image.FromStream(imageBytes, ImageType.Png);
  27073. //builder.InsertImage(imageBytes, RelativeHorizontalPosition.Margin, 0, RelativeVerticalPosition.Margin, 0, 81, 36, WrapType.None);
  27074. Aspose.Words.Drawing.Shape shape = builder.InsertImage(imageBytes);
  27075. // 调整图片位置
  27076. shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page; // 将图片的水平位置设置为页面
  27077. shape.RelativeVerticalPosition = RelativeVerticalPosition.TopMargin; // 将图片的垂直位置设置为页眉上边距
  27078. shape.Top = 50; // 将图片距离页眉上边缘的距离
  27079. shape.Left = 0; // 将图片距离页面左边缘的距离
  27080. shape.Width = 81; // 设置图片宽度
  27081. shape.Height = 36; // 设置图片高度
  27082. }
  27083. //靠右
  27084. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  27085. //// 设置页脚上下边距
  27086. //builder.PageSetup.HeaderDistance = 42;
  27087. // 添加页眉线
  27088. Aspose.Words.Border borderHeader = null;
  27089. try
  27090. {
  27091. borderHeader = builder.ParagraphFormat.Borders.Bottom;
  27092. }
  27093. catch (Exception e)
  27094. {
  27095. // TODO Auto-generated catch block
  27096. //e.printStackTrace();
  27097. }
  27098. borderHeader.Shadow = true;
  27099. borderHeader.DistanceFromText = 2;
  27100. borderHeader.LineStyle = Aspose.Words.LineStyle.Single;
  27101. #endregion
  27102. }
  27103. catch (Exception ex)
  27104. {
  27105. }
  27106. var fileDir = AppSettingsHelper.Get("WordBasePath") + strFileName;
  27107. doc.Save(fileDir);
  27108. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/" + strFileName;
  27109. return Ok(JsonView(true, "操作成功!", Url));
  27110. }
  27111. /// <summary>
  27112. /// 酒店预订
  27113. /// 生成 预定成本 Excel
  27114. /// </summary>
  27115. /// <param name="_dto"></param>
  27116. /// <returns></returns>
  27117. [HttpPost]
  27118. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27119. public async Task<IActionResult> PostHotelReservationsPredictedCostFileDownload(HotelReservations_PCFD_DTO _dto)
  27120. {
  27121. #region 参数验证
  27122. var vadalitor = new HotelReservations_PCFD_DTOFoalidator();
  27123. var vadalitorRes = await vadalitor.ValidateAsync(_dto);
  27124. if (!vadalitorRes.IsValid)
  27125. {
  27126. var errors = new StringBuilder();
  27127. foreach (var valid in vadalitorRes.Errors) errors.AppendLine(valid.ErrorMessage);
  27128. return Ok(JsonView(StatusCodes.Status400BadRequest, errors.ToString(), ""));
  27129. }
  27130. #region 团组操作权限验证 76 酒店预定模块
  27131. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  27132. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  27133. #endregion
  27134. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  27135. #region 页面操作权限验证
  27136. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  27137. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  27138. #endregion
  27139. #endregion
  27140. decimal _rate = 1.00M;
  27141. string _currency = string.Empty;
  27142. var currDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.STid == 66).ToList();
  27143. var hrDtas = _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && it.DiId == _dto.DiId).ToList();
  27144. if (hrDtas.Count < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "酒店预订费用未录入,不支持预定成本Excel导出", ""));
  27145. var hotelSubData = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => it.IsDel == 0 && it.DiId == _dto.DiId).ToList();
  27146. var ccpData = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.IsDel == 0 && it.DIId == _dto.DiId && it.CTable == 76).ToList();
  27147. var _GroupCostParameter = _sqlSugar.Queryable<Grp_GroupCostParameter>().Where(it => it.IsDel == 0 && it.DiId == _dto.DiId).First();
  27148. //if (_GroupCostParameter == null) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组成本费用未录入,不支持预定成本Excel导出", ""));
  27149. if (_GroupCostParameter == null)
  27150. {
  27151. //return Ok(JsonView(StatusCodes.Status400BadRequest, "团组成本费用“币种为录入”未录入,不支持预定成本Excel导出", ""));
  27152. bool isIntType = int.TryParse(_currency, out int currId);
  27153. if (isIntType)
  27154. {
  27155. _currency = currDatas.Find(it => it.Id == currId)?.Name ?? "";
  27156. }
  27157. var teamRate = await _teamRateRep.PostGroupTeamRateItemByDiIdAndCTableId(1, _dto.DiId, 76);
  27158. var currInfo = teamRate.Find(it => it.CurrencyCode.Equals(_currency));
  27159. if (currInfo == null)
  27160. {
  27161. //return Ok(JsonView(StatusCodes.Status400BadRequest, $"团组汇率-->酒店模块 {_currency} 币种未设置汇率,不支持预定成本Excel导出", ""));
  27162. }
  27163. else _rate = currInfo.Rate;
  27164. if (!string.IsNullOrEmpty(_currency) && !_currency.ToUpper().Equals("CNY"))
  27165. {
  27166. _rate = _GroupCostParameter.Rate;
  27167. }
  27168. hrDtas = hrDtas.OrderBy(it => it.CheckInDate).ToList();
  27169. //string strFileName = "HotelStatement/";
  27170. //string guestNames = ""; //格式Mr.xxx Ms.xxx
  27171. List<HotelReservations_PCFD_View> pcfds = new List<HotelReservations_PCFD_View>();
  27172. var rateDatas = new List<dynamic>();
  27173. #region 数据处理
  27174. foreach (var item in hrDtas)
  27175. {
  27176. var ccpInfo = ccpData.Where(it => it.DIId == _dto.DiId && it.CId == item.Id).First();
  27177. var roomInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 1).FirstOrDefault(); //房费
  27178. var breakfastInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 2).FirstOrDefault(); //早餐
  27179. var governmentRentInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 3).FirstOrDefault(); //地税
  27180. var cityTaxInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 4).FirstOrDefault(); //城市税
  27181. if (ccpInfo == null || roomInfo == null || breakfastInfo == null || governmentRentInfo == null || cityTaxInfo == null)
  27182. {
  27183. continue;
  27184. }
  27185. string roomCurr = currDatas.Find(it => it.Id == roomInfo?.Currency)?.Name ?? "";
  27186. if (string.IsNullOrEmpty(_currency)) _currency = $"CNY";
  27187. string singleRoomFeeStr = string.Empty,
  27188. doubleRoomFeeStr = string.Empty,
  27189. suiteRoomFeeStr = string.Empty,
  27190. otherRoomFeeStr = string.Empty,
  27191. payMoneyStr = string.Empty,
  27192. cardPriceStr = string.Empty;
  27193. if (roomCurr.Equals("CNY"))
  27194. {
  27195. rateDatas.Add(new { code = "CNY", rate = 1.0000 });
  27196. singleRoomFeeStr = $"{item.SingleRoomPrice.ToString("#0.00")} {roomCurr}";
  27197. doubleRoomFeeStr = $"{item.DoubleRoomPrice.ToString("#0.00")} {roomCurr}";
  27198. suiteRoomFeeStr = $"{item.SuiteRoomPrice.ToString("#0.00")} {roomCurr}";
  27199. otherRoomFeeStr = $"{item.OtherRoomPrice.ToString("#0.00")} {roomCurr}";
  27200. payMoneyStr = $"{ccpInfo.PayMoney.ToString("#0.00")} {currDatas.Find(it => it.Id == ccpInfo?.PaymentCurrency)?.Name ?? ""}";
  27201. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} {currDatas.Find(it => it.Id == item.CardPriceCurrency)?.Name ?? ""}";
  27202. }
  27203. else
  27204. {
  27205. //singleRoomFeeStr = $"{((item.SingleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.SingleRoomPrice.ToString("#0.00")} {roomCurr}";
  27206. //doubleRoomFeeStr = $"{((item.DoubleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.DoubleRoomPrice.ToString("#0.00")} {roomCurr}";
  27207. //suiteRoomFeeStr = $"{((item.SuiteRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.SuiteRoomPrice.ToString("#0.00")} {roomCurr}";
  27208. //otherRoomFeeStr = $"{((item.OtherRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.OtherRoomPrice.ToString("#0.00")} {roomCurr}";
  27209. //payMoneyStr = $"{((ccpInfo.PayMoney * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{ccpInfo.PayMoney.ToString("#0.00")} {roomCurr}";
  27210. //cardPriceStr = $"{((item.CardPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.CardPrice.ToString("#0.00")} {roomCurr}";
  27211. singleRoomFeeStr = $"{item.SingleRoomPrice.ToString("#0.00")} {roomCurr}\r\n{((item.SingleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}";
  27212. doubleRoomFeeStr = $"{item.DoubleRoomPrice.ToString("#0.00")} {roomCurr}\r\n{((item.DoubleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}";
  27213. suiteRoomFeeStr = $"{item.SuiteRoomPrice.ToString("#0.00")} {roomCurr}\r\n{((item.SuiteRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}";
  27214. otherRoomFeeStr = $"{item.OtherRoomPrice.ToString("#0.00")} {roomCurr}\r\n{((item.OtherRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}";
  27215. rateDatas.Add(new { code = roomCurr, rate = roomInfo.Rate });
  27216. var ccpPaymentCurrency = currDatas.Find(it => it.Id == ccpInfo?.PaymentCurrency)?.Name ?? "";
  27217. if (ccpPaymentCurrency.Equals("CNY"))
  27218. {
  27219. payMoneyStr = $"{ccpInfo.PayMoney.ToString("#0.00")} CNY";
  27220. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} CNY";
  27221. }
  27222. else
  27223. {
  27224. rateDatas.Add(new { code = ccpPaymentCurrency, rate = ccpInfo.DayRate });
  27225. payMoneyStr = $"{ccpInfo.PayMoney.ToString("#0.00")} {ccpPaymentCurrency}\r\n{((ccpInfo.PayMoney * ccpInfo.DayRate) / _rate).ToString("#0.00")} CNY";
  27226. }
  27227. var hotelcardPriceCurrency = currDatas.Find(it => it.Id == item?.CardPriceCurrency)?.Name ?? "";
  27228. if (hotelcardPriceCurrency.Equals("CNY"))
  27229. {
  27230. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} CNY";
  27231. }
  27232. else
  27233. {
  27234. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} {hotelcardPriceCurrency}\r\n{((item.CardPrice * roomInfo.Rate) / _rate).ToString("#0.00")} CNY";
  27235. }
  27236. }
  27237. string breakfastPriceStr = string.Empty,
  27238. breakfastCurrency = currDatas.Find(it => it.Id == item.BreakfastCurrency)?.Name ?? "",
  27239. governmentRentStr = string.Empty,
  27240. governmentRentCurrency = currDatas.Find(it => it.Id == item.GovernmentRentCurrency)?.Name ?? "",
  27241. cityTaxStr = string.Empty,
  27242. cityTaxStrCurrency = currDatas.Find(it => it.Id == item.CityTaxCurrency)?.Name ?? "";
  27243. var breakfastCurrency1 = currDatas.Find(it => it.Id == breakfastInfo?.Currency)?.Name;
  27244. if (!string.IsNullOrEmpty(breakfastCurrency1))
  27245. {
  27246. if (breakfastCurrency1.Equals("CNY"))
  27247. {
  27248. breakfastPriceStr = $"{breakfastInfo?.Price.ToString("#0.00")} {breakfastCurrency1}";
  27249. }
  27250. else
  27251. {
  27252. rateDatas.Add(new { code = breakfastCurrency1, rate = breakfastInfo.Rate });
  27253. var breakfastPriceCny = breakfastInfo.Price * breakfastInfo.Rate;
  27254. breakfastPriceStr = $"{breakfastInfo?.Price.ToString("#0.00")} {breakfastCurrency1}\r\n{breakfastPriceCny.ToString("#0.00")} CNY";
  27255. }
  27256. }
  27257. else breakfastPriceStr = $"{breakfastInfo?.Price.ToString("#0.00")} {breakfastCurrency1}";
  27258. var governmentRentCurrency1 = currDatas.Find(it => it.Id == governmentRentInfo?.Currency)?.Name;
  27259. if (!string.IsNullOrEmpty(governmentRentCurrency1))
  27260. {
  27261. if (governmentRentCurrency.Equals("CNY"))
  27262. {
  27263. governmentRentStr = $"{governmentRentInfo?.Price.ToString("#0.00")} {governmentRentCurrency1}";
  27264. }
  27265. else
  27266. {
  27267. rateDatas.Add(new { code = governmentRentCurrency1, rate = governmentRentInfo.Rate });
  27268. var governmentRentCny = governmentRentInfo.Price * governmentRentInfo.Rate;
  27269. governmentRentStr = $"{governmentRentInfo?.Price.ToString("#0.00")} {governmentRentCurrency1}\r\n{governmentRentCny.ToString("#0.00")} CNY";
  27270. }
  27271. }
  27272. else governmentRentStr = $"{governmentRentInfo?.Price.ToString("#0.00")} {governmentRentCurrency1}";
  27273. var cityTaxStrCurrency1 = currDatas.Find(it => it.Id == cityTaxInfo?.Currency)?.Name;
  27274. if (!string.IsNullOrEmpty(cityTaxStrCurrency1))
  27275. {
  27276. if (cityTaxStrCurrency1.Equals("CNY"))
  27277. {
  27278. cityTaxStr = $"{cityTaxInfo?.Price.ToString("#0.00")} {cityTaxStrCurrency1}";
  27279. }
  27280. else
  27281. {
  27282. rateDatas.Add(new { code = cityTaxStrCurrency1, rate = cityTaxInfo.Rate });
  27283. var cityTaxCny = cityTaxInfo.Price * cityTaxInfo.Rate;
  27284. cityTaxStr = $"{cityTaxInfo?.Price.ToString("#0.00")} {cityTaxStrCurrency1}\r\n{cityTaxCny.ToString("#0.00")} CNY";
  27285. }
  27286. }
  27287. else cityTaxStr = $"{cityTaxInfo?.Price.ToString("#0.00")} {cityTaxStrCurrency1}";
  27288. int payDId = roomInfo?.PayDId ?? 0;
  27289. pcfds.Add(new HotelReservations_PCFD_View()
  27290. {
  27291. City = item.City,
  27292. HotelName = item.HotelName,
  27293. Date = $"{item.CheckInDate} - {item.CheckOutDate}",
  27294. // SingleRoomCount = item.SingleRoomCount,
  27295. SingleRoomPrice = singleRoomFeeStr,
  27296. // DoubleRoomCount = item.DoubleRoomCount,
  27297. DoubleRoomPrice = doubleRoomFeeStr,
  27298. //SuiteRoomCount = item.SuiteRoomCount,
  27299. SuiteRoomPrice = suiteRoomFeeStr,
  27300. OtherRoomPrice = otherRoomFeeStr,
  27301. //OtherRoomCount = item.OtherRoomCount,
  27302. BreakfastPrice = breakfastPriceStr,
  27303. GovernmentRent = governmentRentStr,
  27304. CityTax = cityTaxStr,
  27305. RoomExplanation = item.RoomExplanation,
  27306. PayTypeName = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == payDId).First()?.Name ?? "",
  27307. PayTime = roomInfo?.ConsumptionDate,
  27308. BankNo = roomInfo?.BankNo,
  27309. PayMoney = payMoneyStr,
  27310. //PayMoneys = ccpInfo.PayMoney.ToString("#0.00"),
  27311. ConsumptionPatterns = roomInfo?.ConsumptionPatterns,
  27312. CardPrice = cardPriceStr,
  27313. Remark = ccpInfo.Remark
  27314. });
  27315. }
  27316. #endregion
  27317. //载入模板
  27318. WorkbookDesigner designer = new WorkbookDesigner();
  27319. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/酒店预订成本.xls");
  27320. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == _dto.DiId).First();
  27321. var userInfo = _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == hrDtas[0].CreateUserId).First();
  27322. designer.SetDataSource("TourNo", groupInfo.TourCode);
  27323. var rateDatas1 = rateDatas.Distinct();
  27324. var rateStr = string.Empty;
  27325. foreach (var item in rateDatas1)
  27326. {
  27327. rateStr += $"{item.code} {item.rate.ToString("#0.0000")} \t\t";
  27328. }
  27329. designer.SetDataSource("TeamName", $"酒店模块汇率:{rateStr}");
  27330. designer.SetDataSource("Opertor", userInfo.CnName);
  27331. DataTable dt = CommonFun.GetDataTableFromIList<HotelReservations_PCFD_View>(pcfds);
  27332. dt.TableName = "ViewMyHotelReservations";
  27333. designer.SetDataSource(dt);
  27334. designer.Process();
  27335. string fileName = $"HotelReservation/{groupInfo.TeamName.Replace("/", "").Replace(@"\", "").Trim()}_酒店预订成本_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  27336. string serverPath = AppSettingsHelper.Get("ExcelBasePath") + fileName;
  27337. designer.Workbook.Save(serverPath);
  27338. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  27339. #region 删除指定行
  27340. bool singleDel = true, doubleDel = true, suiteDel = true, otherDel = true, zcDel = true, dsDel = true, cssDel = true, cpDel = true, remarkDel = true;
  27341. int singleIndex = dt.Columns["SingleRoomPrice"].Ordinal,
  27342. doubleIndex = dt.Columns["DoubleRoomPrice"].Ordinal,
  27343. suiteIndex = dt.Columns["SuiteRoomPrice"].Ordinal,
  27344. otherIndex = dt.Columns["OtherRoomPrice"].Ordinal,
  27345. zcIndex = dt.Columns["BreakfastPrice"].Ordinal,
  27346. dsIndex = dt.Columns["GovernmentRent"].Ordinal,
  27347. cssIndex = dt.Columns["CityTax"].Ordinal,
  27348. cpIndex = dt.Columns["ConsumptionPatterns"].Ordinal,
  27349. remarkIndex = dt.Columns["Remark"].Ordinal;
  27350. //删除指定列
  27351. foreach (DataRow item in dt.Rows)
  27352. {
  27353. string singleStr = item["SingleRoomPrice"].ToString();
  27354. bool containsDigitButNotZero1 = !singleStr.StartsWith("0") && Regex.IsMatch(singleStr, @"[1-9]");
  27355. if (containsDigitButNotZero1) singleDel = false;
  27356. singleIndex = dt.Columns["SingleRoomPrice"].Ordinal;
  27357. string doubleStr = item["DoubleRoomPrice"].ToString();
  27358. bool containsDigitButNotZero2 = !doubleStr.StartsWith("0") && Regex.IsMatch(doubleStr, @"[1-9]");
  27359. if (containsDigitButNotZero2) doubleDel = false;
  27360. string suiteStr = item["SuiteRoomPrice"].ToString();
  27361. bool containsDigitButNotZero3 = !singleStr.StartsWith("0") && Regex.IsMatch(doubleStr, @"[1-9]");
  27362. if (containsDigitButNotZero3) suiteDel = false;
  27363. string otherStr = item["OtherRoomPrice"].ToString();
  27364. bool containsDigitButNotZero4 = !otherStr.StartsWith("0") && Regex.IsMatch(otherStr, @"[1-9]");
  27365. if (containsDigitButNotZero4) otherDel = false;
  27366. string zcStr = item["BreakfastPrice"].ToString();
  27367. bool containsDigitButNotZero5 = !zcStr.StartsWith("0") && Regex.IsMatch(zcStr, @"[1-9]");
  27368. if (containsDigitButNotZero5) zcDel = false;
  27369. string dsStr = item["GovernmentRent"].ToString();
  27370. bool containsDigitButNotZero6 = !dsStr.StartsWith("0") && Regex.IsMatch(dsStr, @"[1-9]");
  27371. if (containsDigitButNotZero6) dsDel = false;
  27372. string cssStr = item["CityTax"].ToString();
  27373. bool containsDigitButNotZero7 = !cssStr.StartsWith("0") && Regex.IsMatch(cssStr, @"[1-9]");
  27374. if (containsDigitButNotZero7) cssDel = false;
  27375. string cpStr = item["ConsumptionPatterns"].ToString();
  27376. if (!string.IsNullOrEmpty(cpStr)) cpDel = false;
  27377. string remarkStr = item["Remark"].ToString();
  27378. if (!string.IsNullOrEmpty(remarkStr)) remarkDel = false;
  27379. }
  27380. DeleteColumn(serverPath, remarkIndex, remarkDel);
  27381. DeleteColumn(serverPath, cpIndex, cpDel);
  27382. DeleteColumn(serverPath, dsIndex, dsDel);
  27383. DeleteColumn(serverPath, cssIndex, cssDel);
  27384. DeleteColumn(serverPath, zcIndex, zcDel);
  27385. DeleteColumn(serverPath, otherIndex, otherDel);
  27386. DeleteColumn(serverPath, suiteIndex, suiteDel);
  27387. DeleteColumn(serverPath, doubleIndex, doubleDel);
  27388. DeleteColumn(serverPath, singleIndex, singleDel);
  27389. #endregion
  27390. //只保留第一个表格
  27391. DeleteSheet(serverPath);
  27392. return Ok(JsonView(true, "操作成功", url = rst));
  27393. }
  27394. else
  27395. {
  27396. _currency = _GroupCostParameter.Currency;
  27397. bool isIntType = int.TryParse(_currency, out int currId);
  27398. if (isIntType)
  27399. {
  27400. _currency = currDatas.Find(it => it.Id == currId)?.Name ?? "";
  27401. }
  27402. var teamRate = await _teamRateRep.PostGroupTeamRateItemByDiIdAndCTableId(1, _dto.DiId, 76);
  27403. var currInfo = teamRate.Find(it => it.CurrencyCode.Equals(_currency));
  27404. if (currInfo == null)
  27405. {
  27406. return Ok(JsonView(StatusCodes.Status400BadRequest, $"团组汇率-->酒店模块 {_currency} 币种未设置汇率,不支持预定成本Excel导出", ""));
  27407. }
  27408. if (!_currency.ToUpper().Equals("CNY"))
  27409. {
  27410. _rate = _GroupCostParameter.Rate;
  27411. }
  27412. _rate = currInfo.Rate;
  27413. hrDtas = hrDtas.OrderBy(it => it.CheckInDate).ToList();
  27414. //string strFileName = "HotelStatement/";
  27415. //string guestNames = ""; //格式Mr.xxx Ms.xxx
  27416. List<HotelReservations_PCFD_View> pcfds = new List<HotelReservations_PCFD_View>();
  27417. #region 数据处理
  27418. foreach (var item in hrDtas)
  27419. {
  27420. var ccpInfo = ccpData.Where(it => it.DIId == _dto.DiId && it.CId == item.Id).First();
  27421. var roomInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 1).FirstOrDefault(); //房费
  27422. var breakfastInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 2).FirstOrDefault(); //早餐
  27423. var governmentRentInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 3).FirstOrDefault(); //地税
  27424. var cityTaxInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 4).FirstOrDefault(); //城市税
  27425. string roomCurr = currDatas.Find(it => it.Id == roomInfo?.Currency)?.Name ?? "";
  27426. string singleRoomFeeStr = string.Empty,
  27427. doubleRoomFeeStr = string.Empty,
  27428. suiteRoomFeeStr = string.Empty,
  27429. otherRoomFeeStr = string.Empty,
  27430. payMoneyStr = string.Empty,
  27431. cardPriceStr = string.Empty;
  27432. if (roomCurr.Equals(_currency))
  27433. {
  27434. singleRoomFeeStr = $"{item.SingleRoomPrice.ToString("#0.00")} {_currency}";
  27435. doubleRoomFeeStr = $"{item.DoubleRoomPrice.ToString("#0.00")} {_currency}";
  27436. suiteRoomFeeStr = $"{item.SuiteRoomPrice.ToString("#0.00")} {_currency}";
  27437. otherRoomFeeStr = $"{item.OtherRoomPrice.ToString("#0.00")} {_currency}";
  27438. payMoneyStr = $"{ccpInfo.PayMoney.ToString("#0.00")} {_currency}";
  27439. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} {_currency}";
  27440. }
  27441. else
  27442. {
  27443. singleRoomFeeStr = $"{((item.SingleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.SingleRoomPrice.ToString("#0.00")} {roomCurr}";
  27444. doubleRoomFeeStr = $"{((item.DoubleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.DoubleRoomPrice.ToString("#0.00")} {roomCurr}";
  27445. suiteRoomFeeStr = $"{((item.SuiteRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.SuiteRoomPrice.ToString("#0.00")} {roomCurr}";
  27446. otherRoomFeeStr = $"{((item.OtherRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.OtherRoomPrice.ToString("#0.00")} {roomCurr}";
  27447. payMoneyStr = $"{((ccpInfo.PayMoney * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{ccpInfo.PayMoney.ToString("#0.00")} {roomCurr}";
  27448. cardPriceStr = $"{((item.CardPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.CardPrice.ToString("#0.00")} {roomCurr}";
  27449. }
  27450. string breakfastPriceStr = string.Empty,
  27451. breakfastCurrency = currDatas.Find(it => it.Id == item.BreakfastCurrency)?.Name ?? "",
  27452. governmentRentStr = string.Empty,
  27453. governmentRentCurrency = currDatas.Find(it => it.Id == item.GovernmentRentCurrency)?.Name ?? "",
  27454. cityTaxStrStr = string.Empty,
  27455. cityTaxStrCurrency = currDatas.Find(it => it.Id == item.CityTaxCurrency)?.Name ?? "";
  27456. breakfastPriceStr = $"{breakfastInfo?.Price.ToString("#0.00")} {currDatas.Find(it => it.Id == breakfastInfo?.Currency)?.Name}";
  27457. governmentRentStr = $"{governmentRentInfo?.Price.ToString("#0.00")} {currDatas.Find(it => it.Id == governmentRentInfo?.Currency)?.Name}";
  27458. cityTaxStrStr = $"{cityTaxInfo?.Price.ToString("#0.00")} {currDatas.Find(it => it.Id == cityTaxInfo?.Currency)?.Name}";
  27459. int payDId = roomInfo?.PayDId ?? 0;
  27460. pcfds.Add(new HotelReservations_PCFD_View()
  27461. {
  27462. City = item.City,
  27463. HotelName = item.HotelName,
  27464. Date = $"{item.CheckInDate} - {item.CheckOutDate}",
  27465. // SingleRoomCount = item.SingleRoomCount,
  27466. SingleRoomPrice = singleRoomFeeStr,
  27467. // DoubleRoomCount = item.DoubleRoomCount,
  27468. DoubleRoomPrice = doubleRoomFeeStr,
  27469. //SuiteRoomCount = item.SuiteRoomCount,
  27470. SuiteRoomPrice = suiteRoomFeeStr,
  27471. OtherRoomPrice = otherRoomFeeStr,
  27472. //OtherRoomCount = item.OtherRoomCount,
  27473. BreakfastPrice = breakfastPriceStr,
  27474. GovernmentRent = governmentRentStr,
  27475. CityTax = cityTaxStrStr,
  27476. RoomExplanation = item.RoomExplanation,
  27477. PayTypeName = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == payDId).First()?.Name ?? "",
  27478. PayTime = roomInfo?.ConsumptionDate,
  27479. BankNo = roomInfo?.BankNo,
  27480. PayMoney = payMoneyStr,
  27481. //PayMoneys = ccpInfo.PayMoney.ToString("#0.00"),
  27482. ConsumptionPatterns = roomInfo?.ConsumptionPatterns,
  27483. CardPrice = cardPriceStr,
  27484. Remark = ccpInfo.Remark
  27485. });
  27486. }
  27487. #endregion
  27488. //载入模板
  27489. WorkbookDesigner designer = new WorkbookDesigner();
  27490. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/酒店预订成本.xls");
  27491. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == _dto.DiId).First();
  27492. var userInfo = _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == hrDtas[0].CreateUserId).First();
  27493. designer.SetDataSource("TourNo", groupInfo.TourCode);
  27494. designer.SetDataSource("TeamName", $"{groupInfo.TeamName} 团组成本币种:{_currency} 团组汇率-->酒店模块汇率:{_rate.ToString("#0.0000")}");
  27495. designer.SetDataSource("Opertor", userInfo.CnName);
  27496. DataTable dt = CommonFun.GetDataTableFromIList<HotelReservations_PCFD_View>(pcfds);
  27497. dt.TableName = "ViewMyHotelReservations";
  27498. designer.SetDataSource(dt);
  27499. designer.Process();
  27500. string fileName = $"HotelReservation/{groupInfo.TeamName.Replace("/", "").Replace(@"\", "").Trim()}_酒店预订成本_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  27501. string serverPath = AppSettingsHelper.Get("ExcelBasePath") + fileName;
  27502. designer.Workbook.Save(serverPath);
  27503. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  27504. #region 删除指定行
  27505. bool singleDel = true, doubleDel = true, suiteDel = true, otherDel = true, zcDel = true, dsDel = true, cssDel = true, cpDel = true, remarkDel = true;
  27506. int singleIndex = dt.Columns["SingleRoomPrice"].Ordinal,
  27507. doubleIndex = dt.Columns["DoubleRoomPrice"].Ordinal,
  27508. suiteIndex = dt.Columns["SuiteRoomPrice"].Ordinal,
  27509. otherIndex = dt.Columns["OtherRoomPrice"].Ordinal,
  27510. zcIndex = dt.Columns["BreakfastPrice"].Ordinal,
  27511. dsIndex = dt.Columns["GovernmentRent"].Ordinal,
  27512. cssIndex = dt.Columns["CityTax"].Ordinal,
  27513. cpIndex = dt.Columns["ConsumptionPatterns"].Ordinal,
  27514. remarkIndex = dt.Columns["Remark"].Ordinal;
  27515. //删除指定列
  27516. foreach (DataRow item in dt.Rows)
  27517. {
  27518. string singleStr = item["SingleRoomPrice"].ToString();
  27519. bool containsDigitButNotZero1 = !singleStr.StartsWith("0") && Regex.IsMatch(singleStr, @"[1-9]");
  27520. if (containsDigitButNotZero1) singleDel = false;
  27521. singleIndex = dt.Columns["SingleRoomPrice"].Ordinal;
  27522. string doubleStr = item["DoubleRoomPrice"].ToString();
  27523. bool containsDigitButNotZero2 = !doubleStr.StartsWith("0") && Regex.IsMatch(doubleStr, @"[1-9]");
  27524. if (containsDigitButNotZero2) doubleDel = false;
  27525. string suiteStr = item["SuiteRoomPrice"].ToString();
  27526. bool containsDigitButNotZero3 = !singleStr.StartsWith("0") && Regex.IsMatch(doubleStr, @"[1-9]");
  27527. if (containsDigitButNotZero3) suiteDel = false;
  27528. string otherStr = item["OtherRoomPrice"].ToString();
  27529. bool containsDigitButNotZero4 = !otherStr.StartsWith("0") && Regex.IsMatch(otherStr, @"[1-9]");
  27530. if (containsDigitButNotZero4) otherDel = false;
  27531. string zcStr = item["BreakfastPrice"].ToString();
  27532. bool containsDigitButNotZero5 = !zcStr.StartsWith("0") && Regex.IsMatch(zcStr, @"[1-9]");
  27533. if (containsDigitButNotZero5) zcDel = false;
  27534. string dsStr = item["GovernmentRent"].ToString();
  27535. bool containsDigitButNotZero6 = !dsStr.StartsWith("0") && Regex.IsMatch(dsStr, @"[1-9]");
  27536. if (containsDigitButNotZero6) dsDel = false;
  27537. string cssStr = item["CityTax"].ToString();
  27538. bool containsDigitButNotZero7 = !cssStr.StartsWith("0") && Regex.IsMatch(cssStr, @"[1-9]");
  27539. if (containsDigitButNotZero7) cssDel = false;
  27540. string cpStr = item["ConsumptionPatterns"].ToString();
  27541. if (!string.IsNullOrEmpty(cpStr)) cpDel = false;
  27542. string remarkStr = item["Remark"].ToString();
  27543. if (!string.IsNullOrEmpty(remarkStr)) remarkDel = false;
  27544. }
  27545. DeleteColumn(serverPath, remarkIndex, remarkDel);
  27546. DeleteColumn(serverPath, cpIndex, cpDel);
  27547. DeleteColumn(serverPath, dsIndex, dsDel);
  27548. DeleteColumn(serverPath, cssIndex, cssDel);
  27549. DeleteColumn(serverPath, zcIndex, zcDel);
  27550. DeleteColumn(serverPath, otherIndex, otherDel);
  27551. DeleteColumn(serverPath, suiteIndex, suiteDel);
  27552. DeleteColumn(serverPath, doubleIndex, doubleDel);
  27553. DeleteColumn(serverPath, singleIndex, singleDel);
  27554. #endregion
  27555. //只保留第一个表格
  27556. DeleteSheet(serverPath);
  27557. return Ok(JsonView(true, "操作成功", url = rst));
  27558. }
  27559. //return Ok(JsonView(false));
  27560. }
  27561. /// <summary>
  27562. /// 删除指定列
  27563. /// </summary>
  27564. /// <param name="file"></param>
  27565. /// <param name="columnIndex"></param>
  27566. /// <param name="isDel"></param>
  27567. private void DeleteColumn(string file, int columnIndex, bool isDel)
  27568. {
  27569. Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(file);
  27570. //wb.Save(file);
  27571. Aspose.Cells.Worksheet sheet1 = wb.Worksheets[0];
  27572. if (sheet1 != null)
  27573. {
  27574. if (isDel)
  27575. {
  27576. Cells cells = sheet1.Cells;
  27577. cells.DeleteColumn(columnIndex);
  27578. }
  27579. }
  27580. wb.Save(file);
  27581. }
  27582. /// <summary>
  27583. /// 删除sheet
  27584. /// </summary>
  27585. /// <param name="file"></param>
  27586. private void DeleteSheet(string file)
  27587. {
  27588. Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(file);
  27589. //wb.Save(file);
  27590. List<string> sheets = new List<string>();
  27591. foreach (var item in wb.Worksheets)
  27592. {
  27593. sheets.Add(item.Name);
  27594. }
  27595. if (sheets.Count > 0)
  27596. {
  27597. sheets.RemoveAt(0);//不删除第一个sheet
  27598. foreach (var item in sheets)
  27599. {
  27600. wb.Worksheets.RemoveAt(item);
  27601. }
  27602. }
  27603. wb.Save(file);
  27604. }
  27605. /// <summary>
  27606. /// 酒店预订
  27607. /// 确认单
  27608. /// </summary>
  27609. /// <param name="_dto"></param>
  27610. /// <returns></returns>
  27611. [HttpPost]
  27612. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27613. public async Task<IActionResult> PostHotelReservationsConfirmationSlip(HotelReservationsConfirmationSlipDto _dto)
  27614. {
  27615. try
  27616. {
  27617. #region 参数验证
  27618. if (_dto.UserId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "员工Id为空", ""));
  27619. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  27620. if (_dto.DiId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组Id为空", ""));
  27621. #region 团组操作权限验证 76 酒店预定模块
  27622. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  27623. if (groupAuthView.Code != 0) return Ok(JsonView(StatusCodes.Status400BadRequest, groupAuthView.Msg, ""));
  27624. #endregion
  27625. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  27626. #region 页面操作权限验证
  27627. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  27628. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  27629. #endregion
  27630. #endregion
  27631. //团组信息
  27632. Grp_DelegationInfo di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(a => a.Id == _dto.DiId);
  27633. //酒店数据
  27634. List<Grp_HotelReservations> listhoteldata = await _sqlSugar.Queryable<Grp_HotelReservations>().Where(a => a.DiId == _dto.DiId && a.IsDel == 0).ToListAsync();
  27635. if (listhoteldata.Count < 0)
  27636. {
  27637. return Ok(JsonView(StatusCodes.Status400BadRequest, "当前团组暂无酒店预订信息!", ""));
  27638. }
  27639. //利datatable存储
  27640. DataTable dt = new DataTable();
  27641. dt.Columns.Add("CheckInDate", typeof(string));
  27642. dt.Columns.Add("City", typeof(string));
  27643. dt.Columns.Add("Hotel", typeof(string));
  27644. dt.Columns.Add("Room", typeof(string));
  27645. for (int i = 0; i < listhoteldata.Count; i++)
  27646. {
  27647. DateTime dayStart = Convert.ToDateTime(listhoteldata[i].CheckInDate);
  27648. DateTime dayEnd = Convert.ToDateTime(listhoteldata[i].CheckOutDate);
  27649. while (dayStart < dayEnd)
  27650. {
  27651. string temp = "";
  27652. DataRow row = dt.NewRow();
  27653. row["CheckInDate"] = dayStart.ToString("yyyy-MM-dd");
  27654. row["City"] = listhoteldata[i].City;
  27655. row["Hotel"] = listhoteldata[i].HotelName;
  27656. if (listhoteldata[i].SingleRoomCount > 0)
  27657. {
  27658. temp = listhoteldata[i].SingleRoomCount + "个单间" + "\r\n";
  27659. }
  27660. if (listhoteldata[i].DoubleRoomCount > 0)
  27661. {
  27662. temp = temp + listhoteldata[i].DoubleRoomCount + "个标间" + "\r\n";
  27663. }
  27664. if (listhoteldata[i].SuiteRoomCount > 0)
  27665. {
  27666. temp = temp + listhoteldata[i].SuiteRoomCount + "个套房" + "\r\n";
  27667. }
  27668. if (listhoteldata[i].OtherRoomCount > 0)
  27669. {
  27670. temp = temp + listhoteldata[i].OtherRoomCount + "个其他房型" + "\r\n";
  27671. }
  27672. row["Room"] = temp;
  27673. dt.Rows.Add(row);
  27674. dayStart = dayStart.AddDays(1);
  27675. }
  27676. }
  27677. Dictionary<string, string> dic = new Dictionary<string, string>();
  27678. dic.Add("Dele", di.TeamName);
  27679. dic.Add("City", di.VisitCountry);
  27680. //模板路径
  27681. string tempPath = AppSettingsHelper.Get("WordBasePath") + "Template/酒店用房确认单-模板.doc";
  27682. //载入模板
  27683. Aspose.Words.Document doc = new Aspose.Words.Document(tempPath);
  27684. DocumentBuilder builder = new DocumentBuilder(doc);
  27685. foreach (var key in dic.Keys)
  27686. {
  27687. builder.MoveToBookmark(key);
  27688. builder.Write(dic[key]);
  27689. }
  27690. //获取word里所有表格
  27691. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  27692. //获取所填表格的序数
  27693. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  27694. var rowStart = tableOne.Rows[0]; //获取第1行
  27695. //循环赋值
  27696. for (int i = 0; i < dt.Rows.Count; i++)
  27697. {
  27698. builder.MoveToCell(0, i + 1, 0, 0);
  27699. builder.Write(dt.Rows[i]["CheckInDate"].ToString());
  27700. builder.MoveToCell(0, i + 1, 1, 0);
  27701. builder.Write(dt.Rows[i]["City"].ToString());
  27702. builder.MoveToCell(0, i + 1, 2, 0);
  27703. builder.Write(dt.Rows[i]["Hotel"].ToString());
  27704. builder.MoveToCell(0, i + 1, 3, 0);
  27705. builder.Write(dt.Rows[i]["Room"].ToString());
  27706. }
  27707. //删除多余行
  27708. while (tableOne.Rows.Count > dt.Rows.Count + 1)
  27709. {
  27710. tableOne.Rows.RemoveAt(dt.Rows.Count + 1);
  27711. }
  27712. string strFileName = di.TeamName + "酒店确认单.doc";
  27713. doc.Save(AppSettingsHelper.Get("WordBasePath") + "HotelStatement/" + strFileName);
  27714. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/HotelStatement/" + strFileName;
  27715. return Ok(JsonView(true, "成功", url));
  27716. }
  27717. catch (Exception ex)
  27718. {
  27719. return Ok(JsonView(StatusCodes.Status400BadRequest, ex.Message, ""));
  27720. }
  27721. }
  27722. #endregion
  27723. #region 团组状态
  27724. /// <summary>
  27725. /// 团组状态列表 Page
  27726. /// </summary>
  27727. /// <param name="dto">团组列表请求dto</param>
  27728. /// <returns></returns>
  27729. [HttpPost]
  27730. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27731. public async Task<IActionResult> PostGroupStatusPageList(GroupStatusListDto dto)
  27732. {
  27733. if (dto == null) return Ok(JsonView(false, "请输入搜索条件!"));
  27734. if (dto.PortType == 1 || dto.PortType == 2) // web/Android
  27735. {
  27736. string sqlWhere = string.Empty;
  27737. if (dto.IsSure == 0) //未完成
  27738. {
  27739. sqlWhere += string.Format(@" And IsSure = 0");
  27740. }
  27741. else if (dto.IsSure == 1) //已完成
  27742. {
  27743. sqlWhere += string.Format(@" And IsSure = 1");
  27744. }
  27745. if (!string.IsNullOrEmpty(dto.SearchCriteria))
  27746. {
  27747. string tj = dto.SearchCriteria;
  27748. sqlWhere += string.Format(@"And (ssd.Name Like '%{0}%' Or TeamName Like '%{1}%' Or ClientName Like '%{2}%' Or ClientName Like '%{3}%' Or su.CnName Like '%{4}%')",
  27749. tj, tj, tj, tj, tj);
  27750. }
  27751. string sql = string.Format(@"Select Row_Number,Id,SalesQuoteNo,TourCode,TeamTypeId, TeamType,
  27752. TeamLevId,TeamLev,TeamName,ClientName,ClientUnit,
  27753. VisitDate,VisitDays,VisitPNumber,JietuanOperator,IsSure,CreateTime
  27754. From (
  27755. Select row_number() over(order by gdi.VisitStartDate Desc) as Row_Number,
  27756. gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,
  27757. ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,
  27758. VisitDate,VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure,gdi.CreateTime
  27759. From Grp_DelegationInfo gdi
  27760. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  27761. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  27762. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  27763. Where gdi.IsDel = 0 {0}
  27764. ) temp ", sqlWhere);
  27765. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  27766. var _DelegationList = await _sqlSugar.SqlQueryable<GroupStatusView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);//ToPageAsync
  27767. return Ok(JsonView(true, "查询成功!", _DelegationList, total));
  27768. }
  27769. else
  27770. {
  27771. return Ok(JsonView(false, "查询失败"));
  27772. }
  27773. }
  27774. /// <summary>
  27775. /// 团组状态
  27776. /// 设置操作完成
  27777. /// </summary>
  27778. /// <param name="dto">团组列表请求dto</param>
  27779. /// <returns></returns>
  27780. [HttpPost]
  27781. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27782. public async Task<IActionResult> PostGroupStatusSetOperationComplete(GroupStatusSetOperationCompleteDto dto)
  27783. {
  27784. if (dto == null) return Ok(JsonView(false, "请输入搜索条件!"));
  27785. Grp_DelegationInfo _DelegationInfo = new Grp_DelegationInfo()
  27786. {
  27787. Id = dto.Id,
  27788. IsSure = 1
  27789. };
  27790. var result = await _sqlSugar.Updateable(_DelegationInfo)
  27791. .UpdateColumns(it => new { it.IsSure })
  27792. .WhereColumns(it => new { it.Id })
  27793. .ExecuteCommandAsync();
  27794. if (result > 0)
  27795. {
  27796. return Ok(JsonView(true, "操作完成!"));
  27797. }
  27798. return Ok(JsonView(false, "操作失败!"));
  27799. }
  27800. #endregion
  27801. #region 保险费用录入
  27802. /// <summary>
  27803. /// 根据团组Id查询保险费用列表
  27804. /// </summary>
  27805. /// <param name="dto"></param>
  27806. /// <returns></returns>
  27807. [HttpPost]
  27808. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27809. public async Task<IActionResult> CustomersByDiId(CustomersByDiIdDto dto)
  27810. {
  27811. Result groupData = await _customersRep.CustomersByDiId(dto);
  27812. if (groupData.Code != 0)
  27813. {
  27814. return Ok(JsonView(false, groupData.Msg));
  27815. }
  27816. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  27817. }
  27818. /// <summary>
  27819. /// 根据保险费用Id查询保险费用详细
  27820. /// </summary>
  27821. /// <param name="dto"></param>
  27822. /// <returns></returns>
  27823. [HttpPost]
  27824. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27825. public async Task<IActionResult> CustomersById(CustomersByIdDto dto)
  27826. {
  27827. try
  27828. {
  27829. Result groupData = await _customersRep.CustomersById(dto);
  27830. if (groupData.Code != 0)
  27831. {
  27832. return Ok(JsonView(false, groupData.Msg));
  27833. }
  27834. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  27835. }
  27836. catch (Exception ex)
  27837. {
  27838. return Ok(JsonView(false, ex.Message));
  27839. }
  27840. }
  27841. /// <summary>
  27842. /// 保险费用录入页面初始化绑定
  27843. /// </summary>
  27844. /// <param name="dto"></param>
  27845. /// <returns></returns>
  27846. [HttpPost]
  27847. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27848. public async Task<IActionResult> CustomersInitialize(CustomersInitializeDto dto)
  27849. {
  27850. try
  27851. {
  27852. Result groupData = await _customersRep.CustomersInitialize(dto);
  27853. if (groupData.Code != 0)
  27854. {
  27855. return Ok(JsonView(false, groupData.Msg));
  27856. }
  27857. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  27858. }
  27859. catch (Exception ex)
  27860. {
  27861. return Ok(JsonView(false, ex.Message));
  27862. }
  27863. }
  27864. /// <summary>
  27865. /// 保险费用操作(Status:1.新增,2.修改)
  27866. /// </summary>
  27867. /// <param name="dto"></param>
  27868. /// <returns></returns>
  27869. [HttpPost]
  27870. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27871. public async Task<IActionResult> OpCustomers(OpCustomersDto dto)
  27872. {
  27873. //验证
  27874. if (dto.Status == 2)
  27875. {
  27876. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 82);
  27877. if (!valid) return Ok(JsonView(false, msg));
  27878. }
  27879. Result groupData = await _customersRep.OpCustomers(dto);
  27880. if (groupData.Code != 0)
  27881. {
  27882. return Ok(JsonView(false, groupData.Msg));
  27883. }
  27884. #region 应用推送
  27885. try
  27886. {
  27887. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  27888. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  27889. int dataId = groupData.Data.GetType().GetProperty("dataId").GetValue(groupData.Data, null);
  27890. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  27891. //自动审核
  27892. await _feeAuditRep.FeeAutomaticAudit(4, dto.DiId, dataId);
  27893. //2024-10-21 新增LZ UID
  27894. var userIds = new List<int>() { 21 };
  27895. string title = $"系统通知";
  27896. var diId = dto.DiId;
  27897. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  27898. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  27899. string content = "";
  27900. if (dto.Status == 1) content = $"[新增-保险费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  27901. else if (dto.Status == 2) content = $"[更新-保险费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  27902. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  27903. PageParam_PriceAuditH5 h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "82" };
  27904. await APNsTools.iOS_PushNotifications1("051", "保险费用审核", "", content, true, "ExpenseAuditWebView", h5);
  27905. }
  27906. catch (Exception ex)
  27907. {
  27908. }
  27909. #endregion
  27910. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  27911. }
  27912. /// <summary>
  27913. /// 保险文件上传
  27914. /// </summary>
  27915. /// <param name="file"></param>
  27916. /// <returns></returns>
  27917. [HttpPost]
  27918. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27919. public async Task<IActionResult> UploadCus(IFormFile file)
  27920. {
  27921. try
  27922. {
  27923. if (file != null)
  27924. {
  27925. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  27926. //文件名称
  27927. string projectFileName = file.FileName;
  27928. //上传的文件的路径
  27929. string filePath = "";
  27930. if (!Directory.Exists(fileDir))
  27931. {
  27932. Directory.CreateDirectory(fileDir);
  27933. }
  27934. //上传的文件的路径
  27935. filePath = fileDir + $@"\保险费用文件上传\{projectFileName}";
  27936. using (FileStream fs = System.IO.File.Create(filePath))
  27937. {
  27938. file.CopyTo(fs);
  27939. fs.Flush();
  27940. }
  27941. return Ok(JsonView(true, "上传成功!", projectFileName));
  27942. }
  27943. else
  27944. {
  27945. return Ok(JsonView(false, "上传失败!"));
  27946. }
  27947. }
  27948. catch (Exception ex)
  27949. {
  27950. return Ok(JsonView(false, ex.Message));
  27951. }
  27952. }
  27953. /// <summary>
  27954. /// 保险删除指定文件
  27955. /// </summary>
  27956. /// <param name="dto"></param>
  27957. /// <returns></returns>
  27958. [HttpPost]
  27959. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27960. public async Task<IActionResult> DelFileCus(DelFileDto dto)
  27961. {
  27962. try
  27963. {
  27964. string filePath = "";
  27965. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  27966. // 返回与指定虚拟路径相对应的物理路径即绝对路径
  27967. //int id = 0;
  27968. filePath = fileDir + "/保险费用文件上传/" + dto.fileName;
  27969. // 删除该文件
  27970. try
  27971. {
  27972. System.IO.File.Delete(filePath);
  27973. var result = await _sqlSugar.Updateable<Grp_Customers>().Where(a => a.Id == dto.Id && a.IsDel == 0 && a.Attachment == dto.fileName).SetColumns(a => new Grp_Customers()
  27974. {
  27975. Attachment = "",
  27976. }).ExecuteCommandAsync();
  27977. if (result != 0)
  27978. {
  27979. return Ok(JsonView(true, "成功!"));
  27980. }
  27981. else
  27982. {
  27983. return Ok(JsonView(false, "失败!"));
  27984. }
  27985. }
  27986. catch (Exception)
  27987. {
  27988. var result = await _sqlSugar.Updateable<Grp_Customers>().Where(a => a.Id == dto.Id && a.IsDel == 0 && a.Attachment == dto.fileName).SetColumns(a => new Grp_Customers()
  27989. {
  27990. Attachment = "",
  27991. }).ExecuteCommandAsync();
  27992. if (result != 0)
  27993. {
  27994. return Ok(JsonView(true, "成功!"));
  27995. }
  27996. else
  27997. {
  27998. return Ok(JsonView(false, "失败!"));
  27999. }
  28000. }
  28001. }
  28002. catch (Exception ex)
  28003. {
  28004. return Ok(JsonView(false, "程序错误!"));
  28005. throw;
  28006. }
  28007. }
  28008. /// <summary>
  28009. /// 保险费用操作(删除)
  28010. /// </summary>
  28011. /// <param name="dto"></param>
  28012. /// <returns></returns>
  28013. [HttpPost]
  28014. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28015. public async Task<IActionResult> DelCustomers(DelBaseDto dto)
  28016. {
  28017. try
  28018. {
  28019. //验证
  28020. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 82);
  28021. if (!valid) return Ok(JsonView(false, msg));
  28022. var res = await _customersRep.SoftDeleteByIdAsync<Grp_Customers>(dto.Id.ToString(), dto.DeleteUserId);
  28023. if (!res)
  28024. {
  28025. return Ok(JsonView(false, "删除失败"));
  28026. }
  28027. var resultC = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 82).SetColumns(a => new Grp_CreditCardPayment()
  28028. {
  28029. IsDel = 1,
  28030. DeleteUserId = dto.DeleteUserId,
  28031. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  28032. }).ExecuteCommandAsync();
  28033. return Ok(JsonView(true, "删除成功!"));
  28034. }
  28035. catch (Exception ex)
  28036. {
  28037. return Ok(JsonView(false, "程序错误!"));
  28038. }
  28039. }
  28040. #endregion
  28041. #region 接团客户名单 PageId 104
  28042. /// <summary>
  28043. /// 接团客户名单
  28044. /// 迁移数据(慎用!)
  28045. /// </summary>
  28046. /// <returns></returns>
  28047. [HttpPost]
  28048. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28049. public async Task<IActionResult> PostTourClientListChange()
  28050. {
  28051. try
  28052. {
  28053. _sqlSugar.ChangeDatabase(DBEnum.OA2014DB);
  28054. //var groupClinetData1
  28055. string sql = string.Format($"Select * From DeleClient Where Isdel = 0");
  28056. var oldOAClientList = await _sqlSugar.SqlQueryable<OA2021_DeleClient>(sql).Where(it => it.Isdel == 0).ToListAsync();
  28057. int updateCount = 0;
  28058. if (oldOAClientList.Count > 0)
  28059. {
  28060. _sqlSugar.ChangeDatabase(DBEnum.OA2023DB);
  28061. _sqlSugar.BeginTran();
  28062. var clientComInfos = _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToList();
  28063. var clientInfos = _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToList();
  28064. foreach (var item in oldOAClientList)
  28065. {
  28066. int comId = 0;
  28067. string format = "yyyy-MM-dd HH:mm:ss";
  28068. string data11 = "1990-01-01 00:00";
  28069. var data1 = IsValidDate(item.OPdate, format);
  28070. if (data1) data11 = item.OPdate;
  28071. //客户公司验证
  28072. if (!string.IsNullOrEmpty(item.Company))
  28073. {
  28074. var clientComInfo = clientComInfos.Where(it => it.CompanyFullName.Equals(item.Company)).FirstOrDefault();
  28075. if (clientComInfo == null) // add
  28076. {
  28077. var addInfo = new Crm_CustomerCompany()
  28078. {
  28079. CompanyAbbreviation = "",
  28080. CompanyFullName = item.Company,
  28081. Address = "",
  28082. PostCodes = "",
  28083. LastedOpUserId = item.OPer,
  28084. LastedOpDt = Convert.ToDateTime(data11),
  28085. CreateUserId = item.OPer,
  28086. CreateTime = Convert.ToDateTime(data11),
  28087. IsDel = 0
  28088. };
  28089. var comId1 = _sqlSugar.Insertable<Crm_CustomerCompany>(addInfo).ExecuteReturnIdentity();
  28090. if (comId1 > 0) comId = comId1;
  28091. }
  28092. else comId = clientComInfo.Id;
  28093. }
  28094. //客户人员验证
  28095. int clientId = 0;
  28096. string name = item.LastName + item.Name;
  28097. if (!string.IsNullOrEmpty(name))
  28098. {
  28099. var clientInfo = clientInfos.Where(it => (it.LastName + it.FirstName).Equals(name)).FirstOrDefault();
  28100. if (clientInfo == null)
  28101. {
  28102. DateTime? dateTime = null;
  28103. var isDt = DateTime.TryParse(item.Birthday, out DateTime birthDayDt);
  28104. if (isDt) dateTime = birthDayDt;
  28105. var addInfo1 = new Crm_DeleClient()
  28106. {
  28107. CrmCompanyId = comId,
  28108. DiId = -1,
  28109. LastName = item.LastName,
  28110. FirstName = item.Name,
  28111. OldName = "",
  28112. Pinyin = item.Pinyin,
  28113. Sex = item.Sex == "男" ? 0 : item.Sex == "女" ? 1 : -1,
  28114. Marriage = 0,
  28115. Phone = item.Phone,
  28116. Job = item.Job,
  28117. BirthDay = dateTime
  28118. };
  28119. var clientId1 = _sqlSugar.Insertable<Crm_DeleClient>(addInfo1).ExecuteReturnIdentity();
  28120. if (clientId1 > 0) clientId = clientId1;
  28121. }
  28122. else clientId = clientInfo.Id;
  28123. }
  28124. if (clientId < 1)
  28125. {
  28126. continue;
  28127. }
  28128. int airType = 0;
  28129. if (item.AirType == "超经舱") airType = 459;
  28130. else if (item.AirType == "公务舱") airType = 458;
  28131. else if (item.AirType == "经济舱") airType = 460;
  28132. else if (item.AirType == "其他") airType = 565;
  28133. else if (item.AirType == "头等舱") airType = 457;
  28134. var _TourClientListEntity = new Grp_TourClientList()
  28135. {
  28136. DiId = item.Diid,
  28137. ClientId = clientId,
  28138. CreateUserId = item.OPer,
  28139. CreateTime = Convert.ToDateTime(data11),
  28140. Remark = item.Remark,
  28141. IsDel = item.Isdel,
  28142. ShippingSpaceTypeId = airType,
  28143. ShippingSpaceSpecialNeeds = item.AirRemark,
  28144. HotelSpecialNeeds = item.RoomType
  28145. };
  28146. var _TourClientList = _sqlSugar.Insertable<Grp_TourClientList>(_TourClientListEntity).ExecuteCommand();
  28147. if (_TourClientList > 0)
  28148. {
  28149. updateCount++;
  28150. }
  28151. }
  28152. _sqlSugar.CommitTran();
  28153. }
  28154. return Ok(JsonView(true, $"更新条数:{updateCount}条"));
  28155. }
  28156. catch (Exception ex)
  28157. {
  28158. _sqlSugar.RollbackTran();
  28159. return Ok(JsonView(false, ex.Message));
  28160. }
  28161. //return Ok(JsonView(true));
  28162. }
  28163. private bool IsValidDate(string dateString, string format)
  28164. {
  28165. return DateTime.TryParseExact(dateString, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateValue);
  28166. }
  28167. /// <summary>
  28168. /// 接团客户名单
  28169. /// 根据团组Id查询List
  28170. /// </summary>
  28171. /// <param name="_dto"></param>
  28172. /// <returns></returns>
  28173. [HttpPost]
  28174. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28175. public async Task<IActionResult> PostTourClientListByDiId(TourClientListByDiIdDto _dto)
  28176. {
  28177. #region 参数验证
  28178. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId"));
  28179. if (_dto.PageId != 104) _dto.PageId = 104; //接团客户名单PageId
  28180. if (_dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId!"));
  28181. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  28182. #region 页面操作权限验证
  28183. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  28184. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  28185. #endregion
  28186. #endregion
  28187. var viewData = await _tourClientListRep._ItemByDiId(_dto.PortType, _dto.DiId);
  28188. if (viewData.Code != 0)
  28189. {
  28190. return Ok(JsonView(false, viewData.Msg));
  28191. }
  28192. return Ok(JsonView(viewData.Data));
  28193. }
  28194. /// <summary>
  28195. /// 接团客户名单
  28196. /// 基础数据 Init
  28197. /// </summary>
  28198. /// <param name="_dto"></param>
  28199. /// <returns></returns>
  28200. [HttpPost]
  28201. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28202. public async Task<IActionResult> PostTourClientListBasicDataInit(TourClientListBasicDataInitDto _dto)
  28203. {
  28204. #region 参数验证
  28205. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  28206. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  28207. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  28208. #region 页面操作权限验证
  28209. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  28210. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  28211. #endregion
  28212. #endregion
  28213. return Ok(await _tourClientListRep._BasicDataInit(_dto.PortType));
  28214. }
  28215. /// <summary>
  28216. /// 接团客户名单
  28217. /// 根据 Id查询 Details
  28218. /// </summary>
  28219. /// <param name="_dto"></param>
  28220. /// <returns></returns>
  28221. [HttpPost]
  28222. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28223. public async Task<IActionResult> PostTourClientListDetails(TourClientListDetailsDto _dto)
  28224. {
  28225. #region 参数验证
  28226. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  28227. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  28228. if (_dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数!"));
  28229. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  28230. #region 页面操作权限验证
  28231. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  28232. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  28233. #endregion
  28234. #endregion
  28235. var viewData = await _tourClientListRep._Details(_dto.PortType, _dto.Id);
  28236. if (viewData.Code != 0)
  28237. {
  28238. return Ok(JsonView(false, viewData.Msg));
  28239. }
  28240. return Ok(JsonView(viewData.Data));
  28241. }
  28242. /// <summary>
  28243. /// 接团客户名单
  28244. /// Add Or Edit
  28245. /// </summary>
  28246. /// <param name="_dto"></param>
  28247. /// <returns></returns>
  28248. [HttpPost]
  28249. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28250. public async Task<IActionResult> PostTourClientListAddOrEdit(TourClientListAddOrEditDto _dto)
  28251. {
  28252. #region 参数验证
  28253. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  28254. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  28255. if (_dto.Id < 0) return Ok(JsonView(false, "请传入有效的Id参数!"));
  28256. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  28257. #region 页面操作权限验证
  28258. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  28259. if (_dto.Id == 0) //添加
  28260. {
  28261. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
  28262. }
  28263. else if (_dto.Id >= 0) //修改
  28264. {
  28265. if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
  28266. }
  28267. #endregion
  28268. #endregion
  28269. var viewData = await _tourClientListRep._AddOrEdit(_dto);
  28270. if (viewData.Code != 0)
  28271. {
  28272. return Ok(JsonView(false, viewData.Msg));
  28273. }
  28274. return Ok(JsonView(true));
  28275. }
  28276. /// <summary>
  28277. /// 接团客户名单
  28278. /// json字符串 AddMultiple(添加多个)
  28279. /// </summary>
  28280. /// <param name="_dto"></param>
  28281. /// <returns></returns>
  28282. [HttpPost]
  28283. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28284. public async Task<IActionResult> PostTourClientListJsonFormatAddMultiple(PostTourClientListJsonFormatAddMultipleDto _dto)
  28285. {
  28286. #region 参数验证
  28287. string jsonLabel = _dto.JsonLabel;
  28288. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  28289. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  28290. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  28291. #region 页面操作权限验证
  28292. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  28293. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
  28294. #endregion
  28295. #endregion
  28296. var request = new TourClientListAddMultipleDto();
  28297. request.DiId = _dto.DiId;
  28298. request.UserId = _dto.UserId;
  28299. if (!CommonFun.IsValidJson(jsonLabel)) return Ok(JsonView(false, "JsonLabel参数不是合法的json格式!"));
  28300. if (string.IsNullOrEmpty(jsonLabel)) return Ok(JsonView(false, "JsonLabel参数值不能为空"));
  28301. List<TourClientListInfoCN> datas = JsonConvert.DeserializeObject<List<TourClientListInfoCN>>(jsonLabel);
  28302. if (!datas.Any()) return Ok(JsonView(false, "JsonLabel参数值不能为空!"));
  28303. var infos = new List<TourClientListInfo>();
  28304. foreach (var data in datas)
  28305. {
  28306. (string lastName, string firstName) = CommonFun.GetLastNameAndFirstName(data.Name);
  28307. string lastNameEn = CommonFun.ConvertToPinyin(lastName),
  28308. firstNameEn = CommonFun.ConvertToPinyin(lastName);
  28309. if (string.IsNullOrEmpty(lastNameEn) || string.IsNullOrEmpty(firstNameEn))
  28310. {
  28311. continue;
  28312. }
  28313. infos.Add(new TourClientListInfo()
  28314. {
  28315. IsAccompany = 1,
  28316. LastName = lastName,
  28317. FirstName = firstName,
  28318. Pinyin = lastNameEn + @"/" + firstNameEn,
  28319. Sex = data.Sex.Equals("男") ? 0 : data.Sex.Equals("女") ? 1 : 2,
  28320. CompanyFullName = data.CompanyFullName,
  28321. Job = data.Job
  28322. });
  28323. }
  28324. if (infos.Any())
  28325. {
  28326. var viewData = await _tourClientListRep._AddMultiple(request);
  28327. if (viewData.Code != 0)
  28328. {
  28329. return Ok(JsonView(false, viewData.Msg));
  28330. }
  28331. return Ok(JsonView(true));
  28332. }
  28333. return Ok(JsonView(false));
  28334. }
  28335. /// <summary>
  28336. /// 接团客户名单
  28337. /// AddMultiple(添加多个)
  28338. /// </summary>
  28339. /// <param name="_dto"></param>
  28340. /// <returns></returns>
  28341. [HttpPost]
  28342. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28343. public async Task<IActionResult> PostTourClientListAddMultiple(TourClientListAddMultipleDto _dto)
  28344. {
  28345. #region 参数验证
  28346. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  28347. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  28348. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  28349. #region 页面操作权限验证
  28350. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  28351. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
  28352. #endregion
  28353. #endregion
  28354. var viewData = await _tourClientListRep._AddMultiple(_dto);
  28355. if (viewData.Code != 0)
  28356. {
  28357. return Ok(JsonView(false, viewData.Msg));
  28358. }
  28359. return Ok(JsonView(true));
  28360. }
  28361. /// <summary>
  28362. /// 接团客户名单
  28363. /// Del
  28364. /// </summary>
  28365. /// <param name="_dto"></param>
  28366. /// <returns></returns>
  28367. [HttpPost]
  28368. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28369. public async Task<IActionResult> PostTourClientListDel(TourClientListDelDto _dto)
  28370. {
  28371. #region 参数验证
  28372. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  28373. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  28374. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  28375. #region 页面操作权限验证
  28376. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  28377. if (pageFunAuthView.DeleteAuth == 0) return Ok(JsonView(false, "您没有删除权限!"));
  28378. #endregion
  28379. #endregion
  28380. var viewData = await _tourClientListRep._Del(_dto.Id, _dto.UserId);
  28381. if (viewData.Code != 0)
  28382. {
  28383. return Ok(JsonView(false, viewData.Msg));
  28384. }
  28385. return Ok(JsonView(true));
  28386. }
  28387. /// <summary>
  28388. /// 接团客户名单
  28389. /// 文件下载 客户名单
  28390. /// </summary>
  28391. /// <param name="_dto"></param>
  28392. /// <returns></returns>
  28393. [HttpPost]
  28394. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28395. public async Task<IActionResult> PostTourClientListDownloadFile(PostTourClientListDownloadFile _dto)
  28396. {
  28397. #region 参数验证
  28398. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  28399. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  28400. if (_dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId参数"));
  28401. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  28402. #region 页面操作权限验证
  28403. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  28404. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  28405. #endregion
  28406. #endregion
  28407. string clientSql = string.Format(@"Select tcl.Id,tcl.DiId,temp.*,tcl.ShippingSpaceTypeId,tcl.ShippingSpaceSpecialNeeds,
  28408. tcl.HotelSpecialNeeds,tcl.MealSpecialNeeds,tcl.Remark
  28409. From Grp_TourClientList tcl
  28410. Left Join
  28411. (Select dc.Id As DcId,dc.LastName,dc.FirstName,dc.Pinyin,dc.Sex,ccom.CompanyFullName,dc.Job,
  28412. cc1.CertNo As IDCardNo,dc.Phone,dc.BirthDay,cc2.PassportType,cc2.CertNo As PassportNo,cc2.Country,
  28413. cc2.Area,cc2.IssueDt,cc2.ExpiryDt
  28414. From Crm_DeleClient dc
  28415. Left Join Crm_CustomerCompany ccom On dc.CrmCompanyId = ccom.Id And ccom.IsDel = 0
  28416. Left Join Crm_CustomerCert cc1 On dc.Id = cc1.DcId And cc1.SdId = 773 And cc1.IsDel = 0
  28417. Left Join Crm_CustomerCert cc2 On dc.Id = cc2.DcId And cc2.SdId = 774 And cc2.IsDel = 0
  28418. Where dc.IsDel = 0) temp
  28419. On temp.DcId =tcl.ClientId
  28420. Where tcl.IsDel = 0 And tcl.DiId = {0}", _dto.DiId);
  28421. List<TourClientListDetailsView> DcList = await _sqlSugar.SqlQueryable<TourClientListDetailsView>(clientSql).ToListAsync();
  28422. if (DcList.Count < 0) return Ok(JsonView(false, "该团未录入客户名单!"));
  28423. //载入模板
  28424. string tempPath = AppSettingsHelper.Get("WordBasePath") + "Template/dwon_团组人员列表模板.doc";
  28425. if (_dto.Language == 1)
  28426. {
  28427. tempPath = AppSettingsHelper.Get("WordBasePath") + "Template/EN_Down_团组人员列表模板.doc";
  28428. }
  28429. //载入模板
  28430. var doc = new Document(tempPath);
  28431. DocumentBuilder builder = new DocumentBuilder(doc);
  28432. //获取word里所有表格
  28433. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  28434. //获取所填表格的序数
  28435. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  28436. var rowStart = tableOne.Rows[0]; //获取第1行
  28437. if (_dto.Language == 0)
  28438. {
  28439. //循环赋值
  28440. for (int i = 0; i < DcList.Count; i++)
  28441. {
  28442. EncryptionProcessor.DecryptProperties(DcList[i]);
  28443. builder.MoveToCell(0, i + 1, 0, 0);
  28444. builder.Write(DcList[i].LastName + DcList[i].FirstName);
  28445. builder.MoveToCell(0, i + 1, 1, 0);
  28446. int sex = DcList[i].Sex;
  28447. string sexStr = string.Empty;
  28448. if (sex == 0) sexStr = "男";
  28449. else if (sex == 1) sexStr = "女";
  28450. else sexStr = "未设置";
  28451. builder.Write(sexStr);
  28452. builder.MoveToCell(0, i + 1, 2, 0);
  28453. string birthDay = DcList[i].BirthDay;
  28454. string birthDayStr = string.Empty;
  28455. if (!string.IsNullOrEmpty(birthDay))
  28456. {
  28457. birthDayStr = Convert.ToDateTime(birthDay).ToString("yyyy-MM-dd");
  28458. }
  28459. builder.Write(birthDayStr);
  28460. builder.MoveToCell(0, i + 1, 3, 0);
  28461. string company = "";
  28462. if (!string.IsNullOrEmpty(DcList[i].CompanyFullName))
  28463. {
  28464. company = DcList[i].CompanyFullName.ToString();
  28465. }
  28466. builder.Write(company);
  28467. builder.MoveToCell(0, i + 1, 4, 0);
  28468. builder.Write(DcList[i].Job);
  28469. }
  28470. }
  28471. else if (_dto.Language == 1)
  28472. {
  28473. List<Res_PositionEnglishComparison> listPEC = _setDataRep.Query<Res_PositionEnglishComparison>(s => s.IsDel == 0).ToList();
  28474. List<Res_CompanyEnglishComparison> listCEC = _setDataRep.Query<Res_CompanyEnglishComparison>(s => s.IsDel == 0).ToList();
  28475. List<string> transArrayStr = new List<string>();
  28476. string transStrRes1 = "";
  28477. var clientEnglishs = new List<ClientEnglishView>();
  28478. for (int i = 0; i < DcList.Count; i++)
  28479. {
  28480. var dc = DcList[i];
  28481. EncryptionProcessor.DecryptProperties(dc);
  28482. if (dc.CompanyFullName.Equals("暂无")) dc.CompanyFullName = "-";
  28483. if (dc.Job.Equals("暂无")) dc.Job = "-";
  28484. string str1 = $"{i}&{dc.CompanyFullName}&{dc.Job}";
  28485. if (DcList.Count - 1 == i) transStrRes1 += str1;
  28486. else transStrRes1 += $"{str1}|";
  28487. clientEnglishs.Add(new()
  28488. {
  28489. Id = dc.Id,
  28490. LastName = dc.LastName,
  28491. FirstName = dc.FirstName,
  28492. Pinyin = dc.Pinyin,
  28493. Sex = dc.Sex,
  28494. CompanyFullName = dc.CompanyFullName,
  28495. Job = dc.Job,
  28496. IDCardNo = dc.IDCardNo,
  28497. BirthDay = dc.BirthDay,
  28498. });
  28499. }
  28500. #region AI转英文
  28501. string jsonValue = JsonConvert.SerializeObject(clientEnglishs);
  28502. string text = @"将此JSON的中文部分全部翻译为英文,然后只给出修改后的JSON数据,不要其他任何文字";
  28503. List<SeedMessages> messages = new List<SeedMessages>()
  28504. {
  28505. new SeedMessages
  28506. {
  28507. Role = KimiRole.user,
  28508. Content = jsonValue + text
  28509. }
  28510. };
  28511. KiMiApiClient client = new KiMiApiClient();
  28512. var kimiApiResult = await client.SeedMessage(messages);
  28513. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  28514. string clients = kimiApiResult_JObject["content"].ToString();
  28515. string startStr = "```json", endStr = "```";
  28516. // 判断并清除开头部分
  28517. if (clients.StartsWith(startStr))
  28518. {
  28519. clients = clients.Remove(0, startStr.Length);
  28520. }
  28521. // 判断并清除结尾部分
  28522. if (clients.EndsWith(endStr))
  28523. {
  28524. clients = clients.Remove(clients.Length - endStr.Length);
  28525. }
  28526. var en_Json = JsonConvert.DeserializeObject<List<ClientEnglishView>>(clients);
  28527. //循环赋值
  28528. for (int i = 0; i < en_Json.Count; i++)
  28529. {
  28530. var dc = en_Json[i];
  28531. var dc1 = DcList.Find(x => x.Id == dc.Id);
  28532. string PYName = dc.FirstName + " " + dc.LastName;
  28533. builder.MoveToCell(0, i + 1, 0, 0);
  28534. builder.Write(PYName);
  28535. string sex = dc.Sex == 0 ? "Male" : dc.Sex == 1 ? "Female" : "";
  28536. builder.MoveToCell(0, i + 1, 1, 0);
  28537. builder.Write(sex);
  28538. DateTime birthDt;
  28539. bool b_birth = DateTime.TryParse(dc.BirthDay, out birthDt);
  28540. string birthday = b_birth ? birthDt.ToString("yyyy-MM-dd") : " ";
  28541. builder.MoveToCell(0, i + 1, 2, 0);
  28542. builder.Write(birthday);
  28543. string company = string.Empty, job = string.Empty;
  28544. company = dc.CompanyFullName;
  28545. job = dc.Job;
  28546. if (dc1 != null && !string.IsNullOrEmpty(dc1.CompanyFullName))
  28547. {
  28548. //查询对照表
  28549. Res_CompanyEnglishComparison tempCec = listCEC.FirstOrDefault(s => s.zhName.Contains(dc1.CompanyFullName.ToString().Trim()));
  28550. if (tempCec != null)
  28551. {
  28552. company = tempCec.enName;
  28553. }
  28554. }
  28555. builder.MoveToCell(0, i + 1, 3, 0);
  28556. builder.Write(company);
  28557. if (dc1 != null && !string.IsNullOrEmpty(dc1.Job))
  28558. {
  28559. //查询对照表
  28560. Res_PositionEnglishComparison tempPec = listPEC.FirstOrDefault(s => s.zhName == dc1.Job.ToString().Trim());
  28561. if (tempPec != null)
  28562. {
  28563. job = tempPec.enName;
  28564. }
  28565. }
  28566. builder.MoveToCell(0, i + 1, 4, 0);
  28567. builder.Write(job);
  28568. }
  28569. #endregion
  28570. #region 旧翻译英文处理
  28571. ////string transStrRes = "0 & Provincial Health & Health Commission Deputy Director | 1 & Provincial People's Hospital & Provincial People's Hospital Chief Accountant | 2 & Secretary of the Party Committee of the Affiliated Hospital of North Sichuan Medical College & North Sichuan Medical College | 3 & Provincial Health Commission Planning & Provincial Health Commission Planning and Information Division Director | 4 &-& Deputy Director | 5 & Provincial Health Commission population and Family Division & Provincial Health Commission population and Family Division Director";
  28572. //string transStrRes = "";
  28573. //if (transStrRes1.Length > 0)
  28574. //{
  28575. // transStrRes = await _juHeApi.GetTextTranslateAsync(transStrRes1);
  28576. //}
  28577. ////0、 Deputy Director of the Provincial Health and Health Commission | 1、 Chief Accountant of the provincial People's Hospital | 2、 Secretary of the Party Committee of the Affiliated Hospital of North Sichuan Medical College | 3、 Director of the Planning and Information Department of the Provincial Health and Health Commission | 4、 Deputy Director | 5、 Director of the population and Family Department of the Provincial Health and Health Commission | 3、 Secretary of the Party Committee of the Affiliated Hospital of North Sichuan Medical College | 4、 Deputy Director of the Planning and Information Department of the Provincial Health and Health Commission | 4、 Deputy Director of the population and Family Department of the Provincial Health and Health Commission | 5、 Director of the population and Family Department of the Provincial Health and Health Commission
  28578. ////await _juHeApi.GetTextTranslateAsync(DcList[i].CompanyFullName.ToString().Trim()) ?? "";
  28579. ////List<string> transArray = new List<string> { };
  28580. //List<TranslateInfo> transArray = new List<TranslateInfo>();
  28581. //if (transStrRes.Contains("|"))
  28582. //{
  28583. // string[] transArray1 = transStrRes.Split('|');
  28584. // if (transArray1.Length > 0)
  28585. // {
  28586. // foreach (var item in transArray1)
  28587. // {
  28588. // if (item.Contains("&"))
  28589. // {
  28590. // string[] transArray2 = item.Split('&');
  28591. // int index = 0;
  28592. // string companyName = "", job = "";
  28593. // if (transArray2.Length > 0)
  28594. // {
  28595. // bool success = int.TryParse(transArray2[0].Trim(), out index);
  28596. // if (1 < transArray2.Length) companyName = transArray2[1];
  28597. // if (2 < transArray2.Length) job = transArray2[2];
  28598. // }
  28599. // transArray.Add(new TranslateInfo { Index = index, CompanyName = companyName, Job = job });
  28600. // }
  28601. // }
  28602. // }
  28603. //}
  28604. ////循环赋值
  28605. //for (int i = 0; i < DcList.Count; i++)
  28606. //{
  28607. // string PYName = "";
  28608. // if (DcList[i].Pinyin.Length > 0 && DcList[i].Pinyin.IndexOf('/') > -1)
  28609. // {
  28610. // string PY_Last = DcList[i].Pinyin.Split('/')[0];
  28611. // string PY_First = DcList[i].Pinyin.Split('/')[1];
  28612. // PYName = PY_First + " " + PY_Last;
  28613. // }
  28614. // else
  28615. // {
  28616. // string PY_Last = DcList[i].LastName.GetTotalPingYin().Count > 0 ? DcList[i].LastName.GetTotalPingYin()[0].ToUpper() : "";
  28617. // string PY_First = DcList[i].FirstName.GetTotalPingYin().Count > 0 ? DcList[i].FirstName.GetTotalPingYin()[0].ToUpper() : "";
  28618. // PYName = PY_First + " " + PY_Last;
  28619. // }
  28620. // builder.MoveToCell(0, i + 1, 0, 0);
  28621. // builder.Write(PYName);
  28622. // string sex = DcList[i].Sex == 0 ? "Male" : DcList[i].Sex == 1 ? "Female" : "";
  28623. // builder.MoveToCell(0, i + 1, 1, 0);
  28624. // builder.Write(sex);
  28625. // DateTime birthDt;
  28626. // bool b_birth = DateTime.TryParse(DcList[i].BirthDay, out birthDt);
  28627. // string birthday = b_birth ? birthDt.ToString("yyyy-MM-dd") : " ";
  28628. // builder.MoveToCell(0, i + 1, 2, 0);
  28629. // builder.Write(birthday);
  28630. // string company = string.Empty, job = string.Empty;
  28631. // var dcTransInfo = transArray.FirstOrDefault(s => s.Index == i);
  28632. // if (dcTransInfo != null)
  28633. // {
  28634. // company = dcTransInfo.CompanyName;
  28635. // job = dcTransInfo.Job;
  28636. // }
  28637. // if (!string.IsNullOrEmpty(DcList[i].CompanyFullName))
  28638. // {
  28639. // //查询对照表
  28640. // Res_CompanyEnglishComparison tempCec = listCEC.FirstOrDefault(s => s.zhName.Contains(DcList[i].CompanyFullName.ToString().Trim()));
  28641. // if (tempCec != null)
  28642. // {
  28643. // company = tempCec.enName;
  28644. // }
  28645. // //翻译
  28646. // else
  28647. // {
  28648. // }
  28649. // }
  28650. // builder.MoveToCell(0, i + 1, 3, 0);
  28651. // builder.Write(company);
  28652. // if (!string.IsNullOrEmpty(DcList[i].Job.ToString()))
  28653. // {
  28654. // //查询对照表
  28655. // Res_PositionEnglishComparison tempPec = listPEC.FirstOrDefault(s => s.zhName == DcList[i].Job.ToString().Trim());
  28656. // if (tempPec != null)
  28657. // {
  28658. // job = tempPec.enName;
  28659. // }
  28660. // //翻译
  28661. // else
  28662. // {
  28663. // }
  28664. // }
  28665. // builder.MoveToCell(0, i + 1, 4, 0);
  28666. // builder.Write(job);
  28667. //}
  28668. #endregion
  28669. }
  28670. //删除多余行
  28671. while (tableOne.Rows.Count > DcList.Count + 1)
  28672. {
  28673. tableOne.Rows.RemoveAt(DcList.Count + 1);
  28674. }
  28675. string fileName = "组团人员名单(" + DateTime.Now.ToString("yyyyhhddHHmmss") + ").doc";
  28676. var fileDir = AppSettingsHelper.Get("WordBasePath") + "TourClientList/" + fileName;
  28677. doc.Save(fileDir);
  28678. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/TourClientList/" + fileName;
  28679. return Ok(JsonView(true, "操作成功!", Url));
  28680. }
  28681. private class TranslateInfo
  28682. {
  28683. public int Index { get; set; }
  28684. public string CompanyName { get; set; }
  28685. public string Job { get; set; }
  28686. }
  28687. [HttpPost]
  28688. public async Task<IActionResult> FileReadClient(List<IFormFile> files)
  28689. {
  28690. if (files.Count == 0)
  28691. {
  28692. return Ok(JsonView(false, "文件为空"));
  28693. }
  28694. KiMiApiClient KiMiApi = new KiMiApiClient();
  28695. var seedConter = await KiMiApi.UploadFilesAsync(files);
  28696. if (seedConter.Count == 0)
  28697. {
  28698. return Ok(JsonView(false, "上传结果为空!"));
  28699. }
  28700. var messages = new List<SeedMessages>
  28701. {
  28702. new SeedMessages { Role = KimiRole.system, Content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一切涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。" },
  28703. new SeedMessages { Role = KimiRole.user, Content = "根据文件内容 ,按照“姓、名、姓名拼音、性别、单位、职务、出生日期”的json格式来排列整理(性别和出生日期通过身份证来识别 , 当识别到性别为男时值给0女给1 未识别到性别的情况下值给-1,出生日期按照yyyy-MM-dd来整理(若出生日期没有值则为‘-’),文件存在拼音的情况读取对应的拼音不存在则设置拼音为中文名字全拼),只输出JSON数组数据 从'['开始 到']'结尾 ,不要除JSON数据外的任何文字以及符号" }
  28704. };
  28705. messages.InsertRange(1, seedConter);
  28706. var kimiApiResult = await KiMiApi.SeedMessage(messages);
  28707. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  28708. string clients = kimiApiResult_JObject["content"].ToString();
  28709. string startStr = "```json", endStr = "```";
  28710. // 判断并清除开头部分
  28711. if (clients.StartsWith(startStr))
  28712. {
  28713. clients = clients.Remove(0, startStr.Length);
  28714. }
  28715. // 判断并清除结尾部分
  28716. if (clients.EndsWith(endStr))
  28717. {
  28718. clients = clients.Remove(clients.Length - endStr.Length);
  28719. }
  28720. var clients_JObject = JsonConvert.DeserializeObject<List<JObject>>(clients);
  28721. Dictionary<string, string> clientFieldMap = new Dictionary<string, string>()
  28722. {
  28723. {"姓", "LastName" },
  28724. {"名", "FirstName" },
  28725. {"姓名拼音", "Pinyin" },
  28726. {"性别", "Sex" },
  28727. {"单位", "CompanyFullName" },
  28728. {"职务", "Job" },
  28729. {"出生日期", "Birthday" },
  28730. };
  28731. List<BaiduClientOCRView> crmClients = new List<BaiduClientOCRView>();
  28732. foreach (var item in clients_JObject)
  28733. {
  28734. BaiduClientOCRView cdc = new BaiduClientOCRView();
  28735. foreach (var field in clientFieldMap.Keys)
  28736. {
  28737. if (item.TryGetValue(field, out JToken value))
  28738. {
  28739. var getValue = value.ToString();
  28740. System.Type type = cdc.GetType();
  28741. PropertyInfo propertyInfo = type.GetProperty(clientFieldMap[field]);
  28742. var propertyValue = Convert.ChangeType(getValue, propertyInfo.PropertyType);
  28743. propertyInfo.SetValue(cdc, propertyValue);
  28744. }
  28745. }
  28746. crmClients.Add(cdc);
  28747. }
  28748. return Ok(JsonView(new
  28749. {
  28750. fileCount = files.Count,
  28751. UploadCount = seedConter.Count,
  28752. ApiResult = clients,
  28753. CrmClients = crmClients
  28754. }));
  28755. }
  28756. #endregion
  28757. #region 团组倒推表
  28758. /// <summary>
  28759. /// 倒推表基础数据
  28760. /// Init
  28761. /// </summary>
  28762. /// <returns></returns>
  28763. [HttpPost]
  28764. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28765. public async Task<IActionResult> PostInvertedListInit()
  28766. {
  28767. var viewData = await _invertedListRep.Init();
  28768. if (viewData.Code != 0)
  28769. {
  28770. return Ok(JsonView(false, viewData.Msg));
  28771. }
  28772. return Ok(JsonView(viewData.Data));
  28773. }
  28774. /// <summary>
  28775. /// 倒推表
  28776. /// Info
  28777. /// </summary>
  28778. /// <param name="dto"></param>
  28779. /// <returns></returns>
  28780. [HttpPost]
  28781. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28782. public async Task<IActionResult> PostInvertedListInfo(InvertedListCreateDto dto)
  28783. {
  28784. var viewData = await _invertedListRep.Info(dto.PortType, dto.DiId);
  28785. if (viewData.Code != 0)
  28786. {
  28787. return Ok(JsonView(false, viewData.Msg));
  28788. }
  28789. return Ok(JsonView(viewData.Data));
  28790. }
  28791. /// <summary>
  28792. /// 倒推表
  28793. /// Create
  28794. /// </summary>
  28795. /// <param name="dto"></param>
  28796. /// <returns></returns>
  28797. [HttpPost]
  28798. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28799. public async Task<IActionResult> PostInvertedListCreate(InvertedListCreateDto dto)
  28800. {
  28801. var viewData = await _invertedListRep.Create(dto.PortType, dto.DiId);
  28802. if (viewData.Code != 0)
  28803. {
  28804. return Ok(JsonView(false, viewData.Msg));
  28805. }
  28806. return Ok(JsonView(viewData.Data));
  28807. }
  28808. /// <summary>
  28809. /// 倒推表
  28810. /// Update
  28811. /// </summary>
  28812. /// <param name="dto"></param>
  28813. /// <returns></returns>
  28814. [HttpPost]
  28815. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28816. public async Task<IActionResult> PostInvertedListUpdate(InvertedListUpdateDto dto)
  28817. {
  28818. var viewData = await _invertedListRep.Update(dto);
  28819. if (viewData.Code != 0)
  28820. {
  28821. return Ok(JsonView(false, viewData.Msg));
  28822. }
  28823. return Ok(JsonView(viewData.Data));
  28824. }
  28825. /// <summary>
  28826. /// 倒推表
  28827. /// File Download
  28828. /// </summary>
  28829. /// <param name="dto"></param>
  28830. /// <returns></returns>
  28831. [HttpPost]
  28832. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28833. public async Task<IActionResult> PostInvertedListFileDownload(InvertedListFileDownloadDto dto)
  28834. {
  28835. var info2 = await _invertedListRep.Info(1, dto.DiId);
  28836. if (info2.Code != 0)
  28837. {
  28838. return Ok(JsonView(false, "倒推表数据未生成,请先生成倒退表数据!"));
  28839. }
  28840. var info1 = info2.Data as InvertedListInfoView;
  28841. var info = await _invertedListRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == dto.DiId).FirstAsync();
  28842. string teamName = "";
  28843. if (info != null) teamName = info.TeamName;
  28844. var tempPath = $"{AppSettingsHelper.Get("WordBasePath")}Template/倒退表模板20250121.doc";
  28845. var doc = new Document();
  28846. var builder = new DocumentBuilder(doc);
  28847. #region old insert
  28848. ////载入模板
  28849. //var tempPath = $"{AppSettingsHelper.Get("WordBasePath")}Template/倒退表模板20200617.doc";
  28850. //Document doc = new Document(tempPath);
  28851. //DocumentBuilder builder = new DocumentBuilder(doc);
  28852. //利用键值对存放数据
  28853. //Dictionary<string, string> dic = new Dictionary<string, string>();
  28854. //dic.Add("TeamName", teamName);
  28855. //dic.Add("StartTime", info1.AirportdDropOffDt.ConvertToDatetime()); //开始时间
  28856. //dic.Add("BPtime", info1.ApprovalDataDt.ConvertToDatetime());
  28857. //dic.Add("BPRemark", info1.ApprovalDataRemark);
  28858. //dic.Add("SQtime", info1.ApprovalDt.ConvertToDatetime());
  28859. //dic.Add("SQRemark", info1.ApprovalRemark);
  28860. //dic.Add("CPJtime", info1.IssueApprovalDt.ConvertToDatetime());
  28861. //dic.Add("CPJRemark", info1.IssueApprovalRemark);
  28862. ////dic.Add("HZtime", info1.ApplyPassportDt.ConvertToDatetime());
  28863. ////dic.Add("HZRemark", info1.ApplyPassportRemark);
  28864. //dic.Add("QZtime", info1.VisaInformationDt.ConvertToDatetime());
  28865. //dic.Add("QZRemark", info1.VisaInformationRemark);
  28866. //dic.Add("SQQZtime", info1.SendVisaDt.ConvertToDatetime());
  28867. //dic.Add("SQQZRemark", info1.SendVisaRemark);
  28868. //dic.Add("CQtime", info1.IssueVisaDt.ConvertToDatetime());
  28869. //dic.Add("CQRemark", info1.IssueVisaRemark);
  28870. //dic.Add("XQHtime", info1.PreTripMeetingDt.ConvertToDatetime());
  28871. //dic.Add("XQHRemark", info1.PreTripMeetingRemark);
  28872. //dic.Add("SJtime", info1.AirportdDropOffDt.ConvertToDatetime());
  28873. //dic.Add("SJRemark", info1.AirportdDropOffRemark);
  28874. //#region 填充word模板书签内容
  28875. //foreach (var key in dic.Keys)
  28876. //{
  28877. // builder.MoveToBookmark(key);
  28878. // builder.Write(dic[key]);
  28879. //}
  28880. //#endregion
  28881. #endregion
  28882. #region New Insert
  28883. string titleFont = $"仿宋",
  28884. contentFont = $"仿宋";
  28885. var fontColor = Color.FromArgb(64, 64, 64);
  28886. //设置标题 团组名称
  28887. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  28888. builder.Font.Name = titleFont;
  28889. builder.Font.Color = fontColor;
  28890. builder.Font.Size = 12;
  28891. builder.Font.Bold = true;
  28892. builder.Writeln(teamName);
  28893. //设置副标题 团组出访时间
  28894. builder.Font.Size = 12;
  28895. builder.Writeln("出发时间:" + info1.AirportdDropOffDt.ConvertToDatetime());
  28896. builder.Writeln();
  28897. var backgroundColor = Color.FromArgb(199, 199, 199);
  28898. var table = builder.StartTable();
  28899. builder.InsertCell();
  28900. builder.CellFormat.Shading.BackgroundPatternColor = backgroundColor;
  28901. builder.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.Single;
  28902. builder.CellFormat.Borders.LineWidth = 1;
  28903. builder.CellFormat.Borders.Color = Color.FromArgb(183, 183, 183);
  28904. table.FirstRow.FirstCell.CellFormat.Width = 20; // 单位为百分比
  28905. builder.RowFormat.Height = 40;
  28906. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  28907. builder.Font.Name = contentFont;
  28908. builder.Font.Size = 12;
  28909. builder.Font.Bold = true;
  28910. builder.Font.Color = fontColor;
  28911. builder.Write("时间");
  28912. builder.InsertCell();
  28913. table.FirstRow.FirstCell.CellFormat.Width = 30; // 单位为百分比
  28914. builder.Write("流程");
  28915. builder.InsertCell();
  28916. table.FirstRow.FirstCell.CellFormat.Width = 50; // 单位为百分比
  28917. builder.Write("说明");
  28918. builder.EndRow();
  28919. //报批资料准备
  28920. if (info1.IsSelectedAirportd)
  28921. {
  28922. InvertedListFileDownloadSetRow(builder, contentFont, info1.ApprovalDataDt.ConvertToDatetime(), "报批资料准备", info1.ApprovalDataRemark);
  28923. }
  28924. //报批/提供送签资料
  28925. if (info1.IsSelectedApprovalData)
  28926. {
  28927. InvertedListFileDownloadSetRow(builder, contentFont, info1.ApprovalDt.ConvertToDatetime(), "报批/提供送签资料", info1.ApprovalRemark);
  28928. }
  28929. //出批件护照办理
  28930. if (info1.IsSelectedIssueApproval)
  28931. {
  28932. InvertedListFileDownloadSetRow(builder, contentFont, info1.IssueApprovalDt.ConvertToDatetime(), "出批件\r\n护照办理", info1.IssueApprovalRemark);
  28933. }
  28934. //签证资料准备
  28935. if (info1.IsSelectedVisaInfo)
  28936. {
  28937. InvertedListFileDownloadSetRow(builder, contentFont, info1.VisaInformationDt.ConvertToDatetime(), "签证资料准备", info1.VisaInformationRemark);
  28938. }
  28939. //送签
  28940. if (info1.IsSelectedSendVisa)
  28941. {
  28942. InvertedListFileDownloadSetRow(builder, contentFont, info1.SendVisaDt.ConvertToDatetime(), "送签", info1.SendVisaRemark);
  28943. }
  28944. //出签
  28945. if (info1.IsSelectedIssueVisa)
  28946. {
  28947. InvertedListFileDownloadSetRow(builder, contentFont, info1.IssueVisaDt.ConvertToDatetime(), "出签", info1.IssueVisaRemark);
  28948. }
  28949. //机票
  28950. if (info1.IsSelectedAirTicket)
  28951. {
  28952. if (string.IsNullOrEmpty(info1.AirTicketDt)) info1.AirTicketDt = info1.IssueVisaDt;
  28953. InvertedListFileDownloadSetRow(builder, contentFont, info1.AirTicketDt.ConvertToDatetime(), "机票", info1.AirTicketRemark);
  28954. }
  28955. //酒店
  28956. if (info1.IsSelectedHotel)
  28957. {
  28958. if (string.IsNullOrEmpty(info1.HotelDt)) info1.HotelDt = info1.IssueVisaDt;
  28959. InvertedListFileDownloadSetRow(builder, contentFont, info1.HotelDt.ConvertToDatetime(), "酒店", info1.HotelRemark);
  28960. }
  28961. //开行前会
  28962. if (info1.IsSelectedPreTripMeeting)
  28963. {
  28964. InvertedListFileDownloadSetRow(builder, contentFont, info1.PreTripMeetingDt.ConvertToDatetime(), "开行前会", info1.PreTripMeetingRemark);
  28965. }
  28966. //送机
  28967. if (info1.IsSelectedAirportdDropOff)
  28968. {
  28969. InvertedListFileDownloadSetRow(builder, contentFont, info1.AirportdDropOffDt.ConvertToDatetime(), "送机", info1.AirportdDropOffRemark);
  28970. }
  28971. builder.EndTable();
  28972. //table.PreferredWidth = PreferredWidth.FromPercent(100.00);
  28973. //table.AutoFit(AutoFitBehavior.FixedColumnWidths);
  28974. for (int i = 0; i < table.Rows.Count; i++)
  28975. {
  28976. var row = table.Rows[i];
  28977. //设置宽度
  28978. row.Cells[0].CellFormat.Width = 20.00;
  28979. row.Cells[1].CellFormat.Width = 30.00;
  28980. row.Cells[2].CellFormat.Width = 50.00;
  28981. if (i != 0)
  28982. {
  28983. //边框设置
  28984. InvertedListFileDownloadSetBorders(row.Cells, 0);
  28985. InvertedListFileDownloadSetBorders(row.Cells, 1);
  28986. InvertedListFileDownloadSetBorders(row.Cells, 2);
  28987. }
  28988. }
  28989. #region 页脚插入图片
  28990. // 创建页脚
  28991. Aspose.Words.HeaderFooter footer = new Aspose.Words.HeaderFooter(doc, HeaderFooterType.FooterPrimary);
  28992. doc.FirstSection.HeadersFooters.Add(footer);
  28993. Paragraph para = new Paragraph(doc);
  28994. para.ParagraphFormat.Alignment = ParagraphAlignment.Right;
  28995. footer.AppendChild(para);
  28996. builder.MoveTo(para);
  28997. string imagePath = "./Images/FMGJ_Log.png";
  28998. builder.InsertImage(imagePath);
  28999. #endregion
  29000. #endregion
  29001. var fileDir = AppSettingsHelper.Get("WordBasePath");
  29002. string fileName = $"{teamName}团出行准备流程表{CommonFun.GUID}.doc";
  29003. string filePath = fileDir + $@"InvertedList/{fileName}";
  29004. doc.Save(filePath);
  29005. string Url = $@"{AppSettingsHelper.Get("WordBaseUrl")}Office/Word/InvertedList/{fileName}";
  29006. return Ok(JsonView(true, "操作成功!", Url));
  29007. }
  29008. /// <summary>
  29009. /// 倒推表
  29010. /// File Download
  29011. /// 客户版
  29012. /// </summary>
  29013. /// <param name="dto"></param>
  29014. /// <returns></returns>
  29015. [HttpPost]
  29016. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29017. public async Task<IActionResult> PostInvertedListClientFileDownload(InvertedListFileDownloadDto dto)
  29018. {
  29019. var info2 = await _invertedListRep.Info(1, dto.DiId);
  29020. if (info2.Code != 0)
  29021. {
  29022. return Ok(JsonView(false, "倒推表数据未生成,请先生成倒退表数据!"));
  29023. }
  29024. var info1 = info2.Data as InvertedListInfoView;
  29025. var info = await _invertedListRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == dto.DiId).FirstAsync();
  29026. string teamName = "";
  29027. if (info != null) teamName = info.TeamName;
  29028. var tempPath = $"{AppSettingsHelper.Get("WordBasePath")}Template/倒退表模板20250121.doc";
  29029. var doc = new Document();
  29030. var builder = new DocumentBuilder(doc);
  29031. #region New Insert
  29032. string titleFont = $"仿宋",
  29033. contentFont = $"仿宋";
  29034. var fontColor = Color.FromArgb(64, 64, 64);
  29035. //设置标题 团组名称
  29036. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  29037. builder.Font.Name = titleFont;
  29038. builder.Font.Color = fontColor;
  29039. builder.Font.Size = 12;
  29040. builder.Font.Bold = true;
  29041. builder.Writeln(teamName);
  29042. //设置副标题 团组出访时间
  29043. builder.Font.Size = 12;
  29044. builder.Writeln("出发时间:" + info1.AirportdDropOffDt.ConvertToDatetime());
  29045. builder.Writeln();
  29046. var backgroundColor = Color.FromArgb(199, 199, 199);
  29047. var table = builder.StartTable();
  29048. builder.InsertCell();
  29049. builder.CellFormat.Shading.BackgroundPatternColor = backgroundColor;
  29050. builder.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.Single;
  29051. builder.CellFormat.Borders.LineWidth = 1;
  29052. builder.CellFormat.Borders.Color = Color.FromArgb(183, 183, 183);
  29053. table.FirstRow.FirstCell.CellFormat.Width = 20; // 单位为百分比
  29054. builder.RowFormat.Height = 40;
  29055. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  29056. builder.Font.Name = contentFont;
  29057. builder.Font.Size = 12;
  29058. builder.Font.Bold = true;
  29059. builder.Font.Color = fontColor;
  29060. builder.Write("时间");
  29061. builder.InsertCell();
  29062. table.FirstRow.FirstCell.CellFormat.Width = 30; // 单位为百分比
  29063. builder.Write("流程");
  29064. builder.InsertCell();
  29065. table.FirstRow.FirstCell.CellFormat.Width = 50; // 单位为百分比
  29066. builder.Write("说明");
  29067. builder.EndRow();
  29068. //报批资料准备
  29069. if (info1.IsSelectedAirportd)
  29070. {
  29071. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_ApprovalDataDt.ConvertToDatetime(), "报批资料准备", info1.ApprovalDataRemark);
  29072. }
  29073. //报批/提供送签资料
  29074. if (info1.IsSelectedApprovalData)
  29075. {
  29076. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_ApprovalDt.ConvertToDatetime(), "报批/提供送签资料", info1.ApprovalRemark);
  29077. }
  29078. //出批件护照办理
  29079. if (info1.IsSelectedIssueApproval)
  29080. {
  29081. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_IssueApprovalDt.ConvertToDatetime(), "出批件\r\n护照办理", info1.IssueApprovalRemark);
  29082. }
  29083. //签证资料准备
  29084. if (info1.IsSelectedVisaInfo)
  29085. {
  29086. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_VisaInformationDt.ConvertToDatetime(), "签证资料准备", info1.VisaInformationRemark);
  29087. }
  29088. //送签
  29089. if (info1.IsSelectedSendVisa)
  29090. {
  29091. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_SendVisaDt.ConvertToDatetime(), "送签", info1.SendVisaRemark);
  29092. }
  29093. //出签
  29094. if (info1.IsSelectedIssueVisa)
  29095. {
  29096. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_IssueVisaDt.ConvertToDatetime(), "出签", info1.IssueVisaRemark);
  29097. }
  29098. //机票
  29099. if (info1.IsSelectedAirTicket)
  29100. {
  29101. if (string.IsNullOrEmpty(info1.Client_AirTicketDt)) info1.Client_AirTicketDt = info1.Client_IssueVisaDt;
  29102. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_AirTicketDt.ConvertToDatetime(), "机票", info1.AirTicketRemark);
  29103. }
  29104. //酒店
  29105. if (info1.IsSelectedHotel)
  29106. {
  29107. if (string.IsNullOrEmpty(info1.Client_HotelDt)) info1.Client_HotelDt = info1.Client_IssueVisaDt;
  29108. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_HotelDt.ConvertToDatetime(), "酒店", info1.HotelRemark);
  29109. }
  29110. //开行前会
  29111. if (info1.IsSelectedPreTripMeeting)
  29112. {
  29113. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_PreTripMeetingDt.ConvertToDatetime(), "开行前会", info1.PreTripMeetingRemark);
  29114. }
  29115. //送机
  29116. if (info1.IsSelectedAirportdDropOff)
  29117. {
  29118. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_AirportdDropOffDt.ConvertToDatetime(), "送机", info1.AirportdDropOffRemark);
  29119. }
  29120. builder.EndTable();
  29121. //table.PreferredWidth = PreferredWidth.FromPercent(100.00);
  29122. //table.AutoFit(AutoFitBehavior.FixedColumnWidths);
  29123. for (int i = 0; i < table.Rows.Count; i++)
  29124. {
  29125. var row = table.Rows[i];
  29126. //设置宽度
  29127. row.Cells[0].CellFormat.Width = 20.00;
  29128. row.Cells[1].CellFormat.Width = 30.00;
  29129. row.Cells[2].CellFormat.Width = 50.00;
  29130. if (i != 0)
  29131. {
  29132. //边框设置
  29133. InvertedListFileDownloadSetBorders(row.Cells, 0);
  29134. InvertedListFileDownloadSetBorders(row.Cells, 1);
  29135. InvertedListFileDownloadSetBorders(row.Cells, 2);
  29136. }
  29137. }
  29138. #region 页脚插入图片
  29139. // 创建页脚
  29140. Aspose.Words.HeaderFooter footer = new Aspose.Words.HeaderFooter(doc, HeaderFooterType.FooterPrimary);
  29141. doc.FirstSection.HeadersFooters.Add(footer);
  29142. Paragraph para = new Paragraph(doc);
  29143. para.ParagraphFormat.Alignment = ParagraphAlignment.Right;
  29144. footer.AppendChild(para);
  29145. builder.MoveTo(para);
  29146. string imagePath = "./Images/FMGJ_Log.png";
  29147. builder.InsertImage(imagePath);
  29148. #endregion
  29149. #endregion
  29150. var fileDir = AppSettingsHelper.Get("WordBasePath");
  29151. string fileName = $"{teamName}团出行准备流程表(客户版){CommonFun.GUID}.doc";
  29152. string filePath = fileDir + $@"InvertedList/{fileName}";
  29153. doc.Save(filePath);
  29154. string Url = $@"{AppSettingsHelper.Get("WordBaseUrl")}Office/Word/InvertedList/{fileName}";
  29155. return Ok(JsonView(true, "操作成功!", Url));
  29156. }
  29157. private void InvertedListFileDownloadSetRow(DocumentBuilder builder, string fontName, string dateTime, string content, string reamrk)
  29158. {
  29159. var fontColor = Color.FromArgb(64, 64, 64);
  29160. builder.InsertCell();
  29161. builder.CellFormat.Shading.BackgroundPatternColor = Color.Empty;
  29162. builder.RowFormat.Height = 40;
  29163. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  29164. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  29165. builder.Font.Name = fontName;
  29166. builder.Font.Size = 8;
  29167. builder.Font.Bold = true;
  29168. builder.Font.Color = fontColor;
  29169. builder.Write(dateTime);
  29170. builder.InsertCell();
  29171. builder.Font.Size = 9;
  29172. builder.Font.Bold = true;
  29173. builder.Font.Color = fontColor;
  29174. builder.Write(content);
  29175. builder.InsertCell();
  29176. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  29177. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  29178. builder.Font.Size = 9;
  29179. builder.Font.Bold = false;
  29180. builder.Font.Color = fontColor;
  29181. builder.Write(reamrk);
  29182. builder.EndRow();
  29183. }
  29184. private void InvertedListFileDownloadSetBorders(CellCollection cell, int index)
  29185. {
  29186. cell[index].CellFormat.Borders.Top.LineStyle = Aspose.Words.LineStyle.None;
  29187. cell[index].CellFormat.Borders.Bottom.LineStyle = Aspose.Words.LineStyle.None;
  29188. cell[index].CellFormat.Borders.Left.LineStyle = Aspose.Words.LineStyle.None;
  29189. cell[index].CellFormat.Borders.Right.LineStyle = Aspose.Words.LineStyle.None;
  29190. //cell[index].CellFormat.Borders.Horizontal.LineStyle = Aspose.Words.LineStyle.None;
  29191. //cell[index].CellFormat.Borders.Vertical.LineStyle = Aspose.Words.LineStyle.None;
  29192. }
  29193. #endregion
  29194. #region 会务倒推表
  29195. /// <summary>
  29196. /// 会务倒推表
  29197. /// Init
  29198. /// </summary>
  29199. /// <returns></returns>
  29200. [HttpPost]
  29201. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29202. public async Task<IActionResult> InforRetrogressTableInit()
  29203. {
  29204. var groupData = await _groupRepository.PostShareGroupInfos(1);
  29205. if (groupData.Code == 0) return Ok(JsonView(groupData.Data));
  29206. return Ok(JsonView(false, groupData.Msg));
  29207. }
  29208. /// <summary>
  29209. /// 会务倒推表
  29210. /// ExcelDownload
  29211. /// </summary>
  29212. /// <param name="dto"></param>
  29213. /// <returns></returns>
  29214. [HttpPost]
  29215. [ApiLog("InforRetrogressTable", OperationEnum.Download)]
  29216. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29217. public async Task<IActionResult> InforRetrogressTableFileDownload(InforRetrogressTableFileDownloadDto dto)
  29218. {
  29219. var validator = new InforRetrogressTableFileDownloadDtoValidator();
  29220. var validatorRes = await validator.ValidateAsync(dto);
  29221. if (!validatorRes.IsValid)
  29222. {
  29223. StringBuilder sb = new StringBuilder();
  29224. foreach (var item in validatorRes.Errors)
  29225. {
  29226. sb.AppendLine(item.ErrorMessage);
  29227. }
  29228. return Ok(JsonView(false, sb.ToString()));
  29229. }
  29230. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.GroupId);
  29231. if (groupInfo == null) return Ok(JsonView(false, $"该团组信息未填写!"));
  29232. //时间根据团组出访日期-接团录入日期的天数来判断用哪个模板
  29233. var days = groupInfo.VisitDate.Subtract(groupInfo.CreateTime).Days;
  29234. #region Excel
  29235. var tempPath = AppSettingsHelper.Get("ExcelTempPath");
  29236. var servicePath = AppSettingsHelper.Get("GrpFileBaseUrl");
  29237. var savePath = AppSettingsHelper.Get("ExcelBasePath") + "InforRetrogressTable/";
  29238. var ftpPath = AppSettingsHelper.Get("ExcelFtpPath") + "InforRetrogressTable/";
  29239. var fileNamePrefix = string.Empty;
  29240. if (days >= 30)
  29241. {
  29242. tempPath += $"会务工作倒推进度表(30天).xlsx";
  29243. fileNamePrefix = $"{groupInfo.TeamName}_会务工作倒推进度表(30天)";
  29244. }
  29245. else if (days < 30 && days > 7)
  29246. {
  29247. tempPath += $"会务工作倒推进度表(15天).xlsx";
  29248. fileNamePrefix = $"{groupInfo.TeamName}_会务工作倒推进度表(15天)";
  29249. }
  29250. else if (days <= 7)
  29251. {
  29252. tempPath += $"会务工作倒推进度表(7天).xlsx";
  29253. fileNamePrefix = $"{groupInfo.TeamName}_会务工作倒推进度表(7天)";
  29254. }
  29255. var fileName = $"{fileNamePrefix}{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx";
  29256. fileName = CommonFun.ValidFileName(fileName);
  29257. //载入模板
  29258. WorkbookDesigner designer = new WorkbookDesigner();
  29259. designer.Workbook = new Workbook(tempPath);
  29260. designer.Process();
  29261. if (!Directory.Exists(savePath))
  29262. {
  29263. Directory.CreateDirectory(savePath);
  29264. }
  29265. string serverPath = $"{savePath}{fileName}";
  29266. designer.Workbook.Save(serverPath);
  29267. string rst = $"{servicePath}{ftpPath}{fileName}";
  29268. #endregion
  29269. return Ok(JsonView(new { url = rst }));
  29270. }
  29271. #endregion
  29272. #region 三公签证费用(签证费、代办费)
  29273. /// <summary>
  29274. /// 三公签证费用(签证费、代办费)
  29275. /// List
  29276. /// </summary>
  29277. /// <returns></returns>
  29278. [HttpPost]
  29279. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29280. public async Task<IActionResult> PostVisaFeeList(VisaFeeListDto _dto)
  29281. {
  29282. return Ok(await _visaFeeInfoRep.List(_dto.PortType, _dto.DiId));
  29283. }
  29284. /// <summary>
  29285. /// 三公签证费用(签证费、代办费)
  29286. /// Add Or Update
  29287. /// </summary>
  29288. /// <returns></returns>
  29289. [HttpPost]
  29290. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29291. public async Task<IActionResult> PostVisaFeeAddAndUpdate(VisaFeeAddAndUpdateDto _dto)
  29292. {
  29293. var _view = await _visaFeeInfoRep.Update(_dto);
  29294. if (_view.Code != 0)
  29295. {
  29296. return Ok(JsonView(false, _view.Msg));
  29297. }
  29298. return Ok(JsonView(true, _view.Msg));
  29299. }
  29300. #endregion
  29301. #region 酒店询价
  29302. /// <summary>
  29303. /// 酒店询价
  29304. /// Init
  29305. /// </summary>
  29306. /// <returns></returns>
  29307. [HttpPost]
  29308. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29309. public async Task<IActionResult> PostHotelInquiryInit()
  29310. {
  29311. var res = await _hotelInquiryRep._Init();
  29312. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  29313. return Ok(JsonView(true, res.Msg, res.Data));
  29314. }
  29315. /// <summary>
  29316. /// 酒店询价
  29317. /// page Item
  29318. /// </summary>
  29319. /// <param name="_dto"></param>
  29320. /// <returns></returns>
  29321. [HttpPost]
  29322. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29323. public async Task<IActionResult> PostHotelInquiryPageItem(HotelInquiryPageItemDto _dto)
  29324. {
  29325. var res = await _hotelInquiryRep._PageItem(_dto.PageIndex, _dto.PageSize, _dto.PortType, _dto.DiId);
  29326. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  29327. var view = res.Data as PageDataViewBase;
  29328. return Ok(JsonView(true, res.Msg, view.Data, view.Total));
  29329. }
  29330. /// <summary>
  29331. /// 酒店询价
  29332. /// info
  29333. /// </summary>
  29334. /// <param name="_dto"></param>
  29335. /// <returns></returns>
  29336. [HttpPost]
  29337. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29338. public async Task<IActionResult> PostHotelInquiryInfo(HotelInquiryInfoDto _dto)
  29339. {
  29340. var res = await _hotelInquiryRep._Info(_dto.PortType, _dto.Id);
  29341. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  29342. return Ok(JsonView(true, res.Msg, res.Data));
  29343. }
  29344. /// <summary>
  29345. /// 酒店询价
  29346. /// Add Or Edit
  29347. /// </summary>
  29348. /// <param name="_dto"></param>
  29349. /// <returns></returns>
  29350. [HttpPost]
  29351. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29352. public async Task<IActionResult> PostHotelInquiryAddOrEdit(HotelInquiryAddOrEditDto _dto)
  29353. {
  29354. var res = await _hotelInquiryRep._AddOrEdit(_dto);
  29355. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  29356. return Ok(JsonView(true, res.Msg, res.Data));
  29357. }
  29358. /// <summary>
  29359. /// 酒店询价
  29360. /// Del
  29361. /// </summary>
  29362. /// <param name="_dto"></param>
  29363. /// <returns></returns>
  29364. [HttpPost]
  29365. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29366. public async Task<IActionResult> PostHotelInquiryDel(HotelInquiryDelDto _dto)
  29367. {
  29368. var res = await _hotelInquiryRep._Del(_dto.Id, _dto.DeleteUserId);
  29369. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  29370. return Ok(JsonView(true, res.Msg, res.Data));
  29371. }
  29372. #endregion
  29373. #region 下载匹配op行程单
  29374. /// <summary>
  29375. /// 匹配op行程单
  29376. /// Init
  29377. /// </summary>
  29378. /// <param name="dto">团组列表请求dto</param>
  29379. /// <returns></returns>
  29380. [HttpPost]
  29381. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29382. public async Task<IActionResult> PostMateOpGroupInit(MateOpGroupInitDto dto)
  29383. {
  29384. Stopwatch stopwatch = Stopwatch.StartNew(); // 创建并启动Stopwatch
  29385. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  29386. bool isDepStatus = await GeneralMethod.IsMarketingStaff(dto.CurrUserId);
  29387. List<Grp_DelegationInfo> groupInfos = new List<Grp_DelegationInfo>();
  29388. groupInfos = _sqlSugar.Queryable<Grp_DelegationInfo>()
  29389. .Where(it => it.IsDel == 0)
  29390. .WhereIF(isDepStatus, it => it.JietuanOperator == dto.CurrUserId)
  29391. .OrderByDescending(it => it.VisitStartDate)
  29392. .ToList();
  29393. if (groupInfos.Count < 1) return Ok(JsonView(false, "暂无和你相关的团组信息!"));
  29394. var country = groupInfos.Select(it => it.VisitCountry).ToList();
  29395. var diids = groupInfos.Select(it => it.Id).ToList();
  29396. List<string> countrys = new List<string>();
  29397. foreach (var item in country)
  29398. {
  29399. var data = _groupRepository.FormartTeamName(item);
  29400. var dataArray = _groupRepository.GroupSplitCountry(data);
  29401. if (dataArray.Count > 0) countrys.AddRange(dataArray);
  29402. }
  29403. countrys = countrys.Where(it => !string.IsNullOrEmpty(it)).Distinct().ToList();
  29404. List<string> areaArray = new List<string>(); //GetGroupCityLine
  29405. var areaItem = GeneralMethod.GetGroupCityLineItem(diids, "-");
  29406. foreach (var item in areaItem)
  29407. {
  29408. string areaStr = item.Value;
  29409. if (!string.IsNullOrEmpty(areaStr))
  29410. {
  29411. string[] str1 = areaStr.Split("-");
  29412. if (str1.Length > 0)
  29413. {
  29414. areaArray.AddRange(str1);
  29415. }
  29416. }
  29417. }
  29418. if (areaArray.Count > 0) areaArray = areaArray.Distinct().ToList();
  29419. var cityDatas = _sqlSugar.Queryable<Sys_Cities>()
  29420. .Where(it => it.IsDel == 0 && areaArray.Contains(it.Name_CN))
  29421. .Select(it => new { id = it.Id, parentId = it.CountriesId, name = it.Name_CN })
  29422. .ToList();
  29423. List<int> countriesIds = cityDatas.Select(it => it.parentId).ToList();
  29424. var countriesDatas = _sqlSugar.Queryable<Sys_Countries>()
  29425. .Where(it => countriesIds.Contains(it.Id))
  29426. .Select(it => new { it.Id, Name = it.Name_CN })
  29427. .ToList();
  29428. var teamNames = groupInfos.Where(it => !string.IsNullOrEmpty(it.TeamName))
  29429. .Select(it => it.TeamName).ToList();
  29430. stopwatch.Stop();
  29431. return Ok(JsonView(true, $"操作成功,耗时{stopwatch.ElapsedMilliseconds} ms", new { teamNames, countriesDatas, citiesDatas = cityDatas }));
  29432. }
  29433. ///// <summary>
  29434. ///// 匹配op行程单
  29435. ///// Init 查询区域数据
  29436. ///// </summary>
  29437. ///// <param name="dto">团组列表请求dto</param>
  29438. ///// <returns></returns>
  29439. //[HttpPost]
  29440. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29441. //public async Task<IActionResult> PostMateOpGroupCountryChangeData(MateOpGroupCountryChangeDataDto dto)
  29442. //{
  29443. // Stopwatch stopwatch = Stopwatch.StartNew(); // 创建并启动Stopwatch
  29444. // List<Sys_Cities> cityDatas = new List<Sys_Cities>();
  29445. // string countriesDataStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("CityDatas");//string 取
  29446. // if (string.IsNullOrEmpty(countriesDataStr))
  29447. // {
  29448. // cityDatas = await _sqlSugar.Queryable<Sys_Cities>().Where(it => it.IsDel == 0).ToListAsync();
  29449. // TimeSpan ts = DateTime.Now.AddHours(2).TimeOfDay; //设置redis 过期时间 2
  29450. // await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>("CountriesDatas", JsonConvert.SerializeObject(cityDatas), ts);//string 存
  29451. // }
  29452. // else
  29453. // {
  29454. // cityDatas = JsonConvert.DeserializeObject<List<Sys_Cities>>(countriesDataStr);
  29455. // }
  29456. // var provinceData = cityDatas.Where(it => it.CountriesId == dto.CountriesId && it.Level == 1).ToList();
  29457. // var citiesData = cityDatas.Where(it => it.CountriesId == dto.CountriesId && it.Level == 2).ToList();
  29458. // var countiesData = cityDatas.Where(it => it.CountriesId == dto.CountriesId && it.Level == 3).ToList();
  29459. // List<dynamic> childList = new List<dynamic>();
  29460. // int parentId = dto.CountriesId;
  29461. // if (provinceData.Count > 1)
  29462. // {
  29463. // foreach (var item1 in provinceData)
  29464. // {
  29465. // List<dynamic> childList1 = new List<dynamic>();
  29466. // var citiesData1 = citiesData.Where(it => it.ParentId == item1.Id).ToList();
  29467. // foreach (var item2 in citiesData1)
  29468. // {
  29469. // List<dynamic> childList2 = new List<dynamic>();
  29470. // var countiesData1 = countiesData.Where(it => it.ParentId == item2.Id).ToList();
  29471. // foreach (var item3 in countiesData1)
  29472. // {
  29473. // childList2.Add(new
  29474. // {
  29475. // id = item3.Id,
  29476. // parentId = item2.Id,
  29477. // level = "district",
  29478. // name = item3.Name_CN,
  29479. // });
  29480. // }
  29481. // childList1.Add(new
  29482. // {
  29483. // id = item2.Id,
  29484. // parentId = item1.Id,
  29485. // level = "city",
  29486. // name = item2.Name_CN,
  29487. // childList = childList2
  29488. // });
  29489. // }
  29490. // childList.Add(new
  29491. // {
  29492. // id = item1.Id,
  29493. // parentId = parentId,
  29494. // level = "province",
  29495. // name = item1.Name_CN,
  29496. // childList = childList1
  29497. // });
  29498. // }
  29499. // //城市
  29500. // var citiesData2 = citiesData.Where(it => it.ParentId == 0).ToList();
  29501. // foreach (var item2 in citiesData2)
  29502. // {
  29503. // List<dynamic> childList22 = new List<dynamic>();
  29504. // var countiesData1 = countiesData.Where(it => it.ParentId == item2.Id).ToList();
  29505. // foreach (var item3 in countiesData1)
  29506. // {
  29507. // childList22.Add(new
  29508. // {
  29509. // id = item3.Id,
  29510. // parentId = item2.Id,
  29511. // level = "district",
  29512. // name = item3.Name_CN,
  29513. // });
  29514. // }
  29515. // childList.Add(new
  29516. // {
  29517. // id = item2.Id,
  29518. // parentId = parentId,
  29519. // level = "city",
  29520. // name = item2.Name_CN,
  29521. // childList = childList22
  29522. // });
  29523. // }
  29524. // }
  29525. // else
  29526. // {
  29527. // foreach (var item2 in citiesData)
  29528. // {
  29529. // string cname = item2.Name_CN;
  29530. // List<dynamic> childList1 = new List<dynamic>();
  29531. // var countiesData1 = countiesData.Where(it => it.ParentId == item2.Id).ToList();
  29532. // foreach (var item3 in countiesData1)
  29533. // {
  29534. // childList1.Add(new
  29535. // {
  29536. // Id = item3.Id,
  29537. // parentId = item2.Id,
  29538. // level = "district",
  29539. // name = item3.Name_CN
  29540. // });
  29541. // }
  29542. // childList.Add(new
  29543. // {
  29544. // id = item2.Id,
  29545. // parentId = parentId,
  29546. // level = "city",
  29547. // name = item2.Name_CN,
  29548. // childList = childList1
  29549. // });
  29550. // }
  29551. // }
  29552. // stopwatch.Stop();
  29553. // return Ok(JsonView(true, $"操作成功,耗时{stopwatch.ElapsedMilliseconds} ms", childList));
  29554. //}
  29555. /// <summary>
  29556. /// 匹配op行程单
  29557. /// 接团信息列表 Page
  29558. /// </summary>
  29559. /// <param name="dto">团组列表请求dto</param>
  29560. /// <returns></returns>
  29561. [HttpPost]
  29562. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29563. public async Task<IActionResult> PostMateOpGroupPageList(MateOpGroupPageListDto dto)
  29564. {
  29565. var swatch = new Stopwatch();
  29566. swatch.Start();
  29567. #region 参数验证
  29568. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  29569. if (dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  29570. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  29571. #region 页面操作权限验证
  29572. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  29573. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  29574. #endregion
  29575. #endregion
  29576. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) // web/Android
  29577. {
  29578. var _view = await GeneralMethod.MateOpGroupPageListRedis();
  29579. //string sqlWhere = "";
  29580. if (!string.IsNullOrEmpty(dto.Country))
  29581. {
  29582. _view = _view.Where(x => !string.IsNullOrEmpty(x.VisitCountry) && x.VisitCountry.Contains(dto.Country)).ToList();
  29583. }
  29584. if (!string.IsNullOrEmpty(dto.Area))
  29585. {
  29586. _view = _view.Where(x => !string.IsNullOrEmpty(x.RouteCity) && x.RouteCity.Contains(dto.Area)).ToList();
  29587. }
  29588. if (!string.IsNullOrEmpty(dto.TeamName))
  29589. {
  29590. _view = _view.Where(x => !string.IsNullOrEmpty(x.TeamName) && x.TeamName.Contains(dto.TeamName)).ToList();
  29591. }
  29592. int startIndex = (dto.PageIndex - 1) * dto.PageSize; // 计算开始的索引
  29593. int endIndex = startIndex + dto.PageSize - 1; // 计算结束的索引
  29594. var _view1 = _view.Skip(startIndex).Take(endIndex).ToList();
  29595. swatch.Stop();
  29596. return Ok(JsonView(true, $"查询成功!耗时 {swatch.ElapsedMilliseconds} ms", _view1, _view.Count));
  29597. }
  29598. else
  29599. {
  29600. return Ok(JsonView(false, "查询失败"));
  29601. }
  29602. }
  29603. /// <summary>
  29604. /// 匹配op行程单
  29605. /// 行程单下载
  29606. /// </summary>
  29607. /// <param name="dto">团组列表请求dto</param>
  29608. /// <returns></returns>
  29609. [HttpPost]
  29610. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29611. public async Task<IActionResult> PostMateOpGroupDownload(MateOpGroupDownloadDto dto)
  29612. {
  29613. #region 参数验证
  29614. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  29615. if (dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  29616. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  29617. #region 页面操作权限验证
  29618. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  29619. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限"));
  29620. #endregion
  29621. #endregion
  29622. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) // web/Android
  29623. {
  29624. var res = ExportTravel(new ExportTravelDto() { Diid = dto.diId });
  29625. return Ok(res.GetType().GetProperty("Value").GetValue(res, null));
  29626. }
  29627. else
  29628. {
  29629. return Ok(JsonView(false, "下载失败!"));
  29630. }
  29631. }
  29632. #endregion
  29633. #region 国家信息 数据 注释
  29634. //[HttpPost]
  29635. //public async Task<IActionResult> LoadCitiesInitData(List<int> dto)
  29636. //{
  29637. // List<Grp_GroupsTaskAssignment> infos = new List<Grp_GroupsTaskAssignment>();
  29638. // foreach (var item in dto)
  29639. // {
  29640. // infos.Add(new Grp_GroupsTaskAssignment()
  29641. // {
  29642. // DIId = item,
  29643. // CTId = 82,
  29644. // UId = 248,
  29645. // IsEnable = 1,
  29646. // CreateUserId = 233,
  29647. // CreateTime = DateTime.Now,
  29648. // IsDel = 0
  29649. // });
  29650. // infos.Add(new Grp_GroupsTaskAssignment()
  29651. // {
  29652. // DIId = item,
  29653. // CTId = 82,
  29654. // UId = 286,
  29655. // IsEnable = 1,
  29656. // CreateUserId = 233,
  29657. // CreateTime = DateTime.Now,
  29658. // IsDel = 0
  29659. // });
  29660. // }
  29661. // int add = _sqlSugar.Insertable<Grp_GroupsTaskAssignment>(infos).ExecuteCommand();
  29662. // return Ok("操作成功");
  29663. //}
  29664. //public class paramJsonDto
  29665. //{
  29666. // public List<CountriesInfo> str { get; set; }
  29667. //}
  29668. //[HttpPost]
  29669. //public async Task<IActionResult> LoadCitiesInitData(paramJsonDto dto)
  29670. //{
  29671. // //List<CountriesInfo> infos = new List<CountriesInfo>();
  29672. // //infos = JsonConvert.DeserializeObject<List<CountriesInfo>>(dto.str);
  29673. // List<Sys_Cities> cities = new List<Sys_Cities>();
  29674. // List<Sys_Cities> districts = new List<Sys_Cities>();
  29675. // var counties = _sqlSugar.Queryable<Sys_Countries>().Where(it => it.IsDel == 0).ToList();
  29676. // _sqlSugar.BeginTran();
  29677. // int countitiesIndex = 0;
  29678. // foreach (var item in dto.str)
  29679. // {
  29680. // dynamic data = item.c;
  29681. // int countriesId = counties.Find(it => it.Name_CN.Equals(item.cn))?.Id ?? 0;
  29682. // if (data != null)
  29683. // {
  29684. // countitiesIndex++;
  29685. // foreach (var item1 in data)
  29686. // {
  29687. // string cnname = item1.cn;
  29688. // string enname = item1.en;
  29689. // Sys_Cities provinceInfo = new Sys_Cities()
  29690. // {
  29691. // CountriesId = countriesId,
  29692. // Name_CN = cnname,
  29693. // Name_EN = enname,
  29694. // ParentId = 0,
  29695. // IsCapital = 1,
  29696. // CreateUserId = 208,
  29697. // CreateTime = DateTime.Now,
  29698. // IsDel = 0
  29699. // };
  29700. // if (item1.lv == "province") //省份
  29701. // {
  29702. // provinceInfo.Level = 1;
  29703. // int provinceId = 0;
  29704. // var provinceInfo1 = _sqlSugar.Queryable<Sys_Cities>().Where(it => it.CountriesId == countriesId && it.Level == 1 && it.Name_CN.Equals(cnname)).First();
  29705. // if (provinceInfo1 != null) provinceId = provinceInfo1.Id;
  29706. // else provinceId = _sqlSugar.Insertable<Sys_Cities>(provinceInfo).ExecuteReturnIdentity();
  29707. // var data1 = item1.c;
  29708. // foreach (var item2 in data1)
  29709. // {
  29710. // if (item2.lv == "city")
  29711. // {
  29712. // string citycnname = item2.cn;
  29713. // string cityenname = item2.en;
  29714. // Sys_Cities cityInfo = new Sys_Cities()
  29715. // {
  29716. // CountriesId = countriesId,
  29717. // ParentId = provinceId,
  29718. // Level = 2,
  29719. // Name_CN = citycnname,
  29720. // Name_EN = cityenname,
  29721. // IsCapital = 1,
  29722. // CreateUserId = 208,
  29723. // CreateTime = DateTime.Now,
  29724. // IsDel = 0
  29725. // };
  29726. // if (item2.c != null)
  29727. // {
  29728. // int cityId = 0;
  29729. // var citiesInfo = _sqlSugar.Queryable<Sys_Cities>().Where(it => it.CountriesId == countriesId && it.Level == 2 && it.Name_CN.Equals(citycnname)).First();
  29730. // if (citiesInfo != null) cityId = citiesInfo.Id;
  29731. // else cityId = _sqlSugar.Insertable<Sys_Cities>(cityInfo).ExecuteReturnIdentity();
  29732. // foreach (var item3 in item2.c)
  29733. // {
  29734. // if (item3.lv == "district")
  29735. // {
  29736. // var districtInfo = new Sys_Cities()
  29737. // {
  29738. // CountriesId = countriesId,
  29739. // Name_CN = item3.cn,
  29740. // Name_EN = item3.en,
  29741. // Level = 3,
  29742. // ParentId = cityId,
  29743. // IsCapital = 1,
  29744. // CreateUserId = 208,
  29745. // CreateTime = DateTime.Now,
  29746. // IsDel = 0
  29747. // };
  29748. // //if (districts.Find(it => it.CountriesId == countriesId && it.ParentId == cityId && it.Name_CN.Equals(districtInfo.Name_CN)) == null)
  29749. // //{
  29750. // districts.Add(districtInfo);
  29751. // //}
  29752. // }
  29753. // }
  29754. // }
  29755. // else
  29756. // {
  29757. // //if (cities.Find(it => it.CountriesId == countriesId && it.ParentId == provinceId && it.Name_CN.Equals(citycnname)) == null)
  29758. // //{
  29759. // cities.Add(cityInfo);
  29760. // //}
  29761. // }
  29762. // }
  29763. // }
  29764. // }
  29765. // else if (item1.lv == "city")//城市
  29766. // {
  29767. // provinceInfo.Level = 2;
  29768. // if (item1.c != null)
  29769. // {
  29770. // int cityId = 0;
  29771. // var citiesInfo = _sqlSugar.Queryable<Sys_Cities>().Where(it => it.CountriesId == countriesId && it.Level == 1 && it.Name_CN.Equals(provinceInfo.Name_CN)).First();
  29772. // if (citiesInfo != null) cityId = citiesInfo.Id;
  29773. // else cityId = _sqlSugar.Insertable<Sys_Cities>(provinceInfo).ExecuteReturnIdentity();
  29774. // foreach (var item3 in item1.c)
  29775. // {
  29776. // if (item3.lv == "district")
  29777. // {
  29778. // var districtInfo = new Sys_Cities()
  29779. // {
  29780. // CountriesId = countriesId,
  29781. // Name_CN = item3.cn,
  29782. // Name_EN = item3.en,
  29783. // Level = 3,
  29784. // ParentId = cityId,
  29785. // IsCapital = 1,
  29786. // CreateUserId = 208,
  29787. // CreateTime = DateTime.Now,
  29788. // IsDel = 0
  29789. // };
  29790. // //if (districts.Find(it => it.CountriesId == countriesId && it.ParentId == cityId && it.Name_CN.Equals(districtInfo.Name_CN)) == null)
  29791. // //{
  29792. // districts.Add(districtInfo);
  29793. // //}
  29794. // }
  29795. // }
  29796. // }
  29797. // else
  29798. // {
  29799. // //if (cities.Find(it => it.CountriesId == countriesId && it.Name_CN.Equals(provinceInfo.Name_CN)) == null)
  29800. // //{
  29801. // cities.Add(provinceInfo);
  29802. // //}
  29803. // }
  29804. // }
  29805. // }
  29806. // }
  29807. // }
  29808. // var procinceDatas = _sqlSugar.Queryable<Sys_Cities>().ToList();
  29809. // cities = cities.Distinct().ToList();
  29810. // districts = districts.Distinct().ToList();
  29811. // var citiesDatas = cities.Where(it => it.Level == 2).ToList();
  29812. // //var districtDatas = cities.Where(it => it.Level == 3).ToList();
  29813. // cities.AddRange(districts);
  29814. // var citiesAdd = _sqlSugar.Insertable<Sys_Cities>(cities).ExecuteReturnIdentity();
  29815. // //_sqlSugar.RollbackTran();
  29816. // _sqlSugar.CommitTran();
  29817. // return Ok(JsonView(false, "操作成功!"));
  29818. //}
  29819. //[HttpPost]
  29820. //public async Task<IActionResult> LoadCitiesInitInfo(CounrtiesDto dto)
  29821. //{
  29822. // List<CountitiesInfo> infos = dto.MyProperty;
  29823. // List<Sys_Cities> cityInfos = new List<Sys_Cities>();
  29824. // _sqlSugar.BeginTran();
  29825. // var countities = _sqlSugar.Queryable<Sys_Countries>().Where(it => it.IsDel == 0).ToList();
  29826. // var citities = _sqlSugar.Queryable<Sys_Cities>().Where(it => it.IsDel == 0 && it.Level == 2).ToList();
  29827. // foreach (var item in infos)
  29828. // {
  29829. // var countryInfo = countities.Where(it => it.ThreeCode.Equals(item.country_code3)).FirstOrDefault();
  29830. // if (countryInfo != null)
  29831. // {
  29832. // var cityInfo = citities.Where(it => it.CountriesId == countryInfo.Id).ToList();
  29833. // var cityInfo1 = cityInfo.Where(it => item.capital_name_chinese.Contains(it.Name_CN)).FirstOrDefault();
  29834. // if (cityInfo1 != null)
  29835. // {
  29836. // cityInfo1.IsCapital = 0;
  29837. // cityInfos.Add(cityInfo1);
  29838. // }
  29839. // }
  29840. // }
  29841. // var update = _sqlSugar.Updateable<Sys_Cities>(cityInfos)
  29842. // .UpdateColumns(it => it.IsCapital)
  29843. // .WhereColumns(it => it.Id)
  29844. // .ExecuteCommand();
  29845. // //_sqlSugar.RollbackTran();
  29846. // _sqlSugar.CommitTran();
  29847. // return Ok(JsonView(false, "操作成功!"));
  29848. //}
  29849. //public class CounrtiesDto
  29850. //{
  29851. // public List<CountitiesInfo> MyProperty { get; set; }
  29852. //}
  29853. //public class CountitiesInfo
  29854. //{
  29855. // /// <summary>
  29856. // /// 圣约翰
  29857. // /// </summary>
  29858. // public string capital_name_chinese { get; set; }
  29859. // /// <summary>
  29860. // ///
  29861. // /// </summary>
  29862. // public string capital_name { get; set; }
  29863. // /// <summary>
  29864. // ///
  29865. // /// </summary>
  29866. // public string country_type { get; set; }
  29867. // /// <summary>
  29868. // /// 安提瓜和巴布达
  29869. // /// </summary>
  29870. // public string country_name_chinese { get; set; }
  29871. // /// <summary>
  29872. // /// 安提瓜和巴布达
  29873. // /// </summary>
  29874. // public string country_name_chinese_short { get; set; }
  29875. // /// <summary>
  29876. // /// 安提瓜和巴布达
  29877. // /// </summary>
  29878. // public string country_name_chinese_UN { get; set; }
  29879. // /// <summary>
  29880. // ///
  29881. // /// </summary>
  29882. // public string country_name_english_abbreviation { get; set; }
  29883. // /// <summary>
  29884. // ///
  29885. // /// </summary>
  29886. // public string country_name_english_formal { get; set; }
  29887. // /// <summary>
  29888. // ///
  29889. // /// </summary>
  29890. // public string country_name_english_UN { get; set; }
  29891. // /// <summary>
  29892. // ///
  29893. // /// </summary>
  29894. // public string continent_name { get; set; }
  29895. // /// <summary>
  29896. // ///
  29897. // /// </summary>
  29898. // public string subregion_name { get; set; }
  29899. // /// <summary>
  29900. // ///
  29901. // /// </summary>
  29902. // public string country_code2 { get; set; }
  29903. // /// <summary>
  29904. // ///
  29905. // /// </summary>
  29906. // public string country_code3 { get; set; }
  29907. // /// <summary>
  29908. // ///
  29909. // /// </summary>
  29910. // public string phone_code { get; set; }
  29911. //}
  29912. //public class CountriesInfo : BasicInfo
  29913. //{
  29914. // public List<CitiesInfo> c { get; set; }
  29915. //}
  29916. //public class CitiesInfo : BasicInfo
  29917. //{
  29918. // public List<AreaInfo> c { get; set; }
  29919. //}
  29920. //public class AreaInfo : BasicInfo
  29921. //{
  29922. // public List<AreaInfo> c { get; set; }
  29923. //}
  29924. //public class BasicInfo
  29925. //{
  29926. // public string code { get; set; }
  29927. // public string cn { get; set; }
  29928. // public string lv { get; set; }
  29929. // public string en { get; set; }
  29930. //}
  29931. #endregion
  29932. #region 查看邀请方
  29933. /// <summary>
  29934. /// 查看邀请方
  29935. /// 邀请方信息 Init
  29936. /// </summary>
  29937. /// <param name="dto"></param>
  29938. /// <returns></returns>
  29939. [HttpPost]
  29940. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29941. public async Task<IActionResult> PostGroupLinkInvitingUnitNameInit(GroupLinkInvitingUnitNameInitDto dto)
  29942. {
  29943. string sqlWhere = string.Empty;
  29944. if (!string.IsNullOrEmpty(dto.Search))
  29945. {
  29946. sqlWhere = string.Format($@" And UnitName Like '%{dto.Search}%'");
  29947. }
  29948. string sql = string.Format($@"Select
  29949. ROW_NUMBER() Over(Order By Id desc) As Row_Number,
  29950. Id,
  29951. UnitName
  29952. From Res_InvitationOfficialActivityData
  29953. Where IsDel = 0
  29954. And (UnitName != '' Or UnitName != null) {sqlWhere}");
  29955. RefAsync<int> total = 0;
  29956. var _views = await _sqlSugar.SqlQueryable<GroupLinkInvitingUnitNameInitView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  29957. return Ok(JsonView(true, MsgTips.Succeed, _views, total));
  29958. }
  29959. /// <summary>
  29960. /// 查看邀请方
  29961. /// 国家信息 Init
  29962. /// </summary>
  29963. /// <param name="dto"></param>
  29964. /// <returns></returns>
  29965. [HttpPost]
  29966. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29967. public async Task<IActionResult> PostGroupLinkInvitingCountryInit(GroupLinkInvitingUnitNameInitDto dto)
  29968. {
  29969. var groupInfos = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).OrderByDescending(it => it.CreateUserId).ToListAsync();
  29970. var country = groupInfos.Select(it => it.VisitCountry).ToList();
  29971. var diids = groupInfos.Select(it => it.Id).ToList();
  29972. List<string> countrys = new List<string>();
  29973. foreach (var item in country)
  29974. {
  29975. var data = _groupRepository.FormartTeamName(item);
  29976. var dataArray = _groupRepository.GroupSplitCountry(data);
  29977. if (dataArray.Count > 0) countrys.AddRange(dataArray);
  29978. }
  29979. countrys = countrys.Distinct().ToList();
  29980. for (int i = 0; i < countrys.Count; i++)
  29981. {
  29982. string item = countrys[i];
  29983. if (string.IsNullOrEmpty(item) || item.Contains("-"))
  29984. {
  29985. countrys.Remove(item);
  29986. i--;
  29987. }
  29988. }
  29989. RefAsync<int> total = 0;
  29990. var countyDatas = await _sqlSugar.Queryable<Sys_Countries>()
  29991. .Where(it => countrys.Contains(it.Name_CN))
  29992. .WhereIF(!string.IsNullOrEmpty(dto.Search), it => it.Name_CN.Contains(dto.Search))
  29993. .Select(it => new { id = it.Id, name = it.Name_CN })
  29994. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  29995. return Ok(JsonView(true, MsgTips.Succeed, countyDatas, total));
  29996. }
  29997. /// <summary>
  29998. /// 查看邀请方
  29999. /// 城市信息 Init
  30000. /// </summary>
  30001. /// <param name="dto"></param>
  30002. /// <returns></returns>
  30003. [HttpPost]
  30004. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30005. public async Task<IActionResult> PostGroupLinkInvitingCityInit(GroupLinkInvitingCityInitDto dto)
  30006. {
  30007. if (dto.CountiesId < 1) return Ok(JsonView(false, "请传入有效的国家Id"));
  30008. RefAsync<int> total = 0;
  30009. var countyDatas = await _sqlSugar.Queryable<Sys_Cities>()
  30010. .Where(it => it.CountriesId == dto.CountiesId)
  30011. .WhereIF(!string.IsNullOrEmpty(dto.Search), it => it.Name_CN.Contains(dto.Search))
  30012. .OrderBy(it => new { IsCapital = SqlFunc.Asc(it.IsCapital), Id = SqlFunc.Asc(it.Id) })
  30013. .Select(it => new { id = it.Id, name = it.Name_CN })
  30014. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  30015. return Ok(JsonView(true, MsgTips.Succeed, countyDatas, total));
  30016. }
  30017. /// <summary>
  30018. /// 查看邀请方
  30019. /// 团组名称 Init
  30020. /// </summary>
  30021. /// <param name="dto"></param>
  30022. /// <returns></returns>
  30023. [HttpPost]
  30024. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30025. public async Task<IActionResult> PostGroupLinkInvitingGroupInit(GroupLinkInvitingDto dto)
  30026. {
  30027. var watch = new Stopwatch();
  30028. watch.Start();
  30029. RefAsync<int> total = 0;
  30030. var countyDatas = await _sqlSugar.Queryable<Res_OfficialActivities>()
  30031. .InnerJoin<Grp_DelegationInfo>((oa, di) => oa.DiId == di.Id)
  30032. .Where((oa, di) => oa.IsDel == 0)
  30033. .WhereIF(!string.IsNullOrEmpty(dto.Search), (oa, di) => di.TeamName.Contains(dto.Search))
  30034. .OrderBy((oa, di) => new { id = SqlFunc.Desc(di.Id) })
  30035. .Select((oa, di) => new { id = di.Id, name = di.TeamName })
  30036. .Distinct()
  30037. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  30038. watch.Stop();
  30039. return Ok(JsonView(true, $"{MsgTips.Succeed},耗时 {watch.ElapsedMilliseconds} ms", countyDatas, total));
  30040. }
  30041. /// <summary>
  30042. /// 查看邀请方
  30043. /// 团组 & 邀请方信息
  30044. /// </summary>
  30045. /// <param name="dto"></param>
  30046. /// <returns></returns>
  30047. [HttpPost]
  30048. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30049. public async Task<IActionResult> PostGroupLinkInvitingPageList(GroupLinkInvitingPageListDto dto)
  30050. {
  30051. var watch = new Stopwatch();
  30052. watch.Start();
  30053. RefAsync<int> total = 0;
  30054. var infos = await _sqlSugar.Queryable<GroupLinkInvitingPageListView>()
  30055. .AS("Grp_DelegationInfo")
  30056. .Includes(x => x.InvitingInfos)
  30057. .Where(x => x.IsDel == 0 && x.InvitingInfos.Any(z => z.IsDel == 0))
  30058. .WhereIF(!string.IsNullOrEmpty(dto.Counrty), x => x.VisitCountry.Contains(dto.Counrty))
  30059. .WhereIF(!string.IsNullOrEmpty(dto.Area), x => x.InvitingInfos.Any(z => z.Area.Contains(dto.Area))) //
  30060. .WhereIF(!string.IsNullOrEmpty(dto.TeamName), x => x.TeamName.Contains(dto.TeamName)) //
  30061. .WhereIF(!string.IsNullOrEmpty(dto.UnitName), x => x.InvitingInfos.Any(z => z.Client.Contains(dto.UnitName)))
  30062. .OrderBy(x => new { JietuanTime = SqlFunc.Desc(x.VisitStartDate) })
  30063. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  30064. var userDatas = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToList();
  30065. var setDatas = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0).ToList();
  30066. infos.ForEach(x =>
  30067. {
  30068. x.TeamDid = setDatas.Find(y => int.Parse(x.TeamDid) == y.Id)?.Name ?? "-";
  30069. x.JietuanOperator = userDatas.Find(y => int.Parse(x.JietuanOperator) == y.Id)?.CnName ?? "-";
  30070. x.TeamLevSId = setDatas.Find(y => int.Parse(x.TeamLevSId) == y.Id)?.Name ?? "-";
  30071. x.InvitingInfos = x.InvitingInfos.Where(it => it.IsDel == 0).ToList();
  30072. });
  30073. watch.Stop();
  30074. return Ok(JsonView(true, $"{MsgTips.Succeed},耗时 {watch.ElapsedMilliseconds} ms", infos, total));
  30075. }
  30076. #endregion
  30077. #region 报批行程
  30078. /// <summary>
  30079. /// 报批行程初始化
  30080. /// </summary>
  30081. /// <param name="dto"></param>
  30082. /// <returns></returns>
  30083. [HttpPost]
  30084. public IActionResult ApprovalJourneyInit(ApprovalJourneyDto dto)
  30085. {
  30086. const int chiNumber = 5;
  30087. var jw = JsonView(false);
  30088. var groupList = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0).OrderByDescending(x => x.VisitStartDate).ToList();
  30089. var group = groupList.First();
  30090. var diid = dto.Diid == -1 ? group?.Id : dto.Diid;
  30091. group = groupList.First(x => x.Id == diid);
  30092. var blackCodeList = _sqlSugar.Queryable<Air_TicketBlackCode>()
  30093. .Where(x => x.DiId == diid && x.IsDel == 0)
  30094. .ToArray();
  30095. var count = 1;
  30096. foreach (var item in blackCodeList)
  30097. {
  30098. if (string.IsNullOrWhiteSpace(item.Title))
  30099. {
  30100. item.Title = "未设置名称数据" + count;
  30101. }
  30102. count++;
  30103. }
  30104. ;
  30105. if (group == null)
  30106. {
  30107. jw.Msg = "暂无团组!";
  30108. return Ok(jw);
  30109. }
  30110. var data = new
  30111. {
  30112. groupList = groupList.Select(x => new
  30113. {
  30114. x.TeamName,
  30115. x.Id
  30116. }),
  30117. content = new ArrayList(),
  30118. groupInfo = new
  30119. {
  30120. group.VisitDays,
  30121. group.TourCode,
  30122. group.VisitPNumber,
  30123. group.TeamName,
  30124. group.Id,
  30125. visitStartDate = group.VisitStartDate.ToString("yyyy-MM-dd"),
  30126. visitEndDate = group.VisitEndDate.ToString("yyyy-MM-dd"),
  30127. group.ClientUnit
  30128. },
  30129. blackCodeList = blackCodeList.Select(x => new
  30130. {
  30131. x.Title,
  30132. x.Id
  30133. }),
  30134. FileTempList = new ArrayList()
  30135. {
  30136. new { Index = 1,FileName = "旧模板" },
  30137. new { Index = 2,FileName = "省外办" },
  30138. new { Index = 3,FileName = "市外办" },
  30139. }
  30140. };
  30141. var resultArr = new ArrayList();
  30142. var content = _sqlSugar.Queryable<Grp_ApprovalTravel>().Where(x => x.Diid == diid && x.IsDel == 0).ToList();
  30143. #region 默认不生成行程
  30144. //if (content.Count == 0)
  30145. //{
  30146. // var stay = "-";
  30147. // var cityPath = "-";
  30148. // var blackCodeList = _sqlSugar.Queryable<Air_TicketBlackCode>()
  30149. // .Where(x => x.DiId == diid && x.IsDel == 0)
  30150. // .ToList();
  30151. // //添加城市路径以及住宿地
  30152. // //黑屏代码数据
  30153. // DataTable dtBlack = GeneralMethod.GetTableByBlackCodeById(blackCodeList.FirstOrDefault());
  30154. // if (dtBlack.Rows.Count == 0 || string.IsNullOrWhiteSpace(dtBlack.Rows[0][1].ToString()))
  30155. // {
  30156. // jw = JsonView(true, "黑屏代码有误!", data);
  30157. // return Ok(jw);
  30158. // }
  30159. // data = data with
  30160. // {
  30161. // blackCodeList = new ArrayList(blackCodeList.Select(x => new
  30162. // {
  30163. // x.Title,
  30164. // x.Id,
  30165. // }).ToArray())
  30166. // };
  30167. // foreach (DataRow row in dtBlack.Rows)
  30168. // {
  30169. // if (!string.IsNullOrWhiteSpace(row["Error"].ToString()))
  30170. // {
  30171. // jw = JsonView(true, "黑屏代码有误!" + row["Error"].ToString(), data);
  30172. // return Ok(jw);
  30173. // }
  30174. // }
  30175. // //黑屏代码获取时间区间
  30176. // var timeArr = GeneralMethod.GetTimeListByDataTable(dtBlack);
  30177. // string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  30178. // _sqlSugar.BeginTran();
  30179. // for (int i = 0; i < timeArr.Count; i++)
  30180. // {
  30181. // stay = "-";
  30182. // cityPath = "-";
  30183. // DateTime NewData = DateTime.Parse(timeArr[i]);
  30184. // string week = Day[Convert.ToInt32(NewData.DayOfWeek.ToString("d"))].ToString();
  30185. // Grp_ApprovalTravel appro = new Grp_ApprovalTravel();
  30186. // var tbSelect = dtBlack.Select(string.Format("Day = '{0}'", NewData.ToString("yyyy-MM-dd")));
  30187. // if (tbSelect.Length > 0)
  30188. // {
  30189. // List<string> threeCodeStr = new List<string>();
  30190. // foreach (var item in tbSelect)
  30191. // {
  30192. // var threeCode = item["Three"].ToString() ?? "";
  30193. // if (threeCode.Length == 6)
  30194. // {
  30195. // var start = threeCode.Substring(0, 3);
  30196. // var end = threeCode.Substring(3, 3);
  30197. // if (threeCodeStr.Count == 0)
  30198. // {
  30199. // threeCodeStr.Add(start);
  30200. // threeCodeStr.Add(end);
  30201. // }
  30202. // else
  30203. // {
  30204. // if (threeCodeStr[threeCodeStr.Count - 1] == start)
  30205. // {
  30206. // threeCodeStr.Add(end);
  30207. // }
  30208. // else
  30209. // {
  30210. // threeCodeStr.Add(start);
  30211. // threeCodeStr.Add(end);
  30212. // }
  30213. // }
  30214. // }
  30215. // }
  30216. // var threeCodeList = _threeCodeRepository.QueryThreeCodeArray(threeCodeStr);
  30217. // var last = threeCodeStr.Last();
  30218. // foreach (var item in threeCodeStr)
  30219. // {
  30220. // cityPath += (threeCodeList.Keys.Contains(item) ? threeCodeList[item].City : "【未知三字码】") + "-";
  30221. // if (item.Equals(last))
  30222. // {
  30223. // stay = threeCodeList.Keys.Contains(item) ? threeCodeList[item].City : "【未知三字码】";
  30224. // }
  30225. // }
  30226. // cityPath = cityPath.Trim('-');
  30227. // }
  30228. // appro.Date = "第" + intToString(i + 1) + "天 " + NewData.Month + "月" + NewData.Day + "日(" + week + ") " + cityPath + " 宿:" + stay;
  30229. // appro.Diid = diid ?? -1;
  30230. // var thisId = _sqlSugar.Insertable<Grp_ApprovalTravel>(appro).ExecuteReturnIdentity();
  30231. // appro.Id = thisId;
  30232. // appro.CreateUserId = dto.UserId;
  30233. // appro.CreateTime = DateTime.Now;
  30234. // content.Add(appro);
  30235. // }
  30236. // _sqlSugar.CommitTran();
  30237. //}
  30238. #endregion
  30239. foreach (var x in content)
  30240. {
  30241. var chiList = _sqlSugar.Queryable<Grp_ApprovalTravelDetails>().Where(x1 => x1.ParentId == x.Id && x1.IsDel == 0).ToList();
  30242. if (chiList.Count < chiNumber)
  30243. {
  30244. for (int i = chiList.Count; i < chiNumber; i++)
  30245. {
  30246. chiList.Add(new Grp_ApprovalTravelDetails());
  30247. }
  30248. }
  30249. resultArr.Add(new
  30250. {
  30251. x.Id,
  30252. x.Date,
  30253. x.Diid,
  30254. chiList = chiList.Select(x1 => new
  30255. {
  30256. timeInterval = string.IsNullOrWhiteSpace(x1.Time) ? new string[1] : x1.Time.Split('-'),
  30257. x1.Details,
  30258. x1.ParentId,
  30259. x1.Id
  30260. })
  30261. });
  30262. }
  30263. data = data with
  30264. {
  30265. content = resultArr,
  30266. };
  30267. jw = JsonView(true, "获取成功!", data);
  30268. return Ok(jw);
  30269. }
  30270. /// <summary>
  30271. /// 报批行程删除
  30272. /// </summary>
  30273. /// <param name="dto"></param>
  30274. /// <returns></returns>
  30275. [HttpPost]
  30276. public IActionResult DeleteApprovalJourney(DeleteApprovalJourney dto)
  30277. {
  30278. var jw = JsonView(false);
  30279. var group = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  30280. if (group == null)
  30281. {
  30282. jw.Msg = "团组参数有误!";
  30283. return Ok(jw);
  30284. }
  30285. try
  30286. {
  30287. _sqlSugar.BeginTran();
  30288. var arr = _sqlSugar.Queryable<Grp_ApprovalTravel>().Where(x => x.Diid == dto.Diid && x.IsDel == 0).Select(x => x.Id).ToList();
  30289. _ = _sqlSugar.Updateable<Grp_ApprovalTravelDetails>().SetColumns(x => new Grp_ApprovalTravelDetails
  30290. {
  30291. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  30292. DeleteUserId = dto.uesrId,
  30293. IsDel = 1
  30294. }).Where(x => arr.Contains(x.ParentId) && x.IsDel == 0).ExecuteCommand();
  30295. _ = _sqlSugar.Updateable<Grp_ApprovalTravel>().SetColumns(x => new Grp_ApprovalTravel
  30296. {
  30297. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  30298. DeleteUserId = dto.uesrId,
  30299. IsDel = 1
  30300. }).Where(x => arr.Contains(x.Id)).ExecuteCommand();
  30301. _sqlSugar.CommitTran();
  30302. jw = JsonView(true, "删除成功");
  30303. }
  30304. catch (Exception ex)
  30305. {
  30306. jw = JsonView(false, ex.Message);
  30307. }
  30308. return Ok(jw);
  30309. }
  30310. /// <summary>
  30311. /// 报批行程保存
  30312. /// </summary>
  30313. /// <param name="dto"></param>
  30314. /// <returns></returns>
  30315. [HttpPost]
  30316. public IActionResult SaveApprovalJourney(SaveApprovalJourney dto)
  30317. {
  30318. var jw = JsonView(false);
  30319. var Find = dto.Arr.Find(x => x.id == 0);
  30320. if (Find != null)
  30321. {
  30322. jw.Msg = "生成的ID为0!";
  30323. return Ok(jw);
  30324. }
  30325. foreach (var item in dto.Arr)
  30326. {
  30327. foreach (var chi in item.chiList)
  30328. {
  30329. if (chi.parentId == 0)
  30330. {
  30331. chi.parentId = item.id;
  30332. }
  30333. }
  30334. }
  30335. var chiArr = dto.Arr.SelectMany(x => x.chiList).ToList();
  30336. _sqlSugar.BeginTran();
  30337. if (chiArr.Where(x => x.id == 0).Count() == chiArr.Count)
  30338. {
  30339. var parentIds = dto.Arr.Select(x => x.id).ToList();
  30340. _sqlSugar.Updateable<Grp_ApprovalTravelDetails>().Where(x => parentIds.Contains(x.ParentId) && x.IsDel == 0).SetColumns(x => new Grp_ApprovalTravelDetails
  30341. {
  30342. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  30343. DeleteUserId = dto.UserId,
  30344. IsDel = 1
  30345. }).ExecuteCommand();
  30346. }
  30347. try
  30348. {
  30349. _ = _sqlSugar.Insertable<Grp_ApprovalTravelDetails>(chiArr.Where(x => x.id == 0).Select(x => new Grp_ApprovalTravelDetails
  30350. {
  30351. CreateTime = DateTime.Now,
  30352. CreateUserId = dto.UserId,
  30353. Details = x.details,
  30354. ParentId = x.parentId,
  30355. Time = x.timeInterval.Where(x => !string.IsNullOrWhiteSpace(x)).Count() > 1 ? x.timeInterval[0] + "-" + x.timeInterval[1] : "",
  30356. Remark = "",
  30357. IsDel = 0
  30358. }).ToList()).ExecuteCommand();
  30359. _ = _sqlSugar.Updateable<Grp_ApprovalTravelDetails>(chiArr.Where(x => x.id != 0).Select(x => new Grp_ApprovalTravelDetails
  30360. {
  30361. Id = x.id,
  30362. Details = x.details,
  30363. ParentId = x.parentId,
  30364. Time = x.timeInterval.Where(x => !string.IsNullOrWhiteSpace(x)).Count() > 1 ? x.timeInterval[0] + "-" + x.timeInterval[1] : "",
  30365. }).ToList()).UpdateColumns(x => new Grp_ApprovalTravelDetails
  30366. {
  30367. Details = x.Details,
  30368. ParentId = x.ParentId,
  30369. Time = x.Time
  30370. }).ExecuteCommand();
  30371. _ = _sqlSugar.Updateable<Grp_ApprovalTravel>(dto.Arr.Where(x => x.id != 0).Select(x => new Grp_ApprovalTravel
  30372. {
  30373. Id = x.id,
  30374. Date = x.date,
  30375. }).ToList()).UpdateColumns(x => new Grp_ApprovalTravel
  30376. {
  30377. Date = x.Date
  30378. }).ExecuteCommand();
  30379. _sqlSugar.CommitTran();
  30380. jw = JsonView(true, "保存成功!");
  30381. }
  30382. catch (Exception ex)
  30383. {
  30384. _sqlSugar.RollbackTran();
  30385. jw = JsonView(false, "保存失败!" + ex.Message);
  30386. }
  30387. return Ok(jw);
  30388. }
  30389. /// <summary>
  30390. /// 报批行程生成
  30391. /// </summary>
  30392. /// <param name="dto"></param>
  30393. /// <returns></returns>
  30394. [HttpPost]
  30395. public IActionResult CreateApprovalJourney(CreateApprovalJourneyDto dto)
  30396. {
  30397. var jw = JsonView(false);
  30398. var group = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  30399. if (group == null)
  30400. {
  30401. jw.Msg = "暂无该团组!";
  30402. return Ok(jw);
  30403. }
  30404. var blackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().First(x => x.Id == dto.BlackCodeId && x.IsDel == 0);
  30405. //黑屏代码数据
  30406. DataTable dtBlack = GeneralMethod.GetTableByBlackCodeBySingle(blackCode);
  30407. if (dtBlack.Rows.Count == 0 || string.IsNullOrWhiteSpace(dtBlack.Rows[0][1].ToString()))
  30408. {
  30409. jw.Msg = "黑屏代码有误!";
  30410. return Ok(jw);
  30411. }
  30412. foreach (DataRow row in dtBlack.Rows)
  30413. {
  30414. if (!string.IsNullOrWhiteSpace(row["Error"].ToString()))
  30415. {
  30416. jw.Msg = "黑屏代码有误!" + row["Error"].ToString();
  30417. return Ok(jw);
  30418. }
  30419. }
  30420. //var officialActivitiesArr = _sqlSugar.Queryable<Res_OfficialActivities>().Where(x => x.DiId == dto.Diid && x.IsDel == 0).ToList();
  30421. var resultArr = new ArrayList();
  30422. //if (officialActivitiesArr.Count == 0)
  30423. //{
  30424. // jw.Msg = "暂无公务出访信息!";
  30425. // return Ok(jw);
  30426. //}
  30427. try
  30428. {
  30429. _sqlSugar.BeginTran();
  30430. DeleteApprovalJourney(new
  30431. Domain.Dtos.Groups.DeleteApprovalJourney
  30432. {
  30433. Diid = dto.Diid,
  30434. uesrId = dto.Userid
  30435. });
  30436. var stay = "-";
  30437. var cityPath = "-";
  30438. var arriveCountry = string.Empty;
  30439. //添加城市路径以及住宿地
  30440. //黑屏代码获取时间区间
  30441. var timeArr = GeneralMethod.GetTimeListByDataTable(dtBlack);
  30442. var empty = "【未收入该三字码!请机票同事录入】";
  30443. string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  30444. #region 配置公务活动时间
  30445. List<Tuple<int, string, string>> Times = new List<Tuple<int, string, string>>();
  30446. Times.Add(new Tuple<int, string, string>(9, "9:00", "10:30"));
  30447. Times.Add(new Tuple<int, string, string>(11, "11:00", "12:00"));
  30448. Times.Add(new Tuple<int, string, string>(14, "14:00", "15:30"));
  30449. Times.Add(new Tuple<int, string, string>(16, "16:00", "17:00"));
  30450. List<Tuple<DateTime, List<string>>> fallTimesCheckCountry = new List<Tuple<DateTime, List<string>>>()
  30451. {
  30452. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,6,0,0), new List<string>{"9:00-10:30","11:00-12:00","14:00-15:30","16:00-17:00" }),
  30453. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,8,30,0), new List<string>{"11:00-12:00","14:00-15:30","16:00-17:00"}),
  30454. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,11,30,0), new List<string>{"14:00-15:30","16:00-17:00"}),
  30455. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,13,30,0), new List<string>{"16:30-17:30"}),
  30456. };
  30457. List<Tuple<DateTime, List<string>>> fallTimesNotCheckCountry = new List<Tuple<DateTime, List<string>>>()
  30458. {
  30459. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,7,0,0), new List<string>{"9:00-10:30","11:00-12:00","14:00-15:30","16:00-17:00" }),
  30460. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,9,0,0), new List<string>{"11:00-12:00","14:00-15:30","16:00-17:00"}),
  30461. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,11,30,0), new List<string>{"14:00-15:30","16:00-17:00"}),
  30462. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,14,30,0), new List<string>{"16:30-17:30"}),
  30463. };
  30464. List<Tuple<DateTime, List<string>>> takeoffTimes = new List<Tuple<DateTime, List<string>>>()
  30465. {
  30466. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,18,0,0), new List<string>{"9:00-10:30","11:00-12:00", "14:00-15:30","16:00-17:00" }),
  30467. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,15,30,0), new List<string>{"9:00-10:30", "11:00-12:00", "14:00-15:00","15:00-16:00"}),
  30468. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,14,00,0), new List<string>{"9:00-10:30", "11:00-12:00",}),
  30469. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,12,00,0), new List<string>{"09:00-10:00"}),
  30470. };
  30471. #endregion
  30472. var nextDayNum = 0;
  30473. for (int i = 0; i < timeArr.Count; i++)
  30474. {
  30475. stay = "-";
  30476. cityPath = "-";
  30477. var chiarr = new List<Grp_ApprovalTravelDetails>();
  30478. DateTime NewData = DateTime.Parse(timeArr[i]);
  30479. //var gwinfo = officialActivitiesArr.Where(x => DateTime.TryParse(x.Date, out DateTime gwData) && gwData.ToString("yyyy-MM-dd") == NewData.ToString("yyyy-MM-dd")).OrderBy(x => x.Time).ToList();
  30480. var tbSelect = dtBlack.Select(string.Format("Day = '{0}'", NewData.ToString("yyyy-MM-dd")));
  30481. if (nextDayNum > 0)
  30482. {
  30483. nextDayNum--;
  30484. }
  30485. if (tbSelect.Length > 0)
  30486. {
  30487. List<string> threeCodeStr = new List<string>();
  30488. bool isTrade = false;
  30489. string trip = string.Empty;
  30490. foreach (var item in tbSelect)
  30491. {
  30492. if (nextDayNum == 0)
  30493. {
  30494. nextDayNum = Convert.ToInt32(item["Sign"]);
  30495. }
  30496. var airStartTime = item["StartTime"].ToString() ?? "0000";
  30497. var airEndTime = item["EndTime"].ToString() ?? "0000";
  30498. var takeOffTime = DateTime.Parse(timeArr[i]);
  30499. var fallToTime = DateTime.Parse(timeArr[i]);
  30500. takeOffTime = takeOffTime.AddHours(int.Parse(airStartTime.Substring(0, 2)));
  30501. takeOffTime = takeOffTime.AddMinutes(int.Parse(airStartTime.Substring(2, 2)));
  30502. fallToTime = fallToTime.AddHours(int.Parse(airEndTime.Substring(0, 2)));
  30503. fallToTime = fallToTime.AddMinutes(int.Parse(airEndTime.Substring(2, 2)));
  30504. if (nextDayNum > 0)
  30505. {
  30506. fallToTime = fallToTime.AddDays(nextDayNum);
  30507. }
  30508. trip = string.Empty;
  30509. var start = string.Empty;
  30510. var end = string.Empty;
  30511. var threeCode = item["Three"].ToString() ?? "";
  30512. if (threeCode.Length == 6)
  30513. {
  30514. start = threeCode.Substring(0, 3);
  30515. end = threeCode.Substring(3, 3);
  30516. if (threeCodeStr.Count == 0)
  30517. {
  30518. threeCodeStr.Add(start);
  30519. threeCodeStr.Add(end);
  30520. }
  30521. else
  30522. {
  30523. if (threeCodeStr[threeCodeStr.Count - 1] == start)
  30524. {
  30525. threeCodeStr.Add(end);
  30526. }
  30527. else
  30528. {
  30529. threeCodeStr.Add(start);
  30530. threeCodeStr.Add(end);
  30531. }
  30532. }
  30533. }
  30534. //处理机票信息
  30535. var start_Object = _sqlSugar.Queryable<Res_ThreeCode>().First(x => x.Three.ToUpper() == start.ToUpper());
  30536. var end_Object = _sqlSugar.Queryable<Res_ThreeCode>().First(x => x.Three.ToUpper() == end.ToUpper());
  30537. if (start_Object == null)
  30538. {
  30539. start_Object = new Res_ThreeCode()
  30540. {
  30541. AirPort = empty,
  30542. AirPort_En = empty,
  30543. City = empty,
  30544. Country = empty,
  30545. Four = empty,
  30546. Three = empty,
  30547. };
  30548. }
  30549. if (end_Object == null)
  30550. {
  30551. end_Object = new Res_ThreeCode()
  30552. {
  30553. AirPort = empty,
  30554. AirPort_En = empty,
  30555. City = empty,
  30556. Country = empty,
  30557. Four = empty,
  30558. Three = empty,
  30559. };
  30560. }
  30561. //机型判断
  30562. string airModel = item["AirModel"].ToString();
  30563. airModel = GeneralMethod.GetLonger(airModel!.Substring(0, 1)) + airModel;
  30564. string flightTime = item["FlightTime"].ToString();
  30565. flightTime = ParseBlackTime(flightTime);
  30566. //航班号
  30567. string flightcode = item["Fliagtcode"].ToString();
  30568. var aircompany = _sqlSugar.Queryable<Res_AirCompany>().First(x => x.ShortCode.ToUpper() == flightcode!.Substring(0, 2).ToUpper() && x.IsDel == 0);
  30569. var hsEmpty = "【此航司" + flightcode!.Substring(0, 2).ToUpper() + "未收录,请机票同事录入】";
  30570. if (aircompany == null)
  30571. {
  30572. aircompany = new Res_AirCompany
  30573. {
  30574. CnName = hsEmpty,
  30575. EnName = hsEmpty,
  30576. ShortCode = hsEmpty,
  30577. };
  30578. }
  30579. //航班前公务安排
  30580. if (tbSelect.First().Equals(item) && i != 0)
  30581. {
  30582. foreach (var takeoff in takeoffTimes)
  30583. {
  30584. var takeoffItem1 = NewData.AddHours(takeoff.Item1.Hour).AddMinutes(takeoff.Item1.Minute);
  30585. if (DateTime.Compare(takeOffTime, takeoffItem1) > 0)
  30586. {
  30587. foreach (var addTime in takeoff.Item2)
  30588. {
  30589. chiarr.Add(new Grp_ApprovalTravelDetails
  30590. {
  30591. Time = addTime,
  30592. CreateTime = DateTime.Now,
  30593. CreateUserId = dto.Userid,
  30594. ParentId = 0,
  30595. Details = "公务活动"
  30596. });
  30597. }
  30598. break;
  30599. }
  30600. }
  30601. }
  30602. //从成都天府国际机场搭乘四川航空公司3U3961飞往东京
  30603. //trip += $"从{start_Object.AirPort}搭乘{aircompany.CnName}{flightcode}飞往{end_Object.City}。\r\n({start_Object.AirPort}/{end_Object.AirPort} 机型:{airModel} 飞行时间{flightTime});\r\n";
  30604. //乘坐四川航空3U3901次航班由成都飞往加德满都,3小时25分钟
  30605. trip += $"乘坐{aircompany.CnName}{flightcode}次航班由{start_Object.City}飞往{end_Object.City},{flightTime}";
  30606. isTrade = Convert.ToBoolean(item["isTransitShipment"]);
  30607. if (isTrade)
  30608. {
  30609. //trip += $"抵达{end_Object.AirPort}{item["EndBuilding"].ToString().Trim()}航站楼(中转 行李直达)\r\n";
  30610. trip += "(转机不出机场)。";
  30611. }
  30612. //else
  30613. //{
  30614. // trip += "\r\n"; //$"抵达{end_Object.AirPort}{item["EndBuilding"].ToString().Trim()}航站楼,办理入境手续,之后前往提取行李\r\n";
  30615. //}
  30616. chiarr.Add(new Grp_ApprovalTravelDetails
  30617. {
  30618. Time = takeOffTime.ToString("HH:mm") + "-" + fallToTime.ToString("HH:mm"),
  30619. CreateTime = DateTime.Now,
  30620. CreateUserId = dto.Userid,
  30621. ParentId = 0,
  30622. Details = trip
  30623. });
  30624. //最后一条到达的时间安排公务
  30625. if (tbSelect.Last().Equals(item) && i != timeArr.Count - 1)
  30626. {
  30627. bool isCheckCountry = false;
  30628. if (end_Object.Country != arriveCountry)
  30629. {
  30630. arriveCountry = end_Object.Country;
  30631. isCheckCountry = true;
  30632. }
  30633. if (nextDayNum == 0)
  30634. {
  30635. //需要入境的情况
  30636. if (isCheckCountry)
  30637. {
  30638. foreach (var fallTime in fallTimesCheckCountry)
  30639. {
  30640. var fallTimeItem1 = NewData.AddHours(fallTime.Item1.Hour).AddMinutes(fallTime.Item1.Minute);
  30641. if (DateTime.Compare(fallToTime, fallTimeItem1) < 0)
  30642. {
  30643. foreach (var addTime in fallTime.Item2)
  30644. {
  30645. chiarr.Add(new Grp_ApprovalTravelDetails
  30646. {
  30647. Time = addTime,
  30648. CreateTime = DateTime.Now,
  30649. CreateUserId = dto.Userid,
  30650. ParentId = 0,
  30651. Details = "公务活动"
  30652. });
  30653. }
  30654. break;
  30655. }
  30656. }
  30657. }
  30658. else
  30659. {
  30660. foreach (var fallTime in fallTimesNotCheckCountry)
  30661. {
  30662. var fallTimeItem1 = NewData.AddHours(fallTime.Item1.Hour).AddMinutes(fallTime.Item1.Minute);
  30663. if (DateTime.Compare(fallToTime, fallTimeItem1) < 0)
  30664. {
  30665. foreach (var addTime in fallTime.Item2)
  30666. {
  30667. chiarr.Add(new Grp_ApprovalTravelDetails
  30668. {
  30669. Time = addTime,
  30670. CreateTime = DateTime.Now,
  30671. CreateUserId = dto.Userid,
  30672. ParentId = 0,
  30673. Details = "公务活动"
  30674. });
  30675. }
  30676. break;
  30677. }
  30678. }
  30679. }
  30680. }
  30681. }
  30682. }
  30683. //添加乘车语句
  30684. //chiarr.Add(new Grp_ApprovalTravelDetails
  30685. //{
  30686. // Time = (fallToTime.AddHours(2.5).ToString("HH:mm") + "-" + fallToTime.AddHours(3).ToString("HH:mm")),
  30687. // CreateTime = DateTime.Now,
  30688. // CreateUserId = dto.Userid,
  30689. // ParentId = 0,
  30690. // Details = "乘车前往市区(约xx公里,大约需要xx分钟)"
  30691. //});
  30692. //if (i != timeArr.Count - 1)
  30693. //{
  30694. // fallToTime = fallToTime.AddHours(2.5);
  30695. // foreach (var item in Times)
  30696. // {
  30697. // //排列公务时间
  30698. // if (fallToTime.Hour < item.Item1)
  30699. // {
  30700. // chiarr.Add(new Grp_ApprovalTravelDetails
  30701. // {
  30702. // Time = $"{item.Item2} - {item.Item3}",
  30703. // CreateTime = DateTime.Now,
  30704. // CreateUserId = dto.Userid,
  30705. // ParentId = 0,
  30706. // Details = "公务活动"
  30707. // });
  30708. // }
  30709. // }
  30710. //}
  30711. var threeCodeList = _threeCodeRepository.QueryThreeCodeArray(threeCodeStr);
  30712. var last = threeCodeStr.Last();
  30713. foreach (var item in threeCodeStr)
  30714. {
  30715. cityPath += (threeCodeList.Keys.Contains(item) ? threeCodeList[item].City : "【未知三字码】") + "-";
  30716. if (item.Equals(last))
  30717. {
  30718. stay = threeCodeList.Keys.Contains(item) ? threeCodeList[item].City : "【未知三字码】";
  30719. }
  30720. }
  30721. cityPath = cityPath.Trim('-');
  30722. }
  30723. else
  30724. {
  30725. foreach (var item in Times)
  30726. {
  30727. chiarr.Add(new Grp_ApprovalTravelDetails
  30728. {
  30729. Time = $"{item.Item2} - {item.Item3}",
  30730. CreateTime = DateTime.Now,
  30731. CreateUserId = dto.Userid,
  30732. ParentId = 0,
  30733. Details = "公务活动"
  30734. });
  30735. }
  30736. }
  30737. string week = Day[Convert.ToInt32(NewData.DayOfWeek.ToString("d"))].ToString();
  30738. Grp_ApprovalTravel appro = new Grp_ApprovalTravel();
  30739. appro.Date = NewData.Month + "月" + NewData.Day + "日(" + week + ")" + "第" + intToString(i + 1) + "天 ";
  30740. appro.Diid = dto.Diid;
  30741. appro.CreateUserId = dto.Userid;
  30742. appro.CreateTime = DateTime.Now;
  30743. var thisId = _sqlSugar.Insertable<Grp_ApprovalTravel>(appro).ExecuteReturnIdentity();
  30744. appro.Id = thisId;
  30745. //foreach (var item in gwinfo)
  30746. //{
  30747. // Grp_ApprovalTravelDetails chi = new Grp_ApprovalTravelDetails();
  30748. // chi.Details = "拜访" + item.Client;
  30749. // if (!string.IsNullOrWhiteSpace(item.ReqSample))
  30750. // {
  30751. // chi.Details += "," + item.ReqSample;
  30752. // }
  30753. // chi.ParentId = thisId;
  30754. // chi.Time = item.Time;
  30755. // chiarr.Add(chi);
  30756. //}
  30757. if (chiarr.Count < 6)
  30758. {
  30759. for (int j = chiarr.Count; j < 6; j++)
  30760. {
  30761. chiarr.Add(new
  30762. Grp_ApprovalTravelDetails());
  30763. }
  30764. }
  30765. resultArr.Add(new
  30766. {
  30767. appro.Id,
  30768. appro.Date,
  30769. appro.Diid,
  30770. chiList = chiarr.Select(x1 => new
  30771. {
  30772. timeInterval = string.IsNullOrWhiteSpace(x1.Time) ? new string[1] : x1.Time.Split('-'),
  30773. x1.Details,
  30774. x1.ParentId,
  30775. x1.Id
  30776. })
  30777. });
  30778. }
  30779. _sqlSugar.CommitTran();
  30780. jw = JsonView(true, "生成成功!", resultArr);
  30781. }
  30782. catch (Exception ex)
  30783. {
  30784. jw.Code = 400;
  30785. jw.Msg = "生成失败!" + ex.Message;
  30786. }
  30787. return Ok(jw);
  30788. }
  30789. /// <summary>
  30790. /// 报批行程word导出
  30791. /// </summary>
  30792. /// <param name="dto"></param>
  30793. /// <returns></returns>
  30794. [HttpPost]
  30795. public IActionResult ExportApprovalJourneyWord(ExportApprovalJourneyWord dto)
  30796. {
  30797. var jw = JsonView(false);
  30798. var group = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  30799. if (group == null)
  30800. {
  30801. jw.Msg = "暂无该团组!";
  30802. return Ok(jw);
  30803. }
  30804. //模板路径
  30805. string tempPath = AppSettingsHelper.Get("WordBasePath") + "Template/";
  30806. var fileName = string.Empty;
  30807. string titleFont = string.Empty, timeFont = string.Empty, contentFont = string.Empty;
  30808. bool bold = false;
  30809. if (dto.FileIndex == 1)
  30810. {
  30811. fileName = "公务行程导出模板.docx"; //"C:\\Server\\File\\OA2023\\Office\\Word\\Template/公务行程导出模板.docx"
  30812. }
  30813. else if (dto.FileIndex == 2)
  30814. {
  30815. fileName = "省外办-报批.docx";
  30816. bold = false;
  30817. titleFont = "方正黑体简体";
  30818. timeFont = "Times New Roman";
  30819. contentFont = "方正仿宋_GBK";
  30820. }
  30821. else if (dto.FileIndex == 3)
  30822. {
  30823. fileName = "市外办-报批.docx";
  30824. titleFont = "方正黑体简体";
  30825. timeFont = "Times New Roman";
  30826. contentFont = "方正仿宋简体";
  30827. }
  30828. tempPath = tempPath + fileName;
  30829. //载入模板
  30830. Document doc = new Document(tempPath);
  30831. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  30832. //获取所填表格的序数
  30833. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  30834. Aspose.Words.Tables.Row titleRowClone = null;
  30835. Aspose.Words.Tables.Row CenterRowClone = null;
  30836. int index = 0;
  30837. int indexChi = 0;
  30838. int SetIndex = 0;
  30839. var ApprovalTravelArr = _sqlSugar.Queryable<Grp_ApprovalTravel>().Where(x => x.IsDel == 0 && x.Diid == dto.Diid).ToList();
  30840. //获取数据,放到datatable
  30841. foreach (var item in ApprovalTravelArr)
  30842. {
  30843. if (index > 0)
  30844. {
  30845. titleRowClone = (Aspose.Words.Tables.Row)tableOne.Rows[0].Clone(true);
  30846. tableOne.AppendChild(titleRowClone);
  30847. }
  30848. var textTime = item.Date;
  30849. var ChiRep = _sqlSugar.Queryable<Grp_ApprovalTravelDetails>().Where(x => x.IsDel == 0 && x.ParentId == item.Id).ToList();
  30850. SetCells(tableOne, doc, SetIndex, 0, textTime, titleFont, bold);
  30851. SetIndex++;
  30852. if (ChiRep.Count > 0)
  30853. {
  30854. foreach (var itemChi in ChiRep)
  30855. {
  30856. var txtTime = itemChi.Time;
  30857. var txtDetail = itemChi.Details;
  30858. if (string.IsNullOrEmpty(txtTime) && string.IsNullOrEmpty(txtDetail))
  30859. {
  30860. //SetCells(tableOne, doc, SetIndex, 0, "", timeFont, bold);
  30861. //SetCells(tableOne, doc, SetIndex, 1, "", contentFont, bold);
  30862. //indexChi++;
  30863. //SetIndex++;
  30864. break;
  30865. }
  30866. if (indexChi > 0)
  30867. {
  30868. CenterRowClone = (Aspose.Words.Tables.Row)tableOne.Rows[1].Clone(true);
  30869. tableOne.AppendChild(CenterRowClone);
  30870. }
  30871. SetCells(tableOne, doc, SetIndex, 0, txtTime, timeFont, bold);
  30872. SetCells(tableOne, doc, SetIndex, 1, txtDetail, contentFont, bold);
  30873. indexChi++;
  30874. SetIndex++;
  30875. }
  30876. }
  30877. //else
  30878. //{
  30879. // if (indexChi > 0)
  30880. // {
  30881. // CenterRowClone = (Aspose.Words.Tables.Row)tableOne.Rows[1].Clone(true);
  30882. // tableOne.AppendChild(CenterRowClone);
  30883. // }
  30884. // SetCells(tableOne, doc, SetIndex, 0, "",timeFont, bold);
  30885. // SetCells(tableOne, doc, SetIndex, 1, "", contentFont, bold);
  30886. // indexChi++;
  30887. // SetIndex++;
  30888. //}
  30889. index++;
  30890. }
  30891. string strFileName = "/Travel/ExportApprovalJourneyWord/" + group.TeamName + fileName;
  30892. doc.Save(AppSettingsHelper.Get("WordBasePath") + strFileName, Aspose.Words.SaveFormat.Docx); //"C:\\Server\\File\\OA2023\\Office\\Word" + strFileName
  30893. jw.Data = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + strFileName; //"C:\\Server\\File\\OA2023\\Office\\Word" + strFileName
  30894. jw.Code = 200;
  30895. jw.Msg = "";
  30896. return Ok(jw);
  30897. }
  30898. private string ParseBlackTime(string time)
  30899. {
  30900. // 匹配可能只有分钟的情况
  30901. string pattern = @"(?:(\d+)H)?(?:(\d+)M)?";
  30902. System.Text.RegularExpressions.Match match = Regex.Match(time, pattern);
  30903. if (match.Success)
  30904. {
  30905. string hours = match.Groups[1].Value;
  30906. string minutes = match.Groups[2].Value;
  30907. // 如果小时部分为空,则只显示分钟
  30908. if (string.IsNullOrEmpty(hours))
  30909. {
  30910. return $"{minutes}分钟";
  30911. }
  30912. // 如果分钟部分为空,则只显示小时
  30913. else if (string.IsNullOrEmpty(minutes))
  30914. {
  30915. return $"{hours}小时";
  30916. }
  30917. // 否则显示完整格式
  30918. else
  30919. {
  30920. return $"{hours}小时{minutes}分钟";
  30921. }
  30922. }
  30923. else
  30924. {
  30925. return "未知时长";
  30926. }
  30927. }
  30928. private string intToString(int numberVal)
  30929. {
  30930. string numberval = numberVal.ToString();
  30931. Dictionary<char, string> Number = new Dictionary<char, string>();
  30932. Number.Add('1', "一");
  30933. Number.Add('2', "二");
  30934. Number.Add('3', "三");
  30935. Number.Add('4', "四");
  30936. Number.Add('5', "五");
  30937. Number.Add('6', "六");
  30938. Number.Add('7', "七");
  30939. Number.Add('8', "八");
  30940. Number.Add('9', "九");
  30941. string stringNumberVal = string.Empty;
  30942. for (int i = 0; i < numberval.Length; i++)
  30943. {
  30944. if (i == 0)
  30945. {
  30946. stringNumberVal += Number[numberval[i]];
  30947. }
  30948. else if (i >= 1)
  30949. {
  30950. if (numberval[i] == '0')
  30951. {
  30952. stringNumberVal = "十";
  30953. }
  30954. else
  30955. {
  30956. stringNumberVal += "十" + Number[numberval[i]];
  30957. }
  30958. }
  30959. }
  30960. return stringNumberVal;
  30961. }
  30962. private void SetCells(Aspose.Words.Tables.Table table, Document doc, int rows, int cells, string val, string font, bool bold)
  30963. {
  30964. //获取table中的某个单元格,从0开始
  30965. Cell lshCell = table.Rows[rows].Cells[cells];
  30966. //将单元格中段落移除
  30967. foreach (Paragraph item in lshCell.Paragraphs)
  30968. {
  30969. lshCell.Paragraphs.Remove(item);
  30970. }
  30971. if (val.Contains("\r\n"))
  30972. {
  30973. var spArr = val.Split("\r\n").Where(x => !string.IsNullOrWhiteSpace(x));
  30974. foreach (var item in spArr)
  30975. {
  30976. //新建一个段落
  30977. Paragraph p = new Paragraph(doc);
  30978. var r = new Run(doc, item);
  30979. //设置字体
  30980. if (!string.IsNullOrEmpty(font))
  30981. {
  30982. r.Font.Name = font;
  30983. }
  30984. r.Font.Bold = bold;
  30985. //把设置的值赋给之前新建的段落
  30986. p.AppendChild(r);
  30987. //将此段落加到单元格内
  30988. lshCell.AppendChild(p);
  30989. }
  30990. }
  30991. else
  30992. {
  30993. //新建一个段落
  30994. Paragraph p = new Paragraph(doc);
  30995. var r = new Run(doc, val);
  30996. //设置字体
  30997. if (!string.IsNullOrEmpty(font))
  30998. {
  30999. r.Font.Name = font;
  31000. }
  31001. r.Font.Bold = bold;
  31002. //把设置的值赋给之前新建的段落
  31003. p.AppendChild(r);
  31004. //将此段落加到单元格内
  31005. lshCell.AppendChild(p);
  31006. }
  31007. }
  31008. /// <summary>
  31009. /// 报批行程AI续写
  31010. /// </summary>
  31011. /// <returns></returns>
  31012. [HttpPost]
  31013. public async Task<IActionResult> ApprovalJourneyAiWrite(ApprovalJourneyAiWriteDto dto)
  31014. {
  31015. var jw = JsonView(false);
  31016. if (dto.ClientPurpose.IsNullOrWhiteSpace() || dto.ClientName.IsNullOrWhiteSpace())
  31017. {
  31018. jw.Msg = "参数有误!";
  31019. return Ok(jw);
  31020. }
  31021. KiMiApiClient kiMi = new KiMiApiClient();
  31022. List<SeedMessages> messages = new List<SeedMessages>() {
  31023. new SeedMessages
  31024. {
  31025. Role = KimiRole.system,
  31026. Content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。"
  31027. },
  31028. new SeedMessages
  31029. {
  31030. Role = KimiRole.user,
  31031. Content = $@"参考这个模板格式来编写一份{dto.ClientName}拜访{dto.ClientPurpose},结合{dto.ClientName}的业务,描述拜访目的,字数在200字内(直接给出拜访目的,不输出其他内容)"
  31032. }
  31033. };
  31034. var kimi_result = await kiMi.SeedMessageByFullConterObject(messages);
  31035. string data = kimi_result.Choices[0]?.Message.Content;
  31036. if (string.IsNullOrWhiteSpace(data))
  31037. {
  31038. jw.Data = "Ai续写失败!";
  31039. }
  31040. else
  31041. {
  31042. jw = JsonView(true, "success!", data);
  31043. }
  31044. return Ok(jw);
  31045. }
  31046. #endregion
  31047. #region 团组接待意见调查
  31048. /// <summary>
  31049. /// 团组接待意见调查 - 信息管理
  31050. /// 基础数据(团组)
  31051. /// </summary>
  31052. /// <returns></returns>
  31053. [HttpGet]
  31054. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31055. public async Task<IActionResult> OpinionaireInit()
  31056. {
  31057. var groupData = await _groupRepository.Query(x => x.IsDel == 0)
  31058. .Select(x => new
  31059. {
  31060. x.Id,
  31061. GroupName = $"[{x.VisitDate.ToString("yyyy-MM-dd")}]{x.TeamName}"
  31062. })
  31063. .OrderByDescending(x => x.Id)
  31064. .ToListAsync();
  31065. return Ok(JsonView(groupData, groupData.Count));
  31066. }
  31067. /// <summary>
  31068. /// 团组接待意见调查 - 信息管理
  31069. /// 列表
  31070. /// </summary>
  31071. /// <param name="groupId"></param>
  31072. /// <returns></returns>
  31073. [HttpGet("{groupId}")]
  31074. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31075. public async Task<IActionResult> OpinionaireManageList(int groupId)
  31076. {
  31077. if (groupId < 1) Ok(JsonView(false, "请传入有效的diId"));
  31078. var data = await _opinionaireRep.Query(x => x.DiId == groupId)
  31079. .Select(x => new
  31080. {
  31081. x.Id,
  31082. x.TourGuideName,
  31083. x.CityName,
  31084. CreateUserName = SqlFunc.Subqueryable<Sys_Users>().Where(x1 => x.CreateUserId == x1.Id).Select(x1 => x1.CnName),
  31085. x.CreateTime
  31086. })
  31087. .OrderBy(x => x.Id)
  31088. .ToListAsync();
  31089. return Ok(JsonView(data));
  31090. }
  31091. /// <summary>
  31092. /// 团组接待意见调查 - 信息管理
  31093. /// 保存
  31094. /// </summary>
  31095. /// <param name="dto"></param>
  31096. /// <returns></returns>
  31097. [HttpPost]
  31098. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31099. public async Task<IActionResult> OpinionaireManageSave(OpinionaireManageSaveDto dto)
  31100. {
  31101. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  31102. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  31103. if (dto.DiId < 1) Ok(JsonView(false, "请传入有效的diId"));
  31104. if (dto.Items.Length < 1) Ok(JsonView(false, "请传入需要保存的信息"));
  31105. var addData = _mapper.Map<List<Grp_Opinionaire>>(dto.Items.Where(x => x.Id == 0).ToList());
  31106. var updData = _mapper.Map<List<Grp_Opinionaire>>(dto.Items.Where(x => x.Id > 0).ToList());
  31107. _opinionaireRep.BeginTran();
  31108. if (addData != null && addData.Count > 0)
  31109. {
  31110. foreach (var item in addData)
  31111. {
  31112. item.CreateUserId = currUserInfo.UserId;
  31113. item.DiId = dto.DiId;
  31114. }
  31115. var add = await _opinionaireRep._sqlSugar.Insertable(addData).ExecuteCommandAsync();
  31116. }
  31117. if (updData != null && updData.Count > 0)
  31118. {
  31119. var upd = await _opinionaireRep._sqlSugar
  31120. .Updateable(updData)
  31121. .UpdateColumns(x => new { x.CityName, x.TourGuideName })
  31122. .WhereColumns(x => new { x.Id })
  31123. .ExecuteCommandAsync();
  31124. }
  31125. _opinionaireRep.CommitTran();
  31126. return Ok(JsonView("操作成功!"));
  31127. }
  31128. /// <summary>
  31129. /// 团组接待意见调查 - 信息管理
  31130. /// 删除
  31131. /// </summary>
  31132. /// <param name="id"></param>
  31133. /// <returns></returns>
  31134. [HttpDelete("{id}")]
  31135. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31136. public async Task<IActionResult> OpinionaireManageDel(int id)
  31137. {
  31138. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  31139. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  31140. if (id < 1) Ok(JsonView(false, "请传入有效的id"));
  31141. var del = await _opinionaireRep.SoftDeleteAsync(x => x.Id == id, currUserInfo.UserId);
  31142. if (!del) return Ok(JsonView("操作失败!"));
  31143. return Ok(JsonView("操作成功!"));
  31144. }
  31145. /// <summary>
  31146. /// 团组接待意见调查 - 用户
  31147. /// 列表
  31148. /// </summary>
  31149. /// <param name="diId"></param>
  31150. /// <returns></returns>
  31151. [HttpGet("{diId}")]
  31152. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31153. public async Task<IActionResult> OpinionaireUserList(int diId)
  31154. {
  31155. if (diId < 1) Ok(JsonView(false, "请传入有效的diId"));
  31156. var sql = string.Format(@"
  31157. SELECT
  31158. o.Id,
  31159. o.DiId,
  31160. di.TeamName AS 'GroupName',
  31161. di.VisitPNumber AS 'PeopleNumber',
  31162. di.ClientName AS 'LeadGroup',
  31163. di.VisitCountry AS 'Travel',
  31164. di.VisitDays AS 'Days',
  31165. o.CityName,
  31166. o.TourGuideName,
  31167. o.Catering,
  31168. o.CateringReason,
  31169. o.Stay,
  31170. o.StayReason,
  31171. o.[Route],
  31172. o.RouteReason,
  31173. o.OfficialActivity,
  31174. o.OfficialActivityReason,
  31175. o.TourGuide,
  31176. o.TourGuideReason,
  31177. o.[Translate],
  31178. o.TranslateReason,
  31179. o.Trip,
  31180. o.TripReason,
  31181. o.ESFileName,
  31182. o.SignatureDate,
  31183. o.Remark
  31184. FROM
  31185. Grp_Opinionaire o
  31186. LEFT JOIN Grp_DelegationInfo di ON o.DiId = di.Id
  31187. WHERE
  31188. o.IsDel = 0
  31189. AND o.DiId = {0}
  31190. ORDER BY
  31191. o.Id ASC", diId);
  31192. var data = await _sqlSugar.SqlQueryable<OpinionaireUserListView>(sql).ToListAsync();
  31193. if (data.Count < 1) return Ok(JsonView(false, "暂无数据"));
  31194. return Ok(JsonView(data));
  31195. }
  31196. /// <summary>
  31197. /// 团组接待意见调查 - 用户
  31198. /// 保存
  31199. /// </summary>
  31200. /// <param name="dto"></param>
  31201. /// <returns></returns>
  31202. [HttpPost]
  31203. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31204. public async Task<IActionResult> OpinionaireUserSave([FromForm] OpinionaireUserSaveInfo[] dto)
  31205. {
  31206. if (dto.Length < 1) Ok(JsonView(false, "请传入有效的参数"));
  31207. foreach (var item in dto)
  31208. {
  31209. if (string.IsNullOrEmpty(item.Catering)) Ok(JsonView(false, "请选择餐饮评分!"));
  31210. if (string.IsNullOrEmpty(item.Stay)) Ok(JsonView(false, "请选择住宿评分!"));
  31211. if (string.IsNullOrEmpty(item.Route)) Ok(JsonView(false, "请选择行程评分!"));
  31212. if (string.IsNullOrEmpty(item.OfficialActivity)) Ok(JsonView(false, "请选择公务活动评分!"));
  31213. if (string.IsNullOrEmpty(item.Translate)) Ok(JsonView(false, "请选择翻译评分!"));
  31214. if (string.IsNullOrEmpty(item.Trip)) Ok(JsonView(false, "请选择行程评分!"));
  31215. if (string.IsNullOrEmpty(item.SignatureDate)) Ok(JsonView(false, "请填写签名日期!"));
  31216. if (item.File.Length < 1) Ok(JsonView(false, "请上传签名图片!"));
  31217. }
  31218. var filePathBase = $"{AppSettingsHelper.Get("GrpFileBasePath")}OpinionaireElectronicSignature";
  31219. if (!Directory.Exists(filePathBase))
  31220. {
  31221. Directory.CreateDirectory(filePathBase);
  31222. }
  31223. #region 上传文件
  31224. var filePaths = new List<string>();
  31225. foreach (var item in dto)
  31226. {
  31227. var file = item.File;
  31228. // 将文件保存到指定位置
  31229. var filePath = Path.Combine(filePathBase, file.FileName);
  31230. using (var stream = new FileStream(filePath, FileMode.Create))
  31231. {
  31232. await file.CopyToAsync(stream);
  31233. }
  31234. //验证文件是否上传成功
  31235. if (!System.IO.File.Exists(filePath))
  31236. {
  31237. foreach (var filePathStr in filePaths)
  31238. {
  31239. System.IO.File.Delete(filePathStr);
  31240. }
  31241. return Ok(JsonView(false, "文件上传失败!"));
  31242. }
  31243. item.ESFileName = file.FileName;
  31244. }
  31245. #endregion
  31246. var infos = _mapper.Map<List<Grp_Opinionaire>>(dto);
  31247. var upd = await _sqlSugar.Updateable<Grp_Opinionaire>(infos)
  31248. .UpdateColumns(x => new
  31249. {
  31250. x.Catering,
  31251. x.CateringReason,
  31252. x.Stay,
  31253. x.StayReason,
  31254. x.Route,
  31255. x.RouteReason,
  31256. x.OfficialActivity,
  31257. x.OfficialActivityReason,
  31258. x.TourGuide,
  31259. x.TourGuideReason,
  31260. x.Translate,
  31261. x.TranslateReason,
  31262. x.Trip,
  31263. x.TripReason,
  31264. x.ESFileName,
  31265. x.SignatureDate,
  31266. x.Remark
  31267. })
  31268. .WhereColumns(x => new { x.Id })
  31269. .ExecuteCommandAsync();
  31270. if (upd < 1)
  31271. {
  31272. foreach (var filePathStr in filePaths)
  31273. {
  31274. System.IO.File.Delete(filePathStr);
  31275. }
  31276. return Ok(JsonView(false));
  31277. }
  31278. return Ok(JsonView(true));
  31279. }
  31280. #endregion
  31281. #region 团组餐厅相关信息
  31282. /// <summary>
  31283. /// 团组相关餐厅信息
  31284. /// 基础数据(团组)
  31285. /// </summary>
  31286. /// <returns></returns>
  31287. [HttpGet]
  31288. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31289. public async Task<IActionResult> RestaurantInit()
  31290. {
  31291. return Ok(await _restaurantRep.InitAsync());
  31292. }
  31293. /// <summary>
  31294. /// 团组相关餐厅信息
  31295. /// Item
  31296. /// </summary>
  31297. /// <param name="dto"></param>
  31298. /// <returns></returns>
  31299. [HttpPost]
  31300. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31301. public async Task<IActionResult> RestaurantItem(RestaurantItemDto dto)
  31302. {
  31303. int portType = dto.PortType,
  31304. groupId = dto.GroupId;
  31305. if (!SharingStaticData.PortTypes.Contains(portType)) return Ok(JsonView(false, MsgTips.Port));
  31306. if (groupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  31307. return Ok(await _restaurantRep.ItemAsync(portType, groupId));
  31308. }
  31309. /// <summary>
  31310. /// 团组相关餐厅信息
  31311. /// List
  31312. /// </summary>
  31313. /// <param name="dto"></param>
  31314. /// <returns></returns>
  31315. [HttpPost]
  31316. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31317. public async Task<IActionResult> RestaurantList(RestaurantItemDto dto)
  31318. {
  31319. int portType = dto.PortType,
  31320. groupId = dto.GroupId;
  31321. if (!SharingStaticData.PortTypes.Contains(portType)) return Ok(JsonView(false, MsgTips.Port));
  31322. if (groupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  31323. var sql = string.Format(@" SELECT
  31324. ri.Id,
  31325. ri.GroupId,
  31326. ri.Date,
  31327. ri.StartTime,
  31328. ri.EndTime,
  31329. CASE WHEN ri.Type = 1 THEN '早餐'
  31330. WHEN ri.Type = 2 THEN '午餐'
  31331. WHEN ri.Type = 3 THEN '晚餐'
  31332. ELSE '其他'
  31333. END AS 'Type',
  31334. ri.Name,
  31335. ri.Address,
  31336. ri.Tel,
  31337. ri.Remark,
  31338. ri.CreateTime,
  31339. u.CnName AS CreateUserName
  31340. FROM
  31341. Grp_RestaurantInfo ri
  31342. LEFT JOIN Sys_Users u ON ri.CreateUserId = u.Id
  31343. WHERE
  31344. ri.IsDel = 0
  31345. AND ri.GroupId = {0}
  31346. ORDER BY
  31347. ri.Date ASC
  31348. ", groupId);
  31349. var infos = await _sqlSugar.SqlQueryable<RestaurantItemView>(sql).ToListAsync();
  31350. if (!infos.Any()) Ok(JsonView(false, "数据未填写!"));
  31351. return Ok(JsonView(infos));
  31352. }
  31353. /// <summary>
  31354. /// 团组相关餐厅信息
  31355. /// Info
  31356. /// </summary>
  31357. /// <param name="dto"></param>
  31358. /// <returns></returns>
  31359. [HttpPost]
  31360. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31361. public async Task<IActionResult> RestaurantInfo(RestaurantInfoDto dto)
  31362. {
  31363. int portType = dto.PortType,
  31364. id = dto.Id;
  31365. if (!SharingStaticData.PortTypes.Contains(portType)) return Ok(JsonView(false, MsgTips.Port));
  31366. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  31367. return Ok(await _restaurantRep.InfoAsync(portType, id));
  31368. }
  31369. /// <summary>
  31370. /// 团组相关餐厅信息
  31371. /// Op
  31372. /// </summary>
  31373. /// <param name="dto"></param>
  31374. /// <returns></returns>
  31375. [HttpPost]
  31376. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31377. public async Task<IActionResult> RestaurantOp(RestaurantOpDto dto)
  31378. {
  31379. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  31380. if (dto.GroupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  31381. if (string.IsNullOrEmpty(dto.Name)) return Ok(JsonView(false, "餐厅名称为空!"));
  31382. return Ok(await _restaurantRep.OpAsync(dto));
  31383. }
  31384. /// <summary>
  31385. /// 团组相关餐厅信息
  31386. /// Del
  31387. /// </summary>
  31388. /// <param name="dto"></param>
  31389. /// <returns></returns>
  31390. [HttpPost]
  31391. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31392. public async Task<IActionResult> RestaurantDel(RestaurantDelDto dto)
  31393. {
  31394. int userId = dto.DeleteUserId;
  31395. var id = dto.Id;
  31396. if (userId < 1) return Ok(JsonView(false, MsgTips.UserId));
  31397. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  31398. return Ok(await _restaurantRep.DelAsync(dto));
  31399. }
  31400. #endregion
  31401. #region 团组会务成本
  31402. ///读取excel数据
  31403. /// </summary>
  31404. /// <returns></returns>
  31405. [HttpPost]
  31406. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31407. public async Task<IActionResult> MaterialCostsReadExcel(MaterialCostsReadExcelDto dto)
  31408. {
  31409. var file = dto.File;
  31410. var rowIndex = dto.RowIndex;
  31411. var userId = dto.UserId;
  31412. var groupId = dto.GroupId;
  31413. var conferenceAffairsCostId = dto.ConferenceAffairsCostId;
  31414. if (file == null || file.Length == 0)
  31415. {
  31416. return Ok(JsonView(false, "请选择文件"));
  31417. }
  31418. var conferenceAffairsCost = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
  31419. .First(x => x.Id == conferenceAffairsCostId && x.IsDel == 0);
  31420. if (conferenceAffairsCost == null)
  31421. {
  31422. return Ok(JsonView(false, "ConferenceAffairsCostId 参数有误!"));
  31423. }
  31424. var workbook = new Workbook(file.OpenReadStream());
  31425. var worksheet = workbook.Worksheets[0];
  31426. var rowCount = worksheet.Cells.MaxDataRow + 1;
  31427. var colCount = worksheet.Cells.MaxDataColumn + 1;
  31428. var setDatas = await _sqlSugar.Queryable<Sys_SetData>()
  31429. .Where(x => x.IsDel == 0 && (x.STid == 21 || x.STid == 119))
  31430. .Select(x => new { x.Id, x.Name, x.STid })
  31431. .ToListAsync();
  31432. var typeItems = setDatas.Where(x => x.STid == 21).ToList();
  31433. var unitItems = setDatas.Where(x => x.STid == 119).ToList();
  31434. // 预处理为字典,提高查找效率
  31435. var typeDict = typeItems.GroupBy(x => x.Name).ToDictionary(g => g.Key, g => g.First().Id);
  31436. var unitDict = unitItems.GroupBy(x => x.Name).ToDictionary(g => g.Key, g => g.First().Id);
  31437. List<Grp_ConferenceAffairsCostChild> data = new List<Grp_ConferenceAffairsCostChild>();
  31438. for (int i = rowIndex; i < rowCount; i++)
  31439. {
  31440. var sotr = int.TryParse(worksheet.Cells[i, 0].Value.toString(), out int index) ? index : 0;
  31441. var typeName = worksheet.Cells[i, 1].Value.toString();
  31442. var itemName = worksheet.Cells[i, 2].Value.toString();
  31443. var count = int.TryParse(worksheet.Cells[i, 3].Value.toString(), out int countInt) ? countInt : 0;
  31444. var unitName = worksheet.Cells[i, 4].Value.toString();
  31445. var baoJiaPrice = decimal.TryParse(worksheet.Cells[i, 5].Value.toString(), out decimal priceDecimal) ? priceDecimal : 0;
  31446. var baoJiaAllPrice = decimal.TryParse(worksheet.Cells[i, 6].Value.toString(), out decimal allPriceDecimal) ? allPriceDecimal : 0;
  31447. var costPriceAll = decimal.TryParse(worksheet.Cells[i, 7].Value.toString(), out decimal costPriceAllDecimal) ? costPriceAllDecimal : 0; //成本总价
  31448. var rowNo = i + 1;
  31449. if (count == 0) return Ok(JsonView(false, $"第{rowNo}行第4列单元格数据有误"));
  31450. if (baoJiaPrice == 0) return Ok(JsonView(false, $"第{rowNo}行第6列单元格数据有误"));
  31451. if (baoJiaAllPrice == 0) return Ok(JsonView(false, $"第{rowNo}行第7列单元格数据有误"));
  31452. if (costPriceAll == 0) return Ok(JsonView(false, $"第{rowNo}行第8列单元格数据有误"));
  31453. //计算系数
  31454. var costSinglePrice = costPriceAll / count; //单项成本
  31455. var costSinglePriceRate = baoJiaPrice / costSinglePrice; //系数
  31456. data.Add(new Grp_ConferenceAffairsCostChild
  31457. {
  31458. Index = index,
  31459. PriceType = typeDict.GetValueOrDefault(typeName, 0),
  31460. PriceName = itemName,
  31461. Count = count,
  31462. Unit = unitDict.GetValueOrDefault(unitName, 0),
  31463. CostPrice = costSinglePrice,
  31464. Currency = 836, // 建议定义为常量或从配置读取
  31465. Rate = costSinglePriceRate,
  31466. AddedValue = 0,
  31467. Details = "",
  31468. ReviewStatus = 0,
  31469. Imgs = "",
  31470. Diid = groupId,
  31471. ConferenceAffairsCostId = conferenceAffairsCostId,
  31472. CreateTime = DateTime.Now,
  31473. CreateUserId = userId,
  31474. IsDel = 0,
  31475. BaoJiaPrice = baoJiaPrice,
  31476. Coefficient = costSinglePriceRate,
  31477. Remark = string.Empty
  31478. });
  31479. }
  31480. var result = await _sqlSugar.Insertable(data).ExecuteCommandAsync();
  31481. if (result < 1) return Ok(JsonView(false, "数据插入失败!"));
  31482. return Ok(JsonView(true, "数据插入成功!", new { count = result }));
  31483. }
  31484. /// <summary>
  31485. /// 团组会务成本数据初始化
  31486. /// </summary>
  31487. /// <returns></returns>
  31488. [HttpPost]
  31489. public async Task<IActionResult> ConferenceAffairsInIt(ConferenceAffairsInItDto Dto)
  31490. {
  31491. var hwids = _sqlSugar.Queryable<Sys_SetData>()
  31492. .Where(x => x.IsDel == 0 && x.STid == 10 && x.Name.Contains("会务活动"))
  31493. .Select(x => x.Id)
  31494. .ToList();
  31495. var expr = _sqlSugar.Queryable<Grp_DelegationInfo>()
  31496. .OrderByDescending(x => x.VisitDate)
  31497. .Where(x => x.IsDel == 0 && hwids.Contains(x.TeamDid))
  31498. .Select<DelegationEasyView>();
  31499. DelegationEasyView di = Dto.GroupId == 0 ?
  31500. expr.First() :
  31501. expr.First(x => x.Id == Dto.GroupId);
  31502. if (di == null)
  31503. {
  31504. return Ok(JsonView(false, "团组信息不存在!"));
  31505. }
  31506. var typeData = await _sqlSugar.Queryable<Sys_SetData>()
  31507. .Where(x => x.IsDel == 0 && x.STid == 21)
  31508. .Select(x => new { x.Id, Text = x.Name })
  31509. .ToListAsync();
  31510. //仅检索会务团组
  31511. var groupList = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  31512. .Where(x => x.IsDel == 0 && hwids.Contains(x.TeamDid))
  31513. .OrderByDescending(x => x.VisitDate)
  31514. .Select(x => new { x.Id, x.TeamName })
  31515. .ToListAsync();
  31516. var currenyList = await GeneralMethod.PostGroupTeamRateByDiIdAndCTableId(1, di.Id, 98);
  31517. var userList = await _sqlSugar.Queryable<Sys_Users>()
  31518. .Where(x => x.IsDel == 0)
  31519. .Select(x => new { x.Id, x.CnName })
  31520. .ToListAsync();
  31521. var units = await _sqlSugar.Queryable<Sys_SetData>()
  31522. .Where(x => x.IsDel == 0 && x.STid == 119)
  31523. .Select(x => new { x.Id, Text = x.Name })
  31524. .ToListAsync();
  31525. var FileType = new[]
  31526. {
  31527. new { Id = 0 , Name = "成本下载" },
  31528. new { Id = 1 , Name = "报价下载" },
  31529. new { Id = 2 , Name = "总表下载" },
  31530. };
  31531. var GM = new List<int>();
  31532. var permissionControlDB = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == 1448)?.Remark;
  31533. try
  31534. {
  31535. GM = JsonConvert.DeserializeObject<List<int>>(permissionControlDB);
  31536. }
  31537. catch (Exception ex)
  31538. {
  31539. GM = new List<int>() { 21 };
  31540. }
  31541. var isReview = Dto.UserId == 21;
  31542. var isGM = GM.Contains(Dto.UserId);
  31543. var ConferenceAffairsCost = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
  31544. .Where(x => x.IsDel == 0)
  31545. .First(x => x.Diid == di.Id);
  31546. if (ConferenceAffairsCost == null)
  31547. {
  31548. //插入主表数据
  31549. ConferenceAffairsCost = new Grp_ConferenceAffairsCost()
  31550. {
  31551. Diid = di.Id,
  31552. CreateTime = DateTime.Now,
  31553. CreateUserId = Dto.UserId,
  31554. IsDel = 0,
  31555. AllocationAmount = 0,
  31556. AllocationCurrency = 836,
  31557. AllocationRate = 0,
  31558. AllocationGroupId = di.Id,
  31559. CostAll = 0,
  31560. BaoJiaAll = 0,
  31561. MostCurr = 836,
  31562. Remark = "",
  31563. City = "",
  31564. };
  31565. ConferenceAffairsCost.Id = _sqlSugar.Insertable(ConferenceAffairsCost).ExecuteReturnIdentity();
  31566. }
  31567. #region 权限校验
  31568. var ids = _sqlSugar.Queryable<Grp_ConferenceAffairsCostControl>()
  31569. .Where(x => x.Diid == di.Id && x.IsDel == 0)
  31570. .Select(x => x.UserId)
  31571. .Distinct()
  31572. .ToList();
  31573. if (!ids.Contains(Dto.UserId) && !isGM)
  31574. {
  31575. return Ok(JsonView(201, "暂无权限!", new
  31576. {
  31577. typeData,
  31578. groupList,
  31579. currenyList,
  31580. isGM,
  31581. userList,
  31582. units,
  31583. isReview,
  31584. operatorUser = ids,
  31585. di,
  31586. FileType
  31587. }));
  31588. }
  31589. #endregion
  31590. var ConferenceAffairsCostChi = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  31591. .Where(x => x.IsDel == 0 && x.Diid == di.Id)
  31592. .Select<ConferenceAffairsCostChildView>()
  31593. .OrderBy(x => x.Index)
  31594. .ToList();
  31595. for (int i = 1; i <= ConferenceAffairsCostChi.Count; i++)
  31596. {
  31597. ConferenceAffairsCostChi[i - 1].Index = i;
  31598. }
  31599. var ConferenceAffairsCostMap = _mapper.Map<ConferenceAffairsCostView>(ConferenceAffairsCost);
  31600. var backData = new
  31601. {
  31602. ConferenceAffairsCost = ConferenceAffairsCostMap,
  31603. ConferenceAffairsCostChi,
  31604. typeData,
  31605. groupList,
  31606. currenyList,
  31607. isGM,
  31608. userList,
  31609. units,
  31610. isReview,
  31611. operatorUser = ids,
  31612. di,
  31613. FileType
  31614. };
  31615. return Ok(JsonView(true, "SUCCESS", backData));
  31616. }
  31617. [HttpPost]
  31618. public async Task<IActionResult> ConferenceAffairsChildAddRowReturnId(ConferenceAffairsChildAddRowReturnIdDto dto)
  31619. {
  31620. var data = _mapper.Map<Grp_ConferenceAffairsCostChild>(dto.data);
  31621. if (data.Rate == 0)
  31622. {
  31623. data.Rate = 1;
  31624. }
  31625. if (data.Coefficient == 0)
  31626. {
  31627. data.Coefficient = 1;
  31628. }
  31629. if (data.Count == 0)
  31630. {
  31631. data.Count = 1;
  31632. }
  31633. var id = await _sqlSugar.Insertable(data).ExecuteReturnIdentityAsync();
  31634. return Ok(JsonView(true, "SUCCESS", new { id }));
  31635. }
  31636. /// <summary>
  31637. /// 会务成本从表新增行
  31638. /// </summary>
  31639. /// <param name="Dto"></param>
  31640. /// <returns></returns>
  31641. [HttpPost]
  31642. public async Task<IActionResult> ConferenceAffairsChildAddRow(ConferenceAffairsChildAddRowDto Dto)
  31643. {
  31644. if (Dto.diid < 1) return Ok(JsonView(false, "团组id有误!"));
  31645. if (Dto.userId < 1) return Ok(JsonView(false, "用户id有误!"));
  31646. var queryList = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  31647. .Where(x => x.IsDel == 0 && x.Diid == Dto.diid)
  31648. .OrderByDescending(x => x.Index)
  31649. .ToList();
  31650. var queryData = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
  31651. .Where(x => x.IsDel == 0 && x.Diid == Dto.diid)
  31652. .First();
  31653. if (queryData == null)
  31654. {
  31655. return Ok(JsonView(false, "会务成本主表不存在!"));
  31656. }
  31657. var child = new Grp_ConferenceAffairsCostChild();
  31658. child.Diid = Dto.diid;
  31659. child.CreateTime = DateTime.Now;
  31660. child.CreateUserId = Dto.userId;
  31661. child.IsDel = 0;
  31662. child.Index = queryList.Count + 1;
  31663. child.ConferenceAffairsCostId = queryData.Id;
  31664. child.PriceType = 0;
  31665. child.PriceName = "";
  31666. child.CostPrice = 0;
  31667. child.Currency = 836;
  31668. child.Rate = 1;
  31669. child.Count = 1;
  31670. child.Unit = 0;
  31671. child.Coefficient = 1;
  31672. child.BaoJiaPrice = 0;
  31673. child.AddedValue = 0;
  31674. child.Details = "";
  31675. child.ReviewStatus = 0;
  31676. child.Imgs = "";
  31677. child.Id = _sqlSugar.Insertable(child).ExecuteReturnIdentity();
  31678. var result = new
  31679. {
  31680. index = queryList.Count + 1,
  31681. priceType = "",
  31682. priceName = "",
  31683. costPrice = 0m,
  31684. currency = 836,
  31685. rate = 1m,
  31686. count = 1,
  31687. unit = "",
  31688. coefficient = 1m,
  31689. baoJiaPrice = 0m,
  31690. addedValue = 0m,
  31691. details = "",
  31692. reviewStatus = 0,
  31693. diid = Dto.diid,
  31694. imgs = "",
  31695. imgsList = new List<string>(),
  31696. id = child.Id,
  31697. remark = ""
  31698. };
  31699. return Ok(JsonView(true, "新增成功!", result));
  31700. }
  31701. /// <summary>
  31702. /// 会务成本从表图片文件上传
  31703. /// </summary>
  31704. /// <param name="Dto"></param>
  31705. /// <returns></returns>
  31706. [HttpPost]
  31707. public async Task<IActionResult> ConferenceAffairsChildImageUpload([FromForm] ConferenceAffairsChildImageUploadDto Dto)
  31708. {
  31709. try
  31710. {
  31711. if (Dto == null || Dto.Files == null || Dto.Files.Count == 0)
  31712. {
  31713. return Ok(JsonView(false, "请选择要上传的图片文件!"));
  31714. }
  31715. var child = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  31716. .Where(x => x.IsDel == 0 && x.Id == Dto.childId)
  31717. .First();
  31718. if (child == null)
  31719. {
  31720. return Ok(JsonView(false, "会务成本从表不存在!"));
  31721. }
  31722. // 允许的图片类型
  31723. var allowedImageTypes = new[] { ".jpg", ".jpeg", ".png", ".gif", ".bmp" };
  31724. var allowedContentTypes = new[] { "image/jpeg", "image/jpg", "image/png", "image/gif", "image/bmp" };
  31725. // 获取配置路径
  31726. string baseUrl = AppSettingsHelper.Get("ConferenceCostImageBaseUrl");
  31727. string basePath = AppSettingsHelper.Get("ConferenceCostImageBasePath");
  31728. string ftpPath = AppSettingsHelper.Get("ConferenceCostImageFtpPath");
  31729. // 确保路径以/结尾
  31730. if (!baseUrl.EndsWith("/"))
  31731. {
  31732. baseUrl = baseUrl.TrimEnd('/') + "/";
  31733. }
  31734. if (!basePath.EndsWith("\\") && !basePath.EndsWith("/"))
  31735. {
  31736. basePath = basePath.TrimEnd('\\', '/') + "\\";
  31737. }
  31738. // 创建保存目录(按childId分目录)
  31739. string saveDir = Path.Combine(basePath, "child", child.Id.ToString());
  31740. if (!Directory.Exists(saveDir))
  31741. {
  31742. Directory.CreateDirectory(saveDir);
  31743. }
  31744. var uploadedImageUrls = new List<string>();
  31745. var existingImgs = string.IsNullOrWhiteSpace(child.Imgs)
  31746. ? new List<string>()
  31747. : child.Imgs.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  31748. foreach (var file in Dto.Files)
  31749. {
  31750. if (file == null || file.Length == 0)
  31751. {
  31752. continue;
  31753. }
  31754. // 验证文件扩展名
  31755. var fileExtension = Path.GetExtension(file.FileName).ToLowerInvariant();
  31756. if (string.IsNullOrEmpty(fileExtension) || !allowedImageTypes.Contains(fileExtension))
  31757. {
  31758. return Ok(JsonView(false, $"文件 {file.FileName} 不是支持的图片格式,仅支持:{string.Join("、", allowedImageTypes)}"));
  31759. }
  31760. // 验证ContentType
  31761. if (!string.IsNullOrEmpty(file.ContentType) && !allowedContentTypes.Contains(file.ContentType.ToLowerInvariant()))
  31762. {
  31763. return Ok(JsonView(false, $"文件 {file.FileName} 的ContentType不正确,不是图片类型"));
  31764. }
  31765. // 获取原始文件名(不含扩展名)和扩展名
  31766. string originalFileName = Path.GetFileNameWithoutExtension(file.FileName);
  31767. string fileName = file.FileName;
  31768. string filePath = Path.Combine(saveDir, fileName);
  31769. // 如果文件已存在,添加计数后缀
  31770. int count = 0;
  31771. while (System.IO.File.Exists(filePath))
  31772. {
  31773. count++;
  31774. fileName = $"{originalFileName}({count}){fileExtension}";
  31775. filePath = Path.Combine(saveDir, fileName);
  31776. }
  31777. // 保存文件
  31778. using (var stream = new FileStream(filePath, FileMode.Create))
  31779. {
  31780. await file.CopyToAsync(stream);
  31781. }
  31782. // 生成完整URL路径
  31783. string imageUrl = $"{baseUrl}{ftpPath}child/{child.Id}/{fileName}";
  31784. uploadedImageUrls.Add(imageUrl);
  31785. }
  31786. if (uploadedImageUrls.Count == 0)
  31787. {
  31788. return Ok(JsonView(false, "没有成功上传任何图片!"));
  31789. }
  31790. // 合并现有图片路径和新上传的图片路径
  31791. existingImgs.AddRange(uploadedImageUrls);
  31792. string updatedImgs = string.Join(",", existingImgs);
  31793. // 更新数据库
  31794. _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>()
  31795. .SetColumns(x => new Grp_ConferenceAffairsCostChild { Imgs = updatedImgs })
  31796. .Where(x => x.Id == child.Id)
  31797. .ExecuteCommand();
  31798. return Ok(JsonView(true, $"成功上传 {uploadedImageUrls.Count} 张图片", uploadedImageUrls));
  31799. }
  31800. catch (Exception ex)
  31801. {
  31802. return Ok(JsonView(false, $"上传失败:{ex.Message}"));
  31803. }
  31804. }
  31805. /// <summary>
  31806. /// 根据文件名和从表id删除对应的图片
  31807. /// </summary>
  31808. /// <param name="Dto"></param>
  31809. /// <returns></returns>
  31810. [HttpPost]
  31811. public async Task<IActionResult> ConferenceAffairsChildImageDelete(ConferenceAffairsChildImageDeleteDto Dto)
  31812. {
  31813. if (Dto == null || Dto.fileNames == null || Dto.fileNames.Count == 0)
  31814. {
  31815. return Ok(JsonView(false, "请提供要删除的文件名列表!"));
  31816. }
  31817. var child = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  31818. .Where(x => x.IsDel == 0 && x.Id == Dto.childId)
  31819. .First();
  31820. if (child == null)
  31821. {
  31822. return Ok(JsonView(false, "会务成本id有误!"));
  31823. }
  31824. var existingImgs = string.IsNullOrWhiteSpace(child.Imgs)
  31825. ? new List<string>()
  31826. : child.Imgs.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  31827. // 获取配置路径
  31828. string baseUrl = AppSettingsHelper.Get("ConferenceCostImageBaseUrl");
  31829. string basePath = AppSettingsHelper.Get("ConferenceCostImageBasePath");
  31830. string ftpPath = AppSettingsHelper.Get("ConferenceCostImageFtpPath");
  31831. // 确保路径格式正确
  31832. if (!baseUrl.EndsWith("/"))
  31833. {
  31834. baseUrl = baseUrl.TrimEnd('/') + "/";
  31835. }
  31836. if (!basePath.EndsWith("\\") && !basePath.EndsWith("/"))
  31837. {
  31838. basePath = basePath.TrimEnd('\\', '/') + "\\";
  31839. }
  31840. if (!ftpPath.EndsWith("/"))
  31841. {
  31842. ftpPath = ftpPath.TrimEnd('/') + "/";
  31843. }
  31844. int deletedCount = 0;
  31845. var expectedUrlPrefix = $"{baseUrl}{ftpPath}child/{child.Id}/";
  31846. var fileDir = Path.Combine(basePath, "child", child.Id.ToString());
  31847. // 遍历要删除的文件名列表
  31848. foreach (var fileNameOrUrl in Dto.fileNames)
  31849. {
  31850. if (string.IsNullOrWhiteSpace(fileNameOrUrl))
  31851. {
  31852. continue;
  31853. }
  31854. string fileName = fileNameOrUrl;
  31855. string fullUrl = fileNameOrUrl;
  31856. // 判断是完整URL还是文件名
  31857. if (fileNameOrUrl.StartsWith("http://") || fileNameOrUrl.StartsWith("https://"))
  31858. {
  31859. // 是完整URL,提取文件名
  31860. try
  31861. {
  31862. var uri = new Uri(fileNameOrUrl);
  31863. fileName = Path.GetFileName(uri.AbsolutePath);
  31864. // 如果URL包含child/{childId}/路径,使用完整URL匹配
  31865. if (fileNameOrUrl.Contains($"/child/{child.Id}/"))
  31866. {
  31867. fullUrl = fileNameOrUrl;
  31868. }
  31869. else
  31870. {
  31871. // URL格式不匹配,尝试构造完整URL
  31872. fullUrl = $"{expectedUrlPrefix}{fileName}";
  31873. }
  31874. }
  31875. catch
  31876. {
  31877. // URL解析失败,当作文件名处理
  31878. fileName = Path.GetFileName(fileNameOrUrl);
  31879. fullUrl = $"{expectedUrlPrefix}{fileName}";
  31880. }
  31881. }
  31882. else
  31883. {
  31884. // 是文件名,构造完整URL用于匹配
  31885. fullUrl = $"{expectedUrlPrefix}{fileName}";
  31886. }
  31887. // 从现有图片列表中移除(支持完整URL匹配或文件名匹配)
  31888. var removed = existingImgs.RemoveAll(img =>
  31889. img.Equals(fullUrl, StringComparison.OrdinalIgnoreCase) ||
  31890. img.Equals(fileNameOrUrl, StringComparison.OrdinalIgnoreCase) ||
  31891. img.EndsWith($"/{fileName}", StringComparison.OrdinalIgnoreCase));
  31892. if (removed > 0)
  31893. {
  31894. deletedCount++;
  31895. }
  31896. // 删除磁盘上的文件
  31897. var filePath = Path.Combine(fileDir, fileName);
  31898. if (System.IO.File.Exists(filePath))
  31899. {
  31900. try
  31901. {
  31902. System.IO.File.Delete(filePath);
  31903. }
  31904. catch (Exception ex)
  31905. {
  31906. _logger.LogError(ex, "删除图片失败:{fileName}", fileName);
  31907. }
  31908. }
  31909. }
  31910. if (deletedCount == 0)
  31911. {
  31912. return Ok(JsonView(false, "没有找到要删除的图片!"));
  31913. }
  31914. // 更新数据库
  31915. var updatedImgs = string.Join(",", existingImgs);
  31916. _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>()
  31917. .SetColumns(x => new Grp_ConferenceAffairsCostChild { Imgs = updatedImgs })
  31918. .Where(x => x.Id == child.Id)
  31919. .ExecuteCommand();
  31920. return Ok(JsonView(true, $"成功删除 {deletedCount} 张图片", updatedImgs));
  31921. }
  31922. /// <summary>
  31923. /// 会务流程word下载
  31924. /// </summary>
  31925. /// <param name="Dto"></param>
  31926. /// <returns></returns>
  31927. [HttpPost]
  31928. public async Task<IActionResult> InspectionReportFileDown(InspectionReportFileDownDto Dto)
  31929. {
  31930. var di = _sqlSugar.Queryable<Grp_DelegationInfo>()
  31931. .Where(x => x.IsDel == 0 && x.Id == Dto.Diid)
  31932. .First();
  31933. if (di == null)
  31934. {
  31935. return Ok(JsonView(false, "团组信息不存在!"));
  31936. }
  31937. //书签dic
  31938. var bookmarks = new Dictionary<string, string>();
  31939. bookmarks.Add("TeamName", di.TeamName);
  31940. bookmarks.Add("TeamName1", di.TeamName);
  31941. bookmarks.Add("ClientUnit", di.ClientUnit);
  31942. bookmarks.Add("ClientUnit1", di.ClientUnit);
  31943. bookmarks.Add("thisTime", DateTime.Now.ToString("yyyy年MM月dd日"));
  31944. //读取word模板
  31945. var templatePath = $"{AppSettingsHelper.Get("WordBasePath")}/template/活动验收报告.docx";
  31946. var doc = new Document(templatePath);
  31947. var chiList = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  31948. .Where(x => x.IsDel == 0 && x.Diid == Dto.Diid && x.PriceType > 0 && x.Unit > 0)
  31949. .Select(x => new
  31950. {
  31951. x.Index,
  31952. x.PriceName,
  31953. PriceType = SqlFunc.Subqueryable<Sys_SetData>().Where(y => y.IsDel == 0 && y.Id == x.PriceType).Select(y => y.Name),
  31954. x.Count,
  31955. x.Remark,
  31956. x.Imgs
  31957. })
  31958. .OrderBy(x => x.Index)
  31959. .ToList();
  31960. //获取word所有表格
  31961. var allTables = doc.GetChildNodes(NodeType.Table, true);
  31962. //获取word第一个表格
  31963. var table = allTables[0] as Aspose.Words.Tables.Table;
  31964. //内容行索引
  31965. var startIndex = 2;
  31966. var copyRow = table.Rows[startIndex].Clone(true);
  31967. for (int i = 0; i < chiList.Count; i++)
  31968. {
  31969. var chi = chiList[i];
  31970. //插入复制的行(从第2次开始插入新行,第1次使用模板行)
  31971. if (i > 0)
  31972. {
  31973. var newRow = copyRow.Clone(true) as Aspose.Words.Tables.Row;
  31974. table.Rows.Insert(startIndex, newRow);
  31975. }
  31976. //word 表格 赋值
  31977. var row = table.Rows[startIndex];
  31978. row.Cells[0].FirstParagraph.Runs.Clear();
  31979. row.Cells[0].FirstParagraph.AppendChild(new Run(doc, (i + 1).ToString()));
  31980. row.Cells[1].FirstParagraph.Runs.Clear();
  31981. row.Cells[1].FirstParagraph.AppendChild(new Run(doc, chi.PriceName));
  31982. row.Cells[2].FirstParagraph.Runs.Clear();
  31983. row.Cells[2].FirstParagraph.AppendChild(new Run(doc, chi.PriceType));
  31984. row.Cells[3].FirstParagraph.Runs.Clear();
  31985. row.Cells[3].FirstParagraph.AppendChild(new Run(doc, chi.Count.ToString()));
  31986. row.Cells[4].FirstParagraph.Runs.Clear();
  31987. row.Cells[4].FirstParagraph.AppendChild(new Run(doc, chi.Remark));
  31988. if (!string.IsNullOrWhiteSpace(chi.Imgs))
  31989. {
  31990. var imgs = chi.Imgs.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  31991. if (imgs.Length > 0)
  31992. {
  31993. // 获取图片基础路径配置
  31994. string baseUrl = AppSettingsHelper.Get("ConferenceCostImageBaseUrl");
  31995. string basePath = AppSettingsHelper.Get("ConferenceCostImageBasePath");
  31996. // 按图片方向分类,同时缓存图片字节数据
  31997. var imageInfos = new List<(string url, bool isWide, int width, int height, byte[] imageData)>();
  31998. _logger.LogInformation($"开始处理图片,配置 - BaseUrl: {baseUrl}, BasePath: {basePath}, 索引: {chi.Index}");
  31999. using (var httpClient = new HttpClient())
  32000. {
  32001. httpClient.Timeout = TimeSpan.FromSeconds(30);
  32002. foreach (var imgUrl in imgs)
  32003. {
  32004. try
  32005. {
  32006. string fullUrl = imgUrl;
  32007. string localPath = "";
  32008. // 判断是否为完整URL
  32009. if (imgUrl.StartsWith("http://") || imgUrl.StartsWith("https://"))
  32010. {
  32011. fullUrl = imgUrl;
  32012. // 尝试从URL转换为本地路径
  32013. if (imgUrl.Contains("/child/"))
  32014. {
  32015. var pathPart = imgUrl.Substring(imgUrl.IndexOf("/child/"));
  32016. localPath = Path.Combine(basePath, pathPart.TrimStart('/').Replace("/", "\\"));
  32017. }
  32018. }
  32019. else
  32020. {
  32021. // 文件名,构造本地路径和完整URL
  32022. localPath = Path.Combine(basePath, "child", chi.Index.ToString(), imgUrl);
  32023. fullUrl = $"{baseUrl.TrimEnd('/')}/child/{chi.Index}/{imgUrl}";
  32024. }
  32025. _logger.LogInformation($"处理图片 [{imgUrl}] - 本地路径: {localPath}, URL: {fullUrl}");
  32026. // 优先使用本地文件,如果不存在则尝试下载
  32027. byte[] imageBytes = null;
  32028. if (!string.IsNullOrEmpty(localPath) && System.IO.File.Exists(localPath))
  32029. {
  32030. imageBytes = System.IO.File.ReadAllBytes(localPath);
  32031. _logger.LogInformation($"从本地加载成功,大小: {imageBytes.Length} 字节");
  32032. }
  32033. else
  32034. {
  32035. // 从URL下载图片
  32036. try
  32037. {
  32038. _logger.LogInformation($"本地文件不存在,尝试从URL下载: {fullUrl}");
  32039. imageBytes = await httpClient.GetByteArrayAsync(fullUrl);
  32040. _logger.LogInformation($"从URL下载成功,大小: {imageBytes.Length} 字节");
  32041. }
  32042. catch (Exception ex)
  32043. {
  32044. _logger.LogWarning($"下载图片失败: {fullUrl}, 错误: {ex.Message}");
  32045. continue;
  32046. }
  32047. }
  32048. if (imageBytes != null && imageBytes.Length > 0)
  32049. {
  32050. // 获取图片尺寸
  32051. using (var ms = new MemoryStream(imageBytes))
  32052. {
  32053. using (var image = System.Drawing.Image.FromStream(ms))
  32054. {
  32055. bool isWide = image.Width >= image.Height;
  32056. // 缓存图片数据,避免后续重复加载
  32057. imageInfos.Add((imgUrl, isWide, image.Width, image.Height, imageBytes));
  32058. _logger.LogInformation($"图片分析完成 - 宽度: {image.Width}px, 高度: {image.Height}px, 类型: {(isWide ? "横图" : "竖图")}");
  32059. }
  32060. }
  32061. }
  32062. }
  32063. catch (Exception ex)
  32064. {
  32065. _logger.LogError(ex, $"处理图片失败: {imgUrl}");
  32066. continue;
  32067. }
  32068. }
  32069. }
  32070. _logger.LogInformation($"图片处理完成,成功加载 {imageInfos.Count} 张图片");
  32071. // 插入图片行
  32072. if (imageInfos.Count > 0)
  32073. {
  32074. var builder = new DocumentBuilder(doc);
  32075. // 从数据模板行获取正确的列数,而不是标题行(标题行可能是合并单元格)
  32076. int totalColumns = table.Rows[startIndex].Cells.Count;
  32077. _logger.LogInformation($"表格总列数: {totalColumns}(从第{startIndex}行获取)");
  32078. for (int imgIndex = 0; imgIndex < imageInfos.Count;)
  32079. {
  32080. var currentImg = imageInfos[imgIndex];
  32081. // 在当前行后插入新行(使用复制的模板行)
  32082. var newRow = copyRow.Clone(true) as Aspose.Words.Tables.Row;
  32083. table.Rows.Insert(startIndex + 1, newRow);
  32084. startIndex++; // 更新startIndex,因为插入了新行
  32085. // 重置所有单元格的合并状态(关键:清除克隆行的原有格式)
  32086. for (int col = 0; col < totalColumns; col++)
  32087. {
  32088. if (col < newRow.Cells.Count)
  32089. {
  32090. newRow.Cells[col].CellFormat.HorizontalMerge = CellMerge.None;
  32091. newRow.Cells[col].CellFormat.VerticalMerge = CellMerge.None;
  32092. }
  32093. }
  32094. if (currentImg.isWide)
  32095. {
  32096. _logger.LogInformation($"开始插入宽图 [{currentImg.url}],宽度: {currentImg.width}px");
  32097. // 宽图:先设置所有单元格的合并状态
  32098. for (int col = 0; col < totalColumns; col++)
  32099. {
  32100. if (col < newRow.Cells.Count)
  32101. {
  32102. var cell = newRow.Cells[col];
  32103. cell.RemoveAllChildren();
  32104. if (col == 0)
  32105. {
  32106. cell.CellFormat.HorizontalMerge = CellMerge.First;
  32107. }
  32108. else
  32109. {
  32110. cell.CellFormat.HorizontalMerge = CellMerge.Previous;
  32111. }
  32112. cell.CellFormat.PreferredWidth = PreferredWidth.Auto;
  32113. }
  32114. }
  32115. // 然后在第一个单元格插入图片
  32116. var firstCell = newRow.Cells[0];
  32117. var para = new Paragraph(doc);
  32118. para.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  32119. firstCell.AppendChild(para);
  32120. builder.MoveTo(para);
  32121. try
  32122. {
  32123. // 使用缓存的图片数据
  32124. byte[] imageBytes = currentImg.imageData;
  32125. if (imageBytes != null && imageBytes.Length > 0)
  32126. {
  32127. using (var imgStream = new MemoryStream(imageBytes))
  32128. {
  32129. // 插入图片,设置合理的宽度和最大高度
  32130. var shape = builder.InsertImage(imgStream);
  32131. // 使用预先获取的原始尺寸
  32132. double originalWidth = currentImg.width;
  32133. double originalHeight = currentImg.height;
  32134. // 设置最大宽度(约表格宽度的85%,避免超出)
  32135. double maxWidth = 380;
  32136. double maxHeight = 300; // 限制最大高度,避免图片过高
  32137. // 计算缩放比例
  32138. double widthScale = originalWidth > maxWidth ? maxWidth / originalWidth : 1;
  32139. double heightScale = originalHeight > maxHeight ? maxHeight / originalHeight : 1;
  32140. double scale = Math.Min(widthScale, heightScale);
  32141. shape.Width = originalWidth * scale;
  32142. shape.Height = originalHeight * scale;
  32143. _logger.LogInformation($"宽图插入成功,原始尺寸: {originalWidth}x{originalHeight}, 缩放后: {shape.Width:F0}x{shape.Height:F0},已合并 {totalColumns} 个单元格");
  32144. }
  32145. }
  32146. else
  32147. {
  32148. _logger.LogWarning($"图片数据为空");
  32149. para.AppendChild(new Run(doc, "[图片数据为空]"));
  32150. }
  32151. }
  32152. catch (Exception ex)
  32153. {
  32154. _logger.LogError(ex, $"插入宽图失败: {currentImg.url}");
  32155. para.AppendChild(new Run(doc, "[图片加载失败]"));
  32156. }
  32157. imgIndex++; // 处理下一张图片
  32158. }
  32159. else
  32160. {
  32161. _logger.LogInformation($"开始插入高图 [{currentImg.url}],高度: {currentImg.height}px");
  32162. // 高图:合并一半单元格
  32163. int halfColumns = totalColumns / 2;
  32164. _logger.LogInformation($"高图模式 - 前半部分列数: {halfColumns}, 后半部分列数: {totalColumns - halfColumns}");
  32165. // 先设置前一半单元格的合并状态
  32166. for (int col = 0; col < halfColumns; col++)
  32167. {
  32168. if (col < newRow.Cells.Count)
  32169. {
  32170. var cell = newRow.Cells[col];
  32171. cell.RemoveAllChildren();
  32172. if (col == 0)
  32173. {
  32174. cell.CellFormat.HorizontalMerge = CellMerge.First;
  32175. }
  32176. else
  32177. {
  32178. cell.CellFormat.HorizontalMerge = CellMerge.Previous;
  32179. }
  32180. cell.CellFormat.PreferredWidth = PreferredWidth.Auto;
  32181. }
  32182. }
  32183. // 设置后一半单元格的合并状态
  32184. for (int col = halfColumns; col < totalColumns; col++)
  32185. {
  32186. if (col < newRow.Cells.Count)
  32187. {
  32188. var cell = newRow.Cells[col];
  32189. cell.RemoveAllChildren();
  32190. if (col == halfColumns)
  32191. {
  32192. cell.CellFormat.HorizontalMerge = CellMerge.First;
  32193. }
  32194. else
  32195. {
  32196. cell.CellFormat.HorizontalMerge = CellMerge.Previous;
  32197. }
  32198. cell.CellFormat.PreferredWidth = PreferredWidth.Auto;
  32199. }
  32200. }
  32201. // 在第一个单元格插入第一张高图
  32202. var firstCell = newRow.Cells[0];
  32203. var para1 = new Paragraph(doc);
  32204. para1.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  32205. firstCell.AppendChild(para1);
  32206. builder.MoveTo(para1);
  32207. try
  32208. {
  32209. // 使用缓存的图片数据
  32210. byte[] imageBytes = currentImg.imageData;
  32211. if (imageBytes != null && imageBytes.Length > 0)
  32212. {
  32213. using (var imgStream = new MemoryStream(imageBytes))
  32214. {
  32215. var shape = builder.InsertImage(imgStream);
  32216. // 使用预先获取的原始尺寸
  32217. double originalWidth = currentImg.width;
  32218. double originalHeight = currentImg.height;
  32219. // 设置最大宽度和高度(约表格一半宽度)
  32220. double maxWidth = 180;
  32221. double maxHeight = 300; // 限制最大高度
  32222. // 计算缩放比例
  32223. double widthScale = originalWidth > maxWidth ? maxWidth / originalWidth : 1;
  32224. double heightScale = originalHeight > maxHeight ? maxHeight / originalHeight : 1;
  32225. double scale = Math.Min(widthScale, heightScale);
  32226. shape.Width = originalWidth * scale;
  32227. shape.Height = originalHeight * scale;
  32228. _logger.LogInformation($"第一张高图插入成功,原始尺寸: {originalWidth}x{originalHeight}, 缩放后: {shape.Width:F0}x{shape.Height:F0},已合并前 {halfColumns} 个单元格");
  32229. }
  32230. }
  32231. else
  32232. {
  32233. _logger.LogWarning($"图片数据为空");
  32234. para1.AppendChild(new Run(doc, "[图片数据为空]"));
  32235. }
  32236. }
  32237. catch (Exception ex)
  32238. {
  32239. _logger.LogError(ex, $"插入高图失败: {currentImg.url}");
  32240. para1.AppendChild(new Run(doc, "[图片加载失败]"));
  32241. }
  32242. imgIndex++; // 第一张高图已处理
  32243. // 检查是否还有下一张高图,如果有则插入到后一半单元格
  32244. if (imgIndex < imageInfos.Count && !imageInfos[imgIndex].isWide)
  32245. {
  32246. var secondCell = newRow.Cells[halfColumns];
  32247. var para2 = new Paragraph(doc);
  32248. para2.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  32249. secondCell.AppendChild(para2);
  32250. builder.MoveTo(para2);
  32251. try
  32252. {
  32253. var nextImg = imageInfos[imgIndex];
  32254. _logger.LogInformation($"开始插入第二张高图 [{nextImg.url}]");
  32255. // 使用缓存的图片数据
  32256. byte[] imageBytes = nextImg.imageData;
  32257. if (imageBytes != null && imageBytes.Length > 0)
  32258. {
  32259. using (var imgStream = new MemoryStream(imageBytes))
  32260. {
  32261. var shape = builder.InsertImage(imgStream);
  32262. // 使用预先获取的原始尺寸
  32263. double originalWidth = nextImg.width;
  32264. double originalHeight = nextImg.height;
  32265. // 设置最大宽度和高度
  32266. double maxWidth = 180;
  32267. double maxHeight = 300;
  32268. // 计算缩放比例
  32269. double widthScale = originalWidth > maxWidth ? maxWidth / originalWidth : 1;
  32270. double heightScale = originalHeight > maxHeight ? maxHeight / originalHeight : 1;
  32271. double scale = Math.Min(widthScale, heightScale);
  32272. shape.Width = originalWidth * scale;
  32273. shape.Height = originalHeight * scale;
  32274. _logger.LogInformation($"第二张高图插入成功,原始尺寸: {originalWidth}x{originalHeight}, 缩放后: {shape.Width:F0}x{shape.Height:F0},已合并后 {totalColumns - halfColumns} 个单元格");
  32275. }
  32276. }
  32277. else
  32278. {
  32279. _logger.LogWarning($"第二张高图数据为空");
  32280. para2.AppendChild(new Run(doc, "[图片数据为空]"));
  32281. }
  32282. imgIndex++; // 第二张高图已处理
  32283. }
  32284. catch (Exception ex)
  32285. {
  32286. _logger.LogError(ex, $"插入第二张高图失败");
  32287. para2.AppendChild(new Run(doc, "[图片加载失败]"));
  32288. }
  32289. }
  32290. }
  32291. }
  32292. }
  32293. }
  32294. }
  32295. startIndex++;
  32296. }
  32297. //替换书签
  32298. foreach (var key in bookmarks.Keys)
  32299. {
  32300. if (doc.Range.Bookmarks[key] != null)
  32301. {
  32302. Bookmark mark = doc.Range.Bookmarks[key];
  32303. mark.Text = bookmarks[key];
  32304. }
  32305. }
  32306. //去水印
  32307. new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String(AsposeHelper.asposeKey)));
  32308. //保存word
  32309. string fileName = $"活动验收报告_{di.TeamName}_{DateTime.Now:yyyyMMddHHmmss}.docx";
  32310. string filePath = $"InspectionReport/{fileName}";
  32311. string fullPath = AppSettingsHelper.Get("WordBasePath") + filePath;
  32312. //确保目录存在
  32313. string directory = Path.GetDirectoryName(fullPath);
  32314. if (!Directory.Exists(directory))
  32315. {
  32316. Directory.CreateDirectory(directory);
  32317. }
  32318. //保存文档
  32319. doc.Save(fullPath, Aspose.Words.SaveFormat.Docx);
  32320. //返回文件路径http
  32321. string url = AppSettingsHelper.Get("WordBaseUrl") + $"Office/Word/{filePath}";
  32322. return Ok(JsonView(true, "SUCCESS!", new { Url = url, FileName = fileName }));
  32323. }
  32324. /// <summary>
  32325. /// 会务成本保存
  32326. /// </summary>
  32327. /// <returns></returns>
  32328. [HttpPost]
  32329. public async Task<IActionResult> ConferenceAffairsSave(ConferenceAffairsSaveDto Dto)
  32330. {
  32331. _sqlSugar.BeginTran();
  32332. var data = _mapper.Map<Grp_ConferenceAffairsCost>(Dto.ConferenceAffairsCost);
  32333. var childResult = new
  32334. {
  32335. success = 0,
  32336. error = 0
  32337. };
  32338. try
  32339. {
  32340. if (data.Id == 0)
  32341. {
  32342. _sqlSugar.Updateable<Grp_ConferenceAffairsCost>()
  32343. .Where(x => x.Diid == Dto.GroupId)
  32344. .SetColumns(x => new Grp_ConferenceAffairsCost
  32345. {
  32346. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  32347. DeleteUserId = Dto.UserId
  32348. })
  32349. .ExecuteCommand();
  32350. data.Diid = Dto.GroupId;
  32351. data.CreateTime = DateTime.Now;
  32352. data.CreateUserId = Dto.UserId;
  32353. data.Id = _sqlSugar.Insertable<Grp_ConferenceAffairsCost>(data)
  32354. .ExecuteReturnIdentity();
  32355. }
  32356. else
  32357. {
  32358. _sqlSugar.Updateable<Grp_ConferenceAffairsCost>(data)
  32359. .ExecuteCommand();
  32360. data.Id = data.Id;
  32361. }
  32362. if (Dto.ConferenceAffairsCostChild.Any())
  32363. {
  32364. var datas = _mapper.Map<List<Grp_ConferenceAffairsCostChild>>(Dto.ConferenceAffairsCostChild);
  32365. var insertArr = datas.Where(x => x.Id == 0).ToList();
  32366. var updateArr = datas.Where(x => x.Id != 0 && x.ReviewStatus != 1).ToList();
  32367. var notUpdateArr = datas.Where(x => x.Id != 0 && x.ReviewStatus == 1).ToList();
  32368. insertArr.ForEach(x => { x.Diid = Dto.GroupId; x.ConferenceAffairsCostId = data.Id; });
  32369. var inrsetCount = insertArr.Any() ? _sqlSugar.Insertable<Grp_ConferenceAffairsCostChild>(insertArr).ExecuteCommand() : 0;
  32370. var updateCount = updateArr.Any() ? _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>(updateArr)
  32371. .IgnoreColumns(x => new { x.ConferenceAffairsCostId })
  32372. .ExecuteCommand() : 0;
  32373. childResult = childResult with
  32374. {
  32375. error = notUpdateArr.Count(),
  32376. success = inrsetCount + updateCount
  32377. };
  32378. }
  32379. _sqlSugar.CommitTran();
  32380. }
  32381. catch (Exception ex)
  32382. {
  32383. _sqlSugar.RollbackTran();
  32384. return Ok(JsonView(false, "失败!" + ex.Message));
  32385. }
  32386. return Ok(JsonView(true, "操作成功!", childResult));
  32387. }
  32388. [HttpPost]
  32389. public async Task<IActionResult> ConferenceAffairsAudit(ConferenceAffairsAuditDto Dto)
  32390. {
  32391. var count = 0;
  32392. if (Dto.ConferenceAffairsCostChildids.Any())
  32393. {
  32394. count = _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>().
  32395. Where(x => Dto.ConferenceAffairsCostChildids.Contains(x.Id)).
  32396. SetColumns(x => new Grp_ConferenceAffairsCostChild
  32397. {
  32398. ReviewStatus = Dto.ReviewStatus
  32399. }).
  32400. ExecuteCommand();
  32401. }
  32402. return Ok(JsonView(true, "操作成功!", count));
  32403. }
  32404. /// <summary>
  32405. /// 会务成本所有数据清除
  32406. /// </summary>
  32407. /// <param name="Dto"></param>
  32408. /// <returns></returns>
  32409. [HttpPost]
  32410. public async Task<IActionResult> ConferenceAffairsDelete(ConferenceAffairsDeleteDto Dto)
  32411. {
  32412. if (Dto.GroupId < 1) return Ok(JsonView(false, "请传入有效的Id"));
  32413. if (Dto.UserId < 1) return Ok(JsonView(false, "请传入有效的用户Id"));
  32414. _sqlSugar.BeginTran();
  32415. try
  32416. {
  32417. var delCount = _sqlSugar.Updateable<Grp_ConferenceAffairsCost>()
  32418. .Where(x => x.Diid == Dto.GroupId)
  32419. .SetColumns(x => new Grp_ConferenceAffairsCost
  32420. {
  32421. IsDel = 1,
  32422. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  32423. DeleteUserId = Dto.UserId
  32424. })
  32425. .ExecuteCommand();
  32426. if (delCount > 0)
  32427. {
  32428. _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>()
  32429. .Where(x => x.Diid == Dto.GroupId)
  32430. .SetColumns(x => new Grp_ConferenceAffairsCostChild
  32431. {
  32432. IsDel = 1,
  32433. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  32434. DeleteUserId = Dto.UserId
  32435. })
  32436. .ExecuteCommand();
  32437. _sqlSugar.Updateable<Grp_ConferenceAffairsCostControl>()
  32438. .Where(x => x.Diid == Dto.GroupId && x.IsDel == 0)
  32439. .SetColumns(x => new Grp_ConferenceAffairsCostControl
  32440. {
  32441. IsDel = 1,
  32442. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  32443. DeleteUserId = Dto.UserId
  32444. })
  32445. .ExecuteCommand();
  32446. }
  32447. _sqlSugar.CommitTran();
  32448. }
  32449. catch (Exception ex)
  32450. {
  32451. _sqlSugar.RollbackTran();
  32452. return Ok(JsonView(false, "操作失败!" + ex.Message));
  32453. }
  32454. return Ok(JsonView(true, "操作成功!"));
  32455. }
  32456. /// <summary>
  32457. /// 子项数据删除
  32458. /// </summary>
  32459. /// <param name="Dto"></param>
  32460. /// <returns></returns>
  32461. [HttpPost]
  32462. public async Task<IActionResult> ConferenceAffairSinglesDelete(ConferenceAffairsDeleteSingleDto Dto)
  32463. {
  32464. var isAudit = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>().Where(x => x.IsDel == 0 && Dto.ids.Contains(x.Id))
  32465. .Any(x => x.ReviewStatus == 1);
  32466. if (isAudit) return Ok(JsonView(false, "包含已审核数据无法删除!"));
  32467. var queryData = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  32468. .Where(x => x.IsDel == 0 && Dto.ids.Contains(x.Id))
  32469. .ToList();
  32470. //删除图片
  32471. foreach (var item in queryData)
  32472. {
  32473. if (!string.IsNullOrEmpty(item.Imgs))
  32474. {
  32475. var imgList = item.Imgs.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  32476. string baseUrl = AppSettingsHelper.Get("ConferenceCostImageBaseUrl");
  32477. string basePath = AppSettingsHelper.Get("ConferenceCostImageBasePath");
  32478. foreach (var imgUrl in imgList)
  32479. {
  32480. try
  32481. {
  32482. string localPath = "";
  32483. // 判断是否为完整URL
  32484. if (imgUrl.StartsWith("http://") || imgUrl.StartsWith("https://"))
  32485. {
  32486. // 尝试从URL转换为本地路径
  32487. if (imgUrl.Contains("/child/"))
  32488. {
  32489. var pathPart = imgUrl.Substring(imgUrl.IndexOf("/child/"));
  32490. localPath = Path.Combine(basePath, pathPart.TrimStart('/').Replace("/", "\\"));
  32491. }
  32492. }
  32493. else
  32494. {
  32495. // 文件名,构造本地路径
  32496. localPath = Path.Combine(basePath, "child", item.Index.ToString(), imgUrl);
  32497. }
  32498. if (!string.IsNullOrEmpty(localPath) && System.IO.File.Exists(localPath))
  32499. {
  32500. _logger.LogInformation($"-----------------------");
  32501. _logger.LogInformation($"删除图片: {localPath}");
  32502. System.IO.File.Delete(localPath);
  32503. _logger.LogInformation($"删除成功");
  32504. _logger.LogInformation($"-----------------------");
  32505. }
  32506. else
  32507. {
  32508. _logger.LogWarning($"图片文件不存在或路径为空: {imgUrl} -> {localPath}");
  32509. }
  32510. }
  32511. catch (Exception ex)
  32512. {
  32513. _logger.LogError(ex, $"删除图片失败: {imgUrl}");
  32514. }
  32515. }
  32516. }
  32517. }
  32518. var count = _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>()
  32519. .Where(x => Dto.ids.Contains(x.Id) && x.IsDel == 0)
  32520. .SetColumns(x => new Grp_ConferenceAffairsCostChild
  32521. {
  32522. IsDel = 1,
  32523. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  32524. DeleteUserId = Dto.UserId
  32525. })
  32526. .ExecuteCommand();
  32527. return Ok(JsonView(true, "SUCCESS!", count));
  32528. }
  32529. /// <summary>
  32530. /// 会务成本权限分配
  32531. /// </summary>
  32532. /// <param name="Dto"></param>
  32533. /// <returns></returns>
  32534. [HttpPost]
  32535. public async Task<IActionResult> PermissionSetting(PermissionSettingDto Dto)
  32536. {
  32537. _sqlSugar.BeginTran();
  32538. var count = 0;
  32539. try
  32540. {
  32541. _sqlSugar.Updateable<Grp_ConferenceAffairsCostControl>()
  32542. .Where(x => x.Diid == Dto.GroupId && x.IsDel == 0)
  32543. .SetColumns(x => new Grp_ConferenceAffairsCostControl
  32544. {
  32545. IsDel = 1,
  32546. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  32547. DeleteUserId = Dto.CreateUserId
  32548. })
  32549. .ExecuteCommand();
  32550. count = _sqlSugar.Insertable<Grp_ConferenceAffairsCostControl>(Dto.UserIds.Select(x => new Grp_ConferenceAffairsCostControl
  32551. {
  32552. CreateTime = DateTime.Now,
  32553. CreateUserId = Dto.CreateUserId,
  32554. UserId = x,
  32555. Diid = Dto.GroupId,
  32556. }).ToList()).ExecuteCommand();
  32557. _sqlSugar.CommitTran();
  32558. }
  32559. catch (Exception ex)
  32560. {
  32561. _sqlSugar.RollbackTran();
  32562. return Ok(JsonView(false, "操作失败!" + ex.Message));
  32563. }
  32564. return Ok(JsonView(true, "操作成功!", count));
  32565. }
  32566. /// <summary>
  32567. /// 团组会务成本文件下载
  32568. /// </summary>
  32569. /// <returns></returns>
  32570. [HttpPost]
  32571. public async Task<IActionResult> ConferenceAffairsFileDown(ConferenceAffairsFileDownDto Dto)
  32572. {
  32573. var FileType = new[]
  32574. {
  32575. new { Id = 0 , Name = "成本下载" },
  32576. new { Id = 1 , Name = "报价下载" },
  32577. new { Id = 2 , Name = "总表下载" },
  32578. };
  32579. if (Dto.GroupId < 1) return Ok(JsonView(false, "请传入有效的Id"));
  32580. if (Dto.FileTypeId < 0 || Dto.FileTypeId > 2) return Ok(JsonView(false, "请传入有效的文件类型"));
  32581. var di = _sqlSugar.Queryable<Grp_DelegationInfo>()
  32582. .Where(x => x.IsDel == 0 && x.Id == Dto.GroupId)
  32583. .Select<DelegationEasyView>()
  32584. .First();
  32585. var main = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
  32586. .First(x => x.Diid == Dto.GroupId && x.IsDel == 0);
  32587. if (main == null)
  32588. {
  32589. return Ok(JsonView(false, "团组会务成本信息不存在!"));
  32590. }
  32591. JsonView jw = JsonView(false);
  32592. //总表下载
  32593. var loadPath = $"{AppSettingsHelper.Get("ExcelBasePath")}ConferenceAffairs/template/";
  32594. var outputPath = $"{AppSettingsHelper.Get("ExcelBasePath")}ConferenceAffairs/output/total/";
  32595. var networkPath = outputPath.Replace(AppSettingsHelper.Get("ExcelBasePath"), AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath"));
  32596. var field = string.Empty;
  32597. var fileTypeName = string.Empty;
  32598. field = @$"
  32599. a.[Index],a.PriceName,a.CostPrice,a.Count,a.Coefficient,a.BaoJiaPrice,a.AddedValue,a.Details,a.Remark,a.Rate,
  32600. b.Name as PriceTypeStr ,
  32601. c.Name as CurrencyStr ,
  32602. d.Name as UnitStr ,
  32603. case a.ReviewStatus
  32604. WHEN 1 THEN '已通过'
  32605. WHEN 0 THEN '未审核'
  32606. WHEN -1 THEN '未通过'
  32607. ELSE '未审核'
  32608. END AS ReviewStatusStr
  32609. ";
  32610. if (Dto.FileTypeId == 0)
  32611. {
  32612. fileTypeName = "会务成本成本表";
  32613. loadPath += $"{fileTypeName}.xlsx";
  32614. outputPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  32615. networkPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  32616. }
  32617. else if (Dto.FileTypeId == 1)
  32618. {
  32619. fileTypeName = "会务成本报价表";
  32620. loadPath += $"{fileTypeName}.xlsx";
  32621. outputPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  32622. networkPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  32623. }
  32624. else if (Dto.FileTypeId == 2)
  32625. {
  32626. fileTypeName = "会务成本总表";
  32627. loadPath += $"{fileTypeName}.xlsx";
  32628. outputPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  32629. networkPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  32630. }
  32631. var chiExcelContent = _sqlSugar.SqlQueryable<ConferenceAffairsExcelContent>(@$"
  32632. SELECT
  32633. {field}
  32634. FROM Grp_ConferenceAffairsCostChild a
  32635. LEFT JOIN Sys_SetData b on b.IsDel = 0 AND b.Id = a.PriceType
  32636. LEFT JOIN Sys_SetData c on c.IsDel = 0 AND c.Id = a.Currency
  32637. LEFT JOIN Sys_SetData d on d.IsDel = 0 AND d.Id = a.Unit
  32638. WHERE a.isdel = 0
  32639. AND a.Diid = {main.Diid}
  32640. AND a.ConferenceAffairsCostId = {main.Id}
  32641. ").ToList();
  32642. var currLists = chiExcelContent.Select(x => new CurrList
  32643. {
  32644. CurrName = x.CurrencyStr,
  32645. CurrRate = x.Rate
  32646. })
  32647. .Distinct()
  32648. .ToList();
  32649. var designer = new WorkbookDesigner
  32650. {
  32651. Workbook = new Workbook(loadPath)
  32652. };
  32653. var MostCurr = _sqlSugar.Queryable<Sys_SetData>().First(x => x.IsDel == 0 && x.Id == main.MostCurr);
  32654. MostCurr ??= new Sys_SetData { Name = "暂无!" };
  32655. designer.SetDataSource("TeamName", di.TeamName);
  32656. designer.SetDataSource("City", main.City);
  32657. designer.SetDataSource("AllCost", main.CostAll);
  32658. designer.SetDataSource("AllBaoJia", main.BaoJiaAll);
  32659. designer.SetDataSource("Curr", MostCurr.Name);
  32660. designer.SetDataSource("Curr1", MostCurr.Name);
  32661. DataTable dt = CommonFun.GetDataTableFromIList<ConferenceAffairsExcelContent>(chiExcelContent);
  32662. dt.TableName = "TB";
  32663. designer.SetDataSource(dt);
  32664. DataTable dt1 = CommonFun.GetDataTableFromIList<CurrList>(currLists);
  32665. dt1.TableName = "currTb";
  32666. designer.SetDataSource(dt1);
  32667. designer.Process();
  32668. designer.Workbook.Save(outputPath);
  32669. jw = JsonView(true, "操作成功!", new
  32670. {
  32671. FileName = $"{di.TeamName}_{fileTypeName}.xlsx",
  32672. FilePath = networkPath
  32673. });
  32674. return Ok(jw);
  32675. }
  32676. [HttpPost]
  32677. public async Task<IActionResult> QueryConferenceAffairsChild(QueryConferenceAffairsChildDto Dto)
  32678. {
  32679. return Ok(JsonView(true, "SUCCESS", _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>().Where(x => x.IsDel == 0 && x.Diid == Dto.GroupId)
  32680. .Select(x => x.PriceName).ToList()));
  32681. }
  32682. #endregion
  32683. #region 会务流程
  32684. /// <summary>
  32685. /// 会务流程 - 团组列表
  32686. /// </summary>
  32687. /// <returns>团组基本信息、团组列表和会务基本信息列表</returns>
  32688. [HttpGet]
  32689. public async Task<IActionResult> ConferenceProceduresGroupNames()
  32690. {
  32691. var conferenceTypeIds = new List<int>() {
  32692. 302, // 成都-会务活动
  32693. 691 // 四川-会务活动
  32694. };
  32695. var groupList = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  32696. .Where(x => x.IsDel == 0)
  32697. .Where(x => conferenceTypeIds.Contains(x.TeamDid))
  32698. .OrderByDescending(x => x.VisitDate)
  32699. .Select(x => new
  32700. {
  32701. x.Id,
  32702. x.TeamName,
  32703. HasChildData = SqlFunc.Subqueryable<Grp_ConferenceProcedures>()
  32704. .Where(child => child.DiId == x.Id) // 替换关联条件
  32705. .Any() // 判断子表是否存在数据
  32706. })
  32707. .ToListAsync();
  32708. return Ok(JsonView(true, "SUCCESS", groupList));
  32709. }
  32710. /// <summary>
  32711. /// 会务流程 - 数据初始化
  32712. /// </summary>
  32713. /// <param name="dto"></param>
  32714. /// <returns>团组基本信息、团组列表和会务基本信息列表</returns>
  32715. [HttpPost]
  32716. public async Task<IActionResult> ConferenceProceduresInit(ConferenceProceduresInitDto dto)
  32717. {
  32718. try
  32719. {
  32720. var conferenceTypeIds = new List<int>() {
  32721. 302, // 成都-会务活动
  32722. 691 // 四川-会务活动
  32723. };
  32724. Grp_DelegationInfo targetGroup = null;
  32725. targetGroup = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  32726. .Where(x => x.Id == dto.GroupId && x.IsDel == 0)
  32727. .FirstAsync();
  32728. if (targetGroup == null)
  32729. {
  32730. targetGroup = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  32731. .Where(x => x.IsDel == 0)
  32732. .Where(x => conferenceTypeIds.Contains(x.TeamDid))
  32733. .OrderByDescending(x => x.VisitDate)
  32734. .FirstAsync();
  32735. }
  32736. if (targetGroup == null)
  32737. {
  32738. return Ok(JsonView(false, "未找到任何团组信息"));
  32739. }
  32740. var groupList = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  32741. .Where(x => x.IsDel == 0)
  32742. .Where(x => conferenceTypeIds.Contains(x.TeamDid))
  32743. .OrderByDescending(x => x.VisitDate)
  32744. .Select(x => new
  32745. {
  32746. x.Id,
  32747. x.TeamName,
  32748. HasChildData = SqlFunc.Subqueryable<Grp_ConferenceProcedures>()
  32749. .Where(child => child.DiId == x.Id)
  32750. .Any() // 判断子表是否存在数据
  32751. })
  32752. .ToListAsync();
  32753. var conferenceProceduresList = await _sqlSugar.Queryable<Grp_ConferenceProcedures>()
  32754. .Where(x => x.DiId == targetGroup.Id && x.IsDel == 0)
  32755. .Select(x => new { x.Id, x.Title, x.DataDetails, x.Details, x.Remark })
  32756. .ToListAsync();
  32757. if (!conferenceProceduresList.Any())
  32758. {
  32759. conferenceProceduresList = await _sqlSugar.Queryable<Grp_ConferenceProcedures>()
  32760. .Where(x => x.DiId == -1 && x.IsDel == 0)
  32761. .Select(x => new { x.Id, x.Title, x.DataDetails, x.Details, x.Remark })
  32762. .ToListAsync();
  32763. }
  32764. var conferenceProceduresGroupByTitle = conferenceProceduresList
  32765. .GroupBy(x => x.Title)
  32766. .Select(x => new
  32767. {
  32768. title = x.Key,
  32769. itmes = x.Select(y => new
  32770. {
  32771. y.Id,
  32772. y.DataDetails,
  32773. y.Details,
  32774. y.Remark
  32775. }).ToList()
  32776. })
  32777. .ToList();
  32778. var response = new
  32779. {
  32780. GroupInfo = new
  32781. {
  32782. targetGroup.Id,
  32783. targetGroup.TeamName,
  32784. targetGroup.VisitDate,
  32785. targetGroup.VisitDays,
  32786. targetGroup.VisitPNumber,
  32787. targetGroup.VisitCountry,
  32788. targetGroup.VisitStartDate,
  32789. targetGroup.VisitEndDate,
  32790. targetGroup.ClientName,
  32791. targetGroup.ClientUnit
  32792. },
  32793. GroupList = groupList,
  32794. ConferenceProceduresList = conferenceProceduresList,
  32795. conferenceProceduresGroupByTitle = conferenceProceduresGroupByTitle
  32796. };
  32797. return Ok(JsonView(true, "SUCCESS", response));
  32798. }
  32799. catch (Exception ex)
  32800. {
  32801. _logger.LogError(ex, "数据初始化失败");
  32802. return Ok(JsonView(false, $"ERROR:{ex.Message}"));
  32803. }
  32804. }
  32805. /// <summary>
  32806. /// 会务流程 - 保存
  32807. /// </summary>
  32808. /// <param name="dto"></param>
  32809. /// <returns></returns>
  32810. [HttpPost]
  32811. public async Task<IActionResult> ConferenceProceduresSave(ConferenceProceduresSaveDto dto)
  32812. {
  32813. _sqlSugar.BeginTran();
  32814. try
  32815. {
  32816. //删除旧数据
  32817. _sqlSugar.Updateable<Grp_ConferenceProcedures>()
  32818. .Where(x => x.DiId == dto.GroupId && x.IsDel == 0)
  32819. .SetColumns(x => new Grp_ConferenceProcedures
  32820. {
  32821. IsDel = 1,
  32822. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  32823. DeleteUserId = dto.UserId
  32824. })
  32825. .ExecuteCommand();
  32826. //添加新数据
  32827. var newData = new List<Grp_ConferenceProcedures>();
  32828. foreach (var item in dto.ConferenceProceduresSaveItem)
  32829. {
  32830. foreach (var item2 in item.itmes)
  32831. {
  32832. newData.Add(new Grp_ConferenceProcedures
  32833. {
  32834. DiId = dto.GroupId,
  32835. Title = item.title,
  32836. DataDetails = item2.DataDetails,
  32837. Details = item2.details,
  32838. Remark = item2.Remark,
  32839. CreateTime = DateTime.Now,
  32840. CreateUserId = dto.UserId
  32841. });
  32842. }
  32843. }
  32844. _sqlSugar.Insertable(newData).ExecuteCommand();
  32845. _sqlSugar.CommitTran();
  32846. }
  32847. catch (Exception ex)
  32848. {
  32849. _sqlSugar.RollbackTran();
  32850. return Ok(JsonView(false, $"ERROR:{ex.Message}"));
  32851. }
  32852. return Ok(JsonView(true, "SUCCESS"));
  32853. }
  32854. [HttpPost]
  32855. public async Task<IActionResult> ConferenceProceduresFileDown(ConferenceProceduresFileDownDto dto)
  32856. {
  32857. var jw = JsonView(false, "团组信息不存在");
  32858. jw.Data = string.Empty;
  32859. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  32860. .Where(x => x.Id == dto.GroupId && x.IsDel == 0)
  32861. .FirstAsync();
  32862. if (groupInfo == null)
  32863. {
  32864. return Ok(jw);
  32865. }
  32866. var conferenceProceduresList = await _sqlSugar.Queryable<Grp_ConferenceProcedures>()
  32867. .Where(x => x.DiId == dto.GroupId && x.IsDel == 0)
  32868. .ToListAsync();
  32869. if (!conferenceProceduresList.Any())
  32870. {
  32871. jw.Msg = "会务流程信息不存在";
  32872. return Ok(jw);
  32873. }
  32874. var filePath = $"{AppSettingsHelper.Get("ExcelBasePath")}Template/会务流程.xlsx";
  32875. if (!System.IO.File.Exists(filePath))
  32876. {
  32877. jw.Msg = "模板文件不存在";
  32878. return Ok(jw);
  32879. }
  32880. var designer = new WorkbookDesigner();
  32881. designer.Workbook = new Workbook(filePath);
  32882. designer.SetDataSource("TB", conferenceProceduresList);
  32883. designer.Process();
  32884. var sheet = designer.Workbook.Worksheets[0];
  32885. var cells = sheet.Cells;
  32886. int col = 0; // 第一列
  32887. int startRow = 2; // 若第0行为表头,则从第1行开始;无表头请改为0
  32888. int endRow = cells.MaxDataRow;
  32889. if (endRow >= startRow)
  32890. {
  32891. int mergeStart = startRow;
  32892. string prev = cells[mergeStart, col].StringValue?.Trim() ?? string.Empty;
  32893. for (int r = startRow + 1; r <= endRow; r++)
  32894. {
  32895. string cur = cells[r, col].StringValue?.Trim() ?? string.Empty;
  32896. if (!string.Equals(cur, prev, StringComparison.Ordinal))
  32897. {
  32898. int count = r - mergeStart;
  32899. if (count > 1)
  32900. cells.Merge(mergeStart, col, count, 1);
  32901. mergeStart = r;
  32902. prev = cur;
  32903. }
  32904. }
  32905. int tailCount = endRow - mergeStart + 1;
  32906. if (tailCount > 1)
  32907. cells.Merge(mergeStart, col, tailCount, 1);
  32908. }
  32909. // byte[] bytes = null;
  32910. // using (MemoryStream stream = new MemoryStream())
  32911. // {
  32912. // designer.Workbook.Save(stream, Aspose.Cells.SaveFormat.Xlsx);
  32913. // bytes = stream.ToArray();
  32914. // }
  32915. // return File(bytes, "application/excel", $"{groupInfo.TeamName}_会务流程.xlsx");
  32916. string savePath = $"{AppSettingsHelper.Get("ExcelBasePath")}ConferenceProcedures";
  32917. if (!System.IO.Directory.Exists(savePath))
  32918. {
  32919. System.IO.Directory.CreateDirectory(savePath);
  32920. }
  32921. designer.Workbook.Save($"{savePath}/{groupInfo.TeamName}_会务流程.xlsx");
  32922. string rst = savePath.replace(AppSettingsHelper.Get("ExcelBasePath"),
  32923. AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath"));
  32924. return Ok(JsonView(true, "SUCCESS", $"{rst}/{groupInfo.TeamName}_会务流程.xlsx"));
  32925. }
  32926. #endregion
  32927. #region 团组签证流程
  32928. /// <summary>
  32929. /// 团组签证流程 - 团组列表(分页)
  32930. /// </summary>
  32931. /// <returns></returns>
  32932. [HttpPost]
  32933. public async Task<IActionResult> VisaProcessGroupNames(VisaProcessGroupNamesDto dto)
  32934. {
  32935. int currUserId = dto.CurrUserId <= 0 ? 1 : dto.CurrUserId;
  32936. string groupName = dto.GroupName.Trim();
  32937. int pageIndex = dto.PageIndex <= 0 ? 1 : dto.PageIndex;
  32938. int pageSize = dto.PageSize <= 0 ? 10 : dto.PageSize;
  32939. int portType = dto.PortType;
  32940. RefAsync<int> total = 0;
  32941. var query = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>()
  32942. .InnerJoin<Grp_DelegationInfo>((x, y) => x.DIId == y.Id)
  32943. .InnerJoin<Grp_VisaProcessSteps>((x, y, z) => x.DIId == z.GroupId)
  32944. .Where((x, y, z) => x.IsDel == 0 && x.CTId == 80 && x.UId == currUserId && z.IsDel == 0);
  32945. //构建单字模糊查询
  32946. if (!string.IsNullOrEmpty(groupName))
  32947. {
  32948. var characters = groupName.ToCharArray();
  32949. foreach (var character in characters)
  32950. {
  32951. var charString = character.ToString();
  32952. query = query.Where((x, y) =>
  32953. SqlFunc.Contains(y.TeamName, charString));
  32954. }
  32955. }
  32956. var groups = await query
  32957. .OrderByDescending((x, y) => y.VisitDate)
  32958. .Select((x, y) => new
  32959. {
  32960. y.Id,
  32961. GroupName = y.TeamName,
  32962. y.VisitDate,
  32963. // 加入子查询统计子表条数
  32964. CompletedCount = SqlFunc.Subqueryable<Grp_VisaProcessSteps>()
  32965. .Where(sub => sub.GroupId == y.Id && sub.IsCompleted && sub.IsDel == 0)
  32966. .Count()
  32967. })
  32968. .Distinct()
  32969. .ToPageListAsync(pageIndex, pageSize, total);
  32970. var msg = "SUCCESS";
  32971. if (total <= 0) msg = "暂无可操作的团组,请联系经理分配团组!";
  32972. var groups1 = groups.Select(x => new
  32973. {
  32974. x.Id,
  32975. x.GroupName,
  32976. x.CompletedCount
  32977. }).ToList();
  32978. return Ok(JsonView(true, msg, groups1, total));
  32979. }
  32980. /// <summary>
  32981. /// 团组签证流程 - 详情
  32982. /// </summary>
  32983. /// <returns></returns>
  32984. [HttpPost]
  32985. public async Task<IActionResult> VisaProcessInfoByGroupId(VisaProcessInfoByGroupIdDto dto)
  32986. {
  32987. var res = await _visaProcessRep.Info(dto);
  32988. if (res.Code != 200) return Ok(JsonView(false, res.Msg));
  32989. return Ok(JsonView(true, res.Msg, res.Data));
  32990. }
  32991. /// <summary>
  32992. /// 团组签证流程 - 流程创建测试
  32993. /// </summary>
  32994. /// <returns></returns>
  32995. [HttpPost]
  32996. public async Task<IActionResult> VisaProcessAdd(int groupId, int currUserId)
  32997. {
  32998. return Ok(await _visaProcessRep.Create(currUserId, groupId));
  32999. }
  33000. /// <summary>
  33001. /// 团组签证流程 - 流程Top4Init 测试
  33002. /// </summary>
  33003. /// <returns></returns>
  33004. [HttpPost]
  33005. public async Task<IActionResult> VisaProcessTop4StepInit(int groupId, int currUserId)
  33006. {
  33007. return Ok(await _visaProcessRep.UpdateBatchTop4Step(groupId, currUserId));
  33008. }
  33009. /// <summary>
  33010. /// 团组签证流程 - 设置状态 完成/未完成
  33011. /// </summary>
  33012. /// <returns></returns>
  33013. [HttpPost]
  33014. public async Task<IActionResult> VisaProcessSetCompleted(VisaProcessSetCompletedDto dto)
  33015. {
  33016. //参数验证
  33017. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.Id == dto.StepId && x.IsDel == 0).AnyAsync();
  33018. if (!stepValid) return Ok(JsonView(false, "签证流程ID无效。"));
  33019. var userValid = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == dto.CurrUserId && x.IsDel == 0).AnyAsync();
  33020. if (!userValid) return Ok(JsonView(false, "用户ID无效。"));
  33021. var res = await _visaProcessRep.SetCompleted(dto.StepId, dto.CurrUserId, dto.IsCompleted);
  33022. if (res.Code != 200) return Ok(JsonView(false, res.Msg));
  33023. return Ok(JsonView(true, res.Msg));
  33024. }
  33025. /// <summary>
  33026. /// 团组签证流程 - 修改各步骤内容
  33027. /// </summary>
  33028. /// <returns></returns>
  33029. [HttpPost]
  33030. public async Task<IActionResult> VisaProcessSetContent(VisaProcessSetContent dto)
  33031. {
  33032. //参数验证
  33033. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.Id == dto.StepId && x.IsDel == 0).FirstAsync();
  33034. if (stepValid == null) return Ok(JsonView(false, "签证流程ID无效。"));
  33035. var userValid = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == dto.CurrUserId && x.IsDel == 0).AnyAsync();
  33036. if (!userValid) return Ok(JsonView(false, "用户ID无效。"));
  33037. if (dto.StepContents == null && dto.StepContents.Count < 1)
  33038. {
  33039. return Ok(JsonView(false, "步骤内容无效。"));
  33040. }
  33041. //各步骤值处理
  33042. object stepVal;
  33043. if (stepValid.Step == 7) stepVal = dto.StepContents;
  33044. else stepVal = dto.StepContents[0].ToString();
  33045. var stepInfo = new Grp_VisaProcessSteps
  33046. {
  33047. Id = dto.StepId,
  33048. DataType = stepValid.DataType,
  33049. TypedValue = stepVal,
  33050. LastUpdateUserId = dto.CurrUserId
  33051. };
  33052. var res = await _visaProcessRep.Update(stepInfo);
  33053. if (res.Code != 200) return Ok(JsonView(false, res.Msg));
  33054. return Ok(JsonView(true, res.Msg));
  33055. }
  33056. /// <summary>
  33057. /// 团组签证流程 - 上传文件
  33058. /// </summary>
  33059. /// <returns></returns>
  33060. [HttpPost]
  33061. public async Task<IActionResult> VisaProcessUploadFiles([FromForm] VisaProcessUploadFilesDto dto)
  33062. {
  33063. //参数验证
  33064. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.Id == dto.StepId && x.IsDel == 0).FirstAsync();
  33065. if (stepValid == null) return Ok(JsonView(false, "签证流程ID无效。"));
  33066. var before = stepValid;
  33067. var userValid = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == dto.CurrUserId && x.IsDel == 0).AnyAsync();
  33068. if (!userValid) return Ok(JsonView(false, "用户ID无效。"));
  33069. //验证文件是否存在
  33070. if (dto.Files == null || dto.Files.Count < 1) return Ok(JsonView(false, "请选择文件。"));
  33071. //验证该步骤是否可以上传文件
  33072. var uploadSteps = new List<int>() {
  33073. 5, //实际出签时间
  33074. 6, //是否需要开出境证明
  33075. 7, //是否需要办理电子入境卡手续
  33076. };
  33077. if (!uploadSteps.Contains(stepValid.Step))
  33078. {
  33079. return Ok(JsonView(false, $"该步骤不可上传附件。可上传附件步骤({string.Join("、", uploadSteps)})"));
  33080. }
  33081. //验证根目录
  33082. string rootRrl = AppSettingsHelper.Get("OfficeBaseUrl");
  33083. string rootPath = AppSettingsHelper.Get("OfficeTempBasePath");
  33084. if (!System.IO.Directory.Exists(rootPath))
  33085. {
  33086. System.IO.Directory.CreateDirectory(rootPath);
  33087. }
  33088. //验证签证流程上传文件夹 //按照团组名称存储文件夹 GrpFile/VisaProcessFiles/
  33089. var groupName = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  33090. .Where(x => x.IsDel == 0 && x.Id == stepValid.GroupId)
  33091. .Select(x => $"{x.TeamName}({x.Id})")
  33092. .FirstAsync();
  33093. //创建团组文件夹
  33094. var groupPath = rootPath + "GrpFile/VisaProcessFiles/" + groupName;
  33095. if (!System.IO.Directory.Exists(groupPath))
  33096. {
  33097. System.IO.Directory.CreateDirectory(groupPath);
  33098. }
  33099. List<string> filePaths = new List<string>();
  33100. //保存文件
  33101. foreach (var file in dto.Files)
  33102. {
  33103. // 生成存储文件名
  33104. var fileName = CommonFun.GenerateStoredFileName($"Step{stepValid.Step}.{file.FileName.Split(".")[1]}");
  33105. var filePath = Path.Combine(groupPath, fileName);
  33106. // 保存文件到磁盘
  33107. using (var stream = new FileStream(filePath, FileMode.Create))
  33108. {
  33109. await file.CopyToAsync(stream);
  33110. }
  33111. filePaths.Add($"GrpFile/VisaProcessFiles/{groupName}/{fileName}");
  33112. }
  33113. //数据库存储
  33114. stepValid.TypedFileNameValue = filePaths;
  33115. stepValid.LastUpdateUserId = dto.CurrUserId;
  33116. stepValid.LastUpdateTime = DateTime.Now;
  33117. var res = await _sqlSugar.Updateable(stepValid)
  33118. .UpdateColumns(it => new { it.TypedFileNameValue, it.LastUpdateUserId, it.LastUpdateTime })
  33119. .Where(s => s.Id == dto.StepId && s.IsDel == 0)
  33120. .ExecuteCommandAsync();
  33121. if (res < 1) Ok(JsonView(false, "文件上传失败。"));
  33122. //记录上传文件
  33123. await _visaProcessRep.LogOperationAsync(before, stepValid, "Upload", dto.CurrUserId);
  33124. return Ok(JsonView(true));
  33125. }
  33126. /// <summary>
  33127. /// 团组签证流程 - step 7 资料下载
  33128. /// </summary>
  33129. /// <returns></returns>
  33130. [HttpGet]
  33131. public async Task<IActionResult> VisaProcessDownload(int groupId, int currUserId)
  33132. {
  33133. var userValid = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == currUserId && x.IsDel == 0).AnyAsync();
  33134. if (!userValid) return Ok(JsonView(false, "用户ID无效。"));
  33135. //验证根目录
  33136. string rootRrl = AppSettingsHelper.Get("OfficeBaseUrl");
  33137. string rootPath = AppSettingsHelper.Get("OfficeTempBasePath");
  33138. if (!System.IO.Directory.Exists(rootPath))
  33139. {
  33140. System.IO.Directory.CreateDirectory(rootPath);
  33141. }
  33142. //验证签证流程上传文件夹 //按照团组名称存储文件夹 GrpFile/VisaProcessFiles/
  33143. var groupName = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  33144. .Where(x => x.IsDel == 0 && x.Id == groupId)
  33145. .Select(x => $"{x.TeamName}({x.Id})")
  33146. .FirstAsync();
  33147. //创建团组文件夹
  33148. var timestamp = DateTime.Now.ToString("yyyyMMddHHmmss");
  33149. var randomStr = Guid.NewGuid().ToString("N").Substring(0, 8);
  33150. var dirName = $"{groupName}_相关资料_{timestamp}";
  33151. var sourceDirectoryPath = $"{rootPath}/GrpFile/VisaProcessFiles/{groupName}";
  33152. var path = $"{rootPath}/GrpFile/VisaProcessFiles/{groupName}/{dirName}";
  33153. if (!System.IO.Directory.Exists(path))
  33154. {
  33155. System.IO.Directory.CreateDirectory(path);
  33156. }
  33157. //验证接团客户名单
  33158. string sql = string.Format(@"
  33159. SELECT
  33160. tcl.Id,
  33161. tcl.DiId,
  33162. tcl.IsAccompany,
  33163. temp.*,
  33164. u.CnName AS Operator,
  33165. tcl.CreateTime AS OperatingTime,
  33166. ssd.name AS ShippingSpaceType
  33167. FROM
  33168. Grp_TourClientList tcl
  33169. LEFT JOIN (
  33170. SELECT
  33171. dc.Id AS DcId,
  33172. dc.LastName,
  33173. dc.FirstName,
  33174. ccom.CompanyFullName,
  33175. dc.Job,
  33176. cc.CertNo AS IDCardNo,
  33177. dc.Sex,
  33178. dc.BirthDay
  33179. FROM
  33180. Crm_DeleClient dc
  33181. LEFT JOIN Crm_CustomerCompany ccom ON dc.CrmCompanyId = ccom.Id
  33182. AND ccom.IsDel = 0
  33183. LEFT JOIN Crm_CustomerCert cc ON dc.Id = cc.DcId
  33184. AND cc.SdId = 773
  33185. AND cc.IsDel = 0
  33186. WHERE
  33187. dc.IsDel = 0
  33188. ) temp ON temp.DcId = tcl.ClientId
  33189. LEFT JOIN Sys_Users u ON tcl.CreateUserId = u.Id
  33190. LEFT JOIN sys_setdata ssd ON ssd.isdel = 0 AND ssd.id = tcl.ShippingSpaceTypeid
  33191. WHERE
  33192. tcl.IsDel = 0
  33193. AND tcl.DiId = {0}", groupId);
  33194. var groupClientList = await _sqlSugar.SqlQueryable<TourClientInfosView>(sql).ToListAsync();
  33195. //解密
  33196. foreach (var item in groupClientList)
  33197. {
  33198. EncryptionProcessor.DecryptProperties(item);
  33199. }
  33200. if (groupClientList == null || groupClientList.Count < 1)
  33201. {
  33202. return Ok(JsonView(false, $"团组客户名单未录入客户信息,不可生成相关资料。"));
  33203. }
  33204. #region 生成文件
  33205. //酒店信息
  33206. var hotelInfos = await _sqlSugar.Queryable<Grp_HotelReservations>()
  33207. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  33208. .OrderBy(x => x.CheckInDate)
  33209. .ToListAsync();
  33210. //航班信息
  33211. var airInfos = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  33212. .Where(x => x.IsDel == 0 && x.DIId == groupId)
  33213. .OrderBy(x => x.FlightsDate)
  33214. .ToListAsync();
  33215. foreach (var clientInfo in groupClientList)
  33216. {
  33217. var clientId = clientInfo.DcId;
  33218. var guestName = $"{clientInfo.LastName}{clientInfo.FirstName}";
  33219. #region 个人信息资料
  33220. #endregion
  33221. #region 机票航班信息
  33222. var clientAirInfos = airInfos.Where(x => x.ClientName.Contains(clientId.ToString())).ToList();
  33223. if (clientAirInfos != null && clientAirInfos.Count > 0)
  33224. {
  33225. //创建表格
  33226. Document airDoc = new Document();
  33227. DocumentBuilder airBuilder = new DocumentBuilder(airDoc);
  33228. GeneralMethod.SetupDocumentStyles(airBuilder);
  33229. GeneralMethod.AddTitle(airBuilder, $"{guestName} - 机票信息");
  33230. GeneralMethod.AddAirInfoSections(airBuilder, clientAirInfos, "机票航班信息");
  33231. var airRandomStr = Guid.NewGuid().ToString("N").Substring(0, 8);
  33232. var airFileName = $"{guestName}_机票信息_{airRandomStr}.docx";
  33233. airDoc.Save($"{path}/{airFileName}");
  33234. }
  33235. #endregion
  33236. #region 酒店信息
  33237. var clientHotelInfos = hotelInfos.Where(x => x.GuestName.Contains(clientId.ToString())).ToList();
  33238. if (clientHotelInfos != null && clientHotelInfos.Count > 0)
  33239. {
  33240. //创建表格
  33241. Document hotelDoc = new Document();
  33242. DocumentBuilder HotelBuilder = new DocumentBuilder(hotelDoc);
  33243. GeneralMethod.SetupDocumentStyles(HotelBuilder);
  33244. GeneralMethod.AddTitle(HotelBuilder, $"{guestName} - 酒店信息");
  33245. GeneralMethod.AddHotelInfoSections(HotelBuilder, clientHotelInfos, "酒店信息");
  33246. var hotelRandomStr = Guid.NewGuid().ToString("N").Substring(0, 8);
  33247. var hotelFileName = $"{guestName}_酒店信息_{hotelRandomStr}.docx";
  33248. hotelDoc.Save($"{path}/{hotelFileName}");
  33249. }
  33250. #endregion
  33251. }
  33252. #endregion
  33253. //打包文件夹
  33254. var sourceDirectory = $"{sourceDirectoryPath}/{dirName}";
  33255. var zipFilePath = $"{sourceDirectoryPath}/{dirName}.zip";
  33256. if (System.IO.File.Exists(zipFilePath))
  33257. {
  33258. System.IO.File.Delete(zipFilePath);
  33259. }
  33260. ZipFile.CreateFromDirectory(sourceDirectory, zipFilePath, CompressionLevel.Fastest, false);
  33261. // 等待并验证
  33262. await Task.Delay(100); // 给系统时间完成文件操作
  33263. if (System.IO.File.Exists(zipFilePath))
  33264. {
  33265. var fileInfo = new FileInfo(zipFilePath);
  33266. var url = $"{rootRrl}Office/GrpFile/VisaProcessFiles/{groupName}/{dirName}.zip";
  33267. //记录下载日志
  33268. await _visaProcessRep.LogOperationAsync(null, null, "Download", currUserId);
  33269. return Ok(JsonView(StatusCodes.Status200OK, "操作成功!", url));
  33270. }
  33271. return Ok(JsonView(false));
  33272. }
  33273. /// <summary>
  33274. /// 团组签证流程 - 根据步骤记录ID获取该步骤的所有操作日志
  33275. /// </summary>
  33276. /// <returns></returns>
  33277. [HttpGet]
  33278. public async Task<IActionResult> VisaProcessLogByStepId(int stepId)
  33279. {
  33280. //参数验证
  33281. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.Id == stepId && x.IsDel == 0).FirstAsync();
  33282. if (stepValid == null) return Ok(JsonView(false, "签证流程ID无效。"));
  33283. var logs = await _visaProcessRep.GetStepLogsAsync(stepId);
  33284. return Ok(JsonView(logs));
  33285. }
  33286. /// <summary>
  33287. /// 团组签证流程 - 根据团组ID获取该团组下所有步骤的操作日志
  33288. /// </summary>
  33289. /// <returns></returns>
  33290. [HttpGet]
  33291. public async Task<IActionResult> VisaProcessLogByGroupId(int groupId)
  33292. {
  33293. //参数验证
  33294. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.GroupId == groupId && x.IsDel == 0).FirstAsync();
  33295. if (stepValid == null) return Ok(JsonView(false, "团组ID无效。"));
  33296. var logs = await _visaProcessRep.GetGroupStepLogsAsync(groupId);
  33297. return Ok(JsonView(logs));
  33298. }
  33299. #endregion
  33300. #region 团组总览进程
  33301. /// <summary>
  33302. /// 团组总览进程 - 流程创建测试
  33303. /// </summary>
  33304. /// <returns></returns>
  33305. [HttpGet]
  33306. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  33307. public async Task<IActionResult> GroupProcessInitTest(int groupId, int currUserId)
  33308. {
  33309. return Ok(await _processOverviewRep.ProcessInitAsync(groupId, currUserId));
  33310. }
  33311. /// <summary>
  33312. /// 团组总览进程 - 团组名称集合
  33313. /// </summary>
  33314. /// <returns></returns>
  33315. [HttpGet()]
  33316. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  33317. public async Task<IActionResult> GroupProcessGroupNames()
  33318. {
  33319. var groupNames = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  33320. .Where(x => x.IsDel == 0)
  33321. .OrderByDescending(x => x.VisitDate)
  33322. .Select(x => new
  33323. {
  33324. x.Id,
  33325. GroupName = x.TeamName,
  33326. HasProcess = SqlFunc.Subqueryable<Grp_ProcessOverview>()
  33327. .Where(po => po.GroupId == x.Id && po.IsDel == 0)
  33328. .Any()
  33329. })
  33330. .ToListAsync();
  33331. return Ok(JsonView(groupNames));
  33332. }
  33333. /// <summary>
  33334. /// 团组总览进程 - 流程详情
  33335. /// </summary>
  33336. /// <returns></returns>
  33337. [HttpGet]
  33338. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  33339. public async Task<IActionResult> GroupProcessDetails(int groupId)
  33340. {
  33341. var res = await _processOverviewRep.ProcessesDetailsAsync(groupId);
  33342. if (res.Code == StatusCodes.Status200OK)
  33343. {
  33344. return Ok(JsonView(res.Data));
  33345. }
  33346. return Ok(JsonView(false, res.Msg));
  33347. }
  33348. /// <summary>
  33349. /// 团组总览进程 - 更新节点状态
  33350. /// </summary>
  33351. /// <returns></returns>
  33352. [HttpPost]
  33353. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  33354. public async Task<IActionResult> GroupProcessUpdateNodeStatus(GroupProcessUpdateNodeStatusDto dto)
  33355. {
  33356. var res = await _processOverviewRep.UpdateNodeStatusSimpleAsync(dto.NodeId, dto.CurrUserId);
  33357. if (res.Code == StatusCodes.Status200OK)
  33358. {
  33359. return Ok(JsonView(res.Data));
  33360. }
  33361. return Ok(JsonView(false, res.Msg));
  33362. }
  33363. /// <summary>
  33364. /// 团组总览进程 - 更新签证节点信息
  33365. /// </summary>
  33366. /// <returns></returns>
  33367. [HttpPost]
  33368. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  33369. public async Task<IActionResult> GroupProcessUpdateVisaNodeDetails(GroupProcessUpdateVisaNodeDetailsDto dto)
  33370. {
  33371. //验证签证信息
  33372. if (dto.VisaSubNodes.Count < 1) return Ok(JsonView(false, "请传入有效的签证节点信息。"));
  33373. var res = await _processOverviewRep.UpdateVisaNodeDetailsAsync(dto);
  33374. if (res.Code == StatusCodes.Status200OK)
  33375. {
  33376. return Ok(JsonView(res.Data));
  33377. }
  33378. return Ok(JsonView(false, res.Msg));
  33379. }
  33380. /// <summary>
  33381. /// 团组总览进程 - 设置实际完成时间
  33382. /// </summary>
  33383. /// <returns></returns>
  33384. [HttpPost]
  33385. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  33386. public async Task<IActionResult> GroupProcessSetActualDone(GroupProcessSetActualDoneDto dto)
  33387. {
  33388. //验证签证信息
  33389. var res = await _processOverviewRep.SetActualDoneAsync(dto);
  33390. if (res.Code == StatusCodes.Status200OK)
  33391. {
  33392. return Ok(JsonView(res.Data));
  33393. }
  33394. return Ok(JsonView(false, res.Msg));
  33395. }
  33396. #endregion
  33397. #region 团组会务总览进程
  33398. /// <summary>
  33399. /// 团组会务总览进程 - 流程创建测试
  33400. /// </summary>
  33401. /// <returns></returns>
  33402. [HttpGet]
  33403. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  33404. public async Task<IActionResult> ConfProcessInitTest(int groupId, int currUserId)
  33405. {
  33406. return Ok(await _processOverviewRep.ProcessInitAsync(groupId, currUserId));
  33407. }
  33408. /// <summary>
  33409. /// 团组会务总览进程 - 基础信息集合(团组名称、参与人信息)
  33410. /// </summary>
  33411. /// <returns></returns>
  33412. [HttpGet]
  33413. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  33414. public async Task<IActionResult> ConfProcessGroupNames()
  33415. {
  33416. var groupTypes = new List<int>() {
  33417. 302, // 成都-会务活动
  33418. 691, // 四川-会务活动
  33419. 762, // 四川-赛事项目收入
  33420. 1047 // 成都-赛事项目收入
  33421. };
  33422. var groupNames = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  33423. .Where(x => x.IsDel == 0 && groupTypes.Contains(x.TeamDid))
  33424. .OrderByDescending(x => x.VisitDate)
  33425. .Select(x => new
  33426. {
  33427. x.Id,
  33428. GroupName = x.TeamName,
  33429. HasProcess = SqlFunc.Subqueryable<Grp_ConfProcessOverview>()
  33430. .Where(po => po.GroupId == x.Id && po.IsDel == 0)
  33431. .Any()
  33432. })
  33433. .ToListAsync();
  33434. var participators = await _sqlSugar.Queryable<Sys_Users>()
  33435. .Where(x => x.IsDel == 0 && x.DepId == 5)
  33436. .Select(x => new ParticipatorInfo()
  33437. {
  33438. UserId = x.Id,
  33439. UserName = x.CnName
  33440. })
  33441. .ToListAsync();
  33442. var view = new { groupNames, participators };
  33443. return Ok(JsonView(view));
  33444. }
  33445. /// <summary>
  33446. /// 团组会务总览进程 - 获取节点模板信息
  33447. /// </summary>
  33448. /// <returns></returns>
  33449. [HttpGet]
  33450. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  33451. public async Task<IActionResult> ConfProcessNodeTempInfos(int groupId, int currUserId)
  33452. {
  33453. var nodeTemps1 = await _processOverviewRep.DefaultConfProcessTemps(groupId, currUserId);
  33454. var nodeTemps = nodeTemps1.Select(x => new
  33455. {
  33456. TempId = x.ProcessOrder,
  33457. TempName = $"情况{x.ProcessOrder}",
  33458. //TempNodes = x.Nodes
  33459. }).ToList();
  33460. return Ok(JsonView(nodeTemps));
  33461. }
  33462. /// <summary>
  33463. /// 团组会务总览进程 - 更新节点模板
  33464. /// </summary>
  33465. /// <param name="groupId">团组Id</param>
  33466. /// <param name="nodeTempId">节点模板Id</param>
  33467. /// <param name="currUserId">当前用户Id</param>
  33468. /// <returns></returns>
  33469. [HttpGet]
  33470. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  33471. public async Task<IActionResult> ConfProcessChangeNodeTempSave(int groupId, int nodeTempId, int currUserId)
  33472. {
  33473. var res = await _processOverviewRep.ConfProcessChangeNodeTempSaveAsync(groupId, nodeTempId, currUserId);
  33474. if (res.Code == StatusCodes.Status200OK)
  33475. {
  33476. return Ok(JsonView(res.Data));
  33477. }
  33478. return Ok(JsonView(false, res.Msg));
  33479. }
  33480. /// <summary>
  33481. /// 团组会务总览进程 - 流程详情
  33482. /// </summary>
  33483. /// <param name="groupId">团组Id</param>
  33484. /// <param name="currUserId">当前userId</param>
  33485. /// <returns></returns>
  33486. [HttpGet]
  33487. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  33488. public async Task<IActionResult> ConfProcessDetails(int groupId, int currUserId)
  33489. {
  33490. var res = await _processOverviewRep.ConfProcessesDetailsAsync(groupId, currUserId);
  33491. if (res.Code == StatusCodes.Status200OK)
  33492. {
  33493. return Ok(JsonView(res.Data));
  33494. }
  33495. return Ok(JsonView(false, res.Msg));
  33496. }
  33497. /// <summary>
  33498. /// 团组会务总览进程 - 更新节点状态
  33499. /// </summary>
  33500. /// <returns></returns>
  33501. [HttpPost]
  33502. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  33503. public async Task<IActionResult> ConfProcessUpdateNodeStatus(GroupProcessUpdateNodeStatusDto dto)
  33504. {
  33505. var res = await _processOverviewRep.UpdateConfNodeStatusAsync(dto.NodeId, dto.CurrUserId);
  33506. if (res.Code == StatusCodes.Status200OK)
  33507. {
  33508. return Ok(JsonView(res.Data));
  33509. }
  33510. return Ok(JsonView(false, res.Msg));
  33511. }
  33512. /// <summary>
  33513. /// 团组会务总览进程 - 设置实际完成时间及其他信息
  33514. /// </summary>
  33515. /// <returns></returns>
  33516. [HttpPost]
  33517. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  33518. public async Task<IActionResult> ConfProcessSetActualDone(ConfProcessSetActualDoneDto dto)
  33519. {
  33520. var res = await _processOverviewRep.SetNodeInfoAsync(dto);
  33521. if (res.Code == StatusCodes.Status200OK)
  33522. {
  33523. return Ok(JsonView(res.Data));
  33524. }
  33525. return Ok(JsonView(false, res.Msg));
  33526. }
  33527. #endregion
  33528. }
  33529. }