GroupsController.cs 1.8 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644
  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 NetUV.Core.Requests;
  13. using NPOI.OpenXmlFormats.Wordprocessing;
  14. using NPOI.SS.Formula.Functions;
  15. using NPOI.SS.UserModel;
  16. using NPOI.SS.Util;
  17. using NPOI.XSSF.UserModel;
  18. using OASystem.API.Middlewares;
  19. using OASystem.API.OAMethodLib;
  20. using OASystem.API.OAMethodLib.APNs;
  21. using OASystem.API.OAMethodLib.DeepSeekAPI;
  22. using OASystem.API.OAMethodLib.File;
  23. using OASystem.API.OAMethodLib.GenericSearch;
  24. using OASystem.API.OAMethodLib.Hub.HubClients;
  25. using OASystem.API.OAMethodLib.Hub.Hubs;
  26. using OASystem.API.OAMethodLib.JuHeAPI;
  27. using OASystem.API.OAMethodLib.KiMiApi;
  28. using OASystem.API.OAMethodLib.QiYeWeChatAPI.AppNotice;
  29. using OASystem.Domain.AesEncryption;
  30. using OASystem.Domain.Attributes;
  31. using OASystem.Domain.Dtos.CRM;
  32. using OASystem.Domain.Dtos.FileDto;
  33. using OASystem.Domain.Dtos.Financial;
  34. using OASystem.Domain.Dtos.Groups;
  35. using OASystem.Domain.Entities.Customer;
  36. using OASystem.Domain.Entities.Financial;
  37. using OASystem.Domain.Entities.Groups;
  38. using OASystem.Domain.ViewModels.Financial;
  39. using OASystem.Domain.ViewModels.Groups;
  40. using OASystem.Domain.ViewModels.JuHeExchangeRate;
  41. using OASystem.Domain.ViewModels.OCR;
  42. using OASystem.Domain.ViewModels.QiYeWeChat;
  43. using OASystem.Domain.ViewModels.Statistics;
  44. using OASystem.Infrastructure.Logging;
  45. using OASystem.Infrastructure.Repositories.CRM;
  46. using OASystem.Infrastructure.Repositories.Financial;
  47. using OASystem.Infrastructure.Repositories.Groups;
  48. using Quartz.Util;
  49. using SqlSugar.Extensions;
  50. using System.Collections;
  51. using System.ComponentModel.DataAnnotations;
  52. using System.Data;
  53. using System.Diagnostics;
  54. using System.Globalization;
  55. using System.IO.Compression;
  56. using System.Linq.Expressions;
  57. using System.Runtime.ConstrainedExecution;
  58. using System.Text.Json;
  59. using System.Web;
  60. using static OASystem.API.OAMethodLib.JWTHelper;
  61. using static OASystem.Infrastructure.Repositories.Groups.AirTicketResRepository;
  62. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  63. using Bookmark = Aspose.Words.Bookmark;
  64. using Cell = Aspose.Words.Tables.Cell;
  65. using Table = Aspose.Words.Tables.Table;
  66. using OASystem.Domain.Dtos.PersonnelModule;
  67. using OASystem.API.OAMethodLib.DoubaoAPI;
  68. namespace OASystem.API.Controllers
  69. {
  70. /// <summary>
  71. /// 团组相关
  72. /// </summary>
  73. //[Authorize]
  74. [Route("api/[controller]/[action]")]
  75. public class GroupsController : ControllerBase
  76. {
  77. private readonly ILogger<GroupsController> _logger;
  78. private readonly ITextFileLogger _eec_textLogger;
  79. private readonly IGroupTextFileLogger _groupTextLogger;
  80. private readonly GrpScheduleRepository _grpScheduleRep;
  81. private readonly IMapper _mapper;
  82. private readonly DelegationInfoRepository _groupRepository;
  83. private readonly TaskAssignmentRepository _taskAssignmentRep;
  84. private readonly AirTicketResRepository _airTicketResRep;
  85. private readonly DecreasePaymentsRepository _decreasePaymentsRep;
  86. private readonly InvitationOfficialActivitiesRepository _InvitationOfficialActivitiesRep;
  87. private readonly DelegationEnDataRepository _delegationEnDataRep;
  88. private readonly DelegationVisaRepository _delegationVisaRep;
  89. private readonly VisaPriceRepository _visaPriceRep;
  90. private readonly CarTouristGuideGroundRepository _carTouristGuideGroundRep;
  91. private readonly HotelPriceRepository _hotelPriceRep;
  92. private readonly CustomersRepository _customersRep;
  93. private readonly MessageRepository _message;
  94. private readonly SqlSugarClient _sqlSugar;
  95. private readonly TourClientListRepository _tourClientListRep;
  96. private readonly TeamRateRepository _teamRateRep;
  97. #region 成本相关
  98. private readonly CheckBoxsRepository _checkBoxs;
  99. private readonly GroupCostRepository _GroupCostRepository;
  100. private readonly CostTypeHotelNumberRepository _CostTypeHotelNumberRepository;
  101. private readonly GroupCostParameterRepository _GroupCostParameterRepository;
  102. #endregion
  103. private readonly IDoubaoService _doubaoService;
  104. private readonly SetDataRepository _setDataRep;
  105. private string url;
  106. private string path;
  107. private readonly EnterExitCostRepository _enterExitCostRep;
  108. private readonly IHubContext<ChatHub, IChatClient> _hubContext;
  109. private readonly UsersRepository _usersRep;
  110. private readonly IJuHeApiService _juHeApi;
  111. private readonly InvertedListRepository _invertedListRep;
  112. private readonly VisaFeeInfoRepository _visaFeeInfoRep;
  113. private readonly TicketBlackCodeRepository _ticketBlackCodeRep;
  114. private readonly ThreeCodeRepository _threeCodeRepository;
  115. private readonly HotelInquiryRepository _hotelInquiryRep;
  116. private readonly FeeAuditRepository _feeAuditRep;
  117. private readonly VisaCommissionRepository _visaCommissionRep;
  118. private readonly ForeignReceivablesRepository _ffrRep; //对外收款账单仓库
  119. private readonly OpinionaireRepository _opinionaireRep; //对外收款账单仓库
  120. private readonly List<CurrencyInfo> _currencyInit;
  121. private readonly List<int> _portTypeData;
  122. private readonly TableOperationRecordRepository _tableorRep;
  123. private readonly EnterExitCostDraftRepository _enterExitCostDraftRep;
  124. private readonly RestaurantRepository _restaurantRep;
  125. private readonly EnterExitCostQuoteRepository _enterExitCostQuoteRep;
  126. private readonly GroupOrderPreInfoRepository _grpOrderPreInfoRep;
  127. private readonly VisaProcessRepository _visaProcessRep;
  128. private readonly ProcessOverviewRepository _processOverviewRep;
  129. private readonly IDeepSeekService _deepSeekService;
  130. private readonly DynamicSearchService<Grp_DelegationInfo> _groupSearchService;
  131. /// <summary>
  132. /// 接送机默认报价系数
  133. /// </summary>
  134. public const decimal Def_AirportTransferCoeff = 2.50M;
  135. /// <summary>
  136. /// 接送机默认服务次数
  137. /// </summary>
  138. public const int Def_ServiceCount = 1;
  139. /// <summary>
  140. /// 火车默认报价系数
  141. /// </summary>
  142. public const decimal Def_TrainCoeff = 2.50M;
  143. /// <summary>
  144. /// 拉扯默认报价系数
  145. /// </summary>
  146. public const decimal Def_PullCartCoeff = 2.50M;
  147. /// <summary>
  148. /// 城市机票默认报价系数
  149. /// </summary>
  150. public const decimal Def_CityFlightCoeff = 2.50M;
  151. /// <summary>
  152. /// 初始化岗位对应负责的数据类型
  153. ///
  154. /// 岗位ID
  155. /// 24 机票、25 酒店、26 签证、27 商邀、28 OP
  156. ///
  157. /// 费用类型ID
  158. /// 76 酒店预订、79 车/导游地接、80 签证、81 邀请/公务活动、82 团组客户保险、85 机票预订、98 其他款项
  159. /// </summary>
  160. private readonly Dictionary<int, List<int>> _dataInit = new() {
  161. { 24, new List<int> { 85 } }, // 机票 -> 机票预订
  162. { 25, new List<int> { 76 } }, // 酒店 -> 酒店预订
  163. { 26, new List<int> { 80, 82 } }, // 签证 -> 签证, 团组客户保险
  164. { 27, new List<int> { 81 } }, // 地接 -> 邀请/公务活动
  165. { 28, new List<int> { 79 } } // 商邀 -> 车/导游地接
  166. };
  167. /// <summary>
  168. /// 构造函数
  169. /// </summary>
  170. /// <param name="logger"></param>
  171. /// <param name="eec_textLogger"></param>
  172. /// <param name="groupTextLogger"></param>
  173. /// <param name="mapper"></param>
  174. /// <param name="hubContext"></param>
  175. /// <param name="sqlSugar"></param>
  176. /// <param name="grpScheduleRep"></param>
  177. /// <param name="groupRepository"></param>
  178. /// <param name="taskAssignmentRep"></param>
  179. /// <param name="airTicketResRep"></param>
  180. /// <param name="decreasePaymentsRep"></param>
  181. /// <param name="InvitationOfficialActivitiesRep"></param>
  182. /// <param name="delegationEnDataRep"></param>
  183. /// <param name="enterExitCostRep"></param>
  184. /// <param name="delegationVisaRep"></param>
  185. /// <param name="message"></param>
  186. /// <param name="visaPriceRep"></param>
  187. /// <param name="carTouristGuideGroundRep"></param>
  188. /// <param name="checkBoxs"></param>
  189. /// <param name="GroupCostRepository"></param>
  190. /// <param name="CostTypeHotelNumberRepository"></param>
  191. /// <param name="GroupCostParameterRepository"></param>
  192. /// <param name="hotelPriceRep"></param>
  193. /// <param name="customersRep"></param>
  194. /// <param name="setDataRep"></param>
  195. /// <param name="tourClientListRep"></param>
  196. /// <param name="teamRateRep"></param>
  197. /// <param name="usersRep"></param>
  198. /// <param name="juHeApi"></param>
  199. /// <param name="invertedListRep"></param>
  200. /// <param name="visaFeeInfoRep"></param>
  201. /// <param name="ticketBlackCodeRep"></param>
  202. /// <param name="hotelInquiryRep"></param>
  203. /// <param name="threeCodeRepository"></param>
  204. /// <param name="feeAuditRep"></param>
  205. /// <param name="visaCommissionRep"></param>
  206. /// <param name="ffrRep"></param>
  207. /// <param name="opinionaireRep"></param>
  208. /// <param name="tableorRep"></param>
  209. /// <param name="enterExitCostDraftRep"></param>
  210. /// <param name="restaurantRep"></param>
  211. /// <param name="enterExitCostQuoteRep"></param>
  212. /// <param name="grpOrderPreInfoRep"></param>
  213. /// <param name="visaProcessRep"></param>
  214. /// <param name="processOverviewRep"></param>
  215. /// <param name="groupSearchService"></param>
  216. /// <param name="deepSeekService"></param>
  217. public GroupsController(
  218. ILogger<GroupsController> logger,
  219. ITextFileLogger eec_textLogger,
  220. IGroupTextFileLogger groupTextLogger,
  221. IMapper mapper,
  222. IHubContext<ChatHub, IChatClient> hubContext,
  223. SqlSugarClient sqlSugar,
  224. GrpScheduleRepository grpScheduleRep,
  225. DelegationInfoRepository groupRepository,
  226. TaskAssignmentRepository taskAssignmentRep,
  227. AirTicketResRepository airTicketResRep,
  228. DecreasePaymentsRepository decreasePaymentsRep,
  229. InvitationOfficialActivitiesRepository InvitationOfficialActivitiesRep,
  230. DelegationEnDataRepository delegationEnDataRep,
  231. EnterExitCostRepository enterExitCostRep,
  232. DelegationVisaRepository delegationVisaRep,
  233. MessageRepository message,
  234. VisaPriceRepository visaPriceRep,
  235. CarTouristGuideGroundRepository carTouristGuideGroundRep,
  236. CheckBoxsRepository checkBoxs,
  237. GroupCostRepository GroupCostRepository,
  238. CostTypeHotelNumberRepository CostTypeHotelNumberRepository,
  239. GroupCostParameterRepository GroupCostParameterRepository,
  240. HotelPriceRepository hotelPriceRep,
  241. CustomersRepository customersRep,
  242. SetDataRepository setDataRep,
  243. TourClientListRepository tourClientListRep,
  244. TeamRateRepository teamRateRep,
  245. UsersRepository usersRep,
  246. IJuHeApiService juHeApi,
  247. InvertedListRepository invertedListRep,
  248. VisaFeeInfoRepository visaFeeInfoRep,
  249. TicketBlackCodeRepository ticketBlackCodeRep,
  250. HotelInquiryRepository hotelInquiryRep,
  251. ThreeCodeRepository threeCodeRepository,
  252. FeeAuditRepository feeAuditRep,
  253. VisaCommissionRepository visaCommissionRep,
  254. ForeignReceivablesRepository ffrRep,
  255. OpinionaireRepository opinionaireRep,
  256. TableOperationRecordRepository tableorRep,
  257. EnterExitCostDraftRepository enterExitCostDraftRep,
  258. RestaurantRepository restaurantRep,
  259. EnterExitCostQuoteRepository enterExitCostQuoteRep,
  260. GroupOrderPreInfoRepository grpOrderPreInfoRep,
  261. VisaProcessRepository visaProcessRep,
  262. ProcessOverviewRepository processOverviewRep,
  263. DynamicSearchService<Grp_DelegationInfo> groupSearchService,
  264. IDeepSeekService deepSeekService,
  265. IDoubaoService doubaoService
  266. )
  267. {
  268. _logger = logger;
  269. _eec_textLogger = eec_textLogger;
  270. _groupTextLogger = groupTextLogger;
  271. _mapper = mapper;
  272. _grpScheduleRep = grpScheduleRep;
  273. _groupRepository = groupRepository;
  274. _taskAssignmentRep = taskAssignmentRep;
  275. _airTicketResRep = airTicketResRep;
  276. _sqlSugar = sqlSugar;
  277. url = AppSettingsHelper.Get("ExcelBaseUrl");
  278. path = AppSettingsHelper.Get("ExcelBasePath");
  279. if (!System.IO.Directory.Exists(path))
  280. {
  281. System.IO.Directory.CreateDirectory(path);//不存在就创建文件夹
  282. }
  283. _decreasePaymentsRep = decreasePaymentsRep;
  284. _InvitationOfficialActivitiesRep = InvitationOfficialActivitiesRep;
  285. _delegationEnDataRep = delegationEnDataRep;
  286. _enterExitCostRep = enterExitCostRep;
  287. _delegationVisaRep = delegationVisaRep;
  288. _message = message;
  289. _visaPriceRep = visaPriceRep;
  290. _carTouristGuideGroundRep = carTouristGuideGroundRep;
  291. _checkBoxs = checkBoxs;
  292. _GroupCostRepository = GroupCostRepository;
  293. _CostTypeHotelNumberRepository = CostTypeHotelNumberRepository;
  294. _GroupCostParameterRepository = GroupCostParameterRepository;
  295. _hotelPriceRep = hotelPriceRep;
  296. _customersRep = customersRep;
  297. _setDataRep = setDataRep;
  298. _tourClientListRep = tourClientListRep;
  299. _teamRateRep = teamRateRep;
  300. _hubContext = hubContext;
  301. _usersRep = usersRep;
  302. _juHeApi = juHeApi;
  303. _invertedListRep = invertedListRep;
  304. _visaFeeInfoRep = visaFeeInfoRep;
  305. _ticketBlackCodeRep = ticketBlackCodeRep;
  306. _hotelInquiryRep = hotelInquiryRep;
  307. _threeCodeRepository = threeCodeRepository;
  308. _feeAuditRep = feeAuditRep;
  309. _visaCommissionRep = visaCommissionRep;
  310. _ffrRep = ffrRep;
  311. _opinionaireRep = opinionaireRep;
  312. _currencyInit = new List<CurrencyInfo>()
  313. {
  314. new(){ CurrencyCode="USD",CurrencyName = "美元",Rate = 7.5000M },
  315. new(){ CurrencyCode="EUR",CurrencyName = "欧元",Rate = 8.0000M },
  316. new(){ CurrencyCode="GBP",CurrencyName = "英镑",Rate = 9.5000M },
  317. new(){ CurrencyCode="JPY",CurrencyName = "日元",Rate = 0.0500M },
  318. new(){ CurrencyCode="HKD",CurrencyName = "港币",Rate = 0.9500M },
  319. };
  320. _portTypeData = new List<int>() { 2, 3 };
  321. _tableorRep = tableorRep;
  322. _enterExitCostDraftRep = enterExitCostDraftRep;
  323. _restaurantRep = restaurantRep;
  324. _enterExitCostQuoteRep = enterExitCostQuoteRep;
  325. _grpOrderPreInfoRep = grpOrderPreInfoRep;
  326. _visaProcessRep = visaProcessRep;
  327. _processOverviewRep = processOverviewRep;
  328. _groupSearchService = groupSearchService;
  329. _deepSeekService = deepSeekService;
  330. _doubaoService = doubaoService;
  331. }
  332. #region 页面加载弹窗信息
  333. /// <summary>
  334. /// 提示用户录入团组费用信息
  335. /// 根据用户ID获取分配权限内团组名称
  336. /// </summary>
  337. /// <param name="currUserId">用户Id</param>
  338. /// <param name="daysAgo">往前推的天数</param>
  339. /// <returns></returns>
  340. [HttpGet]
  341. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  342. public async Task<IActionResult> GetGroupNamesByUserId(int currUserId, int daysAgo = 5)
  343. {
  344. var stopwatch = Stopwatch.StartNew();
  345. var userInfo = await _sqlSugar.Queryable<Sys_Users>()
  346. .Where(x => x.Id == currUserId && x.IsDel == 0)
  347. .Select(x => new { x.Id, x.JobPostId, x.CnName })
  348. .FirstAsync();
  349. if (userInfo == null)
  350. {
  351. return Ok(JsonView(false, "用户不存在或已被禁用!"));
  352. }
  353. var jobId = userInfo.JobPostId;
  354. var feeTypeIds = new List<int>() { };
  355. if (_dataInit.TryGetValue(jobId, out var values))
  356. {
  357. feeTypeIds = values;
  358. }
  359. /*
  360. * 获取今天时间往前推5天查询团组c表里有没有费用
  361. */
  362. var today_startDate = DateTime.Now.Date.AddDays(-daysAgo);
  363. //var today_endDate = DateTime.Now.Date.AddDays(-daysAgo).AddDays(1).AddSeconds(-1);
  364. var today_endDate = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
  365. var groupNames = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  366. .Where(di => di.IsDel == 0)
  367. .Where(di => di.VisitDate >= today_startDate && di.VisitDate <= today_endDate)
  368. // 存在任务分配记录
  369. .Where(di => SqlFunc.Subqueryable<Grp_GroupsTaskAssignment>()
  370. .Where(gta => gta.DIId == di.Id && gta.IsDel == 0 && feeTypeIds.Contains(gta.CTId))
  371. .Any())
  372. // 不存在费用记录
  373. .Where(di => !SqlFunc.Subqueryable<Grp_CreditCardPayment>()
  374. .Where(ccp => ccp.DIId == di.Id && ccp.IsDel == 0 && feeTypeIds.Contains(ccp.CTable))
  375. .Any())
  376. // 新增条件:不在确认记录表中(排除已确认的团组)
  377. .Where(di => !SqlFunc.Subqueryable<Grp_FeeEntryAcknowledge>()
  378. .Where(ack => ack.GroupId == di.Id && ack.IsDel == 0 && ack.UserId == currUserId)
  379. .Where(ack => feeTypeIds.Contains(ack.FeeTypeId))
  380. .Where(ack => ack.IsAcknowledged == AcknowledgeStatusEnum.Acknowledged) // 只排除已确认的记录
  381. .Any())
  382. .Select(di => new
  383. {
  384. di.Id,
  385. di.TeamName,
  386. di.VisitDate
  387. })
  388. .OrderBy(di => di.VisitDate)
  389. .ToListAsync();
  390. stopwatch.Stop();
  391. return Ok(JsonView(true, $"操作成功!【耗时:{stopwatch.ElapsedMilliseconds}ms】", new
  392. {
  393. isTips = groupNames.Any(),
  394. groupNames = groupNames.Select(x => new { x.Id, GroupName = x.TeamName, x.VisitDate }).ToList()
  395. }));
  396. }
  397. /// <summary>
  398. /// 提示用户录入团组费用信息
  399. /// 已知晓确认操作记录(添加) 批量
  400. /// </summary>
  401. /// <param name="dto">请求体</param>
  402. /// <returns></returns>
  403. [HttpPost]
  404. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  405. public async Task<IActionResult> FeeEntryAcknowledgeCrate(FeeEntryAcknowledgeCrateDto dto)
  406. {
  407. // 1. 参数验证
  408. if (dto?.GroupIds == null || !dto.GroupIds.Any())
  409. return Ok(JsonView(false, "请选择需要确认的团组!"));
  410. if (dto.GroupIds.Count > 100)
  411. return Ok(JsonView(false, "一次性确认团组数量不能超过100个!"));
  412. if (dto.CurrUserId <= 0)
  413. return Ok(JsonView(false, "用户ID无效!"));
  414. // 2. 验证用户存在性
  415. var userInfo = await _sqlSugar.Queryable<Sys_Users>()
  416. .Where(x => x.Id == dto.CurrUserId && x.IsDel == 0)
  417. .Select(x => new { x.Id, x.JobPostId, x.CnName })
  418. .FirstAsync();
  419. if (userInfo == null)
  420. return Ok(JsonView(false, "用户不存在或已被禁用!"));
  421. // 3. 获取费用类型
  422. if (!_dataInit.TryGetValue(userInfo.JobPostId, out var feeTypeIds) || feeTypeIds?.Count == 0)
  423. return Ok(JsonView(false, "当前用户岗位无对应的费用类型配置!"));
  424. // 4. 验证团组存在性
  425. var validGroupIds = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  426. .Where(x => dto.GroupIds.Contains(x.Id) && x.IsDel == 0)
  427. .Select(x => x.Id)
  428. .ToListAsync();
  429. if (!validGroupIds.Any())
  430. return Ok(JsonView(false, "未找到有效的团组信息!"));
  431. // 5. 检查团组费用表中是否存在对应费用类型的数据
  432. var existingFeeRecords = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  433. .Where(x => validGroupIds.Contains(x.DIId) && x.IsDel == 0)
  434. .Where(x => feeTypeIds.Contains(x.CTable))
  435. .Select(x => new { GroupId = x.DIId, FeeTypeId = x.CTable })
  436. .ToListAsync();
  437. if (existingFeeRecords.Count > 0)
  438. {
  439. // 找出有问题的团组和费用类型
  440. var problematicGroups = existingFeeRecords
  441. .GroupBy(x => x.GroupId)
  442. .Select(g => new
  443. {
  444. GroupId = g.Key,
  445. FeeTypeIds = string.Join(",", g.Select(x => x.FeeTypeId).Distinct())
  446. })
  447. .ToList();
  448. var errorMessage = $"以下团组的费用表中已存在费用数据,不可添加确认记录:";
  449. foreach (var group in problematicGroups)
  450. {
  451. errorMessage += $"\n团组 {group.GroupId} - 费用类型ID: [{group.FeeTypeIds}]";
  452. }
  453. return Ok(JsonView(false, errorMessage));
  454. }
  455. // 6. 检查是否已存在确认记录(避免重复确认)
  456. var existingAcknowledgeRecords = await _sqlSugar.Queryable<Grp_FeeEntryAcknowledge>()
  457. .Where(x => x.UserId == dto.CurrUserId && x.IsDel == 0)
  458. .Where(x => validGroupIds.Contains(x.GroupId))
  459. .Where(x => feeTypeIds.Contains(x.FeeTypeId))
  460. .Select(x => new { x.GroupId, x.FeeTypeId })
  461. .ToListAsync();
  462. // 7. 准备插入数据(过滤已存在的记录)
  463. var recordsToInsert = new List<Grp_FeeEntryAcknowledge>();
  464. foreach (var groupId in validGroupIds)
  465. {
  466. foreach (var feeTypeId in feeTypeIds)
  467. {
  468. // 检查是否已存在相同记录
  469. var exists = existingAcknowledgeRecords.Any(x => x.GroupId == groupId && x.FeeTypeId == feeTypeId);
  470. if (!exists)
  471. {
  472. recordsToInsert.Add(new Grp_FeeEntryAcknowledge()
  473. {
  474. GroupId = groupId,
  475. UserId = dto.CurrUserId,
  476. JobPostId = userInfo.JobPostId,
  477. FeeTypeId = feeTypeId,
  478. IsAcknowledged = Domain.Enums.AcknowledgeStatusEnum.Acknowledged,
  479. AcknowledgeTime = DateTime.Now,
  480. AcknowledgeType = Domain.Enums.AcknowledgeTypeEnum.WebConfirm,
  481. CreateUserId = 4, // 系统创建
  482. CreateTime = DateTime.Now
  483. });
  484. }
  485. }
  486. }
  487. if (!recordsToInsert.Any())
  488. return Ok(JsonView(true, "所选团组已确认,无需重复操作!"));
  489. // 8. 批量插入数据
  490. var successCount = await _sqlSugar.Insertable(recordsToInsert).ExecuteCommandAsync();
  491. if (successCount <= 0)
  492. return Ok(JsonView(false, "操作失败,未能保存确认记录!"));
  493. // 9. 记录操作日志
  494. _logger.LogInformation("用户 {UserName}(ID:{UserId}) 批量确认了 {GroupCount} 个团组的费用类型,共添加 {RecordCount} 条确认记录",
  495. userInfo.CnName, dto.CurrUserId, validGroupIds.Count, successCount);
  496. // 10. 操作成功 返回成功视图
  497. var result = await GetGroupNamesByUserId(dto.CurrUserId, dto.DaysAgo);
  498. if (result is OkObjectResult okObjectResult)
  499. {
  500. return Ok(okObjectResult.Value);
  501. }
  502. //return Ok(result);
  503. return Ok(JsonView(true, $"操作成功!共为 {validGroupIds.Count} 个团组添加了 {successCount} 条确认记录"));
  504. }
  505. /// <summary>
  506. /// 提示用户录入团组费用信息
  507. /// 已知晓确认操作记录(添加) 单个
  508. /// </summary>
  509. /// <param name="dto">请求体</param>
  510. /// <returns></returns>
  511. [HttpPost]
  512. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  513. public async Task<IActionResult> FeeEntryAcknowledgeSingleCreate(FeeEntryAcknowledgeSingleDto dto)
  514. {
  515. // 1. 参数验证
  516. if (dto.GroupId <= 0)
  517. return Ok(JsonView(false, "请选择有效的团组ID!"));
  518. if (dto.CurrUserId <= 0)
  519. return Ok(JsonView(false, "用户ID无效!"));
  520. // 2. 验证用户存在性
  521. var userInfo = await _sqlSugar.Queryable<Sys_Users>()
  522. .Where(x => x.Id == dto.CurrUserId && x.IsDel == 0)
  523. .Select(x => new { x.Id, x.JobPostId, x.CnName })
  524. .FirstAsync();
  525. if (userInfo == null)
  526. return Ok(JsonView(false, "用户不存在或已被禁用!"));
  527. // 3. 获取费用类型
  528. if (!_dataInit.TryGetValue(userInfo.JobPostId, out var feeTypeIds) || feeTypeIds?.Count == 0)
  529. return Ok(JsonView(false, "当前用户岗位无对应的费用类型配置!"));
  530. // 4. 验证团组存在性
  531. var groupExists = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  532. .AnyAsync(x => x.Id == dto.GroupId && x.IsDel == 0);
  533. if (!groupExists)
  534. return Ok(JsonView(false, "未找到有效的团组信息!"));
  535. // 5. 检查团组费用表中是否存在对应费用类型的数据
  536. var existingFeeRecords = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  537. .Where(x => x.DIId == dto.GroupId && x.IsDel == 0)
  538. .Where(x => feeTypeIds.Contains(x.CTable))
  539. .Select(x => new { x.CTable })
  540. .ToListAsync();
  541. if (existingFeeRecords.Count > 0)
  542. {
  543. var existingFeeTypeNames = existingFeeRecords.Select(x => x.CTable).Distinct().ToList();
  544. return Ok(JsonView(false, $"团组费用表中已存在费用类型ID [{string.Join(",", existingFeeTypeNames)}] 的数据,不可添加确认无费用记录!"));
  545. }
  546. // 6. 检查已存在的确认记录
  547. var existingAcknowledgeRecords = await _sqlSugar.Queryable<Grp_FeeEntryAcknowledge>()
  548. .Where(x => x.UserId == dto.CurrUserId && x.IsDel == 0)
  549. .Where(x => x.GroupId == dto.GroupId)
  550. .Where(x => feeTypeIds.Contains(x.FeeTypeId))
  551. .Select(x => new { x.FeeTypeId })
  552. .ToListAsync();
  553. var existingAcknowledgeFeeTypeIds = existingAcknowledgeRecords.Select(x => x.FeeTypeId).ToHashSet();
  554. // 7. 准备插入数据(过滤已存在的记录)
  555. var recordsToInsert = feeTypeIds
  556. .Where(feeTypeId => !existingAcknowledgeFeeTypeIds.Contains(feeTypeId))
  557. .Select(feeTypeId => new Grp_FeeEntryAcknowledge
  558. {
  559. GroupId = dto.GroupId,
  560. UserId = dto.CurrUserId,
  561. JobPostId = userInfo.JobPostId,
  562. FeeTypeId = feeTypeId,
  563. IsAcknowledged = Domain.Enums.AcknowledgeStatusEnum.Acknowledged,
  564. AcknowledgeTime = DateTime.Now,
  565. AcknowledgeType = Domain.Enums.AcknowledgeTypeEnum.WebConfirm,
  566. CreateUserId = 4, // 系统创建
  567. CreateTime = DateTime.Now
  568. })
  569. .ToList();
  570. if (recordsToInsert.Count == 0)
  571. return Ok(JsonView(true, "所选团组已确认,无需重复操作!"));
  572. // 8. 批量插入数据
  573. var successCount = await _sqlSugar.Insertable(recordsToInsert).ExecuteCommandAsync();
  574. if (successCount <= 0)
  575. return Ok(JsonView(false, "操作失败,未能保存确认记录!"));
  576. // 9. 记录操作日志(可选)
  577. _logger.LogInformation("用户 {UserName}(ID:{UserId}) 确认了团组 {GroupId} 的费用类型",
  578. userInfo.CnName, dto.CurrUserId, dto.GroupId);
  579. return Ok(JsonView(true, $"操作成功!"));
  580. }
  581. #endregion
  582. #region 流程管控
  583. /// <summary>
  584. /// 获取团组流程管控信息
  585. /// </summary>
  586. /// <param name="_jsonDto">查询参数</param>
  587. /// <returns></returns>
  588. [HttpPost]
  589. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  590. public async Task<IActionResult> PostSearchGrpSchedule(JsonDtoBase _jsonDto)
  591. {
  592. if (string.IsNullOrEmpty(_jsonDto.Paras))
  593. {
  594. return Ok(JsonView(false, "参数为空"));
  595. }
  596. Grp_ScheduleDto _ScheduleDto = JsonConvert.DeserializeObject<Grp_ScheduleDto>(_jsonDto.Paras);
  597. if (_ScheduleDto != null)
  598. {
  599. if (_ScheduleDto.SearchType == 2)//获取列表
  600. {
  601. List<Grp_ScheduleView> _grpScheduleViewList = await _grpScheduleRep.GetViewList_GrpSchedule(_ScheduleDto);
  602. return Ok(JsonView(_grpScheduleViewList));
  603. }
  604. else//获取对象
  605. {
  606. Grp_ScheduleCombinView _grpScheduleView = await _grpScheduleRep.GetView_GrpSchedule(_ScheduleDto);
  607. if (_grpScheduleView != null)
  608. {
  609. return Ok(JsonView(_grpScheduleView));
  610. }
  611. }
  612. }
  613. else
  614. {
  615. return Ok(JsonView(false, "参数反序列化失败"));
  616. }
  617. return Ok(JsonView(false, "暂无数据!"));
  618. }
  619. /// <summary>
  620. /// 修改团组流程管控详细表数据
  621. /// </summary>
  622. /// <param name="dto"></param>
  623. /// <returns></returns>
  624. [HttpPost]
  625. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  626. public async Task<IActionResult> PostUpdateGrpScheduleDetail(Grp_ScheduleDetailUpdDto dto)
  627. {
  628. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  629. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_ScheduleDetailInfo>()
  630. .SetColumns(it => it.Duty == _detail.Duty)
  631. .SetColumns(it => it.ExpectBeginDt == _detail.ExpectBeginDt)
  632. .SetColumns(it => it.ExpectEndDt == _detail.ExpectEndDt)
  633. .SetColumns(it => it.JobContent == _detail.JobContent)
  634. .SetColumns(it => it.Remark == _detail.Remark)
  635. .SetColumns(it => it.StepStatus == _detail.StepStatus)
  636. .Where(s => s.Id == dto.Id)
  637. //.UpdateColumns(s => new { s.Duty, s.ExpectBeginDt, s.ExpectEndDt, s.JobContent, s.Remark, s.StepStatus })
  638. .ExecuteCommandAsync();
  639. if (result > 0)
  640. {
  641. return Ok(JsonView(true, "保存成功!"));
  642. }
  643. return Ok(JsonView(false, "保存失败!"));
  644. }
  645. /// <summary>
  646. /// 删除团组流程管控详细表数据,删除人Id请放在Duty
  647. /// </summary>
  648. /// <param name="dto"></param>
  649. /// <returns></returns>
  650. [HttpPost]
  651. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  652. public async Task<ActionResult> PostDeleteGrpScheduleDetail(Grp_ScheduleDetailUpdDto dto)
  653. {
  654. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  655. _detail.IsDel = 1;
  656. _detail.DeleteUserId = dto.Duty;
  657. _detail.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  658. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_ScheduleDetailInfo>()
  659. .SetColumns(it => it.IsDel == _detail.IsDel)
  660. .SetColumns(it => it.DeleteUserId == _detail.DeleteUserId)
  661. .SetColumns(it => it.DeleteTime == _detail.DeleteTime)
  662. .Where(it => it.Id == dto.Id)
  663. //.UpdateColumns(s => new { s.IsDel, s.DeleteUserId, s.DeleteTime })
  664. //.WhereColumns(s => s.Id == dto.Id)
  665. .ExecuteCommandAsync();
  666. if (result > 0)
  667. {
  668. return Ok(JsonView(true, "删除成功!"));
  669. }
  670. return Ok(JsonView(false, "删除失败!"));
  671. }
  672. /// <summary>
  673. /// 增加团组流程管控详细表数据
  674. /// </summary>
  675. /// <param name="dto"></param>
  676. /// <returns></returns>
  677. [HttpPost]
  678. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  679. public async Task<ActionResult> PostInsertGrpScheduleDetail(Grp_ScheduleDetailInsertDto dto)
  680. {
  681. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  682. if (DateTime.Now < _detail.ExpectBeginDt)
  683. {
  684. _detail.StepStatus = 0;
  685. }
  686. else
  687. {//若大于设置时间,不考虑设置的预计结束日期,统一视为进行中
  688. _detail.StepStatus = 1;
  689. }
  690. var result = await _grpScheduleRep._sqlSugar.Insertable(_detail).ExecuteReturnIdentityAsync();
  691. if (result > 0)
  692. {
  693. Grp_ScheduleDetailView _result = await _grpScheduleRep.GetInsertBackData(result);
  694. return Ok(JsonView(true, "添加成功!", _result));
  695. }
  696. return Ok(JsonView(false, "添加失败!"));
  697. }
  698. #endregion
  699. #region 团组前期信息
  700. /// <summary>
  701. /// 团组前期信息H5-URL(员工对应地址)
  702. /// </summary>
  703. /// <param name="name">用户名称</param>
  704. /// <returns></returns>
  705. [HttpGet]
  706. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  707. public async Task<IActionResult> GroupOrderPreInfoH5URLList([FromQuery] string name)
  708. {
  709. var userURLs = await _sqlSugar.Queryable<Sys_Users>()
  710. .Where(x => x.IsDel == 0)
  711. .WhereIF(!string.IsNullOrEmpty(name), x => x.CnName.Contains(name))
  712. .OrderBy(x => x.Id)
  713. .Select(x => new
  714. {
  715. name = x.CnName,
  716. url = $"http://oa.pan-american-intl.com:4399/#/MarketplacePick?userid={x.Id}",
  717. })
  718. .ToListAsync();
  719. return Ok(JsonView(true, "操作成功!", userURLs, userURLs.Count));
  720. }
  721. /// <summary>
  722. /// 团组前期信息 List
  723. /// </summary>
  724. /// <returns></returns>
  725. [HttpPost]
  726. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  727. public async Task<IActionResult> GroupOrderPreInfoList(GroupOrderPreInfoListDto dto)
  728. {
  729. var search = dto.Search;
  730. int[] nameTempIds = new int[] { 1, 12, 28 },
  731. countryTempIds = new int[] { 2, 13, 29 },
  732. daysTempIds = new int[] { 4, 15, 31 },
  733. ppNumTempIds = new int[] { 6 };
  734. var list = await _sqlSugar.Queryable<Grp_OrderPreInfo>()
  735. .LeftJoin<Sys_Users>((opi, u) => opi.CreateUserId == u.Id)
  736. .Where((opi, u) => opi.IsDel == 0)
  737. .OrderByDescending((opi, u) => opi.CreateTime)
  738. .Select((opi, u) => new GroupOrderPreInfoListView()
  739. {
  740. Id = opi.Id,
  741. Name = opi.Name,
  742. UnitName = SqlFunc.Subqueryable<Grp_OrderPreItem>().Where(x => x.ParentId == opi.Id && nameTempIds.Contains(x.FormTempId)).Select(x => x.Value),
  743. VisitCountryVal = SqlFunc.Subqueryable<Grp_OrderPreItem>().Where(x => x.ParentId == opi.Id && countryTempIds.Contains(x.FormTempId)).Select(x => x.Value),
  744. VisitDays = SqlFunc.Subqueryable<Grp_OrderPreItem>().Where(x => x.ParentId == opi.Id && daysTempIds.Contains(x.FormTempId)).Select(x => x.Value),
  745. VisiPpNum = SqlFunc.Subqueryable<Grp_OrderPreItem>().Where(x => x.ParentId == opi.Id && ppNumTempIds.Contains(x.FormTempId)).Select(x => x.Value),
  746. Operator = u.CnName,
  747. OperationTime = opi.CreateTime
  748. })
  749. //.WhereIF(!string.IsNullOrEmpty(search), x => x.Name.Contains(search) || x.UnitName.Contains(search) || x.VisitCountrys.Contains(search))
  750. //.ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  751. .ToListAsync();
  752. var listPageData = list.WhereIF(!string.IsNullOrEmpty(search), x => x.Name.Contains(search) || x.UnitName.Contains(search) || x.VisitCountrys.Contains(search)).ToList();
  753. int total = list.Count;
  754. int totalPageCount = (int)Math.Ceiling(list.Count / (double)dto.PageSize);
  755. var listPageData1 = listPageData
  756. .Skip((dto.PageIndex - 1) * dto.PageSize)
  757. .Take(dto.PageSize)
  758. .ToList();
  759. var infoIds = listPageData1.Select(x => x.Id).ToList();
  760. var typeDatas = await _sqlSugar.Queryable<Sys_SetData>()
  761. .Where(x => x.IsDel == 0 && x.STid == 109)
  762. .ToArrayAsync();
  763. var items = await _sqlSugar.Queryable<Grp_OrderPreItem>()
  764. .LeftJoin<Sys_FormTemp>((opi, ft) => opi.FormTempId == ft.Id)
  765. .Where((opi, ft) => opi.IsDel == 0 && infoIds.Contains(opi.ParentId))
  766. .Select((opi, ft) => new { opi.ParentId, opi.FormTempId, ft.TempId })
  767. .ToListAsync();
  768. foreach (var item in listPageData1)
  769. {
  770. var typeDatas1 = typeDatas.Select(x => new
  771. {
  772. x.Id,
  773. x.Name,
  774. IsNull = !items.Any(x1 => item.Id == x1.ParentId && x.Id == x1.TempId)
  775. }).ToArray();
  776. item.VersionDetails = typeDatas1;
  777. }
  778. return Ok(JsonView(listPageData1, listPageData1.Count));
  779. }
  780. /// <summary>
  781. /// 团组前期信息 Init
  782. /// </summary>
  783. /// <returns></returns>
  784. [HttpGet("{userId}")]
  785. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  786. public async Task<IActionResult> GroupOrderPreInfo(int userId)
  787. {
  788. return Ok(await _grpOrderPreInfoRep.DataInit(userId));
  789. }
  790. /// <summary>
  791. /// 国家数据源
  792. /// </summary>
  793. /// <param name="pageIndex">当前页码</param>
  794. /// <param name="pageSize">每页条数</param>
  795. /// <param name="search">查询条件</param>
  796. /// <returns></returns>
  797. [HttpGet]
  798. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  799. public async Task<IActionResult> CountryInit([FromQuery] int pageIndex, [FromQuery] int pageSize, [FromQuery] string search)
  800. {
  801. var countrys = await _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x => x.IsDel == 0).Select(x => x.Country).Distinct().ToListAsync();
  802. if (pageIndex == 0 && pageSize == 0)
  803. {
  804. //所有数据
  805. return Ok(JsonView(countrys, countrys.Count));
  806. }
  807. //分页
  808. int skip = (pageIndex - 1) * pageSize;
  809. int take = pageSize;
  810. if (!string.IsNullOrEmpty(search))
  811. {
  812. IEnumerable<char> charSequence = search.Select(c => c);
  813. var pageResult1 = countrys.Where(x => charSequence.All(x1 => x.Contains(x1))).ToList();
  814. var pageData = pageResult1.Skip(skip).Take(take).ToList();
  815. return Ok(JsonView(pageData, pageResult1.Count));
  816. }
  817. var pageResult2 = countrys.Skip(skip).Take(take).ToList();
  818. return Ok(JsonView(pageResult2, countrys.Count));
  819. }
  820. /// <summary>
  821. /// 城市数据源
  822. /// </summary>
  823. /// <param name="countryLabel">国家名称 多个使用英文逗号隔开</param>
  824. /// <param name="pageIndex">当前页码</param>
  825. /// <param name="pageSize">每页条数</param>
  826. /// <param name="search">查询条件</param>
  827. /// <returns></returns>
  828. [HttpGet("{countryLabel}")]
  829. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  830. public async Task<IActionResult> CityByCountry(
  831. string countryLabel,
  832. [FromQuery] int pageIndex,
  833. [FromQuery] int pageSize,
  834. [FromQuery] string search)
  835. {
  836. countryLabel = HttpUtility.UrlDecode(countryLabel);
  837. var countryList = countryLabel.Split(',', StringSplitOptions.RemoveEmptyEntries).ToArray();
  838. var citys = Array.Empty<string?>();
  839. if (countryList.Any())
  840. {
  841. var cityDatas = await _sqlSugar
  842. .Queryable<Grp_NationalTravelFee>()
  843. .Where(x => x.IsDel == 0 && countryList.Contains(x.Country) && !string.IsNullOrEmpty(x.City))
  844. .ToArrayAsync();
  845. foreach (var item in cityDatas)
  846. {
  847. if (item.City.Contains("城市"))
  848. {
  849. item.City = item.Country + "-所有城市";
  850. }
  851. }
  852. var cityDatas1 = cityDatas.OrderBy(x => x.Country);
  853. citys = cityDatas1.Select(x => x.City).Distinct().ToArray();
  854. }
  855. if (pageIndex == 0 && pageSize == 0)
  856. {
  857. //所有数据
  858. return Ok(JsonView(citys, citys?.Length ?? 0));
  859. }
  860. //分页
  861. int skip = (pageIndex - 1) * pageSize;
  862. int take = pageSize;
  863. if (!string.IsNullOrEmpty(search))
  864. {
  865. IEnumerable<char> charSequence = search.Select(c => c);
  866. var pageResult1 = citys.Where(x => charSequence.All(x1 => x.Contains(x1))).ToList();
  867. var pageData = pageResult1.Skip(skip).Take(take).ToList();
  868. return Ok(JsonView(pageData, pageResult1.Count));
  869. }
  870. var pageResult2 = citys.Skip(skip).Take(take).ToList();
  871. return Ok(JsonView(pageResult2, citys?.Length ?? 0));
  872. }
  873. /// <summary>
  874. /// 团组前期信息 Info
  875. /// </summary>
  876. /// <param name="dto">Id</param>
  877. /// <returns></returns>
  878. [HttpGet("{Id}/{TempId}")]
  879. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  880. public async Task<IActionResult> GroupOrderPreInfo([FromRoute] GroupOrderPreInfoDto dto)
  881. {
  882. return Ok(await _grpOrderPreInfoRep.InfoAsync(dto.Id, dto.TempId));
  883. }
  884. /// <summary>
  885. /// 团组前期信息 移动端 Info
  886. /// </summary>
  887. /// <param name="dto">Id</param>
  888. /// <returns></returns>
  889. [HttpGet("{Id}/{TempId}")]
  890. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  891. public async Task<IActionResult> GroupOrderPreMobileInfo([FromRoute] GroupOrderPreInfoDto dto)
  892. {
  893. return Ok(await _grpOrderPreInfoRep.MobileInfoAsync(dto.Id, dto.TempId));
  894. }
  895. /// <summary>
  896. /// 团组前期信息 Save
  897. /// </summary>
  898. /// <param name="dto">Id</param>
  899. /// <returns></returns>
  900. [HttpPost]
  901. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  902. public async Task<IActionResult> GroupOrderPreInfoSave(GroupOrderPreInfoOpDto dto)
  903. {
  904. return Ok(await _grpOrderPreInfoRep.OpAsync(dto));
  905. }
  906. /// <summary>
  907. /// 团组前期信息 Del
  908. /// </summary>
  909. /// <param name="dto">Id</param>
  910. /// <returns></returns>
  911. [HttpPost]
  912. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  913. public async Task<IActionResult> GroupOrderPreInfoDel(GroupOrderPreInfoDelDto dto)
  914. {
  915. return Ok(await _grpOrderPreInfoRep.DelAsync(dto));
  916. }
  917. /// <summary>
  918. /// 团组前期信息 文件下载
  919. /// </summary>
  920. /// <param name="dto">Id</param>
  921. /// <returns></returns>
  922. [HttpGet("{Id}/{TempId}")]
  923. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  924. public async Task<IActionResult> GroupOrderPreInfoFileDownload([FromRoute] GroupOrderPreInfoDto dto)
  925. {
  926. int id = dto.Id, tempId = dto.TempId;
  927. var view = await _grpOrderPreInfoRep.InfoAsync(id, tempId);
  928. var data = view.Data as GrpOrderPreInfoView;
  929. #region Excel
  930. var tempPath = AppSettingsHelper.Get("ExcelTempPath");
  931. var servicePath = AppSettingsHelper.Get("GrpFileBaseUrl");
  932. var savePath = AppSettingsHelper.Get("ExcelBasePath") + "GroupOrderPreInfo/";
  933. var ftpPath = AppSettingsHelper.Get("ExcelFtpPath") + "GroupOrderPreInfo/";
  934. var fileNamePrefix = string.Empty;
  935. if (tempId == 1405)
  936. {
  937. tempPath += $"前期需客户提供信息_无商邀版Temp.xlsx";
  938. fileNamePrefix = $"{data.Name}_无商邀版";
  939. }
  940. else if (tempId == 1406)
  941. {
  942. tempPath += $"前期需客户提供信息_有商邀版Temp.xlsx";
  943. fileNamePrefix = $"{data.Name}_有商邀版";
  944. }
  945. else
  946. {
  947. //tempId == 1404 默认下载
  948. tempPath += $"前期需客户提供信息_单接送机Temp.xlsx";
  949. fileNamePrefix = $"{data.Name}_单接送机";
  950. }
  951. foreach (var item in data.Items)
  952. {
  953. var obj = item.NewValue;
  954. if (obj == null) item.OriginVal = "";
  955. else if (obj.Equals("有") || obj.Equals("无"))
  956. {
  957. item.OriginVal = obj.ToString();
  958. }
  959. else if (obj is object[] objArray)
  960. {
  961. string[] stringArray = Array.ConvertAll(objArray, item => item?.ToString() ?? string.Empty);
  962. item.OriginVal = string.Join("、", stringArray);
  963. }
  964. else if (obj is string[] stringArray)
  965. {
  966. item.OriginVal = string.Join("、", stringArray);
  967. }
  968. else if (obj.Equals("-"))
  969. {
  970. item.OriginVal = "";
  971. }
  972. }
  973. var fileName = $"{fileNamePrefix}{CommonFun.GUID}.xlsx";
  974. fileName = CommonFun.ValidFileName(fileName);
  975. //载入模板
  976. var designer = new WorkbookDesigner
  977. {
  978. Workbook = new Workbook(tempPath)
  979. };
  980. if (tempId == 1406)
  981. {
  982. var view1 = data.Items.Where(x => x.Index < 11).ToArray();
  983. var view2 = data.Items.Where(x => x.Index > 10).ToArray();
  984. for (int i = 1; i <= view2.Length; i++)
  985. {
  986. view2[i - 1].Index = i;
  987. }
  988. designer.SetDataSource("View1", view1);
  989. designer.SetDataSource("View2", view2);
  990. }
  991. else
  992. {
  993. designer.SetDataSource("View", data.Items);
  994. }
  995. designer.Process();
  996. if (!Directory.Exists(savePath))
  997. {
  998. Directory.CreateDirectory(savePath);
  999. }
  1000. string serverPath = $"{savePath}{fileName}";
  1001. designer.Workbook.Save(serverPath);
  1002. string rst = $"{servicePath}{ftpPath}{fileName}";
  1003. #endregion
  1004. return Ok(JsonView(new { url = rst }));
  1005. }
  1006. #endregion
  1007. #region 团组基本信息
  1008. /// <summary>
  1009. /// 接团信息列表
  1010. /// </summary>
  1011. /// <param name="dto">团组列表请求dto</param>
  1012. /// <returns></returns>
  1013. [HttpPost]
  1014. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1015. public async Task<IActionResult> GetGroupList(GroupListDto dto)
  1016. {
  1017. var groupData = await _groupRepository.GetGroupList(dto);
  1018. if (groupData.Code != 0)
  1019. {
  1020. return Ok(JsonView(false, groupData.Msg));
  1021. }
  1022. return Ok(JsonView(groupData.Data));
  1023. }
  1024. /// <summary>
  1025. /// 分页查询团组列表
  1026. /// </summary>
  1027. /// <param name="dto"></param>
  1028. /// <returns></returns>
  1029. [HttpPost]
  1030. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1031. public async Task<IActionResult> QueryGroupListOffset(QueryGroupListOffsetDto dto)
  1032. {
  1033. var watch = new Stopwatch();
  1034. watch.Start();
  1035. RefAsync<int> total = 0;
  1036. var countyDatas = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  1037. .Where((di) => di.IsDel == 0 && !string.IsNullOrWhiteSpace(di.TeamName))
  1038. .WhereIF(!string.IsNullOrEmpty(dto.Search), (di) => di.TeamName.Contains(dto.Search))
  1039. .OrderBy((di) => new { id = SqlFunc.Desc(di.Id) })
  1040. .Select((di) => new { id = di.Id, name = di.TeamName, di.ClientName, di.VisitPNumber, di.VisitCountry, di.VisitDays, di.VisitStartDate, di.VisitEndDate, di.TourCode })
  1041. .Distinct()
  1042. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  1043. watch.Stop();
  1044. return Ok(JsonView(true, $"{MsgTips.Succeed},耗时 {watch.ElapsedMilliseconds} ms", countyDatas, total));
  1045. }
  1046. /// <summary>
  1047. /// 接团信息列表 Page Init
  1048. /// </summary>
  1049. /// <returns></returns>
  1050. [HttpPost]
  1051. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1052. public async Task<IActionResult> PostGroupPageListInit()
  1053. {
  1054. var depDatas = await GeneralMethod.GroupOpAffiliationBranchInit();
  1055. var rankDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 56).Select(x => new { x.Id, x.Name }).ToListAsync();
  1056. rankDatas.Insert(0, new { Id = 0, Name = "全部" });
  1057. var _view = new
  1058. {
  1059. depData = depDatas,
  1060. rankData = rankDatas
  1061. };
  1062. return Ok(JsonView(true, "查询成功!", _view));
  1063. }
  1064. /// <summary>
  1065. /// 接团信息列表 关键字输入提示
  1066. /// </summary>
  1067. /// <param name="keyword">关键字</param>
  1068. /// <returns></returns>
  1069. [HttpGet]
  1070. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1071. public async Task<IActionResult> GroupItemNativeKeywordSearch(string keyword)
  1072. {
  1073. var jw = JsonView(true, "暂无数据");
  1074. if (string.IsNullOrEmpty(keyword)) return Ok(jw);
  1075. var expression = Expressionable
  1076. .Create<Grp_DelegationInfo>()
  1077. .And(x => x.IsDel == 0);
  1078. string field = "TeamName,ClientUnit,ClientName";
  1079. var groupData = _sqlSugar.Queryable<Grp_DelegationInfo>()
  1080. .Where(expression.ToExpression())
  1081. .Select(field)
  1082. .ToList();
  1083. var keywordArray = keyword.ToCharArray();
  1084. var matches = groupData
  1085. .Where(fullString => !string.IsNullOrWhiteSpace(fullString.TeamName) &&
  1086. keywordArray.All(keyword => fullString.TeamName.Contains(keyword)))
  1087. .Select(x => new
  1088. {
  1089. x.TeamName,
  1090. x.ClientUnit,
  1091. x.ClientName
  1092. })
  1093. .DistinctBy(x => x.TeamName)
  1094. .ToList();
  1095. if (matches.Any())
  1096. {
  1097. jw.Code = StatusCodes.Status200OK;
  1098. jw.Msg = "搜索成功";
  1099. jw.Data = matches;
  1100. jw.Count = matches.Count;
  1101. }
  1102. return Ok(jw);
  1103. }
  1104. /// <summary>
  1105. /// 接团信息列表 关键字输入提示(智能版)
  1106. /// </summary>
  1107. /// <param name="keyword">关键字</param>
  1108. /// <returns></returns>
  1109. [HttpGet]
  1110. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1111. public async Task<IActionResult> GroupItemKeywordSearch(string keyword)
  1112. {
  1113. try
  1114. {
  1115. // 验证请求参数
  1116. if (string.IsNullOrEmpty(keyword))
  1117. {
  1118. return Ok(JsonView(true, $"暂无数据!"));
  1119. }
  1120. var searchRequest = new DynamicSearchRequest
  1121. {
  1122. Keyword = keyword,
  1123. RequireAllSingleChars = true,
  1124. PageIndex = 1,
  1125. PageSize = 999999,
  1126. FieldWeights = new Dictionary<string, int>
  1127. {
  1128. { "TeamName", 10 }
  1129. },
  1130. Filters = new List<SearchFilter>()
  1131. {
  1132. new(){Field = "IsDel",Operator="eq",Value="0" }
  1133. },
  1134. OrderBy = "VisitDate",
  1135. ReturnFields = new List<string>() { "TeamName", "ClientUnit", "ClientName" }
  1136. };
  1137. // 验证字段配置
  1138. var validation = _groupSearchService.ValidateFieldConfig(
  1139. searchRequest.FieldWeights,
  1140. searchRequest.ReturnFields);
  1141. if (!validation.IsValid)
  1142. {
  1143. return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
  1144. }
  1145. var result = await _groupSearchService.SearchAsync(searchRequest);
  1146. if (result.Success)
  1147. {
  1148. var data = new List<dynamic>();
  1149. foreach (var item in result.Items)
  1150. {
  1151. data.Add(new
  1152. {
  1153. item.Data.TeamName,
  1154. item.Data.ClientUnit,
  1155. item.Data.ClientName,
  1156. //item.Data.VisitDate
  1157. });
  1158. }
  1159. return Ok(JsonView(true, result.Message, data, data.Count));
  1160. }
  1161. return Ok(JsonView(true, result.Message));
  1162. }
  1163. catch (Exception ex)
  1164. {
  1165. return Ok(JsonView(true, $"搜索服务暂时不可用!"));
  1166. }
  1167. }
  1168. /// <summary>
  1169. /// 接团信息列表 Page
  1170. /// </summary>
  1171. /// <param name="dto">团组列表请求dto</param>
  1172. /// <returns></returns>
  1173. [HttpPost]
  1174. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1175. public async Task<IActionResult> PostGroupPageList(GroupPageListDto dto)
  1176. {
  1177. // 创建Stopwatch实例
  1178. var stopwatch = new Stopwatch();
  1179. stopwatch.Start();
  1180. #region 参数验证
  1181. if (dto.UserId < 1)
  1182. return Ok(JsonView(false, "员工Id为空"));
  1183. if (dto.PageId < 1)
  1184. return Ok(JsonView(false, "页面Id为空"));
  1185. #region 页面操作权限验证
  1186. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1187. if (pageFunAuthView.CheckAuth == 0)
  1188. return Ok(JsonView(false, "您没有查看权限"));
  1189. #endregion
  1190. #endregion
  1191. //if (dto.PortType != 1 && dto.PortType != 2) // web/Android
  1192. // return Ok(JsonView(false, "不支持的端口类型"));
  1193. // 构建查询条件
  1194. var sqlWhereBuilder = new StringBuilder(" WHERE gdi.IsDel = 0");
  1195. var parameters = new List<SugarParameter>();
  1196. // 完成状态筛选
  1197. if (dto.IsSure == 0 || dto.IsSure == 1)
  1198. {
  1199. sqlWhereBuilder.Append(" AND gdi.IsSure = @IsSure");
  1200. parameters.Add(new SugarParameter("@IsSure", dto.IsSure));
  1201. }
  1202. // 搜索条件
  1203. if (!string.IsNullOrWhiteSpace(dto.SearchCriteria))
  1204. {
  1205. var searchParam = $"%{dto.SearchCriteria.Trim()}%";
  1206. sqlWhereBuilder.Append(@"
  1207. AND (ssd.Name LIKE @SearchCriteria
  1208. OR gdi.TeamName LIKE @SearchCriteria
  1209. OR gdi.ClientName LIKE @SearchCriteria
  1210. OR su.CnName LIKE @SearchCriteria)");
  1211. parameters.Add(new SugarParameter("@SearchCriteria", searchParam));
  1212. }
  1213. // 等级筛选
  1214. if (int.TryParse(dto.Rank, out int rankId) && rankId > 0)
  1215. {
  1216. sqlWhereBuilder.Append(" AND gdi.TeamLevSId = @RankId");
  1217. parameters.Add(new SugarParameter("@RankId", rankId));
  1218. }
  1219. // 部门筛选
  1220. var departmentWhere = string.Empty;
  1221. if (!string.IsNullOrWhiteSpace(dto.Department) && !dto.Department.Equals("全部"))
  1222. {
  1223. departmentWhere = " WHERE Department = @Department";
  1224. parameters.Add(new SugarParameter("@Department", dto.Department));
  1225. }
  1226. // 构建SQL查询
  1227. string sql = $@"
  1228. SELECT Row_Number, Id, SalesQuoteNo, TourCode, TeamTypeId, TeamType, Department,
  1229. TeamLevId, TeamLev, TeamName, ClientName, ClientUnit,
  1230. VisitDate, VisitDays, VisitPNumber, JietuanOperatorId,
  1231. JietuanOperator, IsSure, CreateTime, IsBid, Step,
  1232. CONVERT(VARCHAR(19), StepOperationTime, 20) AS StepOperationTime
  1233. FROM (
  1234. SELECT ROW_NUMBER() OVER(ORDER BY gdi.VisitStartDate DESC) AS Row_Number,
  1235. CASE
  1236. WHEN gdi.JietuanOperator IN (4, 21) THEN '国交部'
  1237. ELSE (SELECT DepName FROM OA2023DB.dbo.Sys_Department WHERE Id = su.DepId)
  1238. END AS 'Department',
  1239. gdi.Id, SalesQuoteNo, TourCode, ssd.Id AS TeamTypeId, ssd.Name AS TeamType, gdi.Step,
  1240. ssd1.Id AS TeamLevId, ssd1.Name AS TeamLev, TeamName, ClientName, ClientUnit,
  1241. VisitDate, VisitDays, VisitPNumber, JietuanOperator AS JietuanOperatorId,
  1242. su.CnName AS JietuanOperator, IsSure, gdi.CreateTime, gdi.IsBid,StepOperationTime
  1243. FROM Grp_DelegationInfo gdi
  1244. LEFT JOIN Sys_SetData ssd ON gdi.TeamDid = ssd.Id
  1245. LEFT JOIN Sys_SetData ssd1 ON gdi.TeamLevSId = ssd1.Id
  1246. LEFT JOIN Sys_Users su ON gdi.JietuanOperator = su.Id
  1247. {sqlWhereBuilder}
  1248. ) temp {departmentWhere}";
  1249. // 执行分页查询
  1250. RefAsync<int> total = 0;
  1251. var delegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql)
  1252. .AddParameters(parameters)
  1253. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  1254. if (!delegationList.Any())
  1255. {
  1256. var emptyView = new
  1257. {
  1258. PageFuncAuth = pageFunAuthView,
  1259. Data = delegationList
  1260. };
  1261. return Ok(JsonView(true, "查询成功,暂无数据", emptyView, total));
  1262. }
  1263. // 批量处理团组模块实际操作人和背景颜色设置
  1264. await ProcessDelegationListData(delegationList);
  1265. var resultView = new
  1266. {
  1267. PageFuncAuth = pageFunAuthView,
  1268. Data = delegationList
  1269. };
  1270. stopwatch.Stop();
  1271. return Ok(JsonView(true, $"查询成功!耗时:{stopwatch.Elapsed.TotalSeconds:F3}s", resultView, total));
  1272. }
  1273. /// <summary>
  1274. /// 批量处理团组数据
  1275. /// </summary>
  1276. private async Task ProcessDelegationListData(List<DelegationListView> delegationList)
  1277. {
  1278. var groupIds = delegationList.Select(x => x.Id).ToList();
  1279. // 批量查询信用卡支付记录
  1280. var creditCardPayments = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  1281. .Where(y => groupIds.Contains(y.DIId) && y.IsDel == 0)
  1282. .Select(y => y.DIId)
  1283. .Distinct()
  1284. .ToListAsync();
  1285. // 批量查询费用确认记录
  1286. var feeAcknowledgements = await _sqlSugar.Queryable<Grp_FeeEntryAcknowledge>()
  1287. .Where(y => groupIds.Contains(y.GroupId) && y.IsDel == 0)
  1288. .Where(y => y.IsAcknowledged == AcknowledgeStatusEnum.Acknowledged)
  1289. .Select(y => y.GroupId)
  1290. .Distinct()
  1291. .ToListAsync();
  1292. var creditCardPaymentSet = creditCardPayments.ToHashSet();
  1293. var feeAcknowledgementSet = feeAcknowledgements.ToHashSet();
  1294. // 并行处理每个团组
  1295. var tasks = delegationList.Select(async x =>
  1296. {
  1297. // 处理团组模块实际操作人
  1298. var operators = GeneralMethod.GetGroupModuleOperators(x.Id);
  1299. var operatorNames = new StringBuilder();
  1300. if (operators.Any())
  1301. {
  1302. foreach (var operatorInfo in operators)
  1303. {
  1304. string label = operatorInfo.OperationUsers.Any()
  1305. ? string.Join('、', operatorInfo.OperationUsers.Select(u => u.UserName))
  1306. : "暂未指定";
  1307. operatorNames.AppendLine($"{operatorInfo.CTableName}:{label}");
  1308. operatorNames.AppendLine();
  1309. }
  1310. }
  1311. x.OperatorLabel = operatorNames.ToString().TrimEnd('\n', '\r');
  1312. // 设置背景颜色为红色
  1313. // C表没数据并且没点提醒确认按钮(无成本费用按钮)的团组该行显示红色
  1314. bool hasCreditCardPayment = creditCardPaymentSet.Contains(x.Id);
  1315. bool hasFeeAcknowledgement = feeAcknowledgementSet.Contains(x.Id);
  1316. x.UseRedBackground = !hasCreditCardPayment && !hasFeeAcknowledgement;
  1317. });
  1318. await Task.WhenAll(tasks);
  1319. }
  1320. /// <summary>
  1321. /// 团组列表
  1322. /// </summary>
  1323. /// <returns></returns>
  1324. [HttpPost]
  1325. public async Task<IActionResult> GetGroupListByWhere(GroupListByWhere dto)
  1326. {
  1327. #region 参数验证
  1328. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  1329. if (dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  1330. #region 页面操作权限验证
  1331. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1332. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  1333. #endregion
  1334. #endregion
  1335. if (dto.PortType != 1 && dto.PortType != 2)
  1336. {
  1337. return Ok(JsonView(false, "查询失败!"));
  1338. }
  1339. string orderbyStr = "order by gdi.CreateTime Desc";
  1340. string sqlWhere = string.Empty;
  1341. if (dto.IsSure == 0) //未完成
  1342. {
  1343. sqlWhere += string.Format(@" And IsSure = 0");
  1344. }
  1345. else if (dto.IsSure == 1) //已完成
  1346. {
  1347. sqlWhere += string.Format(@" And IsSure = 1");
  1348. }
  1349. //团组类型
  1350. if (dto.TeamDid > 0)
  1351. {
  1352. sqlWhere += string.Format(@"And TeamDid = {0} ", dto.TeamDid);
  1353. }
  1354. //团组名称
  1355. if (!string.IsNullOrEmpty(dto.TeamName))
  1356. {
  1357. sqlWhere += string.Format(@"And TeamName Like '%{0}%'", dto.TeamName);
  1358. }
  1359. //客户名称
  1360. if (!string.IsNullOrEmpty(dto.ClientName))
  1361. {
  1362. sqlWhere += string.Format(@"And ClientName Like '%{0}%'", dto.ClientName);
  1363. }
  1364. //客户单位
  1365. if (!string.IsNullOrEmpty(dto.ClientUnit))
  1366. {
  1367. sqlWhere += string.Format(@"And ClientUnit Like '%{0}%'", dto.ClientUnit);
  1368. }
  1369. //出访时间
  1370. if (!string.IsNullOrEmpty(dto.visitDataTime))
  1371. {
  1372. sqlWhere += string.Format(@"And VisitDate >= '{0}'", dto.visitDataTime);
  1373. orderbyStr = "order by gdi.VisitDate";
  1374. }
  1375. string sql = string.Format(@"Select Row_Number,Id,SalesQuoteNo,TourCode,TeamTypeId, TeamType,
  1376. TeamLevId,TeamLev,TeamName,ClientName,ClientUnit,
  1377. VisitDate,VisitDays,VisitPNumber,JietuanOperatorId,
  1378. JietuanOperator,IsSure,CreateTime
  1379. From (
  1380. Select row_number() over({0}) as Row_Number,
  1381. gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,
  1382. ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,
  1383. VisitDate,VisitDays,VisitPNumber,JietuanOperator JietuanOperatorId,
  1384. su.CnName JietuanOperator,IsSure,gdi.CreateTime
  1385. From Grp_DelegationInfo gdi
  1386. Left Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  1387. Left Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  1388. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  1389. Where gdi.IsDel = 0 {1}
  1390. ) temp ", orderbyStr, sqlWhere);
  1391. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  1392. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);//ToPageAsync
  1393. #region 处理所属部门
  1394. /*
  1395. * 1.sq 和 gyy 等显示 市场部
  1396. * 2.王鸽和主管及张总还有管理员号统一国交部
  1397. * 2-1. 4 管理员 ,21 张海麟
  1398. */
  1399. var userIds = _DelegationList.Select(it => it.JietuanOperatorId).ToList();
  1400. var userIds1 = new List<int>() { 4, 21 };
  1401. var UserDepDatas = _sqlSugar.Queryable<Sys_Users>()
  1402. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  1403. .Where(u => u.IsDel == 0 && userIds.Contains(u.Id))
  1404. .Select((u, d) => new { UserId = u.Id, DepName = userIds1.Contains(u.Id) ? "国交部" : d.DepName })
  1405. .ToList();
  1406. foreach (var item in _DelegationList)
  1407. {
  1408. item.Department = UserDepDatas.Find(it => item.JietuanOperatorId == it.UserId)?.DepName ?? "Unknown";
  1409. }
  1410. #endregion
  1411. var _view = new
  1412. {
  1413. PageFuncAuth = pageFunAuthView,
  1414. Data = _DelegationList
  1415. };
  1416. return Ok(JsonView(true, $"查询成功!", _view, total));
  1417. }
  1418. /// <summary>
  1419. /// 接团信息详情
  1420. /// </summary>
  1421. /// <param name="dto">团组info请求dto</param>
  1422. /// <returns></returns>
  1423. [HttpPost]
  1424. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1425. public async Task<IActionResult> GetGroupInfo(GroupInfoDto dto)
  1426. {
  1427. var groupData = await _groupRepository.GetGroupInfo(dto);
  1428. if (groupData.Code != 0)
  1429. {
  1430. return Ok(JsonView(false, groupData.Msg));
  1431. }
  1432. return Ok(JsonView(groupData.Data));
  1433. }
  1434. /// <summary>
  1435. /// 接团信息 编辑添加
  1436. /// 基础信息数据源
  1437. /// </summary>
  1438. /// <param name="dto"></param>
  1439. /// <returns></returns>
  1440. [HttpPost]
  1441. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1442. public async Task<IActionResult> GroupEditBasicSource(GroupListDto dto)
  1443. {
  1444. var groupData = await _groupRepository.GroupEditBasicSource(dto);
  1445. if (groupData.Code != 0)
  1446. {
  1447. return Ok(JsonView(false, groupData.Msg));
  1448. }
  1449. return Ok(JsonView(groupData.Data));
  1450. }
  1451. /// <summary>
  1452. /// 成本修改团组信息
  1453. /// </summary>
  1454. /// <param name="dto"></param>
  1455. /// <returns></returns>
  1456. [HttpPost]
  1457. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1458. public async Task<IActionResult> GroupCostEditGroupInfo(GroupCostEditGroupInfoDto dto)
  1459. {
  1460. var jw = JsonView(false, "操作失败");
  1461. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  1462. if (di == null)
  1463. {
  1464. jw.Msg = "参数有误!";
  1465. return Ok(jw);
  1466. }
  1467. #region 添加出访起止时间
  1468. var startTime = new DateTime();
  1469. var endTime = new DateTime();
  1470. if (DateTime.TryParse(dto.VisitDate, out startTime))
  1471. {
  1472. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  1473. }
  1474. else
  1475. {
  1476. jw.Msg = "参数有误!";
  1477. return Ok(jw);
  1478. }
  1479. #endregion
  1480. #region 验证出访时间是否有变化 有变化则重新生成倒推表
  1481. if (!startTime.ToString("yyyy-MM-dd").Equals(di.VisitDate.ToString("yyyy-MM-dd")))
  1482. {
  1483. var msg = "团组成本模块修改出访时间,删除倒推表重新生成";
  1484. var softDel = await _sqlSugar.Updateable<Grp_InvertedList>()
  1485. .SetColumns(x => x.IsDel == 1)
  1486. .SetColumns(x => x.DeleteUserId == 4)
  1487. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  1488. .SetColumns(x => x.Remark == msg)
  1489. .Where(x => x.DiId == dto.Diid)
  1490. .ExecuteCommandAsync();
  1491. //默认创建倒推表
  1492. await _invertedListRep.Create(4, dto.Diid, msg);
  1493. }
  1494. #endregion
  1495. di.VisitDate = startTime;
  1496. di.VisitPNumber = dto.VisitPNumber;
  1497. di.VisitDays = dto.VisitDays;
  1498. di.VisitStartDate = startTime;
  1499. di.VisitEndDate = endTime;
  1500. var count = _sqlSugar.Updateable(di)
  1501. .UpdateColumns(x => new { x.VisitDate, x.VisitPNumber, x.VisitDays, x.VisitStartDate, x.VisitEndDate })
  1502. .ExecuteCommand();
  1503. return Ok(count > 0 ? JsonView(true, "操作成功") : jw);
  1504. }
  1505. /// <summary>
  1506. /// 接团信息 编辑添加
  1507. /// 省份-城市 基础信息数据源
  1508. /// </summary>
  1509. /// <param name="dto"></param>
  1510. /// <returns></returns>
  1511. [HttpPost]
  1512. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1513. public async Task<IActionResult> GroupProvCityBasicSource(GroupProvCityBasicSourceDto dto)
  1514. {
  1515. int pageIndex = dto.PageIndex, pageSize = dto.PageSize;
  1516. string search = dto.Search;
  1517. var data = await _groupRepository.CityBasicSource();
  1518. int total = data.Length;
  1519. data = data.WhereIF(!string.IsNullOrEmpty(search), x => x.Name.Contains(search))
  1520. .Skip((pageIndex - 1) * pageSize)
  1521. .Take(pageSize)
  1522. .ToArray();
  1523. return Ok(JsonView(data, total));
  1524. }
  1525. /// <summary>
  1526. /// 接团信息 操作(增改)
  1527. /// </summary>
  1528. /// <param name="dto"></param>
  1529. /// <returns></returns>
  1530. [HttpPost]
  1531. [ApiLog("Grp_DelegationInfo", OperationEnum.Edit)]
  1532. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1533. public async Task<IActionResult> GroupOperation(GroupOperationDto dto)
  1534. {
  1535. // 创建 Stopwatch 实例
  1536. Stopwatch stopwatch = Stopwatch.StartNew();
  1537. decimal ffrPrice = 0.00M;
  1538. DateTime? visitDt = null;
  1539. if (dto.Status == 2)
  1540. {
  1541. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.Id && x.IsDel == 0);
  1542. if (groupInfo != null)
  1543. {
  1544. ffrPrice = groupInfo.PaymentMoney;
  1545. visitDt = groupInfo.VisitDate.AddDays(-groupInfo.PayDay);
  1546. #region 验证出访时间是否有变化 有变化则重新生成倒推表
  1547. if (DateTime.TryParse(dto.VisitDate, out DateTime startTime))
  1548. {
  1549. if (!startTime.ToString("yyyy-MM-dd").Equals(groupInfo.VisitDate.ToString("yyyy-MM-dd")))
  1550. {
  1551. var msg = "团组信息模块修改出访时间,删除倒推表重新生成";
  1552. var softDel = await _sqlSugar.Updateable<Grp_InvertedList>()
  1553. .SetColumns(x => x.IsDel == 1)
  1554. .SetColumns(x => x.DeleteUserId == 4)
  1555. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  1556. .SetColumns(x => x.Remark == msg)
  1557. .Where(x => x.DiId == dto.Id)
  1558. .ExecuteCommandAsync();
  1559. //默认创建倒推表
  1560. await _invertedListRep.Create(dto.UserId, dto.Id, msg);
  1561. }
  1562. }
  1563. #endregion
  1564. }
  1565. }
  1566. var groupData = await _groupRepository.GroupOperation(dto);
  1567. if (groupData.Code != 0)
  1568. {
  1569. return Ok(JsonView(false, groupData.Msg));
  1570. }
  1571. int diId = 0;
  1572. try
  1573. {
  1574. //添加时 默认加入团组汇率
  1575. if (dto.Status == 1) //添加
  1576. {
  1577. diId = groupData.Data;
  1578. //添加默认币种
  1579. await GeneralMethod.PostGroupRateAddInit(dto.UserId, diId);
  1580. //默认分配权限
  1581. await GeneralMethod.PostGroupAuthAddInit(dto.UserId, diId);
  1582. //消息提示 王鸽 主管号 2024-10-21 新增LZ UID
  1583. var _managerIds = new List<int>() { 22, 32, 21 };
  1584. var userIds = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && _managerIds.Contains(it.JobPostId)).Select(it => it.Id).ToList();
  1585. if (userIds.Count > 0)
  1586. {
  1587. userIds.Add(208);
  1588. //创建团组管控
  1589. GroupStepForDelegation.CreateWorkStep(diId);
  1590. //发送消息
  1591. string groupName = dto.TeamName;
  1592. string createGroupUser = string.Empty;
  1593. var userInfo = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.Id == dto.UserId).First();
  1594. if (userInfo != null) createGroupUser = userInfo.CnName;
  1595. string title = $"系统通知";
  1596. string content = $"团组[{groupName}(创建人:{createGroupUser})]创建成功,请前往页面进行下一步操作!";
  1597. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  1598. }
  1599. //默认创建倒推表
  1600. await _invertedListRep.Create(dto.UserId, diId);
  1601. //默认创建签证流程
  1602. await _visaProcessRep.Create(dto.UserId, diId);
  1603. //默认创建团组流程总览信息
  1604. await _processOverviewRep.ProcessInitAsync(diId, dto.UserId);
  1605. }
  1606. else if (dto.Status == 2)
  1607. {
  1608. diId = dto.Id;
  1609. }
  1610. #region 签证人员团组时间通知
  1611. #region 计算出访起止时间
  1612. var startTime = new DateTime();
  1613. var endTime = new DateTime();
  1614. if (DateTime.TryParse(dto.VisitDate, out startTime))
  1615. {
  1616. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  1617. }
  1618. #endregion
  1619. #endregion
  1620. #region 团组操作默认添加/修改收款账单
  1621. if (dto.PayDay > 0 && dto.PaymentMoney > 0)
  1622. {
  1623. var ffrInfo = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  1624. .Where(x => x.IsDel == 0 &&
  1625. x.Diid == diId &&
  1626. x.Remark.Equals("预付款")
  1627. )
  1628. .WhereIF(ffrPrice > 0, x => x.ItemSumPrice == ffrPrice)
  1629. .WhereIF(visitDt != null, x => x.CreateTime == visitDt)
  1630. .FirstAsync();
  1631. ffrInfo = new Fin_ForeignReceivables()
  1632. {
  1633. Diid = diId,
  1634. PriceName = dto.ClientUnit,
  1635. Price = dto.PaymentMoney,
  1636. Count = 1,
  1637. Unit = $"元",
  1638. ItemSumPrice = dto.PaymentMoney,
  1639. Rate = 1.0000M,
  1640. Currency = 836,
  1641. AddingWay = 0,
  1642. CreateUserId = dto.UserId,
  1643. CreateTime = Convert.ToDateTime(dto.VisitDate).AddDays(-dto.PayDay),
  1644. Remark = $"预付款"
  1645. };
  1646. if (ffrInfo == null) //Add
  1647. {
  1648. await _sqlSugar.Insertable(ffrInfo).ExecuteCommandAsync();
  1649. }
  1650. else //修改
  1651. {
  1652. await _sqlSugar.Updateable(ffrInfo)
  1653. .UpdateColumns(x => new
  1654. {
  1655. x.PriceName,
  1656. x.Price,
  1657. x.ItemSumPrice,
  1658. x.CreateTime,
  1659. x.CreateUserId
  1660. })
  1661. .WhereColumns(x => x.Id)
  1662. .ExecuteCommandAsync();
  1663. }
  1664. }
  1665. #endregion
  1666. if (diId > 0)
  1667. {
  1668. await AppNoticeLibrary.SendUserMsg_GroupTimeInfo_ToVisaUser(diId, startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"));
  1669. }
  1670. // 停止计时
  1671. stopwatch.Stop();
  1672. return Ok(JsonView(true, $"操作成功!{stopwatch.ElapsedMilliseconds}ms", diId));
  1673. }
  1674. catch (Exception ex)
  1675. {
  1676. // 停止计时
  1677. stopwatch.Stop();
  1678. Logs("[response]" + JsonConvert.SerializeObject(dto));
  1679. Logs(ex.Message);
  1680. //return Ok(JsonView(false, $"{ex.Message}[{stopwatch.ElapsedMilliseconds}ms]"));
  1681. }
  1682. // 停止计时
  1683. stopwatch.Stop();
  1684. return Ok(JsonView(true, $"操作成功!{stopwatch.ElapsedMilliseconds}ms", diId));
  1685. }
  1686. /// <summary>
  1687. /// 团组聚合API测试接口
  1688. /// </summary>
  1689. /// <param name="userId"></param>
  1690. /// <param name="groupId"></param>
  1691. /// <returns></returns>
  1692. [HttpPost]
  1693. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1694. public async Task<IActionResult> GroupJuHeAPITest(int userId, int groupId)
  1695. {
  1696. //添加默认币种
  1697. var currencyData = await GeneralMethod.PostGroupRateAddInit(userId, groupId);
  1698. return Ok(JsonView(true, $"操作成功!", currencyData.Data));
  1699. }
  1700. /// <summary>
  1701. /// 接团流程操作(增改)
  1702. /// 安卓端使用 建团时添加客户名单
  1703. /// </summary>
  1704. /// <param name="dto"></param>
  1705. /// <returns></returns>
  1706. [HttpPost]
  1707. [ApiLog("Grp_DelegationInfo", OperationEnum.Edit)]
  1708. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1709. public async Task<IActionResult> GroupProcessOperation(GroupProcessOperationDto dto)
  1710. {
  1711. #region 参数验证
  1712. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  1713. #region 页面操作权限验证
  1714. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, 104);
  1715. //if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "客户名单您没有添加权限!"));
  1716. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, 27);
  1717. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "团组操作您没有添加权限!"));
  1718. #endregion
  1719. #endregion
  1720. try
  1721. {
  1722. //_sqlSugar.BeginTran();
  1723. decimal ffrPrice = 0.00M;
  1724. DateTime? visitDt = null;
  1725. if (dto.Status == 2)
  1726. {
  1727. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.Id && x.IsDel == 0);
  1728. if (groupInfo != null)
  1729. {
  1730. ffrPrice = groupInfo.PaymentMoney;
  1731. visitDt = groupInfo.VisitDate.AddDays(-groupInfo.PayDay);
  1732. }
  1733. }
  1734. var _dto = new GroupOperationDto();
  1735. _dto = _mapper.Map<GroupProcessOperationDto, GroupOperationDto>(dto);
  1736. var groupData = await _groupRepository.GroupOperation(_dto);
  1737. if (groupData.Code != 0)
  1738. {
  1739. return Ok(JsonView(false, "团组操作添加失败!" + groupData.Msg));
  1740. }
  1741. int diId = 0;
  1742. //添加时 默认加入团组汇率
  1743. if (dto.Status == 1) //添加
  1744. {
  1745. diId = groupData.Data;
  1746. //添加默认币种
  1747. await GeneralMethod.PostGroupRateAddInit(dto.UserId, diId);
  1748. //默认分配权限
  1749. await GeneralMethod.PostGroupAuthAddInit(dto.UserId, diId);
  1750. //消息提示 王鸽 主管号 2024-10-21 新增LZ UID
  1751. var _managerIds = new List<int>() { 21, 22, 32 };
  1752. var userIds = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && _managerIds.Contains(it.JobPostId)).Select(it => it.Id).ToList();
  1753. if (userIds.Count > 0)
  1754. {
  1755. userIds.Add(208);
  1756. //创建团组管控
  1757. GroupStepForDelegation.CreateWorkStep(diId);
  1758. //发送消息
  1759. string groupName = dto.TeamName;
  1760. string createGroupUser = string.Empty;
  1761. var userInfo = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.Id == dto.UserId).First();
  1762. if (userInfo != null) createGroupUser = userInfo.CnName;
  1763. string title = $"系统通知";
  1764. string content = $"团组[{groupName}(创建人:{createGroupUser})]创建成功,请前往页面进行下一步操作!";
  1765. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  1766. }
  1767. #region 应用推送
  1768. try
  1769. {
  1770. await AppNoticeLibrary.SendChatMsg_GroupStatus_Create(diId, QiyeWeChatEnum.CompanyCRMChat);
  1771. Sys_Users users = _airTicketResRep.Query<Sys_Users>(s => s.Id == dto.UserId).First();
  1772. Sys_Department department = _airTicketResRep.Query<Sys_Department>(s => s.Id == users.DepId).First();
  1773. if (department.Id == 6 && !string.IsNullOrEmpty(users.QiyeChatUserId))
  1774. {
  1775. var userList = new List<string>() { users.QiyeChatUserId };
  1776. await AppNoticeLibrary.SendUserMsg_GroupStatus_Create(diId, userList);
  1777. }
  1778. }
  1779. catch (Exception ex)
  1780. {
  1781. }
  1782. #endregion
  1783. //默认创建倒推表
  1784. await _invertedListRep.Create(dto.UserId, diId);
  1785. //默认创建签证流程
  1786. await _visaProcessRep.Create(dto.UserId, diId);
  1787. //默认创建团组流程总览信息
  1788. await _processOverviewRep.ProcessInitAsync(diId, dto.UserId);
  1789. }
  1790. if (dto.Status == 2)
  1791. {
  1792. diId = dto.Id;
  1793. if (diId == 0)
  1794. {
  1795. //_sqlSugar.RollbackTran();
  1796. return Ok(JsonView(false, "修改失败! 未添加团组id" + groupData.Msg));
  1797. }
  1798. }
  1799. var viewData = await _tourClientListRep.OperMultiple(dto.TourClientListInfos, diId, dto.UserId);
  1800. if (viewData.Code != 0)
  1801. {
  1802. //_sqlSugar.RollbackTran();
  1803. return Ok(JsonView(false, "客户名单添加失败!" + viewData.Msg));
  1804. }
  1805. #region 团组操作默认添加/修改收款账单
  1806. if (dto.PayDay > 0 && dto.PaymentMoney > 0)
  1807. {
  1808. var ffrInfo = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  1809. .Where(x => x.IsDel == 0 &&
  1810. x.Diid == diId &&
  1811. x.Remark.Equals("预付款")
  1812. )
  1813. .WhereIF(ffrPrice > 0, x => x.ItemSumPrice == ffrPrice)
  1814. .WhereIF(visitDt != null, x => x.CreateTime == visitDt)
  1815. .FirstAsync();
  1816. ffrInfo = new Fin_ForeignReceivables()
  1817. {
  1818. Diid = diId,
  1819. PriceName = dto.ClientUnit,
  1820. Price = dto.PaymentMoney,
  1821. Count = 1,
  1822. Unit = $"元",
  1823. ItemSumPrice = dto.PaymentMoney,
  1824. Rate = 1.0000M,
  1825. Currency = 836,
  1826. AddingWay = 0,
  1827. CreateUserId = dto.UserId,
  1828. CreateTime = Convert.ToDateTime(dto.VisitDate).AddDays(-dto.PayDay),
  1829. Remark = $"预付款"
  1830. };
  1831. if (ffrInfo == null) //Add
  1832. {
  1833. await _sqlSugar.Insertable(ffrInfo).ExecuteCommandAsync();
  1834. }
  1835. else //修改
  1836. {
  1837. await _sqlSugar.Updateable<Fin_ForeignReceivables>(ffrInfo)
  1838. .UpdateColumns(x => new
  1839. {
  1840. x.PriceName,
  1841. x.Price,
  1842. x.ItemSumPrice,
  1843. x.CreateTime,
  1844. x.CreateUserId
  1845. })
  1846. .WhereColumns(x => x.Id)
  1847. .ExecuteCommandAsync();
  1848. }
  1849. }
  1850. #endregion
  1851. #region 签证人员团组时间通知
  1852. #region 计算出访起止时间
  1853. var startTime = new DateTime();
  1854. var endTime = new DateTime();
  1855. if (DateTime.TryParse(dto.VisitDate, out startTime))
  1856. {
  1857. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  1858. }
  1859. #endregion
  1860. if (diId > 0)
  1861. {
  1862. await AppNoticeLibrary.SendUserMsg_GroupTimeInfo_ToVisaUser(diId, startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"));
  1863. }
  1864. #endregion
  1865. //_sqlSugar.CommitTran();
  1866. return Ok(JsonView(true, "添加成功"));
  1867. }
  1868. catch (Exception ex)
  1869. {
  1870. _sqlSugar.RollbackTran();
  1871. return Ok(JsonView(false, ex.Message));
  1872. }
  1873. }
  1874. /// <summary>
  1875. /// 接团流程操作(增改)
  1876. /// 安卓端使用 建团时添加客户名单
  1877. /// </summary>
  1878. /// <param name="dto"></param>
  1879. /// <returns></returns>
  1880. [HttpPost]
  1881. [ApiLog("Grp_DelegationInfo", OperationEnum.Edit)]
  1882. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1883. public async Task<IActionResult> GroupProcessOperation1(GroupProcessOperationDto dto)
  1884. {
  1885. #region 参数验证
  1886. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  1887. #region 页面操作权限验证
  1888. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, 104);
  1889. //if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "客户名单您没有添加权限!"));
  1890. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, 27);
  1891. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "团组操作您没有添加权限!"));
  1892. #endregion
  1893. #endregion
  1894. _sqlSugar.BeginTran();
  1895. decimal ffrPrice = 0.00M;
  1896. DateTime? visitDt = null;
  1897. if (dto.Status == 2)
  1898. {
  1899. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.Id && x.IsDel == 0);
  1900. if (groupInfo != null)
  1901. {
  1902. ffrPrice = groupInfo.PaymentMoney;
  1903. visitDt = groupInfo.VisitDate.AddDays(-groupInfo.PayDay);
  1904. }
  1905. }
  1906. var _dto = new GroupOperationDto();
  1907. _dto = _mapper.Map<GroupProcessOperationDto, GroupOperationDto>(dto);
  1908. var groupData = await _groupRepository.GroupOperation(_dto);
  1909. if (groupData.Code != 0)
  1910. {
  1911. _sqlSugar.RollbackTran();
  1912. return Ok(JsonView(false, "团组操作添加失败!" + groupData.Msg));
  1913. }
  1914. try
  1915. {
  1916. int diId = 0;
  1917. //添加时 默认加入团组汇率
  1918. if (dto.Status == 1) //添加
  1919. {
  1920. diId = groupData.Data;
  1921. //添加默认币种
  1922. await GeneralMethod.PostGroupRateAddInit(dto.UserId, diId);
  1923. //默认分配权限
  1924. await GeneralMethod.PostGroupAuthAddInit(dto.UserId, diId);
  1925. //消息提示 王鸽 主管号 2024-10-21 新增LZ UID
  1926. var _managerIds = new List<int>() { 21, 22, 32 };
  1927. var userIds = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && _managerIds.Contains(it.JobPostId)).Select(it => it.Id).ToList();
  1928. if (userIds.Count > 0)
  1929. {
  1930. userIds.Add(208);
  1931. //创建团组管控
  1932. GroupStepForDelegation.CreateWorkStep(diId);
  1933. //发送消息
  1934. string groupName = dto.TeamName;
  1935. string createGroupUser = string.Empty;
  1936. var userInfo = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.Id == dto.UserId).First();
  1937. if (userInfo != null) createGroupUser = userInfo.CnName;
  1938. string title = $"系统通知";
  1939. string content = $"团组[{groupName}(创建人:{createGroupUser})]创建成功,请前往页面进行下一步操作!";
  1940. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  1941. }
  1942. #region 应用推送
  1943. try
  1944. {
  1945. await AppNoticeLibrary.SendChatMsg_GroupStatus_Create(diId, QiyeWeChatEnum.CompanyCRMChat);
  1946. Sys_Users users = _airTicketResRep.Query<Sys_Users>(s => s.Id == dto.UserId).First();
  1947. Sys_Department department = _airTicketResRep.Query<Sys_Department>(s => s.Id == users.DepId).First();
  1948. if (department.Id == 6 && !string.IsNullOrEmpty(users.QiyeChatUserId))
  1949. {
  1950. var userList = new List<string>() { users.QiyeChatUserId };
  1951. await AppNoticeLibrary.SendUserMsg_GroupStatus_Create(diId, userList);
  1952. }
  1953. }
  1954. catch (Exception ex)
  1955. {
  1956. _sqlSugar.CommitTran();
  1957. return Ok(JsonView(true, "操作成功! 应用推送异常:" + groupData.Msg));
  1958. }
  1959. #endregion
  1960. //默认创建倒推表
  1961. await _invertedListRep.Create(dto.UserId, diId);
  1962. }
  1963. else if (dto.Status == 2)
  1964. {
  1965. diId = dto.Id;
  1966. if (diId == 0)
  1967. {
  1968. _sqlSugar.RollbackTran();
  1969. return Ok(JsonView(false, "操作失败! 未添加团组id" + groupData.Msg));
  1970. }
  1971. }
  1972. var viewData = await _tourClientListRep.OperMultiple(dto.TourClientListInfos, diId, dto.UserId);
  1973. if (viewData.Code != 0)
  1974. {
  1975. _sqlSugar.RollbackTran();
  1976. return Ok(JsonView(false, "客户名单添加失败!" + viewData.Msg));
  1977. }
  1978. #region 团组操作默认添加/修改收款账单
  1979. if (dto.PayDay > 0 && dto.PaymentMoney > 0)
  1980. {
  1981. var ffrInfo = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  1982. .Where(x => x.IsDel == 0 &&
  1983. x.Diid == diId &&
  1984. x.Remark.Equals("预付款")
  1985. )
  1986. .WhereIF(ffrPrice > 0, x => x.ItemSumPrice == ffrPrice)
  1987. .WhereIF(visitDt != null, x => x.CreateTime == visitDt)
  1988. .FirstAsync();
  1989. ffrInfo = new Fin_ForeignReceivables()
  1990. {
  1991. Diid = diId,
  1992. PriceName = dto.ClientUnit,
  1993. Price = dto.PaymentMoney,
  1994. Count = 1,
  1995. Unit = $"元",
  1996. ItemSumPrice = dto.PaymentMoney,
  1997. Rate = 1.0000M,
  1998. Currency = 836,
  1999. AddingWay = 0,
  2000. CreateUserId = dto.UserId,
  2001. CreateTime = Convert.ToDateTime(dto.VisitDate).AddDays(-dto.PayDay),
  2002. Remark = $"预付款"
  2003. };
  2004. if (ffrInfo == null) //Add
  2005. {
  2006. await _sqlSugar.Insertable(ffrInfo).ExecuteCommandAsync();
  2007. }
  2008. else //修改
  2009. {
  2010. await _sqlSugar.Updateable<Fin_ForeignReceivables>(ffrInfo)
  2011. .UpdateColumns(x => new
  2012. {
  2013. x.PriceName,
  2014. x.Price,
  2015. x.ItemSumPrice,
  2016. x.CreateTime,
  2017. x.CreateUserId
  2018. })
  2019. .WhereColumns(x => x.Id)
  2020. .ExecuteCommandAsync();
  2021. }
  2022. }
  2023. #endregion
  2024. #region 签证人员团组时间通知
  2025. #region 计算出访起止时间
  2026. var startTime = new DateTime();
  2027. var endTime = new DateTime();
  2028. if (DateTime.TryParse(dto.VisitDate, out startTime))
  2029. {
  2030. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  2031. }
  2032. #endregion
  2033. if (diId > 0)
  2034. {
  2035. await AppNoticeLibrary.SendUserMsg_GroupTimeInfo_ToVisaUser(diId, startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"));
  2036. }
  2037. #endregion
  2038. _sqlSugar.CommitTran();
  2039. return Ok(JsonView(true));
  2040. }
  2041. catch (Exception ex)
  2042. {
  2043. _sqlSugar.RollbackTran();
  2044. return Ok(JsonView(false, ex.Message));
  2045. }
  2046. }
  2047. /// <summary>
  2048. /// 接团信息 操作(删除)
  2049. /// </summary>
  2050. /// <param name="dto"></param>
  2051. /// <returns></returns>
  2052. [HttpPost]
  2053. [ApiLog("Grp_DelegationInfo", OperationEnum.Del)]
  2054. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2055. public async Task<IActionResult> GroupDel(GroupDelDto dto)
  2056. {
  2057. var diId = dto.Id;
  2058. if (diId < 1) return Ok(JsonView(false, MsgTips.Id));
  2059. #region 删除 验证
  2060. /*
  2061. * 1、收款账单数据:0 条
  2062. * 2、收款退还数据:0 条
  2063. * 3、机票费用数据:0 条
  2064. * 4、签证费用数据:0 条
  2065. * 5、保险费用数据:0 条
  2066. * 6、酒店费用数据:0 条
  2067. * 7、公务出访数据:1 条
  2068. * 8、邀请公务活动费用数据:1 条
  2069. * 9、OP费用数据:5 条
  2070. * 10、其他费用数据:0 条
  2071. * 11、团组日付报销费用数据:0 条
  2072. *
  2073. * 温馨提示:该团组已产生费用,不允许删除;如需删除,请先删除对应版块费用,谢谢!
  2074. */
  2075. //收款账单
  2076. int frCount = _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(x => x.IsDel == 0 && x.Diid == diId).Count();
  2077. //收款退还
  2078. int fraomCount = _sqlSugar.Queryable<Fin_PaymentRefundAndOtherMoney>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2079. //机票费用
  2080. int arCount = _sqlSugar.Queryable<Grp_AirTicketReservations>().Where(x => x.IsDel == 0 && x.DIId == diId).Count();
  2081. //签证费用
  2082. int viCount = _sqlSugar.Queryable<Grp_VisaInfo>().Where(x => x.IsDel == 0 && x.DIId == diId).Count();
  2083. //保险费用
  2084. int cCount = _sqlSugar.Queryable<Grp_Customers>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2085. //酒店费用
  2086. int hrCount = _sqlSugar.Queryable<Grp_HotelReservations>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2087. //公务出访
  2088. int oaCount = _sqlSugar.Queryable<Res_OfficialActivities>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2089. //邀请公务活动费用
  2090. int ioaCount = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2091. //OP费用
  2092. int ctggrCount = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2093. //其他费用
  2094. int dpCount = _sqlSugar.Queryable<Grp_DecreasePayments>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2095. //团组日付报销费用
  2096. int dfpCount = _sqlSugar.Queryable<Fin_DailyFeePayment>().Where(x => x.IsDel == 0 && x.GroupId == diId).Count();
  2097. var feeCount = frCount + fraomCount + arCount + viCount + cCount + hrCount + oaCount + ioaCount + ctggrCount + dpCount + dfpCount;
  2098. if (feeCount > 0)
  2099. {
  2100. var delMsgTips = new StringBuilder();
  2101. delMsgTips.AppendLine($"1、收款账单数据:{frCount} 条");
  2102. delMsgTips.AppendLine($"2、收款退换数据:{fraomCount} 条");
  2103. delMsgTips.AppendLine($"3、机票费用数据:{arCount} 条");
  2104. delMsgTips.AppendLine($"4、签证费用数据:{viCount} 条");
  2105. delMsgTips.AppendLine($"5、保险费用数据:{cCount} 条");
  2106. delMsgTips.AppendLine($"6、酒店费用数据:{hrCount} 条");
  2107. delMsgTips.AppendLine($"7、公务出访数据:{oaCount} 条");
  2108. delMsgTips.AppendLine($"8、邀请公务活动费用数据:{ioaCount} 条");
  2109. delMsgTips.AppendLine($"9、OP费用数据:{ctggrCount} 条");
  2110. delMsgTips.AppendLine($"10、其他费用数据:{dpCount} 条");
  2111. delMsgTips.AppendLine($"11、团组日付报销费用数据:{dfpCount} 条");
  2112. delMsgTips.AppendLine($"");
  2113. delMsgTips.AppendLine($"温馨提示:该团组已产生费用,不允许删除;如需删除,请先删除对应版块费用,谢谢!");
  2114. return Ok(JsonView(false, delMsgTips.ToString()));
  2115. }
  2116. #endregion
  2117. var groupData = await _groupRepository.GroupDel(dto);
  2118. if (groupData.Code != 0)
  2119. {
  2120. return Ok(JsonView(false, groupData.Msg));
  2121. }
  2122. return Ok(JsonView(true));
  2123. }
  2124. /// <summary>
  2125. /// 获取团组销售报价号
  2126. /// 团组添加时 使用
  2127. /// </summary>
  2128. /// <returns></returns>
  2129. [HttpPost]
  2130. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2131. public async Task<IActionResult> GetGroupSalesQuoteNo()
  2132. {
  2133. var groupData = await _groupRepository.GetGroupSalesQuoteNo();
  2134. if (groupData.Code != 0)
  2135. {
  2136. return Ok(JsonView(false, groupData.Msg));
  2137. }
  2138. object salesQuoteNo = new
  2139. {
  2140. SalesQuoteNo = groupData.Data
  2141. };
  2142. return Ok(JsonView(salesQuoteNo));
  2143. }
  2144. /// <summary>
  2145. /// 设置确认出团
  2146. /// </summary>
  2147. /// <param name="dto"></param>
  2148. /// <returns></returns>
  2149. [HttpPost]
  2150. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2151. public async Task<IActionResult> SetConfirmationGroup(ConfirmationGroupDto dto)
  2152. {
  2153. var groupData = await _groupRepository.ConfirmationGroup(dto);
  2154. if (groupData.Code != 0)
  2155. {
  2156. return Ok(JsonView(false, groupData.Msg));
  2157. }
  2158. var groupInfo = _groupRepository.Query(s => s.Id == dto.GroupId).First();
  2159. #region OA消息推送
  2160. try
  2161. {
  2162. string groupName = groupInfo.TeamName;
  2163. var userIds = _airTicketResRep.Query<Sys_Users>(s => s.DepId == 7 && s.IsDel == 0).Select(x => x.Id).ToList();
  2164. string title = $"系统通知";
  2165. string content = $"团组[{groupName}]已确认出团!";
  2166. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, dto.GroupId);
  2167. }
  2168. catch (Exception ex)
  2169. {
  2170. }
  2171. #endregion
  2172. #region 应用推送
  2173. try
  2174. {
  2175. await AppNoticeLibrary.SendChatMsg_GroupStatus_Create(dto.GroupId, QiyeWeChatEnum.CompanyCRMChat);
  2176. Sys_Users users = _airTicketResRep.Query<Sys_Users>(s => s.Id == groupInfo.JietuanOperator).First();
  2177. Sys_Department department = _airTicketResRep.Query<Sys_Department>(s => s.Id == users.DepId).First();
  2178. if (department.Id == 6 && !string.IsNullOrEmpty(users.QiyeChatUserId))
  2179. {
  2180. var userList = new List<string>() { users.QiyeChatUserId };
  2181. await AppNoticeLibrary.SendUserMsg_GroupStatus_Create(dto.GroupId, userList);
  2182. }
  2183. }
  2184. catch (Exception ex)
  2185. {
  2186. }
  2187. #endregion
  2188. GroupStepForDelegation.CreateWorkStep(dto.GroupId); //创建管控流程
  2189. return Ok(JsonView(true, "操作成功!", groupData.Data));
  2190. }
  2191. /// <summary>
  2192. /// 获取团组名称data And 签证国别Data
  2193. /// </summary>
  2194. /// <param name="dto"></param>
  2195. /// <returns></returns>
  2196. [HttpPost]
  2197. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2198. public async Task<IActionResult> GetGroupNameAndVisaNationality(GroupNameDto dto)
  2199. {
  2200. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  2201. Where TeamName != '' And IsDel = 0
  2202. Order By VisitDate Desc");
  2203. var groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  2204. var data = new
  2205. {
  2206. groupNameData = groupNameList,
  2207. visaNationalityData = _visaTypeInit.ToList()
  2208. };
  2209. return Ok(JsonView(data));
  2210. }
  2211. /// <summary>
  2212. /// 根据CTable类型返回对应的团组名称及简单数据(APP端)
  2213. /// </summary>
  2214. /// <returns></returns>
  2215. [HttpPost]
  2216. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2217. public async Task<IActionResult> PostGroupNameAndEasy(DecreasePaymentsDto dto)
  2218. {
  2219. try
  2220. {
  2221. Result groupData = await _decreasePaymentsRep.PostGroupNameAndEasy(dto);
  2222. if (groupData.Code != 0)
  2223. {
  2224. return Ok(JsonView(false, groupData.Msg));
  2225. }
  2226. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  2227. }
  2228. catch (Exception ex)
  2229. {
  2230. return Ok(JsonView(false, ex.Message));
  2231. throw;
  2232. }
  2233. }
  2234. /// <summary>
  2235. /// 团组清单 Excel
  2236. /// </summary>
  2237. /// <param name="beginDt">开始时间 EG:“2024-01-01”</param>
  2238. /// <param name="endDt">结束时间 EG;“2024-12-31”</param>
  2239. /// <returns></returns>
  2240. [HttpGet]
  2241. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2242. public async Task<IActionResult> GroupListFile([FromQuery] string beginDt, [FromQuery] string endDt)
  2243. {
  2244. bool beginBool = DateTime.TryParse($"{beginDt} 00:00:00", out DateTime _beginDt),
  2245. endBool = DateTime.TryParse($"{endDt} 23:59:59", out DateTime _endDt);
  2246. if (!beginBool && !endBool)
  2247. {
  2248. return Ok(JsonView(false, "开始或结束时间不正确!"));
  2249. }
  2250. string sql = string.Format(@"
  2251. SELECT
  2252. ROW_NUMBER,
  2253. Id,
  2254. SalesQuoteNo,
  2255. TourCode,
  2256. TeamTypeId,
  2257. TeamType,
  2258. TeamLevId,
  2259. TeamLev,
  2260. TeamName,
  2261. ClientName,
  2262. ClientUnit,
  2263. VisitDate,
  2264. VisitDays,
  2265. VisitPNumber,
  2266. JietuanOperatorId,
  2267. JietuanOperator,
  2268. IsSure,
  2269. CreateUserName,
  2270. IsBid
  2271. FROM
  2272. (
  2273. SELECT
  2274. ROW_NUMBER() OVER(
  2275. ORDER BY
  2276. gdi.VisitDate Desc
  2277. ) AS ROW_NUMBER,
  2278. gdi.Id,
  2279. SalesQuoteNo,
  2280. TourCode,
  2281. ssd.Id TeamTypeId,
  2282. ssd.Name TeamType,
  2283. ssd1.Id TeamLevId,
  2284. ssd1.Name TeamLev,
  2285. TeamName,
  2286. ClientName,
  2287. ClientUnit,
  2288. VisitDate,
  2289. VisitDays,
  2290. VisitPNumber,
  2291. JietuanOperator JietuanOperatorId,
  2292. su.CnName JietuanOperator,
  2293. IsSure,
  2294. gdi.CreateTime,
  2295. su1.CnName As CreateUserName,
  2296. gdi.IsBid
  2297. FROM
  2298. Grp_DelegationInfo gdi
  2299. LEFT JOIN Sys_SetData ssd ON gdi.TeamDid = ssd.Id
  2300. LEFT JOIN Sys_SetData ssd1 ON gdi.TeamLevSId = ssd1.Id
  2301. LEFT JOIN Sys_Users su ON gdi.JietuanOperator = su.Id
  2302. LEFT JOIN Sys_Users su1 ON gdi.CreateUserId = su1.Id
  2303. WHERE
  2304. gdi.IsDel = 0
  2305. AND gdi.IsBid = 0
  2306. AND gdi.VisitDate BETWEEN '{0}' AND '{1}'
  2307. ) temp", _beginDt.ToString("yyyy-MM-dd HH:mm:ss"), _endDt.ToString("yyyy-MM-dd HH:mm:ss"));
  2308. var groupList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
  2309. #region 处理所属部门
  2310. /*
  2311. * 1.sq 和 gyy 等显示 市场部
  2312. * 2.王鸽和主管及张总还有管理员号统一国交部
  2313. * 2-1. 4 管理员 ,21 张海麟
  2314. */
  2315. var userIds = groupList.Select(it => it.JietuanOperatorId).ToList();
  2316. var userIds1 = new List<int>() { 4, 21 };
  2317. var userDepDatas = await _sqlSugar.Queryable<Sys_Users>()
  2318. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  2319. .Where(u => u.IsDel == 0 && userIds.Contains(u.Id))
  2320. .Select((u, d) => new { UserId = u.Id, DepName = userIds1.Contains(u.Id) ? "国交部" : d.DepName })
  2321. .ToListAsync();
  2322. var droupIds = groupList.Select(it => it.Id).ToList();
  2323. var deleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  2324. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  2325. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  2326. .Where((tcl, dc, cc) => tcl.IsDel == 0 && droupIds.Contains(tcl.DiId))
  2327. .Select((tcl, dc, cc) => new ClientInfoInfo_Group
  2328. {
  2329. DiId = tcl.DiId,
  2330. LastName = dc.LastName,
  2331. FirstName = dc.FirstName,
  2332. Sex = dc.Sex,
  2333. Birthday = dc.BirthDay,
  2334. Company = cc.CompanyFullName,
  2335. Job = dc.Job,
  2336. CreateTime = tcl.CreateTime,
  2337. })
  2338. .ToList();
  2339. foreach (var item in groupList)
  2340. {
  2341. item.Department = userDepDatas.Find(it => item.JietuanOperatorId == it.UserId)?.DepName ?? "Unknown";
  2342. string groupFirstName = "";
  2343. var currDatas = deleClientList.Where(x => x.DiId == item.Id).ToList();
  2344. if (currDatas.Any())
  2345. {
  2346. groupFirstName = AesEncryptionHelper.Decrypt(currDatas[0].LastName) + AesEncryptionHelper.Decrypt(currDatas[0].FirstName);
  2347. }
  2348. item.GroupFirst = groupFirstName;
  2349. }
  2350. #endregion
  2351. #region Excel
  2352. var tempPath = AppSettingsHelper.Get("ExcelTempPath");
  2353. var servicePath = AppSettingsHelper.Get("GrpFileBaseUrl");
  2354. var savePath = AppSettingsHelper.Get("GrpListFileBasePath");
  2355. var ftpPath = AppSettingsHelper.Get("GrpListFileFtpPath");
  2356. var fileName = $"团组清单({beginDt}~{endDt}){DateTime.Now:yyyyMMddHHmmss}.xlsx";
  2357. //载入模板
  2358. var designer = new WorkbookDesigner
  2359. {
  2360. Workbook = new Workbook($"{tempPath}团组清单模板.xlsx")
  2361. };
  2362. designer.SetDataSource("Titel", $"团组清单({beginDt}~{endDt})");
  2363. DataTable dt = CommonFun.GetDataTableFromIList<DelegationListView>(groupList); ;
  2364. dt.TableName = "GroupList";
  2365. designer.SetDataSource(dt);
  2366. designer.Process();
  2367. if (!Directory.Exists(savePath))
  2368. {
  2369. Directory.CreateDirectory(savePath);
  2370. }
  2371. string serverPath = $"{savePath}{fileName}";
  2372. designer.Workbook.Save(serverPath);
  2373. string rst = $"{servicePath}{ftpPath}{fileName}";
  2374. #endregion
  2375. return Ok(JsonView(true, "操作成功!", rst));
  2376. }
  2377. /// <summary>
  2378. /// 团组合同下载(1.付款80% 2.付全款 政府团 ---- 3.企业团-出访前结算合同 4.政府团-预付款及尾款结算 5.政府团-归国后结算 6.政府团-出访前结算)
  2379. /// </summary>
  2380. /// <param name="dto"></param>
  2381. /// <returns></returns>
  2382. /// <exception cref="Exception"></exception>
  2383. [HttpPost]
  2384. public async Task<IActionResult> DownGroupContractFile(DownGroupContractFileDto dto)
  2385. {
  2386. var jw = JsonView(false);
  2387. var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  2388. .FirstAsync(x => x.Id == dto.GroupId && x.IsDel == 0);
  2389. if (di == null)
  2390. {
  2391. jw.Msg = "团组Id有误!";
  2392. return Ok(jw);
  2393. }
  2394. #region 权限校验
  2395. var allDownFile = new List<int>() { 21 };
  2396. try
  2397. {
  2398. var setting = _sqlSugar.Queryable<Sys_SetData>()
  2399. .First(x => x.Id == 1418 && x.IsDel == 0);
  2400. allDownFile.AddRange(JsonConvert.DeserializeObject<List<int>>(setting.Remark));
  2401. }
  2402. catch (Exception)
  2403. { }
  2404. var guojiaoDownFile = new List<int>() { 330, 383 };
  2405. var shichangDownFile = new List<int>() { 95 };
  2406. if (allDownFile.Contains(dto.UserId))
  2407. {
  2408. }
  2409. else if (guojiaoDownFile.Contains(dto.UserId))
  2410. {
  2411. var guojiaobuDi = new List<int>() { 4, 21 };
  2412. var departmentStr = _sqlSugar.Queryable<Sys_Department>()
  2413. .LeftJoin<Sys_Users>((d, u) => d.Id == u.DepId && u.IsDel == 0)
  2414. .Where((d, u) => u.Id == di.JietuanOperator)
  2415. .Select((d, u) => d.DepName)
  2416. .First();
  2417. if (!guojiaobuDi.Contains(di.JietuanOperator) && departmentStr != "策划部" && departmentStr != "国交部")
  2418. {
  2419. jw.Msg = "暂无下载权限!";
  2420. return Ok(jw);
  2421. }
  2422. }
  2423. else if (shichangDownFile.Contains(dto.UserId))
  2424. {
  2425. var dic = new Dictionary<int, int[]>()
  2426. {
  2427. { 95, new int []{ 95 , 337 , 302, 350, 355, 357, 353 , 359 , 361, 368, 364, 366, 369} }
  2428. };
  2429. try
  2430. {
  2431. var sqSetting = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == 1417);
  2432. if (sqSetting != null)
  2433. {
  2434. Dictionary<int, int[]> result = JsonConvert.DeserializeObject<Dictionary<int, int[]>>(sqSetting.Remark);
  2435. foreach (var item in result.Keys)
  2436. {
  2437. if (dic.ContainsKey(item))
  2438. {
  2439. int[] dilatation = new int[dic[item].Length + result[item].Length];
  2440. Array.Copy(dic[item], dilatation, dic[item].Length);
  2441. Array.Copy(result[item], 0, dilatation, dic[item].Length, result[item].Length);
  2442. dic[item] = dilatation;
  2443. }
  2444. else
  2445. {
  2446. dic.Add(item, result[item]);
  2447. }
  2448. }
  2449. }
  2450. if (!dic[95].Contains(di.CreateUserId))
  2451. {
  2452. jw.Msg = "暂无下载权限!";
  2453. return Ok(jw);
  2454. }
  2455. }
  2456. catch (Exception)
  2457. { }
  2458. }
  2459. else if (dto.UserId == di.CreateUserId)
  2460. {
  2461. }
  2462. else
  2463. {
  2464. jw.Msg = "暂无下载权限!";
  2465. return Ok(jw);
  2466. }
  2467. #endregion
  2468. var blackCodeList = await _sqlSugar.Queryable<Air_TicketBlackCode>()
  2469. .Where(x => x.DiId == dto.GroupId && x.IsDel == 0)
  2470. .ToListAsync();
  2471. var blackType = new List<int>() { 1, 2 };
  2472. if (!blackCodeList.Any() && blackType.Contains(dto.FileType))
  2473. {
  2474. jw.Msg = "该团无机票行程代码!";
  2475. return Ok(jw);
  2476. }
  2477. var groupEnterExitCost = await _sqlSugar.Queryable<Grp_EnterExitCost>()
  2478. .FirstAsync(x => x.DiId == dto.GroupId && x.IsDel == 0);
  2479. if (groupEnterExitCost == null)
  2480. {
  2481. jw.Msg = "暂无三公费用信息!";
  2482. return Ok(jw);
  2483. }
  2484. var rateList = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(groupEnterExitCost.CurrencyRemark);
  2485. rateList ??= new List<CurrencyInfo>();
  2486. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == di.Id).ToList();
  2487. var dac5 = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  2488. .LeftJoin<Sys_SetData>((x, a) => a.IsDel == 0 && a.Id == x.SetDataId)
  2489. .LeftJoin<Sys_SetData>((x, a, b) => b.IsDel == 0 && b.Id == x.Currency)
  2490. .Where((x, a, b) => x.IsDel == 0 && x.Diid == di.Id)
  2491. .Select((x, a, b) => new
  2492. {
  2493. x.Index,
  2494. itemName = a.Name,
  2495. CurrencyStr = b.Name,
  2496. x.Cost,
  2497. x.SubTotal,
  2498. x.Remark
  2499. })
  2500. .OrderBy((x) => x.Index)
  2501. .ToList();
  2502. decimal stayFeeTotal = groupEnterExitCost.ChoiceThree == 1 ? _DayAndCosts.Where(it => it.Type == 1).Sum(it => it.SubTotal) : 0.00M; // 住宿费
  2503. decimal mealsFeeTotal = groupEnterExitCost.ChoiceFour == 1 ? _DayAndCosts.Where(it => it.Type == 2).Sum(it => it.SubTotal) : 0.00M; // 伙食费费
  2504. decimal miscellaneousFeeTotal = groupEnterExitCost.ChoiceFive == 1 ? _DayAndCosts.Where(it => it.Type == 3).Sum(it => it.SubTotal) : 0.00M; // 公杂费
  2505. decimal tainFeeTotal = groupEnterExitCost.ChoiceSix == 1 ? _DayAndCosts.Where(it => it.Type == 4).Sum(it => it.SubTotal) : 0.00M; // 培训费
  2506. decimal otherPriceTotal = groupEnterExitCost.OtherExpenses_Checked == 1 ? dac5.Sum(x => x.SubTotal) : 0.00M; //其他费用
  2507. decimal insidePayTotal = groupEnterExitCost.ChoiceOne == 1 ? groupEnterExitCost.InsidePay : 0.00M;
  2508. decimal otherFeeTotal = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + otherPriceTotal;
  2509. decimal subJJC = 0.00M,
  2510. subGWC = 0.00M,
  2511. subTDC = 0.00M;
  2512. //经济舱
  2513. if (groupEnterExitCost.SumJJC == 1)
  2514. {
  2515. subJJC = otherFeeTotal + groupEnterExitCost.OutsideJJPay;
  2516. }
  2517. //公务舱
  2518. if (groupEnterExitCost.SumGWC == 1)
  2519. {
  2520. subGWC = otherFeeTotal + groupEnterExitCost.OutsideGWPay;
  2521. }
  2522. //头等舱
  2523. if (groupEnterExitCost.SumTDC == 1)
  2524. {
  2525. subTDC = otherFeeTotal + groupEnterExitCost.OutsideTDPay;
  2526. }
  2527. var groupClints = await _sqlSugar.Queryable<Grp_TourClientList>()
  2528. .LeftJoin<Sys_SetData>((x, s) => s.Id == x.ShippingSpaceTypeId && s.IsDel == 0)
  2529. .LeftJoin<Crm_DeleClient>((x, s, dc) => x.ClientId == dc.Id && dc.IsDel == 0)
  2530. .LeftJoin<Crm_CustomerCompany>((x, s, dc, cc) => dc.CrmCompanyId == cc.Id && cc.IsDel == 0)
  2531. .Where((x, s, dc, cc) => x.DiId == dto.GroupId && x.IsDel == 0)
  2532. .Select((x, s, dc, cc) => new GroupClints
  2533. {
  2534. Id = x.Id,
  2535. Name = s.Name,
  2536. IsAccompany = x.IsAccompany,
  2537. CompanyFullName = cc.CompanyFullName
  2538. })
  2539. .ToListAsync();
  2540. groupClints.ForEach(x => x.CompanyFullName = AesEncryptionHelper.Decrypt(x.CompanyFullName));
  2541. //获取舱位人数
  2542. var cabinCount = groupClints.Where(x => x.IsAccompany != 2 && !x.CompanyFullName.Contains("泛美国际"))
  2543. .GroupBy(x => x.Name)
  2544. .Select(x => new { Cabin = x.Key, Count = x.Count() })
  2545. .ToList();
  2546. string cityPath = string.Empty;
  2547. string startCity = string.Empty;
  2548. string endCity = string.Empty;
  2549. foreach (var item in blackCodeList)
  2550. {
  2551. string city = GeneralMethod.GetGroupCityLine(item, "-");
  2552. cityPath += city + "\r\n";
  2553. if (item.Equals(blackCodeList.First()))
  2554. {
  2555. var sp = city.Split('-');
  2556. startCity = sp[0];
  2557. endCity = sp[^1];
  2558. }
  2559. }
  2560. di.VisitCountry = Regex.Replace(di.VisitCountry, @"[|-]", "、");
  2561. var bookMarkDic = new Dictionary<string, string>
  2562. {
  2563. { "ClientUnit", di.ClientUnit },
  2564. { "VisitCountry", di.VisitCountry },
  2565. { "VisitDate", di.VisitDate.ToString("yyyy年MM月dd日") },
  2566. { "VisitPNumber", di.VisitPNumber.ToString() },
  2567. { "CityPath", cityPath },
  2568. { "StartCity", startCity },
  2569. { "EndCity", endCity },
  2570. { "StayDays", $"{di.VisitDays}天{di.VisitDays - 1}晚" }
  2571. };
  2572. Document doc = null;
  2573. var percentage = 0.8M;
  2574. var fileNameadd = "预付版本合同文件";
  2575. if (dto.FileType == 1)
  2576. {
  2577. doc = new Document($"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Template/团组合同bookmarkFormat.doc");
  2578. }
  2579. else if (dto.FileType == 2)
  2580. {
  2581. doc = new Document($"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Template/团组合同全款无表格.doc");
  2582. percentage = 1;
  2583. fileNameadd = "全款版本合同文件";
  2584. }
  2585. else if (dto.FileType == 3)
  2586. {
  2587. doc = new Document($"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Template/企业合同模板.doc");
  2588. percentage = 1;
  2589. fileNameadd = "企业团-出访前结算合同";
  2590. }
  2591. else if (dto.FileType == 4)
  2592. {
  2593. doc = new Document($"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Template/出访考察协议模版-预付款及尾款结算.doc");
  2594. percentage = 0.85M;
  2595. fileNameadd = "政府团-预付款及尾款结算合同";
  2596. }
  2597. else if (dto.FileType == 5)
  2598. {
  2599. doc = new Document($"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Template/出访考察协议模版-归国后结算.doc");
  2600. percentage = 1M;
  2601. fileNameadd = "政府团-归国后结算合同";
  2602. }
  2603. else if (dto.FileType == 6)
  2604. {
  2605. doc = new Document($"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Template/出访考察协议模板(出访前结算).doc");
  2606. percentage = 1M;
  2607. fileNameadd = "政府团-出访前结算合同";
  2608. }
  2609. else
  2610. {
  2611. throw new Exception("FileType有误!");
  2612. }
  2613. var builder = new DocumentBuilder(doc);
  2614. decimal totalPrice = 0.00M;
  2615. Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true);
  2616. if (firstTable != null)
  2617. {
  2618. // 遍历表格的行和单元格
  2619. foreach (Aspose.Words.Tables.Row row in firstTable.Rows)
  2620. {
  2621. for (int i = 0; i < row.Cells.Count; i++)
  2622. {
  2623. var cell = row.Cells[i];
  2624. // 读取单元格内容
  2625. string cellTextFirst = row.Cells[0].FirstParagraph.ToString(Aspose.Words.SaveFormat.Text).Trim();
  2626. if (cellTextFirst.Contains("舱位"))
  2627. {
  2628. break;
  2629. }
  2630. if (cellTextFirst == "经济舱" || cellTextFirst == "公务舱")
  2631. {
  2632. if (i == 2)
  2633. {
  2634. if (cellTextFirst == "经济舱")
  2635. {
  2636. // 设置单元格内容
  2637. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2638. cell.FirstParagraph.AppendChild(new Run(doc, subJJC.ToString())); // 添加
  2639. }
  2640. else
  2641. {
  2642. // 设置单元格内容
  2643. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2644. cell.FirstParagraph.AppendChild(new Run(doc, subGWC.ToString())); // 添加
  2645. }
  2646. }
  2647. if (i == 3)
  2648. {
  2649. var count = cabinCount.Find(x => x.Cabin == cellTextFirst)?.Count;
  2650. if (count != null)
  2651. {
  2652. // 设置单元格内容
  2653. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2654. cell.FirstParagraph.AppendChild(new Run(doc, count.ToString())); // 添加
  2655. }
  2656. }
  2657. if (i == 4)
  2658. {
  2659. var rowPrice = 0.00M;
  2660. var count = cabinCount.Find(x => x.Cabin == cellTextFirst)?.Count;
  2661. count ??= 0;
  2662. if (cellTextFirst == "经济舱")
  2663. {
  2664. rowPrice = subJJC * (int)count;
  2665. }
  2666. else
  2667. {
  2668. rowPrice = subGWC * (int)count;
  2669. }
  2670. totalPrice += rowPrice;
  2671. // 设置单元格内容
  2672. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2673. cell.FirstParagraph.AppendChild(new Run(doc, rowPrice.ToString())); // 添加
  2674. }
  2675. }
  2676. }
  2677. }
  2678. }
  2679. bookMarkDic.Add("TotalPrice", (totalPrice).ToString("#0.00"));
  2680. bookMarkDic.Add("TotalPrice1", (totalPrice * percentage).ToString("#0.00"));
  2681. bookMarkDic.Add("TotalPriceChinese", decimal.Parse((totalPrice * percentage).ToString("#0.00")).ConvertCNYUpper());
  2682. bookMarkDic.Add("TotalPriceUp", decimal.Parse((totalPrice * percentage).ToString("#0.00")).ConvertCNYUpper());
  2683. //--合同表格部分
  2684. bookMarkDic.Add("TimeNowDate", DateTime.Now.ToString("yyyy年MM月dd日"));
  2685. bookMarkDic.Add("ClientUnit1", di.ClientUnit);
  2686. bookMarkDic.Add("VisitCountry1", di.VisitCountry);
  2687. bookMarkDic.Add("DayCount", di.VisitDays.ToString());
  2688. bookMarkDic.Add("VisitingArea", di.VisitDate.ToString("yyyy年MM月dd日") + "-" + di.VisitEndDate.ToString("yyyy年MM月dd日"));
  2689. bookMarkDic.Add("CityPath1", cityPath);
  2690. bookMarkDic.Add("CityPath2", cityPath);
  2691. Table contractTable = (Table)doc.GetChild(NodeType.Table, 1, true);
  2692. if (contractTable != null)
  2693. {
  2694. //数据源
  2695. var _DayAndCostsAndCity = _sqlSugar.Queryable<Grp_DayAndCost>()
  2696. .LeftJoin<Grp_NationalTravelFee>((it, y) => it.NationalTravelFeeId == y.Id && y.IsDel == 0)
  2697. .LeftJoin<Sys_SetData>((it, y, s) => s.IsDel == 0 && s.Id == it.Currency)
  2698. .Where((it, y, s) => it.IsDel == 0 && it.DiId == di.Id)
  2699. .Select((it, y, s) => new
  2700. {
  2701. it.Cost,
  2702. it.SubTotal,
  2703. it.Type,
  2704. y.Id,
  2705. y.City,
  2706. s.Name,
  2707. CurrencyCodeCn = s.Remark
  2708. })
  2709. .ToList()
  2710. .Select(x => new
  2711. {
  2712. CurrencyCode = x.Name,
  2713. CityId = x.Id,
  2714. x.City,
  2715. di.VisitPNumber,
  2716. x.Type,
  2717. x.Cost,
  2718. x.SubTotal,
  2719. rateList.Find(y => y.CurrencyCode == x.Name)?.Rate,
  2720. x.CurrencyCodeCn,
  2721. });
  2722. var dac1 = _DayAndCostsAndCity.Where(it => it.Type == 1).GroupBy(x => x.CityId).ToList(); //住宿费
  2723. var dac2 = _DayAndCostsAndCity.Where(it => it.Type == 2).GroupBy(x => x.CityId).ToList(); //伙食费
  2724. var dac3 = _DayAndCostsAndCity.Where(it => it.Type == 3).GroupBy(x => x.CityId).ToList(); //公杂费
  2725. var dac4 = _DayAndCostsAndCity.Where(it => it.Type == 4).GroupBy(x => x.CityId).ToList(); //培训费
  2726. var tableSettings = new List<tableSetting>()
  2727. {
  2728. new(){ Index = 1 , Property = "City"},
  2729. new(){ Index = 2 , Property = "CurrencyCodeCn"},
  2730. new(){ Index = 3 , Property = "Cost"},
  2731. new(){ Index = 4 , Property = "VisitPNumber"},
  2732. //new tableSetting{ Index = 5 , Property = ""},
  2733. //new tableSetting{ Index = 6 , Property = ""},
  2734. new(){ Index = 7 , Property = "Rate"},
  2735. //new tableSetting{ Index = 8 , Property = ""},
  2736. };
  2737. //1.住宿费
  2738. int cloneRow = 8;
  2739. int startDayPrice = 8; //写入index
  2740. decimal ZSPriceSum = 0.00M, HSPriceSum = 0.00M, GZPriceSum = 0.00M;
  2741. foreach (var dac in dac1)
  2742. {
  2743. var first = dac.First();
  2744. var dayCount = dac.Count();
  2745. Aspose.Words.Tables.Row row = contractTable.Rows[startDayPrice];
  2746. for (int i = 1; i < row.Cells.Count; i++)
  2747. {
  2748. var cell = row.Cells[i];
  2749. var findProperty = tableSettings.Find(x => x.Index == i);
  2750. if (findProperty != null)
  2751. {
  2752. string value = first.GetType().GetProperty(findProperty.Property).GetValue(first).ToString();
  2753. // 设置单元格内容
  2754. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2755. cell.FirstParagraph.AppendChild(new Run(doc, value)); // 添加
  2756. }
  2757. else
  2758. {
  2759. switch (i)
  2760. {
  2761. case 5:
  2762. cell.FirstParagraph.Runs.Clear();
  2763. cell.FirstParagraph.AppendChild(new Run(doc, dayCount.ToString()));
  2764. break;
  2765. case 6:
  2766. var xiaoji = dayCount * first.VisitPNumber * first.Cost;
  2767. cell.FirstParagraph.Runs.Clear();
  2768. cell.FirstParagraph.AppendChild(new Run(doc, xiaoji.ToString("F2")));
  2769. break;
  2770. case 8:
  2771. var xiaojiRMB = dayCount * first.VisitPNumber * first.SubTotal;
  2772. cell.FirstParagraph.Runs.Clear();
  2773. cell.FirstParagraph.AppendChild(new Run(doc, xiaojiRMB.ToString("F2")));
  2774. ZSPriceSum += xiaojiRMB;
  2775. break;
  2776. default:
  2777. break;
  2778. }
  2779. }
  2780. }
  2781. startDayPrice++;
  2782. if (!dac1.Last().Equals(dac))
  2783. {
  2784. Aspose.Words.Tables.Row newRow = (Aspose.Words.Tables.Row)contractTable.Rows[cloneRow].Clone(true);
  2785. // 将克隆的行追加到原行后面
  2786. contractTable.Rows.Insert(startDayPrice, newRow);
  2787. }
  2788. else
  2789. {
  2790. cloneRow += dac1.Count + 1;
  2791. startDayPrice = cloneRow;
  2792. }
  2793. }
  2794. //2.伙食费
  2795. foreach (var dac in dac2)
  2796. {
  2797. var first = dac.First();
  2798. var dayCount = dac.Count();
  2799. Aspose.Words.Tables.Row row = contractTable.Rows[startDayPrice];
  2800. for (int i = 1; i < row.Cells.Count; i++)
  2801. {
  2802. var cell = row.Cells[i];
  2803. var findProperty = tableSettings.Find(x => x.Index == i);
  2804. if (findProperty != null)
  2805. {
  2806. string value = first.GetType().GetProperty(findProperty.Property).GetValue(first).ToString();
  2807. // 设置单元格内容
  2808. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2809. cell.FirstParagraph.AppendChild(new Run(doc, value)); // 添加
  2810. }
  2811. else
  2812. {
  2813. switch (i)
  2814. {
  2815. case 5:
  2816. cell.FirstParagraph.Runs.Clear();
  2817. cell.FirstParagraph.AppendChild(new Run(doc, dayCount.ToString()));
  2818. break;
  2819. case 6:
  2820. var xiaoji = dayCount * first.VisitPNumber * first.Cost;
  2821. cell.FirstParagraph.Runs.Clear();
  2822. cell.FirstParagraph.AppendChild(new Run(doc, xiaoji.ToString("F2")));
  2823. break;
  2824. case 8:
  2825. var xiaojiRMB = dayCount * first.VisitPNumber * first.SubTotal;
  2826. cell.FirstParagraph.Runs.Clear();
  2827. cell.FirstParagraph.AppendChild(new Run(doc, xiaojiRMB.ToString("F2")));
  2828. HSPriceSum += xiaojiRMB;
  2829. break;
  2830. default:
  2831. break;
  2832. }
  2833. }
  2834. }
  2835. startDayPrice++;
  2836. if (!dac2.Last().Equals(dac))
  2837. {
  2838. Aspose.Words.Tables.Row newRow = (Aspose.Words.Tables.Row)contractTable.Rows[cloneRow].Clone(true);
  2839. // 将克隆的行追加到原行后面
  2840. contractTable.Rows.Insert(startDayPrice, newRow);
  2841. }
  2842. else
  2843. {
  2844. cloneRow += dac2.Count + 1;
  2845. startDayPrice = cloneRow;
  2846. }
  2847. }
  2848. //3.公杂费
  2849. foreach (var dac in dac3)
  2850. {
  2851. var first = dac.First();
  2852. var dayCount = dac.Count();
  2853. Aspose.Words.Tables.Row row = contractTable.Rows[startDayPrice];
  2854. for (int i = 1; i < row.Cells.Count; i++)
  2855. {
  2856. var cell = row.Cells[i];
  2857. var findProperty = tableSettings.Find(x => x.Index == i);
  2858. if (findProperty != null)
  2859. {
  2860. string value = first.GetType().GetProperty(findProperty.Property).GetValue(first).ToString();
  2861. // 设置单元格内容
  2862. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2863. cell.FirstParagraph.AppendChild(new Run(doc, value)); // 添加
  2864. }
  2865. else
  2866. {
  2867. switch (i)
  2868. {
  2869. case 5:
  2870. cell.FirstParagraph.Runs.Clear();
  2871. cell.FirstParagraph.AppendChild(new Run(doc, dayCount.ToString()));
  2872. break;
  2873. case 6:
  2874. var xiaoji = dayCount * first.VisitPNumber * first.Cost;
  2875. cell.FirstParagraph.Runs.Clear();
  2876. cell.FirstParagraph.AppendChild(new Run(doc, xiaoji.ToString("F2")));
  2877. break;
  2878. case 8:
  2879. var xiaojiRMB = dayCount * first.VisitPNumber * first.SubTotal;
  2880. cell.FirstParagraph.Runs.Clear();
  2881. cell.FirstParagraph.AppendChild(new Run(doc, xiaojiRMB.ToString("F2")));
  2882. GZPriceSum += xiaojiRMB;
  2883. break;
  2884. default:
  2885. break;
  2886. }
  2887. }
  2888. }
  2889. startDayPrice++;
  2890. if (!dac3.Last().Equals(dac))
  2891. {
  2892. Aspose.Words.Tables.Row newRow = (Aspose.Words.Tables.Row)contractTable.Rows[cloneRow].Clone(true);
  2893. // 将克隆的行追加到原行后面
  2894. contractTable.Rows.Insert(startDayPrice, newRow);
  2895. }
  2896. else
  2897. {
  2898. cloneRow += dac3.Count + 1;
  2899. startDayPrice = cloneRow;
  2900. }
  2901. }
  2902. //合并单元格
  2903. for (int i = 8; i < contractTable.Rows.Count - 1; i++)
  2904. {
  2905. var currentRow = contractTable.Rows[i];
  2906. var nextRow = contractTable.Rows[i + 1];
  2907. // 获取当前行和下一行的第一个单元格
  2908. Cell currentCell = currentRow.Cells[0];
  2909. Cell nextCell = nextRow.Cells[0];
  2910. // 检查单元格内容是否一致(去除尾部的换行符)
  2911. string currentText = currentCell.GetText().Trim();
  2912. string nextText = nextCell.GetText().Trim();
  2913. if (currentText == nextText)
  2914. {
  2915. // 如果当前单元格已经被合并,找到合并的起始单元格
  2916. if (currentCell.CellFormat.VerticalMerge == CellMerge.Previous)
  2917. {
  2918. // 找到合并的起始单元格
  2919. int mergeStartIndex = FindMergeStartRowIndex(contractTable, i);
  2920. // 将下一行的单元格设置为合并的后续单元格
  2921. nextCell.CellFormat.VerticalMerge = CellMerge.Previous;
  2922. }
  2923. else
  2924. {
  2925. // 如果当前单元格是合并的起始单元格
  2926. currentCell.CellFormat.VerticalMerge = CellMerge.First;
  2927. // 将下一行的单元格设置为合并的后续单元格
  2928. nextCell.CellFormat.VerticalMerge = CellMerge.Previous;
  2929. }
  2930. }
  2931. else
  2932. {
  2933. // 如果内容不一致,重置当前单元格的合并属性
  2934. if (currentCell.CellFormat.VerticalMerge == CellMerge.Previous)
  2935. {
  2936. // 如果当前单元格是合并的后续单元格,找到合并的起始单元格并重置
  2937. int mergeStartIndex = FindMergeStartRowIndex(contractTable, i);
  2938. contractTable.Rows[mergeStartIndex].Cells[0].CellFormat.VerticalMerge = CellMerge.First;
  2939. }
  2940. else
  2941. {
  2942. currentCell.CellFormat.VerticalMerge = CellMerge.None;
  2943. }
  2944. }
  2945. }
  2946. bookMarkDic.Add("ZSPriceSum", ZSPriceSum.ToString("F2"));
  2947. bookMarkDic.Add("HSPriceSum", HSPriceSum.ToString("F2"));
  2948. bookMarkDic.Add("GZPriceSum", GZPriceSum.ToString("F2"));
  2949. }
  2950. foreach (var bookmarkName in bookMarkDic.Keys)
  2951. {
  2952. Bookmark bookmark = doc.Range.Bookmarks[bookmarkName];
  2953. if (bookmark != null)
  2954. {
  2955. if (bookmarkName == "ClientUnit")
  2956. {
  2957. // 移动到书签位置
  2958. builder.MoveTo(bookmark.BookmarkStart);
  2959. // 设置字体样式为下划线
  2960. builder.Font.Underline = Aspose.Words.Underline.Single;
  2961. // 插入书签值
  2962. builder.Write(bookMarkDic[bookmarkName]);
  2963. // 清除字体格式,避免影响后续文本
  2964. builder.Font.ClearFormatting();
  2965. }
  2966. else
  2967. {
  2968. builder.MoveToBookmark(bookmarkName);
  2969. builder.Write(bookMarkDic[bookmarkName]);
  2970. }
  2971. }
  2972. }
  2973. string savePaht = $"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Export/{di.TeamName}_{fileNameadd}.doc";
  2974. doc.Save(savePaht);
  2975. jw.Msg = "生成成功!";
  2976. jw.Code = 200;
  2977. jw.Data = new { Url = AppSettingsHelper.Get("WordBaseUrl") + savePaht.Replace(AppSettingsHelper.Get("WordBasePath"), AppSettingsHelper.Get("WordFtpPath")) };
  2978. return Ok(jw);
  2979. }
  2980. /// <summary>
  2981. /// 会务团
  2982. /// </summary>
  2983. /// <param name="dto"></param>
  2984. /// <returns></returns>
  2985. [HttpPost]
  2986. public async Task<IActionResult> DownGroupContractConferenceFile(DownGroupContractFileDto dto)
  2987. {
  2988. var jw = JsonView(false);
  2989. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  2990. .Where(x => x.IsDel == 0 && x.Id == dto.GroupId)
  2991. .FirstAsync();
  2992. if (groupInfo == null)
  2993. {
  2994. jw.Msg = "团组信息不存在!";
  2995. return Ok(jw);
  2996. }
  2997. var GroupPrice = 0.00M;
  2998. string VisitCountry = Regex.Replace(groupInfo.VisitCountry, @"[|-]", "、"); ;
  2999. GroupPrice = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
  3000. .First(x => x.Diid == dto.GroupId && x.IsDel == 0)?.BaoJiaAll ?? 0.00M;
  3001. Dictionary<string, string> bookMarkDic = new Dictionary<string, string>();
  3002. bookMarkDic.Add("UpGroupPrice", GeneralMethod.ConvertCNYUpper(GroupPrice.ToString("F2").ObjToDecimal()));
  3003. bookMarkDic.Add("ClientUnit", groupInfo.ClientUnit);
  3004. bookMarkDic.Add("GroupPrice", GroupPrice.ToString("F2"));
  3005. bookMarkDic.Add("VisitCountry", VisitCountry);
  3006. bookMarkDic.Add("VisitPNumber", groupInfo.VisitPNumber.ToString());
  3007. bookMarkDic.Add("VisitStartDate", groupInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  3008. bookMarkDic.Add("StartYear", groupInfo.VisitStartDate.Year.ToString());
  3009. bookMarkDic.Add("EndYear", groupInfo.VisitEndDate.Year.ToString());
  3010. bookMarkDic.Add("StartMonth", groupInfo.VisitStartDate.Month.ToString());
  3011. bookMarkDic.Add("EndMonth", groupInfo.VisitEndDate.Month.ToString());
  3012. bookMarkDic.Add("StartDay", groupInfo.VisitStartDate.Day.ToString());
  3013. bookMarkDic.Add("EndDay", groupInfo.VisitEndDate.Day.ToString());
  3014. bookMarkDic.Add("GroupPrice1", (GroupPrice * 0.80M).ToString("F2"));
  3015. bookMarkDic.Add("GroupPrice2", (GroupPrice * 0.20M).ToString("F2"));
  3016. bookMarkDic.Add("UpGroupPrice1", GeneralMethod.ConvertCNYUpper((GroupPrice * 0.80M).ToString("F2").ObjToDecimal()));
  3017. bookMarkDic.Add("UpGroupPrice2", GeneralMethod.ConvertCNYUpper((GroupPrice * 0.20M).ToString("F2").ObjToDecimal()));
  3018. var underlineFont = new List<String>{
  3019. "ClientUnit",
  3020. "VisitStartDate"
  3021. };
  3022. var doc = new Document($"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Template/会务合同模板.doc");
  3023. var builder = new DocumentBuilder(doc);
  3024. foreach (var bookmarkName in bookMarkDic.Keys)
  3025. {
  3026. Bookmark bookmark = doc.Range.Bookmarks[bookmarkName];
  3027. if (bookmark == null)
  3028. {
  3029. continue;
  3030. }
  3031. builder.MoveTo(bookmark.BookmarkStart);
  3032. if (underlineFont.Contains(bookmarkName))
  3033. {
  3034. builder.Font.Underline = Aspose.Words.Underline.Single;
  3035. }
  3036. builder.Write(bookMarkDic[bookmarkName]);
  3037. if (underlineFont.Contains(bookmarkName))
  3038. {
  3039. builder.Font.ClearFormatting();
  3040. }
  3041. }
  3042. string savePaht = $"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Export/{groupInfo.TeamName}_会务服务合同.doc";
  3043. doc.Save(savePaht);
  3044. jw.Msg = "生成成功!";
  3045. jw.Code = 200;
  3046. jw.Data = new { Url = AppSettingsHelper.Get("WordBaseUrl") + savePaht.Replace(AppSettingsHelper.Get("WordBasePath"), AppSettingsHelper.Get("WordFtpPath")) };
  3047. return Ok(jw);
  3048. }
  3049. static int FindMergeStartRowIndex(Table table, int rowIndex)
  3050. {
  3051. int index = rowIndex;
  3052. while (index > 0 && table.Rows[index].Cells[0].CellFormat.VerticalMerge == CellMerge.Previous)
  3053. {
  3054. index--;
  3055. }
  3056. return index;
  3057. }
  3058. /// <summary>
  3059. /// 报批完成企微通知
  3060. /// </summary>
  3061. /// <param name="dto"></param>
  3062. /// <returns></returns>
  3063. [HttpPost]
  3064. public async Task<IActionResult> EnterpriseWeChatNotificationAsyncBaoPi(EnterpriseWeChatNotificationAsyncBaoPiDto dto)
  3065. {
  3066. int currUserId = dto.currUserId;
  3067. int diid = dto.diid;
  3068. var jw = JsonView(true);
  3069. var users = new List<string>();
  3070. var ssd = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == 1460);
  3071. //时间格式验证
  3072. if (!DateTime.TryParse(dto.stepOperationTime, out DateTime dt))
  3073. {
  3074. return Ok(JsonView(false, "请传入有效的时间格式!(例如:2026-01-06 15:45:02)"));
  3075. }
  3076. try
  3077. {
  3078. users = JsonConvert.DeserializeObject<List<string>>(ssd.Remark);
  3079. var groupModuleOperators = GeneralMethod.GetGroupModuleOperators(dto.diid);
  3080. //添加分配人员
  3081. // 79 车/导游地接
  3082. // 80 签证
  3083. // 81 邀请/公务活动
  3084. var setdataids = new List<int>() { 79, 81 };
  3085. foreach (var groupModule in groupModuleOperators)
  3086. {
  3087. if (setdataids.Contains(groupModule.CTableId))
  3088. {
  3089. users.AddRange(groupModule.OperationUsers.Select(x => x.UserId.ToString()));
  3090. }
  3091. }
  3092. var res = await AppNoticeLibrary.SendUserMsg_BaoPi_ToUser(users, diid);
  3093. //消息通知成功 更改团组step、记录日志
  3094. if (res)
  3095. {
  3096. var groupStep = 0; //0-新建 1-企微消息通知
  3097. //更改团组step
  3098. var updStatus = await _sqlSugar.Updateable<Grp_DelegationInfo>()
  3099. .SetColumns(x => new Grp_DelegationInfo()
  3100. {
  3101. Step = 2,
  3102. StepOperationTime = dt
  3103. })
  3104. .Where(x => x.Id == diid && x.IsDel == 0)
  3105. .ExecuteCommandAsync();
  3106. if (updStatus > 0) groupStep = 2;
  3107. string groupStepLabel = groupStep switch
  3108. {
  3109. 1 => "新建",
  3110. 2 => "企微消息通知(报批)",
  3111. _ => "未设置"
  3112. };
  3113. //记录日志
  3114. var teamName = _sqlSugar.Queryable<Grp_DelegationInfo>()
  3115. .Where(x => x.Id == diid && x.IsDel == 0)
  3116. .Select(x => x.TeamName)
  3117. .First() ?? "-";
  3118. var operationName = _sqlSugar.Queryable<Sys_Users>()
  3119. .Where(x => x.Id == currUserId && x.IsDel == 0)
  3120. .Select(x => x.CnName)
  3121. .First() ?? "-";
  3122. _groupTextLogger.LogInformation("团组:【{teamName}({groupId})】 操作人:【{operationName}】 操作时间:【{operationTime}】{logContent}", teamName, diid, operationName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), groupStepLabel);
  3123. //设置 签证流程初始值
  3124. await _visaProcessRep.UpdateBatchTop4Step(dto.diid, dto.currUserId);
  3125. }
  3126. }
  3127. catch (Exception ex)
  3128. {
  3129. return Ok(JsonView(false, ex.Message));
  3130. }
  3131. return Ok(jw);
  3132. }
  3133. #endregion
  3134. #region 团组&签证
  3135. #region 团组&签证 New
  3136. /// <summary>
  3137. /// 团组&签证 New
  3138. /// DeepSeek API:测试API连通性
  3139. /// </summary>
  3140. /// <param name="file">请求dto</param>
  3141. /// <returns></returns>
  3142. [HttpPost]
  3143. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3144. public async Task<IActionResult> TestDeepSeekApiConnectivityAsync()
  3145. {
  3146. return Ok(JsonView(await _deepSeekService.TestApiConnectivityAsync()));
  3147. }
  3148. /// <summary>
  3149. /// 团组&签证 New
  3150. /// DeepSeek API:检查可用端点
  3151. /// </summary>
  3152. /// <param name="file">请求dto</param>
  3153. /// <returns></returns>
  3154. [HttpPost]
  3155. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3156. public async Task<IActionResult> DiscoverAvailableEndpointsAsync()
  3157. {
  3158. return Ok(JsonView(await _deepSeekService.DiscoverAvailableEndpointsAsync()));
  3159. }
  3160. /// <summary>
  3161. /// 团组&签证 New
  3162. /// 上传签证文件(客户填写签证文件),新增或更新 签证信息
  3163. /// </summary>
  3164. /// <param name="visaFile">文件</param>
  3165. /// </param>
  3166. /// <returns></returns>
  3167. [HttpPost]
  3168. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3169. public async Task<IActionResult> VisaFileUploadAndUpdate(IFormFile visaFile)
  3170. {
  3171. //文件验证
  3172. if (visaFile.Length < 1) return Ok(JsonView(false, "请选择文件!"));
  3173. //var visaFiles = new VisaUploadFileTypeView();
  3174. //var filetypes = VisaUploadFileTypeView.GetVisaUploadFileTypeViewItemInit();
  3175. //if (!filetypes.Any(x => x.FileId == fileTypeId)) return Ok(JsonView(false, "请选择文件类型!"));
  3176. //服务器存储文件
  3177. var fileServerPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Uploads";
  3178. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(fileServerPath);
  3179. var filePath = Path.Combine(fileServerPath, visaFile.FileName);
  3180. using (var stream = new FileStream(filePath, FileMode.Create))
  3181. {
  3182. await visaFile.CopyToAsync(stream);
  3183. }
  3184. //日志记录-上传文件
  3185. _logger.LogInformation("【签证上传文件操作信息】签证文件存储成功!路径:{fileServerPath} 文件名称:{fileName}", fileServerPath, visaFile.FileName);
  3186. #region kimi API
  3187. //kimi AI 识别文档返回json结果
  3188. var KiMiApi = new KiMiApiClient();
  3189. var files = new List<IFormFile>() { visaFile };
  3190. var seedConter = await KiMiApi.UploadFilesAsync(files);
  3191. if (seedConter.Count == 0) return Ok(JsonView(false, "Kimi AI 文件上传结果为空!"));
  3192. var seedMessage = string.Format(@"你是领事馆电子材料审核员,只关注 Word 里的表格,正文、页眉页脚、水印、批注全部忽略。
  3193. 个人信息:
  3194. - 姓名:请提取文档中的“姓名”。
  3195. - 拼音名:请提取文档中的“拼音名”或“英文名”。
  3196. - 曾用名:请提取文档中的“曾用名”或“别名”,去除“曾用名”“别名”等字段名称字样,仅保留实际姓名内容。
  3197. - 性别:请提取文档中的“性别”。当前信息未提取到且身份证效验通过可提取第17位奇偶性判断性别(奇男偶女)。
  3198. - 出生日期:请提取文档中的“出生日期”。当前信息未提取到且身份证效验通过可提取第7-14位作为出生日期(格式YYYY-MM-DD)。
  3199. - 出生地省:请提取文档中的“出生地省”或“出生地省份”。当前信息未提取到且身份证效验通过可提取第1-2位对应省级行政区划代码用于出生地省回填。
  3200. - 出生地市:请提取文档中的“出生地市”或“出生地城市”。当前信息未提取到且身份证效验通过可提取第3-4位对应地级行政区划代码用于出生地市回填。
  3201. - 国籍:请提取文档中的“国籍”或“现国籍”。当前信息未提取到且身份证效验通过可提取信息回填。
  3202. - 身份证号码:请提取文档中的“身份证号码”。效验规则:身份证号码必须为18位,前17位为数字、第18位为数字或X,且需通过ISO 7064:1983 MOD 11-2校验算法验证;
  3203. - 婚姻状况:请提取文档中的“婚姻状况”。
  3204. - 离婚原因:请提取文档中的“离婚原因”。
  3205. 家庭信息:
  3206. - 家庭成员:请提取文档中所有家庭成员信息,以列表形式返回,每个条目包含以下信息:
  3207. - 关系
  3208. - 姓名
  3209. - 出生日期
  3210. - 婚姻状况
  3211. - 现国籍
  3212. - 出生国
  3213. - 现居住国
  3214. - 现职务
  3215. - 家庭地址:请提取文档中的“家庭地址”或“现住址”。
  3216. - 家庭电话:请提取文档中的“家庭电话”。
  3217. - 移动电话:请提取文档中的“移动电话”或“手机”。
  3218. - 电子邮箱:请提取文档中的“电子邮箱”或“电子邮件”。
  3219. 工作信息:
  3220. - 工作经历:请提取文档中所有工作经历,以列表形式返回,每个条目包含以下信息:
  3221. - 单位名称
  3222. - 单位地址
  3223. - 职务
  3224. - 入职时间
  3225. - 离职时间
  3226. - 上级领导姓名(如适用)
  3227. - 工作单位名称:请提取文档中的“工作单位名称”或“现单位名称”。
  3228. - 工作单位地址:请提取文档中的“工作单位地址”或“单位地址”。
  3229. - 工作单位电话:请提取文档中的“工作单位电话”或“单位电话”。
  3230. - 职位:请提取文档中的“职位”或“目前职位”。
  3231. - 月薪:请提取文档中的“月薪”或“月收入”或“年薪”(如果是年薪自动除以12得到月薪)。
  3232. 教育经历:
  3233. - 教育经历:请提取文档中所有教育经历,以列表形式返回,每个条目包含以下信息:
  3234. - 学校名称
  3235. - 学校地址
  3236. - 学位
  3237. - 专业
  3238. - 入学时间
  3239. - 毕业时间
  3240. 签证与旅行记录:
  3241. - 拒签记录:请提取文档中所有拒签记录,以列表形式返回,每个条目包含以下信息:
  3242. - 国家
  3243. - 拒签日期:请提取文档中的“拒签日期”或“申请日期”。
  3244. - 地点:请提取文档中的“地点”或“拒签地点”。
  3245. - 签证申请类别
  3246. - 拒签原因
  3247. - 旅行历史:请提取文档中所有旅行历史,以列表形式返回,每个条目包含以下信息:
  3248. - 国家
  3249. - 到达日期
  3250. - 离开日期
  3251. - 签证类型(如适用)
  3252. - 服役历史:请提取文档中所有服役历史,以列表形式返回,每个条目包含以下信息:
  3253. - 军种
  3254. - 军衔
  3255. - 服役时间范围(开始日期至结束日期)
  3256. - 去过的国家:请提取文档中所有去过的国家及访问日期范围,以列表形式返回,每个条目包含以下信息:
  3257. - 国家名称
  3258. - 访问日期范围
  3259. - 申根签证记录:请提取文档中所有申根签证记录,以列表形式返回,每个条目包含以下信息:
  3260. - 签证类型
  3261. - 签发日期
  3262. - 有效期
  3263. 其他信息:
  3264. - 社交账号:请提取文档中提到的所有社交账号信息,以列表形式返回,每个条目包含以下信息:
  3265. - 平台名称
  3266. - 账号名称
  3267. - 邀请人信息:请提取文档中的“邀请人信息”,以列表形式返回,每个条目包含以下信息:
  3268. - 邀请人姓名
  3269. - 邀请人地址
  3270. - 邀请人联系方式
  3271. - 旅行目的:请提取文档中的“旅行目的”或“赴美目的”。
  3272. - 旅费支付方:请提取文档中的“旅费支付方”或“费用谁付”。
  3273. - 是否持有因公护照:请提取文档中的“是否持有因公护照”。
  3274. - 因公护照类型:请提取文档中的“因公护照类型”。
  3275. - 因公护照号码:请提取文档中的“因公护照号码”。
  3276. - 因公护照有效期:请提取文档中的“因公护照有效期”。
  3277. - 是否申请过该国签证:请提取文档中的“是否申请过该国签证”。
  3278. - 是否有亲属在目标国家:请提取文档中的“是否有亲属在目标国家”。
  3279. - 亲属、朋友及联系人信息:
  3280. - 请提取文档中所有在目标国家的亲属、朋友及联系人信息,以列表形式返回。
  3281. - 每个条目包含以下信息:
  3282. - 类型(亲属/朋友/联系人)
  3283. - 姓名
  3284. - 关系(如适用,如亲属关系)
  3285. - 出生日期
  3286. - 地址
  3287. - 联系方式
  3288. - 是否居住在现国籍以外的国家:请提取文档中的“是否居住在现国籍以外的国家”。
  3289. - 居留证编号:请提取文档中的“居留证编号”。
  3290. - 居留证有效期:请提取文档中的“居留证有效期”。
  3291. - 是否有指纹记录:请提取文档中的“是否有指纹记录”。
  3292. - 指纹记录日期:请提取文档中的“指纹记录日期”。
  3293. - 是否有美国驾照:请提取文档中的“是否有美国驾照”。
  3294. - 美国驾照号码:请提取文档中的“美国驾照号码”。
  3295. - 美国驾照签发地:请提取文档中的“美国驾照签发地”。
  3296. - 是否有美国社会安全号:请提取文档中的“是否有美国社会安全号”。
  3297. - 美国社会安全号:请提取文档中的“美国社会安全号”。
  3298. - 是否是其他国家的永久居民:请提取文档中的“是否是其他国家的永久居民”。
  3299. - 是否曾抵达过美国:请提取文档中的“是否曾抵达过美国”。
  3300. - 抵达美国时间:请提取文档中的“抵达美国时间”。
  3301. - 在美停留时间:请提取文档中的“在美停留时间”。
  3302. - 是否曾被美国拒签:请提取文档中的“是否曾被美国拒签”。
  3303. - 美国拒签日期:请提取文档中的“美国拒签日期”。
  3304. - 美国拒签原因:请提取文档中的“美国拒签原因”。
  3305. - 代办人姓名:请提取文档中的“代办人姓名”。
  3306. - 代办人手机号码:请提取文档中的“代办人手机号码”。
  3307. - 代办人现居住地址:请提取文档中的“代办人现居住地址”。
  3308. 把表格里的每个可填字段转换成“标题:值”的键值对,值用原文,不翻译。
  3309. 注:日期格式:YYYY-MM-DD、值为空时空字符串
  3310. 只返回json结构体,不需要其他内容,json内容去掉换行。");
  3311. var messages = new List<SeedMessages>
  3312. {
  3313. new() { Role = KimiRole.system, Content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长识别文件为Json格式的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一切涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。" },
  3314. new() { Role = KimiRole.user, Content = seedMessage }
  3315. };
  3316. messages.InsertRange(1, seedConter);
  3317. string jsonString = "";
  3318. dynamic jsonData = null;
  3319. bool isJson = false;
  3320. while (!isJson)
  3321. {
  3322. var kimiApiResult = await KiMiApi.SeedMessage(messages);
  3323. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  3324. var newJsonString = kimiApiResult_JObject["content"].ToString();
  3325. string startStr = "```json", endStr = "```";
  3326. // 判断并清除开头部分
  3327. if (newJsonString.StartsWith(startStr))
  3328. {
  3329. newJsonString = newJsonString.Replace(startStr, "");
  3330. }
  3331. // 判断并清除结尾部分
  3332. if (newJsonString.EndsWith(endStr))
  3333. {
  3334. newJsonString = newJsonString.Replace(endStr, "");
  3335. }
  3336. jsonString += newJsonString;
  3337. //验证json格式是否正确
  3338. try
  3339. {
  3340. jsonData = JsonDocument.Parse(jsonString);
  3341. isJson = true; // 如果解析成功,则是json格式
  3342. }
  3343. catch (Exception)
  3344. {
  3345. messages.Add(new() { Role = KimiRole.user, Content = "请接着续写未完成的json格式内容。" });
  3346. }
  3347. }
  3348. if (jsonData == null)
  3349. {
  3350. return Ok(JsonView(false, "kimi识别json转换失败。"));
  3351. }
  3352. var info = new Crm_DeleClient();
  3353. var company = new Crm_CustomerCompany();
  3354. var certs = new List<Crm_CustomerCert>();
  3355. var familys = new List<Crm_VisaCustomerFamily>();
  3356. var schools = new List<Crm_VisaCustomerSchool>();
  3357. var works = new List<Crm_VisaCustomerCompany>();
  3358. var refusalRecords = new List<VisaRefusalRecord>(); // 拒签记录
  3359. var travelHistories = new List<TravelHistory>(); // 出行历史
  3360. var militaries = new List<MilitaryInfo>(); // 军事信息
  3361. var countryVisiteds = new List<CountryVisited>(); // 已出访的国家
  3362. var schengenVisaRecords = new List<SchengenVisaRecord>(); // 申根签证记录
  3363. var socialAccounts = new List<SocialAccount>(); // 社交账号
  3364. var personInfos = new List<PersonInfo>(); // 亲属朋友信息
  3365. try
  3366. {
  3367. using (JsonDocument document = JsonDocument.Parse(jsonString))
  3368. {
  3369. JsonElement root = document.RootElement;
  3370. if (root.ValueKind == JsonValueKind.Object)
  3371. {
  3372. if (root.TryGetProperty("个人信息", out JsonElement userInfo))
  3373. {
  3374. if (TryGetNonEmptyStringProperty(userInfo, "姓名", out string name))
  3375. {
  3376. info.LastName = name.Substring(0, 1);
  3377. info.FirstName = name.Substring(1, name.Length - 1);
  3378. }
  3379. if (TryGetNonEmptyStringProperty(userInfo, "曾用名", out string oldName))
  3380. info.OldName = oldName;
  3381. if (TryGetNonEmptyStringProperty(userInfo, "拼音名", out string pinyin))
  3382. info.Pinyin = pinyin;
  3383. if (TryGetNonEmptyStringProperty(userInfo, "性别", out string gender))
  3384. info.Sex = gender switch
  3385. {
  3386. "男" => 0,
  3387. "女" => 1,
  3388. _ => -1
  3389. };
  3390. if (TryGetNonEmptyDateTimeProperty(userInfo, "出生日期", out DateTime? birthDay))
  3391. info.BirthDay = birthDay;
  3392. if (TryGetNonEmptyStringProperty(userInfo, "出生地省", out string birthProvince))
  3393. info.BirthProvince = birthProvince;
  3394. if (TryGetNonEmptyStringProperty(userInfo, "出生地市", out string birthCity))
  3395. info.BirthCity = birthCity;
  3396. if (TryGetNonEmptyStringProperty(userInfo, "国籍", out string nationality))
  3397. { }
  3398. if (TryGetNonEmptyStringProperty(userInfo, "身份证号码", out string idNo))
  3399. certs.Add(new() { SdId = 773, CertNo = idNo, Country = nationality });
  3400. if (TryGetNonEmptyStringProperty(userInfo, "婚姻状况", out string marital_status))
  3401. info.Marriage = marital_status switch
  3402. {
  3403. "未婚" => 1,
  3404. "已婚" => 2,
  3405. "离异" => 3,
  3406. "丧偶" => 4,
  3407. _ => 0
  3408. };
  3409. if (TryGetNonEmptyStringProperty(userInfo, "离婚原因", out string DivorceRsn))
  3410. info.DivorceRsn = DivorceRsn;
  3411. }
  3412. if (root.TryGetProperty("家庭信息", out JsonElement familyInfo))
  3413. {
  3414. if (TryGetNonEmptyStringProperty(familyInfo, "家庭地址", out string address))
  3415. info.Address = address;
  3416. if (TryGetNonEmptyStringProperty(familyInfo, "家庭电话", out string tel))
  3417. info.Tel = tel;
  3418. if (TryGetNonEmptyStringProperty(familyInfo, "移动电话", out string phone))
  3419. info.Phone = phone;
  3420. if (TryGetNonEmptyStringProperty(familyInfo, "电子邮箱", out string email))
  3421. info.Email = email;
  3422. if (familyInfo.TryGetProperty("家庭成员", out JsonElement family_members))
  3423. {
  3424. foreach (JsonElement family_member in family_members.EnumerateArray())
  3425. {
  3426. var familyInfo1 = new Crm_VisaCustomerFamily();
  3427. if (TryGetNonEmptyStringProperty(family_member, "关系", out string gx))
  3428. familyInfo1.Appellation = gx;
  3429. if (TryGetNonEmptyStringProperty(family_member, "姓名", out string family_name))
  3430. familyInfo1.Name = family_name;
  3431. if (TryGetNonEmptyDateTimeProperty(family_member, "出生日期", out DateTime? family_date_of_birth))
  3432. familyInfo1.BirthDay = family_date_of_birth;
  3433. if (TryGetNonEmptyStringProperty(family_member, "婚姻状况", out string marital_status))
  3434. familyInfo1.MaritalStatus = marital_status;
  3435. if (TryGetNonEmptyStringProperty(family_member, "现国籍", out string currentNationality))
  3436. familyInfo1.CurrentNationality = currentNationality;
  3437. if (TryGetNonEmptyStringProperty(family_member, "出生国", out string countryOfBirth))
  3438. familyInfo1.CountryOfBirth = countryOfBirth;
  3439. if (TryGetNonEmptyStringProperty(family_member, "现居住国", out string currentResidenceCountry))
  3440. familyInfo1.CurrentResidenceCountry = currentResidenceCountry;
  3441. if (TryGetNonEmptyStringProperty(family_member, "现职务", out string currentOccupation))
  3442. familyInfo1.CurrentOccupation = currentOccupation;
  3443. familys.Add(familyInfo1);
  3444. }
  3445. }
  3446. }
  3447. if (root.TryGetProperty("工作信息", out JsonElement workInfo))
  3448. {
  3449. if (TryGetNonEmptyStringProperty(workInfo, "工作单位名称", out string workName))
  3450. company.CompanyFullName = workName;
  3451. if (TryGetNonEmptyStringProperty(workInfo, "工作单位电话", out string workPhone))
  3452. info.ClientPhone = workPhone;
  3453. if (TryGetNonEmptyStringProperty(workInfo, "工作单位地址", out string address))
  3454. company.Address = address;
  3455. if (TryGetNonEmptyStringProperty(workInfo, "职位", out string job))
  3456. info.Job = job;
  3457. if (TryGetNonEmptyStringProperty(workInfo, "月薪", out string wage))
  3458. info.Wage = wage;
  3459. if (workInfo.TryGetProperty("工作经历", out JsonElement workExp))
  3460. {
  3461. foreach (JsonElement work in workExp.EnumerateArray())
  3462. {
  3463. var workInfo1 = new Crm_VisaCustomerCompany();
  3464. if (TryGetNonEmptyStringProperty(work, "单位名称", out string unit_name))
  3465. workInfo1.Company = unit_name;
  3466. if (TryGetNonEmptyStringProperty(work, "单位地址", out string unit_address))
  3467. workInfo1.CompanyAddress = unit_address;
  3468. if (TryGetNonEmptyStringProperty(work, "职务", out string work_position))
  3469. workInfo1.Job = work_position;
  3470. if (TryGetNonEmptyStringProperty(work, "上级领导姓名", out string superior_leader_name))
  3471. workInfo1.LeaderName = superior_leader_name;
  3472. if (TryGetNonEmptyDateTimeProperty(work, "入职时间", out DateTime? start_date))
  3473. workInfo1.WorkStart = start_date;
  3474. if (TryGetNonEmptyDateTimeProperty(work, "离职时间", out DateTime? end_date))
  3475. workInfo1.WorkEnd = end_date;
  3476. workInfo1.WorkState = "";
  3477. works.Add(workInfo1);
  3478. }
  3479. }
  3480. }
  3481. if (root.TryGetProperty("教育经历", out JsonElement eduInfo))
  3482. {
  3483. if (eduInfo.ValueKind == JsonValueKind.Array)
  3484. {
  3485. foreach (JsonElement edu in eduInfo.EnumerateArray())
  3486. {
  3487. var schoolInfo = new Crm_VisaCustomerSchool();
  3488. if (TryGetNonEmptyStringProperty(edu, "学校名称", out string school_name))
  3489. schoolInfo.School = school_name;
  3490. if (TryGetNonEmptyStringProperty(edu, "学校地址", out string school_address))
  3491. schoolInfo.Address = school_address;
  3492. if (TryGetNonEmptyStringProperty(edu, "专业", out string degree))
  3493. schoolInfo.Subject = degree;
  3494. if (TryGetNonEmptyStringProperty(edu, "学位", out string major))
  3495. schoolInfo.Education = major;
  3496. if (TryGetNonEmptyDateTimeProperty(edu, "入学时间", out DateTime? enrollment_date))
  3497. schoolInfo.StudyStart = enrollment_date;
  3498. if (TryGetNonEmptyDateTimeProperty(edu, "毕业时间", out DateTime? graduation_date))
  3499. schoolInfo.StudyEnd = graduation_date;
  3500. schools.Add(schoolInfo);
  3501. }
  3502. }
  3503. //if (eduInfo.TryGetProperty("教育经历", out JsonElement educations))
  3504. //{
  3505. //}
  3506. }
  3507. if (root.TryGetProperty("签证与旅行记录", out JsonElement visaTravelRecs))
  3508. {
  3509. if (visaTravelRecs.TryGetProperty("拒签记录", out JsonElement rejectRecs))
  3510. {
  3511. foreach (JsonElement rejectRec in rejectRecs.EnumerateArray())
  3512. {
  3513. var visaRefusalRecordInfo = new VisaRefusalRecord();
  3514. if (TryGetNonEmptyStringProperty(rejectRec, "国家", out string country))
  3515. visaRefusalRecordInfo.Country = country;
  3516. if (TryGetNonEmptyDateTimeProperty(rejectRec, "拒签日期", out DateTime? refusal_date))
  3517. visaRefusalRecordInfo.Date = refusal_date;
  3518. if (TryGetNonEmptyStringProperty(rejectRec, "申请签证类别", out string visaType))
  3519. visaRefusalRecordInfo.VisaType = visaType;
  3520. if (TryGetNonEmptyStringProperty(rejectRec, "地点", out string address))
  3521. visaRefusalRecordInfo.Address = address;
  3522. if (TryGetNonEmptyStringProperty(rejectRec, "拒签原因", out string refusal_reason))
  3523. visaRefusalRecordInfo.Reason = refusal_reason;
  3524. refusalRecords.Add(visaRefusalRecordInfo);
  3525. }
  3526. info.RefusalRecords = refusalRecords;
  3527. }
  3528. if (visaTravelRecs.TryGetProperty("旅行历史", out JsonElement travelHist))
  3529. {
  3530. foreach (JsonElement travel in travelHist.EnumerateArray())
  3531. {
  3532. var travelHistoryInfo = new TravelHistory();
  3533. if (TryGetNonEmptyStringProperty(travel, "国家", out string country))
  3534. travelHistoryInfo.Country = country;
  3535. if (TryGetNonEmptyDateTimeProperty(travel, "到达日期", out DateTime? arrival_date))
  3536. travelHistoryInfo.ArrivalDate = arrival_date;
  3537. if (TryGetNonEmptyDateTimeProperty(travel, "离开日期", out DateTime? departure_date))
  3538. travelHistoryInfo.DepartureDate = departure_date;
  3539. if (TryGetNonEmptyStringProperty(travel, "visa_type", out string visa_type))
  3540. travelHistoryInfo.VisaType = visa_type;
  3541. travelHistories.Add(travelHistoryInfo);
  3542. }
  3543. info.TravelHistories = travelHistories;
  3544. }
  3545. if (visaTravelRecs.TryGetProperty("服役历史", out JsonElement militaryHist))
  3546. {
  3547. foreach (JsonElement military in militaryHist.EnumerateArray())
  3548. {
  3549. var militaryInfo = new MilitaryInfo();
  3550. if (TryGetNonEmptyStringProperty(military, "军种", out string military_branch))
  3551. militaryInfo.MilBranch = military_branch;
  3552. if (TryGetNonEmptyStringProperty(military, "军衔", out string military_rank))
  3553. militaryInfo.MilRank = military_rank;
  3554. if (TryGetNonEmptyStringProperty(military, "服役时间范围", out string service_duration))
  3555. militaryInfo.ServeDuration = service_duration;
  3556. militaries.Add(militaryInfo);
  3557. }
  3558. info.Militaries = militaries;
  3559. }
  3560. if (visaTravelRecs.TryGetProperty("去过的国家", out JsonElement visitedCountries))
  3561. {
  3562. foreach (JsonElement country in visitedCountries.EnumerateArray())
  3563. {
  3564. var countryVisitedInfo = new CountryVisited();
  3565. if (TryGetNonEmptyStringProperty(country, "国家名称", out string visit_country))
  3566. countryVisitedInfo.Country = visit_country;
  3567. if (TryGetNonEmptyStringProperty(country, "访问日期范围", out string visit_date_range))
  3568. countryVisitedInfo.VisitDate = visit_date_range;
  3569. countryVisiteds.Add(countryVisitedInfo);
  3570. }
  3571. info.CountryVisiteds = countryVisiteds;
  3572. }
  3573. if (visaTravelRecs.TryGetProperty("申根签证记录", out JsonElement schengenVisaRecs))
  3574. {
  3575. foreach (JsonElement schengenVisaRec in schengenVisaRecs.EnumerateArray())
  3576. {
  3577. var schengenVisaRecInfo = new SchengenVisaRecord();
  3578. if (TryGetNonEmptyStringProperty(schengenVisaRec, "签证类型", out string visaType))
  3579. schengenVisaRecInfo.VisaType = visaType;
  3580. if (TryGetNonEmptyDateTimeProperty(schengenVisaRec, "签发日期", out DateTime? issueDate))
  3581. schengenVisaRecInfo.IssueDate = issueDate;
  3582. if (TryGetNonEmptyDateTimeProperty(schengenVisaRec, "有效期", out DateTime? expiryDate))
  3583. schengenVisaRecInfo.ExpiryDate = expiryDate;
  3584. schengenVisaRecords.Add(schengenVisaRecInfo);
  3585. }
  3586. info.SchengenVisaRecords = schengenVisaRecords;
  3587. }
  3588. }
  3589. if (root.TryGetProperty("其他信息", out JsonElement otherInfo))
  3590. {
  3591. if (otherInfo.TryGetProperty("社交账号", out JsonElement socialAccountss))
  3592. {
  3593. foreach (JsonElement socialAccount in socialAccountss.EnumerateArray())
  3594. {
  3595. var socialAccount1 = new SocialAccount();
  3596. if (TryGetNonEmptyStringProperty(socialAccount, "平台名称", out string platform))
  3597. socialAccount1.Platform = platform;
  3598. if (TryGetNonEmptyStringProperty(socialAccount, "账号名称", out string account))
  3599. socialAccount1.Account = account;
  3600. socialAccounts.Add(socialAccount1);
  3601. }
  3602. info.SocialAccounts = socialAccounts;
  3603. }
  3604. if (TryGetNonEmptyStringProperty(otherInfo, "旅行目的", out string usaPurpose))
  3605. info.USAPurpose = usaPurpose;
  3606. if (TryGetNonEmptyStringProperty(otherInfo, "旅费支付方", out string payer))
  3607. info.CostBearers = payer;
  3608. if (TryGetNonEmptyStringProperty(otherInfo, "是否持有因公护照", out string isUSAVia))
  3609. info.IsUSAVia = isUSAVia switch
  3610. {
  3611. "是" => 1,
  3612. _ => 0
  3613. };
  3614. if (info.IsUSAVia == 1)
  3615. {
  3616. if (TryGetNonEmptyDateTimeProperty(otherInfo, "因公护照有效期", out DateTime? GetUSAVisaDate))
  3617. info.GetUSAVisaDate = GetUSAVisaDate;
  3618. if (TryGetNonEmptyStringProperty(otherInfo, "因公护照类型", out string USAVisaCate))
  3619. info.USAVisaCate = USAVisaCate;
  3620. if (TryGetNonEmptyStringProperty(otherInfo, "因公护照号码", out string USAVisaCode))
  3621. info.USAVisaCode = USAVisaCode;
  3622. certs.Add(new() { SdId = 774, PassportType = 1012, CertNo = info.USAVisaCode });
  3623. }
  3624. if (otherInfo.TryGetProperty("亲属、朋友及联系人信息", out JsonElement personInfos1))
  3625. {
  3626. foreach (JsonElement personInfo in personInfos1.EnumerateArray())
  3627. {
  3628. var personInfo1 = new PersonInfo();
  3629. if (TryGetNonEmptyStringProperty(personInfo, "类型", out string type))
  3630. personInfo1.Type = type;
  3631. if (TryGetNonEmptyStringProperty(personInfo, "姓名", out string name))
  3632. personInfo1.Name = name;
  3633. if (TryGetNonEmptyDateTimeProperty(personInfo, "出生日期", out DateTime? birthDay))
  3634. personInfo1.BirthDay = birthDay;
  3635. if (TryGetNonEmptyStringProperty(personInfo, "地址", out string address))
  3636. personInfo1.Address = address;
  3637. if (TryGetNonEmptyStringProperty(personInfo, "联系方式", out string contactInfo))
  3638. personInfo1.ContactInfo = contactInfo;
  3639. personInfos.Add(personInfo1);
  3640. }
  3641. info.PersonInfos = personInfos;
  3642. }
  3643. if (TryGetNonEmptyStringProperty(otherInfo, "是否有指纹记录", out string IsFinger))
  3644. info.IsFinger = IsFinger switch
  3645. {
  3646. "是" => 1,
  3647. _ => 0
  3648. };
  3649. if (TryGetNonEmptyDateTimeProperty(otherInfo, "指纹记录日期", out DateTime? FingerDate))
  3650. info.FingerDate = FingerDate;
  3651. if (TryGetNonEmptyStringProperty(otherInfo, "美国驾照号码", out string USA_DLNo))
  3652. info.USA_DLNo = USA_DLNo;
  3653. if (TryGetNonEmptyStringProperty(otherInfo, "指纹记录日期", out string USA_DLPlace))
  3654. info.USA_DLPlace = USA_DLPlace;
  3655. if (TryGetNonEmptyStringProperty(otherInfo, "美国社会安全号", out string USA_SSNOrITIN))
  3656. info.USA_SSNOrITIN = USA_SSNOrITIN;
  3657. if (TryGetNonEmptyStringProperty(otherInfo, "是否是其他国家的永久居民", out string Resident))
  3658. info.Resident = Resident;
  3659. if (TryGetNonEmptyStringProperty(otherInfo, "抵达美国时间", out string USAHadArrival‌))
  3660. info.USAHadArrival‌ = USAHadArrival‌;
  3661. if (TryGetNonEmptyStringProperty(otherInfo, "在美停留时间", out string USAHadDays‌))
  3662. info.USAHadDays‌ = USAHadDays‌;
  3663. if (TryGetNonEmptyStringProperty(otherInfo, "代办人姓名", out string TableOpName))
  3664. info.TableOpName = TableOpName;
  3665. if (TryGetNonEmptyStringProperty(otherInfo, "代办人手机号码", out string TableOpTel))
  3666. info.TableOpTel = TableOpTel;
  3667. if (TryGetNonEmptyStringProperty(otherInfo, "代办人现居住地址", out string TableOpAddress))
  3668. { }
  3669. }
  3670. }
  3671. }
  3672. }
  3673. catch (Exception ex)
  3674. {
  3675. return Ok(JsonView(false, "信息提取失败:" + ex.Message));
  3676. }
  3677. #region 数据提交
  3678. _sqlSugar.BeginTran();
  3679. try
  3680. {
  3681. var infos = await _sqlSugar.Queryable<Crm_DeleClient>().Where(x => x.IsDel == 0).Select(x => new { x.Id, x.FirstName, x.LastName, x.Phone }).ToListAsync();
  3682. var infoDecrypts = new List<dynamic>();
  3683. foreach (var item in infos)
  3684. {
  3685. infoDecrypts.Add(new
  3686. {
  3687. Id = item.Id,
  3688. FirstName = AesEncryptionHelper.Decrypt(item.FirstName),
  3689. LastName = AesEncryptionHelper.Decrypt(item.LastName),
  3690. Phone = AesEncryptionHelper.Decrypt(item.Phone),
  3691. });
  3692. }
  3693. var infoVaild = infoDecrypts.Where(x =>
  3694. info.FirstName.Equals(x.FirstName) &&
  3695. info.LastName.Equals(x.LastName) &&
  3696. info.Phone.Equals(x.Phone))
  3697. .FirstOrDefault();
  3698. var compnayInfos = await _sqlSugar
  3699. .Queryable<Crm_CustomerCompany>()
  3700. .Where(x => x.IsDel == 0)
  3701. .ToListAsync();
  3702. foreach (var company1 in compnayInfos)
  3703. {
  3704. company1.CompanyFullName = AesEncryptionHelper.Decrypt(company1.CompanyFullName);
  3705. }
  3706. var compnayInfo = compnayInfos.FirstOrDefault(x => x.CompanyFullName == company.CompanyFullName);
  3707. if (compnayInfo == null)
  3708. {
  3709. company.CompanyFullName = AesEncryptionHelper.Encrypt(company.CompanyFullName);
  3710. compnayInfo = await _sqlSugar.Insertable(company).ExecuteReturnEntityAsync();
  3711. if (compnayInfo == null)
  3712. {
  3713. _sqlSugar.RollbackTran();
  3714. return Ok(JsonView(false, "公司信息添加失败!"));
  3715. }
  3716. }
  3717. else
  3718. {
  3719. // 存在信息为空则更新公司地址信息
  3720. if (string.IsNullOrEmpty(compnayInfo.Address))
  3721. {
  3722. compnayInfo.Address = company.Address;
  3723. var companyUpd = await _sqlSugar.Updateable(compnayInfo)
  3724. .UpdateColumns(x => x.Address)
  3725. .ExecuteCommandAsync();
  3726. if (companyUpd < 1)
  3727. {
  3728. _sqlSugar.RollbackTran();
  3729. return Ok(JsonView(false, "公司地址信息更新失败!"));
  3730. }
  3731. }
  3732. }
  3733. if (infoVaild == null) //添加
  3734. {
  3735. info.CrmCompanyId = compnayInfo.Id;
  3736. EncryptionProcessor.EncryptProperties(info);
  3737. var insertId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  3738. if (insertId < 1)
  3739. {
  3740. _sqlSugar.RollbackTran();
  3741. return Ok(JsonView(false, "信息添加失败!"));
  3742. }
  3743. if (certs.Any())
  3744. {
  3745. foreach (var cert in certs)
  3746. {
  3747. cert.CertNo = AesEncryptionHelper.Encrypt(cert.CertNo);
  3748. cert.DcId = insertId;
  3749. cert.CreateUserId = 4;
  3750. }
  3751. var cretInsert = await _sqlSugar.Insertable(certs).ExecuteCommandAsync();
  3752. if (cretInsert < 1)
  3753. {
  3754. _sqlSugar.RollbackTran();
  3755. return Ok(JsonView(false, "证件信息添加失败!"));
  3756. }
  3757. }
  3758. if (familys.Any())
  3759. {
  3760. foreach (var family in familys)
  3761. {
  3762. family.DcId = insertId;
  3763. family.CreateUserId = 4;
  3764. }
  3765. var familyInsert = await _sqlSugar.Insertable(familys).ExecuteCommandAsync();
  3766. if (familyInsert < 1)
  3767. {
  3768. _sqlSugar.RollbackTran();
  3769. return Ok(JsonView(false, "家庭信息添加失败!"));
  3770. }
  3771. }
  3772. if (schools.Any())
  3773. {
  3774. foreach (var school in schools)
  3775. {
  3776. school.DcId = insertId;
  3777. school.CreateUserId = 4;
  3778. }
  3779. var schoolInsert = await _sqlSugar.Insertable(schools).ExecuteCommandAsync();
  3780. if (schoolInsert < 1)
  3781. {
  3782. _sqlSugar.RollbackTran();
  3783. return Ok(JsonView(false, "学校信息添加失败!"));
  3784. }
  3785. }
  3786. if (works.Any())
  3787. {
  3788. foreach (var work in works)
  3789. {
  3790. work.DcId = insertId;
  3791. work.CreateUserId = 4;
  3792. }
  3793. var workInsert = await _sqlSugar.Insertable(works).ExecuteCommandAsync();
  3794. if (workInsert < 1)
  3795. {
  3796. _sqlSugar.RollbackTran();
  3797. return Ok(JsonView(false, "工作信息添加失败!"));
  3798. }
  3799. }
  3800. }
  3801. //修改
  3802. else
  3803. {
  3804. int id = infoVaild?.Id ?? 0;
  3805. var updInfo = await _sqlSugar.Queryable<Crm_DeleClient>().FirstAsync(x => x.Id == id);
  3806. EncryptionProcessor.DecryptProperties(updInfo);
  3807. foreach (var prop in info.GetType().GetProperties())
  3808. {
  3809. var currentVal = prop.GetValue(updInfo);
  3810. var newValue = prop.GetValue(info);
  3811. // 检查当前值是否为 null 或空字符串
  3812. if (currentVal == null || (currentVal is string && string.IsNullOrEmpty((string)currentVal)))
  3813. {
  3814. // 如果新值不为 null 或空字符串,则更新
  3815. if (newValue != null && !(newValue is string && string.IsNullOrEmpty((string)newValue)))
  3816. {
  3817. prop.SetValue(updInfo, newValue);
  3818. }
  3819. }
  3820. }
  3821. // 单独处理 婚姻字段 0 未设置 重新设置值
  3822. if (updInfo.Marriage == 0) updInfo.Marriage = info.Marriage;
  3823. EncryptionProcessor.EncryptProperties(updInfo);
  3824. var upd = await _sqlSugar.Updateable(updInfo).ExecuteCommandAsync();
  3825. if (upd < 1)
  3826. {
  3827. _sqlSugar.RollbackTran();
  3828. return Ok(JsonView(false, "个人信息更新失败!"));
  3829. }
  3830. int parentId = updInfo.Id;
  3831. if (certs.Any())
  3832. {
  3833. await _sqlSugar.Updateable<Crm_CustomerCert>()
  3834. .SetColumns(x => x.IsDel == 1)
  3835. .SetColumns(x => x.DeleteUserId == 4)
  3836. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  3837. .Where(x => x.DcId == parentId)
  3838. .ExecuteCommandAsync();
  3839. foreach (var cert in certs)
  3840. {
  3841. cert.CertNo = AesEncryptionHelper.Encrypt(cert.CertNo);
  3842. cert.DcId = parentId;
  3843. cert.CreateUserId = 4;
  3844. }
  3845. var cretInsert = await _sqlSugar.Insertable(certs).ExecuteCommandAsync();
  3846. if (cretInsert < 1)
  3847. {
  3848. _sqlSugar.RollbackTran();
  3849. return Ok(JsonView(false, "证件信息添加失败!"));
  3850. }
  3851. }
  3852. if (familys.Any())
  3853. {
  3854. await _sqlSugar.Updateable<Crm_VisaCustomerFamily>()
  3855. .SetColumns(x => x.IsDel == 1)
  3856. .SetColumns(x => x.DeleteUserId == 4)
  3857. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  3858. .Where(x => x.DcId == parentId)
  3859. .ExecuteCommandAsync();
  3860. foreach (var family in familys)
  3861. {
  3862. family.DcId = parentId;
  3863. family.CreateUserId = 4;
  3864. }
  3865. var familyInsert = await _sqlSugar.Insertable(familys).ExecuteCommandAsync();
  3866. if (familyInsert < 1)
  3867. {
  3868. _sqlSugar.RollbackTran();
  3869. return Ok(JsonView(false, "家庭信息添加失败!"));
  3870. }
  3871. }
  3872. if (schools.Any())
  3873. {
  3874. await _sqlSugar.Updateable<Crm_VisaCustomerSchool>()
  3875. .SetColumns(x => x.IsDel == 1)
  3876. .SetColumns(x => x.DeleteUserId == 4)
  3877. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  3878. .Where(x => x.DcId == parentId)
  3879. .ExecuteCommandAsync();
  3880. foreach (var school in schools)
  3881. {
  3882. school.DcId = parentId;
  3883. school.CreateUserId = 4;
  3884. }
  3885. var schoolInsert = await _sqlSugar.Insertable(schools).ExecuteCommandAsync();
  3886. if (schoolInsert < 1)
  3887. {
  3888. _sqlSugar.RollbackTran();
  3889. return Ok(JsonView(false, "学校信息添加失败!"));
  3890. }
  3891. }
  3892. if (works.Any())
  3893. {
  3894. await _sqlSugar.Updateable<Crm_VisaCustomerCompany>()
  3895. .SetColumns(x => x.IsDel == 1)
  3896. .SetColumns(x => x.DeleteUserId == 4)
  3897. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  3898. .Where(x => x.DcId == parentId)
  3899. .ExecuteCommandAsync();
  3900. foreach (var work in works)
  3901. {
  3902. work.DcId = parentId;
  3903. work.CreateUserId = 4;
  3904. }
  3905. var workInsert = await _sqlSugar.Insertable(works).ExecuteCommandAsync();
  3906. if (workInsert < 1)
  3907. {
  3908. _sqlSugar.RollbackTran();
  3909. return Ok(JsonView(false, "工作信息添加失败!"));
  3910. }
  3911. }
  3912. }
  3913. _sqlSugar.CommitTran();
  3914. return Ok(JsonView(true, "操作成功"));
  3915. }
  3916. catch (Exception ex)
  3917. {
  3918. _sqlSugar.RollbackTran();
  3919. return Ok(JsonView(false, ex.Message));
  3920. }
  3921. #endregion
  3922. #endregion
  3923. }
  3924. private static bool TryGetNonEmptyStringProperty(JsonElement root, string propertyName, out string value)
  3925. {
  3926. value = null;
  3927. if (root.TryGetProperty(propertyName, out JsonElement propertyElement))
  3928. {
  3929. string stringValue = propertyElement.GetString();
  3930. if (stringValue != null && stringValue != "null" && stringValue != "")
  3931. {
  3932. value = stringValue;
  3933. return true;
  3934. }
  3935. }
  3936. return false;
  3937. }
  3938. private static bool TryGetNonEmptyDateTimeProperty(JsonElement root, string propertyName, out DateTime? value)
  3939. {
  3940. value = null; // 初始化为null
  3941. if (root.TryGetProperty(propertyName, out JsonElement propertyElement))
  3942. {
  3943. string stringValue = propertyElement.GetString();
  3944. if (stringValue != null && stringValue != "null" && stringValue != "")
  3945. {
  3946. if (DateTime.TryParse(stringValue, out DateTime parsedValue))
  3947. {
  3948. value = parsedValue; // 将解析结果赋值给value
  3949. return true;
  3950. }
  3951. }
  3952. }
  3953. return false;
  3954. }
  3955. #region 扩展处理
  3956. // 从 Expression<Func<T,object>> 里取出属性名
  3957. static string GetPropName<T>(Expression<Func<T, object>> expr)
  3958. {
  3959. if (expr.Body is UnaryExpression ue) expr = Expression.Lambda<Func<T, object>>(ue.Operand, expr.Parameters);
  3960. return ((MemberExpression)expr.Body).Member.Name;
  3961. }
  3962. /// <summary>
  3963. /// 5.1.4.193 可用:存在更新(非NULL非空串),不存在插入,返回主键ID
  3964. /// </summary>
  3965. public int UpsertReturnId<T>(T entity, Expression<Func<T, object>> whereExpr) where T : class, new()
  3966. {
  3967. // 1. 空字符串→NULL,让后续忽略
  3968. foreach (var pi in typeof(T).GetProperties())
  3969. if (pi.PropertyType == typeof(string) &&
  3970. pi.GetValue(entity) is string s &&
  3971. string.IsNullOrWhiteSpace(s))
  3972. pi.SetValue(entity, null);
  3973. // 2. 从表达式里拿属性名
  3974. string propName = GetPropName(whereExpr);
  3975. var propValue = typeof(T).GetProperty(propName)?.GetValue(entity);
  3976. // 3. 判断存在
  3977. bool exists = _sqlSugar.Queryable<T>().Where(propName, propValue).Any();
  3978. // 4. 执行 Upsert
  3979. if (exists)
  3980. {
  3981. _sqlSugar.Updateable(entity)
  3982. .WhereColumns(propName) // 指定条件列
  3983. .IgnoreColumns(ignoreAllNullColumns: true) // 忽略 NULL
  3984. .ExecuteCommand();
  3985. }
  3986. else
  3987. {
  3988. _sqlSugar.Insertable(entity).ExecuteReturnIdentity();
  3989. }
  3990. // 5. 返回主键值(自增/雪花已回填)
  3991. var idProp = typeof(T).GetProperties()
  3992. .First(p => p.GetCustomAttributes<SugarColumn>()
  3993. .Any(a => a.IsPrimaryKey));
  3994. return (int)idProp.GetValue(entity)!;
  3995. }
  3996. /// <summary>
  3997. /// 地址喊邮编 相关处理
  3998. /// </summary>
  3999. public static (string address, string zipCode) SplitAddressZip(string? s)
  4000. {
  4001. if (string.IsNullOrWhiteSpace(s))
  4002. return ("", "");
  4003. ReadOnlySpan<char> src = s.AsSpan();
  4004. int i = src.IndexOf("邮编".AsSpan());
  4005. if (i < 0) // 没有“邮编”字样
  4006. return (src.Trim().ToString(), "");
  4007. ReadOnlySpan<char> addr = src[..i].TrimEnd();
  4008. ReadOnlySpan<char> zip = src[(i + 3)..].Trim(); // 跳过“邮编:”
  4009. // 可能只有“邮编:”而没有数字
  4010. return (addr.IsEmpty ? "" : addr.ToString(),
  4011. zip.IsEmpty ? "" : zip.ToString());
  4012. }
  4013. /// <summary>
  4014. /// 驾照相 关处理
  4015. /// </summary>
  4016. /// <param name="raw"></param>
  4017. /// <returns></returns>
  4018. public static (bool hasLicense, string number, string place) LicenseParser(string? raw)
  4019. {
  4020. if (string.IsNullOrWhiteSpace(raw))
  4021. return (false, "", "");
  4022. // 1. 是否持有
  4023. bool has = raw.StartsWith("是", System.StringComparison.OrdinalIgnoreCase) ||
  4024. raw.StartsWith("Y", System.StringComparison.OrdinalIgnoreCase);
  4025. // 2. 去掉前缀,按空格切
  4026. ReadOnlySpan<char> s = raw.AsSpan();
  4027. int colon = s.IndexOf(':');
  4028. ReadOnlySpan<char> after = colon < 0 ? s : s[(colon + 1)..];
  4029. after = after.Trim();
  4030. int space = after.IndexOf(' ');
  4031. ReadOnlySpan<char> num = space < 0 ? after : after[..space];
  4032. ReadOnlySpan<char> st = space < 0 ? ReadOnlySpan<char>.Empty : after[(space + 1)..];
  4033. return (has, num.ToString().Trim(), st.ToString().Trim());
  4034. }
  4035. /// <summary>
  4036. /// 美国社会安全号或者纳税ID号 相关处理
  4037. /// </summary>
  4038. /// <param name="raw"></param>
  4039. /// <returns></returns>
  4040. public static (bool hasSsnItin, string number) SsnItinParser(string? raw)
  4041. {
  4042. if (string.IsNullOrWhiteSpace(raw))
  4043. return (false, "");
  4044. ReadOnlySpan<char> s = raw.AsSpan();
  4045. // 1. 是否持有
  4046. bool has = s.StartsWith("是", System.StringComparison.Ordinal) ||
  4047. s.StartsWith("Y", System.StringComparison.OrdinalIgnoreCase);
  4048. // 2. 取号码(去掉前缀和空格)
  4049. int colon = s.IndexOf(':');
  4050. ReadOnlySpan<char> num = colon < 0
  4051. ? ReadOnlySpan<char>.Empty
  4052. : s[(colon + 1)..].Trim();
  4053. return (has, num.ToString());
  4054. }
  4055. /// <summary>
  4056. /// 取消开始的“是:”或者“是”或者“ :”
  4057. /// </summary>
  4058. /// <param name="raw"></param>
  4059. /// <returns></returns>
  4060. public static string CleanPrefix(string? raw)
  4061. {
  4062. if (string.IsNullOrWhiteSpace(raw)) return "";
  4063. // 跳过第一个“是”或“Y”
  4064. ReadOnlySpan<char> s = raw.AsSpan();
  4065. int start = 0;
  4066. if (s.StartsWith("是") || s.StartsWith("Y", StringComparison.OrdinalIgnoreCase))
  4067. start = 1;
  4068. // 跳过连续 : 或空格
  4069. while (start < s.Length && (s[start] == ':' || s[start] == ' '))
  4070. start++;
  4071. return s[start..].Trim().ToString();
  4072. }
  4073. /// <summary>
  4074. /// 婚姻起止时间处理
  4075. /// </summary>
  4076. /// <param name="raw"></param>
  4077. /// <returns></returns>
  4078. public static (DateTime? fromDate, DateTime? toDate) WeddingParser(string? raw)
  4079. {
  4080. if (string.IsNullOrWhiteSpace(raw)) return (null, null);
  4081. Regex _clean = new(@"[\s~至]+", RegexOptions.Compiled);
  4082. // 1. 把所有“空格~至”统一成 '-'
  4083. string normalized = _clean.Replace(raw, "-");
  4084. // 2. 切两段
  4085. string[] parts = normalized.Split('-', StringSplitOptions.RemoveEmptyEntries);
  4086. if (parts.Length != 2) return (null, null);
  4087. // 3. 解析
  4088. bool ff = DateTime.TryParse(parts[0].Trim(), out var from);
  4089. bool tf = DateTime.TryParse(parts[1].Trim(), out var to);
  4090. return (tf ? from : null, tf ? to : null);
  4091. }
  4092. /// <summary>
  4093. /// 出行日期和天数处理
  4094. /// </summary>
  4095. /// <param name="raw"></param>
  4096. /// <returns></returns>
  4097. public static (DateTime? travelDate, int? days) TravelParser(string? raw)
  4098. {
  4099. if (string.IsNullOrWhiteSpace(raw)) return (null, null);
  4100. // 切成两段:第一段日期,第二段天数
  4101. Regex sep = new(@"[^0-9./-]+", RegexOptions.Compiled);
  4102. string[] parts = sep.Split(raw.Trim());
  4103. if (parts.Length < 2) return (null, null);
  4104. bool okDate = DateTime.TryParse(parts[0], out DateTime date);
  4105. bool okDays = int.TryParse(parts[1], out int days) && days > 0;
  4106. return (okDate ? date : null, okDays ? days : null);
  4107. }
  4108. /// <summary>
  4109. /// 是否曾抵达过美国
  4110. /// </summary>
  4111. /// <param name="raw"></param>
  4112. /// <returns></returns>
  4113. public static (bool hasTravel, string date, string days) TravelHadFlagParser(string? raw)
  4114. {
  4115. if (string.IsNullOrWhiteSpace(raw)) return (false, string.Empty, string.Empty);
  4116. Regex sep = new(@"[^0-9./-]+", RegexOptions.Compiled);
  4117. // 1. 是否持有
  4118. bool has = raw.AsSpan().TrimStart().StartsWith("是") ||
  4119. raw.AsSpan().TrimStart().StartsWith("Y", StringComparison.OrdinalIgnoreCase);
  4120. // 2. 用非数字分隔符切成三段:第一段空,第二段日期,第三段天数
  4121. string[] parts = sep.Split(raw.Trim());
  4122. if (parts.Length < 3) return (has, string.Empty, string.Empty);
  4123. return (has, parts[1], parts[2]);
  4124. }
  4125. /// <summary>
  4126. /// 是否有被美国拒发签证的经历
  4127. /// </summary>
  4128. /// <param name="raw"></param>
  4129. /// <returns></returns>
  4130. public static (bool wasDenied, DateTime? date, string place, string visaType) VisaDenialParser(string? raw)
  4131. {
  4132. if (string.IsNullOrWhiteSpace(raw)) return (false, null, "", "");
  4133. bool denied = raw.AsSpan().TrimStart().StartsWith("有") ||
  4134. raw.AsSpan().TrimStart().StartsWith("Y", StringComparison.OrdinalIgnoreCase);
  4135. var parts = Regex.Split(raw.Trim(), @"[^0-9A-Za-z-]+");
  4136. if (parts.Length < 4) return (denied, null, "", "");
  4137. DateTime.TryParse(parts[1], out var dt); // ← 这里改为 DateTime
  4138. return (denied, dt, parts[2], parts[3]);
  4139. }
  4140. /// <summary>
  4141. /// 在美直系、旁系 处理
  4142. /// </summary>
  4143. /// <param name="raw"></param>
  4144. /// <returns></returns>
  4145. public static (bool flag, string name, string rel, string stat) FourFieldParser(string? raw)
  4146. {
  4147. if (string.IsNullOrWhiteSpace(raw)) return (false, "", "", "");
  4148. var parts = raw.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
  4149. if (parts.Length < 4) return (false, "", "", "");
  4150. bool flag = parts[0] is "有" or "是" or "Y" or "Yes";
  4151. string name = parts[1];
  4152. string rel = parts[2];
  4153. string stat = parts[3];
  4154. return (flag, name, rel, stat);
  4155. }
  4156. /// <summary>
  4157. /// 服役时间处理
  4158. /// </summary>
  4159. /// <param name="raw"></param>
  4160. /// <returns></returns>
  4161. public static (bool hasService, string branch, string rank, string specialty, (DateTime? start, DateTime? end) period) MilitaryParser(string? raw)
  4162. {
  4163. const string fmt = "yyyy年MM月dd日";
  4164. if (string.IsNullOrWhiteSpace(raw))
  4165. return (false, "", "", "", (null, null));
  4166. var parts = raw.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
  4167. if (parts.Length < 5) return (false, "", "", "", (null, null));
  4168. bool has = parts[0] is "是" or "Y" or "Yes";
  4169. string branch = parts[1];
  4170. string rank = parts[2];
  4171. string specialty = parts[3];
  4172. // 拼回时间字符串
  4173. string periodRaw = string.Join(" ", parts[4..]);
  4174. var span = periodRaw.AsSpan();
  4175. int zhi = span.IndexOf("至");
  4176. if (zhi < 0) return (has, branch, rank, specialty, (null, null));
  4177. var startStr = span.Slice(0, zhi).Trim();
  4178. var endStr = span.Slice(zhi + 1).Trim();
  4179. bool okStart = DateTime.TryParseExact(startStr.ToString(), fmt, null, DateTimeStyles.None, out var start);
  4180. bool okEnd = DateTime.TryParseExact(endStr.ToString(), fmt, null, DateTimeStyles.None, out var end);
  4181. return (has, branch, rank, specialty, (okStart ? start : null, okEnd ? end : null));
  4182. }
  4183. /// <summary>
  4184. /// 申请人父母信息
  4185. /// </summary>
  4186. /// <param name="raw"></param>
  4187. /// <returns></returns>
  4188. public static (string fatherName, DateTime? fatherDob, string motherName, DateTime? motherDob) ParentParser(string? raw)
  4189. {
  4190. const string fmt = "yyyy年MM月dd日";
  4191. if (string.IsNullOrWhiteSpace(raw)) return ("", null, "", null);
  4192. // 按空格切,去掉空元素
  4193. var parts = raw.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
  4194. if (parts.Length < 4) return ("", null, "", null);
  4195. // 父亲
  4196. string fName = parts[0];
  4197. DateTime.TryParseExact(parts[1], fmt, null, DateTimeStyles.None, out var fDob);
  4198. // 母亲
  4199. string mName = parts[2];
  4200. DateTime.TryParseExact(parts[3], fmt, null, DateTimeStyles.None, out var mDob);
  4201. return (fName, fDob, mName, mDob);
  4202. }
  4203. public class VisaDetailsView
  4204. {
  4205. /// <summary>
  4206. /// 客户资料表
  4207. /// </summary>
  4208. public Crm_DeleClient ClientInfo { get; set; }
  4209. /// <summary>
  4210. /// 客户家庭表
  4211. /// </summary>
  4212. public List<Crm_VisaCustomerFamily> ClientFamilys { get; set; }
  4213. /// <summary>
  4214. /// 客户公司表
  4215. /// </summary>
  4216. public Crm_CustomerCompany ClientCompany { get; set; }
  4217. /// <summary>
  4218. /// 客户证件表
  4219. /// </summary>
  4220. public List<Crm_CustomerCert> ClientCerts { get; set; }
  4221. /// <summary>
  4222. /// 客户学历表
  4223. /// </summary>
  4224. public List<Crm_VisaCustomerSchool> ClientSchools { get; set; }
  4225. }
  4226. private int GetSuccessCount(List<FileUploadResult> results)
  4227. {
  4228. var count = 0;
  4229. foreach (var result in results)
  4230. {
  4231. if (result.Success) count++;
  4232. }
  4233. return count;
  4234. }
  4235. #endregion
  4236. #region 文件下载
  4237. /// <summary>
  4238. /// 签证下载类型初始化
  4239. /// </summary>
  4240. private readonly static Dictionary<int, string> _visaTypeInit = new()
  4241. {
  4242. { 8, "西班牙" },
  4243. { 1, "美国" },
  4244. { 2, "日本" },
  4245. { 3, "韩国" },
  4246. { 4, "瑞典" },
  4247. { 5, "波兰" },
  4248. //{ 6, "加拿大" },
  4249. { 7, "克罗地亚" },
  4250. };
  4251. /// <summary>
  4252. /// 申根国
  4253. /// </summary>
  4254. private readonly static string[] _shenGenGuos = new string[] { "奥地利", "比利时", "丹麦", "芬兰", "法国", "德国", "冰岛", "意大利", "希腊", "卢森堡", "荷兰", "挪威", "葡萄牙", "西班牙",
  4255. "瑞典", "匈牙利", "捷克", "斯洛伐克", "斯洛文尼亚","波兰","爱沙尼亚","拉脱维亚","立陶宛","马耳他","瑞士","列支敦士登" };
  4256. /// <summary>
  4257. /// 欧盟国家
  4258. /// </summary>
  4259. private readonly static string[] _eucountries = new string[] { "奥地利", "比利时", "丹麦", "芬兰", "法国", "德国", "意大利", "希腊", "卢森堡", "荷兰", "葡萄牙", "西班牙","爱尔兰","罗马尼亚",
  4260. "保加利亚","匈牙利", "捷克", "斯洛伐克", "斯洛文尼亚","波兰","爱沙尼亚","拉脱维亚","立陶宛","马耳他","瑞士","列支敦士登" };
  4261. /// <summary>
  4262. /// 欧洲国家
  4263. /// </summary>
  4264. private readonly static string[] _aBC = new string[] { "英国", "爱尔兰" };
  4265. /// <summary>
  4266. /// 团组&签证 New
  4267. /// 签证文申请表下载 批量
  4268. /// </summary>
  4269. /// <param name="groupId"></param>
  4270. /// <param name="fileTypeId"></param>
  4271. /// <param name="language">
  4272. /// 下载语言:1-中文,2-英文
  4273. /// </param>
  4274. /// <returns></returns>
  4275. [HttpGet]
  4276. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  4277. public async Task<IActionResult> VisaFileDownload1(int groupId, int fileTypeId, int language = 1)
  4278. {
  4279. if (!_visaTypeInit.TryGetValue(fileTypeId, out _))
  4280. {
  4281. return Ok(JsonView(false, "请选择正确的文件类型!"));
  4282. }
  4283. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0 && x.Id == groupId).First();
  4284. if (groupInfo == null)
  4285. {
  4286. return Ok(JsonView(false, "团组信息不存在!"));
  4287. }
  4288. string group_unique_name = $"{groupInfo.TeamName}_{Guid.NewGuid().ToString("N").Substring(0, 10)}";
  4289. //访问路径
  4290. var serverPath = $"http://132.232.92.186:24/Office/Word/VisaClientData/Downloads/{group_unique_name}/";
  4291. //模板存储位置
  4292. var tempPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Template/";
  4293. //服务器存储文件位置
  4294. var fileServerPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Downloads/{group_unique_name}/";
  4295. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(fileServerPath);
  4296. //文件生成路径
  4297. string url = string.Empty;
  4298. //基础数据
  4299. //团组客户名单
  4300. var groupClients = await _sqlSugar.Queryable<Grp_TourClientList>()
  4301. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  4302. .Select(x => x.ClientId)
  4303. .ToListAsync();
  4304. if (groupClients.Count < 1)
  4305. {
  4306. return Ok(JsonView(false, "该团组下暂无团组名单!"));
  4307. }
  4308. //团组客户详细信息
  4309. var groupCustInfos = _sqlSugar.Queryable<Crm_DeleClient>().Where(x => x.IsDel == 0 && groupClients.Contains(x.Id)).ToList();
  4310. //家庭成员资料
  4311. var familyInfos = _sqlSugar.Queryable<Crm_VisaCustomerFamily>().Where(x => x.IsDel == 0 && groupClients.Contains(x.DcId)).ToList();
  4312. //公司资料
  4313. var companyInfo‌‌s = _sqlSugar.Queryable<Crm_VisaCustomerCompany>().Where(x => x.IsDel == 0 && groupClients.Contains(x.DcId)).ToList();
  4314. //学校资料
  4315. var schoolInfos = _sqlSugar.Queryable<Crm_VisaCustomerSchool>().Where(x => x.IsDel == 0 && groupClients.Contains(x.DcId)).ToList();
  4316. /* 证件类型
  4317. *
  4318. * 773 身份证
  4319. * 774 护照
  4320. * 775 学生证
  4321. * 776 军人证
  4322. * 777 回乡证
  4323. * 778 台胞证
  4324. * 779 港澳通行证
  4325. * 780 国际海员证
  4326. * 781 外国人永久居留证
  4327. * 782 旅行证
  4328. * 783 台湾通行证
  4329. * 784 港澳台居住证
  4330. * 785 其他
  4331. */
  4332. //证件资料
  4333. var certInfos = _sqlSugar.Queryable<Crm_CustomerCert>().Where(x => x.IsDel == 0 && groupClients.Contains(x.DcId)).ToList();
  4334. var applyDate = DateTime.Now.ToString("yyyy-MM-dd");
  4335. var filePaths = new List<string>();
  4336. var visaTypeName = string.Empty;
  4337. var currTempPath = string.Empty;
  4338. switch (fileTypeId)
  4339. {
  4340. case 1: // 美国
  4341. visaTypeName = $"美国签证申请表";
  4342. currTempPath = $"{tempPath}{visaTypeName}.doc";
  4343. var usaSavePath = $"{fileServerPath}{visaTypeName}/";
  4344. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(usaSavePath);
  4345. foreach (var custInfo in groupCustInfos)
  4346. {
  4347. //解密
  4348. EncryptionProcessor.DecryptProperties(custInfo);
  4349. Dictionary<string, string> dics = new();
  4350. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  4351. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  4352. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  4353. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4354. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4355. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4356. #region 美国签证模板书签值处理
  4357. dics.Add("LastNameEn", custInfo?.LastName ?? "");//名拼音
  4358. dics.Add("FirstNameEn", custInfo?.FirstName ?? "");//姓拼音
  4359. dics.Add("LastName", custInfo?.LastName ?? "");//名
  4360. dics.Add("FirstName", custInfo?.FirstName ?? "");//姓
  4361. dics.Add("OldNameEn", custInfo?.OldName ?? "");//曾用姓名拼音
  4362. dics.Add("OldName", custInfo?.FirstName ?? "");//曾用姓名
  4363. //未设置、未婚、已婚、离异、丧偶
  4364. var marriage = custInfo.Marriage switch
  4365. {
  4366. 0 => "未设置",
  4367. 1 => "未婚",
  4368. 2 => "已婚",
  4369. 3 => "离异",
  4370. 4 => "丧偶",
  4371. _ => "未知"
  4372. };
  4373. dics.Add("Marriage", marriage);//婚姻状况
  4374. dics.Add("Phone", custInfo?.Phone ?? "");//家庭电话
  4375. dics.Add("BirthCity", custInfo?.BirthCity ?? "");//出生城市
  4376. dics.Add("BirthProvince", custInfo?.BirthProvince ?? "");//出生省份
  4377. string m_idCard = idInfo?.CertNo ?? "";
  4378. string m_birthday = string.Empty;
  4379. if (!string.IsNullOrEmpty(m_idCard))
  4380. {
  4381. string m_year = m_idCard.Substring(6, 4);
  4382. string m_month = m_idCard.Substring(10, 2);
  4383. string m_day = m_idCard.Substring(12, 2);
  4384. m_birthday = m_year + "." + m_month + "." + m_day;
  4385. }
  4386. dics.Add("BirthDay", m_birthday);//出生日期
  4387. dics.Add("Tel", custInfo?.Tel ?? "");//移动电话
  4388. dics.Add("Email", custInfo?.Email ?? "");//电子信箱
  4389. dics.Add("IdCard", m_idCard);//身份证号码
  4390. dics.Add("Address", custInfo?.Address ?? "");//现居家庭地址
  4391. dics.Add("PostCodes", custInfo?.PostCodes ?? "");//邮编
  4392. dics.Add("Client", clinetInfo?.Company ?? "");//单位名称
  4393. dics.Add("ClientAddress", clinetInfo?.CompanyAddress ?? "");//单位地址
  4394. dics.Add("ClientPostCodes", custInfo?.PostCodes ?? "");//单位邮编
  4395. dics.Add("Job", custInfo?.Job ?? "");//职务
  4396. dics.Add("WorkDate", custInfo?.WorkDate ?? "");//入职时间
  4397. dics.Add("Wage", custInfo?.Wage ?? "");//月薪
  4398. dics.Add("ClientPhone", custInfo?.ClientPhone ?? "");//单位电话
  4399. dics.Add("ClientFax", custInfo?.ClientFax ?? "");//单位传真
  4400. dics.Add("ClientEmail", custInfo?.ClientEmail ?? "");//单位邮箱
  4401. dics.Add("ClientLeader", custInfo?.ClientLeader ?? "");//单位主管姓名
  4402. dics.Add("ClientLeaderJob", custInfo?.ClientLeaderJob ?? "");//单位主管职务
  4403. dics.Add("WorkState", custInfo?.WorkState ?? "");//工作内容简单介绍
  4404. dics.Add("IsGetSchengen", custInfo?.IsGetSchengen == 0 ? "否" : "是");//是否有获批的申根签证
  4405. dics.Add("StartTime", custInfo?.StartTime.ToString("yyyy-MM-dd") ?? "");//申根签证有效期开始
  4406. dics.Add("EndTime", custInfo?.EndTime.ToString("yyyy-MM-dd") ?? "");//申根签证有效期结束
  4407. dics.Add("IsFinger", custInfo.IsFinger == 0 ? "否" : "是");//申根签证是否有指纹记录
  4408. dics.Add("FingerDate", custInfo?.FingerDate?.ToString("yyyy-MM-dd") ?? "");//申根签指纹采集时间
  4409. dics.Add("TableOpName", custInfo?.TableOpName ?? "");//填表经办人
  4410. dics.Add("TableOpTel", custInfo?.TableOpTel ?? "");//填表经办人联系电话
  4411. dics.Add("TableDate", custInfo?.TableDate.ToString("yyyy-MM-dd") ?? "");//填表日期
  4412. dics.Add("Party", custInfo?.Party ?? "");//所属党派或宗教
  4413. dics.Add("Nationality", custInfo?.Nationality ?? "");//国籍
  4414. var sex = custInfo.Sex switch
  4415. {
  4416. 0 => "男",
  4417. 1 => "女",
  4418. _ => "未知"
  4419. };
  4420. dics.Add("Sex", sex);//性别
  4421. dics.Add("WeddingDate", custInfo?.WeddingDate?.ToString("yyyy-MM-dd") ?? "");//结婚日期
  4422. dics.Add("DivorceDate", custInfo?.DivorceDate?.ToString("yyyy-MM-dd") ?? "");//离婚日期
  4423. dics.Add("MateName", custInfo?.MateName ?? "");//配偶姓名
  4424. dics.Add("MateBirthDay", custInfo?.MateBirthDay.ToString("yyyy-MM-dd") ?? "");//配偶出生日期
  4425. dics.Add("MateBirthCity", custInfo?.MateBirthCity ?? "");//配偶出生城市
  4426. dics.Add("MateBirthCountry", custInfo?.MateBirthCountry ?? "");//配偶出生省份
  4427. dics.Add("MateAddress", custInfo?.MateAddress ?? "");//配偶住址
  4428. dics.Add("MateClient", custInfo?.MateClient ?? "");//配偶工作单位名称
  4429. dics.Add("MateClientAddress", custInfo?.MateClientAddress ?? "");//配偶工作单位地址
  4430. dics.Add("MateJob", custInfo?.MateJob ?? "");//配偶职务
  4431. dics.Add("VisitCountry", custInfo?.VisitCountry ?? "");//因公出访的国家
  4432. dics.Add("Paper", custInfo?.Paper ?? "");//发表的期刊、论文
  4433. dics.Add("Papent", custInfo?.Papent ?? "");//专利
  4434. dics.Add("PhD", custInfo?.PhD ?? "");//博士论文
  4435. dics.Add("IsVisitUC", custInfo?.IsVisitUC == 0 ? "否" : "是" ?? "");//是否因公去过美国/加拿大
  4436. dics.Add("USADate", custInfo?.USADate?.ToString("yyyy-MM-dd") ?? "");//美国抵达日期
  4437. dics.Add("USADays", custInfo?.USADays.ToString() ?? "");//美国停留天数
  4438. dics.Add("CanDate", custInfo?.CanDate.ToString("yyyy-MM-dd") ?? "");//加拿大抵达日期
  4439. dics.Add("CanDays", custInfo?.CanDays.ToString() ?? "");//加拿大停留天数
  4440. dics.Add("IsUSAVia", custInfo?.IsUSAVia == 0 ? "否" : "是" ?? "");//是否获得过因公美国签证
  4441. dics.Add("GetUSAVisaDate", custInfo?.GetUSAVisaDate?.ToString("yyyy-MM-dd") ?? "");//因公美国签证时间
  4442. dics.Add("GetUPPlace", custInfo?.GetUPPlace ?? "");//因公美国签证地点
  4443. dics.Add("USAVisaCate", custInfo?.USAVisaCate ?? "");//因公美国签证种类
  4444. dics.Add("USAVisaCode", custInfo?.USAVisaCode ?? "");//因公美国签证编码
  4445. dics.Add("USAFinger", custInfo?.USAFinger == 0 ? "否" : "是" ?? "");//是否在使馆留过十指的指纹
  4446. dics.Add("IsRejected", custInfo?.IsRejected == 0 ? "否" : "是" ?? "");//是否被拒
  4447. dics.Add("RejectedDate", custInfo?.RejectedDate?.ToString("yyyy-MM-dd") ?? "");//被拒时间
  4448. dics.Add("RejectedPlace", custInfo?.RejectedPlace ?? "");//被拒地点
  4449. dics.Add("RejectedVisa", custInfo?.RejectedVisa ?? "");//被拒签证种类
  4450. dics.Add("IsRevoke", custInfo?.IsRevoke == 0 ? "否" : "是" ?? "");//美国签证是否被吊销
  4451. dics.Add("IsLose", custInfo?.IsLose == 0 ? "否" : "是" ?? "");//护照是否丢失
  4452. dics.Add("LoseDate", custInfo?.LoseDate.ToString("yyyy-MM-dd") ?? "");//丢失的护照时间
  4453. dics.Add("LoseCode", custInfo?.LoseCode ?? "");//丢失的护照号码
  4454. dics.Add("IsUSAVisa", custInfo?.IsUSAVisa == 0 ? "否" : "是" ?? "");//丢失的护照是否有美国签证
  4455. dics.Add("MateUSA", custInfo?.MateUSA == 0 ? "否" : "是" ?? "");//夫/妻是否已在美国
  4456. dics.Add("MateIden", custInfo?.MateIden ?? "");//夫/妻身份
  4457. dics.Add("WHUSA", custInfo?.WHUSA == 0 ? "否" : "是" ?? "");//未婚夫/妻是否已在美国
  4458. dics.Add("WHIden", custInfo?.WHIden ?? "");//未婚夫/妻身份
  4459. dics.Add("ParentUSA", custInfo?.ParentUSA == 0 ? "否" : "是" ?? "");//父/母是否已在美国
  4460. dics.Add("ParentIden", custInfo?.ParentIden ?? "");//父/母身份
  4461. dics.Add("ChildUSA", custInfo?.ChildUSA == 0 ? "否" : "是" ?? "");//儿子/女儿是否已在美国
  4462. dics.Add("ChildIden", custInfo?.ChildIden ?? "");//儿子/女儿身份
  4463. dics.Add("BroUSA", custInfo?.BroUSA == 0 ? "否" : "是" ?? "");//兄弟/姐妹是否已在美国
  4464. dics.Add("BroIden", custInfo?.BroIden ?? "");//兄弟/姐妹身份
  4465. dics.Add("Social", custInfo?.Social ?? "");//所属/捐助/工作过的职业协会、社会团体和慈善机构
  4466. dics.Add("IsArmy", custInfo?.IsArmy == 0 ? "否" : "是" ?? "");//是否参军
  4467. dics.Add("ArmyState", custInfo?.ArmyState ?? "");//参军详情
  4468. dics.Add("ApplyDate", applyDate);//申请日期
  4469. //公司信息书签
  4470. if (currCompanyInfos.Count > 0)
  4471. {
  4472. for (int i = 0; i < currCompanyInfos.Count; i++)
  4473. {
  4474. var compnayInfo = currCompanyInfos[i];
  4475. if (!string.IsNullOrEmpty(compnayInfo.Company))
  4476. {
  4477. dics.Add("Company", compnayInfo?.Company ?? "");//公司名称
  4478. dics.Add("CompanyAddress", compnayInfo?.CompanyAddress ?? "");//公司地址
  4479. dics.Add("CompanyPhone", compnayInfo?.Phone ?? "");//公司电话
  4480. dics.Add("CompanyJob", compnayInfo?.Job ?? "");//职务
  4481. dics.Add("CompanyLeaderName", compnayInfo?.LeaderName ?? "");//主管名字
  4482. dics.Add("CompanyWorkStart", compnayInfo?.WorkStart?.ToString("yyyy-MM-dd") ?? "");//雇佣起始年月日
  4483. dics.Add("CompanyWorkEnd", compnayInfo?.WorkEnd?.ToString("yyyy-MM-dd") ?? "");//雇佣结束年月日
  4484. dics.Add("CompanyWorkState", compnayInfo?.WorkState ?? "");//工作职责及内容简述
  4485. }
  4486. else break;
  4487. }
  4488. }
  4489. //学校信息书签
  4490. if (currSchoolInfos.Count > 0)
  4491. {
  4492. for (int i = 0; i < currSchoolInfos.Count; i++)
  4493. {
  4494. var schoolInfo = currSchoolInfos[i];
  4495. if (!string.IsNullOrEmpty(schoolInfo.School))
  4496. {
  4497. dics.Add("School", schoolInfo?.School ?? "");//学校名称和学历
  4498. dics.Add("SchoolAddress", schoolInfo?.Address ?? "");//学校地址
  4499. dics.Add("SchoolTeacher", schoolInfo?.Teacher ?? "");//指导老师
  4500. dics.Add("SchoolSubject", schoolInfo?.Subject ?? "");//所学课程或专业名称
  4501. dics.Add("SchoolStudyStart", schoolInfo?.StudyStart?.ToString("yyyy-MM-dd") ?? "");//就读起始日
  4502. dics.Add("SchoolStudyEnd", schoolInfo?.StudyEnd?.ToString("yyyy-MM-dd") ?? "");//就读结束日
  4503. }
  4504. else break;
  4505. }
  4506. }
  4507. //家人信息书签
  4508. if (currFamilyInfos.Count > 0)
  4509. {
  4510. for (int i = 0; i < currFamilyInfos.Count; i++)
  4511. {
  4512. var familyInfo = currFamilyInfos[i];
  4513. if (!string.IsNullOrEmpty(familyInfo.Appellation))
  4514. {
  4515. dics.Add("FamilyAppellation", familyInfo?.Appellation ?? "");//家庭成员称谓
  4516. dics.Add("FamilyName", familyInfo?.Name ?? "");//家庭成员姓名
  4517. dics.Add("FamilyBirthDay", familyInfo?.BirthDay?.ToString("yyyy-MM-dd") ?? "");//家庭成员出生日期
  4518. dics.Add("FamilyBirthPlace", familyInfo?.BirthPlace ?? "");// 家庭成员出生地
  4519. dics.Add("FamilyPolitics", familyInfo?.Politics ?? "");//家庭成员政治面貌
  4520. dics.Add("FamilyClient", familyInfo?.Client ?? "");//家庭成员工作单位
  4521. dics.Add("FamilyAddress", familyInfo?.Address ?? "");// 家庭地址
  4522. dics.Add("IsEu", familyInfo?.IsEu == 0 ? "No" : "Yes" ?? "");// 欧盟公民
  4523. dics.Add("FamilyNameSnd", familyInfo?.NameSnd ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员姓名
  4524. dics.Add("FamilyBirthDaySnd", familyInfo?.BirthDaySnd.ToString("yyyy-MM-dd") ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员生日
  4525. dics.Add("FamilyNationality", familyInfo?.Nationality ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员国籍
  4526. dics.Add("FamilyIDCard", familyInfo?.IDCard ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员旅行证件编号或身份证号码
  4527. dics.Add("FamilyReletionship", familyInfo?.Reletionship ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员与申请人的关系
  4528. dics.Add("IsUSA", familyInfo?.IsUSA == 1 ? "是" : "否" ?? "");// 家庭成员是否在美国
  4529. }
  4530. else break;
  4531. }
  4532. }
  4533. #endregion
  4534. #region 生成文件
  4535. try
  4536. {
  4537. _logger.LogInformation("模板位置:{currTempPath}", currTempPath);
  4538. Document doc = new(currTempPath);
  4539. Aspose.Words.DocumentBuilder builder = new(doc);
  4540. string strTemp = "";
  4541. //循环键值对
  4542. foreach (var key in dics.Keys)
  4543. {
  4544. //将光标移入书签的位置
  4545. builder.MoveToBookmark(key);
  4546. //判断书签值是否为空
  4547. if (!string.IsNullOrEmpty(dics[key]))
  4548. {
  4549. strTemp = dics[key];
  4550. }
  4551. else strTemp = "";
  4552. //填充书签
  4553. builder.Write(strTemp.Replace("\\N", "\n"));
  4554. }
  4555. var custName = custInfo.LastName + custInfo.FirstName;
  4556. string fileName = $"{custName}_{visaTypeName}.doc";
  4557. var currFilePath = $"{usaSavePath}{fileName}";
  4558. doc.Save(currFilePath);
  4559. filePaths.Add(currFilePath);
  4560. }
  4561. catch (Exception ex)
  4562. {
  4563. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  4564. }
  4565. #endregion
  4566. }
  4567. break;
  4568. case 2: // 日本
  4569. visaTypeName = $"新办日本申请表";
  4570. currTempPath = $"{tempPath}/{visaTypeName}.pdf";
  4571. var jpnSavePath = $"{fileServerPath}/{visaTypeName}/";
  4572. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(jpnSavePath);
  4573. foreach (var custInfo in groupCustInfos)
  4574. {
  4575. EncryptionProcessor.DecryptProperties(custInfo);
  4576. Dictionary<string, string> dics = new();
  4577. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  4578. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  4579. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  4580. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4581. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4582. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4583. #region 生成文件
  4584. PdfReader reader = null;
  4585. FileStream templateStream = null;
  4586. FileStream outputStream = null;
  4587. PdfStamper stamper = null;
  4588. try
  4589. {
  4590. string outputPath = $"{jpnSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  4591. //读取模板文件
  4592. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  4593. reader = new PdfReader(templateStream);
  4594. //创建输出文件
  4595. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  4596. stamper = new PdfStamper(reader, outputStream);
  4597. AcroFields formFields = stamper.AcroFields;
  4598. #region 设置文本值
  4599. SetFieldValue(formFields, "surname_en", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? ""); // 姓 英文
  4600. SetFieldValue(formFields, "name_en", CommonFun.ConvertToPinyin(custInfo?.FirstName?.Trim() ?? "")?.ToLower() ?? ""); // 名 英文
  4601. SetFieldValue(formFields, "surname_cn", custInfo?.LastName ?? ""); // 姓 中文
  4602. SetFieldValue(formFields, "name_cn", custInfo?.FirstName ?? ""); // 名 中文
  4603. if (!string.IsNullOrEmpty(custInfo.OldName))
  4604. {
  4605. SetFieldValue(formFields, "formername_en", CommonFun.ConvertToPinyin(custInfo?.OldName?.Trim() ?? "")?.ToLower() ?? ""); // 出生时姓氏
  4606. SetFieldValue(formFields, "formername_cn", custInfo.OldName); // 出生时姓氏
  4607. }
  4608. else
  4609. {
  4610. SetFieldValue(formFields, "formername_cn", custInfo.OldName); // 出生时姓氏
  4611. }
  4612. // 出生日期(日-月-年)
  4613. string idCard = idInfo?.CertNo?.Trim() ?? "";
  4614. string birthday = string.Empty;
  4615. if (!string.IsNullOrEmpty(idCard))
  4616. {
  4617. string year = idCard.Substring(6, 4);
  4618. string month = idCard.Substring(10, 2);
  4619. string day = idCard.Substring(12, 2);
  4620. birthday = day + "-" + month + "-" + year;
  4621. }
  4622. SetFieldValue(formFields, "birthday", birthday);
  4623. string currentNationality = custInfo.BirthProvince + custInfo.BirthCity;
  4624. SetFieldValue(formFields, "birthplace", currentNationality); // 出生地
  4625. SetFieldValue(formFields, "nationality", "中国"); // 出生国
  4626. SetFieldValue(formFields, "previous_nationality", "中国"); // 现国籍
  4627. SetFieldValue(formFields, "IdNo", idCard); // 身份证号码
  4628. #region 性别处理
  4629. //清除性别
  4630. SetFieldValue(formFields, "sex_man", "Off"); // 性别 - 男
  4631. SetFieldValue(formFields, "sex_woman", "Off"); // 性别 - 女
  4632. //设置性别
  4633. if (custInfo.Sex == 0) //男
  4634. {
  4635. SetFieldValue(formFields, "sex_man", "Yes"); // 性别 - 男
  4636. }
  4637. else if (custInfo.Sex == 1) //女
  4638. {
  4639. SetFieldValue(formFields, "sex_woman", "Yes"); // 性别 - 女
  4640. }
  4641. #endregion
  4642. #region 婚姻状况处理
  4643. //清除婚姻状况
  4644. SetFieldValue(formFields, "marriage_single", "Off"); // 婚姻状况 - 未婚
  4645. SetFieldValue(formFields, "marriage_married", "Off"); // 婚姻状况 - 已婚
  4646. SetFieldValue(formFields, "marriage_divorce", "Off"); // 婚姻状况 - 离婚
  4647. SetFieldValue(formFields, "marriage_widowedw", "Off"); // 婚姻状况 - 丧偶
  4648. //设置婚姻状况
  4649. switch (custInfo.Marriage)
  4650. {
  4651. case 1: // 未婚
  4652. SetFieldValue(formFields, "marriage_single", "Yes");
  4653. break;
  4654. case 2: // 已婚
  4655. SetFieldValue(formFields, "marriage_married", "Yes");
  4656. break;
  4657. case 3: // 离异
  4658. SetFieldValue(formFields, "marriage_divorce", "Yes");
  4659. break;
  4660. case 4: // 离异
  4661. SetFieldValue(formFields, "marriage_widowedw", "Yes");
  4662. break;
  4663. }
  4664. #endregion
  4665. #region 护照(旅行证件类型)
  4666. //清除值
  4667. SetFieldValue(formFields, "passport_diplomacy", "Off"); // 旅行证件类型 - 外交护照
  4668. SetFieldValue(formFields, "passport_official", "Off"); // 旅行证件类型 - 公务护照
  4669. SetFieldValue(formFields, "passport_ordinary", "Off"); // 旅行证件类型 - 普通护照
  4670. SetFieldValue(formFields, "passport_other", "Off"); // 旅行证件类型 - 其它
  4671. //设置值
  4672. if (passportInfo != null)
  4673. {
  4674. // 签证类型
  4675. var visatypeInfo = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == passportInfo.PassportType);
  4676. if (visatypeInfo != null)
  4677. {
  4678. string visaName = visatypeInfo?.Name ?? "-";
  4679. if (visaName.contains("外交")) SetFieldValue(formFields, "passport_diplomacy", "Yes"); // 旅行证件类型 - 外交护照
  4680. else if (visaName.contains("公务")) SetFieldValue(formFields, "passport_official", "Yes"); // 旅行证件类型 - 公务护照
  4681. else if (visaName.contains("普通")) SetFieldValue(formFields, "passport_ordinary", "Yes"); // 旅行证件类型 - 普通护照
  4682. else if (visaName.contains("其它")) SetFieldValue(formFields, "passport_other", "Yes"); // 旅行证件类型 - 其它
  4683. else SetFieldValue(formFields, "passport_ordinary", "Yes"); // 旅行证件类型 - 普通护照
  4684. }
  4685. SetFieldValue(formFields, "passport_no", passportInfo.CertNo); // 签证编号
  4686. SetFieldValue(formFields, "passport_issuplice", passportInfo.Country + passportInfo.Area); // 签发 国、地区
  4687. SetFieldValue(formFields, "passport_issuauthority", ""); // 签发机关
  4688. SetFieldValue(formFields, "passport_issudate", passportInfo.IssueDt?.ToString("yyyy-MM-dd") ?? ""); // 签发日期
  4689. SetFieldValue(formFields, "passport_validdate", passportInfo.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); // 有效期至
  4690. }
  4691. #endregion
  4692. SetFieldValue(formFields, "certification_number", ""); // 再留资格认证证书编号
  4693. SetFieldValue(formFields, "residentialstatus_purposetojapan", groupInfo?.VisitPurpose ?? ""); // 居住身份、赴日目的
  4694. // 签证国家下的城市
  4695. string city = "";
  4696. string county = "";
  4697. #region 入境信息
  4698. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  4699. if (atbc != null)
  4700. {
  4701. string startTime = string.Empty; // 开始停留时间
  4702. string endTime = string.Empty; // 离开时间
  4703. string three = string.Empty; // 航司
  4704. string threeCode = string.Empty; // 入境口岸
  4705. for (int i = 0; i < atbc.Rows.Count; i++)
  4706. {
  4707. if (i == 0) //得到抵达日期
  4708. {
  4709. three = atbc.Rows[i]["Fliagtcode"].ToString();
  4710. startTime = atbc.Rows[i]["Day"].ToString();
  4711. threeCode = atbc.Rows[i]["Three"].ToString();
  4712. continue;
  4713. }
  4714. if (i == 1)
  4715. endTime = atbc.Rows[i]["Day"].ToString();
  4716. }
  4717. dics.Add("japandate_stay", startTime); // 预计逗留日期 起
  4718. dics.Add("japandate_end", endTime); // 预计逗留日期 止
  4719. dics.Add("japanduring", startTime); // 预计逗留期间
  4720. if (!string.IsNullOrEmpty(three))
  4721. {
  4722. //查询航司名称
  4723. var threeCodeTwo = three.Substring(0, 2);
  4724. var ac = _sqlSugar.Queryable<Res_AirCompany>().Where(x => x.ShortCode == threeCodeTwo).First();
  4725. if (ac != null)
  4726. {
  4727. dics.Add("shiporairlinename", $"{ac?.EnName ?? ""} {three}"); // 航司名称
  4728. }
  4729. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  4730. if (tc != null)
  4731. {
  4732. county = tc.Country;
  4733. city = tc.City;
  4734. dics.Add("portentry", tc?.City ?? ""); // 入境口岸
  4735. }
  4736. }
  4737. }
  4738. #endregion
  4739. #region 申请人酒店信息
  4740. if (!string.IsNullOrEmpty(city))
  4741. {
  4742. //得到当前国家下的城市酒店信息
  4743. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  4744. .Where(x => x.DiId == groupId)
  4745. .Where(x => x.City.contains(city))
  4746. .First();
  4747. //酒店住址
  4748. if (hotelInfo != null)
  4749. {
  4750. dics.Add("hotelorfriend_name", hotelInfo?.HotelName ?? ""); // 酒店名称
  4751. dics.Add("hotelorfriend_tel", hotelInfo?.HotelAddress ?? ""); // 酒店地址
  4752. dics.Add("hotelorfriend_address", hotelInfo?.HotelTel ?? ""); // 酒店电话
  4753. }
  4754. }
  4755. #endregion
  4756. SetFieldValue(formFields, "japanduring_lasttime", ""); // 上次赴日日期及停留时间
  4757. #region 家庭信息
  4758. SetFieldValue(formFields, "family_address", custInfo.Address); // 地址
  4759. SetFieldValue(formFields, "family_tel", custInfo.Tel); // 电话
  4760. SetFieldValue(formFields, "family_phone", custInfo.Phone); // 手机
  4761. SetFieldValue(formFields, "family_email", custInfo.Email); // 电子邮件
  4762. #endregion
  4763. #region 工作单位信息
  4764. SetFieldValue(formFields, "company_name", companyInfos?.FirstOrDefault()?.Company ?? ""); // 名称
  4765. SetFieldValue(formFields, "company_tel", companyInfos?.FirstOrDefault()?.Phone ?? ""); // 电话
  4766. SetFieldValue(formFields, "family_address", companyInfos?.FirstOrDefault()?.CompanyAddress ?? "");// 地址
  4767. SetFieldValue(formFields, "company_job", custInfo?.Job ?? ""); // 职位
  4768. #endregion
  4769. SetFieldValue(formFields, "spouseorparents_job", custInfo?.MateJob ?? ""); // 配偶职业(如果是未成年人请填写服务的职业)
  4770. #region 担保人、邀请人 信息
  4771. if (!string.IsNullOrEmpty(county) && !string.IsNullOrEmpty(city))
  4772. {
  4773. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  4774. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  4775. .Where(x => x.Country.Contains(county))
  4776. .Where(x => x.Area.Contains(city))
  4777. .First();
  4778. //邀请 接待单位
  4779. if (oa != null)
  4780. {
  4781. dics.Add("guarantor_name_en", CommonFun.ConvertToPinyin(oa?.Contact?.Trim() ?? "")?.ToLower() ?? ""); // 担保人姓名(英文)
  4782. dics.Add("guarantor_name_cn", oa?.Contact ?? ""); // 担保人姓名(中文)
  4783. dics.Add("guarantor_tel", oa?.Tel ?? ""); // 担保人电话
  4784. dics.Add("guarantor_address_en", CommonFun.ConvertToPinyin(oa?.Address?.Trim() ?? "")?.ToLower() ?? ""); //担保人地址(英文)
  4785. dics.Add("guarantor_address_cn", oa?.Address ?? ""); // 担保人地址(中文)
  4786. dics.Add("guarantor_occuandposition", oa?.Job ?? ""); // 担保人职务
  4787. dics.Add("guarantor_relationship", "邀请方"); // 和申请人关系
  4788. dics.Add("guarantor_birthday", ""); // 出生日期
  4789. dics.Add("guarantor_sex_woman", "Off"); // 性别 女
  4790. dics.Add("guarantor_sex_man", "Off"); // 性别 男
  4791. dics.Add("guarantor_nationalityandvisatype", "日本"); // 邀请方 国家
  4792. dics.Add("inviter_name", "同上"); // 邀请人 姓名
  4793. dics.Add("inviter_tel", "同上"); // 邀请人 电话
  4794. dics.Add("inviter_addres", "同上"); // 邀请人 地址
  4795. dics.Add("inviter_birthday", "同上"); // 邀请人 出生日期
  4796. dics.Add("inviter_sex_man", "Off"); // 邀请人 性别 女
  4797. dics.Add("inviter_sex_woman", "Off"); // 邀请人 性别 男
  4798. dics.Add("inviter_relationship", "同上"); // 邀请人 与申请人关系
  4799. dics.Add("inviter_occuandposition", "同上"); // 邀请人 职业、职务
  4800. dics.Add("inviter_nationalityandvisatype", "同上"); // 邀请人 国籍
  4801. dics.Add("inviter_remark", ""); // 邀请人 备注
  4802. }
  4803. }
  4804. #endregion
  4805. #region 犯罪信息
  4806. // 在任何国家曾被判决有罪
  4807. dics.Add("criminal_conviction_yes", "Off");
  4808. dics.Add("criminal_conviction_no", "Off");
  4809. // 在任何国家曾被判处一年或一年以上徒刑
  4810. dics.Add("felony_conviction_yes", "Off");
  4811. dics.Add("felony_conviction_no", "Off");
  4812. // 在任何国家曾因非法滞留或违反改过法律法规而被驱逐出镜
  4813. dics.Add("deportation_order_yes", "Off");
  4814. dics.Add("deportation_order_no", "Off");
  4815. // 因违反毒品相关法律被判刑
  4816. dics.Add("drug_conviction_yes", "Off");
  4817. dics.Add("drug_conviction_no", "Off");
  4818. // 从事或参与卖淫相关活动
  4819. dics.Add("prostitution_involvement_yes", "Off");
  4820. dics.Add("prostitution_involvement_no", "Off");
  4821. // 贩卖人口相关犯罪经历
  4822. dics.Add("human_trafficking_offense_yes", "Off");
  4823. dics.Add("human_trafficking_offense_no", "Off");
  4824. //备注
  4825. dics.Add("yes_remark", "");
  4826. #endregion
  4827. SetFieldValue(formFields, "application_date", DateTime.Now.ToString("dd/MM/yyyy")); // 申请日期
  4828. #endregion
  4829. filePaths.Add(outputPath);
  4830. //return outputPath;
  4831. }
  4832. catch (Exception ex)
  4833. {
  4834. return Ok(JsonView(false, $"生成PDF文件时出错:{ex.Message}"));
  4835. }
  4836. finally
  4837. {
  4838. // 按正确顺序关闭资源
  4839. stamper?.Close();
  4840. reader?.Close();
  4841. templateStream?.Close();
  4842. outputStream?.Close();
  4843. }
  4844. #endregion
  4845. }
  4846. break;
  4847. case 3: // 韩国
  4848. visaTypeName = $"韩国签证申请表";
  4849. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  4850. var korSavePath = $"{fileServerPath}{visaTypeName}/";
  4851. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(korSavePath);
  4852. foreach (var custInfo in groupCustInfos)
  4853. {
  4854. EncryptionProcessor.DecryptProperties(custInfo);
  4855. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  4856. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  4857. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  4858. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4859. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4860. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4861. #region 生成文件
  4862. PdfReader reader = null;
  4863. FileStream templateStream = null;
  4864. FileStream outputStream = null;
  4865. PdfStamper stamper = null;
  4866. try
  4867. {
  4868. string outputPath = $"{korSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  4869. //读取模板文件
  4870. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  4871. reader = new PdfReader(templateStream);
  4872. //创建输出文件
  4873. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  4874. stamper = new PdfStamper(reader, outputStream);
  4875. AcroFields formFields = stamper.AcroFields;
  4876. #region 设置文本值
  4877. string selected = "√";
  4878. #region 1. 个人信息
  4879. SetFieldValue(formFields, "family_name", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? ""); // 姓 英文
  4880. SetFieldValue(formFields, "given_names", CommonFun.ConvertToPinyin(custInfo?.FirstName?.Trim() ?? "")?.ToLower() ?? ""); // 名 英文
  4881. string name_cn = custInfo.LastName + custInfo.FirstName;
  4882. SetFieldValue(formFields, "name_cn", name_cn); // 姓名 中文
  4883. #region 性别
  4884. //清除性别
  4885. SetFieldValue(formFields, "sex_male", "Off"); // 性别 - 男
  4886. SetFieldValue(formFields, "sex_female", "Off"); // 性别 - 女
  4887. //设置性别
  4888. if (custInfo.Sex == 0) //男
  4889. {
  4890. SetFieldValue(formFields, "sex_male", "Yes"); // 性别 - 男
  4891. }
  4892. else if (custInfo.Sex == 1) //女
  4893. {
  4894. SetFieldValue(formFields, "sex_female", "Yes"); // 性别 - 女
  4895. }
  4896. #endregion
  4897. #region 出生日期(日-月-年)
  4898. string idCard = idInfo?.CertNo?.Trim() ?? "";
  4899. string birthday = string.Empty;
  4900. if (!string.IsNullOrEmpty(idCard))
  4901. {
  4902. string year = idCard.Substring(6, 4);
  4903. string month = idCard.Substring(10, 2);
  4904. string day = idCard.Substring(12, 2);
  4905. birthday = day + "-" + month + "-" + year;
  4906. }
  4907. SetFieldValue(formFields, "birthday", birthday);
  4908. #endregion
  4909. SetFieldValue(formFields, "previous_nationality", "中国"); // 现国籍
  4910. SetFieldValue(formFields, "nationality", "中国"); // 出生国
  4911. SetFieldValue(formFields, "IdNo", idCard); // 身份证号码
  4912. #region 是否曾用别名从韩国出入境
  4913. SetFieldValue(formFields, "applicant_no", selected); // 否 默认选中
  4914. SetFieldValue(formFields, "applicant_yes", "");
  4915. string isGetSchengenStr = custInfo.IsGetSchengen == 0 ? "否" : "是";
  4916. string oldName = custInfo?.OldName ?? "";
  4917. if (!string.IsNullOrEmpty(oldName) && isGetSchengenStr.equals("是"))
  4918. {
  4919. SetFieldValue(formFields, "applicant_no", "");
  4920. SetFieldValue(formFields, "applicant_yes", selected);
  4921. if (!string.IsNullOrEmpty(oldName))
  4922. {
  4923. SetFieldValue(formFields, "former_surname", oldName.Substring(0, 1));
  4924. SetFieldValue(formFields, "former_given_name", oldName.Remove(0, 1));
  4925. }
  4926. }
  4927. #endregion
  4928. #region 是否拥有双重国籍
  4929. SetFieldValue(formFields, "dual_citizenship_no", selected); // 否 默认选中
  4930. SetFieldValue(formFields, "dual_citizenship_yes", "");
  4931. SetFieldValue(formFields, "dual_citizenship_remark", "");
  4932. #endregion
  4933. #endregion
  4934. #region 2. 申请签证信息
  4935. //SetFieldValue(formFields, "overstay_period_over_90_days", selected); // 90天以上长期滞留
  4936. //SetFieldValue(formFields, "overstay_period_under_90_days", selected); // 90天以下短期滞留
  4937. //SetFieldValue(formFields, "overstay_period_status", ""); // 滞留资格
  4938. #endregion
  4939. #region 3. 护照信息
  4940. //清除值
  4941. SetFieldValue(formFields, "passport_type_diplomatic", ""); // 旅行证件类型 - 外交护照
  4942. SetFieldValue(formFields, "passport_type__official", ""); // 旅行证件类型 - 公务护照
  4943. SetFieldValue(formFields, "passport_type__regular", ""); // 旅行证件类型 - 普通护照
  4944. SetFieldValue(formFields, "passport_type__other", ""); // 旅行证件类型 - 其它
  4945. //设置值
  4946. if (passportInfo != null)
  4947. {
  4948. // 签证类型
  4949. var visatypeInfo = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == passportInfo.PassportType);
  4950. if (visatypeInfo != null)
  4951. {
  4952. string visaName = visatypeInfo?.Name ?? "-";
  4953. if (visaName.contains("外交")) SetFieldValue(formFields, "passport_type_diplomatic", selected); // 旅行证件类型 - 外交护照
  4954. else if (visaName.contains("公务")) SetFieldValue(formFields, "passport_type__official", selected); // 旅行证件类型 - 公务护照
  4955. else if (visaName.contains("普通")) SetFieldValue(formFields, "passport_type__regular", selected); // 旅行证件类型 - 普通护照
  4956. else if (visaName.contains("其它")) // 旅行证件类型 - 其它
  4957. {
  4958. SetFieldValue(formFields, "passport_type__other", selected);
  4959. SetFieldValue(formFields, "passport_type__other_remark", "");
  4960. }
  4961. else SetFieldValue(formFields, "passport_ordinary", selected); // 旅行证件类型 - 普通护照
  4962. }
  4963. SetFieldValue(formFields, "passport_no", passportInfo.CertNo); // 签证 编号
  4964. SetFieldValue(formFields, "passport_country", passportInfo.Country); // 签发 国
  4965. SetFieldValue(formFields, "passport_issuePlace", passportInfo.Area); // 签发 地
  4966. SetFieldValue(formFields, "passport_issue_date", passportInfo.IssueDt?.ToString("yyyy-MM-dd") ?? ""); // 签发日期
  4967. SetFieldValue(formFields, "passport_expiryDate", passportInfo.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); // 有效期至
  4968. #region 是否有其他护照信息
  4969. SetFieldValue(formFields, "otherPassport_no", selected); // 否 默认选中
  4970. SetFieldValue(formFields, "otherPassport_yes", ""); // 是
  4971. //清除值
  4972. SetFieldValue(formFields, "other_passport_type_diplomatic", ""); // 旅行证件类型 - 外交护照
  4973. SetFieldValue(formFields, "other_passport_type_official", ""); // 旅行证件类型 - 公务护照
  4974. SetFieldValue(formFields, "other_passport_type_regular", ""); // 旅行证件类型 - 普通护照
  4975. SetFieldValue(formFields, "other_passport_type_other", ""); // 旅行证件类型 - 其它
  4976. SetFieldValue(formFields, "other_passport_no", ""); // 签证 编号
  4977. SetFieldValue(formFields, "other_passport_country", ""); // 签发 国
  4978. SetFieldValue(formFields, "other_passport_expiry_date", ""); // 有效期至
  4979. #endregion
  4980. }
  4981. #endregion
  4982. #region 4. 联系信息
  4983. SetFieldValue(formFields, "contact_info_address", custInfo.Address); // 本国地址
  4984. SetFieldValue(formFields, "contact_info_current_adress", ""); // 现居住地址,如与本国地址不同填写
  4985. SetFieldValue(formFields, "contact_info_tel_or_phone", custInfo.Tel); // 电话
  4986. SetFieldValue(formFields, "contact_info_email", custInfo.Email); // 电子邮件
  4987. #region 紧急联系人
  4988. //默认没有
  4989. SetFieldValue(formFields, "contact_info_emergency_name", ""); // 姓名
  4990. SetFieldValue(formFields, "contact_info_emergency_country", ""); // 居住国家
  4991. SetFieldValue(formFields, "contact_info_emergency_tel", ""); // 电话
  4992. SetFieldValue(formFields, "contact_info_emergency_relationship", ""); // 关系
  4993. #endregion
  4994. #endregion
  4995. #region 5. 婚姻状况及家庭成员信息
  4996. //清除婚姻状况
  4997. SetFieldValue(formFields, "marital_married", ""); // 婚姻状况 - 已婚
  4998. SetFieldValue(formFields, "marital_divorced", ""); // 婚姻状况 - 离婚
  4999. SetFieldValue(formFields, "marital_single", ""); // 婚姻状况 - 单身
  5000. //设置婚姻状况
  5001. switch (custInfo.Marriage)
  5002. {
  5003. case 1: // 未婚
  5004. break;
  5005. case 2: // 已婚
  5006. SetFieldValue(formFields, "marital_married", selected);
  5007. #region 配偶信息
  5008. string mateName = custInfo?.MateName ?? "";
  5009. if (!string.IsNullOrEmpty(mateName))
  5010. {
  5011. string mateFirstName = mateName.Remove(0, 1);
  5012. SetFieldValue(formFields, "marital_personal_surname", mateName.Substring(0, 1)); // 姓
  5013. SetFieldValue(formFields, "marital_personal_name", mateFirstName); // 名
  5014. }
  5015. SetFieldValue(formFields, "marital_personal_birthday", custInfo?.MateBirthDay.ToString("yyyy-MM-dd")); // 生日
  5016. SetFieldValue(formFields, "marital_personal_nationaliy", custInfo.MateBirthCountry); // 国家
  5017. SetFieldValue(formFields, "marital_personal_nationaliy", custInfo.MateAddress); // 居住地址
  5018. SetFieldValue(formFields, "marital_personal_nationaliy", ""); // 电话
  5019. #endregion
  5020. break;
  5021. case 3: // 离婚/离异
  5022. SetFieldValue(formFields, "marriage_divorce", selected);
  5023. break;
  5024. case 4: // 离异
  5025. break;
  5026. }
  5027. //子女信息
  5028. SetFieldValue(formFields, "famliy_children_no", selected); // 否
  5029. SetFieldValue(formFields, "famliy_children_yes", ""); // 是
  5030. if (currFamilyInfos.Count > 0)
  5031. {
  5032. // 定义接受子女人数
  5033. int children = currFamilyInfos.Where(x => x.Appellation.contains("儿子") || x.Appellation.contains("女儿")).ToList().Count;
  5034. // 判断子女人数
  5035. if (children > 0)
  5036. {
  5037. SetFieldValue(formFields, "famliy_children_yes", selected);
  5038. SetFieldValue(formFields, "famliy_children_number", children.ToString()); // 子女人数
  5039. }
  5040. }
  5041. #endregion
  5042. #region 6. 学历
  5043. SetFieldValue(formFields, "education_masters_or_doctoral_degree", "");// 博士/硕士
  5044. SetFieldValue(formFields, "education_bachelors_degree", ""); // 学士
  5045. SetFieldValue(formFields, "education_hight_school_diploma", ""); // 高中
  5046. SetFieldValue(formFields, "education_other", ""); // 其他
  5047. SetFieldValue(formFields, "education_other_remark", ""); // 其他 - 备注
  5048. if (custInfo.HighestEducation.Contains("硕士") || custInfo.HighestEducation.Contains("博士"))
  5049. SetFieldValue(formFields, "education_masters_or_doctoral_degree", selected);
  5050. else if (custInfo.HighestEducation.Contains("学士"))
  5051. SetFieldValue(formFields, "education_bachelors_degree", selected);
  5052. else if (custInfo.HighestEducation.Contains("高中"))
  5053. SetFieldValue(formFields, "education_hight_school_diploma", selected);
  5054. else
  5055. {
  5056. SetFieldValue(formFields, "education_other", selected);
  5057. SetFieldValue(formFields, "education_other_remark", custInfo.HighestEducation.Trim());
  5058. }
  5059. SetFieldValue(formFields, "education_school_name", ""); // 学校名称
  5060. SetFieldValue(formFields, "education_school_address", ""); // 学校地址
  5061. #endregion
  5062. #region 7. 职业
  5063. //清除值
  5064. SetFieldValue(formFields, "employment_entreeneur", ""); // 事业家
  5065. SetFieldValue(formFields, "employment_self_employed", ""); // 自雇
  5066. SetFieldValue(formFields, "employment_employed", ""); // 公司职员
  5067. SetFieldValue(formFields, "employment_civil_servant", selected);// 公务员 默认
  5068. SetFieldValue(formFields, "employment_student", ""); // 学生
  5069. SetFieldValue(formFields, "employment_retired", ""); // 退休
  5070. SetFieldValue(formFields, "employment_unemployed", ""); // 无业
  5071. SetFieldValue(formFields, "employment_other", ""); // 其他
  5072. SetFieldValue(formFields, "employment_other_remark", ""); // 其他 - 备注
  5073. //职业信息
  5074. if (companyInfos != null && companyInfos.Count > 0)
  5075. {
  5076. SetFieldValue(formFields, "employment_name", companyInfos.FirstOrDefault()?.Company ?? ""); // 单位名称
  5077. SetFieldValue(formFields, "employment_position", companyInfos.FirstOrDefault()?.Job ?? ""); // 职业
  5078. SetFieldValue(formFields, "employment_address", companyInfos.FirstOrDefault()?.CompanyAddress ?? ""); // 地址
  5079. SetFieldValue(formFields, "employment_tel", companyInfos.FirstOrDefault()?.Phone ?? ""); // 电话
  5080. }
  5081. #endregion
  5082. #region 8. 访问信息
  5083. //入境事由
  5084. //清除值
  5085. SetFieldValue(formFields, "korea_tourism", ""); // 旅游/过境
  5086. SetFieldValue(formFields, "korea_meeting", ""); // 参加会议等活动
  5087. SetFieldValue(formFields, "korea_medical_tourism", ""); // 医疗旅游
  5088. SetFieldValue(formFields, "korea_business", ""); // 短期商务
  5089. SetFieldValue(formFields, "korea_study", ""); // 学习/培训
  5090. SetFieldValue(formFields, "korea_work", ""); // 就业活动
  5091. SetFieldValue(formFields, "korea_trade", ""); // 贸易/投资/派驻
  5092. SetFieldValue(formFields, "korea_visiting_family", ""); // 探亲访友
  5093. SetFieldValue(formFields, "marriage_migrant", ""); // 结婚移民
  5094. SetFieldValue(formFields, "korea_diplomatic", ""); // 外交/公务
  5095. SetFieldValue(formFields, "korea_other", ""); // 其他
  5096. SetFieldValue(formFields, "korea_other_details", ""); // 其他 - 备注
  5097. var visit_purpose = groupInfo.VisitPurpose;
  5098. if (!string.IsNullOrEmpty(visit_purpose))
  5099. {
  5100. if (visit_purpose.contains("旅游") || visit_purpose.contains("过境"))
  5101. {
  5102. SetFieldValue(formFields, "korea_tourism", selected); // 旅游/过境
  5103. }
  5104. else if (visit_purpose.contains("会议") || visit_purpose.contains("活动"))
  5105. {
  5106. SetFieldValue(formFields, "korea_meeting", selected); // 参加会议等活动
  5107. }
  5108. else if (visit_purpose.contains("医疗") || visit_purpose.contains("旅游"))
  5109. {
  5110. SetFieldValue(formFields, "korea_medical_tourism", selected); // 医疗旅游
  5111. }
  5112. else if (visit_purpose.contains("短期商务") || visit_purpose.contains("商务"))
  5113. {
  5114. SetFieldValue(formFields, "korea_business", selected); // 短期商务
  5115. }
  5116. else if (visit_purpose.contains("学习") || visit_purpose.contains("培训"))
  5117. {
  5118. SetFieldValue(formFields, "korea_study", selected); // 学习/培训
  5119. }
  5120. else if (visit_purpose.contains("就业活动"))
  5121. {
  5122. SetFieldValue(formFields, "korea_work", selected); // 就业活动
  5123. }
  5124. else if (visit_purpose.contains("贸易") || visit_purpose.contains("投资") || visit_purpose.contains("派驻"))
  5125. {
  5126. SetFieldValue(formFields, "korea_trade", selected); // 贸易/投资/派驻
  5127. }
  5128. else if (visit_purpose.contains("探亲访友") || visit_purpose.contains("探亲") || visit_purpose.contains("访友"))
  5129. {
  5130. SetFieldValue(formFields, "korea_visiting_family", selected); // 探亲访友
  5131. }
  5132. else if (visit_purpose.contains("结婚移民") || visit_purpose.contains("结婚") || visit_purpose.contains("移民"))
  5133. {
  5134. SetFieldValue(formFields, "marriage_migrant", selected); // 结婚移民
  5135. }
  5136. else if (visit_purpose.contains("外交") || visit_purpose.contains("公务"))
  5137. {
  5138. SetFieldValue(formFields, "korea_diplomatic", selected); // 外交/公务
  5139. }
  5140. else
  5141. {
  5142. SetFieldValue(formFields, "korea_other", selected); // 其他
  5143. SetFieldValue(formFields, "korea_other_details", visit_purpose);// 其他 - 备注
  5144. }
  5145. }
  5146. #region 滞留信息
  5147. string day1 = ""; //得到抵达日期
  5148. string day2 = ""; //得到离开日期
  5149. string country = groupInfo.VisitCountry; //国家名
  5150. string HG_City = ""; //城市
  5151. string HG_Country = "";//国家
  5152. string[] HG_countryName = new string[] { };
  5153. if (!string.IsNullOrEmpty(country))
  5154. {
  5155. //处理国家名
  5156. if (country.Contains(" "))
  5157. HG_countryName = country.Split(' ');
  5158. else if (country.Contains(","))
  5159. HG_countryName = country.Split(',');
  5160. else if (country.Contains(","))
  5161. HG_countryName = country.Split(',');
  5162. else if (country.Contains("、"))
  5163. HG_countryName = country.Split('、');
  5164. }
  5165. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  5166. int k = 0;
  5167. for (int i = 0; i < HG_countryName.Length; i++)
  5168. {
  5169. for (int j = 0; j < atbc.Rows.Count; j++)
  5170. {
  5171. string HL_Three = atbc.Rows[j]["Three"].ToString();
  5172. if (!string.IsNullOrEmpty(HL_Three))
  5173. {
  5174. var hl_three = HL_Three.Substring(3);
  5175. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == hl_three).First();
  5176. if (tc != null)
  5177. {
  5178. HG_Country = HG_countryName[i];
  5179. HG_City = tc.City; //得到当前国家 城市名
  5180. day1 = atbc.Rows[j]["Day"].ToString(); //得到抵达日期
  5181. k = j + 1;
  5182. }
  5183. }
  5184. if (k == j)
  5185. day2 = atbc.Rows[j]["Day"].ToString(); //离开航班起飞时间
  5186. }
  5187. }
  5188. if (atbc != null)
  5189. {
  5190. if (day2 != null && day1 != null)
  5191. {
  5192. try
  5193. {
  5194. int Han_day = (Convert.ToDateTime(day2) - Convert.ToDateTime(day1)).Days; //得到天数
  5195. SetFieldValue(formFields, "visit_prtiod_stay", Han_day.ToString()); // 滞留天数
  5196. }
  5197. catch (Exception) { }
  5198. }
  5199. }
  5200. //得到当前国家下的城市酒店信息
  5201. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  5202. .Where(x => x.DiId == groupId)
  5203. .Where(x => x.City.contains(HG_City))
  5204. .First();
  5205. //访问信息
  5206. if (hotelInfo != null)
  5207. {
  5208. SetFieldValue(formFields, "visit_address", hotelInfo?.HotelAddress ?? ""); // 停留酒店地址
  5209. SetFieldValue(formFields, "visit_tel", hotelInfo?.HotelTel ?? ""); // 停留酒店联系电话
  5210. }
  5211. #endregion
  5212. SetFieldValue(formFields, "visit_tel", hotelInfo?.HotelTel ?? ""); // 停留酒店联系电话
  5213. SetFieldValue(formFields, "visit_tel", hotelInfo?.HotelTel ?? ""); // 停留酒店联系电话
  5214. SetFieldValue(formFields, "visit_travelled_5year_no", ""); // 近五年到访过韩国
  5215. SetFieldValue(formFields, "visit_travelled_5year_othercountry_no", ""); // 近五年到访过除韩国之外的国家
  5216. SetFieldValue(formFields, "visit_travelled_no", ""); // 是否有其他家人滞留在韩国
  5217. SetFieldValue(formFields, "visit_travelled_travelling_no", ""); // 是否有随行家属
  5218. #endregion
  5219. #region 9. 在韩邀请方信息
  5220. SetFieldValue(formFields, "invitation_no", selected); // 是否有邀请方 - 否 默认选中
  5221. SetFieldValue(formFields, "invitation_yes", ""); // 是否有邀请方 - 是
  5222. if (!string.IsNullOrEmpty(HG_Country) && !string.IsNullOrEmpty(HG_City))
  5223. {
  5224. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  5225. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  5226. .Where(x => x.Country.Contains(HG_Country))
  5227. .Where(x => x.Area.Contains(HG_City))
  5228. .First();
  5229. //邀请 接待单位
  5230. if (oa != null)
  5231. {
  5232. SetFieldValue(formFields, "invitation_no", ""); // 是否有邀请方 - 否
  5233. SetFieldValue(formFields, "invitation_yes", selected); // 是否有邀请方 - 是
  5234. SetFieldValue(formFields, "invitation_name", oa?.Contact?.Trim() ?? "");// 邀请方 姓名
  5235. SetFieldValue(formFields, "invitation_birthday", ""); // 邀请方 生日/证件号
  5236. SetFieldValue(formFields, "invitation_relationship", "邀请方"); // 邀请方 关系
  5237. SetFieldValue(formFields, "invitation_address", oa?.Address ?? ""); // 邀请方 地址
  5238. SetFieldValue(formFields, "invitation_tel", oa?.Tel ?? ""); // 邀请方 电话
  5239. }
  5240. }
  5241. #endregion
  5242. #region 9. 费用信息
  5243. var compnayName = currCompanyInfos.FirstOrDefault(x => x.Id == custInfo.CrmCompanyId)?.Company ?? "";
  5244. SetFieldValue(formFields, "funding_costs", ""); // 费用金额
  5245. SetFieldValue(formFields, "funding_pay_name_or_unit", compnayName); // 单位名称
  5246. SetFieldValue(formFields, "funding_pay_relationship", "企业"); // 关系
  5247. SetFieldValue(formFields, "funding_pay_cost_type", "自费"); // 费用类别
  5248. SetFieldValue(formFields, "funding_pay_tel", custInfo.ClientPhone); // 电话
  5249. #endregion
  5250. #region 10. 协助填表人信息
  5251. if (string.IsNullOrEmpty(custInfo.TableOpName))
  5252. SetFieldValue(formFields, "assistance_no", selected); // 否
  5253. else
  5254. {
  5255. SetFieldValue(formFields, "assistance_yes", selected); // 是
  5256. SetFieldValue(formFields, "assistance_name", selected); // 姓名
  5257. SetFieldValue(formFields, "assistance_birthday", ""); // 生日
  5258. SetFieldValue(formFields, "assistance_tel", custInfo.TableOpTel); // 电话
  5259. SetFieldValue(formFields, "assistance_relationship", "雇佣"); // 和协助人关系
  5260. }
  5261. #endregion
  5262. var date_year = DateTime.Now.Year.ToString();
  5263. var date_month = DateTime.Now.Month.ToString();
  5264. var date_day = DateTime.Now.Day.ToString();
  5265. SetFieldValue(formFields, "declaration_year", date_year); // 申请日期 - 年
  5266. SetFieldValue(formFields, "declaration_month", date_month); // 申请日期 - 月
  5267. SetFieldValue(formFields, "declaration_day", date_day); // 申请日期 - 日
  5268. var applicant_name = custInfo.LastName + custInfo.FirstName;
  5269. SetFieldValue(formFields, "declaration_applicant_name", applicant_name); // 申请人姓名
  5270. #endregion
  5271. filePaths.Add(outputPath);
  5272. }
  5273. catch (Exception ex)
  5274. {
  5275. return Ok(JsonView(false, $"生成PDF文件时出错:{ex.Message}"));
  5276. }
  5277. finally
  5278. {
  5279. // 按正确顺序关闭资源
  5280. stamper?.Close();
  5281. reader?.Close();
  5282. templateStream?.Close();
  5283. outputStream?.Close();
  5284. }
  5285. #endregion
  5286. }
  5287. break;
  5288. case 4: // 瑞典
  5289. visaTypeName = $"瑞典签证申请表";
  5290. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  5291. var swedenSavePath = $"{fileServerPath}{visaTypeName}/";
  5292. if (!Directory.Exists(swedenSavePath)) Directory.CreateDirectory(swedenSavePath);
  5293. if (!System.IO.File.Exists(currTempPath))
  5294. {
  5295. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  5296. }
  5297. foreach (var custInfo in groupCustInfos)
  5298. {
  5299. EncryptionProcessor.DecryptProperties(custInfo);
  5300. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  5301. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  5302. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  5303. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  5304. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  5305. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  5306. #region 生成文件
  5307. PdfReader reader = null;
  5308. FileStream templateStream = null;
  5309. FileStream outputStream = null;
  5310. PdfStamper stamper = null;
  5311. try
  5312. {
  5313. string outputPath = $"{swedenSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  5314. //读取模板文件
  5315. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  5316. reader = new PdfReader(templateStream);
  5317. //创建输出文件
  5318. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  5319. stamper = new PdfStamper(reader, outputStream);
  5320. AcroFields formFields = stamper.AcroFields;
  5321. #region 设置文本值
  5322. SetFieldValue(formFields, "LastName", custInfo.LastName); //姓
  5323. SetFieldValue(formFields, "BirthLastName", custInfo.LastName); // 出生时姓氏
  5324. SetFieldValue(formFields, "FirstName", custInfo.FirstName); // 名
  5325. // 出生日期(日-月-年)
  5326. string idCard = idInfo.CertNo;
  5327. string birthday = string.Empty;
  5328. if (!string.IsNullOrEmpty(idCard))
  5329. {
  5330. string year = idCard.Substring(6, 4);
  5331. string month = idCard.Substring(10, 2);
  5332. string day = idCard.Substring(12, 2);
  5333. birthday = day + "-" + month + "-" + year;
  5334. }
  5335. SetFieldValue(formFields, "Birthday", birthday);
  5336. string currentNationality = custInfo.BirthProvince + custInfo.BirthCity;
  5337. SetFieldValue(formFields, "CurrentNationality", currentNationality); // 出生地
  5338. SetFieldValue(formFields, "CountryBirth", "中国"); // 出生国
  5339. SetFieldValue(formFields, "CurrentNationalityCountry", "中国"); // 现国籍
  5340. SetFieldValue(formFields, "NationalityBirth", ""); // 出生时国籍,如与现国籍不同
  5341. SetFieldValue(formFields, "OtherNationalities", ""); // 其他国籍
  5342. #region 性别处理
  5343. //清除性别
  5344. SetFieldValue(formFields, "Male", "Off"); // 性别 - 男
  5345. SetFieldValue(formFields, "Female", "Off"); // 性别 - 女
  5346. //设置性别
  5347. if (custInfo.Sex == 0) //男
  5348. {
  5349. SetFieldValue(formFields, "Male", "Yes"); // 性别 - 男
  5350. }
  5351. else if (custInfo.Sex == 1) //女
  5352. {
  5353. SetFieldValue(formFields, "Female", "Yes"); // 性别 - 女
  5354. }
  5355. #endregion
  5356. #region 婚姻状况处理
  5357. //清除婚姻状况
  5358. SetFieldValue(formFields, "Single", "Off"); // 婚姻状况 - 未婚
  5359. SetFieldValue(formFields, "Married", "Off"); // 婚姻状况 - 已婚
  5360. SetFieldValue(formFields, "RegisteredPartnership", "Off"); // 婚姻状况 - 注册伴侣关系
  5361. SetFieldValue(formFields, "Separated", "Off"); // 婚姻状况 - 分居
  5362. SetFieldValue(formFields, "Divorced", "Off"); // 婚姻状况 - 离婚
  5363. SetFieldValue(formFields, "Widow(er)", "Off"); // 婚姻状况 - 丧偶
  5364. SetFieldValue(formFields, "OtherCivilStatus", "Off"); // 婚姻状况 - 其它
  5365. SetFieldValue(formFields, "CivilStatusOther", ""); // 婚姻状况 - 其它(请注明)
  5366. //设置婚姻状况
  5367. switch (custInfo.Marriage)
  5368. {
  5369. case 1: // 未婚
  5370. SetFieldValue(formFields, "Single", "Yes");
  5371. break;
  5372. case 2: // 已婚
  5373. SetFieldValue(formFields, "Married", "Yes");
  5374. break;
  5375. case 3: // 离异
  5376. SetFieldValue(formFields, "Divorced", "Yes");
  5377. break;
  5378. case 4: // 离异
  5379. SetFieldValue(formFields, "Widow(er)", "Yes");
  5380. break;
  5381. }
  5382. #endregion
  5383. //亲权人(如是未成年申请人 )/合法监护人(姓名、住址,如与申请人不同) 电话号码、电子邮件及国籍
  5384. SetFieldValue(formFields, "ParentalAuthority", "");
  5385. SetFieldValue(formFields, "NationalIdentityNumber", idCard); //公民身份证号码
  5386. #region 护照(旅行证件类型)处理
  5387. //清除值
  5388. SetFieldValue(formFields, "OrdinaryPassport", "Off"); //旅行证件类型 - 普通护照
  5389. SetFieldValue(formFields, "DiplomaticPassport", "Off"); //旅行证件类型 - 外交护照
  5390. SetFieldValue(formFields, "ServicePassport", "Off"); //旅行证件类型 - 公务护照
  5391. SetFieldValue(formFields, "OfficialPassport", "Off"); //旅行证件类型 - 因公护照
  5392. SetFieldValue(formFields, "SpecialPassport", "Off"); //旅行证件类型 - 特殊护照
  5393. SetFieldValue(formFields, "OtherTravel", "Off"); //旅行证件类型 - 其它旅行证件
  5394. SetFieldValue(formFields, "OtherTravelDesc", ""); //旅行证件类型 - 其它旅行证件(请注明)
  5395. //设置值
  5396. SetFieldValue(formFields, "OrdinaryPassport", "Yes"); //旅行证件类型 - 普通护照
  5397. if (passportInfo != null)
  5398. {
  5399. SetFieldValue(formFields, "TravelNumber", passportInfo.CertNo); //旅行证件编号
  5400. SetFieldValue(formFields, "IssueDate", passportInfo.IssueDt?.ToString("yyyy-MM-dd") ?? ""); //签发日期
  5401. SetFieldValue(formFields, "ValidUntil", passportInfo.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); //有效期至
  5402. SetFieldValue(formFields, "IssuedCountry", passportInfo.Country); //签发(国)
  5403. }
  5404. #endregion
  5405. //如有家庭成员为欧盟、欧洲经济区、瑞士或受益于退欧协议的英国公民的,请填写该家庭成员的个人信息
  5406. SetFieldValue(formFields, "LastName_om", ""); //姓
  5407. SetFieldValue(formFields, "FirstName_om", ""); //名
  5408. SetFieldValue(formFields, "BirthDate_om", ""); //出生日期(日-月-年)
  5409. SetFieldValue(formFields, "Nationality_om", ""); //国籍
  5410. SetFieldValue(formFields, "TravelNuber_om", ""); //旅行证件或身分证编号
  5411. //申请人与欧盟、欧洲经济区、瑞士或受益于退欧协议的英国公民的关系
  5412. SetFieldValue(formFields, "Spouse_om", ""); //配偶
  5413. SetFieldValue(formFields, "RegisteredPartnership_om", ""); //注册伴侣
  5414. SetFieldValue(formFields, "Child_om", ""); //子女
  5415. SetFieldValue(formFields, "DependentAscendant_om", ""); //受养人
  5416. SetFieldValue(formFields, "Grandchild_om", ""); //孙子女
  5417. SetFieldValue(formFields, "FamilyOther_om", ""); //其他
  5418. SetFieldValue(formFields, "FamilyOtherDesc_om", ""); //其他(说明)
  5419. //申请人住址及电子邮件
  5420. string applicantHomeAddress = $"{custInfo.Address} {custInfo.Email}";
  5421. SetFieldValue(formFields, "ApplicantHomeAddress", applicantHomeAddress); //申请人住址及电子邮件
  5422. SetFieldValue(formFields, "TelephoneNo", custInfo.Tel); //电话号码
  5423. //是否居住在现时国籍以外的国家
  5424. SetFieldValue(formFields, "AnotherCountryNo", "Yes"); //否
  5425. SetFieldValue(formFields, "AnotherCountryYes", ""); //是。
  5426. SetFieldValue(formFields, "ResidencePermit", ""); //居住许可或同等证
  5427. SetFieldValue(formFields, "Number", ""); //编号
  5428. SetFieldValue(formFields, "ValidUntils", ""); //有效期至
  5429. SetFieldValue(formFields, "CurrentOccupation", custInfo.Job); //当前职业
  5430. //工作单位名称,地址和电话,学生填写学校名称及地址
  5431. var currCompanyInfo = currCompanyInfos.FirstOrDefault();
  5432. string employerInfoStr = $"{currCompanyInfo?.Company ?? ""} {currCompanyInfo?.CompanyAddress ?? ""} {currCompanyInfo?.Phone ?? ""}";
  5433. SetFieldValue(formFields, "EmployerInfo", employerInfoStr);
  5434. #region 旅行的目的
  5435. //清空值
  5436. SetFieldValue(formFields, "Tourism", "Off"); //旅游
  5437. SetFieldValue(formFields, "Business", "Off"); //商务
  5438. SetFieldValue(formFields, "VisitingFamily", "Off"); //探亲访友
  5439. SetFieldValue(formFields, "Cultural", "Off"); //文化
  5440. SetFieldValue(formFields, "Sports", "Off"); //体育
  5441. SetFieldValue(formFields, "OfficialVisit", "Off"); //官方访问
  5442. SetFieldValue(formFields, "MedicalReasons", "Off"); //医疗
  5443. SetFieldValue(formFields, "Study", "Off"); //学习
  5444. SetFieldValue(formFields, "AirportTransit", "Off"); //机场过境
  5445. SetFieldValue(formFields, "Other", "Off"); //其它
  5446. SetFieldValue(formFields, "OtherDesc", ""); //其它 (请注明)
  5447. //设置值
  5448. if (groupInfo.VisitPurpose.contains("旅游")) SetFieldValue(formFields, "Tourism", "Yes"); //旅游
  5449. if (groupInfo.VisitPurpose.contains("商务")) SetFieldValue(formFields, "Business", "Yes"); //商务
  5450. if (groupInfo.VisitPurpose.contains("探亲访友")) SetFieldValue(formFields, "VisitingFamily", "Yes"); //探亲访友
  5451. if (groupInfo.VisitPurpose.contains("文化")) SetFieldValue(formFields, "Cultural", "Yes"); //文化
  5452. if (groupInfo.VisitPurpose.contains("体育")) SetFieldValue(formFields, "Sports", "Yes"); //体育
  5453. if (groupInfo.VisitPurpose.contains("官方访问")) SetFieldValue(formFields, "OfficialVisit", "Yes"); //官方访问
  5454. if (groupInfo.VisitPurpose.contains("医疗")) SetFieldValue(formFields, "MedicalReasons", "Yes"); //医疗
  5455. if (groupInfo.VisitPurpose.contains("学习")) SetFieldValue(formFields, "Study", "Yes"); //学习
  5456. if (groupInfo.VisitPurpose.contains("机场过境")) SetFieldValue(formFields, "AirportTransit", "Yes"); //机场过境
  5457. #endregion
  5458. SetFieldValue(formFields, "AdditionalInfo", ""); //有关停留原因的补充信息
  5459. string[] RD_country = new string[] { }; //接收处理的国家
  5460. string firstEntryLabel = string.Empty; //首入申根国标签
  5461. string membeDescLabel = string.Empty; //申根国目的地
  5462. string stopDays = string.Empty; //停留天数
  5463. if (!string.IsNullOrEmpty(groupInfo.VisitCountry))
  5464. {
  5465. List<string> SGGNames = new List<string>();//接收处理后的国家 是申根国
  5466. if (groupInfo.VisitCountry.Contains(","))
  5467. RD_country = groupInfo.VisitCountry.Split(',');
  5468. else if (groupInfo.VisitCountry.Contains(' '))
  5469. RD_country = groupInfo.VisitCountry.Split(' ');
  5470. else if (groupInfo.VisitCountry.Contains(","))
  5471. RD_country = groupInfo.VisitCountry.Split(',');
  5472. else if (groupInfo.VisitCountry.Contains("、"))
  5473. RD_country = groupInfo.VisitCountry.Split('、');
  5474. else if (groupInfo.VisitCountry.Contains("|"))
  5475. RD_country = groupInfo.VisitCountry.Split('|');
  5476. //判断是否是申根国家
  5477. for (int i = 0; i < RD_country.Length; i++)
  5478. {
  5479. if (RD_country[i].ToString() != null)
  5480. {
  5481. //在申根国家中筛选 该国家是否是申根国家
  5482. for (int j = 0; j < _shenGenGuos.Length; j++)
  5483. {
  5484. if (RD_country[i] == _shenGenGuos[j])
  5485. SGGNames.Add(_shenGenGuos[j]); //添加申根国
  5486. }
  5487. }
  5488. }
  5489. //目的地国是否有申根国
  5490. if (SGGNames.Count > 0)
  5491. {
  5492. firstEntryLabel = SGGNames.First();
  5493. membeDescLabel = string.Join(",", SGGNames.ToArray());
  5494. //接收生根国详细信息 存储顺序 起飞日期:Day 起飞时刻:StartTime 抵达日期:ArrivedDate 到达时刻:EndTime
  5495. List<SSGDetails> ListSSGDetails = new List<SSGDetails>();
  5496. //处理申根国家 预定到达时间 预定离开时间 预定停留天数
  5497. for (int i = 0; i < SGGNames.Count; i++)
  5498. {
  5499. //在相同的国家下 得到该航班的信息 //抵达时间 起飞日期:Day 起飞时刻:StartTime 到达时刻:EndTime 抵达日期:ArrivedDate 飞行时间:FlightTime 航司 Fliagtcode 入境口岸
  5500. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  5501. //ResidenceTime1 机票三字码信息
  5502. if (atbc != null)
  5503. {
  5504. string HL_Three = ""; //三字码 Three
  5505. for (int j = 0; j < atbc.Rows.Count; j++)
  5506. {
  5507. HL_Three = atbc.Rows[j]["Three"].ToString();
  5508. if (!string.IsNullOrEmpty(HL_Three))
  5509. {
  5510. string threeCodeTwo = HL_Three.Substring(3);
  5511. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  5512. if (tc != null)
  5513. {
  5514. //首入申根国时间
  5515. if (SGGNames[i] == tc.Country)
  5516. {
  5517. SSGDetails SSGDetails = new SSGDetails()
  5518. {
  5519. Three = atbc.Rows[j]["Three"].ToString(), //三字码
  5520. Fliagtcode = atbc.Rows[j]["Fliagtcode"].ToString(), //航司
  5521. startDate = atbc.Rows[j]["Day"].ToString(), //整理起飞日期
  5522. startTime = atbc.Rows[j]["StartTime"].ToString(), //整理起飞时刻
  5523. endDate = atbc.Rows[j]["ArrivedDate"].ToString(), //整理抵达日期
  5524. endTime = atbc.Rows[j]["EndTime"].ToString() //整理抵达时刻
  5525. };
  5526. ListSSGDetails.Add(SSGDetails);
  5527. }
  5528. }
  5529. }
  5530. }
  5531. }
  5532. }
  5533. ListSSGDetails.Sort((a, b) => a.startDate.CompareTo(b.startDate));
  5534. //得到并计算出入境时间
  5535. if (ListSSGDetails != null)
  5536. {
  5537. string RuJingTime = ListSSGDetails.First().endDate + " " + ListSSGDetails.First().endTime.Substring(0, 2) + ":" + ListSSGDetails.First().endTime.Substring(2); //入境时间
  5538. string LiJingTime = ListSSGDetails[ListSSGDetails.Count - 1].startDate + " " + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(0, 2) + ":" + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(2); //离境时间
  5539. stopDays = Convert.ToDateTime(LiJingTime).Subtract(Convert.ToDateTime(RuJingTime)).Days.ToString();
  5540. }
  5541. }
  5542. }
  5543. SetFieldValue(formFields, "MembeDesc", membeDescLabel); //主要申根目的地 (以及其他申根目的地,如适用)
  5544. SetFieldValue(formFields, "FirstEntry", firstEntryLabel); //首入申根国
  5545. //申请入境次数
  5546. SetFieldValue(formFields, "27.SingleEntry", ""); //单次
  5547. SetFieldValue(formFields, "27.TwoEntries", ""); //两次
  5548. SetFieldValue(formFields, "27.MultipleEntries", ""); //多次
  5549. SetFieldValue(formFields, "27.IntendedDateIn", ""); //在申根地区预计首次停留的预计抵达日期
  5550. SetFieldValue(formFields, "27.IntendedDateOut", ""); //在申根地区预计首次停留之后的预计离开日期
  5551. //以往申根国签证是否有指纹记录
  5552. SetFieldValue(formFields, "28.No", ""); //否
  5553. SetFieldValue(formFields, "28.Yes", ""); //是
  5554. SetFieldValue(formFields, "28.KnownDate", ""); //如有,请写明日期
  5555. SetFieldValue(formFields, "28.KnownVisanumber", ""); //如有,请写明签证贴纸号码
  5556. //最后目的地之入境许可
  5557. SetFieldValue(formFields, "29.Issued", ""); //签发机关
  5558. SetFieldValue(formFields, "29.ValidFrom", ""); //有效期由
  5559. SetFieldValue(formFields, "29.Until", ""); //至
  5560. //申根国的邀请人姓名。如无邀请人,请填写申根国的酒店或暂住居所名称
  5561. //得到当前国家下的城市酒店信息
  5562. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  5563. .Where(x => x.DiId == groupId)
  5564. //.Where(x => x.City.contains(city))
  5565. .First();
  5566. //酒店住址
  5567. if (hotelInfo != null)
  5568. {
  5569. SetFieldValue(formFields, "30.SurnameFirstName", hotelInfo?.HotelName ?? ""); //申根国的酒店
  5570. var otherInfo = $"{hotelInfo.HotelAddress}";
  5571. SetFieldValue(formFields, "30.HotelInfo", otherInfo); //邀请人/酒店/暂住居所的地址及电子邮件
  5572. SetFieldValue(formFields, "30.TelephoneNo", hotelInfo?.HotelTel ?? ""); //电话号码
  5573. }
  5574. //邀请公司或机构的名称及地址
  5575. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  5576. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  5577. //.Where(x => x.Country.Contains(county))
  5578. //.Where(x => x.Area.Contains(city))
  5579. .First();
  5580. if (oa != null)
  5581. {
  5582. //申根国的邀请人姓名。如无邀请人,请填写申根国的酒店或暂住居所名称
  5583. SetFieldValue(formFields, "30.SurnameFirstName", oa?.Contact ?? ""); //申根国的酒店
  5584. SetFieldValue(formFields, "30.HotelInfo", oa?.Address ?? ""); //邀请人/酒店/暂住居所的地址及电子邮件
  5585. SetFieldValue(formFields, "30.TelephoneNo", oa?.Tel ?? ""); //电话号码
  5586. string nameAddressLabel = $"{oa.Client} {oa.Address}";
  5587. SetFieldValue(formFields, "31.NameAddress", nameAddressLabel); //邀请公司或机构的名称及地址
  5588. string surnameLabel = $"{oa.Contact} {oa.Tel}";
  5589. SetFieldValue(formFields, "31.Surname", surnameLabel); //邀请公司或机构的联系人姓名、地址、电话号码及电子邮件
  5590. SetFieldValue(formFields, "31.TelephoneNo", oa?.Tel ?? ""); //邀请公司或机构的电话
  5591. }
  5592. //申请人的旅费以及在国外停留期间的生活费用
  5593. SetFieldValue(formFields, "32.Applicant", ""); //由申请人支付
  5594. SetFieldValue(formFields, "32.Cash", ""); //支付方式 - 现金
  5595. SetFieldValue(formFields, "32.Traveller", ""); //支付方式 - 旅行支票
  5596. SetFieldValue(formFields, "32.CreditCard", ""); //支付方式 - 信用卡
  5597. SetFieldValue(formFields, "32.Prepaid", ""); //支付方式 - 预缴住宿
  5598. SetFieldValue(formFields, "32.Prepaid1", ""); //支付方式 - 预缴交通
  5599. SetFieldValue(formFields, "32.OtherMeans", ""); //支付方式 - 其它
  5600. SetFieldValue(formFields, "32.OtherMeansDesc", ""); //支付方式 - 其它(请注明)
  5601. SetFieldValue(formFields, "32.Sponsor", ""); //由赞助方(邀请人、公司或机构)支付,请注明
  5602. SetFieldValue(formFields, "32.Referred", ""); //参见第 30 及 31 项
  5603. SetFieldValue(formFields, "32.ReferredDesc", ""); //参见第 30 及 31 项(请注明)
  5604. SetFieldValue(formFields, "32.OtherSponsor", ""); //其它
  5605. SetFieldValue(formFields, "32.OtherSponsorDesc", ""); //其它(请注明)
  5606. SetFieldValue(formFields, "32.SponsorCash", ""); //赞助方式 - 现金
  5607. SetFieldValue(formFields, "32.SponsorAccommodation", ""); //赞助方式 - 提供住宿
  5608. SetFieldValue(formFields, "32.SponsorExpenses", ""); //赞助方式 - 支付旅程期间所有开支
  5609. SetFieldValue(formFields, "32.SponsorPrepaid", ""); //赞助方式 - 预缴交通
  5610. SetFieldValue(formFields, "32.ponsorOther", ""); //赞助方式 - 其它
  5611. SetFieldValue(formFields, "32.ponsorOtherDesc", ""); //赞助方式 - 其它(请注明)
  5612. SetFieldValue(formFields, "33.PlaceAndDate", DateTime.Now.ToString("yyyy-MM-dd")); //地点及日期
  5613. #endregion
  5614. filePaths.Add(outputPath);
  5615. //return outputPath;
  5616. }
  5617. catch (Exception ex)
  5618. {
  5619. return Ok(JsonView(false, $"生成PDF文件时出错:{ex.Message}"));
  5620. }
  5621. finally
  5622. {
  5623. // 按正确顺序关闭资源
  5624. stamper?.Close();
  5625. reader?.Close();
  5626. templateStream?.Close();
  5627. outputStream?.Close();
  5628. }
  5629. #endregion
  5630. }
  5631. break;
  5632. case 5: // 波兰
  5633. visaTypeName = $"波兰签证申请表";
  5634. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  5635. var polandSavePath = $"{fileServerPath}{visaTypeName}/";
  5636. if (!Directory.Exists(polandSavePath)) Directory.CreateDirectory(polandSavePath);
  5637. if (!System.IO.File.Exists(currTempPath))
  5638. {
  5639. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  5640. }
  5641. foreach (var custInfo in groupCustInfos)
  5642. {
  5643. EncryptionProcessor.DecryptProperties(custInfo);
  5644. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  5645. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  5646. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  5647. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  5648. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  5649. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  5650. #region 生成文件
  5651. PdfReader reader = null;
  5652. FileStream templateStream = null;
  5653. FileStream outputStream = null;
  5654. PdfStamper stamper = null;
  5655. try
  5656. {
  5657. string outputPath = $"{polandSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  5658. //读取模板文件
  5659. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  5660. reader = new PdfReader(templateStream);
  5661. //创建输出文件
  5662. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  5663. stamper = new PdfStamper(reader, outputStream);
  5664. AcroFields formFields = stamper.AcroFields;
  5665. #region 设置文本值
  5666. SetFieldValue(formFields, "surname", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? ""); // 姓 英文
  5667. SetFieldValue(formFields, "surname_birth", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? ""); // 出生时姓 英文
  5668. SetFieldValue(formFields, "first_name", CommonFun.ConvertToPinyin(custInfo?.FirstName?.Trim() ?? "")?.ToLower() ?? ""); // 名 英文
  5669. #region 出生日期(日-月-年)
  5670. string idCard = idInfo?.CertNo?.Trim() ?? "";
  5671. string birthday = string.Empty;
  5672. if (!string.IsNullOrEmpty(idCard))
  5673. {
  5674. string year = idCard.Substring(6, 4);
  5675. string month = idCard.Substring(10, 2);
  5676. string day = idCard.Substring(12, 2);
  5677. birthday = day + "-" + month + "-" + year;
  5678. }
  5679. SetFieldValue(formFields, "birthday", birthday);
  5680. #endregion
  5681. var area = custInfo.BirthProvince + custInfo.BirthCity;
  5682. SetFieldValue(formFields, "birth_place", area); // 出生地区
  5683. SetFieldValue(formFields, "birth_country", "中国"); // 出生国籍
  5684. SetFieldValue(formFields, "current_nationality", "中国"); // 现国籍
  5685. SetFieldValue(formFields, "birth_nationality", "中国"); // 出生国
  5686. SetFieldValue(formFields, "other_nationality", ""); // 其他国籍
  5687. #region 设置性别
  5688. //清除性别
  5689. SetFieldValue(formFields, "sex_male", "Off"); // 性别 - 男
  5690. SetFieldValue(formFields, "sex_female", "Off"); // 性别 - 女
  5691. SetFieldValue(formFields, "sex_other", "Off"); // 性别 - 其他
  5692. //设置性别
  5693. if (custInfo.Sex == 0) // 男
  5694. {
  5695. SetFieldValue(formFields, "sex_male", "Yes"); // 性别 - 男
  5696. }
  5697. else if (custInfo.Sex == 1) // 女
  5698. {
  5699. SetFieldValue(formFields, "sex_female", "Yes"); // 性别 - 女
  5700. }
  5701. else // 其他
  5702. {
  5703. SetFieldValue(formFields, "sex_other", "Yes"); // 性别 - 其他
  5704. }
  5705. #endregion
  5706. #region 婚姻状态
  5707. //清除婚姻状况
  5708. SetFieldValue(formFields, "civil_single", "Off"); // 婚姻状况 - 未婚
  5709. SetFieldValue(formFields, "civil_married", "Off"); // 婚姻状况 - 已婚
  5710. SetFieldValue(formFields, "civil_registerered_partnership", "Off");// 婚姻状况 - 注册伴侣关系
  5711. SetFieldValue(formFields, "civil_separated", "Off"); // 婚姻状况 - 分居
  5712. SetFieldValue(formFields, "civil_divorced", "Off"); // 婚姻状况 - 离异
  5713. SetFieldValue(formFields, "civil_windower", "Off"); // 婚姻状况 - 妻子(丈夫)去世
  5714. SetFieldValue(formFields, "civil_other", "Off"); // 婚姻状况 - 其他
  5715. SetFieldValue(formFields, "civil_other_details", ""); // 婚姻状况 - 其他(请具体说明)
  5716. //设置婚姻状况
  5717. switch (custInfo.Marriage)
  5718. {
  5719. case 1: // 未婚
  5720. break;
  5721. case 2: // 已婚
  5722. SetFieldValue(formFields, "civil_married", "Yes");
  5723. break;
  5724. case 3: // 离婚/离异
  5725. SetFieldValue(formFields, "civil_divorced", "Yes");
  5726. break;
  5727. case 4:
  5728. break;
  5729. }
  5730. #endregion
  5731. // 父母的监护权(针对未成年人)/法定监护人(姓氏、名字、地址(若与申请人的地址不同)、电话号码、电子邮箱地址以及国籍)
  5732. SetFieldValue(formFields, "parental_authority", "");
  5733. //(如适用)国民身份号码
  5734. SetFieldValue(formFields, "id_number", idCard);
  5735. #region 护照信息
  5736. //清除值
  5737. SetFieldValue(formFields, "travel_type_ordinary_passport", "Off"); // 旅行证件类型 - 普通护照
  5738. SetFieldValue(formFields, "travel_type_diplomatic_passport", "Off"); // 旅行证件类型 - 外交护照
  5739. SetFieldValue(formFields, "travel_type_service_passport", "Off"); // 旅行证件类型 - 服务护照
  5740. SetFieldValue(formFields, "travel_type_offical_passport", "Off"); // 旅行证件类型 - 公务护照
  5741. SetFieldValue(formFields, "travel_type_special_passport", "Off"); // 旅行证件类型 - 特别护照
  5742. SetFieldValue(formFields, "travel_type_other_passport_details", ""); // 其他旅行证件(请注明)
  5743. //设置值
  5744. if (passportInfo != null)
  5745. {
  5746. // 签证类型
  5747. var visatypeInfo = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == passportInfo.PassportType);
  5748. if (visatypeInfo != null)
  5749. {
  5750. string visaName = visatypeInfo?.Name ?? "-";
  5751. if (visaName.contains("普通")) SetFieldValue(formFields, "travel_type_ordinary_passport", "Yes"); // 旅行证件类型 - 普通护照
  5752. else if (visaName.contains("外交")) SetFieldValue(formFields, "travel_type_diplomatic_passport", "Yes"); // 旅行证件类型 - 外交护照
  5753. else if (visaName.contains("服务")) SetFieldValue(formFields, "travel_type_service_passport", "Yes"); // 旅行证件类型 - 服务护照
  5754. else if (visaName.contains("公务")) SetFieldValue(formFields, "travel_type_offical_passport", "Yes"); // 旅行证件类型 - 公务护照
  5755. else // 旅行证件类型 - 特别护照
  5756. {
  5757. SetFieldValue(formFields, "travel_type_other_passport", "Yes");
  5758. SetFieldValue(formFields, "travel_type_other_passport_details", "");
  5759. }
  5760. }
  5761. #region 护照信息
  5762. SetFieldValue(formFields, "travel_number", passportInfo.CertNo); // 签证 编号
  5763. SetFieldValue(formFields, "travel_issue_country", passportInfo.Country); // 签发 国
  5764. SetFieldValue(formFields, "travel_issue_date", passportInfo.IssueDt?.ToString("yyyy-MM-dd") ?? ""); // 签发日期
  5765. SetFieldValue(formFields, "travel_issue_vaild", passportInfo.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); // 有效期至
  5766. #endregion
  5767. }
  5768. #endregion
  5769. #region 适用情况下,欧盟、欧洲经济区或瑞士公民,或英国籍且为《欧盟-英国脱欧协议》受益人的家庭成员的个人资料 “默认空”
  5770. SetFieldValue(formFields, "eu_info_surname", ""); // 姓氏(家族名)
  5771. SetFieldValue(formFields, "eu_info_first_name", ""); // 名字(名字)
  5772. SetFieldValue(formFields, "eu_info_birthday", ""); // 出生日期 (日-月-年)
  5773. SetFieldValue(formFields, "eu_info_nationality", ""); // 国籍
  5774. SetFieldValue(formFields, "eu_info_id_number", ""); // 旅行证件或身份证号码
  5775. #region 与欧盟、欧洲经济区或瑞士公民,或作为《欧盟-英国脱欧协议》受益人的英国国民之间的家庭关系(如适用)
  5776. SetFieldValue(formFields, "eu_family_relationship_spouse", "Off"); // 夫妻
  5777. SetFieldValue(formFields, "eu_family_relationship_child", "Off"); // 子女
  5778. SetFieldValue(formFields, "eu_family_relationship_grandchild", "Off"); // 孙子女
  5779. SetFieldValue(formFields, "eu_family_relationship_ascendant", "Off"); // 有赡养关系的长辈
  5780. SetFieldValue(formFields, "eu_family_relationship_registered", "Off"); // 注册伴侣关系
  5781. #endregion
  5782. #endregion
  5783. // 申请人的家庭住址和电子邮箱地址
  5784. string applicantAddressAndEmail = $"{custInfo.Address} {custInfo.Email}";
  5785. SetFieldValue(formFields, "applicant_address_and_email", applicantAddressAndEmail);
  5786. // 申请人的电话
  5787. SetFieldValue(formFields, "applicant_tel", custInfo.Tel);
  5788. #region 在非当前国籍所属国家的居住情况 “默认空”
  5789. SetFieldValue(formFields, "uncurrent_count_no", "Yes"); // 否
  5790. SetFieldValue(formFields, "uncurrent_count_yes", "Off"); // 是
  5791. SetFieldValue(formFields, "uncurrent_country_residence", "");// 居留许可或同等证明
  5792. SetFieldValue(formFields, "uncurrent_country_no", ""); // No
  5793. SetFieldValue(formFields, "uncurrent_country_valid_until", "");// 有效期至
  5794. #endregion
  5795. #region 职业
  5796. //职业信息
  5797. if (companyInfos != null && companyInfos.Count > 0)
  5798. {
  5799. // 当前职业
  5800. SetFieldValue(formFields, "current_occupation", companyInfos.FirstOrDefault()?.Job ?? "");
  5801. //雇主及雇主的地址和电话号码。对于学生而言,应填写教育机构的名称及地址
  5802. string employerInfo = $"{companyInfos.FirstOrDefault()?.CompanyAddress ?? ""} {companyInfos.FirstOrDefault()?.Phone ?? ""}";
  5803. }
  5804. #endregion
  5805. #region 此次行程的目的
  5806. //清除值
  5807. SetFieldValue(formFields, "purpose_tourism", "Off"); // 旅游
  5808. SetFieldValue(formFields, "purpose_business", "Off"); // 商务
  5809. SetFieldValue(formFields, "purpose_visiting_family_friends", "Off");// 庆祝亲友团聚
  5810. SetFieldValue(formFields, "purpose_cultural", "Off"); // 文化交流
  5811. SetFieldValue(formFields, "purpose_sports", "Off"); // 体育活动
  5812. SetFieldValue(formFields, "purpose_offcial_visit", "Off"); // 官方访问
  5813. SetFieldValue(formFields, "purpose_medical_reasons", "Off"); // 医疗原因
  5814. SetFieldValue(formFields, "purpose_study", "Off"); // 学习
  5815. SetFieldValue(formFields, "purpose_airport_transit", "Off"); // 机场中转
  5816. SetFieldValue(formFields, "purpose_other", "Off"); // 其他
  5817. SetFieldValue(formFields, "purpose_other_remark", ""); // 其他 - 备注
  5818. var visit_purpose = groupInfo.VisitPurpose;
  5819. if (!string.IsNullOrEmpty(visit_purpose))
  5820. {
  5821. if (visit_purpose.contains("旅游"))
  5822. {
  5823. SetFieldValue(formFields, "purpose_tourism", "Yes"); // 旅游
  5824. }
  5825. else if (visit_purpose.contains("商务"))
  5826. {
  5827. SetFieldValue(formFields, "purpose_business", "Yes"); // 商务
  5828. }
  5829. else if (visit_purpose.contains("亲友"))
  5830. {
  5831. SetFieldValue(formFields, "purpose_visiting_family_friends", "Yes");// 庆祝亲友团聚
  5832. }
  5833. else if (visit_purpose.contains("文化交流") || visit_purpose.contains("旅游"))
  5834. {
  5835. SetFieldValue(formFields, "purpose_cultural", "Yes"); // 文化交流
  5836. }
  5837. else if (visit_purpose.contains("体育") || visit_purpose.contains("活动"))
  5838. {
  5839. SetFieldValue(formFields, "purpose_sports", "Yes"); // 体育活动
  5840. }
  5841. else if (visit_purpose.contains("官方访问"))
  5842. {
  5843. SetFieldValue(formFields, "purpose_offcial_visit", "Yes"); // 官方访问
  5844. }
  5845. else if (visit_purpose.contains("医疗原因") || visit_purpose.contains("医疗"))
  5846. {
  5847. SetFieldValue(formFields, "purpose_medical_reasons", "Yes"); // 医疗原因
  5848. }
  5849. else if (visit_purpose.contains("学习"))
  5850. {
  5851. SetFieldValue(formFields, "purpose_study", "Yes"); // 学习
  5852. }
  5853. else if (visit_purpose.contains("机场中转"))
  5854. {
  5855. SetFieldValue(formFields, "purpose_airport_transit", "Yes"); // 机场中转
  5856. }
  5857. else
  5858. {
  5859. SetFieldValue(formFields, "purpose_other", "Yes"); // 其他
  5860. SetFieldValue(formFields, "purpose_other_remark", ""); // 其他 - 备注
  5861. }
  5862. }
  5863. #endregion
  5864. #region 目的国相关信息
  5865. //关于停留目的的补充说明
  5866. SetFieldValue(formFields, "purpose_stay_info", "");
  5867. string[] RD_country = new string[] { }; //接收处理的国家
  5868. string firstEntryLabel = string.Empty; // 首入申根国标签
  5869. string membeDescLabel = string.Empty; // 申根国目的地
  5870. string RuJingTime = string.Empty; // 入境时间
  5871. string LiJingTime = string.Empty; // 离境时间
  5872. string stopDays = string.Empty; // 停留天数
  5873. if (!string.IsNullOrEmpty(groupInfo.VisitCountry))
  5874. {
  5875. List<string> SGGNames = new List<string>();//接收处理后的国家 是申根国
  5876. if (groupInfo.VisitCountry.Contains(","))
  5877. RD_country = groupInfo.VisitCountry.Split(',');
  5878. else if (groupInfo.VisitCountry.Contains(' '))
  5879. RD_country = groupInfo.VisitCountry.Split(' ');
  5880. else if (groupInfo.VisitCountry.Contains(","))
  5881. RD_country = groupInfo.VisitCountry.Split(',');
  5882. else if (groupInfo.VisitCountry.Contains("、"))
  5883. RD_country = groupInfo.VisitCountry.Split('、');
  5884. else if (groupInfo.VisitCountry.Contains("|"))
  5885. RD_country = groupInfo.VisitCountry.Split('|');
  5886. //判断是否是申根国家
  5887. for (int i = 0; i < RD_country.Length; i++)
  5888. {
  5889. if (RD_country[i].ToString() != null)
  5890. {
  5891. //在申根国家中筛选 该国家是否是申根国家
  5892. for (int j = 0; j < _shenGenGuos.Length; j++)
  5893. {
  5894. if (RD_country[i] == _shenGenGuos[j])
  5895. SGGNames.Add(_shenGenGuos[j]); //添加申根国
  5896. }
  5897. }
  5898. }
  5899. //目的地国是否有申根国
  5900. if (SGGNames.Count > 0)
  5901. {
  5902. firstEntryLabel = SGGNames.First();
  5903. membeDescLabel = string.Join(",", SGGNames.ToArray());
  5904. //接收生根国详细信息 存储顺序 起飞日期:Day 起飞时刻:StartTime 抵达日期:ArrivedDate 到达时刻:EndTime
  5905. List<SSGDetails> ListSSGDetails = new List<SSGDetails>();
  5906. //处理申根国家 预定到达时间 预定离开时间 预定停留天数
  5907. for (int i = 0; i < SGGNames.Count; i++)
  5908. {
  5909. //在相同的国家下 得到该航班的信息 //抵达时间 起飞日期:Day 起飞时刻:StartTime 到达时刻:EndTime 抵达日期:ArrivedDate 飞行时间:FlightTime 航司 Fliagtcode 入境口岸
  5910. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  5911. //ResidenceTime1 机票三字码信息
  5912. if (atbc != null)
  5913. {
  5914. string HL_Three = ""; //三字码 Three
  5915. for (int j = 0; j < atbc.Rows.Count; j++)
  5916. {
  5917. HL_Three = atbc.Rows[j]["Three"].ToString();
  5918. if (!string.IsNullOrEmpty(HL_Three))
  5919. {
  5920. string threeCodeTwo = HL_Three.Substring(3);
  5921. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  5922. if (tc != null)
  5923. {
  5924. //首入申根国时间
  5925. if (SGGNames[i] == tc.Country)
  5926. {
  5927. SSGDetails SSGDetails = new SSGDetails()
  5928. {
  5929. Three = atbc.Rows[j]["Three"].ToString(), //三字码
  5930. Fliagtcode = atbc.Rows[j]["Fliagtcode"].ToString(), //航司
  5931. startDate = atbc.Rows[j]["Day"].ToString(), //整理起飞日期
  5932. startTime = atbc.Rows[j]["StartTime"].ToString(), //整理起飞时刻
  5933. endDate = atbc.Rows[j]["ArrivedDate"].ToString(), //整理抵达日期
  5934. endTime = atbc.Rows[j]["EndTime"].ToString() //整理抵达时刻
  5935. };
  5936. ListSSGDetails.Add(SSGDetails);
  5937. }
  5938. }
  5939. }
  5940. }
  5941. }
  5942. }
  5943. ListSSGDetails.Sort((a, b) => a.startDate.CompareTo(b.startDate));
  5944. //得到并计算出入境时间
  5945. if (ListSSGDetails != null)
  5946. {
  5947. RuJingTime = ListSSGDetails.First().endDate + " " + ListSSGDetails.First().endTime.Substring(0, 2) + ":" + ListSSGDetails.First().endTime.Substring(2); //入境时间
  5948. LiJingTime = ListSSGDetails[ListSSGDetails.Count - 1].startDate + " " + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(0, 2) + ":" + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(2); //离境时间
  5949. stopDays = Convert.ToDateTime(LiJingTime).Subtract(Convert.ToDateTime(RuJingTime)).Days.ToString();
  5950. }
  5951. }
  5952. }
  5953. SetFieldValue(formFields, "main_destination", membeDescLabel); // 主要目的地成员国(如适用,还包括目的地的其他成员国)
  5954. SetFieldValue(formFields, "first_entry", firstEntryLabel); // 首次加入的成员国
  5955. // 申请入境次数
  5956. SetFieldValue(formFields, "entries_requested_single", "Off"); // 一次入境
  5957. SetFieldValue(formFields, "entries_requested_two", "Off"); // 两次入境
  5958. SetFieldValue(formFields, "entries_requested_multiple", "Off"); // 多次入境
  5959. SetFieldValue(formFields, "first_schenggen_stay_arrival_date", RuJingTime); // 首次计划在申根区停留的预计抵达日期
  5960. SetFieldValue(formFields, "first_schenggen_stay_departure_date", LiJingTime); // 首次计划在申根区停留结束后离开申根区的预计离境日期
  5961. #endregion
  5962. #region 申请申根签证而先前采集的指纹
  5963. SetFieldValue(formFields, "schengen_visa_no", ""); // 否
  5964. SetFieldValue(formFields, "schengen_visa_yes", ""); // 是
  5965. SetFieldValue(formFields, "fingerpints_date", ""); // 如有,请写明日期
  5966. SetFieldValue(formFields, "fingerpints_visa_number", ""); // 如有,请写明签证贴纸号码
  5967. #endregion
  5968. #region 最终目的地国家的入境许可(如适用)
  5969. SetFieldValue(formFields, "entry_permit_country_issued", ""); // 颁发单位
  5970. SetFieldValue(formFields, "entry_permit_country_valid", ""); // 颁发日期
  5971. SetFieldValue(formFields, "entry_permit_country_until", ""); // 有效期限
  5972. #endregion
  5973. #region 招待方在成员国中的姓氏和名字。如无此信息,则填写成员国内的酒店或临时住宿场所的名称
  5974. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  5975. .Where(x => x.DiId == groupId)
  5976. //.Where(x => x.City.contains(city))
  5977. .First();
  5978. //酒店住址
  5979. if (hotelInfo != null)
  5980. {
  5981. SetFieldValue(formFields, "hotel_namee", hotelInfo?.HotelName ?? ""); // 招待方的地址和电子邮箱地址
  5982. var otherInfo = $"{hotelInfo.HotelAddress}";
  5983. SetFieldValue(formFields, "hotel_address_and_email", otherInfo); // 酒店/临时住宿场所的地址和电子邮箱地址
  5984. SetFieldValue(formFields, "hotel_tel", hotelInfo?.HotelTel ?? ""); // 电话号码
  5985. }
  5986. #endregion
  5987. #region 邀请公司/组织信息
  5988. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  5989. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  5990. //.Where(x => x.Country.Contains(county))
  5991. //.Where(x => x.Area.Contains(city))
  5992. .First();
  5993. if (oa != null)
  5994. {
  5995. string oaInfo = $"{oa.Client} {oa.Address}";
  5996. SetFieldValue(formFields, "inviting_name_and_address", oaInfo); // 邀请公司/组织的名称及地址
  5997. string contactInfo = $"{oa?.Contact ?? ""} {oa?.Tel ?? ""} {oa?.EmailOrWeChat ?? ""}";
  5998. SetFieldValue(formFields, "inviting_contact_Info", contactInfo); // 公司/组织中联系人的姓氏、名字、地址、电话号码以及电子邮箱地址
  5999. SetFieldValue(formFields, "inviting_company_tel", oa?.Tel ?? ""); //电话号码(关于)公司/组织
  6000. }
  6001. #endregion
  6002. #region 申请人在留宿期间的旅行及生活费用已由申请人本人承担
  6003. #region 支持方式
  6004. SetFieldValue(formFields, "cost_type_himself", "Off"); // 支持方式
  6005. SetFieldValue(formFields, "cost_type_himself_cash", "Off"); // 现金
  6006. SetFieldValue(formFields, "cost_type_himself_cheques", "Off"); // 旅行支票
  6007. SetFieldValue(formFields, "cost_type_himself_creditcard", "Off"); // 信用卡
  6008. SetFieldValue(formFields, "cost_type_himself_accommodation", "Off");// 预付费住宿
  6009. SetFieldValue(formFields, "cost_type_himself_transport", "Off"); // 预付费交通
  6010. SetFieldValue(formFields, "cost_type_himself_other", "Off"); // 其他
  6011. SetFieldValue(formFields, "cost_type_himself_other_specify", ""); // 其他(请具体说明)
  6012. #endregion
  6013. #region 由赞助方(主办方、公司、组织)提供
  6014. SetFieldValue(formFields, "cost_type_himself", "Off"); // 由赞助方(主办方、公司、组织)提供
  6015. SetFieldValue(formFields, "cost_type_himself_cash", "Off"); // 在第 30 或 31 栏中提及
  6016. SetFieldValue(formFields, "cost_type_sponsor_other", "Off"); // 其他
  6017. SetFieldValue(formFields, "cost_type_sponsor_other_specify", ""); // 其他(请具体说明
  6018. //支持方式
  6019. SetFieldValue(formFields, "cost_type_support_cash", "Off"); // 现金
  6020. SetFieldValue(formFields, "cost_type_support_provided", "Off"); // 提供住宿
  6021. SetFieldValue(formFields, "cost_type_support_covered", "Off"); // 旅行期间的所有费用均由主办方承担
  6022. SetFieldValue(formFields, "cost_type_support_transport", "Off"); // 预先支付的交通费用
  6023. SetFieldValue(formFields, "cost_type_support_other", "Off"); // 其他
  6024. SetFieldValue(formFields, "cost_type_support_other_specify", ""); // 其他(请具体说明
  6025. #endregion
  6026. #endregion
  6027. #region 填写申请表的人员的姓氏和名字(若与申请人姓名不同)
  6028. SetFieldValue(formFields, "application_form_name", custInfo.TableOpName); // 申请表的人员
  6029. SetFieldValue(formFields, "application_form_address_email", ""); // 申请表人员的地址及电子邮箱地址
  6030. SetFieldValue(formFields, "assistance_tel", custInfo.TableOpTel); // 电话号码
  6031. #endregion
  6032. var date_year = DateTime.Now.Year.ToString();
  6033. var date_month = DateTime.Now.Month.ToString();
  6034. var date_day = DateTime.Now.Day.ToString();
  6035. SetFieldValue(formFields, "place_and_date", DateTime.Now.ToString("yyyy-MM-dd")); // 申请日期
  6036. var applicant_name = custInfo.LastName + custInfo.FirstName;
  6037. SetFieldValue(formFields, "applicant_signature", applicant_name); // 申请人姓名
  6038. SetFieldValue(formFields, "signature_parental_info", ""); // (如适用,需签名的家长授权/监护人信息):
  6039. #endregion
  6040. filePaths.Add(outputPath);
  6041. }
  6042. catch (Exception ex)
  6043. {
  6044. return Ok(JsonView(false, $"生成PDF文件时出错:{ex.Message}"));
  6045. }
  6046. finally
  6047. {
  6048. // 按正确顺序关闭资源
  6049. stamper?.Close();
  6050. reader?.Close();
  6051. templateStream?.Close();
  6052. outputStream?.Close();
  6053. }
  6054. #endregion
  6055. }
  6056. break;
  6057. case 6: // 加拿大
  6058. visaTypeName = $"加拿大签证申请表";
  6059. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  6060. var canadaSavePath = $"{fileServerPath}{visaTypeName}/";
  6061. if (!Directory.Exists(canadaSavePath)) Directory.CreateDirectory(canadaSavePath);
  6062. if (!System.IO.File.Exists(currTempPath))
  6063. {
  6064. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  6065. }
  6066. foreach (var custInfo in groupCustInfos)
  6067. {
  6068. EncryptionProcessor.DecryptProperties(custInfo);
  6069. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  6070. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  6071. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  6072. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  6073. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  6074. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  6075. #region 生成文件
  6076. PdfReader reader = null;
  6077. FileStream templateStream = null;
  6078. FileStream outputStream = null;
  6079. PdfStamper stamper = null;
  6080. try
  6081. {
  6082. string outputPath = $"{canadaSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  6083. //读取模板文件
  6084. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  6085. reader = new PdfReader(templateStream);
  6086. //创建输出文件
  6087. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  6088. stamper = new PdfStamper(reader, outputStream);
  6089. AcroFields formFields = stamper.AcroFields;
  6090. #region 设置文本值
  6091. SetFieldValue(formFields, "surname", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? ""); // 姓 英文
  6092. SetFieldValue(formFields, "surname_birth", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? ""); // 出生时姓 英文
  6093. SetFieldValue(formFields, "first_name", CommonFun.ConvertToPinyin(custInfo?.FirstName?.Trim() ?? "")?.ToLower() ?? ""); // 名 英文
  6094. #region 出生日期(日-月-年)
  6095. string idCard = idInfo?.CertNo?.Trim() ?? "";
  6096. string birthday = string.Empty;
  6097. if (!string.IsNullOrEmpty(idCard))
  6098. {
  6099. string year = idCard.Substring(6, 4);
  6100. string month = idCard.Substring(10, 2);
  6101. string day = idCard.Substring(12, 2);
  6102. birthday = day + "-" + month + "-" + year;
  6103. }
  6104. SetFieldValue(formFields, "birthday", birthday);
  6105. #endregion
  6106. var area = custInfo.BirthProvince + custInfo.BirthCity;
  6107. SetFieldValue(formFields, "birth_place", area); // 出生地区
  6108. SetFieldValue(formFields, "birth_country", "中国"); // 出生国籍
  6109. SetFieldValue(formFields, "current_nationality", "中国"); // 现国籍
  6110. SetFieldValue(formFields, "birth_nationality", "中国"); // 出生国
  6111. SetFieldValue(formFields, "other_nationality", ""); // 其他国籍
  6112. #region 设置性别
  6113. //清除性别
  6114. SetFieldValue(formFields, "sex_male", "Off"); // 性别 - 男
  6115. SetFieldValue(formFields, "sex_female", "Off"); // 性别 - 女
  6116. SetFieldValue(formFields, "sex_other", "Off"); // 性别 - 其他
  6117. //设置性别
  6118. if (custInfo.Sex == 0) // 男
  6119. {
  6120. SetFieldValue(formFields, "sex_male", "Yes"); // 性别 - 男
  6121. }
  6122. else if (custInfo.Sex == 1) // 女
  6123. {
  6124. SetFieldValue(formFields, "sex_female", "Yes"); // 性别 - 女
  6125. }
  6126. else // 其他
  6127. {
  6128. SetFieldValue(formFields, "sex_other", "Yes"); // 性别 - 其他
  6129. }
  6130. #endregion
  6131. #region 婚姻状态
  6132. //清除婚姻状况
  6133. SetFieldValue(formFields, "civil_single", "Off"); // 婚姻状况 - 未婚
  6134. SetFieldValue(formFields, "civil_married", "Off"); // 婚姻状况 - 已婚
  6135. SetFieldValue(formFields, "civil_registerered_partnership", "Off");// 婚姻状况 - 注册伴侣关系
  6136. SetFieldValue(formFields, "civil_separated", "Off"); // 婚姻状况 - 分居
  6137. SetFieldValue(formFields, "civil_divorced", "Off"); // 婚姻状况 - 离异
  6138. SetFieldValue(formFields, "civil_windower", "Off"); // 婚姻状况 - 妻子(丈夫)去世
  6139. SetFieldValue(formFields, "civil_other", "Off"); // 婚姻状况 - 其他
  6140. SetFieldValue(formFields, "civil_other_details", ""); // 婚姻状况 - 其他(请具体说明)
  6141. //设置婚姻状况
  6142. switch (custInfo.Marriage)
  6143. {
  6144. case 1: // 未婚
  6145. break;
  6146. case 2: // 已婚
  6147. SetFieldValue(formFields, "civil_married", "Yes");
  6148. break;
  6149. case 3: // 离婚/离异
  6150. SetFieldValue(formFields, "civil_divorced", "Yes");
  6151. break;
  6152. case 4:
  6153. break;
  6154. }
  6155. #endregion
  6156. // 父母的监护权(针对未成年人)/法定监护人(姓氏、名字、地址(若与申请人的地址不同)、电话号码、电子邮箱地址以及国籍)
  6157. SetFieldValue(formFields, "parental_authority", "");
  6158. //(如适用)国民身份号码
  6159. SetFieldValue(formFields, "id_number", idCard);
  6160. #region 护照信息
  6161. //清除值
  6162. SetFieldValue(formFields, "travel_type_ordinary_passport", "Off"); // 旅行证件类型 - 普通护照
  6163. SetFieldValue(formFields, "travel_type_diplomatic_passport", "Off"); // 旅行证件类型 - 外交护照
  6164. SetFieldValue(formFields, "travel_type_service_passport", "Off"); // 旅行证件类型 - 服务护照
  6165. SetFieldValue(formFields, "travel_type_offical_passport", "Off"); // 旅行证件类型 - 公务护照
  6166. SetFieldValue(formFields, "travel_type_special_passport", "Off"); // 旅行证件类型 - 特别护照
  6167. SetFieldValue(formFields, "travel_type_other_passport_details", ""); // 其他旅行证件(请注明)
  6168. //设置值
  6169. if (passportInfo != null)
  6170. {
  6171. // 签证类型
  6172. var visatypeInfo = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == passportInfo.PassportType);
  6173. if (visatypeInfo != null)
  6174. {
  6175. string visaName = visatypeInfo?.Name ?? "-";
  6176. if (visaName.contains("普通")) SetFieldValue(formFields, "travel_type_ordinary_passport", "Yes"); // 旅行证件类型 - 普通护照
  6177. else if (visaName.contains("外交")) SetFieldValue(formFields, "travel_type_diplomatic_passport", "Yes"); // 旅行证件类型 - 外交护照
  6178. else if (visaName.contains("服务")) SetFieldValue(formFields, "travel_type_service_passport", "Yes"); // 旅行证件类型 - 服务护照
  6179. else if (visaName.contains("公务")) SetFieldValue(formFields, "travel_type_offical_passport", "Yes"); // 旅行证件类型 - 公务护照
  6180. else // 旅行证件类型 - 特别护照
  6181. {
  6182. SetFieldValue(formFields, "travel_type_other_passport", "Yes");
  6183. SetFieldValue(formFields, "travel_type_other_passport_details", "");
  6184. }
  6185. }
  6186. #region 护照信息
  6187. SetFieldValue(formFields, "travel_number", passportInfo.CertNo); // 签证 编号
  6188. SetFieldValue(formFields, "travel_issue_country", passportInfo.Country); // 签发 国
  6189. SetFieldValue(formFields, "travel_issue_date", passportInfo.IssueDt?.ToString("yyyy-MM-dd") ?? ""); // 签发日期
  6190. SetFieldValue(formFields, "travel_issue_vaild", passportInfo.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); // 有效期至
  6191. #endregion
  6192. }
  6193. #endregion
  6194. #region 适用情况下,欧盟、欧洲经济区或瑞士公民,或英国籍且为《欧盟-英国脱欧协议》受益人的家庭成员的个人资料 “默认空”
  6195. SetFieldValue(formFields, "eu_info_surname", ""); // 姓氏(家族名)
  6196. SetFieldValue(formFields, "eu_info_first_name", ""); // 名字(名字)
  6197. SetFieldValue(formFields, "eu_info_birthday", ""); // 出生日期 (日-月-年)
  6198. SetFieldValue(formFields, "eu_info_nationality", ""); // 国籍
  6199. SetFieldValue(formFields, "eu_info_id_number", ""); // 旅行证件或身份证号码
  6200. #region 与欧盟、欧洲经济区或瑞士公民,或作为《欧盟-英国脱欧协议》受益人的英国国民之间的家庭关系(如适用)
  6201. SetFieldValue(formFields, "eu_family_relationship_spouse", "Off"); // 夫妻
  6202. SetFieldValue(formFields, "eu_family_relationship_child", "Off"); // 子女
  6203. SetFieldValue(formFields, "eu_family_relationship_grandchild", "Off"); // 孙子女
  6204. SetFieldValue(formFields, "eu_family_relationship_ascendant", "Off"); // 有赡养关系的长辈
  6205. SetFieldValue(formFields, "eu_family_relationship_registered", "Off"); // 注册伴侣关系
  6206. #endregion
  6207. #endregion
  6208. // 申请人的家庭住址和电子邮箱地址
  6209. string applicantAddressAndEmail = $"{custInfo.Address} {custInfo.Email}";
  6210. SetFieldValue(formFields, "applicant_address_and_email", applicantAddressAndEmail);
  6211. // 申请人的电话
  6212. SetFieldValue(formFields, "applicant_tel", custInfo.Tel);
  6213. #region 在非当前国籍所属国家的居住情况 “默认空”
  6214. SetFieldValue(formFields, "uncurrent_count_no", "Yes"); // 否
  6215. SetFieldValue(formFields, "uncurrent_count_yes", "Off"); // 是
  6216. SetFieldValue(formFields, "uncurrent_country_residence", "");// 居留许可或同等证明
  6217. SetFieldValue(formFields, "uncurrent_country_no", ""); // No
  6218. SetFieldValue(formFields, "uncurrent_country_valid_until", "");// 有效期至
  6219. #endregion
  6220. #region 职业
  6221. //职业信息
  6222. if (companyInfos != null && companyInfos.Count > 0)
  6223. {
  6224. // 当前职业
  6225. SetFieldValue(formFields, "current_occupation", companyInfos.FirstOrDefault()?.Job ?? "");
  6226. //雇主及雇主的地址和电话号码。对于学生而言,应填写教育机构的名称及地址
  6227. string employerInfo = $"{companyInfos.FirstOrDefault()?.CompanyAddress ?? ""} {companyInfos.FirstOrDefault()?.Phone ?? ""}";
  6228. }
  6229. #endregion
  6230. #region 此次行程的目的
  6231. //清除值
  6232. SetFieldValue(formFields, "purpose_tourism", "Off"); // 旅游
  6233. SetFieldValue(formFields, "purpose_business", "Off"); // 商务
  6234. SetFieldValue(formFields, "purpose_visiting_family_friends", "Off");// 庆祝亲友团聚
  6235. SetFieldValue(formFields, "purpose_cultural", "Off"); // 文化交流
  6236. SetFieldValue(formFields, "purpose_sports", "Off"); // 体育活动
  6237. SetFieldValue(formFields, "purpose_offcial_visit", "Off"); // 官方访问
  6238. SetFieldValue(formFields, "purpose_medical_reasons", "Off"); // 医疗原因
  6239. SetFieldValue(formFields, "purpose_study", "Off"); // 学习
  6240. SetFieldValue(formFields, "purpose_airport_transit", "Off"); // 机场中转
  6241. SetFieldValue(formFields, "purpose_other", "Off"); // 其他
  6242. SetFieldValue(formFields, "purpose_other_remark", ""); // 其他 - 备注
  6243. var visit_purpose = groupInfo.VisitPurpose;
  6244. if (!string.IsNullOrEmpty(visit_purpose))
  6245. {
  6246. if (visit_purpose.contains("旅游"))
  6247. {
  6248. SetFieldValue(formFields, "purpose_tourism", "Yes"); // 旅游
  6249. }
  6250. else if (visit_purpose.contains("商务"))
  6251. {
  6252. SetFieldValue(formFields, "purpose_business", "Yes"); // 商务
  6253. }
  6254. else if (visit_purpose.contains("亲友"))
  6255. {
  6256. SetFieldValue(formFields, "purpose_visiting_family_friends", "Yes");// 庆祝亲友团聚
  6257. }
  6258. else if (visit_purpose.contains("文化交流") || visit_purpose.contains("旅游"))
  6259. {
  6260. SetFieldValue(formFields, "purpose_cultural", "Yes"); // 文化交流
  6261. }
  6262. else if (visit_purpose.contains("体育") || visit_purpose.contains("活动"))
  6263. {
  6264. SetFieldValue(formFields, "purpose_sports", "Yes"); // 体育活动
  6265. }
  6266. else if (visit_purpose.contains("官方访问"))
  6267. {
  6268. SetFieldValue(formFields, "purpose_offcial_visit", "Yes"); // 官方访问
  6269. }
  6270. else if (visit_purpose.contains("医疗原因") || visit_purpose.contains("医疗"))
  6271. {
  6272. SetFieldValue(formFields, "purpose_medical_reasons", "Yes"); // 医疗原因
  6273. }
  6274. else if (visit_purpose.contains("学习"))
  6275. {
  6276. SetFieldValue(formFields, "purpose_study", "Yes"); // 学习
  6277. }
  6278. else if (visit_purpose.contains("机场中转"))
  6279. {
  6280. SetFieldValue(formFields, "purpose_airport_transit", "Yes"); // 机场中转
  6281. }
  6282. else
  6283. {
  6284. SetFieldValue(formFields, "purpose_other", "Yes"); // 其他
  6285. SetFieldValue(formFields, "purpose_other_remark", ""); // 其他 - 备注
  6286. }
  6287. }
  6288. #endregion
  6289. #region 目的国相关信息
  6290. //关于停留目的的补充说明
  6291. SetFieldValue(formFields, "purpose_stay_info", "");
  6292. string[] RD_country = new string[] { }; //接收处理的国家
  6293. string firstEntryLabel = string.Empty; // 首入申根国标签
  6294. string membeDescLabel = string.Empty; // 申根国目的地
  6295. string RuJingTime = string.Empty; // 入境时间
  6296. string LiJingTime = string.Empty; // 离境时间
  6297. string stopDays = string.Empty; // 停留天数
  6298. if (!string.IsNullOrEmpty(groupInfo.VisitCountry))
  6299. {
  6300. List<string> SGGNames = new List<string>();//接收处理后的国家 是申根国
  6301. if (groupInfo.VisitCountry.Contains(","))
  6302. RD_country = groupInfo.VisitCountry.Split(',');
  6303. else if (groupInfo.VisitCountry.Contains(' '))
  6304. RD_country = groupInfo.VisitCountry.Split(' ');
  6305. else if (groupInfo.VisitCountry.Contains(","))
  6306. RD_country = groupInfo.VisitCountry.Split(',');
  6307. else if (groupInfo.VisitCountry.Contains("、"))
  6308. RD_country = groupInfo.VisitCountry.Split('、');
  6309. else if (groupInfo.VisitCountry.Contains("|"))
  6310. RD_country = groupInfo.VisitCountry.Split('|');
  6311. //判断是否是申根国家
  6312. for (int i = 0; i < RD_country.Length; i++)
  6313. {
  6314. if (RD_country[i].ToString() != null)
  6315. {
  6316. //在申根国家中筛选 该国家是否是申根国家
  6317. for (int j = 0; j < _shenGenGuos.Length; j++)
  6318. {
  6319. if (RD_country[i] == _shenGenGuos[j])
  6320. SGGNames.Add(_shenGenGuos[j]); //添加申根国
  6321. }
  6322. }
  6323. }
  6324. //目的地国是否有申根国
  6325. if (SGGNames.Count > 0)
  6326. {
  6327. firstEntryLabel = SGGNames.First();
  6328. membeDescLabel = string.Join(",", SGGNames.ToArray());
  6329. //接收生根国详细信息 存储顺序 起飞日期:Day 起飞时刻:StartTime 抵达日期:ArrivedDate 到达时刻:EndTime
  6330. List<SSGDetails> ListSSGDetails = new List<SSGDetails>();
  6331. //处理申根国家 预定到达时间 预定离开时间 预定停留天数
  6332. for (int i = 0; i < SGGNames.Count; i++)
  6333. {
  6334. //在相同的国家下 得到该航班的信息 //抵达时间 起飞日期:Day 起飞时刻:StartTime 到达时刻:EndTime 抵达日期:ArrivedDate 飞行时间:FlightTime 航司 Fliagtcode 入境口岸
  6335. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  6336. //ResidenceTime1 机票三字码信息
  6337. if (atbc != null)
  6338. {
  6339. string HL_Three = ""; //三字码 Three
  6340. for (int j = 0; j < atbc.Rows.Count; j++)
  6341. {
  6342. HL_Three = atbc.Rows[j]["Three"].ToString();
  6343. if (!string.IsNullOrEmpty(HL_Three))
  6344. {
  6345. string threeCodeTwo = HL_Three.Substring(3);
  6346. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  6347. if (tc != null)
  6348. {
  6349. //首入申根国时间
  6350. if (SGGNames[i] == tc.Country)
  6351. {
  6352. SSGDetails SSGDetails = new SSGDetails()
  6353. {
  6354. Three = atbc.Rows[j]["Three"].ToString(), //三字码
  6355. Fliagtcode = atbc.Rows[j]["Fliagtcode"].ToString(), //航司
  6356. startDate = atbc.Rows[j]["Day"].ToString(), //整理起飞日期
  6357. startTime = atbc.Rows[j]["StartTime"].ToString(), //整理起飞时刻
  6358. endDate = atbc.Rows[j]["ArrivedDate"].ToString(), //整理抵达日期
  6359. endTime = atbc.Rows[j]["EndTime"].ToString() //整理抵达时刻
  6360. };
  6361. ListSSGDetails.Add(SSGDetails);
  6362. }
  6363. }
  6364. }
  6365. }
  6366. }
  6367. }
  6368. ListSSGDetails.Sort((a, b) => a.startDate.CompareTo(b.startDate));
  6369. //得到并计算出入境时间
  6370. if (ListSSGDetails != null)
  6371. {
  6372. RuJingTime = ListSSGDetails.First().endDate + " " + ListSSGDetails.First().endTime.Substring(0, 2) + ":" + ListSSGDetails.First().endTime.Substring(2); //入境时间
  6373. LiJingTime = ListSSGDetails[ListSSGDetails.Count - 1].startDate + " " + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(0, 2) + ":" + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(2); //离境时间
  6374. stopDays = Convert.ToDateTime(LiJingTime).Subtract(Convert.ToDateTime(RuJingTime)).Days.ToString();
  6375. }
  6376. }
  6377. }
  6378. SetFieldValue(formFields, "main_destination", membeDescLabel); // 主要目的地成员国(如适用,还包括目的地的其他成员国)
  6379. SetFieldValue(formFields, "first_entry", firstEntryLabel); // 首次加入的成员国
  6380. // 申请入境次数
  6381. SetFieldValue(formFields, "entries_requested_single", "Off"); // 一次入境
  6382. SetFieldValue(formFields, "entries_requested_two", "Off"); // 两次入境
  6383. SetFieldValue(formFields, "entries_requested_multiple", "Off"); // 多次入境
  6384. SetFieldValue(formFields, "first_schenggen_stay_arrival_date", RuJingTime); // 首次计划在申根区停留的预计抵达日期
  6385. SetFieldValue(formFields, "first_schenggen_stay_departure_date", LiJingTime); // 首次计划在申根区停留结束后离开申根区的预计离境日期
  6386. #endregion
  6387. #region 申请申根签证而先前采集的指纹
  6388. SetFieldValue(formFields, "schengen_visa_no", ""); // 否
  6389. SetFieldValue(formFields, "schengen_visa_yes", ""); // 是
  6390. SetFieldValue(formFields, "fingerpints_date", ""); // 如有,请写明日期
  6391. SetFieldValue(formFields, "fingerpints_visa_number", ""); // 如有,请写明签证贴纸号码
  6392. #endregion
  6393. #region 最终目的地国家的入境许可(如适用)
  6394. SetFieldValue(formFields, "entry_permit_country_issued", ""); // 颁发单位
  6395. SetFieldValue(formFields, "entry_permit_country_valid", ""); // 颁发日期
  6396. SetFieldValue(formFields, "entry_permit_country_until", ""); // 有效期限
  6397. #endregion
  6398. #region 招待方在成员国中的姓氏和名字。如无此信息,则填写成员国内的酒店或临时住宿场所的名称
  6399. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  6400. .Where(x => x.DiId == groupId)
  6401. //.Where(x => x.City.contains(city))
  6402. .First();
  6403. //酒店住址
  6404. if (hotelInfo != null)
  6405. {
  6406. SetFieldValue(formFields, "hotel_namee", hotelInfo?.HotelName ?? ""); // 招待方的地址和电子邮箱地址
  6407. var otherInfo = $"{hotelInfo.HotelAddress}";
  6408. SetFieldValue(formFields, "hotel_address_and_email", otherInfo); // 酒店/临时住宿场所的地址和电子邮箱地址
  6409. SetFieldValue(formFields, "hotel_tel", hotelInfo?.HotelTel ?? ""); // 电话号码
  6410. }
  6411. #endregion
  6412. #region 邀请公司/组织信息
  6413. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  6414. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  6415. //.Where(x => x.Country.Contains(county))
  6416. //.Where(x => x.Area.Contains(city))
  6417. .First();
  6418. if (oa != null)
  6419. {
  6420. string oaInfo = $"{oa.Client} {oa.Address}";
  6421. SetFieldValue(formFields, "inviting_name_and_address", oaInfo); // 邀请公司/组织的名称及地址
  6422. string contactInfo = $"{oa?.Contact ?? ""} {oa?.Tel ?? ""} {oa?.EmailOrWeChat ?? ""}";
  6423. SetFieldValue(formFields, "inviting_contact_Info", contactInfo); // 公司/组织中联系人的姓氏、名字、地址、电话号码以及电子邮箱地址
  6424. SetFieldValue(formFields, "inviting_company_tel", oa?.Tel ?? ""); //电话号码(关于)公司/组织
  6425. }
  6426. #endregion
  6427. #region 申请人在留宿期间的旅行及生活费用已由申请人本人承担
  6428. #region 支持方式
  6429. SetFieldValue(formFields, "cost_type_himself", "Off"); // 支持方式
  6430. SetFieldValue(formFields, "cost_type_himself_cash", "Off"); // 现金
  6431. SetFieldValue(formFields, "cost_type_himself_cheques", "Off"); // 旅行支票
  6432. SetFieldValue(formFields, "cost_type_himself_creditcard", "Off"); // 信用卡
  6433. SetFieldValue(formFields, "cost_type_himself_accommodation", "Off");// 预付费住宿
  6434. SetFieldValue(formFields, "cost_type_himself_transport", "Off"); // 预付费交通
  6435. SetFieldValue(formFields, "cost_type_himself_other", "Off"); // 其他
  6436. SetFieldValue(formFields, "cost_type_himself_other_specify", ""); // 其他(请具体说明)
  6437. #endregion
  6438. #region 由赞助方(主办方、公司、组织)提供
  6439. SetFieldValue(formFields, "cost_type_himself", "Off"); // 由赞助方(主办方、公司、组织)提供
  6440. SetFieldValue(formFields, "cost_type_himself_cash", "Off"); // 在第 30 或 31 栏中提及
  6441. SetFieldValue(formFields, "cost_type_sponsor_other", "Off"); // 其他
  6442. SetFieldValue(formFields, "cost_type_sponsor_other_specify", ""); // 其他(请具体说明
  6443. //支持方式
  6444. SetFieldValue(formFields, "cost_type_support_cash", "Off"); // 现金
  6445. SetFieldValue(formFields, "cost_type_support_provided", "Off"); // 提供住宿
  6446. SetFieldValue(formFields, "cost_type_support_covered", "Off"); // 旅行期间的所有费用均由主办方承担
  6447. SetFieldValue(formFields, "cost_type_support_transport", "Off"); // 预先支付的交通费用
  6448. SetFieldValue(formFields, "cost_type_support_other", "Off"); // 其他
  6449. SetFieldValue(formFields, "cost_type_support_other_specify", ""); // 其他(请具体说明
  6450. #endregion
  6451. #endregion
  6452. #region 填写申请表的人员的姓氏和名字(若与申请人姓名不同)
  6453. SetFieldValue(formFields, "application_form_name", custInfo.TableOpName); // 申请表的人员
  6454. SetFieldValue(formFields, "application_form_address_email", ""); // 申请表人员的地址及电子邮箱地址
  6455. SetFieldValue(formFields, "assistance_tel", custInfo.TableOpTel); // 电话号码
  6456. #endregion
  6457. var date_year = DateTime.Now.Year.ToString();
  6458. var date_month = DateTime.Now.Month.ToString();
  6459. var date_day = DateTime.Now.Day.ToString();
  6460. SetFieldValue(formFields, "place_and_date", DateTime.Now.ToString("yyyy-MM-dd")); // 申请日期
  6461. var applicant_name = custInfo.LastName + custInfo.FirstName;
  6462. SetFieldValue(formFields, "applicant_signature", applicant_name); // 申请人姓名
  6463. SetFieldValue(formFields, "signature_parental_info", ""); // (如适用,需签名的家长授权/监护人信息):
  6464. #endregion
  6465. filePaths.Add(outputPath);
  6466. }
  6467. catch (Exception ex)
  6468. {
  6469. return Ok(JsonView(false, $"生成PDF文件时出错:{ex.Message}"));
  6470. }
  6471. finally
  6472. {
  6473. // 按正确顺序关闭资源
  6474. stamper?.Close();
  6475. reader?.Close();
  6476. templateStream?.Close();
  6477. outputStream?.Close();
  6478. }
  6479. #endregion
  6480. }
  6481. break;
  6482. case 7: // 克罗地亚
  6483. visaTypeName = $"克罗地亚签证申请表";
  6484. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  6485. var croatiaSavePath = $"{fileServerPath}{visaTypeName}/";
  6486. if (!Directory.Exists(croatiaSavePath)) Directory.CreateDirectory(croatiaSavePath);
  6487. if (!System.IO.File.Exists(currTempPath))
  6488. {
  6489. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  6490. }
  6491. foreach (var custInfo in groupCustInfos)
  6492. {
  6493. EncryptionProcessor.DecryptProperties(custInfo);
  6494. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  6495. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  6496. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  6497. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  6498. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  6499. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  6500. #region 生成文件
  6501. PdfReader reader = null;
  6502. FileStream templateStream = null;
  6503. FileStream outputStream = null;
  6504. PdfStamper stamper = null;
  6505. try
  6506. {
  6507. string outputPath = $"{croatiaSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  6508. //读取模板文件
  6509. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  6510. reader = new PdfReader(templateStream);
  6511. //创建输出文件
  6512. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  6513. stamper = new PdfStamper(reader, outputStream);
  6514. AcroFields formFields = stamper.AcroFields;
  6515. #region 设置文本值
  6516. SetFieldValue(formFields, "surname", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? ""); // 姓 英文
  6517. SetFieldValue(formFields, "surname_birth", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? ""); // 出生时姓 英文
  6518. SetFieldValue(formFields, "firstname", CommonFun.ConvertToPinyin(custInfo?.FirstName?.Trim() ?? "")?.ToLower() ?? ""); // 名 英文
  6519. #region 出生日期(日-月-年)
  6520. string idCard = idInfo?.CertNo?.Trim() ?? "";
  6521. string birthday = string.Empty;
  6522. if (!string.IsNullOrEmpty(idCard))
  6523. {
  6524. string year = idCard.Substring(6, 4);
  6525. string month = idCard.Substring(10, 2);
  6526. string day = idCard.Substring(12, 2);
  6527. birthday = day + "-" + month + "-" + year;
  6528. }
  6529. SetFieldValue(formFields, "birthday", birthday);
  6530. #endregion
  6531. var area = custInfo.BirthProvince + custInfo.BirthCity;
  6532. SetFieldValue(formFields, "birth_place", area); // 出生地区
  6533. SetFieldValue(formFields, "birth_country", "中国"); // 出生国籍
  6534. SetFieldValue(formFields, "current_nationality", "中国"); // 现国籍
  6535. #region 设置性别
  6536. //清除性别
  6537. SetFieldValue(formFields, "sex_male", "Off"); // 性别 - 男
  6538. SetFieldValue(formFields, "sex_female", "Off"); // 性别 - 女
  6539. //设置性别
  6540. if (custInfo.Sex == 0) // 男
  6541. {
  6542. SetFieldValue(formFields, "sex_male", "Yes"); // 性别 - 男
  6543. }
  6544. else if (custInfo.Sex == 1) // 女
  6545. {
  6546. SetFieldValue(formFields, "sex_female", "Yes"); // 性别 - 女
  6547. }
  6548. #endregion
  6549. #region 婚姻状态
  6550. //清除婚姻状况
  6551. SetFieldValue(formFields, "marital_single", "Off"); // 婚姻状况 - 未婚
  6552. SetFieldValue(formFields, "marital_married", "Off"); // 婚姻状况 - 已婚
  6553. SetFieldValue(formFields, "marital_separated", "Off"); // 婚姻状况 - 分居
  6554. SetFieldValue(formFields, "marital_dicorced", "Off"); // 婚姻状况 - 离异
  6555. SetFieldValue(formFields, "marital_widower", "Off"); // 婚姻状况 - 丧偶
  6556. SetFieldValue(formFields, "marital_other", "Off"); // 婚姻状况 - 其他
  6557. SetFieldValue(formFields, "marital_other_specify", ""); // 婚姻状况 - 其他(请具体说明)
  6558. //设置婚姻状况
  6559. switch (custInfo.Marriage)
  6560. {
  6561. case 1: // 未婚
  6562. SetFieldValue(formFields, "marital_single", "Yes");
  6563. break;
  6564. case 2: // 已婚
  6565. SetFieldValue(formFields, "marital_married", "Yes");
  6566. break;
  6567. case 3: // 离婚/离异
  6568. SetFieldValue(formFields, "marital_dicorced", "Yes");
  6569. break;
  6570. case 4:
  6571. break;
  6572. }
  6573. #endregion
  6574. // 父母的监护权(针对未成年人)/法定监护人(姓氏、名字、地址(若与申请人的地址不同)、电话号码、电子邮箱地址以及国籍)
  6575. SetFieldValue(formFields, "legalGuardian", "");
  6576. //(如适用)国民身份号码
  6577. SetFieldValue(formFields, "nationalIdNumber", idCard);
  6578. #region 护照信息
  6579. //清除值
  6580. SetFieldValue(formFields, "travel_ordinary_passport", "Off"); // 旅行证件类型 - 普通护照
  6581. SetFieldValue(formFields, "travel_diplomatic_passport", "Off");// 旅行证件类型 - 外交护照
  6582. SetFieldValue(formFields, "travel_service_passport", "Off"); // 旅行证件类型 - 服务护照
  6583. SetFieldValue(formFields, "travel_special_passport", "Off"); // 旅行证件类型 - 公务护照
  6584. SetFieldValue(formFields, "travel_other", "Off"); // 旅行证件类型 - 特别护照
  6585. SetFieldValue(formFields, "travel_other_specify", ""); // 其他旅行证件(请注明)
  6586. //设置值
  6587. if (passportInfo != null)
  6588. {
  6589. // 签证类型
  6590. var visatypeInfo = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == passportInfo.PassportType);
  6591. if (visatypeInfo != null)
  6592. {
  6593. string visaName = visatypeInfo?.Name ?? "-";
  6594. if (visaName.contains("普通")) SetFieldValue(formFields, "travel_ordinary_passport", "Yes"); // 旅行证件类型 - 普通护照
  6595. else if (visaName.contains("外交")) SetFieldValue(formFields, "travel_diplomatic_passport", "Yes"); // 旅行证件类型 - 外交护照
  6596. else if (visaName.contains("服务")) SetFieldValue(formFields, "travel_service_passport", "Yes"); // 旅行证件类型 - 服务护照
  6597. else if (visaName.contains("公务")) SetFieldValue(formFields, "travel_type_offical_passport", "Yes");// 旅行证件类型 - 公务护照
  6598. else // 旅行证件类型 - 特别护照
  6599. {
  6600. SetFieldValue(formFields, "travel_other", "Yes");
  6601. SetFieldValue(formFields, "travel_other_specify", "");
  6602. }
  6603. }
  6604. #region 护照信息
  6605. SetFieldValue(formFields, "travel_number", passportInfo.CertNo); // 签证 编号
  6606. SetFieldValue(formFields, "travel_issued", passportInfo.Country); // 签发 国
  6607. SetFieldValue(formFields, "travle_issueDate", passportInfo.IssueDt?.ToString("yyyy-MM-dd") ?? ""); // 签发日期
  6608. SetFieldValue(formFields, "travel_expiryDate", passportInfo.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); // 有效期至
  6609. #endregion
  6610. }
  6611. #endregion
  6612. #region 是否在非国籍国居住
  6613. SetFieldValue(formFields, "residesOutsideNationality_no", "Yes"); // 否
  6614. SetFieldValue(formFields, "residesOutsideNationality_yes", "Off"); // 是
  6615. SetFieldValue(formFields, "residesOutsideNationality_number", ""); // 编号
  6616. SetFieldValue(formFields, "residesOutsideNationality_validuntil", ""); // 有效期限
  6617. #endregion
  6618. #region 职业
  6619. //职业信息
  6620. if (companyInfos != null && companyInfos.Count > 0)
  6621. {
  6622. // 当前职业
  6623. SetFieldValue(formFields, "occupation", companyInfos.FirstOrDefault()?.Job ?? "");
  6624. //雇主及雇主的地址和电话号码。
  6625. string employerInfo = $"{companyInfos.FirstOrDefault()?.CompanyAddress ?? ""} {companyInfos.FirstOrDefault()?.Phone ?? ""}";
  6626. SetFieldValue(formFields, "employerInfo", employerInfo);
  6627. }
  6628. #endregion
  6629. #region 此次行程的目的
  6630. //清除值
  6631. SetFieldValue(formFields, "purpose_tourism", "Off"); // 旅游
  6632. SetFieldValue(formFields, "purpose_business", "Off"); // 商务
  6633. SetFieldValue(formFields, "purpose_visiting_friends_family", "Off");// 庆祝亲友团聚
  6634. SetFieldValue(formFields, "purpose_cultural", "Off"); // 文化交流
  6635. SetFieldValue(formFields, "purpose_sports", "Off"); // 体育活动
  6636. SetFieldValue(formFields, "purpose_official_visit", "Off"); // 官方访问
  6637. SetFieldValue(formFields, "purpose_medical_reasons", "Off"); // 医疗原因
  6638. SetFieldValue(formFields, "purpose_study", "Off"); // 学习
  6639. SetFieldValue(formFields, "purpose_transit", "Off"); // 过境
  6640. SetFieldValue(formFields, "purpose_airport_transit", "Off"); // 机场中转
  6641. SetFieldValue(formFields, "purpose_other", "Off"); // 其他
  6642. SetFieldValue(formFields, "purpose_other_specify", ""); // 其他 - 备注
  6643. var visit_purpose = groupInfo.VisitPurpose;
  6644. if (!string.IsNullOrEmpty(visit_purpose))
  6645. {
  6646. if (visit_purpose.contains("旅游"))
  6647. {
  6648. SetFieldValue(formFields, "purpose_tourism", "Yes"); // 旅游
  6649. }
  6650. else if (visit_purpose.contains("商务"))
  6651. {
  6652. SetFieldValue(formFields, "purpose_business", "Yes"); // 商务
  6653. }
  6654. else if (visit_purpose.contains("亲友"))
  6655. {
  6656. SetFieldValue(formFields, "purpose_visiting_friends_family", "Yes");// 庆祝亲友团聚
  6657. }
  6658. else if (visit_purpose.contains("文化交流") || visit_purpose.contains("旅游"))
  6659. {
  6660. SetFieldValue(formFields, "purpose_cultural", "Yes"); // 文化交流
  6661. }
  6662. else if (visit_purpose.contains("体育") || visit_purpose.contains("活动"))
  6663. {
  6664. SetFieldValue(formFields, "purpose_sports", "Yes"); // 体育活动
  6665. }
  6666. else if (visit_purpose.contains("官方访问"))
  6667. {
  6668. SetFieldValue(formFields, "purpose_official_visit", "Yes"); // 官方访问
  6669. }
  6670. else if (visit_purpose.contains("医疗原因") || visit_purpose.contains("医疗"))
  6671. {
  6672. SetFieldValue(formFields, "purpose_medical_reasons", "Yes"); // 医疗原因
  6673. }
  6674. else if (visit_purpose.contains("学习"))
  6675. {
  6676. SetFieldValue(formFields, "purpose_study", "Yes"); // 学习
  6677. }
  6678. else if (visit_purpose.contains("过境"))
  6679. {
  6680. SetFieldValue(formFields, "purpose_transit", "Yes"); // 过境
  6681. }
  6682. else if (visit_purpose.contains("机场中转"))
  6683. {
  6684. SetFieldValue(formFields, "purpose_airport_transit", "Yes"); // 机场中转
  6685. }
  6686. else
  6687. {
  6688. SetFieldValue(formFields, "purpose_other", "Yes"); // 其他
  6689. SetFieldValue(formFields, "purpose_other_specify", ""); // 其他 - 备注
  6690. }
  6691. }
  6692. #endregion
  6693. #region 目的国相关信息
  6694. //关于停留目的的补充说明
  6695. SetFieldValue(formFields, "purpose_stay_info", "");
  6696. string[] country = new string[] { }; //接收处理的国家
  6697. string firstEntryLabel = string.Empty; // 首入申根国标签
  6698. string membeDescLabel = string.Empty; // 申根国目的地
  6699. string RuJingTime = string.Empty; // 入境时间
  6700. string LiJingTime = string.Empty; // 离境时间
  6701. string stayDays = string.Empty; // 停留天数
  6702. if (!string.IsNullOrEmpty(groupInfo.VisitCountry))
  6703. {
  6704. List<string> SGGNames = new List<string>();//接收处理后的国家 是申根国
  6705. if (groupInfo.VisitCountry.Contains(","))
  6706. country = groupInfo.VisitCountry.Split(',');
  6707. else if (groupInfo.VisitCountry.Contains(' '))
  6708. country = groupInfo.VisitCountry.Split(' ');
  6709. else if (groupInfo.VisitCountry.Contains(","))
  6710. country = groupInfo.VisitCountry.Split(',');
  6711. else if (groupInfo.VisitCountry.Contains("、"))
  6712. country = groupInfo.VisitCountry.Split('、');
  6713. else if (groupInfo.VisitCountry.Contains("|"))
  6714. country = groupInfo.VisitCountry.Split('|');
  6715. //判断是否是申根国家
  6716. for (int i = 0; i < country.Length; i++)
  6717. {
  6718. if (country[i].ToString() != null)
  6719. {
  6720. //在申根国家中筛选 该国家是否是申根国家
  6721. for (int j = 0; j < _shenGenGuos.Length; j++)
  6722. {
  6723. if (country[i] == _shenGenGuos[j])
  6724. SGGNames.Add(_shenGenGuos[j]); //添加申根国
  6725. }
  6726. }
  6727. }
  6728. //目的地国是否有申根国
  6729. if (SGGNames.Count > 0)
  6730. {
  6731. firstEntryLabel = SGGNames.First();
  6732. membeDescLabel = string.Join(",", SGGNames.ToArray());
  6733. //接收生根国详细信息 存储顺序 起飞日期:Day 起飞时刻:StartTime 抵达日期:ArrivedDate 到达时刻:EndTime
  6734. List<SSGDetails> ListSSGDetails = new List<SSGDetails>();
  6735. //处理申根国家 预定到达时间 预定离开时间 预定停留天数
  6736. for (int i = 0; i < SGGNames.Count; i++)
  6737. {
  6738. //在相同的国家下 得到该航班的信息 //抵达时间 起飞日期:Day 起飞时刻:StartTime 到达时刻:EndTime 抵达日期:ArrivedDate 飞行时间:FlightTime 航司 Fliagtcode 入境口岸
  6739. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  6740. //ResidenceTime1 机票三字码信息
  6741. if (atbc != null)
  6742. {
  6743. string HL_Three = ""; //三字码 Three
  6744. for (int j = 0; j < atbc.Rows.Count; j++)
  6745. {
  6746. HL_Three = atbc.Rows[j]["Three"].ToString();
  6747. if (!string.IsNullOrEmpty(HL_Three))
  6748. {
  6749. string threeCodeTwo = HL_Three.Substring(3);
  6750. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  6751. if (tc != null)
  6752. {
  6753. //首入申根国时间
  6754. if (SGGNames[i] == tc.Country)
  6755. {
  6756. SSGDetails SSGDetails = new SSGDetails()
  6757. {
  6758. Three = atbc.Rows[j]["Three"].ToString(), //三字码
  6759. Fliagtcode = atbc.Rows[j]["Fliagtcode"].ToString(), //航司
  6760. startDate = atbc.Rows[j]["Day"].ToString(), //整理起飞日期
  6761. startTime = atbc.Rows[j]["StartTime"].ToString(), //整理起飞时刻
  6762. endDate = atbc.Rows[j]["ArrivedDate"].ToString(), //整理抵达日期
  6763. endTime = atbc.Rows[j]["EndTime"].ToString() //整理抵达时刻
  6764. };
  6765. ListSSGDetails.Add(SSGDetails);
  6766. }
  6767. }
  6768. }
  6769. }
  6770. }
  6771. }
  6772. ListSSGDetails.Sort((a, b) => a.startDate.CompareTo(b.startDate));
  6773. //得到并计算出入境时间
  6774. if (ListSSGDetails != null)
  6775. {
  6776. RuJingTime = ListSSGDetails.First().endDate + " " + ListSSGDetails.First().endTime.Substring(0, 2) + ":" + ListSSGDetails.First().endTime.Substring(2); //入境时间
  6777. LiJingTime = ListSSGDetails[ListSSGDetails.Count - 1].startDate + " " + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(0, 2) + ":" + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(2); //离境时间
  6778. stayDays = Convert.ToDateTime(LiJingTime).Subtract(Convert.ToDateTime(RuJingTime)).Days.ToString();
  6779. }
  6780. }
  6781. }
  6782. SetFieldValue(formFields, "finalDestinationCountry", membeDescLabel);// 主要目的地成员国(如适用,还包括目的地的其他成员国)
  6783. SetFieldValue(formFields, "firstEntryBorder", firstEntryLabel); // 口岸
  6784. // 申请入境次数
  6785. SetFieldValue(formFields, "requestedEntry_single", "Off"); // 一次入境
  6786. SetFieldValue(formFields, "requestedEntry_two", "Off"); // 两次入境
  6787. SetFieldValue(formFields, "requestedEntry_multiple", "Off"); // 多次入境
  6788. SetFieldValue(formFields, "intendedStayDays", stayDays); // 计划停留天数
  6789. #endregion
  6790. #region 过去三年签证
  6791. SetFieldValue(formFields, "hasPreviousVisas_no", "Yes"); // 否
  6792. SetFieldValue(formFields, "hasPreviousVisas_yes", "Off"); // 是
  6793. //第一年
  6794. SetFieldValue(formFields, "hasPreviousVisas_country1", ""); // 国家
  6795. SetFieldValue(formFields, "hasPreviousVisas_valid1", ""); // 有效期限 起
  6796. SetFieldValue(formFields, "hasPreviousVisas_until1", ""); // 有效期限 止
  6797. //第二年
  6798. SetFieldValue(formFields, "hasPreviousVisas_country2", ""); // 国家
  6799. SetFieldValue(formFields, "hasPreviousVisas_valid2", ""); // 有效期限 起
  6800. SetFieldValue(formFields, "hasPreviousVisas_until2", ""); // 有效期限 止
  6801. //第三年
  6802. SetFieldValue(formFields, "hasPreviousVisas_country3", ""); // 国家
  6803. SetFieldValue(formFields, "hasPreviousVisas_valid3", ""); // 有效期限 起
  6804. SetFieldValue(formFields, "hasPreviousVisas_until3", ""); // 有效期限 止
  6805. #endregion
  6806. #region 此前录过指纹
  6807. SetFieldValue(formFields, "fingerprintsPreviouslyCollected_no", "Yes"); // 否
  6808. SetFieldValue(formFields, "fingerprintsPreviouslyCollected_yes", "Off"); // 是
  6809. SetFieldValue(formFields, "fingerprintsPreviouslyCollected_date", ""); // 如有,请写明日期
  6810. #endregion
  6811. #region 最终目的地入境许可
  6812. SetFieldValue(formFields, "finalDestinationEntryPermit_issued", ""); // 发布者
  6813. SetFieldValue(formFields, "finalDestinationEntryPermit_vaild", ""); // 有效期限 起
  6814. SetFieldValue(formFields, "finalDestinationEntryPermit_until", ""); // 有效期限 止
  6815. #endregion
  6816. #region 计划旅行日期
  6817. SetFieldValue(formFields, "travelDates_arrivalDate", groupInfo.VisitStartDate.ToString("yyyy-MM-dd")); // 出发日期
  6818. SetFieldValue(formFields, "travelDates_departureDate", groupInfo.VisitEndDate.ToString("yyyy-MM-dd")); // 离开日期
  6819. #endregion
  6820. #region 邀请人/酒店信息
  6821. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  6822. .Where(x => x.DiId == groupId)
  6823. //.Where(x => x.City.contains(city))
  6824. .First();
  6825. //酒店住址
  6826. if (hotelInfo != null)
  6827. {
  6828. SetFieldValue(formFields, "accommodationInfo_name", hotelInfo?.HotelName ?? ""); // 招待方的地址和电子邮箱地址
  6829. var otherInfo = $"{hotelInfo.HotelAddress}";
  6830. SetFieldValue(formFields, "accommodationInfo_addressAndNameEmail", otherInfo); // 酒店/临时住宿场所的地址和电子邮箱地址
  6831. SetFieldValue(formFields, "accommodationInfo_tel", hotelInfo?.HotelTel ?? ""); // 电话号码
  6832. }
  6833. #endregion
  6834. #region 邀请公司/组织信息
  6835. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  6836. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  6837. //.Where(x => x.Country.Contains(county))
  6838. //.Where(x => x.Area.Contains(city))
  6839. .First();
  6840. if (oa != null)
  6841. {
  6842. string oaInfo = $"{oa.Client} {oa.Address}";
  6843. SetFieldValue(formFields, "invitingOrganization_addressAndName", oaInfo); // 邀请公司/组织的名称及地址
  6844. string contactInfo = $"{oa?.Contact ?? ""} {oa?.Tel ?? ""} {oa?.EmailOrWeChat ?? ""}";
  6845. SetFieldValue(formFields, "invitingOrganization_contactInfo", contactInfo); // 公司/组织中联系人的姓氏、名字、地址、电话号码以及电子邮箱地址
  6846. SetFieldValue(formFields, "invitingOrganization_tel", oa?.Tel ?? ""); //电话号码(关于)公司/组织
  6847. }
  6848. #endregion
  6849. #region 费用承担
  6850. #region 支持方式
  6851. SetFieldValue(formFields, "costCoverage_applicant", "Off"); // 支持方式
  6852. SetFieldValue(formFields, "costCoverage_applicant_cash", "Off"); // 现金
  6853. SetFieldValue(formFields, "costCoverage_applicant_travellers_cheques", "Off"); // 旅行支票
  6854. SetFieldValue(formFields, "costCoverage_applicant_credit_card", "Off"); // 信用卡
  6855. SetFieldValue(formFields, "costCoverage_applicant_prepaid_accommodation", "Off");// 预付费住宿
  6856. SetFieldValue(formFields, "costCoverage_applicant_prepaid_transport", "Off"); // 预付费交通
  6857. SetFieldValue(formFields, "costCoverage_applicant_other", "Off"); // 其他
  6858. SetFieldValue(formFields, "costCoverage_applicant_other_specify", ""); // 其他(请具体说明)
  6859. #endregion
  6860. #region 由赞助方(主办方、公司、组织)提供
  6861. SetFieldValue(formFields, "costCoverage_host", "Off"); // 由赞助方(主办方、公司、组织)提供
  6862. SetFieldValue(formFields, "costCoverage_host_referred", "Off"); // 在第 30 或 31 栏中提及
  6863. SetFieldValue(formFields, "costCoverage_host_referred_specify", "");// 在第 30 或 31 栏中提及(请具体说明
  6864. SetFieldValue(formFields, "costCoverage_host_other", "Off"); // 其他
  6865. SetFieldValue(formFields, "costCoverage_host_other_specify", ""); // 其他(请具体说明
  6866. //支持方式
  6867. SetFieldValue(formFields, "costCoverage_host_cash", "Off"); // 现金
  6868. SetFieldValue(formFields, "costCoverage_host_accommodation", "Off"); // 提供住宿
  6869. SetFieldValue(formFields, "costCoverage_host_duringStay", "Off"); // 旅行期间的所有费用均由主办方承担
  6870. SetFieldValue(formFields, "costCoverage_host_prepaid_transport", "Off");// 预先支付的交通费用
  6871. SetFieldValue(formFields, "costCoverage_host_other", "Off"); // 其他
  6872. SetFieldValue(formFields, "costCoverage_host_other_specify", ""); // 其他(请具体说明
  6873. #endregion
  6874. #endregion
  6875. #region 欧盟家庭成员个人信息
  6876. SetFieldValue(formFields, "euFamilyMember_surname", ""); // 姓氏(家族名)
  6877. SetFieldValue(formFields, "euFamilyMember_firstname", ""); // 名字(名字)
  6878. SetFieldValue(formFields, "euFamilyMember_birthday", ""); // 出生日期 (日-月-年)
  6879. SetFieldValue(formFields, "euFamilyMember_nationality", "");// 国籍
  6880. SetFieldValue(formFields, "euFamilyMember_number", ""); // 旅行证件或身份证号码
  6881. #endregion
  6882. #region 欧盟家庭关系
  6883. SetFieldValue(formFields, "familyRelationship_spouse", "Off"); // 夫妻
  6884. SetFieldValue(formFields, "familyRelationship_child", "Off"); // 子女
  6885. SetFieldValue(formFields, "familyRelationship_grandchild", "Off"); // 孙子女
  6886. SetFieldValue(formFields, "familyRelationship_dependent", "Off"); // 有赡养关系的长辈
  6887. #endregion
  6888. // 申请人的家庭住址和电子邮箱地址
  6889. string applicantAddressAndEmail = $"{custInfo.Address} {custInfo.Email}";
  6890. SetFieldValue(formFields, "applicant_address_and_email", applicantAddressAndEmail);
  6891. // 申请人的电话
  6892. SetFieldValue(formFields, "applicant_tel", custInfo.Tel);
  6893. #region 在非当前国籍所属国家的居住情况 “默认空”
  6894. SetFieldValue(formFields, "uncurrent_count_no", "Yes"); // 否
  6895. SetFieldValue(formFields, "uncurrent_count_yes", "Off"); // 是
  6896. SetFieldValue(formFields, "uncurrent_country_residence", "");// 居留许可或同等证明
  6897. SetFieldValue(formFields, "uncurrent_country_no", ""); // No
  6898. SetFieldValue(formFields, "uncurrent_country_valid_until", "");// 有效期至
  6899. #endregion
  6900. SetFieldValue(formFields, "declaration_place", ""); // 地点
  6901. SetFieldValue(formFields, "declaration_signture", "");// 签名
  6902. var date_year = DateTime.Now.Year.ToString();
  6903. var date_month = DateTime.Now.Month.ToString();
  6904. var date_day = DateTime.Now.Day.ToString();
  6905. SetFieldValue(formFields, "place_and_date", DateTime.Now.ToString("yyyy-MM-dd")); // 申请日期
  6906. var applicant_name = custInfo.LastName + custInfo.FirstName;
  6907. SetFieldValue(formFields, "signture", applicant_name); // 申请人姓名
  6908. #endregion
  6909. filePaths.Add(outputPath);
  6910. }
  6911. catch (Exception ex)
  6912. {
  6913. return Ok(JsonView(false, $"生成PDF文件时出错:{ex.Message}"));
  6914. }
  6915. finally
  6916. {
  6917. // 按正确顺序关闭资源
  6918. stamper?.Close();
  6919. reader?.Close();
  6920. templateStream?.Close();
  6921. outputStream?.Close();
  6922. }
  6923. #endregion
  6924. }
  6925. break;
  6926. case 8: // 西班牙
  6927. visaTypeName = $"西班牙签证申请表";
  6928. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  6929. var spianSavePath = $"{fileServerPath}{visaTypeName}/";
  6930. if (!Directory.Exists(spianSavePath)) Directory.CreateDirectory(spianSavePath);
  6931. if (!System.IO.File.Exists(currTempPath))
  6932. {
  6933. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  6934. }
  6935. foreach (var custInfo in groupCustInfos)
  6936. {
  6937. EncryptionProcessor.DecryptProperties(custInfo);
  6938. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  6939. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  6940. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  6941. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  6942. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  6943. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  6944. string templateKey = $"{custInfo.Id}_{custInfo.LastName}{custInfo.FirstName}";
  6945. //var pdfData = fdfDatas.GetValueOrDefault(templateKey) ?? new Dictionary<string, string>();
  6946. var pdfData = new Dictionary<string, string>();
  6947. #region 生成文件
  6948. PdfReader reader = null;
  6949. FileStream templateStream = null;
  6950. FileStream outputStream = null;
  6951. PdfStamper stamper = null;
  6952. try
  6953. {
  6954. string outputPath = $"{spianSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  6955. //读取模板文件
  6956. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  6957. reader = new PdfReader(templateStream);
  6958. //创建输出文件
  6959. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  6960. stamper = new PdfStamper(reader, outputStream);
  6961. AcroFields formFields = stamper.AcroFields;
  6962. #region 设置文本值
  6963. SetFieldValue(formFields, "surname", pdfData.GetSafeString("surname")); // 姓 英文
  6964. SetFieldValue(formFields, "birth_surname", pdfData.GetSafeString("birth_surname")); // 出生时姓 英文
  6965. SetFieldValue(formFields, "firstname", pdfData.GetSafeString("firstname")); // 名 英文
  6966. SetFieldValue(formFields, "birthday", pdfData.GetSafeString("birthday")); // 出生日期
  6967. SetFieldValue(formFields, "birth_place", pdfData.GetSafeString("birth_place")); // 出生地区
  6968. SetFieldValue(formFields, "birth_country", pdfData.GetSafeString("birth_country")); // 出生国籍
  6969. SetFieldValue(formFields, "current_nationality", pdfData.GetSafeString("current_nationality")); // 现国籍
  6970. SetFieldValue(formFields, "birth_nationality", pdfData.GetSafeString("birth_nationality")); // 出生国籍
  6971. SetFieldValue(formFields, "other_nacionality", pdfData.GetSafeString("other_nacionality")); // 其他国籍
  6972. #region 设置性别
  6973. //清除性别
  6974. SetFieldValue(formFields, "sex_male", "Off"); // 性别 - 男
  6975. SetFieldValue(formFields, "sex_female", "Off"); // 性别 - 女
  6976. SetFieldValue(formFields, "sex_other", "Off"); // 性别 - 其他
  6977. //设置性别
  6978. var sex = pdfData.GetSafeString("sex");
  6979. if (sex.Equals("0")) // 男
  6980. {
  6981. SetFieldValue(formFields, "sex_male", "Yes"); // 性别 - 男
  6982. }
  6983. else if (sex.Equals("1")) // 女
  6984. {
  6985. SetFieldValue(formFields, "sex_female", "Yes"); // 性别 - 女
  6986. }
  6987. else
  6988. {
  6989. SetFieldValue(formFields, "sex_other", "Yes"); // 性别 - 其他
  6990. }
  6991. #endregion
  6992. #region 婚姻状态
  6993. //清除婚姻状况
  6994. SetFieldValue(formFields, "marital_single", "Off"); // 婚姻状况 - 未婚
  6995. SetFieldValue(formFields, "marital_married", "Off"); // 婚姻状况 - 已婚
  6996. SetFieldValue(formFields, "marital_registered_union", "Off");// 婚姻状况 - 注册伴侣关系
  6997. SetFieldValue(formFields, "marital_separated", "Off"); // 婚姻状况 - 分居
  6998. SetFieldValue(formFields, "marital_divorced", "Off"); // 婚姻状况 - 离异
  6999. SetFieldValue(formFields, "marital_widower", "Off"); // 婚姻状况 - 丧偶
  7000. SetFieldValue(formFields, "marital_other", "Off"); // 婚姻状况 - 其他
  7001. SetFieldValue(formFields, "marital_other_specify", ""); // 婚姻状况 - 其他(请具体说明)
  7002. var maritalStatus = pdfData.GetSafeString("marital_status");
  7003. //设置婚姻状况
  7004. switch (maritalStatus)
  7005. {
  7006. case "1": // 未婚
  7007. SetFieldValue(formFields, "marital_single", "Yes");
  7008. break;
  7009. case "2": // 已婚
  7010. SetFieldValue(formFields, "marital_married", "Yes");
  7011. break;
  7012. case "3": // 离婚/离异
  7013. SetFieldValue(formFields, "marital_divorced", "Yes");
  7014. break;
  7015. case "4": // 分居
  7016. SetFieldValue(formFields, "marital_separated", "Yes");
  7017. break;
  7018. case "5": // 丧偶
  7019. SetFieldValue(formFields, "marital_widower", "Yes");
  7020. break;
  7021. case "6": // 其他
  7022. SetFieldValue(formFields, "marital_other", "Yes");
  7023. break;
  7024. }
  7025. #endregion
  7026. // 父母的监护权(针对未成年人)/法定监护人(姓氏、名字、地址(若与申请人的地址不同)、电话号码、电子邮箱地址以及国籍)
  7027. SetFieldValue(formFields, "legal_guardian_info", pdfData.GetSafeString("legal_guardian_info"));
  7028. //(如适用)国民身份号码
  7029. SetFieldValue(formFields, "national_identity_number", pdfData.GetSafeString("national_identity_number"));
  7030. #region 护照信息
  7031. //清除值
  7032. SetFieldValue(formFields, "passport_orfinary", "Off"); // 旅行证件类型 - 普通护照
  7033. SetFieldValue(formFields, "passport_diplomatic", "Off"); // 旅行证件类型 - 外交护照
  7034. SetFieldValue(formFields, "passport_service", "Off"); // 旅行证件类型 - 公务护照
  7035. SetFieldValue(formFields, "passport_official", "Off"); // 旅行证件类型 - 因公护照
  7036. SetFieldValue(formFields, "passport_other", "Off"); // 旅行证件类型 - 特别护照
  7037. SetFieldValue(formFields, "passport_other_specify", ""); // 其他旅行证件(请注明)
  7038. #region 设置 护照信息
  7039. string visaName = pdfData.GetSafeString("passport_type_name");
  7040. if (visaName.contains("普通")) SetFieldValue(formFields, "passport_orfinary", "Yes"); // 旅行证件类型 - 普通护照
  7041. else if (visaName.contains("外交")) SetFieldValue(formFields, "passport_diplomatic", "Yes"); // 旅行证件类型 - 外交护照
  7042. else if (visaName.contains("公务")) SetFieldValue(formFields, "passport_service", "Yes"); // 旅行证件类型 - 公务护照
  7043. else if (visaName.contains("因公")) SetFieldValue(formFields, "passport_official", "Yes"); // 旅行证件类型 - 因公护照
  7044. else // 旅行证件类型 - 特别护照
  7045. {
  7046. SetFieldValue(formFields, "passport_other", "Yes");
  7047. SetFieldValue(formFields, "passport_other_specify", "");
  7048. }
  7049. SetFieldValue(formFields, "travel_number", pdfData.GetSafeString("travel_number")); // 签证 编号
  7050. SetFieldValue(formFields, "travel_issues_country", pdfData.GetSafeString("travel_issues_country"));// 签发 国
  7051. SetFieldValue(formFields, "travel_issue_date", pdfData.GetSafeString("travel_issue_date")); // 签发日期
  7052. SetFieldValue(formFields, "travel_valid_until", pdfData.GetSafeString("travel_valid_until")); // 有效期至
  7053. #endregion
  7054. #endregion
  7055. #region 欧盟家庭成员个人信息
  7056. SetFieldValue(formFields, "ue_family_info", pdfData.GetSafeString("ue_family_info")); // 个人信息
  7057. SetFieldValue(formFields, "ue_family_surname", pdfData.GetSafeString("ue_family_surname")); // 姓氏(家族名)
  7058. SetFieldValue(formFields, "ue_family_firstname", pdfData.GetSafeString("ue_family_firstname")); // 名字(名字)
  7059. SetFieldValue(formFields, "ue_family_birthday", pdfData.GetSafeString("ue_family_birthday")); // 出生日期 (日-月-年)
  7060. SetFieldValue(formFields, "ue_family_nationality", pdfData.GetSafeString("ue_family_nationality")); // 国籍
  7061. SetFieldValue(formFields, "ue_family_travel_number", pdfData.GetSafeString("ue_family_travel_number"));// 旅行证件或身份证号码
  7062. #endregion
  7063. #region 欧盟家庭关系
  7064. SetFieldValue(formFields, "eu_family_relationship_spouse", "Off"); // 夫妻
  7065. SetFieldValue(formFields, "eu_family_relationship_child", "Off"); // 子女
  7066. SetFieldValue(formFields, "eu_family_relationship_grandchild", "Off"); // 孙子女
  7067. SetFieldValue(formFields, "eu_family_relationship_dependent", "Off"); // 受养人
  7068. SetFieldValue(formFields, "eu_family_relationship_registered_partnership", "Off"); // 注册伴侣
  7069. SetFieldValue(formFields, "eu_family_relationship_other", pdfData.GetSafeString("eu_family_relationship_other")); // 其他
  7070. SetFieldValue(formFields, "eu_family_relationship_other_specify", pdfData.GetSafeString("eu_family_relationship_other_specify")); // 其他
  7071. #endregion
  7072. // 申请人的家庭住址和电子邮箱地址
  7073. SetFieldValue(formFields, "applicant_address_and_email", pdfData.GetSafeString("applicant_address_and_email"));
  7074. // 申请人的电话
  7075. SetFieldValue(formFields, "applicant_tel", pdfData.GetSafeString("applicant_tel"));
  7076. #region 是否在非国籍国居住 默认否
  7077. SetFieldValue(formFields, "unresidente_no", "Yes"); // 否
  7078. SetFieldValue(formFields, "unresidente_yes", "Off"); // 是
  7079. SetFieldValue(formFields, "unresidente_equivalen", ""); // 居住许可证
  7080. SetFieldValue(formFields, "unresidente_number", ""); // 编号
  7081. SetFieldValue(formFields, "unresidente_vaild", ""); // 有效期限
  7082. #endregion
  7083. #region 职业
  7084. // 当前职业
  7085. SetFieldValue(formFields, "occupation", pdfData.GetSafeString("fileName"));
  7086. //雇主及雇主的地址和电话号码。
  7087. SetFieldValue(formFields, "employer_info", pdfData.GetSafeString("employer_info"));
  7088. #endregion
  7089. #region 此次行程的目的
  7090. //清除值
  7091. SetFieldValue(formFields, "purpose_tourism", "Off"); // 旅游
  7092. SetFieldValue(formFields, "purpose_business", "Off"); // 商务
  7093. SetFieldValue(formFields, "purpose_visiting_family_friends", "Off");// 庆祝亲友团聚
  7094. SetFieldValue(formFields, "purpose_cultural", "Off"); // 文化交流
  7095. SetFieldValue(formFields, "purpose_sports", "Off"); // 体育
  7096. SetFieldValue(formFields, "purpose_official", "Off"); // 官方访问
  7097. SetFieldValue(formFields, "purpose_medical_reasons", "Off"); // 医疗
  7098. SetFieldValue(formFields, "purpose_study", "Off"); // 学习
  7099. SetFieldValue(formFields, "purpose_airport_transit", "Off"); // 机场过境
  7100. SetFieldValue(formFields, "purpose_other", "Off"); // 其他
  7101. SetFieldValue(formFields, "purpose_other_specify", ""); // 其他 - 备注
  7102. var visit_purpose = pdfData.GetSafeString("purpose");
  7103. var visit_purpose_remark = pdfData.GetSafeString("purpose_other_specify");
  7104. if (!string.IsNullOrEmpty(visit_purpose))
  7105. {
  7106. if (visit_purpose.contains("tourism"))
  7107. {
  7108. SetFieldValue(formFields, "purpose_tourism", "Yes"); // 旅游
  7109. }
  7110. else if (visit_purpose.contains("business"))
  7111. {
  7112. SetFieldValue(formFields, "purpose_business", "Yes"); // 商务
  7113. }
  7114. else if (visit_purpose.contains("visiting_family_friends"))
  7115. {
  7116. SetFieldValue(formFields, "purpose_visiting_family_friends", "Yes");// 庆祝亲友团聚
  7117. }
  7118. else if (visit_purpose.contains("cultural") || visit_purpose.contains("tourism"))
  7119. {
  7120. SetFieldValue(formFields, "purpose_cultural", "Yes"); // 文化交流
  7121. }
  7122. else if (visit_purpose.contains("sports"))
  7123. {
  7124. SetFieldValue(formFields, "purpose_sports", "Yes"); // 体育
  7125. }
  7126. else if (visit_purpose.contains("official"))
  7127. {
  7128. SetFieldValue(formFields, "purpose_official", "Yes"); // 官方访问
  7129. }
  7130. else if (visit_purpose.contains("medical_reasons") || visit_purpose.contains("medical"))
  7131. {
  7132. SetFieldValue(formFields, "purpose_medical_reasons", "Yes"); // 医疗原因
  7133. }
  7134. else if (visit_purpose.contains("study"))
  7135. {
  7136. SetFieldValue(formFields, "purpose_study", "Yes"); // 学习
  7137. }
  7138. else if (visit_purpose.contains("airport_transit") || visit_purpose.contains("transit"))
  7139. {
  7140. SetFieldValue(formFields, "purpose_airport_transit", "Yes"); // 机场过境
  7141. }
  7142. else
  7143. {
  7144. SetFieldValue(formFields, "purpose_other", "Yes"); // 其他
  7145. SetFieldValue(formFields, "purpose_other_specify", visit_purpose_remark);// 其他 - 备注
  7146. }
  7147. }
  7148. #endregion
  7149. #region 目的国相关信息
  7150. // 关于停留目的的补充说明
  7151. SetFieldValue(formFields, "stay_info", pdfData.GetSafeString("stay_info"));
  7152. SetFieldValue(formFields, "member_destination", pdfData.GetSafeString("member_destination")); // 主要目的地成员国(如适用,还包括目的地的其他成员国)
  7153. SetFieldValue(formFields, "member_first_entry", pdfData.GetSafeString("member_first_entry")); // 首入申根国标签
  7154. // 申请入境次数
  7155. string request_entry = pdfData.GetSafeString("request_entry");
  7156. switch (request_entry)
  7157. {
  7158. case "1":
  7159. SetFieldValue(formFields, "request_entry_one", "Yes"); // 一次入境
  7160. break;
  7161. case "2":
  7162. SetFieldValue(formFields, "request_entry_two", "Yes"); // 两次入境
  7163. break;
  7164. case "3":
  7165. SetFieldValue(formFields, "request_entry_multiple", "Yes"); // 多次入境
  7166. break;
  7167. }
  7168. SetFieldValue(formFields, "schengen_first_area_arrival", pdfData.GetSafeString("schengen_first_area_arrival")); // 首次抵达日期
  7169. SetFieldValue(formFields, "schengen_first_area_departure", pdfData.GetSafeString("schengen_first_area_departure")); // 首次抵达日期
  7170. #endregion
  7171. #region 此前录过指纹
  7172. var fingerprints = pdfData.GetSafeString("schengen_fingerprints_status");
  7173. switch (fingerprints)
  7174. {
  7175. // 是
  7176. case "1":
  7177. SetFieldValue(formFields, "schengen_fingerprints_yes", "Yes"); // 是
  7178. SetFieldValue(formFields, "schengen_fingerprints_date", ""); // 如有,请写明日期
  7179. SetFieldValue(formFields, "schengen_fingerprints_visa_no", "");// 编号
  7180. break;
  7181. // 否
  7182. case "2":
  7183. SetFieldValue(formFields, "schengen_fingerprints_no", "Yes"); // 否
  7184. break;
  7185. }
  7186. #endregion
  7187. #region 最终目的地入境许可
  7188. SetFieldValue(formFields, "entry_permit_issued", pdfData.GetSafeString("entry_permit_issued")); // 发布者
  7189. SetFieldValue(formFields, "entry_permit_valid", pdfData.GetSafeString("entry_permit_valid")); // 有效期限 起
  7190. SetFieldValue(formFields, "entry_permit_until", pdfData.GetSafeString("entry_permit_until")); // 有效期限 止
  7191. #endregion
  7192. #region 邀请人/酒店信息
  7193. SetFieldValue(formFields, "schengen_inviting_name", pdfData.GetSafeString("schengen_inviting_name")); // 招待方的酒店、邀请人 名称
  7194. SetFieldValue(formFields, "schengen_inviting_hotel_address_email", pdfData.GetSafeString("schengen_inviting_hotel_address_email")); // 酒店/临时住宿场所的地址和电子邮箱地址
  7195. SetFieldValue(formFields, "schengen_inviting_hotel_tel", pdfData.GetSafeString("schengen_inviting_hotel_tel")); // 电话号码
  7196. #endregion
  7197. #region 邀请公司/组织信息
  7198. SetFieldValue(formFields, "inviting_name_address", pdfData.GetSafeString("inviting_name_address")); // 邀请公司/组织的名称及地址
  7199. SetFieldValue(formFields, "inviting_info", pdfData.GetSafeString("inviting_info")); // 公司/组织中联系人的姓氏、名字、地址、电话号码以及电子邮箱地址
  7200. SetFieldValue(formFields, "inviting_tel", pdfData.GetSafeString("inviting_tel")); // 电话号码(关于)公司/组织
  7201. #endregion
  7202. #region 费用承担
  7203. #region 支持方式
  7204. SetFieldValue(formFields, "cost_covered_herself", "Off"); // 支持方式
  7205. SetFieldValue(formFields, "cost_covered_herself_cash", "Off"); // 现金
  7206. SetFieldValue(formFields, "cost_covered_herself_cheques", "Off"); // 旅行支票
  7207. SetFieldValue(formFields, "cost_covered_herself_credit", "Off"); // 信用卡
  7208. SetFieldValue(formFields, "cost_covered_herself_accomodation", "Off"); // 预付费住宿
  7209. SetFieldValue(formFields, "cost_covered_herself_transport", "Off"); // 预付费交通
  7210. SetFieldValue(formFields, "cost_covered_herself_other", "Off"); // 其他
  7211. SetFieldValue(formFields, "cost_covered_herself_other_specift", ""); // 其他(请具体说明)
  7212. #endregion
  7213. #region 由赞助方(主办方、公司、组织)提供
  7214. SetFieldValue(formFields, "cost_covered_sponsor", "Off"); // 由赞助方(主办方、公司、组织)提供
  7215. SetFieldValue(formFields, "cost_covered_sponsor_referred", "Off"); // 在第 30 或 31 栏中提及
  7216. SetFieldValue(formFields, "cost_covered_sponsor_other", "Yes"); // 其他
  7217. SetFieldValue(formFields, "cost_covered_sponsor_other_specify", pdfData.GetSafeString("cost_covered_sponsor_other_specify")); // 其他(请具体说明
  7218. //支持方式
  7219. SetFieldValue(formFields, "cost_covered_sponsor_cash", "Off"); // 现金
  7220. SetFieldValue(formFields, "cost_covered_sponsor_accomodation", "Off"); // 提供住宿
  7221. SetFieldValue(formFields, "cost_covered_sponsor_during_stay", "Off"); // 旅行期间的所有费用均由主办方承担
  7222. SetFieldValue(formFields, "cost_covered_sponsor_transport", "Off"); // 预先支付的交通费用
  7223. SetFieldValue(formFields, "cost_covered_sponsor_other", "Off"); // 其他
  7224. SetFieldValue(formFields, "cost_covered_sponsor_other_specify", ""); // 其他(请具体说明
  7225. #endregion
  7226. #endregion
  7227. #endregion
  7228. filePaths.Add(outputPath);
  7229. }
  7230. catch (Exception ex)
  7231. {
  7232. return Ok(JsonView(false, $"生成PDF文件时出错:{ex.Message}"));
  7233. }
  7234. finally
  7235. {
  7236. // 展平表单
  7237. stamper.FormFlattening = true;
  7238. // 按正确顺序关闭资源
  7239. stamper?.Close();
  7240. reader?.Close();
  7241. templateStream?.Close();
  7242. outputStream?.Close();
  7243. }
  7244. #endregion
  7245. }
  7246. break;
  7247. default:
  7248. return Ok(JsonView(false, "正在开发中,请等待。。。"));
  7249. }
  7250. // 压缩文件
  7251. var zipFilePathName = $"{groupInfo.TeamName}({visaTypeName}).zip";
  7252. var zipFilePath = $"{fileServerPath}{zipFilePathName}";
  7253. // 关键修复:先获取压缩文件的上级目录,检查并创建(如果不存在)
  7254. string zipDirectory = Path.GetDirectoryName(zipFilePath);
  7255. if (!Directory.Exists(zipDirectory))
  7256. {
  7257. // CreateDirectory会自动创建所有不存在的上级目录,无需手动逐层创建
  7258. Directory.CreateDirectory(zipDirectory);
  7259. }
  7260. using (var zipFileStream = new FileStream(zipFilePath, FileMode.Create))
  7261. {
  7262. using (var zipArchive = new ZipArchive(zipFileStream, ZipArchiveMode.Create))
  7263. {
  7264. foreach (string filePath in filePaths)
  7265. {
  7266. // 增加空值/空字符串校验,提升代码健壮性
  7267. if (!string.IsNullOrEmpty(filePath) && System.IO.File.Exists(filePath))
  7268. {
  7269. // 获取文件名
  7270. string fileName = Path.GetFileName(filePath);
  7271. // 将文件添加到ZIP归档中
  7272. zipArchive.CreateEntryFromFile(filePath, fileName);
  7273. }
  7274. }
  7275. }
  7276. }
  7277. url = $"{serverPath}{zipFilePathName}";
  7278. if (!string.IsNullOrEmpty(url))
  7279. {
  7280. return Ok(JsonView(true, "操作成功", url));
  7281. }
  7282. return Ok(JsonView(false, "操作失败!"));
  7283. }
  7284. /// <summary>
  7285. /// 团组&签证 New
  7286. /// 签证文申请表下载 批量
  7287. /// </summary>
  7288. /// <param name="groupId"></param>
  7289. /// <param name="fileTypeId"></param>
  7290. /// <param name="language">
  7291. /// 下载语言:1-中文,2-英文
  7292. /// </param>
  7293. /// <returns></returns>
  7294. [HttpGet]
  7295. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7296. public async Task<IActionResult> VisaFileDownload(int groupId, int fileTypeId, int language = 1)
  7297. {
  7298. if (!_visaTypeInit.TryGetValue(fileTypeId, out _))
  7299. {
  7300. return Ok(JsonView(false, "请选择正确的文件类型!"));
  7301. }
  7302. var visaBasicData = await GetVisaBasicData(groupId);
  7303. if (visaBasicData == null)
  7304. {
  7305. return Ok(JsonView(false, "基础数据信息为空!"));
  7306. }
  7307. if (visaBasicData.groupInfo == null)
  7308. {
  7309. return Ok(JsonView(false, "团组信息不存在!"));
  7310. }
  7311. if (visaBasicData.groupClients.Count < 1)
  7312. {
  7313. return Ok(JsonView(false, "该团组下暂无团组名单!"));
  7314. }
  7315. string group_unique_name = $"{visaBasicData.groupInfo.TeamName}";
  7316. //访问路径
  7317. var serverPath = $"http://132.232.92.186:24/Office/Word/VisaClientData/Downloads/{group_unique_name}/";
  7318. // 服务器存储文件位置
  7319. var fileServerPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Downloads/{group_unique_name}/";
  7320. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(fileServerPath);
  7321. var filePaths = new List<string>();
  7322. #region 多个下载
  7323. foreach (var custInfo in visaBasicData.groupCustInfos)
  7324. {
  7325. var groupCustInfos = new List<Crm_DeleClient>() { custInfo };
  7326. var idInfo = visaBasicData.certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  7327. var passportInfo = visaBasicData.certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  7328. var clinetInfo = visaBasicData.companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  7329. var currSchoolInfos = visaBasicData.schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  7330. var currFamilyInfos = visaBasicData.familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  7331. var currCompanyInfos = visaBasicData.companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  7332. var generatorFileReq = new GeneratorFileReq
  7333. {
  7334. groupId = groupId,
  7335. fileTypeId = fileTypeId,
  7336. dcIds = custInfo.Id,
  7337. fileServerPath = fileServerPath,
  7338. language = language,
  7339. dataBody = new DataBody
  7340. {
  7341. groupInfo = visaBasicData.groupInfo,
  7342. groupClients = visaBasicData.groupClients,
  7343. groupCustInfos = groupCustInfos,
  7344. familyInfos = visaBasicData.familyInfos,
  7345. certInfos = visaBasicData.certInfos,
  7346. companyInfos = visaBasicData.companyInfos,
  7347. schoolInfos = visaBasicData.schoolInfos
  7348. }
  7349. };
  7350. (bool resStatus, string saveUrl, string downloadUrl) = await GeneratorFileAsync(generatorFileReq);
  7351. if (resStatus)
  7352. {
  7353. filePaths.Add(saveUrl);
  7354. }
  7355. }
  7356. #endregion
  7357. // 压缩文件
  7358. var zipFilePathName = $"{visaBasicData.groupInfo.TeamName}({_visaTypeInit.GetValueOrDefault(fileTypeId)}签证申请表).zip";
  7359. var zipFilePath = $"{fileServerPath}{zipFilePathName}";
  7360. // 关键修复:先获取压缩文件的上级目录,检查并创建(如果不存在)
  7361. string zipDirectory = Path.GetDirectoryName(zipFilePath);
  7362. if (!Directory.Exists(zipDirectory))
  7363. {
  7364. // CreateDirectory会自动创建所有不存在的上级目录,无需手动逐层创建
  7365. Directory.CreateDirectory(zipDirectory);
  7366. }
  7367. using (var zipFileStream = new FileStream(zipFilePath, FileMode.Create))
  7368. {
  7369. using (var zipArchive = new ZipArchive(zipFileStream, ZipArchiveMode.Create))
  7370. {
  7371. foreach (string filePath in filePaths)
  7372. {
  7373. // 增加空值/空字符串校验,提升代码健壮性
  7374. if (!string.IsNullOrEmpty(filePath) && System.IO.File.Exists(filePath))
  7375. {
  7376. // 获取文件名
  7377. string fileName = Path.GetFileName(filePath);
  7378. // 将文件添加到ZIP归档中
  7379. zipArchive.CreateEntryFromFile(filePath, fileName);
  7380. }
  7381. }
  7382. }
  7383. }
  7384. url = $"{serverPath}{zipFilePathName}";
  7385. if (!string.IsNullOrEmpty(url))
  7386. {
  7387. return Ok(JsonView(true, "操作成功", url));
  7388. }
  7389. return Ok(JsonView(false, "操作失败!"));
  7390. }
  7391. /// <summary>
  7392. /// 团组&签证 New
  7393. /// 签证文申请表下载 单个文件生成后提供下载地址
  7394. /// </summary>
  7395. /// <param name="groupId"></param>
  7396. /// <param name="fileTypeId"></param>
  7397. /// <param name="dcId">客户资料Id(dcId)</param>
  7398. /// <param name="language">
  7399. /// 下载语言:1-中文,2-英文
  7400. /// </param>
  7401. /// <returns></returns>
  7402. [HttpGet]
  7403. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7404. public async Task<IActionResult> VisaFileDownloadSingle(int groupId, int fileTypeId, int dcId, int language = 1)
  7405. {
  7406. if (!_visaTypeInit.TryGetValue(fileTypeId, out _))
  7407. {
  7408. return Ok(JsonView(false, "请选择正确的文件类型!"));
  7409. }
  7410. var visaBasicData = await GetVisaBasicData(groupId);
  7411. if (visaBasicData == null)
  7412. {
  7413. return Ok(JsonView(false, "基础数据信息为空!"));
  7414. }
  7415. if (visaBasicData.groupInfo == null)
  7416. {
  7417. return Ok(JsonView(false, "团组信息不存在!"));
  7418. }
  7419. if (visaBasicData.groupClients.Count < 1)
  7420. {
  7421. return Ok(JsonView(false, "该团组下暂无团组名单!"));
  7422. }
  7423. string group_unique_name = $"{visaBasicData.groupInfo.TeamName}";
  7424. //访问路径
  7425. var serverPath = $"http://132.232.92.186:24/Office/Word/VisaClientData/Downloads/{group_unique_name}/";
  7426. // 服务器存储文件位置
  7427. var fileServerPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Downloads/{group_unique_name}/";
  7428. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(fileServerPath);
  7429. var generatorFileReq = new GeneratorFileReq
  7430. {
  7431. groupId = groupId,
  7432. fileTypeId = fileTypeId,
  7433. dcIds = dcId,
  7434. fileServerPath = fileServerPath,
  7435. language = language,
  7436. dataBody = new DataBody
  7437. {
  7438. groupInfo = visaBasicData.groupInfo,
  7439. groupClients = visaBasicData.groupClients.Where(x => x.ClientId == dcId).ToList(),
  7440. groupCustInfos = visaBasicData.groupCustInfos.Where(x => x.Id == dcId).ToList(),
  7441. familyInfos = visaBasicData.familyInfos.Where(x => x.DcId == dcId).ToList(),
  7442. certInfos = visaBasicData.certInfos.Where(x => x.DcId == dcId).ToList(),
  7443. companyInfos = visaBasicData.companyInfos.Where(x => x.DcId == dcId).ToList(),
  7444. schoolInfos = visaBasicData.schoolInfos.Where(x => x.DcId == dcId).ToList()
  7445. }
  7446. };
  7447. (bool resStatus, string msg, string downloadUrl) = await GeneratorFileAsync(generatorFileReq);
  7448. if (resStatus)
  7449. {
  7450. return Ok(JsonView(true, "操作成功", downloadUrl));
  7451. }
  7452. return Ok(JsonView(false, msg));
  7453. }
  7454. /// <summary>
  7455. /// 团组&签证 New
  7456. /// 签证文申请表下载 派遣函
  7457. /// </summary>
  7458. /// <param name="groupId"></param>
  7459. /// <param name="dcId">客户资料Id(dcId)</param>
  7460. /// <returns></returns>
  7461. [HttpGet]
  7462. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7463. public async Task<IActionResult> VisaFileDispatchDownload(int groupId, int dcId)
  7464. {
  7465. var visaBasicData = await GetVisaBasicData(groupId);
  7466. if (visaBasicData == null)
  7467. {
  7468. return Ok(JsonView(false, "基础数据信息为空!"));
  7469. }
  7470. if (visaBasicData.groupInfo == null)
  7471. {
  7472. return Ok(JsonView(false, "团组信息不存在!"));
  7473. }
  7474. if (visaBasicData.groupClients.Count < 1)
  7475. {
  7476. return Ok(JsonView(false, "该团组下暂无团组名单!"));
  7477. }
  7478. (bool resStatus, string msg, string downloadUrl) = await GeneratorDispatchAsync(new DataBody
  7479. {
  7480. groupInfo = visaBasicData.groupInfo,
  7481. groupClients = visaBasicData.groupClients.Where(x => x.ClientId == dcId).ToList(),
  7482. groupCustInfos = visaBasicData.groupCustInfos.Where(x => x.Id == dcId).ToList(),
  7483. familyInfos = visaBasicData.familyInfos.Where(x => x.DcId == dcId).ToList(),
  7484. certInfos = visaBasicData.certInfos.Where(x => x.DcId == dcId).ToList(),
  7485. companyInfos = visaBasicData.companyInfos.Where(x => x.DcId == dcId).ToList(),
  7486. schoolInfos = visaBasicData.schoolInfos.Where(x => x.DcId == dcId).ToList()
  7487. });
  7488. if (resStatus)
  7489. {
  7490. return Ok(JsonView(true, "操作成功", downloadUrl));
  7491. }
  7492. return Ok(JsonView(false, msg));
  7493. }
  7494. /// <summary>
  7495. /// 获取签证基础数据源
  7496. /// </summary>
  7497. /// <param name="groupId"></param>
  7498. /// <returns></returns>
  7499. private async Task<DataBody> GetVisaBasicData(int groupId)
  7500. {
  7501. var data = new DataBody();
  7502. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0 && x.Id == groupId).First();
  7503. if (groupInfo == null) return data;
  7504. // 基础数据
  7505. // 团组客户名单
  7506. var groupClients = await _sqlSugar.Queryable<Grp_TourClientList>()
  7507. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  7508. .ToListAsync();
  7509. if (groupClients.Count < 1) return data;
  7510. var groupClientIds = groupClients.Select(x => x.ClientId).ToList();
  7511. // 团组客户详细信息
  7512. var groupCustInfos = _sqlSugar.Queryable<Crm_DeleClient>().Where(x => x.IsDel == 0 && groupClientIds.Contains(x.Id)).ToList();
  7513. // 解密
  7514. foreach (var custInfo in groupCustInfos)
  7515. {
  7516. EncryptionProcessor.DecryptProperties(custInfo);
  7517. }
  7518. // 家庭成员资料
  7519. var familyInfos = _sqlSugar.Queryable<Crm_VisaCustomerFamily>().Where(x => x.IsDel == 0 && groupClientIds.Contains(x.DcId)).ToList();
  7520. // 公司资料
  7521. var companyInfo‌‌s = _sqlSugar.Queryable<Crm_VisaCustomerCompany>().Where(x => x.IsDel == 0 && groupClientIds.Contains(x.DcId)).ToList();
  7522. // 学校资料
  7523. var schoolInfos = _sqlSugar.Queryable<Crm_VisaCustomerSchool>().Where(x => x.IsDel == 0 && groupClientIds.Contains(x.DcId)).ToList();
  7524. /* 证件类型
  7525. *
  7526. * 773 身份证
  7527. * 774 护照
  7528. * 775 学生证
  7529. * 776 军人证
  7530. * 777 回乡证
  7531. * 778 台胞证
  7532. * 779 港澳通行证
  7533. * 780 国际海员证
  7534. * 781 外国人永久居留证
  7535. * 782 旅行证
  7536. * 783 台湾通行证
  7537. * 784 港澳台居住证
  7538. * 785 其他
  7539. */
  7540. // 证件资料
  7541. var certInfos = _sqlSugar.Queryable<Crm_CustomerCert>().Where(x => x.IsDel == 0 && groupClientIds.Contains(x.DcId)).ToList();
  7542. return new DataBody
  7543. {
  7544. groupInfo = groupInfo,
  7545. groupClients = groupClients,
  7546. groupCustInfos = groupCustInfos,
  7547. familyInfos = familyInfos,
  7548. certInfos = certInfos,
  7549. companyInfos = companyInfo‌‌s,
  7550. schoolInfos = schoolInfos
  7551. };
  7552. }
  7553. /// <summary>
  7554. /// 文件生成
  7555. /// </summary>
  7556. /// <param name="req"></param>
  7557. /// <returns></returns>
  7558. private async Task<(bool, string, string)> GeneratorFileAsync(GeneratorFileReq req)
  7559. {
  7560. string saveUrl = string.Empty;
  7561. string downloadUrl = string.Empty;
  7562. //模板存储位置
  7563. string tempPath = req.tempPath;
  7564. string fileServerPath = req.fileServerPath;
  7565. int fileTypeId = req.fileTypeId;
  7566. int groupId = req.groupId;
  7567. int language = req.language;
  7568. // 数据源
  7569. var custInfo = req.dataBody.groupCustInfos.FirstOrDefault();
  7570. var visaTypeName = string.Empty;
  7571. var currTempPath = string.Empty;
  7572. var pdfData = await FillPdfTemplateAsync(req.dataBody, language);
  7573. switch (fileTypeId)
  7574. {
  7575. case 1: // 美国
  7576. visaTypeName = $"美国签证申请表";
  7577. currTempPath = $"{tempPath}{visaTypeName}.doc";
  7578. var usaSavePath = $"{fileServerPath}{visaTypeName}/";
  7579. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(usaSavePath);
  7580. break;
  7581. case 2: // 日本
  7582. visaTypeName = $"新办日本申请表";
  7583. currTempPath = $"{tempPath}/{visaTypeName}.pdf";
  7584. var jpnSavePath = $"{fileServerPath}/{visaTypeName}/";
  7585. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(jpnSavePath);
  7586. break;
  7587. case 3: // 韩国
  7588. visaTypeName = $"韩国签证申请表";
  7589. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  7590. var korSavePath = $"{fileServerPath}{visaTypeName}/";
  7591. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(korSavePath);
  7592. break;
  7593. case 4: // 瑞典
  7594. visaTypeName = $"瑞典签证申请表";
  7595. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  7596. var swedenSavePath = $"{fileServerPath}{visaTypeName}/";
  7597. if (!Directory.Exists(swedenSavePath)) Directory.CreateDirectory(swedenSavePath);
  7598. break;
  7599. case 5: // 波兰
  7600. visaTypeName = $"波兰签证申请表";
  7601. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  7602. var polandSavePath = $"{fileServerPath}{visaTypeName}/";
  7603. if (!Directory.Exists(polandSavePath)) Directory.CreateDirectory(polandSavePath);
  7604. break;
  7605. case 6: // 加拿大
  7606. visaTypeName = $"加拿大签证申请表";
  7607. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  7608. var canadaSavePath = $"{fileServerPath}{visaTypeName}/";
  7609. if (!Directory.Exists(canadaSavePath)) Directory.CreateDirectory(canadaSavePath);
  7610. break;
  7611. case 7: // 克罗地亚
  7612. visaTypeName = $"克罗地亚签证申请表";
  7613. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  7614. var croatiaSavePath = $"{fileServerPath}{visaTypeName}/";
  7615. if (!Directory.Exists(croatiaSavePath)) Directory.CreateDirectory(croatiaSavePath);
  7616. if (!System.IO.File.Exists(currTempPath))
  7617. {
  7618. return (false, $"{currTempPath}模板不存在!", string.Empty);
  7619. }
  7620. #region 生成文件
  7621. PdfReader croatia_reader = null;
  7622. FileStream croatia_templateStream = null;
  7623. FileStream croatia_outputStream = null;
  7624. PdfStamper croatia_stamper = null;
  7625. try
  7626. {
  7627. string outputPath = $"{croatiaSavePath}{custInfo.LastName}{custInfo.FirstName}_{visaTypeName}.pdf";
  7628. // 读取模板文件
  7629. croatia_templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  7630. croatia_reader = new PdfReader(croatia_templateStream);
  7631. // 创建输出文件
  7632. croatia_outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  7633. croatia_stamper = new PdfStamper(croatia_reader, croatia_outputStream);
  7634. AcroFields formFields = croatia_stamper.AcroFields;
  7635. #region 设置文本值
  7636. SetFieldValue(formFields, "surname", pdfData.GetSafeString("surname")); // 姓
  7637. SetFieldValue(formFields, "surname_birth", pdfData.GetSafeString("birth_surname")); // 出生时姓
  7638. SetFieldValue(formFields, "firstname", pdfData.GetSafeString("firstname")); // 名
  7639. SetFieldValue(formFields, "birthday", pdfData.GetSafeString("birthday")); // 出生日期(日-月-年)
  7640. SetFieldValue(formFields, "birth_place", pdfData.GetSafeString("birth_place")); // 出生地区
  7641. SetFieldValue(formFields, "birth_country", pdfData.GetSafeString("birth_country")); // 出生国籍
  7642. SetFieldValue(formFields, "current_nationality", pdfData.GetSafeString("current_nationality")); // 现国籍
  7643. #region 设置性别
  7644. //清除性别
  7645. SetFieldValue(formFields, "sex_male", "Off"); // 性别 - 男
  7646. SetFieldValue(formFields, "sex_female", "Off"); // 性别 - 女
  7647. string sex = pdfData.GetSafeString("sex");
  7648. //设置性别
  7649. if (sex == "0") // 男
  7650. {
  7651. SetFieldValue(formFields, "sex_male", "Yes"); // 性别 - 男
  7652. }
  7653. else if (sex == "1") // 女
  7654. {
  7655. SetFieldValue(formFields, "sex_female", "Yes"); // 性别 - 女
  7656. }
  7657. #endregion
  7658. #region 婚姻状态
  7659. // 清除婚姻状况
  7660. SetFieldValue(formFields, "marital_single", "Off"); // 婚姻状况 - 未婚
  7661. SetFieldValue(formFields, "marital_married", "Off"); // 婚姻状况 - 已婚
  7662. SetFieldValue(formFields, "marital_separated", "Off"); // 婚姻状况 - 分居
  7663. SetFieldValue(formFields, "marital_dicorced", "Off"); // 婚姻状况 - 离异
  7664. SetFieldValue(formFields, "marital_widower", "Off"); // 婚姻状况 - 丧偶
  7665. SetFieldValue(formFields, "marital_other", "Off"); // 婚姻状况 - 其他
  7666. SetFieldValue(formFields, "marital_other_specify", ""); // 婚姻状况 - 其他(请具体说明)
  7667. string marriage = pdfData.GetSafeString("marriage");
  7668. // 设置婚姻状况
  7669. switch (marriage)
  7670. {
  7671. case "0": // 未设置
  7672. SetFieldValue(formFields, "marital_single", "Yes");
  7673. break;
  7674. case "1": // 未婚
  7675. SetFieldValue(formFields, "marital_single", "Yes");
  7676. break;
  7677. case "2": // 已婚
  7678. SetFieldValue(formFields, "marital_married", "Yes");
  7679. break;
  7680. case "3": // 离婚/离异
  7681. SetFieldValue(formFields, "marital_dicorced", "Yes");
  7682. break;
  7683. case "4": // 丧偶
  7684. break;
  7685. }
  7686. #endregion
  7687. // 父母的监护权(针对未成年人)/法定监护人(姓氏、名字、地址(若与申请人的地址不同)、电话号码、电子邮箱地址以及国籍)
  7688. SetFieldValue(formFields, "legalGuardian", pdfData.GetSafeString("legal_guardian_info"));
  7689. //(如适用)国民身份号码
  7690. SetFieldValue(formFields, "nationalIdNumber", pdfData.GetSafeString("national_identity_number"));
  7691. #region 护照信息
  7692. //清除值
  7693. SetFieldValue(formFields, "travel_ordinary_passport", "Off"); // 旅行证件类型 - 普通护照
  7694. SetFieldValue(formFields, "travel_diplomatic_passport", "Off");// 旅行证件类型 - 外交护照
  7695. SetFieldValue(formFields, "travel_service_passport", "Off"); // 旅行证件类型 - 服务护照
  7696. SetFieldValue(formFields, "travel_special_passport", "Off"); // 旅行证件类型 - 公务护照
  7697. SetFieldValue(formFields, "travel_other", "Off"); // 旅行证件类型 - 特别护照
  7698. SetFieldValue(formFields, "travel_other_specify", ""); // 其他旅行证件(请注明)
  7699. //设置值
  7700. string visaName = pdfData.GetSafeString("passport_type_name");
  7701. if (visaName.contains("普通")) SetFieldValue(formFields, "travel_ordinary_passport", "Yes"); // 旅行证件类型 - 普通护照
  7702. else if (visaName.contains("外交")) SetFieldValue(formFields, "travel_diplomatic_passport", "Yes"); // 旅行证件类型 - 外交护照
  7703. else if (visaName.contains("服务")) SetFieldValue(formFields, "travel_service_passport", "Yes"); // 旅行证件类型 - 服务护照
  7704. else if (visaName.contains("公务")) SetFieldValue(formFields, "travel_type_offical_passport", "Yes");// 旅行证件类型 - 公务护照
  7705. else // 旅行证件类型 - 特别护照
  7706. {
  7707. SetFieldValue(formFields, "travel_other", "Yes");
  7708. SetFieldValue(formFields, "travel_other_specify", "");
  7709. }
  7710. #region 护照信息
  7711. SetFieldValue(formFields, "travel_number", pdfData.GetSafeString("travel_number")); // 签证 编号
  7712. SetFieldValue(formFields, "travel_issued", pdfData.GetSafeString("travel_issues_country")); // 签发 国
  7713. SetFieldValue(formFields, "travle_issueDate", pdfData.GetSafeString("travel_issue_date")); // 签发日期
  7714. SetFieldValue(formFields, "travel_expiryDate", pdfData.GetSafeString("travel_valid_until")); // 有效期至
  7715. #endregion
  7716. #endregion
  7717. #region 是否在非国籍国居住
  7718. SetFieldValue(formFields, "residesOutsideNationality_no", "Yes"); // 否
  7719. SetFieldValue(formFields, "residesOutsideNationality_yes", "Off"); // 是
  7720. SetFieldValue(formFields, "residesOutsideNationality_number", ""); // 编号
  7721. SetFieldValue(formFields, "residesOutsideNationality_validuntil", ""); // 有效期限
  7722. #endregion
  7723. #region 职业
  7724. SetFieldValue(formFields, "employerInfo", pdfData.GetSafeString("employer_info")); // 职业信息
  7725. #endregion
  7726. #region 此次行程的目的
  7727. // 清除值
  7728. SetFieldValue(formFields, "purpose_tourism", "Off"); // 旅游
  7729. SetFieldValue(formFields, "purpose_business", "Off"); // 商务
  7730. SetFieldValue(formFields, "purpose_visiting_friends_family", "Off");// 庆祝亲友团聚
  7731. SetFieldValue(formFields, "purpose_cultural", "Off"); // 文化交流
  7732. SetFieldValue(formFields, "purpose_sports", "Off"); // 体育活动
  7733. SetFieldValue(formFields, "purpose_official_visit", "Off"); // 官方访问
  7734. SetFieldValue(formFields, "purpose_medical_reasons", "Off"); // 医疗原因
  7735. SetFieldValue(formFields, "purpose_study", "Off"); // 学习
  7736. SetFieldValue(formFields, "purpose_transit", "Off"); // 过境
  7737. SetFieldValue(formFields, "purpose_airport_transit", "Off"); // 机场中转
  7738. SetFieldValue(formFields, "purpose_other", "Off"); // 其他
  7739. SetFieldValue(formFields, "purpose_other_specify", ""); // 其他 - 备注
  7740. var visit_purpose = pdfData.GetSafeString("employer_info");
  7741. if (!string.IsNullOrEmpty(visit_purpose))
  7742. {
  7743. if (visit_purpose.contains("tourism"))
  7744. {
  7745. SetFieldValue(formFields, "purpose_tourism", "Yes"); // 旅游
  7746. }
  7747. else if (visit_purpose.contains("business"))
  7748. {
  7749. SetFieldValue(formFields, "purpose_business", "Yes"); // 商务
  7750. }
  7751. else if (visit_purpose.contains("visiting_family_friends"))
  7752. {
  7753. SetFieldValue(formFields, "purpose_visiting_friends_family", "Yes");// 庆祝亲友团聚
  7754. }
  7755. else if (visit_purpose.contains("cultural") || visit_purpose.contains("tourism"))
  7756. {
  7757. SetFieldValue(formFields, "purpose_cultural", "Yes"); // 文化交流
  7758. }
  7759. else if (visit_purpose.contains("sports") || visit_purpose.contains("activities"))
  7760. {
  7761. SetFieldValue(formFields, "purpose_sports", "Yes"); // 体育活动
  7762. }
  7763. else if (visit_purpose.contains("official"))
  7764. {
  7765. SetFieldValue(formFields, "purpose_official_visit", "Yes"); // 官方访问
  7766. }
  7767. else if (visit_purpose.contains("medical_reasons") || visit_purpose.contains("medical"))
  7768. {
  7769. SetFieldValue(formFields, "purpose_medical_reasons", "Yes"); // 医疗原因
  7770. }
  7771. else if (visit_purpose.contains("study"))
  7772. {
  7773. SetFieldValue(formFields, "purpose_study", "Yes"); // 学习
  7774. }
  7775. else if (visit_purpose.contains("airport_transit"))
  7776. {
  7777. SetFieldValue(formFields, "purpose_transit", "Yes"); // 过境
  7778. }
  7779. else if (visit_purpose.contains("airport_transit"))
  7780. {
  7781. SetFieldValue(formFields, "purpose_airport_transit", "Yes"); // 机场中转
  7782. }
  7783. else
  7784. {
  7785. SetFieldValue(formFields, "purpose_other", "Yes"); // 其他
  7786. SetFieldValue(formFields, "purpose_other_specify", ""); // 其他 - 备注
  7787. }
  7788. }
  7789. #endregion
  7790. #region 目的国相关信息
  7791. SetFieldValue(formFields, "purpose_stay_info", pdfData.GetSafeString("stay_info")); //关于停留目的的补充说明
  7792. SetFieldValue(formFields, "finalDestinationCountry", pdfData.GetSafeString("membeDescLabel")); // 主要目的地成员国(如适用,还包括目的地的其他成员国)
  7793. SetFieldValue(formFields, "firstEntryBorder", pdfData.GetSafeString("firstEntryLabel")); // 口岸
  7794. SetFieldValue(formFields, "intendedStayDays", pdfData.GetSafeString("stayDays")); // 计划停留天数
  7795. // 申请入境次数
  7796. string request_entry = pdfData.GetSafeString("firstEntryLabel");
  7797. if (request_entry == "1") SetFieldValue(formFields, "requestedEntry_single", "Yes"); // 一次入境
  7798. else if (request_entry == "2") SetFieldValue(formFields, "requestedEntry_two", "Yes"); // 两次入境
  7799. else if (request_entry == "3") SetFieldValue(formFields, "requestedEntry_multiple", "Yes"); // 多次入境
  7800. #endregion
  7801. #region 过去三年签证
  7802. SetFieldValue(formFields, "hasPreviousVisas_no", "Yes"); // 否
  7803. SetFieldValue(formFields, "hasPreviousVisas_yes", "Off"); // 是
  7804. //第一年
  7805. SetFieldValue(formFields, "hasPreviousVisas_country1", ""); // 国家
  7806. SetFieldValue(formFields, "hasPreviousVisas_valid1", ""); // 有效期限 起
  7807. SetFieldValue(formFields, "hasPreviousVisas_until1", ""); // 有效期限 止
  7808. //第二年
  7809. SetFieldValue(formFields, "hasPreviousVisas_country2", ""); // 国家
  7810. SetFieldValue(formFields, "hasPreviousVisas_valid2", ""); // 有效期限 起
  7811. SetFieldValue(formFields, "hasPreviousVisas_until2", ""); // 有效期限 止
  7812. //第三年
  7813. SetFieldValue(formFields, "hasPreviousVisas_country3", ""); // 国家
  7814. SetFieldValue(formFields, "hasPreviousVisas_valid3", ""); // 有效期限 起
  7815. SetFieldValue(formFields, "hasPreviousVisas_until3", ""); // 有效期限 止
  7816. #endregion
  7817. #region 此前录过指纹
  7818. string schengen_fingerprints_status = pdfData.GetSafeString("schengen_fingerprints_status");
  7819. if (schengen_fingerprints_status == "1")
  7820. {
  7821. SetFieldValue(formFields, "fingerprintsPreviouslyCollected_yes", "Yes"); // 是
  7822. SetFieldValue(formFields, "fingerprintsPreviouslyCollected_date", ""); // 如有,请写明日期
  7823. }
  7824. else if (schengen_fingerprints_status == "2")
  7825. {
  7826. SetFieldValue(formFields, "fingerprintsPreviouslyCollected_no", "Yes"); // 否
  7827. }
  7828. #endregion
  7829. #region 最终目的地入境许可
  7830. SetFieldValue(formFields, "finalDestinationEntryPermit_issued", pdfData.GetSafeString("entry_permit_issued")); // 发布者
  7831. SetFieldValue(formFields, "finalDestinationEntryPermit_vaild", pdfData.GetSafeString("entry_permit_valid")); // 有效期限 起
  7832. SetFieldValue(formFields, "finalDestinationEntryPermit_until", pdfData.GetSafeString("entry_permit_until")); // 有效期限 止
  7833. #endregion
  7834. #region 计划旅行日期
  7835. SetFieldValue(formFields, "travelDates_arrivalDate", pdfData.GetSafeString("schengen_first_area_arrival")); // 出发日期
  7836. SetFieldValue(formFields, "travelDates_departureDate", pdfData.GetSafeString("schengen_first_area_departure")); // 离开日期
  7837. #endregion
  7838. #region 邀请人/酒店信息
  7839. SetFieldValue(formFields, "accommodationInfo_name", pdfData.GetSafeString("schengen_inviting_name")); // 招待方的地址和电子邮箱地址
  7840. SetFieldValue(formFields, "accommodationInfo_addressAndNameEmail", pdfData.GetSafeString("schengen_inviting_hotel_address_email")); // 酒店/临时住宿场所的地址和电子邮箱地址
  7841. SetFieldValue(formFields, "accommodationInfo_tel", pdfData.GetSafeString("schengen_inviting_hotel_tel")); // 电话号码
  7842. #endregion
  7843. #region 邀请公司/组织信息
  7844. SetFieldValue(formFields, "invitingOrganization_addressAndName", pdfData.GetSafeString("inviting_name_address")); // 邀请公司/组织的名称及地址
  7845. SetFieldValue(formFields, "invitingOrganization_contactInfo", pdfData.GetSafeString("inviting_info")); // 公司/组织中联系人的姓氏、名字、地址、电话号码以及电子邮箱地址
  7846. SetFieldValue(formFields, "invitingOrganization_tel", pdfData.GetSafeString("inviting_tel")); // 电话号码(关于)公司/组织
  7847. #endregion
  7848. #region 费用承担
  7849. #region 支持方式
  7850. SetFieldValue(formFields, "costCoverage_applicant", "Off"); // 支持方式
  7851. SetFieldValue(formFields, "costCoverage_applicant_cash", "Off"); // 现金
  7852. SetFieldValue(formFields, "costCoverage_applicant_travellers_cheques", "Off"); // 旅行支票
  7853. SetFieldValue(formFields, "costCoverage_applicant_credit_card", "Off"); // 信用卡
  7854. SetFieldValue(formFields, "costCoverage_applicant_prepaid_accommodation", "Off");// 预付费住宿
  7855. SetFieldValue(formFields, "costCoverage_applicant_prepaid_transport", "Off"); // 预付费交通
  7856. SetFieldValue(formFields, "costCoverage_applicant_other", "Off"); // 其他
  7857. SetFieldValue(formFields, "costCoverage_applicant_other_specify", ""); // 其他(请具体说明)
  7858. #endregion
  7859. #region 由赞助方(主办方、公司、组织)提供
  7860. SetFieldValue(formFields, "costCoverage_host", "Off"); // 由赞助方(主办方、公司、组织)提供
  7861. SetFieldValue(formFields, "costCoverage_host_referred", "Off"); // 在第 30 或 31 栏中提及
  7862. SetFieldValue(formFields, "costCoverage_host_referred_specify", "");// 在第 30 或 31 栏中提及(请具体说明
  7863. SetFieldValue(formFields, "costCoverage_host_other", "Yes"); // 其他
  7864. SetFieldValue(formFields, "costCoverage_host_other_specify", pdfData.GetSafeString("cost_covered_sponsor_other_specify")); // 其他(请具体说明
  7865. //支持方式
  7866. SetFieldValue(formFields, "costCoverage_host_cash", "Off"); // 现金
  7867. SetFieldValue(formFields, "costCoverage_host_accommodation", "Off"); // 提供住宿
  7868. SetFieldValue(formFields, "costCoverage_host_duringStay", "Off"); // 旅行期间的所有费用均由主办方承担
  7869. SetFieldValue(formFields, "costCoverage_host_prepaid_transport", "Off");// 预先支付的交通费用
  7870. SetFieldValue(formFields, "costCoverage_host_other", "Off"); // 其他
  7871. SetFieldValue(formFields, "costCoverage_host_other_specify", ""); // 其他(请具体说明
  7872. #endregion
  7873. #endregion
  7874. #region 欧盟家庭成员个人信息
  7875. SetFieldValue(formFields, "euFamilyMember_surname", ""); // 姓氏(家族名)
  7876. SetFieldValue(formFields, "euFamilyMember_firstname", ""); // 名字(名字)
  7877. SetFieldValue(formFields, "euFamilyMember_birthday", ""); // 出生日期 (日-月-年)
  7878. SetFieldValue(formFields, "euFamilyMember_nationality", "");// 国籍
  7879. SetFieldValue(formFields, "euFamilyMember_number", ""); // 旅行证件或身份证号码
  7880. #endregion
  7881. #region 欧盟家庭关系
  7882. SetFieldValue(formFields, "familyRelationship_spouse", "Off"); // 夫妻
  7883. SetFieldValue(formFields, "familyRelationship_child", "Off"); // 子女
  7884. SetFieldValue(formFields, "familyRelationship_grandchild", "Off"); // 孙子女
  7885. SetFieldValue(formFields, "familyRelationship_dependent", "Off"); // 有赡养关系的长辈
  7886. #endregion
  7887. SetFieldValue(formFields, "applicant_address_and_email", pdfData.GetSafeString("applicant_address_and_email")); // 申请人的家庭住址和电子邮箱地址
  7888. SetFieldValue(formFields, "applicant_tel", pdfData.GetSafeString("applicant_tel")); // 申请人的电话
  7889. #region 在非当前国籍所属国家的居住情况 “默认空”
  7890. SetFieldValue(formFields, "uncurrent_count_no", "Yes"); // 否
  7891. SetFieldValue(formFields, "uncurrent_count_yes", "Off"); // 是
  7892. SetFieldValue(formFields, "uncurrent_country_residence", ""); // 居留许可或同等证明
  7893. SetFieldValue(formFields, "uncurrent_country_no", ""); // No
  7894. SetFieldValue(formFields, "uncurrent_country_valid_until", ""); // 有效期至
  7895. #endregion
  7896. #endregion
  7897. saveUrl = outputPath;
  7898. }
  7899. catch (Exception ex)
  7900. {
  7901. return (false, $"生成PDF文件时出错:{ex.Message}", string.Empty);
  7902. }
  7903. finally
  7904. {
  7905. // 按正确顺序关闭资源
  7906. croatia_stamper?.Close();
  7907. croatia_reader?.Close();
  7908. croatia_templateStream?.Close();
  7909. croatia_outputStream?.Close();
  7910. }
  7911. #endregion
  7912. break;
  7913. case 8: // 西班牙
  7914. visaTypeName = $"西班牙签证申请表";
  7915. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  7916. var spianSavePath = $"{fileServerPath}{visaTypeName}/";
  7917. if (!Directory.Exists(spianSavePath)) Directory.CreateDirectory(spianSavePath);
  7918. if (!System.IO.File.Exists(currTempPath))
  7919. {
  7920. return (false, $"{currTempPath}模板不存在!", string.Empty);
  7921. }
  7922. #region 生成文件
  7923. PdfReader spian_reader = null;
  7924. FileStream spian_templateStream = null;
  7925. FileStream spian_outputStream = null;
  7926. PdfStamper spian_stamper = null;
  7927. try
  7928. {
  7929. string outputPath = $"{spianSavePath}{custInfo.LastName}{custInfo.FirstName}_{visaTypeName}.pdf";
  7930. //读取模板文件
  7931. spian_templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  7932. spian_reader = new PdfReader(spian_templateStream);
  7933. //创建输出文件
  7934. spian_outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  7935. spian_stamper = new PdfStamper(spian_reader, spian_outputStream);
  7936. AcroFields formFields = spian_stamper.AcroFields;
  7937. #region 设置文本值
  7938. SetFieldValue(formFields, "surname", pdfData.GetSafeString("surname")); // 姓 英文
  7939. SetFieldValue(formFields, "birth_surname", pdfData.GetSafeString("birth_surname")); // 出生时姓 英文
  7940. SetFieldValue(formFields, "firstname", pdfData.GetSafeString("firstname")); // 名 英文
  7941. SetFieldValue(formFields, "birthday", pdfData.GetSafeString("birthday")); // 出生日期
  7942. SetFieldValue(formFields, "birth_place", pdfData.GetSafeString("birth_place")); // 出生地区
  7943. SetFieldValue(formFields, "birth_country", pdfData.GetSafeString("birth_country")); // 出生国籍
  7944. SetFieldValue(formFields, "current_nationality", pdfData.GetSafeString("current_nationality")); // 现国籍
  7945. SetFieldValue(formFields, "birth_nationality", pdfData.GetSafeString("birth_nationality")); // 出生国籍
  7946. SetFieldValue(formFields, "other_nacionality", pdfData.GetSafeString("other_nacionality")); // 其他国籍
  7947. #region 设置性别
  7948. //清除性别
  7949. SetFieldValue(formFields, "sex_male", "Off"); // 性别 - 男
  7950. SetFieldValue(formFields, "sex_female", "Off"); // 性别 - 女
  7951. SetFieldValue(formFields, "sex_other", "Off"); // 性别 - 其他
  7952. //设置性别
  7953. var sex = pdfData.GetSafeString("sex");
  7954. if (sex.Equals("0")) // 男
  7955. {
  7956. SetFieldValue(formFields, "sex_male", "Yes"); // 性别 - 男
  7957. }
  7958. else if (sex.Equals("1")) // 女
  7959. {
  7960. SetFieldValue(formFields, "sex_female", "Yes"); // 性别 - 女
  7961. }
  7962. else
  7963. {
  7964. SetFieldValue(formFields, "sex_other", "Yes"); // 性别 - 其他
  7965. }
  7966. #endregion
  7967. #region 婚姻状态
  7968. //清除婚姻状况
  7969. SetFieldValue(formFields, "marital_single", "Off"); // 婚姻状况 - 未婚
  7970. SetFieldValue(formFields, "marital_married", "Off"); // 婚姻状况 - 已婚
  7971. SetFieldValue(formFields, "marital_registered_union", "Off");// 婚姻状况 - 注册伴侣关系
  7972. SetFieldValue(formFields, "marital_separated", "Off"); // 婚姻状况 - 分居
  7973. SetFieldValue(formFields, "marital_divorced", "Off"); // 婚姻状况 - 离异
  7974. SetFieldValue(formFields, "marital_widower", "Off"); // 婚姻状况 - 丧偶
  7975. SetFieldValue(formFields, "marital_other", "Off"); // 婚姻状况 - 其他
  7976. SetFieldValue(formFields, "marital_other_specify", ""); // 婚姻状况 - 其他(请具体说明)
  7977. var maritalStatus = pdfData.GetSafeString("marriage");
  7978. //设置婚姻状况
  7979. switch (maritalStatus)
  7980. {
  7981. case "1": // 未婚
  7982. SetFieldValue(formFields, "marital_single", "Yes");
  7983. break;
  7984. case "2": // 已婚
  7985. SetFieldValue(formFields, "marital_married", "Yes");
  7986. break;
  7987. case "3": // 离婚/离异
  7988. SetFieldValue(formFields, "marital_divorced", "Yes");
  7989. break;
  7990. case "4": // 分居
  7991. SetFieldValue(formFields, "marital_separated", "Yes");
  7992. break;
  7993. case "5": // 丧偶
  7994. SetFieldValue(formFields, "marital_widower", "Yes");
  7995. break;
  7996. case "6": // 其他
  7997. SetFieldValue(formFields, "marital_other", "Yes");
  7998. break;
  7999. }
  8000. #endregion
  8001. // 父母的监护权(针对未成年人)/法定监护人(姓氏、名字、地址(若与申请人的地址不同)、电话号码、电子邮箱地址以及国籍)
  8002. SetFieldValue(formFields, "legal_guardian_info", pdfData.GetSafeString("legal_guardian_info"));
  8003. //(如适用)国民身份号码
  8004. SetFieldValue(formFields, "national_identity_number", pdfData.GetSafeString("national_identity_number"));
  8005. #region 护照信息
  8006. //清除值
  8007. SetFieldValue(formFields, "passport_orfinary", "Off"); // 旅行证件类型 - 普通护照
  8008. SetFieldValue(formFields, "passport_diplomatic", "Off"); // 旅行证件类型 - 外交护照
  8009. SetFieldValue(formFields, "passport_service", "Off"); // 旅行证件类型 - 公务护照
  8010. SetFieldValue(formFields, "passport_official", "Off"); // 旅行证件类型 - 因公护照
  8011. SetFieldValue(formFields, "passport_other", "Off"); // 旅行证件类型 - 特别护照
  8012. SetFieldValue(formFields, "passport_other_specify", ""); // 其他旅行证件(请注明)
  8013. #region 设置 护照信息
  8014. string visaName = pdfData.GetSafeString("passport_type_name");
  8015. if (visaName.contains("普通")) SetFieldValue(formFields, "passport_orfinary", "Yes"); // 旅行证件类型 - 普通护照
  8016. else if (visaName.contains("外交")) SetFieldValue(formFields, "passport_diplomatic", "Yes"); // 旅行证件类型 - 外交护照
  8017. else if (visaName.contains("公务")) SetFieldValue(formFields, "passport_service", "Yes"); // 旅行证件类型 - 公务护照
  8018. else if (visaName.contains("因公")) SetFieldValue(formFields, "passport_official", "Yes"); // 旅行证件类型 - 因公护照
  8019. else // 旅行证件类型 - 特别护照
  8020. {
  8021. SetFieldValue(formFields, "passport_other", "Yes");
  8022. SetFieldValue(formFields, "passport_other_specify", "");
  8023. }
  8024. SetFieldValue(formFields, "travel_number", pdfData.GetSafeString("travel_number")); // 签证 编号
  8025. SetFieldValue(formFields, "travel_issues_country", pdfData.GetSafeString("travel_issues_country"));// 签发 国
  8026. SetFieldValue(formFields, "travel_issue_date", pdfData.GetSafeString("travel_issue_date")); // 签发日期
  8027. SetFieldValue(formFields, "travel_valid_until", pdfData.GetSafeString("travel_valid_until")); // 有效期至
  8028. #endregion
  8029. #endregion
  8030. #region 欧盟家庭成员个人信息
  8031. SetFieldValue(formFields, "ue_family_info", pdfData.GetSafeString("ue_family_info")); // 个人信息
  8032. SetFieldValue(formFields, "ue_family_surname", pdfData.GetSafeString("ue_family_surname")); // 姓氏(家族名)
  8033. SetFieldValue(formFields, "ue_family_firstname", pdfData.GetSafeString("ue_family_firstname")); // 名字(名字)
  8034. SetFieldValue(formFields, "ue_family_birthday", pdfData.GetSafeString("ue_family_birthday")); // 出生日期 (日-月-年)
  8035. SetFieldValue(formFields, "ue_family_nationality", pdfData.GetSafeString("ue_family_nationality")); // 国籍
  8036. SetFieldValue(formFields, "ue_family_travel_number", pdfData.GetSafeString("ue_family_travel_number"));// 旅行证件或身份证号码
  8037. #endregion
  8038. #region 欧盟家庭关系
  8039. SetFieldValue(formFields, "eu_family_relationship_spouse", "Off"); // 夫妻
  8040. SetFieldValue(formFields, "eu_family_relationship_child", "Off"); // 子女
  8041. SetFieldValue(formFields, "eu_family_relationship_grandchild", "Off"); // 孙子女
  8042. SetFieldValue(formFields, "eu_family_relationship_dependent", "Off"); // 受养人
  8043. SetFieldValue(formFields, "eu_family_relationship_registered_partnership", "Off"); // 注册伴侣
  8044. SetFieldValue(formFields, "eu_family_relationship_other", pdfData.GetSafeString("eu_family_relationship_other")); // 其他
  8045. SetFieldValue(formFields, "eu_family_relationship_other_specify", pdfData.GetSafeString("eu_family_relationship_other_specify")); // 其他
  8046. #endregion
  8047. // 申请人的家庭住址和电子邮箱地址
  8048. SetFieldValue(formFields, "applicant_address_and_email", pdfData.GetSafeString("applicant_address_and_email"));
  8049. // 申请人的电话
  8050. SetFieldValue(formFields, "applicant_tel", pdfData.GetSafeString("applicant_tel"));
  8051. #region 是否在非国籍国居住 默认否
  8052. SetFieldValue(formFields, "unresidente_no", "Yes"); // 否
  8053. SetFieldValue(formFields, "unresidente_yes", "Off"); // 是
  8054. SetFieldValue(formFields, "unresidente_equivalen", ""); // 居住许可证
  8055. SetFieldValue(formFields, "unresidente_number", ""); // 编号
  8056. SetFieldValue(formFields, "unresidente_vaild", ""); // 有效期限
  8057. #endregion
  8058. #region 职业
  8059. // 当前职业
  8060. SetFieldValue(formFields, "occupation", pdfData.GetSafeString("fileName"));
  8061. //雇主及雇主的地址和电话号码。
  8062. SetFieldValue(formFields, "employer_info", pdfData.GetSafeString("employer_info"));
  8063. #endregion
  8064. #region 此次行程的目的
  8065. //清除值
  8066. SetFieldValue(formFields, "purpose_tourism", "Off"); // 旅游
  8067. SetFieldValue(formFields, "purpose_business", "Off"); // 商务
  8068. SetFieldValue(formFields, "purpose_visiting_family_friends", "Off");// 庆祝亲友团聚
  8069. SetFieldValue(formFields, "purpose_cultural", "Off"); // 文化交流
  8070. SetFieldValue(formFields, "purpose_sports", "Off"); // 体育
  8071. SetFieldValue(formFields, "purpose_official", "Off"); // 官方访问
  8072. SetFieldValue(formFields, "purpose_medical_reasons", "Off"); // 医疗
  8073. SetFieldValue(formFields, "purpose_study", "Off"); // 学习
  8074. SetFieldValue(formFields, "purpose_airport_transit", "Off"); // 机场过境
  8075. SetFieldValue(formFields, "purpose_other", "Off"); // 其他
  8076. SetFieldValue(formFields, "purpose_other_specify", ""); // 其他 - 备注
  8077. var visit_purpose = pdfData.GetSafeString("purpose");
  8078. var visit_purpose_remark = pdfData.GetSafeString("purpose_other_specify");
  8079. if (!string.IsNullOrEmpty(visit_purpose))
  8080. {
  8081. if (visit_purpose.contains("tourism"))
  8082. {
  8083. SetFieldValue(formFields, "purpose_tourism", "Yes"); // 旅游
  8084. }
  8085. else if (visit_purpose.contains("business"))
  8086. {
  8087. SetFieldValue(formFields, "purpose_business", "Yes"); // 商务
  8088. }
  8089. else if (visit_purpose.contains("visiting_family_friends"))
  8090. {
  8091. SetFieldValue(formFields, "purpose_visiting_family_friends", "Yes");// 庆祝亲友团聚
  8092. }
  8093. else if (visit_purpose.contains("cultural") || visit_purpose.contains("tourism"))
  8094. {
  8095. SetFieldValue(formFields, "purpose_cultural", "Yes"); // 文化交流
  8096. }
  8097. else if (visit_purpose.contains("sports"))
  8098. {
  8099. SetFieldValue(formFields, "purpose_sports", "Yes"); // 体育
  8100. }
  8101. else if (visit_purpose.contains("official"))
  8102. {
  8103. SetFieldValue(formFields, "purpose_official", "Yes"); // 官方访问
  8104. }
  8105. else if (visit_purpose.contains("medical_reasons") || visit_purpose.contains("medical"))
  8106. {
  8107. SetFieldValue(formFields, "purpose_medical_reasons", "Yes"); // 医疗原因
  8108. }
  8109. else if (visit_purpose.contains("study"))
  8110. {
  8111. SetFieldValue(formFields, "purpose_study", "Yes"); // 学习
  8112. }
  8113. else if (visit_purpose.contains("airport_transit") || visit_purpose.contains("transit"))
  8114. {
  8115. SetFieldValue(formFields, "purpose_airport_transit", "Yes"); // 机场过境
  8116. }
  8117. else
  8118. {
  8119. SetFieldValue(formFields, "purpose_other", "Yes"); // 其他
  8120. SetFieldValue(formFields, "purpose_other_specify", visit_purpose_remark);// 其他 - 备注
  8121. }
  8122. }
  8123. #endregion
  8124. #region 目的国相关信息
  8125. // 关于停留目的的补充说明
  8126. SetFieldValue(formFields, "stay_info", pdfData.GetSafeString("stay_info"));
  8127. SetFieldValue(formFields, "member_destination", pdfData.GetSafeString("member_destination")); // 主要目的地成员国(如适用,还包括目的地的其他成员国)
  8128. SetFieldValue(formFields, "member_first_entry", pdfData.GetSafeString("member_first_entry")); // 首入申根国标签
  8129. // 申请入境次数
  8130. string request_entry = pdfData.GetSafeString("request_entry");
  8131. switch (request_entry)
  8132. {
  8133. case "1":
  8134. SetFieldValue(formFields, "request_entry_one", "Yes"); // 一次入境
  8135. break;
  8136. case "2":
  8137. SetFieldValue(formFields, "request_entry_two", "Yes"); // 两次入境
  8138. break;
  8139. case "3":
  8140. SetFieldValue(formFields, "request_entry_multiple", "Yes"); // 多次入境
  8141. break;
  8142. }
  8143. SetFieldValue(formFields, "schengen_first_area_arrival", pdfData.GetSafeString("schengen_first_area_arrival")); // 首次抵达日期
  8144. SetFieldValue(formFields, "schengen_first_area_departure", pdfData.GetSafeString("schengen_first_area_departure")); // 首次抵达日期
  8145. #endregion
  8146. #region 此前录过指纹
  8147. var fingerprints = pdfData.GetSafeString("schengen_fingerprints_status");
  8148. switch (fingerprints)
  8149. {
  8150. // 是
  8151. case "1":
  8152. SetFieldValue(formFields, "schengen_fingerprints_yes", "Yes"); // 是
  8153. SetFieldValue(formFields, "schengen_fingerprints_date", ""); // 如有,请写明日期
  8154. SetFieldValue(formFields, "schengen_fingerprints_visa_no", "");// 编号
  8155. break;
  8156. // 否
  8157. case "2":
  8158. SetFieldValue(formFields, "schengen_fingerprints_no", "Yes"); // 否
  8159. break;
  8160. }
  8161. #endregion
  8162. #region 最终目的地入境许可
  8163. SetFieldValue(formFields, "entry_permit_issued", pdfData.GetSafeString("entry_permit_issued")); // 发布者
  8164. SetFieldValue(formFields, "entry_permit_valid", pdfData.GetSafeString("entry_permit_valid")); // 有效期限 起
  8165. SetFieldValue(formFields, "entry_permit_until", pdfData.GetSafeString("entry_permit_until")); // 有效期限 止
  8166. #endregion
  8167. #region 邀请人/酒店信息
  8168. SetFieldValue(formFields, "schengen_inviting_name", pdfData.GetSafeString("schengen_inviting_name")); // 招待方的酒店、邀请人 名称
  8169. SetFieldValue(formFields, "schengen_inviting_hotel_address_email", pdfData.GetSafeString("schengen_inviting_hotel_address_email")); // 酒店/临时住宿场所的地址和电子邮箱地址
  8170. SetFieldValue(formFields, "schengen_inviting_hotel_tel", pdfData.GetSafeString("schengen_inviting_hotel_tel")); // 电话号码
  8171. #endregion
  8172. #region 邀请公司/组织信息
  8173. SetFieldValue(formFields, "inviting_name_address", pdfData.GetSafeString("inviting_name_address")); // 邀请公司/组织的名称及地址
  8174. SetFieldValue(formFields, "inviting_info", pdfData.GetSafeString("inviting_info")); // 公司/组织中联系人的姓氏、名字、地址、电话号码以及电子邮箱地址
  8175. SetFieldValue(formFields, "inviting_tel", pdfData.GetSafeString("inviting_tel")); // 电话号码(关于)公司/组织
  8176. #endregion
  8177. #region 费用承担
  8178. #region 支持方式
  8179. SetFieldValue(formFields, "cost_covered_herself", "Off"); // 支持方式
  8180. SetFieldValue(formFields, "cost_covered_herself_cash", "Off"); // 现金
  8181. SetFieldValue(formFields, "cost_covered_herself_cheques", "Off"); // 旅行支票
  8182. SetFieldValue(formFields, "cost_covered_herself_credit", "Off"); // 信用卡
  8183. SetFieldValue(formFields, "cost_covered_herself_accomodation", "Off"); // 预付费住宿
  8184. SetFieldValue(formFields, "cost_covered_herself_transport", "Off"); // 预付费交通
  8185. SetFieldValue(formFields, "cost_covered_herself_other", "Off"); // 其他
  8186. SetFieldValue(formFields, "cost_covered_herself_other_specift", ""); // 其他(请具体说明)
  8187. #endregion
  8188. #region 由赞助方(主办方、公司、组织)提供
  8189. SetFieldValue(formFields, "cost_covered_sponsor", "Off"); // 由赞助方(主办方、公司、组织)提供
  8190. SetFieldValue(formFields, "cost_covered_sponsor_referred", "Off"); // 在第 30 或 31 栏中提及
  8191. SetFieldValue(formFields, "cost_covered_sponsor_other", "Yes"); // 其他
  8192. SetFieldValue(formFields, "cost_covered_sponsor_other_specify", pdfData.GetSafeString("cost_covered_sponsor_other_specify")); // 其他(请具体说明
  8193. //支持方式
  8194. SetFieldValue(formFields, "cost_covered_sponsor_cash", "Off"); // 现金
  8195. SetFieldValue(formFields, "cost_covered_sponsor_accomodation", "Off"); // 提供住宿
  8196. SetFieldValue(formFields, "cost_covered_sponsor_during_stay", "Off"); // 旅行期间的所有费用均由主办方承担
  8197. SetFieldValue(formFields, "cost_covered_sponsor_transport", "Off"); // 预先支付的交通费用
  8198. SetFieldValue(formFields, "cost_covered_sponsor_other", "Yes"); // 其他
  8199. SetFieldValue(formFields, "cost_covered_sponsor_other_specify", pdfData.GetSafeString("cost_covered_sponsor_other_specify")); // 其他(请具体说明
  8200. #endregion
  8201. #endregion
  8202. #endregion
  8203. saveUrl = outputPath;
  8204. }
  8205. catch (Exception ex)
  8206. {
  8207. return (false, $"生成PDF文件时出错:{ex.Message}", string.Empty);
  8208. }
  8209. finally
  8210. {
  8211. // 按正确顺序关闭资源
  8212. spian_stamper?.Close();
  8213. spian_reader?.Close();
  8214. spian_templateStream?.Close();
  8215. spian_outputStream?.Close();
  8216. }
  8217. #endregion
  8218. break;
  8219. default:
  8220. return (false, "正在开发中,请等待。。。", string.Empty);
  8221. }
  8222. // 文件下载地址
  8223. downloadUrl = saveUrl.Replace(@"\", @"/").Replace("D:/FTP/File/OA2023", "http://132.232.92.186:24");
  8224. return (true, saveUrl, downloadUrl);
  8225. }
  8226. /// <summary>
  8227. /// 派遣函 生成
  8228. /// </summary>
  8229. /// <returns></returns>
  8230. private async Task<(bool, string, string)> GeneratorDispatchAsync(DataBody dataBody)
  8231. {
  8232. var wordDic = new Dictionary<string, string>();
  8233. var custInfo = dataBody.groupCustInfos.FirstOrDefault();
  8234. var clientInfo = dataBody.companyInfos.FirstOrDefault();
  8235. var groupInfo = dataBody?.groupInfo;
  8236. string clientName = clientInfo?.Company ?? "";
  8237. string clientAddress = clientInfo?.CompanyAddress ?? "";
  8238. string clientTel = clientInfo?.Phone ?? "";
  8239. string clientFax = "";
  8240. string name = $"{custInfo?.LastName ?? ""}{custInfo?.FirstName ?? ""}";
  8241. int sexId = custInfo?.Sex ?? -1;
  8242. string sex = sexId switch
  8243. {
  8244. 0 => "男",
  8245. 1 => "女",
  8246. _ => ""
  8247. };
  8248. string birthday = string.Empty;
  8249. #region 出生日期(日-月-年)
  8250. string idCard = dataBody?.certInfos.FirstOrDefault(x => x.PassportType == 773)?.CertNo?.Trim() ?? "";
  8251. // 1. 优先从身份证中提取 (需为18位身份证)
  8252. if (!string.IsNullOrEmpty(idCard) && idCard.Length >= 14)
  8253. {
  8254. try
  8255. {
  8256. string year = idCard.Substring(6, 4);
  8257. string month = idCard.Substring(10, 2);
  8258. string day = idCard.Substring(12, 2);
  8259. // 统一格式为 yyyy-MM-dd
  8260. birthday = $"{year}-{month}-{day}";
  8261. }
  8262. catch
  8263. {
  8264. // 如果截取失败,回退为空
  8265. birthday = string.Empty;
  8266. }
  8267. }
  8268. // 2. 身份证不存在或提取失败,则从 custInfo 获取
  8269. if (string.IsNullOrEmpty(birthday))
  8270. {
  8271. DateTime? date = custInfo?.BirthDay;
  8272. // 验证逻辑:排除空值、1900年、或 DateTime.MinValue
  8273. if (!date.HasValue || date.Value.Year == 1900 || date.Value == DateTime.MinValue)
  8274. {
  8275. birthday = "";
  8276. }
  8277. else
  8278. {
  8279. birthday = date.Value.ToString("yyyy-MM-dd");
  8280. }
  8281. }
  8282. #endregion
  8283. string passportNo = dataBody.certInfos.FirstOrDefault(x => x.PassportType == 774)?.CertNo ?? "";
  8284. string jobInfo = $"{clientInfo?.WorkStart?.ToString("yyyy-MM-dd") ?? ""} {clientInfo?.Job}";
  8285. string wage = custInfo?.Wage ?? "";
  8286. string invitingPartyName = ""; // 邀请方名称
  8287. string destinationCountry = ""; // 出访国家
  8288. string durationOfStay = ""; // 在外停留天数
  8289. string entryDate = ""; // 入境国外时间
  8290. string exitDate = ""; // 出境国外时间
  8291. string visitPurpose = groupInfo?.VisitPurpose ?? ""; // 出访目的
  8292. string shengenCountryInfos = ""; // 申根国相关信息
  8293. string fillingDate = DateTime.Now.ToString("yyyy-MM-dd"); //填写日期
  8294. #region 国家、(入、离)境信息
  8295. string[] country = new string[] { }; // 接收处理的国家
  8296. string firstEntryLabel = string.Empty; // 首入申根国标签
  8297. string membeDescLabel = string.Empty; // 申根国目的地
  8298. string visitCountry = groupInfo?.VisitCountry;
  8299. if (!string.IsNullOrEmpty(visitCountry))
  8300. {
  8301. List<string> SGGNames = new List<string>(); // 接收处理后的国家 是申根国
  8302. if (visitCountry.Contains(","))
  8303. country = visitCountry.Split(',');
  8304. else if (visitCountry.Contains(' '))
  8305. country = visitCountry.Split(' ');
  8306. else if (visitCountry.Contains(","))
  8307. country = visitCountry.Split(',');
  8308. else if (visitCountry.Contains("、"))
  8309. country = visitCountry.Split('、');
  8310. else if (visitCountry.Contains("|"))
  8311. country = visitCountry.Split('|');
  8312. //判断是否是申根国家
  8313. for (int i = 0; i < country.Length; i++)
  8314. {
  8315. if (country[i].ToString() != null)
  8316. {
  8317. //在申根国家中筛选 该国家是否是申根国家
  8318. for (int j = 0; j < _shenGenGuos.Length; j++)
  8319. {
  8320. if (country[i] == _shenGenGuos[j])
  8321. SGGNames.Add(_shenGenGuos[j]); //添加申根国
  8322. }
  8323. }
  8324. }
  8325. //目的地国是否有申根国
  8326. if (SGGNames.Count > 0)
  8327. {
  8328. firstEntryLabel = SGGNames.First();
  8329. membeDescLabel = string.Join(",", SGGNames.ToArray());
  8330. //接收生根国详细信息 存储顺序 起飞日期:Day 起飞时刻:StartTime 抵达日期:ArrivedDate 到达时刻:EndTime
  8331. List<SSGDetails> ListSSGDetails = new List<SSGDetails>();
  8332. //处理申根国家 预定到达时间 预定离开时间 预定停留天数
  8333. for (int i = 0; i < SGGNames.Count; i++)
  8334. {
  8335. //在相同的国家下 得到该航班的信息 //抵达时间 起飞日期:Day 起飞时刻:StartTime 到达时刻:EndTime 抵达日期:ArrivedDate 飞行时间:FlightTime 航司 Fliagtcode 入境口岸
  8336. var atbc = GeneralMethod.GetTableByBlackCode(groupInfo?.Id ?? 0);
  8337. //ResidenceTime1 机票三字码信息
  8338. if (atbc != null)
  8339. {
  8340. string HL_Three = ""; //三字码 Three
  8341. for (int j = 0; j < atbc.Rows.Count; j++)
  8342. {
  8343. HL_Three = atbc.Rows[j]["Three"].ToString();
  8344. if (!string.IsNullOrEmpty(HL_Three))
  8345. {
  8346. string threeCodeTwo = HL_Three.Substring(3);
  8347. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  8348. if (tc != null)
  8349. {
  8350. //首入申根国时间
  8351. if (SGGNames[i] == tc.Country)
  8352. {
  8353. SSGDetails SSGDetails = new SSGDetails()
  8354. {
  8355. Three = atbc.Rows[j]["Three"].ToString(), //三字码
  8356. Fliagtcode = atbc.Rows[j]["Fliagtcode"].ToString(), //航司
  8357. startDate = atbc.Rows[j]["Day"].ToString(), //整理起飞日期
  8358. startTime = atbc.Rows[j]["StartTime"].ToString(), //整理起飞时刻
  8359. endDate = atbc.Rows[j]["ArrivedDate"].ToString(), //整理抵达日期
  8360. endTime = atbc.Rows[j]["EndTime"].ToString() //整理抵达时刻
  8361. };
  8362. ListSSGDetails.Add(SSGDetails);
  8363. }
  8364. }
  8365. }
  8366. }
  8367. }
  8368. }
  8369. ListSSGDetails.Sort((a, b) => a.startDate.CompareTo(b.startDate));
  8370. //得到并计算出入境时间
  8371. if (ListSSGDetails != null)
  8372. {
  8373. entryDate = ListSSGDetails.First().endDate + " " + ListSSGDetails.First().endTime.Substring(0, 2) + ":" + ListSSGDetails.First().endTime.Substring(2); //入境时间
  8374. exitDate = ListSSGDetails[ListSSGDetails.Count - 1].startDate + " " + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(0, 2) + ":" + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(2); //离境时间
  8375. durationOfStay = Convert.ToDateTime(exitDate).Subtract(Convert.ToDateTime(entryDate)).Days.ToString();
  8376. }
  8377. // (出访2个及以上申根国家,每个国家邀请方名称及出访时间均需要写清楚)
  8378. if (SGGNames.Count >= 2)
  8379. {
  8380. var oaItem = _sqlSugar.Queryable<Res_OfficialActivities>()
  8381. .Where(x => x.IsDel == 0 && x.DiId == groupInfo.Id)
  8382. .Where(x => SGGNames.Contains(x.Country))
  8383. .OrderBy(x => x.Date)
  8384. .ToList();
  8385. foreach (var item in oaItem)
  8386. {
  8387. shengenCountryInfos += $"{item.Country} {item.Client} {item.Date} {item.Time};\r\n";
  8388. }
  8389. }
  8390. }
  8391. destinationCountry = string.Join(", ", country);
  8392. }
  8393. #endregion
  8394. #region 邀请公司/组织信息
  8395. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  8396. .Where(x => x.IsDel == 0 && x.DiId == groupInfo.Id)
  8397. //.Where(x => x.Country.Contains(county))
  8398. //.Where(x => x.Area.Contains(city))
  8399. .First();
  8400. invitingPartyName = $"{oa?.Client ?? ""}";
  8401. #endregion
  8402. #region 填充派遣函数据
  8403. wordDic.Add("clientName", clientName);
  8404. wordDic.Add("clientAddress", clientAddress);
  8405. wordDic.Add("clientTel", clientTel);
  8406. wordDic.Add("clientFax", clientFax);
  8407. wordDic.Add("fillingDate", DateTime.Now.ToString("dd/MM/yyyy"));
  8408. wordDic.Add("name", name);
  8409. wordDic.Add("sex", sex);
  8410. wordDic.Add("birthday", birthday);
  8411. wordDic.Add("passportNo", passportNo);
  8412. wordDic.Add("jobInfo", jobInfo);
  8413. wordDic.Add("wage", wage);
  8414. wordDic.Add("invitingPartyName", invitingPartyName);
  8415. wordDic.Add("destinationCountry", destinationCountry);
  8416. wordDic.Add("durationOfStay", durationOfStay);
  8417. wordDic.Add("entryDate", entryDate);
  8418. wordDic.Add("exitDate", exitDate);
  8419. wordDic.Add("visitPurpose", visitPurpose);
  8420. wordDic.Add("shengenCountryInfos", shengenCountryInfos);
  8421. #endregion
  8422. // DeepSeek AI 中转英
  8423. wordDic = await DeepSeekCNToENAsync(JsonConvert.SerializeObject(wordDic));
  8424. #region 加载模板生成值
  8425. string templatePath = @$"D:\FTP\File\OA2023\Office\Word\VisaClientData\Template\申根派遣函模板.doc";
  8426. if (!System.IO.File.Exists(templatePath))
  8427. {
  8428. return (false, $"找不到指定的派遣函模板: {templatePath}", string.Empty);
  8429. }
  8430. Document doc = new(templatePath);
  8431. DocumentBuilder builder = new(doc);
  8432. // 填充值
  8433. FillBookmark(doc, builder, "clientNameCN", clientName); // 单位名称(中文)
  8434. FillBookmark(doc, builder, "clientNameEN", wordDic.GetSafeString("clientName")); // 单位名称(英文)
  8435. FillBookmark(doc, builder, "clientAddressCN", clientAddress); // 单位地址(中文)
  8436. FillBookmark(doc, builder, "clientAddressEN", wordDic.GetSafeString("clientAddress")); // 单位地址(英文)
  8437. FillBookmark(doc, builder, "clientTel", wordDic.GetSafeString("clientTel")); // 单位电话
  8438. FillBookmark(doc, builder, "clientFax", wordDic.GetSafeString("clientFax")); // 单位传真
  8439. FillBookmark(doc, builder, "fillingDate", wordDic.GetSafeString("fillingDate")); // 填写日期
  8440. FillBookmark(doc, builder, "name", wordDic.GetSafeString("name")); // 姓名
  8441. FillBookmark(doc, builder, "sex", wordDic.GetSafeString("sex")); // 性别
  8442. #region 多出性别处理
  8443. string sex1 = "-", sex2 = "-", sex3 = "-", sex4 = "-", sex5 = "-", sex6 = "-", sex7 = "-";
  8444. if (sex.Equals("男"))
  8445. {
  8446. sex1 = "Mr.";
  8447. sex2 = "His";
  8448. sex3 = "He";
  8449. sex4 = "Mr.";
  8450. sex5 = "He";
  8451. sex6 = "His";
  8452. sex7 = "He";
  8453. }
  8454. else if (sex.Equals("女"))
  8455. {
  8456. sex1 = "Ms.";
  8457. sex2 = "Her";
  8458. sex3 = "She";
  8459. sex4 = "Ms.";
  8460. sex5 = "She";
  8461. sex6 = "Her";
  8462. sex7 = "She";
  8463. }
  8464. FillBookmark(doc, builder, "sex1", sex1); // 1. Mr./Ms
  8465. FillBookmark(doc, builder, "sex2", sex2); // 2. His/Her
  8466. FillBookmark(doc, builder, "sex3", sex3); // 3. He/She
  8467. FillBookmark(doc, builder, "sex4", sex4); // 4. Mr./Ms.
  8468. FillBookmark(doc, builder, "sex5", sex5); // 5. He/She
  8469. FillBookmark(doc, builder, "sex6", sex6); // 6. His/Her
  8470. FillBookmark(doc, builder, "sex7", sex7); // 7. He/She
  8471. #endregion
  8472. FillBookmark(doc, builder, "birthday", wordDic.GetSafeString("birthday")); // 出生日期
  8473. FillBookmark(doc, builder, "passportNo", wordDic.GetSafeString("passportNo")); // 护照号码
  8474. FillBookmark(doc, builder, "clientName", wordDic.GetSafeString("clientName")); // 单位名称
  8475. FillBookmark(doc, builder, "jobInfo", wordDic.GetSafeString("jobInfo")); // 工作信息
  8476. FillBookmark(doc, builder, "wage", wordDic.GetSafeString("wage")); // 工资
  8477. FillBookmark(doc, builder, "invitingPartyName", wordDic.GetSafeString("invitingPartyName")); // 邀请方名称
  8478. FillBookmark(doc, builder, "destinationCountry", wordDic.GetSafeString("destinationCountry")); // 出访国家
  8479. FillBookmark(doc, builder, "durationOfStay", wordDic.GetSafeString("durationOfStay")); // 在外停留天数
  8480. FillBookmark(doc, builder, "entryDate", wordDic.GetSafeString("entryDate")); // 入境国外时间
  8481. FillBookmark(doc, builder, "exitDate", wordDic.GetSafeString("exitDate")); // 出境国外时间
  8482. string visitDateDetails = $"{wordDic.GetSafeString("visitPurpose")}. from {groupInfo.VisitStartDate.ToString("dd-MM-yyyy")} to {groupInfo.VisitEndDate.ToString("dd-MM-yyyy")}";
  8483. FillBookmark(doc, builder, "visitPurpose", visitDateDetails); // 出访目的
  8484. FillBookmark(doc, builder, "nameEnd", wordDic.GetSafeString("name")); // 姓名 END
  8485. FillBookmark(doc, builder, "visitCountryEnd", wordDic.GetSafeString("destinationCountry")); // 出访国家 END
  8486. FillBookmark(doc, builder, "clientNameEnd", wordDic.GetSafeString("clientName")); // 详细费用承担方单位名称 END
  8487. #endregion
  8488. var groupName = dataBody.groupInfo?.TeamName ?? $"";
  8489. //访问路径
  8490. var serverPath = $"http://132.232.92.186:24/Office/Word/VisaClientData/Downloads/{groupName}/派遣函/";
  8491. // 服务器存储文件位置
  8492. var fileServerPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Downloads/{groupName}/派遣函/";
  8493. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(fileServerPath);
  8494. string fileName = $"{name}_派遣函.docx";
  8495. string fullPath = Path.Combine(fileServerPath, fileName);
  8496. doc.Save(fullPath, Aspose.Words.SaveFormat.Docx);
  8497. // 转换为下载地址
  8498. string downloadUrl = fullPath
  8499. .Replace(@"\", "/")
  8500. .Replace("D:/FTP/File/OA2023", "http://132.232.92.186:24", StringComparison.OrdinalIgnoreCase);
  8501. return (true, fullPath, downloadUrl);
  8502. }
  8503. /// <summary>
  8504. /// 填充 PDF 模板数据
  8505. /// </summary>
  8506. /// <param name="dataBody"></param>
  8507. /// <param name="language">
  8508. /// 下载语言:1-中文,2-英文
  8509. /// </param>
  8510. /// <returns></returns>
  8511. private async Task<Dictionary<string, string>> FillPdfTemplateAsync(DataBody dataBody, int language = 1)
  8512. {
  8513. #region PDF模板数据填充,数据来源:团组客户信息、家庭成员资料、公司资料、学校资料、证件信息等
  8514. var custInfo = dataBody.groupCustInfos.FirstOrDefault();
  8515. var groupInfo = dataBody.groupInfo;
  8516. var groupId = groupInfo?.Id ?? 0;
  8517. var idInfo = dataBody.certInfos.Where(x => x.SdId == 773).FirstOrDefault();
  8518. var passportInfo = dataBody.certInfos.Where(x => x.SdId == 774).FirstOrDefault();
  8519. var clinetInfo = dataBody.companyInfos;
  8520. var schoolInfos = dataBody.schoolInfos;
  8521. var familyInfos = dataBody.familyInfos;
  8522. var companyInfos = dataBody.companyInfos;
  8523. var pdfData = new Dictionary<string, string>();
  8524. #region 定义pdf模板中字段存储值
  8525. #region 个人信息
  8526. pdfData.Add("surname", custInfo?.LastName?.Trim() ?? ""); // 姓名(姓氏、名字)
  8527. pdfData.Add("birth_surname", custInfo?.LastName?.Trim() ?? ""); // 出生时姓氏
  8528. pdfData.Add("firstname", custInfo?.FirstName?.Trim() ?? ""); // 名字
  8529. #region 出生日期(日-月-年)
  8530. string birthday = string.Empty;
  8531. string idCard = AesEncryptionHelper.Decrypt(idInfo?.CertNo?.Trim() ?? "");
  8532. // 1. 优先从身份证中提取 (需为18位身份证)
  8533. if (!string.IsNullOrEmpty(idCard) && idCard.Length >= 14)
  8534. {
  8535. try
  8536. {
  8537. string year = idCard.Substring(6, 4);
  8538. string month = idCard.Substring(10, 2);
  8539. string day = idCard.Substring(12, 2);
  8540. // 统一格式为 yyyy-MM-dd
  8541. birthday = $"{day}-{month}-{year}";
  8542. }
  8543. catch
  8544. {
  8545. // 如果截取失败,回退为空
  8546. birthday = string.Empty;
  8547. }
  8548. }
  8549. // 2. 身份证不存在或提取失败,则从 custInfo 获取
  8550. if (string.IsNullOrEmpty(birthday))
  8551. {
  8552. DateTime? date = custInfo?.BirthDay;
  8553. // 验证逻辑:排除空值、1900年、或 DateTime.MinValue
  8554. if (!date.HasValue || date.Value.Year == 1900 || date.Value == DateTime.MinValue)
  8555. {
  8556. birthday = "";
  8557. }
  8558. else
  8559. {
  8560. birthday = date.Value.ToString("dd-MM-yyyy");
  8561. }
  8562. }
  8563. #endregion
  8564. pdfData.Add("birthday", birthday); // 出生日期
  8565. var area = custInfo.BirthProvince + custInfo.BirthCity; // 出生地区
  8566. pdfData.Add("birth_place", area);
  8567. pdfData.Add("birth_country", "中国"); // 出生国籍
  8568. pdfData.Add("current_nationality", "中国"); // 现国籍
  8569. pdfData.Add("birth_nationality", ""); // 出生国籍
  8570. pdfData.Add("other_nacionality", ""); // 其他国籍
  8571. pdfData.Add("sex", custInfo.Sex.ToString()); // 性别
  8572. pdfData.Add("marriage", custInfo.Marriage.ToString()); // 婚姻
  8573. pdfData.Add("legal_guardian_info", ""); // 国民身份号码
  8574. pdfData.Add("national_identity_number", idCard); // 父母的监护权(针对未成年人)/法定监护人
  8575. string applicantAddressAndEmail = $"{custInfo.Address} {custInfo.Email}";
  8576. pdfData.Add("applicant_address_and_email", applicantAddressAndEmail); // 申请人的家庭住址和电子邮箱地址
  8577. pdfData.Add("applicant_tel", custInfo.Tel); // 申请人的电话
  8578. #endregion
  8579. #region 护照信息
  8580. int passportType = passportInfo?.PassportType ?? 0;
  8581. var visatypeInfo = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == passportType);
  8582. pdfData.Add("passport_type_name", visatypeInfo?.Name ?? "");// 护照类型
  8583. pdfData.Add("travel_number", passportInfo?.CertNo ?? ""); // 签证 编号
  8584. pdfData.Add("travel_issues_country", passportInfo?.Country ?? "");// 签发 国
  8585. pdfData.Add("travel_issue_date", passportInfo?.IssueDt?.ToString("yyyy-MM-dd") ?? ""); // 签发日期
  8586. pdfData.Add("travel_valid_until", passportInfo?.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); // 有效期至
  8587. #endregion
  8588. #region 欧盟家庭成员个人信息
  8589. pdfData.Add("ue_family_info", ""); // 个人信息
  8590. pdfData.Add("ue_family_surname", ""); // 姓氏(家族名)
  8591. pdfData.Add("ue_family_firstname", ""); // 名字(名字)
  8592. pdfData.Add("ue_family_birthday", ""); // 出生日期 (日-月-年)
  8593. pdfData.Add("ue_family_nationality", ""); // 国籍
  8594. pdfData.Add("ue_family_travel_number", "");// 旅行证件或身份证号码
  8595. #endregion
  8596. #region 欧盟家庭关系 默认其他值
  8597. pdfData.Add("eu_family_relationship_other", "Off"); // 其他
  8598. pdfData.Add("eu_family_relationship_other_specify", ""); // 其他
  8599. #endregion
  8600. #region 是否在非国籍国居住 默认否
  8601. //pdfData.Add("unresidente_no", "Yes"); // 否
  8602. //pdfData.Add("unresidente_yes", "Off"); // 是
  8603. //pdfData.Add("unresidente_equivalen", ""); // 居住许可证
  8604. //pdfData.Add("unresidente_number", ""); // 编号
  8605. //pdfData.Add("unresidente_vaild", ""); // 有效期限
  8606. #endregion
  8607. #region 此次行程的目的
  8608. var visit_purpose = groupInfo.VisitPurpose;
  8609. if (!string.IsNullOrEmpty(visit_purpose))
  8610. {
  8611. if (visit_purpose.contains("旅游"))
  8612. {
  8613. pdfData.Add("purpose", "tourism"); // 旅游
  8614. }
  8615. else if (visit_purpose.contains("商务"))
  8616. {
  8617. pdfData.Add("purpose", "business"); // 商务
  8618. }
  8619. else if (visit_purpose.contains("亲友"))
  8620. {
  8621. pdfData.Add("purpose", "visiting_family_friends"); // 庆祝亲友团聚
  8622. }
  8623. else if (visit_purpose.contains("文化交流") || visit_purpose.contains("旅游"))
  8624. {
  8625. pdfData.Add("purpose", "cultural"); // 文化交流
  8626. }
  8627. else if (visit_purpose.contains("体育"))
  8628. {
  8629. pdfData.Add("purpose", "sports"); // 体育
  8630. }
  8631. else if (visit_purpose.contains("官方访问"))
  8632. {
  8633. pdfData.Add("purpose", "official"); // 官方访问
  8634. }
  8635. else if (visit_purpose.contains("医疗原因") || visit_purpose.contains("医疗"))
  8636. {
  8637. pdfData.Add("purpose", "medical_reasons"); // 医疗原因
  8638. }
  8639. else if (visit_purpose.contains("学习"))
  8640. {
  8641. pdfData.Add("purpose", "study"); // 学习
  8642. }
  8643. else if (visit_purpose.contains("机场中转") || visit_purpose.contains("过境"))
  8644. {
  8645. pdfData.Add("purpose", "airport_transit"); // 机场过境
  8646. }
  8647. else
  8648. {
  8649. pdfData.Add("purpose", "other"); // 其他
  8650. pdfData.Add("purpose_other_specify", ""); // 其他 - 备注
  8651. }
  8652. }
  8653. else
  8654. {
  8655. pdfData.Add("purpose", "other"); // 其他
  8656. pdfData.Add("purpose_other_specify", ""); // 其他 - 备注
  8657. }
  8658. #endregion
  8659. #region 职业
  8660. // 当前职业
  8661. string employer_info = string.Empty;
  8662. // 雇主及雇主的地址和电话号码。
  8663. string occupation = string.Empty;
  8664. // 职业信息
  8665. if (companyInfos != null && companyInfos.Count > 0)
  8666. {
  8667. occupation = companyInfos.FirstOrDefault()?.Job ?? "";
  8668. employer_info = $"{companyInfos.FirstOrDefault()?.Company ?? ""} {companyInfos.FirstOrDefault()?.CompanyAddress ?? ""} {companyInfos.FirstOrDefault()?.Phone ?? ""}";
  8669. }
  8670. pdfData.Add("employer_info", employer_info);
  8671. pdfData.Add("occupation", occupation);
  8672. #endregion
  8673. #region 停留信息
  8674. // 关于停留目的的补充说明
  8675. pdfData.Add("stay_info", "");
  8676. string[] country = new string[] { }; //接收处理的国家
  8677. string firstEntryLabel = string.Empty; // 首入申根国标签
  8678. string membeDescLabel = string.Empty; // 申根国目的地
  8679. string RuJingTime = string.Empty; // 入境时间
  8680. string LiJingTime = string.Empty; // 离境时间
  8681. string stayDays = string.Empty; // 停留天数
  8682. if (!string.IsNullOrEmpty(groupInfo.VisitCountry))
  8683. {
  8684. List<string> SGGNames = new List<string>();//接收处理后的国家 是申根国
  8685. if (groupInfo.VisitCountry.Contains(","))
  8686. country = groupInfo.VisitCountry.Split(',');
  8687. else if (groupInfo.VisitCountry.Contains(' '))
  8688. country = groupInfo.VisitCountry.Split(' ');
  8689. else if (groupInfo.VisitCountry.Contains(","))
  8690. country = groupInfo.VisitCountry.Split(',');
  8691. else if (groupInfo.VisitCountry.Contains("、"))
  8692. country = groupInfo.VisitCountry.Split('、');
  8693. else if (groupInfo.VisitCountry.Contains("|"))
  8694. country = groupInfo.VisitCountry.Split('|');
  8695. //判断是否是申根国家
  8696. for (int i = 0; i < country.Length; i++)
  8697. {
  8698. if (country[i].ToString() != null)
  8699. {
  8700. //在申根国家中筛选 该国家是否是申根国家
  8701. for (int j = 0; j < _shenGenGuos.Length; j++)
  8702. {
  8703. if (country[i] == _shenGenGuos[j])
  8704. SGGNames.Add(_shenGenGuos[j]); //添加申根国
  8705. }
  8706. }
  8707. }
  8708. //目的地国是否有申根国
  8709. if (SGGNames.Count > 0)
  8710. {
  8711. firstEntryLabel = SGGNames.First();
  8712. membeDescLabel = string.Join(",", SGGNames.ToArray());
  8713. //接收生根国详细信息 存储顺序 起飞日期:Day 起飞时刻:StartTime 抵达日期:ArrivedDate 到达时刻:EndTime
  8714. List<SSGDetails> ListSSGDetails = new List<SSGDetails>();
  8715. //处理申根国家 预定到达时间 预定离开时间 预定停留天数
  8716. for (int i = 0; i < SGGNames.Count; i++)
  8717. {
  8718. //在相同的国家下 得到该航班的信息 //抵达时间 起飞日期:Day 起飞时刻:StartTime 到达时刻:EndTime 抵达日期:ArrivedDate 飞行时间:FlightTime 航司 Fliagtcode 入境口岸
  8719. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  8720. //ResidenceTime1 机票三字码信息
  8721. if (atbc != null)
  8722. {
  8723. string HL_Three = ""; //三字码 Three
  8724. for (int j = 0; j < atbc.Rows.Count; j++)
  8725. {
  8726. HL_Three = atbc.Rows[j]["Three"].ToString();
  8727. if (!string.IsNullOrEmpty(HL_Three))
  8728. {
  8729. string threeCodeTwo = HL_Three.Substring(3);
  8730. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  8731. if (tc != null)
  8732. {
  8733. //首入申根国时间
  8734. if (SGGNames[i] == tc.Country)
  8735. {
  8736. SSGDetails SSGDetails = new SSGDetails()
  8737. {
  8738. Three = atbc.Rows[j]["Three"].ToString(), //三字码
  8739. Fliagtcode = atbc.Rows[j]["Fliagtcode"].ToString(), //航司
  8740. startDate = atbc.Rows[j]["Day"].ToString(), //整理起飞日期
  8741. startTime = atbc.Rows[j]["StartTime"].ToString(), //整理起飞时刻
  8742. endDate = atbc.Rows[j]["ArrivedDate"].ToString(), //整理抵达日期
  8743. endTime = atbc.Rows[j]["EndTime"].ToString() //整理抵达时刻
  8744. };
  8745. ListSSGDetails.Add(SSGDetails);
  8746. }
  8747. }
  8748. }
  8749. }
  8750. }
  8751. }
  8752. ListSSGDetails.Sort((a, b) => a.startDate.CompareTo(b.startDate));
  8753. //得到并计算出入境时间
  8754. if (ListSSGDetails != null)
  8755. {
  8756. RuJingTime = ListSSGDetails.First().endDate + " " + ListSSGDetails.First().endTime.Substring(0, 2) + ":" + ListSSGDetails.First().endTime.Substring(2); //入境时间
  8757. LiJingTime = ListSSGDetails[ListSSGDetails.Count - 1].startDate + " " + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(0, 2) + ":" + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(2); //离境时间
  8758. stayDays = Convert.ToDateTime(LiJingTime).Subtract(Convert.ToDateTime(RuJingTime)).Days.ToString();
  8759. }
  8760. }
  8761. }
  8762. pdfData.Add("member_destination", membeDescLabel); // 主要目的地成员国(如适用,还包括目的地的其他成员国)
  8763. pdfData.Add("member_first_entry", firstEntryLabel); // 首入申根国标签
  8764. pdfData.Add("stayDays", stayDays); // 停留天数
  8765. pdfData.Add("request_entry", "1"); // 申请入境次数(默认一次) 1:一次入境 2:两次入境 3:多次入境
  8766. pdfData.Add("schengen_first_area_arrival", RuJingTime); // 首次抵达日期
  8767. pdfData.Add("schengen_first_area_departure", LiJingTime); // 首次离开日期
  8768. #endregion
  8769. #region 此前录过指纹
  8770. pdfData.Add("schengen_fingerprints_status", "1"); // 1 是 2 否 默认 否
  8771. //pdfData.Add("schengen_fingerprints_date", ""); // 如有,请写明日期
  8772. //pdfData.Add("schengen_fingerprints_visa_no", ""); // 编号
  8773. #endregion
  8774. #region 最终目的地入境许可
  8775. pdfData.Add("entry_permit_issued", ""); // 发布者
  8776. pdfData.Add("entry_permit_valid", ""); // 有效期限 起
  8777. pdfData.Add("entry_permit_until", ""); // 有效期限 止
  8778. #endregion
  8779. #region 邀请人/酒店信息
  8780. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  8781. .Where(x => x.DiId == groupId)
  8782. //.Where(x => x.City.contains(city))
  8783. .First();
  8784. //酒店住址
  8785. pdfData.Add("schengen_inviting_name", hotelInfo?.HotelName ?? ""); // 招待方的酒店、邀请人 名称
  8786. var otherInfo = $"{hotelInfo?.HotelAddress ?? ""}";
  8787. pdfData.Add("schengen_inviting_hotel_address_email", otherInfo); // 酒店/临时住宿场所的地址和电子邮箱地址
  8788. pdfData.Add("schengen_inviting_hotel_tel", hotelInfo?.HotelTel ?? ""); // 电话号码
  8789. #endregion
  8790. #region 邀请公司/组织信息
  8791. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  8792. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  8793. //.Where(x => x.Country.Contains(county))
  8794. //.Where(x => x.Area.Contains(city))
  8795. .First();
  8796. string oaInfo = $"{oa?.Client ?? ""} {oa?.Address ?? ""}";
  8797. pdfData.Add("inviting_name_address", oaInfo); // 邀请公司/组织的名称及地址
  8798. string contactInfo = $"{oa?.Contact ?? ""} {oa?.Tel ?? ""} {oa?.EmailOrWeChat ?? ""}";
  8799. pdfData.Add("inviting_info", contactInfo); // 公司/组织中联系人的姓氏、名字、地址、电话号码以及电子邮箱地址
  8800. pdfData.Add("inviting_tel", oa?.Tel ?? ""); // 电话号码(关于)公司/组织
  8801. #endregion
  8802. // 由赞助方(主办方、公司、组织)提供 - 其他(请具体说明) 默认单位名称
  8803. pdfData.Add("cost_covered_sponsor_other_specify", companyInfos.FirstOrDefault()?.Company ?? "");
  8804. #endregion
  8805. #endregion
  8806. #region 通过 DeepSeek AI实现中文转英文 language == 2 时转换 英文
  8807. if (language == 2)
  8808. {
  8809. pdfData = await DeepSeekCNToENAsync(JsonConvert.SerializeObject(pdfData));
  8810. }
  8811. #endregion
  8812. return pdfData;
  8813. }
  8814. /// <summary>
  8815. /// 通过 DeepSeek AI实现中文转英文
  8816. /// </summary>
  8817. /// <param name="jsonstring"></param>
  8818. /// <returns></returns>
  8819. private async Task<Dictionary<string, string>> DeepSeekCNToENAsync(string jsonstring)
  8820. {
  8821. var dic = new Dictionary<string, string>();
  8822. string question = $@"JSON中文字段转英文大写
  8823. 任务
  8824. 将JSON中所有中文字段值转换为英文,并全部大写。
  8825. 输入数据
  8826. {jsonstring}
  8827. 转换规则
  8828. 1.中文姓名:拼音转换,姓氏单字,名字连写
  8829. 2.中文地址:按层级翻译(中国→CHINA,省/市/区→拼音+PROVINCE/CITY/DISTRICT,街道建筑→拼音)
  8830. 3.公司名称:标准英文译名
  8831. 4.国家/国籍:CHINA
  8832. 5.枚举值:other→OTHER,但Yes/Off保持原样不变
  8833. 6.全部大写:所有转换后的英文字母转大写(Yes/Off除外)
  8834. 7.空值:保持不变
  8835. 输出
  8836. 保持JSON结构不变,只转换中文内容。只返回JSON结构体。";
  8837. var deepseek_result = await _deepSeekService.ChatAsync(question);
  8838. if (deepseek_result.Success)
  8839. {
  8840. _logger.LogInformation("【签证文件下载】【DeepSeekAI】中文转英文完成!消耗Token:{TokensUsed}", deepseek_result.TokensUsed);
  8841. try
  8842. {
  8843. string rawJson = deepseek_result.Answer ?? "";
  8844. // 核心优化:清洗 Markdown 代码块标识 (```json ... ```)
  8845. if (rawJson.Contains("```"))
  8846. {
  8847. rawJson = rawJson.Replace("```json", "").Replace("```", "").Trim();
  8848. }
  8849. // 使用 Newtonsoft.Json 解析
  8850. dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(rawJson);
  8851. if (dic == null)
  8852. {
  8853. _logger.LogWarning("【签证文件下载】警告:解析后的字典为空。内容:{RawJson}", rawJson);
  8854. }
  8855. }
  8856. catch (JsonReaderException jex)
  8857. {
  8858. // 专门捕获 JSON 格式错误
  8859. _logger.LogError("【签证文件下载】【DeepSeekAI】JSON 语法错误:{Message}", jex.Message);
  8860. }
  8861. catch (Exception ex)
  8862. {
  8863. _logger.LogError("【签证文件下载】【DeepSeekAI】系统异常:{ErrorMessage}", ex.Message);
  8864. }
  8865. }
  8866. return dic;
  8867. }
  8868. #region iTextSharp pdf 设置值辅助方法
  8869. /// <summary>
  8870. /// 设置文本值
  8871. /// 辅助方法
  8872. /// </summary>
  8873. /// <param name="formFields"></param>
  8874. /// <param name="fieldName"></param>
  8875. /// <param name="value"></param>
  8876. private static void SetFieldValue(AcroFields formFields, string fieldName, string value)
  8877. {
  8878. if (formFields.Fields.ContainsKey(fieldName) && !string.IsNullOrEmpty(value))
  8879. {
  8880. // 设置宋体(支持中文)
  8881. //BaseFont bf = BaseFont.CreateFont("C:\\Windows\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
  8882. //formFields.SetFieldProperty(fieldName, "textfont", bf, null);
  8883. //// 设置字号:8
  8884. //formFields.SetFieldProperty(fieldName, "textsize", 8f, null);
  8885. // 设置字体颜色:黑色
  8886. formFields.SetFieldProperty(fieldName, "textcolor", iTextSharp.text.BaseColor.BLACK, null);
  8887. // 填充值(显示值、实际值、保存外观)
  8888. formFields.SetField(fieldName, value, value, true);
  8889. // 设置打印标志
  8890. formFields.SetFieldProperty(fieldName, "setflags", PdfFormField.FLAGS_PRINT, null);
  8891. }
  8892. }
  8893. /// <summary>
  8894. /// Word填充书签
  8895. /// </summary>
  8896. /// <param name="doc"></param>
  8897. /// <param name="builder"></param>
  8898. /// <param name="bookmarkName"></param>
  8899. /// <param name="value"></param>
  8900. private void FillBookmark(Document doc, DocumentBuilder builder, string bookmarkName, string value)
  8901. {
  8902. if (doc.Range.Bookmarks[bookmarkName] != null)
  8903. {
  8904. builder.MoveToBookmark(bookmarkName);
  8905. builder.Write(value ?? "");
  8906. }
  8907. }
  8908. #endregion
  8909. #region 文档下载辅助实体类
  8910. private class VisaDateView
  8911. {
  8912. /// <summary>
  8913. /// 团组信息
  8914. /// </summary>
  8915. public Grp_DelegationInfo groupInfo { get; set; }
  8916. /// <summary>
  8917. /// 身份证信息
  8918. /// </summary>
  8919. public Crm_CustomerCert idInfo { get; set; }
  8920. /// <summary>
  8921. /// 护照信息
  8922. /// </summary>
  8923. public Crm_CustomerCert passportInfo { get; set; }
  8924. /// <summary>
  8925. /// 客户信息
  8926. /// </summary>
  8927. public Crm_DeleClient custInfo { get; set; }
  8928. /// <summary>
  8929. /// 学校资料
  8930. /// </summary>
  8931. public List<Crm_VisaCustomerSchool> schoolInfos { get; set; }
  8932. /// <summary>
  8933. /// 家庭成员资料
  8934. /// </summary>
  8935. public List<Crm_VisaCustomerFamily> familyInfos { get; set; }
  8936. /// <summary>
  8937. /// 公司资料
  8938. /// </summary>
  8939. public List<Crm_VisaCustomerCompany> companyInfos { get; set; }
  8940. }
  8941. private class SSGDetails
  8942. {
  8943. public string Three { get; set; } //三字码
  8944. public string Fliagtcode { get; set; } //航司
  8945. public string startDate { get; set; } //首入申根国日期
  8946. public string startTime { get; set; } //首入申根国时间
  8947. public string endDate { get; set; } //离开申根国日期
  8948. public string endTime { get; set; } //离开申根国时间
  8949. }
  8950. /// <summary>
  8951. /// 文件生成请求体
  8952. /// </summary>
  8953. private class GeneratorFileReq
  8954. {
  8955. public int groupId { get; set; }
  8956. public int fileTypeId { get; set; }
  8957. public int dcIds { get; set; }
  8958. /// <summary>
  8959. /// 模板存储地址
  8960. /// </summary>
  8961. public string tempPath { get; set; } = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Template/";
  8962. public string fileServerPath { get; set; }
  8963. public int language { get; set; } = 1;
  8964. public DataBody dataBody { get; set; }
  8965. }
  8966. private class DataBody
  8967. {
  8968. public Grp_DelegationInfo groupInfo { get; set; }
  8969. public List<Grp_TourClientList> groupClients { get; set; }
  8970. public List<Crm_DeleClient> groupCustInfos { get; set; }
  8971. public List<Crm_VisaCustomerFamily> familyInfos { get; set; }
  8972. public List<Crm_CustomerCert> certInfos { get; set; }
  8973. public List<Crm_VisaCustomerCompany> companyInfos { get; set; }
  8974. public List<Crm_VisaCustomerSchool> schoolInfos { get; set; }
  8975. }
  8976. #endregion
  8977. #endregion
  8978. /// <summary>
  8979. /// 根据团组Id获取签证客户信息List
  8980. /// </summary>
  8981. /// <param name="dto">请求dto</param>
  8982. /// <returns></returns>
  8983. [HttpPost]
  8984. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8985. public async Task<IActionResult> GetCrmByGroupId(ClientByGroupIdDto dto)
  8986. {
  8987. var data = await _groupRepository.GetCrmByGroupId(dto);
  8988. return Ok(JsonView(data.Code == 0, data.Code != 0 ? "暂无信息" : "操作成功", data.Data));
  8989. }
  8990. /// <summary>
  8991. /// IOS获取团组签证拍照上传进度01(团组列表)
  8992. /// </summary>
  8993. /// <param name="dto">请求dto</param>
  8994. /// <returns></returns>
  8995. [HttpPost]
  8996. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8997. public async Task<IActionResult> PostIOSVisaProgress(IOS_VisaDto dto)
  8998. {
  8999. if (dto == null)
  9000. {
  9001. return Ok(JsonView(false, "参数为空"));
  9002. }
  9003. DelegationVisaViewList visaList = _delegationVisaRep.GetDelegationList(dto);
  9004. return Ok(JsonView(visaList));
  9005. }
  9006. /// <summary>
  9007. /// IOS获取团组签证拍照上传进度02(团组签证详情\人员列表\国家)
  9008. /// </summary>
  9009. /// <returns></returns>
  9010. [HttpPost]
  9011. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9012. public async Task<ActionResult> PostIOSVisaProgressContent(IOS_VisaCustomerListDto dto)
  9013. {
  9014. if (dto == null)
  9015. {
  9016. return Ok(JsonView(false, "请求错误:"));
  9017. }
  9018. List<DelegationVisaProgressView> list = _delegationVisaRep.GetDelegationProgressList(dto.diId);
  9019. return Ok(JsonView(list));
  9020. }
  9021. /// <summary>
  9022. /// IOS获取团组签证拍照上传进度03(相册)
  9023. /// </summary>
  9024. /// <returns></returns>
  9025. [HttpPost]
  9026. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9027. public async Task<ActionResult> PostIOSVisaProgressImageList(IOS_VisaImageListDto dto)
  9028. {
  9029. if (dto == null)
  9030. {
  9031. return Ok(JsonView(false, "请求错误:"));
  9032. }
  9033. List<VisaProgressImageView> list = _delegationVisaRep.GetVisaProgressImageList(dto.visaProgressCustomerId, dto.picType);
  9034. string url = AppSettingsHelper.Get("VisaProgressImageBaseUrl") + AppSettingsHelper.Get("VisaProgressImageFtpPath");
  9035. list.ForEach(s => s.url = url);
  9036. return Ok(JsonView(list));
  9037. }
  9038. /// <summary>
  9039. /// IOS获取团组签证拍照上传进度04(图片上传)
  9040. /// </summary>
  9041. /// <param name="dto"></param>
  9042. /// <returns></returns>
  9043. [HttpPost]
  9044. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9045. public async Task<ActionResult> PostIOSVisaProgressUploadImage(IOS_VisaUploadImageDto dto)
  9046. {
  9047. //string result = decodeBase64ToImage(dto.base64DataURL, dto.imageName);
  9048. //if (!string.IsNullOrEmpty(result))
  9049. //{
  9050. //}
  9051. //else {
  9052. // return Ok(JsonView(false, "上传失败"));
  9053. //}
  9054. var dt1970 = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  9055. int sucNum = 0;
  9056. try
  9057. {
  9058. foreach (var item in dto.base64DataList)
  9059. {
  9060. string imageName = dto.imageName + ((DateTime.Now.Ticks - dt1970.Ticks) / 10000).ToString();
  9061. string result = DecodeBase64ToImage(item, imageName);
  9062. if (!string.IsNullOrEmpty(result))
  9063. {
  9064. var pic = new Grp_VisaProgressCustomerPicture
  9065. {
  9066. CreateUserId = dto.CreateUserId,
  9067. PicName = imageName,
  9068. PicPath = result,
  9069. VisaProgressCustomerId = dto.visaProgressCustomerId
  9070. };
  9071. int insertResult = await _delegationVisaRep.AddAsync<Grp_VisaProgressCustomerPicture>(pic);
  9072. if (insertResult > 0)
  9073. {
  9074. sucNum++;
  9075. }
  9076. }
  9077. }
  9078. }
  9079. catch (Exception ex)
  9080. {
  9081. return Ok(JsonView(false, ex.Message));
  9082. }
  9083. string msg = string.Format(@"成功上传{0}张", sucNum);
  9084. return Ok(JsonView(true, msg));
  9085. }
  9086. private string DecodeBase64ToImage(string base64DataURL, string imgName)
  9087. {
  9088. string filename = "";//声明一个string类型的相对路径
  9089. String base64 = base64DataURL.Substring(base64DataURL.IndexOf(",") + 1); //将‘,’以前的多余字符串删除
  9090. System.Drawing.Bitmap bitmap = null;//定义一个Bitmap对象,接收转换完成的图片
  9091. try//会有异常抛出,try,catch一下
  9092. {
  9093. byte[] arr = Convert.FromBase64String(base64);//将纯净资源Base64转换成等效的8位无符号整形数组
  9094. var ms = new System.IO.MemoryStream(arr);//转换成无法调整大小的MemoryStream对象
  9095. bitmap = new System.Drawing.Bitmap(ms);//将MemoryStream对象转换成Bitmap对象
  9096. var fileDir = AppSettingsHelper.Get("VisaProgressImageBasePath");
  9097. //文件名称
  9098. filename = "VisaProgress_" + DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + imgName + ".jpeg";//所要保存的相对路径及名字
  9099. //上传的文件的路径
  9100. string filePath = "";
  9101. if (!Directory.Exists(fileDir))
  9102. {
  9103. Directory.CreateDirectory(fileDir);
  9104. }
  9105. //上传的文件的路径
  9106. filePath = fileDir + filename;
  9107. //string url = HttpRuntime.AppDomainAppPath.ToString();
  9108. //string tmpRootDir = System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString()); //获取程序根目录
  9109. //string imagesurl2 = tmpRootDir + filename; //转换成绝对路径
  9110. bitmap.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);//保存到服务器路径
  9111. //bitmap.Save(filePath + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
  9112. //bitmap.Save(filePath + ".gif", System.Drawing.Imaging.ImageFormat.Gif);
  9113. //bitmap.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
  9114. ms.Close();//关闭当前流,并释放所有与之关联的资源
  9115. bitmap.Dispose();
  9116. }
  9117. catch (Exception e)
  9118. {
  9119. string massage = e.Message;
  9120. Logs("IOS图片上传Error:" + massage);
  9121. //filename = e.Message;
  9122. }
  9123. return filename;//返回相对路径
  9124. }
  9125. /// <summary>
  9126. /// IOS获取团组签证拍照上传进度05(修改签证状态/通知)
  9127. /// </summary>
  9128. /// <param name="dto"></param>
  9129. /// <returns></returns>
  9130. [HttpPost]
  9131. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9132. public async Task<ActionResult> PostIOSVisaProgressChangeStatus(IOS_VisaChangeStatusDto dto)
  9133. {
  9134. if (dto == null)
  9135. {
  9136. return Ok(JsonView(false, "请求错误:"));
  9137. }
  9138. string msg = "参数错误";
  9139. if (dto.diId > 0 && dto.visaStatus > 0 && dto.visaStatus < 4)
  9140. {
  9141. try
  9142. {
  9143. //_delegationVisaRep.BeginTran();
  9144. var updCount = await _delegationVisaRep._sqlSugar.Updateable<Grp_VisaProgressCustomer>()
  9145. .SetColumns(it => it.WorkStatus == dto.visaStatus)
  9146. .Where(s => s.Id == dto.visaProgressCustomerId)
  9147. .ExecuteCommandAsync();
  9148. if (updCount > 0 && dto.publishCode == 1)
  9149. {
  9150. _delegationVisaRep.ChangeDataBase(DBEnum.OA2014DB); //切换到新OA后删除
  9151. string sqlDelegation = string.Format(@" Select * From DelegationInfo With(Nolock) Where Id = {0} ", dto.diId);
  9152. OA2021_DelegationInfo groupData = _sqlSugar.SqlQueryable<OA2021_DelegationInfo>(sqlDelegation).First();
  9153. //GroupInfoDto grpDto = new GroupInfoDto() { Id = dto.diId };
  9154. //var groupData = await _groupRepository.GetGroupInfo(grpDto);
  9155. _delegationVisaRep.ChangeDataBase(DBEnum.OA2023DB); //切换到新OA后删除
  9156. if (groupData == null)
  9157. {
  9158. _delegationVisaRep.RollbackTran();
  9159. }
  9160. string title = string.Format(@"[签证进度更新]");
  9161. string content = string.Format(@"测试文本");
  9162. bool rst = await _message.AddMsg(new MessageDto()
  9163. {
  9164. Type = MessageTypeEnum.GroupVisaProgressUpdate,
  9165. IssuerId = dto.publisher,
  9166. Title = title,
  9167. Content = content,
  9168. ReleaseTime = DateTime.Now,
  9169. UIdList = new List<int> {
  9170. 234
  9171. }
  9172. });
  9173. if (rst)
  9174. {
  9175. return Ok(JsonView(true, "发送通知成功"));
  9176. }
  9177. }
  9178. //_delegationVisaRep.CommitTran();
  9179. }
  9180. catch (Exception)
  9181. {
  9182. //_delegationVisaRep.RollbackTran();
  9183. }
  9184. }
  9185. return Ok(JsonView(true, msg));
  9186. }
  9187. #endregion
  9188. #endregion
  9189. #region 团组任务分配
  9190. /// <summary>
  9191. /// 团组任务分配初始化
  9192. /// </summary>
  9193. /// <returns></returns>
  9194. [HttpPost]
  9195. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9196. public async Task<IActionResult> GetTaskAssignmen()
  9197. {
  9198. var groupData = await _taskAssignmentRep.GetTaskAssignmen();
  9199. if (groupData.Code != 0)
  9200. {
  9201. return Ok(JsonView(false, groupData.Msg));
  9202. }
  9203. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  9204. }
  9205. /// <summary>
  9206. /// 团组任务分配查询
  9207. /// </summary>
  9208. /// <param name="dto"></param>
  9209. /// <returns></returns>
  9210. [HttpPost]
  9211. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9212. public async Task<IActionResult> TaskAssignmenQuery(TaskAssignmenQueryDto dto)
  9213. {
  9214. var groupData = await _taskAssignmentRep.TaskAssignmenQuery(dto);
  9215. if (groupData.Code != 0)
  9216. {
  9217. return Ok(JsonView(false, groupData.Msg));
  9218. }
  9219. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  9220. }
  9221. /// <summary>
  9222. /// 团组任务分配操作
  9223. /// </summary>
  9224. /// <param name="dto"></param>
  9225. /// <returns></returns>
  9226. [HttpPost]
  9227. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9228. public async Task<IActionResult> GetTaskAssignmenOp(TaskAssignmenDto dto)
  9229. {
  9230. Result groupData = await _taskAssignmentRep.GetTaskAssignmenOp(dto);
  9231. if (groupData.Code != 0)
  9232. {
  9233. return Ok(JsonView(false, groupData.Msg));
  9234. }
  9235. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  9236. }
  9237. /// <summary>
  9238. /// 团组任务分配
  9239. /// 批量分配
  9240. /// 查询团组
  9241. /// </summary>
  9242. /// <param name="dto"></param>
  9243. /// <returns></returns>
  9244. [HttpPost]
  9245. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9246. public async Task<IActionResult> TaskAllocationGroupSelect(TaskAllocationGroupSelectDto dto)
  9247. {
  9248. //参数验证
  9249. if (dto.PortType < 1 || dto.PortType > 3) return Ok(JsonView(false, MsgTips.Port));
  9250. if (!DateTime.TryParse(dto.VisitBeginDt, out _) || !DateTime.TryParse(dto.VisitEndDt, out _))
  9251. return Ok(JsonView(false, "团组出访开始/结束日期格式不正确!"));
  9252. return Ok(await _taskAssignmentRep.TaskAllocationGroupSelect(dto));
  9253. }
  9254. /// <summary>
  9255. /// 团组任务分配
  9256. /// 批量分配
  9257. /// </summary>
  9258. /// <param name="dto"></param>
  9259. /// <returns></returns>
  9260. [HttpPost]
  9261. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9262. public async Task<IActionResult> TaskAllocationBulkAdd(TaskAllocationBulkAddDto dto)
  9263. {
  9264. //参数验证
  9265. if (dto.UserIds.Length < 1) return Ok(JsonView(false, $"请选择分配人员!"));
  9266. if (dto.PermissionTypeIds.Length < 1) return Ok(JsonView(false, $"请选择分配类型!"));
  9267. if (dto.GroupIds.Length < 1) return Ok(JsonView(false, "请选择分配团组Id"));
  9268. if (dto.CurrUserId < 1) return Ok(JsonView(false, "请传入有效的CurrUserId数组参数"));
  9269. return Ok(await _taskAssignmentRep.TaskAllocationBulkAdd(dto));
  9270. }
  9271. #endregion
  9272. #region 团组费用审核
  9273. /// <summary>
  9274. /// 费用审核
  9275. /// 团组列表 Page
  9276. /// </summary>
  9277. /// <param name="dto">团组列表请求dto</param>
  9278. /// <returns></returns>
  9279. [HttpPost]
  9280. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9281. public async Task<IActionResult> PostExpenseAuditGroupPageItems(ExpenseAuditGroupPageItemsDto dto)
  9282. {
  9283. #region 参数验证
  9284. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  9285. if (dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  9286. #region 页面操作权限验证
  9287. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  9288. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  9289. #endregion
  9290. #endregion
  9291. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) // web/Android/IOS
  9292. {
  9293. string sqlWhere = "WHERE gdi.IsDel = 0";
  9294. var parameters = new List<SugarParameter>();
  9295. // 状态条件(保持不变)
  9296. if (dto.IsSure >= 0)
  9297. {
  9298. sqlWhere += $" AND IsSure = {dto.IsSure}";
  9299. }
  9300. // 搜索条件
  9301. if (!string.IsNullOrEmpty(dto.SearchCriteria))
  9302. {
  9303. // 将搜索词按空格分割为多个关键字(支持多关键字检索)
  9304. var keywords = dto.SearchCriteria.Split(new[] { ' ', ',', ',' }, StringSplitOptions.RemoveEmptyEntries);
  9305. if (keywords.Length > 0)
  9306. {
  9307. var searchConditions = new List<string>();
  9308. foreach (var keyword in keywords)
  9309. {
  9310. if (!string.IsNullOrWhiteSpace(keyword))
  9311. {
  9312. // 对每个关键字构建多字段检索条件
  9313. var keywordConditions = new List<string>
  9314. {
  9315. $"ssd.Name LIKE '%{keyword}%'",
  9316. $"gdi.TeamName LIKE '%{keyword}%'",
  9317. $"gdi.ClientName LIKE '%{keyword}%'",
  9318. $"su.CnName LIKE '%{keyword}%'",
  9319. $"gdi.SalesQuoteNo LIKE '%{keyword}%'",
  9320. $"gdi.TourCode LIKE '%{keyword}%'",
  9321. $"gdi.ClientUnit LIKE '%{keyword}%'",
  9322. $"ssd1.Name LIKE '%{keyword}%'"
  9323. };
  9324. // 将多个字段条件用 OR 连接
  9325. searchConditions.Add($"({string.Join(" OR ", keywordConditions)})");
  9326. }
  9327. }
  9328. // 将多个关键字条件用 AND 连接(实现多关键字AND搜索)
  9329. if (searchConditions.Count > 0)
  9330. {
  9331. sqlWhere += $" AND ({string.Join(" AND ", searchConditions)})";
  9332. }
  9333. }
  9334. }
  9335. // 基础查询sql
  9336. string sql = $@"
  9337. SELECT Row_Number, Id, SalesQuoteNo, TourCode, TeamTypeId, TeamType,
  9338. TeamName, ClientName, ClientUnit, TeamLevId, TeamLev, VisitDate,
  9339. VisitDays, VisitPNumber, JietuanOperator, IsSure, CreateTime
  9340. FROM (
  9341. SELECT ROW_NUMBER() OVER (ORDER BY gdi.VisitDate DESC) AS Row_Number,
  9342. gdi.Id, gdi.SalesQuoteNo, gdi.TourCode,
  9343. ssd1.Id AS TeamLevId, ssd1.Name AS TeamLev,
  9344. gdi.TeamName, gdi.ClientName, gdi.ClientUnit,
  9345. ssd.Id AS TeamTypeId, ssd.Name AS TeamType,
  9346. gdi.VisitDate, gdi.VisitDays, gdi.VisitPNumber,
  9347. su.CnName AS JietuanOperator, gdi.IsSure, gdi.CreateTime
  9348. FROM Grp_DelegationInfo gdi
  9349. LEFT JOIN Sys_SetData ssd ON gdi.TeamDid = ssd.Id
  9350. LEFT JOIN Sys_SetData ssd1 ON gdi.TeamLevSId = ssd1.Id
  9351. LEFT JOIN Sys_Users su ON gdi.JietuanOperator = su.Id
  9352. {sqlWhere}
  9353. ) AS temp";
  9354. RefAsync<int> total = 0;
  9355. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql)
  9356. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  9357. var _view = new
  9358. {
  9359. PageFuncAuth = pageFunAuthView,
  9360. Data = _DelegationList
  9361. };
  9362. return Ok(JsonView(true, "查询成功!", _view, total));
  9363. }
  9364. else
  9365. {
  9366. return Ok(JsonView(false, "查询失败"));
  9367. }
  9368. }
  9369. /// <summary>
  9370. /// 获取团组费用审核
  9371. /// </summary>
  9372. /// <param name="_dto"></param>
  9373. /// <returns></returns>
  9374. [HttpPost]
  9375. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9376. public async Task<IActionResult> PostSearchGrpCreditCardPayment(Search_GrpCreditCardPaymentDto _dto)
  9377. {
  9378. try
  9379. {
  9380. #region 参数验证
  9381. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  9382. if (_dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  9383. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  9384. #region 页面操作权限验证
  9385. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  9386. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  9387. #endregion
  9388. #endregion
  9389. var _view = new Grp_CreditCardPaymentView();
  9390. var clientNameList = GetSimplClientList(_dto.DiId);
  9391. #region 费用清单
  9392. var exp = Expressionable.Create<Grp_CreditCardPayment>();
  9393. exp.AndIF(_dto.AuditStatus != -1, it => it.IsAuditGM == _dto.AuditStatus);
  9394. exp.AndIF(_dto.Label != -1, it => it.CTable == _dto.Label);
  9395. var entityList = _groupRepository.Query<Grp_CreditCardPayment>(s => s.DIId == _dto.DiId && s.IsDel == 0 && s.CreateUserId > 0).Where(exp.ToExpression()).ToList();
  9396. var detailList = new List<Grp_CreditCardPaymentDetailView>();
  9397. var ccpCurrencyPrices = new List<CreditCardPaymentCurrencyPriceItem>();
  9398. /*
  9399. * 76://酒店预订
  9400. */
  9401. var _HotelReservations = await _groupRepository.Query<Grp_HotelReservations>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9402. var _HotelReservationsContents = await _groupRepository.Query<Grp_HotelReservationsContent>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9403. /*
  9404. * 79://车/导游地接
  9405. */
  9406. var _CarTouristGuideGroundReservations = await _groupRepository.Query<Grp_CarTouristGuideGroundReservations>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9407. var _CarTouristGuideGroundReservationsContent = await _groupRepository.Query<Grp_CarTouristGuideGroundReservationsContent>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9408. /*
  9409. * 80: //签证
  9410. */
  9411. var _VisaInfos = await _groupRepository.Query<Grp_VisaInfo>(s => s.DIId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9412. /*
  9413. *81: //邀请/公务活动
  9414. */
  9415. var _InvitationOfficialActivities = await _groupRepository.Query<Grp_InvitationOfficialActivities>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9416. /*
  9417. * 82: //团组客户保险
  9418. */
  9419. var _Customers = await _groupRepository.Query<Grp_Customers>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9420. /*
  9421. * Lable = 85 机票预订
  9422. */
  9423. var p_AirTicketReservations = await _groupRepository.Query<Grp_AirTicketReservations>(s => s.DIId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9424. /*
  9425. * 85 机票预定
  9426. */
  9427. var _AirTicketReservations = await _groupRepository.Query<Grp_AirTicketReservations>(s => s.DIId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9428. /*
  9429. * 98 其他款项
  9430. */
  9431. var _DecreasePayments = await _groupRepository.Query<Grp_DecreasePayments>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9432. /*
  9433. * 285:收款退还
  9434. */
  9435. var _PaymentRefundAndOtherMoneys = await _groupRepository.Query<Fin_PaymentRefundAndOtherMoney>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9436. /*
  9437. * 1015: //超支费用
  9438. */
  9439. var _GroupExtraCosts = await _groupRepository.Query<Fin_GroupExtraCost>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  9440. var initDatas = await _groupRepository.Query<Sys_SetData>(s => s.IsDel == 0).ToListAsync();
  9441. /*
  9442. * 币种信息
  9443. */
  9444. var currencyItems = initDatas.Where(s => s.STid == 66).ToList();
  9445. /*
  9446. * 车/导游地接 费用类型
  9447. */
  9448. var carFeeTypeItems = initDatas.Where(s => s.STid == 17).ToList();
  9449. /*
  9450. * 车/导游地接 费用类型
  9451. */
  9452. var carFeeItems = initDatas.Where(s => s.STid == 83).ToList();
  9453. var cityData = await _groupRepository.Query<Grp_NationalTravelFee>(s => s.IsDel == 0).ToListAsync();
  9454. /*
  9455. * 用户信息
  9456. */
  9457. var userItems = await _groupRepository._sqlSugar.Queryable<Sys_Users>().ToListAsync();
  9458. /*
  9459. * 费用模块
  9460. */
  9461. var sdPriceName = initDatas.Where(s => s.Id == _dto.Label).First();
  9462. string priceModule = string.Empty;
  9463. if (sdPriceName != null)
  9464. {
  9465. priceModule = sdPriceName.Name;
  9466. }
  9467. /*
  9468. * 成本信息
  9469. */
  9470. var groupCost = _groupRepository.Query<Grp_GroupCostParameter>(s => s.DiId == _dto.DiId && s.IsDel == 0).First();
  9471. decimal _groupRate = 0.0000M;
  9472. string _groupCurrencyCode = "-";
  9473. if (groupCost != null)
  9474. {
  9475. _groupRate = groupCost.Rate;
  9476. if (int.TryParse(groupCost.Currency, out int _currency))
  9477. {
  9478. _groupCurrencyCode = currencyItems.Find(it => it.Id == _currency)?.Name ?? "-";
  9479. }
  9480. else _groupCurrencyCode = groupCost.Currency;
  9481. }
  9482. string costContentSql = $"Select * From Grp_GroupCost";
  9483. var groupCostDetails = _sqlSugar.SqlQueryable<GroupCostAuditView>(costContentSql).Where(x => x.IsDel == 0 && x.Diid == _dto.DiId).ToList();
  9484. //处理日期为空的天数
  9485. for (int i = 0; i < groupCostDetails.Count; i++)
  9486. if (i != 0)
  9487. if (string.IsNullOrEmpty(groupCostDetails[i].Date))
  9488. groupCostDetails[i].Date = groupCostDetails[i - 1].Date;
  9489. /*
  9490. * 处理详情数据
  9491. */
  9492. foreach (var entity in entityList)
  9493. {
  9494. var _detail = new Grp_CreditCardPaymentDetailView
  9495. {
  9496. Id = entity.Id,
  9497. PriceName = priceModule,
  9498. PayType = initDatas.Find(it => it.Id == entity.PayDId)?.Name ?? "-"
  9499. };
  9500. if (_detail.PayType.Equals("现金")) _detail.CardType = "-";
  9501. else _detail.CardType = initDatas.Find(it => it.Id == entity.CTDId)?.Name ?? "-";
  9502. //处理金额
  9503. if (entity.CTable == 1015)
  9504. {
  9505. var czInfo = _GroupExtraCosts.Find(x => entity.CId == x.Id);
  9506. if (czInfo != null)
  9507. {
  9508. entity.PayMoney = czInfo.Price * czInfo.PriceCount;
  9509. entity.RMBPrice = czInfo.Price * czInfo.PriceCount * entity.DayRate;
  9510. }
  9511. }
  9512. /*
  9513. * 应付款金额
  9514. */
  9515. var sdPaymentCurrency_WaitPay = currencyItems.Where(s => s.Id == entity.PaymentCurrency).FirstOrDefault();
  9516. string PaymentCurrency_WaitPay = "Unknown";
  9517. string hotelCurrncyCode = "Unknown";
  9518. string hotelCurrncyName = "Unknown";
  9519. if (sdPaymentCurrency_WaitPay != null)
  9520. {
  9521. PaymentCurrency_WaitPay = sdPaymentCurrency_WaitPay.Name;
  9522. hotelCurrncyCode = sdPaymentCurrency_WaitPay.Name;
  9523. hotelCurrncyName = sdPaymentCurrency_WaitPay.Remark;
  9524. if (hotelCurrncyCode.Equals("CNY"))
  9525. {
  9526. entity.DayRate = 1.0000M;
  9527. }
  9528. }
  9529. _detail.WaitPay = entity.PayMoney.ConvertToDecimal1().ToString("#0.00") + " " + PaymentCurrency_WaitPay;
  9530. /*
  9531. * 此次付款金额
  9532. */
  9533. decimal CurrPayStr = 0.00M,
  9534. OriginalCurrPay = 0.00M;
  9535. if (entity.PayPercentage == 0)
  9536. {
  9537. if (entity.PayThenMoney != 0)
  9538. CurrPayStr = (entity.PayThenMoney * entity.DayRate).ConvertToDecimal1();
  9539. }
  9540. else
  9541. {
  9542. if (entity.PayMoney != 0)
  9543. {
  9544. CurrPayStr = (entity.PayMoney * entity.PayPercentage / 100 * entity.DayRate).ConvertToDecimal1();
  9545. }
  9546. }
  9547. //if (_dto.Label == 79)
  9548. //{
  9549. // string original = string.Empty;
  9550. // if (hotelCurrncyCode.Equals("CNY"))
  9551. // {
  9552. // OriginalCurrPay = CurrPayStr;
  9553. // _detail.CurrPay = CurrPayStr.ToString("#0.00") + " CNY";
  9554. // }
  9555. // else
  9556. // {
  9557. // OriginalCurrPay = ((entity.PayMoney / 100) * entity.PayPercentage).ConvertToDecimal1();
  9558. // //760 EUR(7600.00 CNY)
  9559. // _detail.CurrPay = $"{OriginalCurrPay.ToString("#0.00")} {hotelCurrncyCode}({CurrPayStr.ToString("#0.00")} CNY)";
  9560. // }
  9561. //}
  9562. //else _detail.CurrPay = CurrPayStr.ToString("#0.00") + " CNY";
  9563. string original = string.Empty;
  9564. if (hotelCurrncyCode.Equals("CNY"))
  9565. {
  9566. OriginalCurrPay = CurrPayStr;
  9567. _detail.CurrPay = CurrPayStr.ToString("#0.00") + " CNY";
  9568. }
  9569. else
  9570. {
  9571. OriginalCurrPay = ((entity.PayMoney / 100) * entity.PayPercentage).ConvertToDecimal1();
  9572. //760 EUR(7600.00 CNY)
  9573. _detail.CurrPay = $"{OriginalCurrPay:#0.00} {hotelCurrncyCode}({CurrPayStr:#0.00} CNY)";
  9574. }
  9575. /*
  9576. * 剩余尾款
  9577. */
  9578. decimal BalanceStr = 0;
  9579. if (CurrPayStr != 0)
  9580. {
  9581. if (entity.PayMoney - (CurrPayStr / entity.DayRate) < 0.01M)
  9582. BalanceStr = 0;
  9583. else
  9584. BalanceStr = (entity.PayMoney - CurrPayStr / entity.DayRate).ConvertToDecimal1();
  9585. }
  9586. _detail.Balance = BalanceStr.ToString("#0.00") + " " + PaymentCurrency_WaitPay;
  9587. /*
  9588. * Bus名称
  9589. */
  9590. _detail.BusName = "待增加";
  9591. /*
  9592. *费用所属
  9593. */
  9594. switch (entity.CTable)
  9595. {
  9596. case 76://酒店预订
  9597. Grp_HotelReservations hotelReservations = _HotelReservations.Where(s => s.Id == entity.CId).FirstOrDefault();
  9598. if (hotelReservations != null)
  9599. {
  9600. DateTime checkIn = Convert.ToDateTime(hotelReservations.CheckInDate),
  9601. checkOut = Convert.ToDateTime(hotelReservations.CheckOutDate);
  9602. int hotel_days = (int)(checkOut - checkIn).TotalDays;
  9603. string roomFeeStr = "", roomFeestr1 = "";
  9604. //是否比较房型价格
  9605. //bool __isSingle = false, __isDouble = false, __isSuite = false, __isOther = false;
  9606. //roomFeeStr += $"<br/><span style='width:70px;display: inline-block;'></span>";
  9607. roomFeeStr += $"<br/>";
  9608. var roomTotal = 0.00M;
  9609. if (hotelReservations.SingleRoomPrice > 0)
  9610. {
  9611. var fee = hotelReservations.SingleRoomPrice * hotelReservations.SingleRoomCount * hotel_days;
  9612. roomFeestr1 += $"<span style='width:70px;display: inline-block;'></span>单间:{hotelReservations.SingleRoomPrice:#0.00} * {hotelReservations.SingleRoomCount}间 * {hotel_days}晚 = {fee:#0.00}<br/>";
  9613. //__isSingle = true;
  9614. roomTotal += fee;
  9615. }
  9616. if (hotelReservations.DoubleRoomPrice > 0)
  9617. {
  9618. var fee = hotelReservations.DoubleRoomPrice * hotelReservations.DoubleRoomCount * hotel_days;
  9619. roomFeestr1 += $"<span style='width:70px;display: inline-block;'></span>双人间:{hotelReservations.DoubleRoomPrice:#0.00} * {hotelReservations.DoubleRoomCount}间 * {hotel_days}晚 = {fee:#0.00}<br/>";
  9620. // __isDouble = true;
  9621. roomTotal += fee;
  9622. }
  9623. if (hotelReservations.SuiteRoomPrice > 0)
  9624. {
  9625. var fee = hotelReservations.SuiteRoomPrice * hotelReservations.SuiteRoomCount * hotel_days;
  9626. roomFeestr1 += $"<span style='width:70px;display: inline-block;'></span>套房:{hotelReservations.SuiteRoomPrice:#0.00} * {hotelReservations.SuiteRoomCount}间 * {hotel_days}晚 = {fee:#0.00}<br/>";
  9627. //__isSuite = true;
  9628. roomTotal += fee;
  9629. }
  9630. if (hotelReservations.OtherRoomPrice > 0)
  9631. {
  9632. var fee = hotelReservations.OtherRoomPrice * hotelReservations.OtherRoomCount * hotel_days;
  9633. roomFeestr1 += $"<span style='width:70px;display: inline-block;'></span>其他:{hotelReservations.OtherRoomPrice:#0.00} * {hotelReservations.OtherRoomCount}间 * {hotel_days}晚 = {fee:#0.00}<br/>";
  9634. //__isOther = true;
  9635. roomTotal += fee;
  9636. }
  9637. if (roomFeestr1.Length > 0) roomFeeStr += roomFeestr1 + $"<span style='width:70px;display: inline-block;'></span>房费总金额:{roomTotal:#0.00}";
  9638. else roomFeeStr += " 0.00 * 0";
  9639. decimal governmentRentFee = 0.00M, cityTaxFee = 0.00M, breakfastFee = 0.00M, roomFee = 0.00M;
  9640. string governmentRentBool = "否", cityTaxBool = "否", breakfastBool = "否", roomBool = "否";
  9641. string governmentRentCode = "", governmentRentName = "", cityTaxCode = "", cityTaxName = "", breakfastCode = "", breakfastName = "", roomCode = "", roomName = "";
  9642. var _HotelReservationsContents1 = _HotelReservationsContents.Where(it => it.HrId == hotelReservations.Id).ToList();
  9643. /*
  9644. * 费用类型
  9645. * 1:房费
  9646. * 2:早餐
  9647. * 3:地税
  9648. * 4:城市税
  9649. * </summary>
  9650. */
  9651. //地税
  9652. var governmentRentData = _HotelReservationsContents1.Find(it => it.PriceType == 3);
  9653. if (governmentRentData != null)
  9654. {
  9655. governmentRentBool = governmentRentData.IsOppay == 1 ? "是" : "否";
  9656. governmentRentFee = governmentRentData.Price;
  9657. var governmentRentCurrData = currencyItems.Find(s => s.Id == governmentRentData.Currency);
  9658. if (governmentRentCurrData != null)
  9659. {
  9660. governmentRentCode = governmentRentCurrData.Name;
  9661. governmentRentName = $"({governmentRentCurrData.Remark})";
  9662. }
  9663. }
  9664. //城市税
  9665. var cityTaxData = _HotelReservationsContents1.Find(it => it.PriceType == 4);
  9666. if (cityTaxData != null)
  9667. {
  9668. cityTaxBool = cityTaxData.IsOppay == 1 ? "是" : "否";
  9669. cityTaxFee = cityTaxData.Price;
  9670. var cityTaxCurrData = currencyItems.Find(s => s.Id == cityTaxData.Currency);
  9671. if (cityTaxCurrData != null)
  9672. {
  9673. cityTaxCode = cityTaxCurrData.Name;
  9674. cityTaxName = $"({cityTaxCurrData.Remark})";
  9675. }
  9676. }
  9677. //酒店早餐
  9678. var breakfastData = _HotelReservationsContents1.Find(it => it.PriceType == 2);
  9679. if (breakfastData != null)
  9680. {
  9681. breakfastBool = breakfastData.IsOppay == 1 ? "是" : "否";
  9682. breakfastFee = breakfastData.Price;
  9683. var breakfastCurrData = currencyItems.Find(s => s.Id == breakfastData.Currency);
  9684. if (breakfastCurrData != null)
  9685. {
  9686. breakfastCode = breakfastCurrData.Name;
  9687. breakfastName = $"({breakfastCurrData.Remark})";
  9688. }
  9689. }
  9690. //房间费用
  9691. var roomData = _HotelReservationsContents1.Find(it => it.PriceType == 1);
  9692. if (roomData != null)
  9693. {
  9694. _detail.PayType = initDatas.Find(it => it.Id == roomData.PayDId)?.Name ?? "-";
  9695. if (_detail.PayType.Equals("现金")) _detail.CardType = "-";
  9696. else _detail.CardType = initDatas.Find(it => it.Id == roomData.CTDId)?.Name ?? "-";
  9697. roomBool = roomData.IsOppay == 1 ? "是" : "否";
  9698. roomFee = roomData.Price;
  9699. var roomCurrData = currencyItems.Find(s => s.Id == roomData.Currency);
  9700. if (roomCurrData != null)
  9701. {
  9702. roomCode = roomCurrData.Name;
  9703. roomName = $"({roomCurrData.Remark})";
  9704. }
  9705. }
  9706. string hotelCostTitalStr = "<span style='font-weight:800;'>成本信息</span><br/>";
  9707. string hotelCostStr = "";
  9708. decimal hotelCsotTotal = 0.00M;
  9709. if (groupCost != null)
  9710. {
  9711. if (int.TryParse(groupCost.Currency, out int currencyId)) groupCost.Currency = currencyItems.Find(s => s.Id == currencyId)?.Name ?? "-";
  9712. hotelCostStr += $"{groupCost.Currency}(汇率:{groupCost.Rate:#0.0000})<br/>";
  9713. }
  9714. if (checkOut > checkIn) checkOut = checkOut.AddDays(-1);
  9715. var hotelCostDetails = groupCostDetails.Where(x => Convert.ToDateTime(x.Date) >= checkIn && Convert.ToDateTime(x.Date) <= checkOut).ToList();
  9716. string hotelCost_day = "";
  9717. var hotelCostDetails1 = hotelCostDetails.GroupBy(x => x.Date);
  9718. foreach (var item in hotelCostDetails1)
  9719. {
  9720. hotelCsotTotal += item.Sum(x => x.HotelSingleRoomFee) + item.Sum(x => x.HotelDoubleRoomFee) + item.Sum(x => x.HotelSuiteRoomFee) + item.Sum(x => x.HotelSuiteFee);
  9721. hotelCost_day += @$"{item.First()?.Date ?? "-"}";
  9722. if (item.Sum(x => x.HotelSingleRoomFee) != 0) hotelCost_day += @$" 单间:{item.Sum(x => x.HotelSingleRoomFee):#0.00}";
  9723. //else { if (__isSingle) hotelCost_day += @$" 单间:0.00"; }
  9724. if (item.Sum(x => x.HotelDoubleRoomFee) != 0) hotelCost_day += @$" 双人间:{item.Sum(x => x.HotelDoubleRoomFee):#0.00}";
  9725. //else { if (__isDouble) hotelCost_day += @$" 双人间:0.00"; }
  9726. if (item.Sum(x => x.HotelSuiteRoomFee) != 0) hotelCost_day += @$" 小套房/豪华套房:{item.Sum(x => x.HotelSuiteRoomFee):#0.00}";
  9727. //else { if (__isSuite) hotelCost_day += @$" 小套房/豪华套房:0.00"; }
  9728. if (item.Sum(x => x.HotelSuiteFee) != 0) hotelCost_day += @$" 套房:{item.Sum(x => x.HotelSuiteFee):#0.00}";
  9729. //else { if (__isOther) hotelCost_day += @$" 套房:0.00"; }
  9730. hotelCost_day += @$"<br/>";
  9731. }
  9732. string hotelBreakfastStr = "", hotelGovernmentRentStr = "", hotelCityTaxStr = "";
  9733. if (breakfastFee > 0) hotelBreakfastStr = $"酒店早餐: {breakfastFee:#0.00} {breakfastCode} {breakfastName} 当时汇率 {breakfastData?.Rate:#0.0000} <br/>是否由地接或其他人代付:{breakfastBool}<br/><br/>";
  9734. if (governmentRentFee > 0) hotelGovernmentRentStr = $"地税: {governmentRentFee:#0.00} {governmentRentCode} {governmentRentName} 当时汇率 {governmentRentData?.Rate:#0.0000} <br/>是否由地接或其他人代付:{governmentRentBool}<br/><br/>";
  9735. if (cityTaxFee > 0) hotelCityTaxStr = $"城市税: {cityTaxFee:#0.00} {cityTaxCode} {cityTaxName} 当时汇率 {cityTaxData?.Rate:#0.0000)} <br/>是否由地接或其他人代付:{cityTaxBool}<br/>";
  9736. string hotelCostTotalStr = "";// $"&nbsp;&nbsp;成本合计:{hotelCsotTotal.ToString("#0.00")}<br/>";
  9737. _detail.PriceMsgContent = $"{hotelCostTitalStr}{hotelCostStr}{hotelCostTotalStr}{hotelCost_day}<br/>" +
  9738. $"<span style='font-weight:800;'>{hotelReservations.HotelName} [{hotelReservations.CheckInDate} - {hotelReservations.CheckOutDate}]</span><br/>" +
  9739. $"酒店费用总额:{_detail.WaitPay} ({hotelCurrncyName})<br/>" +
  9740. $"房间说明: {hotelReservations.Remark} <br/>" +
  9741. $"房间费用: {roomCode} {roomName} 当时汇率:{roomData?.Rate.ToString("#0.0000")}{roomFeeStr} <br/>是否由地接或其他人代付:{roomBool}<br/><br/>" +
  9742. $"{hotelBreakfastStr}" +
  9743. $"{hotelGovernmentRentStr}" +
  9744. $"{hotelCityTaxStr}";
  9745. _detail.PriceNameContent = hotelReservations.HotelName;
  9746. }
  9747. break;
  9748. case 79://车/导游地接
  9749. Grp_CarTouristGuideGroundReservations touristGuideGroundReservations = _CarTouristGuideGroundReservations.Where(s => s.Id == entity.CId).FirstOrDefault();
  9750. if (touristGuideGroundReservations != null)
  9751. {
  9752. if (!string.IsNullOrEmpty(touristGuideGroundReservations.BusName))
  9753. {
  9754. _detail.BusName = touristGuideGroundReservations.BusName;
  9755. }
  9756. _detail.PriceNameContent = touristGuideGroundReservations.PriceName;
  9757. //bool isInt = int.TryParse(touristGuideGroundReservations.Area, out int cityId);
  9758. //if (isInt)
  9759. //{
  9760. // var cityInfo = cityData.Find(it => it.Id == cityId);
  9761. // if (cityInfo != null)
  9762. // {
  9763. // string nameContent = $@"{cityInfo.Country}-{cityInfo.City}";
  9764. // var carFeeItem = carFeeItems.Find(it => it.Id == touristGuideGroundReservations.PriceType);
  9765. // if (carFeeItem != null)
  9766. // {
  9767. // nameContent += $@"({carFeeItem.Name})";
  9768. // }
  9769. // _detail.PriceNameContent = nameContent;
  9770. // }
  9771. //}
  9772. //else
  9773. //{
  9774. // _detail.PriceNameContent = touristGuideGroundReservations.Area;
  9775. //}
  9776. var touristGuideGroundReservationsContents =
  9777. _CarTouristGuideGroundReservationsContent.Where(s => s.CTGGRId == touristGuideGroundReservations.Id && s.IsDel == 0 && s.Price != 0).ToList();
  9778. var opContent_sb = new StringBuilder();
  9779. string contetTitle = $"<span style='font-weight:800;'>{touristGuideGroundReservations.PriceName}({touristGuideGroundReservations.ServiceStartTime} - {touristGuideGroundReservations.ServiceEndTime})</span><br/>";
  9780. opContent_sb.AppendLine(contetTitle);
  9781. foreach (var item in touristGuideGroundReservationsContents)
  9782. {
  9783. string typeName = "Unknown";
  9784. string carCurrencyCode = "Unknown";
  9785. string carCurrencyName = "Unknown";
  9786. var carTypeData = carFeeTypeItems.Where(s => s.Id == item.SId && s.IsDel == 0).FirstOrDefault();
  9787. if (carTypeData != null) typeName = carTypeData.Name;
  9788. var currencyData = currencyItems.Where(s => s.Id == item.Currency && s.IsDel == 0).FirstOrDefault();
  9789. if (currencyData != null)
  9790. {
  9791. carCurrencyCode = currencyData.Name;
  9792. carCurrencyName = currencyData.Remark;
  9793. }
  9794. //op、成本 币种是否一致 (币种一致只比较金额:2025-04-18)
  9795. bool IsCurrencyAgreement = false;
  9796. if (carCurrencyCode.Equals(_groupCurrencyCode)) IsCurrencyAgreement = true;
  9797. string opCostStr = string.Empty;
  9798. decimal opCostTypePrice = 0.00M;
  9799. #region 处理成本各项费用
  9800. var opDate = item.DatePrice?.ToString("yyyy-MM-dd");
  9801. var opCost = groupCostDetails.Where(x => x.Date.Equals(opDate)).ToList();
  9802. decimal aduitOPFeeCNY = 0.00M, //费用审核 op费用
  9803. costOPFeeCNY = 0.00M, //团组成本 op费用
  9804. opPayPercentage = entity.PayPercentage == 0.00M ? 1.00M : entity.PayPercentage / 100M; //费用审核 op付款百分比
  9805. if (opCost.Count > 0)
  9806. {
  9807. switch (item.SId)
  9808. {
  9809. case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //91车费
  9810. //case 982: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //982 车超时费 -- 暂无
  9811. case 92: opCostTypePrice = opCost.Sum(x => x.GuideFee); break; //92 导游费
  9812. case 94: opCostTypePrice = opCost.Sum(x => x.GuideScenicFee); break; //94 导游景点费
  9813. case 95: opCostTypePrice = opCost.Sum(x => x.GuideTipFee); break; //95 导游小费
  9814. case 983: opCostTypePrice = opCost.Sum(x => x.GuideMealFee); break; //983 导游餐补
  9815. case 984: opCostTypePrice = opCost.Sum(x => x.GuideMealFee); break; //984 导游房补
  9816. case 985: opCostTypePrice = opCost.Sum(x => x.GuideRoomFee); break; //985 导游交通
  9817. //case 96: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //96 接送机费 -- 暂无
  9818. //case 97: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //97 其他费用 -- 暂无
  9819. case 979: opCostTypePrice = opCost.Sum(x => x.DriverFee); break; //979 司机工资
  9820. case 980: opCostTypePrice = opCost.Sum(x => x.DriverTipFee); break; //980 司机小费
  9821. case 981: opCostTypePrice = opCost.Sum(x => x.DriverMealFee); break; //981 司机餐补
  9822. case 988: opCostTypePrice = opCost.Sum(x => x.ClientBreakfastFee); break; //988 客户早餐费用
  9823. case 93: opCostTypePrice = opCost.Sum(x => x.ClientDinnerFee); break; //93 客户午餐费用
  9824. case 989: opCostTypePrice = opCost.Sum(x => x.ClientLunchFee); break; //989 客户晚餐费用
  9825. case 990: opCostTypePrice = opCost.Sum(x => x.ScenicTicketFee); break; //990 景点门票费
  9826. case 991: opCostTypePrice = opCost.Sum(x => x.DrinkSnackFruitFee); break; //991 饮料/零食/水果
  9827. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //992 住补费用 -- 暂无
  9828. case 994: opCostTypePrice = opCost.Sum(x => x.TranslatorFee); break; //994 翻译费
  9829. case 1059: opCostTypePrice = opCost.Sum(x => x.GuideOverTimeFee); break; //1059 导游超时费用
  9830. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1070 尾款金额
  9831. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1071 其他额外费用
  9832. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1073 翻译超时费
  9833. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1074 早餐超支费用
  9834. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1075 午餐超支费用
  9835. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1076 晚餐超支费用
  9836. }
  9837. opCostStr = $"&nbsp;&nbsp;/&nbsp;&nbsp;成本:{opCostTypePrice:#0.00} {_groupCurrencyCode}(汇率:{_groupRate:#0.0000})";
  9838. costOPFeeCNY = opCostTypePrice * _groupRate;
  9839. if (!IsCurrencyAgreement) opCostStr += $" ≈ {costOPFeeCNY:#0.00} CNY";
  9840. }
  9841. #endregion
  9842. string opTypeStr = $"{typeName}:{item.Price:#0.00} {carCurrencyCode}(汇率:{entity.DayRate:#0.0000})";
  9843. aduitOPFeeCNY = item.Price * entity.DayRate;
  9844. if (!IsCurrencyAgreement) opTypeStr += $" ≈ {aduitOPFeeCNY:#0.0000} CNY";
  9845. var opContent = $"日期:{item.DatePrice?.ToString("yyyy-MM-dd") ?? "-"}<br/>" +
  9846. $"{opTypeStr} {opCostStr}<br/>" +
  9847. $"明细:{item.PriceContent ?? "-"}<br/>" +
  9848. $"备注:{item.Remark ?? "-"}<br/><br/>";
  9849. if (entity.IsAuditGM != 3) //状态 != 自动审核
  9850. {
  9851. if (IsCurrencyAgreement)
  9852. {
  9853. if (item.Price > opCostTypePrice)
  9854. {
  9855. opContent_sb.Append("<span style='color:red;'>");
  9856. opContent_sb.Append(opContent);
  9857. opContent_sb.Append("</span>");
  9858. opContent_sb.AppendLine();
  9859. }
  9860. else
  9861. {
  9862. opContent_sb.Append(opContent);
  9863. opContent_sb.AppendLine();
  9864. }
  9865. }
  9866. else
  9867. {
  9868. //验证是否超成本 按付款比例计算
  9869. if (aduitOPFeeCNY * opPayPercentage > costOPFeeCNY * opPayPercentage)
  9870. {
  9871. opContent_sb.Append("<span style='color:red;'>");
  9872. opContent_sb.Append(opContent);
  9873. opContent_sb.Append("</span>");
  9874. opContent_sb.AppendLine();
  9875. }
  9876. else
  9877. {
  9878. opContent_sb.Append(opContent);
  9879. opContent_sb.AppendLine();
  9880. }
  9881. }
  9882. }
  9883. else
  9884. {
  9885. opContent_sb.Append(opContent);
  9886. opContent_sb.AppendLine();
  9887. }
  9888. }
  9889. _detail.PriceMsgContent = opContent_sb.ToString();
  9890. }
  9891. break;
  9892. case 80: //签证
  9893. Grp_VisaInfo visaInfo = _VisaInfos.Where(s => s.Id == entity.CId).FirstOrDefault();
  9894. if (visaInfo != null)
  9895. {
  9896. string visaName = GetClientNameStr1(clientNameList, visaInfo.VisaClient);
  9897. _detail.PriceNameContent = visaInfo.VisaDescription;
  9898. _detail.PriceMsgContent = $"签证描述:{visaName}<br/> 备注:{visaInfo.Remark}";
  9899. }
  9900. break;
  9901. case 81: //邀请/公务活动
  9902. Grp_InvitationOfficialActivities _ioa = _InvitationOfficialActivities.Where(s => s.Id == entity.CId).FirstOrDefault();
  9903. if (_ioa != null)
  9904. {
  9905. string inviteCurrName = "Unknown", //邀请费用币种 Name
  9906. inviteCurrCode = "Unknown", //邀请费用币种 Code
  9907. sendCurrName = "Unknown", //快递费用币种 Name
  9908. sendCurrCode = "Unknown", //快递费用币种 Code
  9909. eventsCurrName = "Unknown", //公务活动费币种 Name
  9910. eventsCurrCode = "Unknown", //公务活动费币种 Code
  9911. translateCurrName = "Unknown", //公务翻译费 Name
  9912. translateCurrCode = "Unknown"; //公务翻译费 Code
  9913. #region 处理费用币种
  9914. var inviteCurrData = currencyItems.Where(s => s.Id == _ioa.InviteCurrency && s.IsDel == 0).FirstOrDefault();
  9915. if (inviteCurrData != null)
  9916. {
  9917. inviteCurrName = inviteCurrData.Remark;
  9918. inviteCurrCode = inviteCurrData.Name;
  9919. }
  9920. var sendCurrData = currencyItems.Where(s => s.Id == _ioa.SendCurrency && s.IsDel == 0).FirstOrDefault();
  9921. if (sendCurrData != null)
  9922. {
  9923. sendCurrName = sendCurrData.Remark;
  9924. sendCurrCode = sendCurrData.Name;
  9925. }
  9926. var eventsCurrData = currencyItems.Where(s => s.Id == _ioa.EventsCurrency && s.IsDel == 0).FirstOrDefault();
  9927. if (eventsCurrData != null)
  9928. {
  9929. eventsCurrName = eventsCurrData.Remark;
  9930. eventsCurrCode = eventsCurrData.Name;
  9931. }
  9932. var translateCurrData = currencyItems.Where(s => s.Id == _ioa.TranslateCurrency && s.IsDel == 0).FirstOrDefault();
  9933. if (translateCurrData != null)
  9934. {
  9935. translateCurrName = translateCurrData.Remark;
  9936. translateCurrCode = translateCurrData.Name;
  9937. }
  9938. #endregion
  9939. _detail.PriceNameContent = _ioa.InviterArea;
  9940. //2025-09-08 商邀费用名称更改:单项费用不等于0,则在名称后面最加费用类型名称。
  9941. List<string> priceExpNames = new List<string>();
  9942. if (_ioa.InviteCost != 0.00M) priceExpNames.Add("邀请费");
  9943. if (_ioa.SendCost != 0.00M) priceExpNames.Add("快递费");
  9944. if (_ioa.EventsCost != 0.00M) priceExpNames.Add("公务活动费");
  9945. if (_ioa.TranslateCost != 0.00M) priceExpNames.Add("公务翻译费");
  9946. if (priceExpNames != null && priceExpNames.Count > 0)
  9947. {
  9948. _detail.PriceNameContent += $"({string.Join("+", priceExpNames)})";
  9949. }
  9950. _detail.PriceMsgContent = $@"邀请费用:{_ioa.InviteCost:#0.00} {inviteCurrCode}({inviteCurrName})<br/>" +
  9951. $@"快递费用:{_ioa.SendCost:#0.00} {sendCurrCode}({sendCurrName})<br/>" +
  9952. $@"公务活动费:{_ioa.EventsCost:#0.00} {eventsCurrCode}({eventsCurrName})<br/>" +
  9953. $@"公务翻译费:{_ioa.TranslateCost:#0.00} {translateCurrCode}({translateCurrName})<br/>" +
  9954. $@"备注:" + _ioa.Remark + "<br/>";
  9955. }
  9956. break;
  9957. case 82: //团组客户保险
  9958. Grp_Customers customers = _Customers.Where(s => s.Id == entity.CId && s.IsDel == 0).FirstOrDefault();
  9959. if (customers != null)
  9960. {
  9961. _detail.PriceNameContent = GetClientNameStr(clientNameList, customers.ClientName);
  9962. _detail.PriceMsgContent = "备注:" + customers.Remark + "<br/>";
  9963. }
  9964. break;
  9965. case 85: //机票预订
  9966. Grp_AirTicketReservations jpRes = _AirTicketReservations.Where(s => s.Id == entity.CId).FirstOrDefault();
  9967. if (jpRes != null)
  9968. {
  9969. string FlightsDescription = jpRes.FlightsDescription;
  9970. string PriceDescription = jpRes.PriceDescription;
  9971. _detail.PriceMsgContent = "航班号:" + jpRes.FlightsCode + "<br/>城市A-B:" + jpRes.FlightsCity + "<br/>航班描述:" + FlightsDescription.Replace("\r\n", "<br />") + "<br/>" + "价格描述:" + PriceDescription;
  9972. _detail.PriceNameContent = "(" + jpRes.FlightsCode + ")";
  9973. }
  9974. break;
  9975. case 98://其他款项
  9976. Grp_DecreasePayments gdpRes = _DecreasePayments.Where(s => s.Id == entity.CId).FirstOrDefault();
  9977. if (gdpRes != null)
  9978. {
  9979. //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/";
  9980. //if (!string.IsNullOrEmpty(gdpRes.FilePath))
  9981. //{
  9982. // _detail.FileUrl = $"{urlBase}{gdpRes.FilePath}";
  9983. //}
  9984. _detail.PriceMsgContent = "备注:" + gdpRes.Remark;
  9985. _detail.PriceNameContent = gdpRes.PriceName;
  9986. }
  9987. break;
  9988. case 285://收款退还
  9989. Fin_PaymentRefundAndOtherMoney refundAndOtherMoney = _PaymentRefundAndOtherMoneys.Where(s => s.Id == entity.CId).FirstOrDefault();
  9990. if (refundAndOtherMoney != null)
  9991. {
  9992. _detail.PriceMsgContent = "备注:" + refundAndOtherMoney.Remark;
  9993. _detail.PriceNameContent = refundAndOtherMoney.PriceName;
  9994. }
  9995. break;
  9996. case 751://酒店早餐
  9997. break;
  9998. case 1015://超支费用
  9999. Fin_GroupExtraCost groupExtraCost = _GroupExtraCosts.Where(s => s.Id == entity.CId).FirstOrDefault();
  10000. if (groupExtraCost != null)
  10001. {
  10002. _detail.PriceNameContent = groupExtraCost.PriceName;
  10003. _detail.PriceMsgContent = "备注:" + groupExtraCost.Remark;
  10004. }
  10005. break;
  10006. default:
  10007. break;
  10008. }
  10009. /*
  10010. * 申请人
  10011. */
  10012. string operatorName = " - ";
  10013. var _opUser = userItems.Where(s => s.Id == entity.CreateUserId).FirstOrDefault();
  10014. if (_opUser != null)
  10015. {
  10016. operatorName = _opUser.CnName;
  10017. }
  10018. _detail.OperatorName = operatorName;
  10019. /*
  10020. * 审核人
  10021. */
  10022. string auditOperatorName = " - ";
  10023. if (entity.IsAuditGM != 0)
  10024. {
  10025. if (entity.AuditGMOperate == 0) auditOperatorName = " - ";
  10026. else if (entity.AuditGMOperate == 4) auditOperatorName = "自动审核";
  10027. else
  10028. {
  10029. var _adUser = userItems.Where(s => s.Id == entity.AuditGMOperate).FirstOrDefault();
  10030. if (_adUser != null)
  10031. {
  10032. auditOperatorName = _adUser.CnName;
  10033. }
  10034. }
  10035. }
  10036. _detail.AuditOperatorName = auditOperatorName;
  10037. /*
  10038. * 超预算比例
  10039. */
  10040. string overBudgetStr = "";
  10041. if (entity.ExceedBudget == -1) overBudgetStr = sdPriceName.Name + "尚无预算";
  10042. else if (entity.ExceedBudget == 0)
  10043. {
  10044. if (entity.CTable == 76 || entity.CTable == 79)
  10045. {
  10046. if (entity.IsAuditGM == 3) overBudgetStr = "未超预算";
  10047. else overBudgetStr = _feeAuditRep.IsOverBudget(entity.CTable, entity.DIId, entity.CId);
  10048. }
  10049. else
  10050. {
  10051. overBudgetStr = "未超预算";
  10052. }
  10053. }
  10054. else overBudgetStr = entity.ExceedBudget.ToString("P");
  10055. _detail.OverBudget = overBudgetStr;
  10056. decimal auditFee = 0.00M; //已审核金额 人名币
  10057. decimal auditedFeeOriginal = 0.00M; ////已审核金额 原始
  10058. decimal unAuditFeeCNY = 0.00M; //未审核款项 原始
  10059. decimal unAuditFeeOriginal = 0.00M; //未审核款项 人名币
  10060. if (entity.IsAuditGM == 1 || entity.IsAuditGM == 3)
  10061. {
  10062. auditedFeeOriginal = entity.PayMoney;
  10063. auditFee = CurrPayStr;
  10064. }
  10065. else if (entity.IsAuditGM == 0)
  10066. {
  10067. unAuditFeeCNY = CurrPayStr;
  10068. unAuditFeeOriginal = OriginalCurrPay;
  10069. OriginalCurrPay = 0.00M;
  10070. }
  10071. /*
  10072. * 费用总计
  10073. */
  10074. ccpCurrencyPrices.Add(new CreditCardPaymentCurrencyPriceItem()
  10075. {
  10076. CurrencyId = entity.PaymentCurrency,
  10077. CurrencyName = PaymentCurrency_WaitPay,
  10078. AmountPayable = entity.PayMoney,
  10079. ThisPayment = OriginalCurrPay,
  10080. BalancePayment = BalanceStr,
  10081. AuditedFunds = auditFee,
  10082. AuditedFundsOriginal = auditedFeeOriginal,
  10083. UnAuditFundsCNY = unAuditFeeCNY,
  10084. UnAuditFundsOriginal = unAuditFeeOriginal
  10085. });
  10086. _detail.IsAuditGM = entity.IsAuditGM;
  10087. detailList.Add(_detail);
  10088. }
  10089. #endregion
  10090. _view.DetailList = new List<Grp_CreditCardPaymentDetailView>(detailList);
  10091. /*
  10092. * 下方描述处理
  10093. */
  10094. var nonDuplicat = ccpCurrencyPrices.Where((x, i) => ccpCurrencyPrices.FindIndex(z => z.CurrencyId == x.CurrencyId) == i).ToList();//Lambda表达式去重
  10095. var ccpCurrencyPrice = nonDuplicat.Where(it => it.CurrencyId == 836).FirstOrDefault();
  10096. if (ccpCurrencyPrice != null)
  10097. {
  10098. int CNYIndex = nonDuplicat.IndexOf(ccpCurrencyPrice);
  10099. nonDuplicat.MoveItemAtIndexToFront(CNYIndex);
  10100. }
  10101. else
  10102. {
  10103. nonDuplicat = nonDuplicat.OrderBy(it => it.CurrencyId).ToList();
  10104. }
  10105. string amountPayableStr = string.Format(@"应付款总金额: ");
  10106. string thisPaymentStr = string.Format(@"此次付款总金额: ");
  10107. string balancePaymentStr = string.Format(@"目前剩余尾款总金额: ");
  10108. string auditedFundsStr = string.Format(@"已审费用总额: ");
  10109. string unAuditedFundsStr = string.Format(@"未审费用总额: ");
  10110. foreach (var item in nonDuplicat)
  10111. {
  10112. var currencyName = item.CurrencyName;
  10113. var strs = ccpCurrencyPrices.Where(it => it.CurrencyId == item.CurrencyId).ToList();
  10114. if (strs.Count > 0)
  10115. {
  10116. decimal amountPayable = strs.Sum(it => it.AmountPayable);
  10117. decimal thisPayment = ccpCurrencyPrices.Sum(it => it.ThisPayment);
  10118. decimal balancePayment = strs.Sum(it => it.BalancePayment);
  10119. amountPayableStr += string.Format(@"{0}{1}&nbsp;|", amountPayable.ToString("#0.00"), currencyName);
  10120. //单独处理此次付款金额
  10121. thisPaymentStr += string.Format(@"{0}{1}&nbsp;|", strs.Sum(x => x.ThisPayment).ToString("#0.00"), currencyName);
  10122. balancePaymentStr += string.Format(@"{0}{1}&nbsp;|", balancePayment.ToString("#0.00"), currencyName);
  10123. //单独处理已审核费用
  10124. //if (item.CurrencyId == 836) //人民币
  10125. //{
  10126. // decimal auditedFunds = ccpCurrencyPrices.Sum(it => it.AuditedFunds);
  10127. // auditedFundsStr += string.Format(@"{0}{1}&nbsp;|", auditedFunds.ToString("#0.00"), currencyName);
  10128. //}
  10129. //else
  10130. //{
  10131. // auditedFundsStr += string.Format(@"{0}{1}&nbsp;|", strs.Sum(x => x.AmountPayable), currencyName);
  10132. //}
  10133. if (currencyName.Equals("CNY"))
  10134. {
  10135. //已审核费用
  10136. auditedFundsStr += string.Format(@"{0}{1}&nbsp;|", strs.Sum(x => x.ThisPayment).ToString("#0.00"), currencyName);
  10137. //未审核费用
  10138. unAuditedFundsStr += string.Format(@"{0}{1}&nbsp;|", strs.Sum(x => x.UnAuditFundsOriginal).ToString("#0.00"), currencyName);
  10139. }
  10140. else
  10141. {
  10142. //已审核费用
  10143. 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"));
  10144. //未审核费用
  10145. 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"));
  10146. }
  10147. }
  10148. }
  10149. _view.TotalStr1 = amountPayableStr[..^1];
  10150. _view.TotalStr2 = thisPaymentStr[..^1];
  10151. _view.TotalStr3 = balancePaymentStr[..^1];
  10152. _view.TotalStr4 = $"{auditedFundsStr[..^1]}<br/>{unAuditedFundsStr[..^1]}";
  10153. //_view.TotalStr5 = unAuditedFundsStr.Substring(0, unAuditedFundsStr.Length - 1);
  10154. var _view1 = new
  10155. {
  10156. PageFuncAuth = pageFunAuthView,
  10157. Data = _view
  10158. };
  10159. return Ok(JsonView(_view1));
  10160. }
  10161. catch (Exception ex)
  10162. {
  10163. return Ok(JsonView(false, ex.Message));
  10164. }
  10165. }
  10166. /// <summary>
  10167. /// 费用审核
  10168. /// 修改团组费用审核状态
  10169. /// </summary>
  10170. /// <param name="_dto">参数Json字符串</param>
  10171. /// <returns></returns>
  10172. [HttpPost]
  10173. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10174. public async Task<IActionResult> PostAuditGrpCreditCardPayment(Edit_GrpCreditCardPaymentDto _dto)
  10175. {
  10176. #region 参数验证
  10177. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  10178. if (_dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  10179. #endregion
  10180. #region 页面操作权限验证
  10181. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  10182. if (pageFunAuthView.AuditAuth == 0) return Ok(JsonView(false, "您没有审核权限"));
  10183. #endregion
  10184. List<string> idList = _dto.CreditIdStr.Split(',').ToList();
  10185. Grp_CreditCardPayment _detail = _mapper.Map<Grp_CreditCardPayment>(_dto);
  10186. DateTime dtNow = DateTime.Now;
  10187. _groupRepository.BeginTran();
  10188. int rst = 0;
  10189. var creditDatas = _grpScheduleRep._sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.IsDel == 0 && idList.Contains(it.Id.ToString())).ToList();
  10190. var creditTypeDatas = _grpScheduleRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 16).ToList();
  10191. var creditCurrencyDatas = _grpScheduleRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  10192. var groupDatas = _grpScheduleRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).ToList();
  10193. var msgDatas = new List<dynamic>();
  10194. var dic_ccp_user = new Dictionary<int, int>() { };
  10195. foreach (var item in idList)
  10196. {
  10197. int CreditId = int.Parse(item);
  10198. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_CreditCardPayment>()
  10199. .SetColumns(it => it.IsAuditGM == _dto.AuditCode)
  10200. .SetColumns(it => it.AuditGMOperate == _dto.UserId)
  10201. .SetColumns(it => it.AuditGMDate == dtNow.ToString("yyyy-MM-dd HH:mm:ss"))
  10202. .Where(s => s.Id == CreditId)
  10203. .ExecuteCommandAsync();
  10204. if (result < 1)
  10205. {
  10206. rst = -1;
  10207. _groupRepository.RollbackTran();
  10208. return Ok(JsonView(false, "操作失败并回滚!"));
  10209. }
  10210. var creditData = creditDatas.Where(it => it.Id == CreditId).FirstOrDefault();
  10211. if (creditData != null)
  10212. {
  10213. #region 应用通知配置
  10214. try
  10215. {
  10216. dic_ccp_user.Add(creditData.Id, creditData.CreateUserId);
  10217. }
  10218. catch (Exception ex)
  10219. {
  10220. }
  10221. #endregion
  10222. string auditStr = _dto.AuditCode == 1 ? "已通过" : _dto.AuditCode == 2 ? "未通过" : "未审核";
  10223. string groupNameStr = string.Empty;
  10224. var groupData = groupDatas.Where(it => it.Id == creditData.DIId).FirstOrDefault();
  10225. if (groupData != null) groupNameStr = groupData.TeamName;
  10226. string creditTypeStr = string.Empty;
  10227. var creditTypeData = creditTypeDatas.Where(it => it.Id == creditData.CTable).FirstOrDefault();
  10228. if (creditTypeData != null) creditTypeStr = creditTypeData.Name;
  10229. string creditCurrency = string.Empty;
  10230. var creditCurrencyData = creditCurrencyDatas.Where(it => it.Id == creditData.PaymentCurrency).FirstOrDefault();
  10231. if (creditCurrencyData != null) creditCurrency = creditCurrencyData.Name;
  10232. if (creditCurrency.Equals("CNY"))
  10233. {
  10234. creditData.DayRate = 1.0000M;
  10235. }
  10236. if (creditData.PayPercentage == 0.00M)
  10237. {
  10238. creditData.PayPercentage = 100M;
  10239. }
  10240. decimal CNYPrice = (creditData.PayMoney * (creditData.PayPercentage / 100)) * creditData.DayRate;
  10241. string msgTitle = $"[{groupNameStr}({creditTypeStr})]的费用申请";
  10242. string msgContent = "";
  10243. if (creditCurrency.Equals("CNY"))
  10244. {
  10245. msgContent = $"[{groupNameStr}({creditTypeStr})]费用申请(金额:{CNYPrice:0.00} CNY) {auditStr}!";
  10246. }
  10247. else
  10248. {
  10249. msgContent = $"[{groupNameStr}({creditTypeStr})]费用申请(金额:{CNYPrice:0.00} CNY({creditData.PayMoney:0.00} {creditCurrency})) {auditStr}!";
  10250. }
  10251. msgDatas.Add(new { DiId = creditData.DIId, UserId = creditData.CreateUserId, MsgTitle = msgTitle, MsgContent = msgContent });
  10252. }
  10253. }
  10254. if (rst == 0)
  10255. {
  10256. _groupRepository.CommitTran();
  10257. foreach (var item in msgDatas)
  10258. {
  10259. //发送消息
  10260. GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupExpenseAudit, item.MsgTitle, item.MsgContent, new List<int>() { item.UserId }, item.DiId);
  10261. }
  10262. #region 应用推送
  10263. try
  10264. {
  10265. foreach (var ccpId in dic_ccp_user.Keys)
  10266. {
  10267. var templist = new List<string>() { dic_ccp_user[ccpId].ToString() };
  10268. await AppNoticeLibrary.SendUserMsg_GroupStatus_AuditFee(ccpId, templist, QiyeWeChatEnum.CaiWuChat);
  10269. }
  10270. }
  10271. catch (Exception)
  10272. {
  10273. }
  10274. #endregion
  10275. return Ok(JsonView(true, "操作成功!"));
  10276. }
  10277. return Ok(JsonView(false, "操作失败!"));
  10278. }
  10279. /// <summary>
  10280. /// 费用审核
  10281. /// 其他款项 文件下载
  10282. /// </summary>
  10283. /// <param name="id">其他款项 主键编号</param>
  10284. /// <returns></returns>
  10285. [HttpGet("{id}")]
  10286. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10287. public async Task<IActionResult> FeeAuditOtherFileDownlaod([Range(1, int.MaxValue, ErrorMessage = "请传入有效的ID")] int id)
  10288. {
  10289. //网站域名
  10290. 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/";
  10291. var otherInfo = await _decreasePaymentsRep._sqlSugar
  10292. .Queryable<Grp_DecreasePayments>()
  10293. .InnerJoin<Grp_CreditCardPayment>((x, y) => x.Id == y.CId && y.Id == id)
  10294. .Where(((x, y) => x.IsDel == 0 && y.IsDel == 0))
  10295. .Select((x, y) => new
  10296. {
  10297. x.Id,
  10298. x.FilePath
  10299. })
  10300. .FirstAsync();
  10301. if (otherInfo != null && !string.IsNullOrEmpty(otherInfo.FilePath.Trim()))
  10302. {
  10303. var url = $"{baseUrl}{otherInfo.FilePath}";
  10304. return Ok(JsonView(true, "操作成功!", url));
  10305. }
  10306. return Ok(JsonView(false, "暂无附件"));
  10307. }
  10308. #endregion
  10309. #region 机票费用录入
  10310. /// <summary>
  10311. /// 机票录入当前登录人可操作团组
  10312. /// </summary>
  10313. /// <param name="dto"></param>
  10314. /// <returns></returns>
  10315. [HttpPost]
  10316. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10317. public async Task<IActionResult> AirTicketResSelect(AirTicketResDto dto)
  10318. {
  10319. try
  10320. {
  10321. Result groupData = await _airTicketResRep.AirTicketResSelect(dto);
  10322. if (groupData.Code != 0)
  10323. {
  10324. return Ok(JsonView(false, groupData.Msg));
  10325. }
  10326. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  10327. }
  10328. catch (Exception ex)
  10329. {
  10330. return Ok(JsonView(false, ex.Message));
  10331. }
  10332. }
  10333. /// <summary>
  10334. /// 机票费用录入列表
  10335. /// </summary>
  10336. /// <param name="dto"></param>
  10337. /// <returns></returns>
  10338. [HttpPost]
  10339. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10340. public async Task<IActionResult> AirTicketResList(AirTicketResDto dto)
  10341. {
  10342. try
  10343. {
  10344. Result groupData = await _airTicketResRep.AirTicketResList(dto);
  10345. if (groupData.Code != 0)
  10346. {
  10347. return Ok(JsonView(false, groupData.Msg));
  10348. }
  10349. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  10350. }
  10351. catch (Exception ex)
  10352. {
  10353. return Ok(JsonView(false, ex.Message));
  10354. throw;
  10355. }
  10356. }
  10357. /// <summary>
  10358. /// 根据id查询费用录入信息
  10359. /// </summary>
  10360. /// <param name="dto"></param>
  10361. /// <returns></returns>
  10362. [HttpPost]
  10363. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10364. public async Task<IActionResult> AirTicketResById(AirTicketResByIdDto dto)
  10365. {
  10366. Result groupData = await _airTicketResRep.AirTicketResById(dto);
  10367. if (groupData.Code != 0)
  10368. {
  10369. return Ok(JsonView(false, groupData.Msg));
  10370. }
  10371. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  10372. }
  10373. /// <summary>
  10374. /// 机票费用录入操作(Status:1.新增,2.修改)
  10375. /// </summary>
  10376. /// <param name="dto"></param>
  10377. /// <returns></returns>
  10378. [HttpPost]
  10379. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10380. public async Task<IActionResult> OpAirTicketRes(AirTicketResOpDto dto)
  10381. {
  10382. //验证
  10383. if (dto.Status == 2)
  10384. {
  10385. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.AirTicketResOpData.Id, 85);
  10386. if (!valid) return Ok(JsonView(false, msg));
  10387. }
  10388. Result groupData = await _airTicketResRep.OpAirTicketRes(dto, _setDataRep.PostCurrencyByDiid);
  10389. if (groupData.Code != 0)
  10390. {
  10391. return Ok(JsonView(false, groupData.Msg));
  10392. }
  10393. #region 应用推送
  10394. try
  10395. {
  10396. var diId = dto.AirTicketResOpData.DiId;
  10397. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  10398. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  10399. int dataId = groupData.Data.GetType().GetProperty("dataId").GetValue(groupData.Data, null);
  10400. //自动审核
  10401. //var autoAdit1 = await _feeAuditRep.FeeAutomaticAudit(5, diId, dataId); //机票费用合计方式
  10402. (bool status, string auditMsg) = await AirTicketResAutoAudit(diId, dataId); //KIMI-AI识别INIT方式
  10403. _logger.LogInformation("【机票费用自动审核(KIMI-AI识别INIT)】请求参数:{RequstData} 返回结果:是否执行:{IsExecute}; 结果消息:{ResponseMsg};",
  10404. $"GroupId:{diId};airId:{dataId};",
  10405. status,
  10406. auditMsg);
  10407. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  10408. //2024-10-21 新增LZ UID
  10409. var userIds = new List<int>() { 21 };
  10410. string title = $"系统通知";
  10411. string content = "";
  10412. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  10413. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  10414. if (dto.Status == 1) content = $"[新增-机票费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  10415. else if (dto.Status == 2) content = $"[更新-机票费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  10416. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  10417. var h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "85" };
  10418. await APNsTools.iOS_PushNotifications1("051", $"机票费用审核", "", content, true, "ExpenseAuditWebView", h5);
  10419. }
  10420. catch (Exception ex)
  10421. {
  10422. }
  10423. #endregion
  10424. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  10425. }
  10426. /// <summary>
  10427. /// 机票费用自动审核 AI识别方式
  10428. /// </summary>
  10429. /// <returns></returns>
  10430. private async Task<(bool, string)> AirTicketResAutoAudit(int diId, int dataId)
  10431. {
  10432. var ecoTypeIds = new List<int>() {
  10433. 459, //超经舱
  10434. 460, //经济舱
  10435. 1430, //公务舱(实际经济舱)
  10436. 1432, //头等舱(实际经济舱)
  10437. };
  10438. var bizTypeIds = new List<int>() {
  10439. 457, //头等舱
  10440. 458, //公务舱
  10441. 1431, //头等舱(实际公务舱)
  10442. };
  10443. var auditFeeTypeIds = new List<int>() { };
  10444. auditFeeTypeIds.AddRange(ecoTypeIds);
  10445. auditFeeTypeIds.AddRange(bizTypeIds);
  10446. int currModule = 85;
  10447. var airInfo = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  10448. .InnerJoin<Grp_CreditCardPayment>((x, y) => x.Id == y.CId && y.CTable == currModule && y.IsDel == 0)
  10449. .Where((x, y) => x.Id == dataId && x.IsDel == 0 && auditFeeTypeIds.Contains(x.CType))
  10450. .Select((x, y) => new
  10451. {
  10452. x.Id,
  10453. CcpId = y.Id,
  10454. x.FlightsDate,
  10455. x.PrePrice,
  10456. x.CType,
  10457. x.ClientNum,
  10458. x.DIId
  10459. })
  10460. .FirstAsync();
  10461. if (airInfo == null) return (false, "机票信息为空或费用类型不在自动审核范围内,不可自动审核!");
  10462. var groupDetails = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.IsDel == 0 && x.Id == diId);
  10463. if (groupDetails == null) return (false, "团组信息为空,不可自动审核!");
  10464. var groupCostInfo = await _sqlSugar.Queryable<Grp_GroupCostParameter>().FirstAsync(x => x.IsDel == 0 && x.DiId == diId);
  10465. if (groupCostInfo == null) return (false, "团组成本信息未填写!");
  10466. var groupCostContents = await _sqlSugar
  10467. .SqlQueryable<GroupCostAuditView>($"Select * From Grp_GroupCost")
  10468. .Where(x => x.IsDel == 0 && x.Diid == diId)
  10469. .ToListAsync();
  10470. if (groupCostContents.Count < 1) return (false, "团组成本信息未填写!");
  10471. //处理 成本详细信息日期为空 填装费用信息
  10472. var airFeeLabel = new StringBuilder();
  10473. airFeeLabel.AppendLine("费用成本:");
  10474. for (int i = 0; i < groupCostContents.Count; i++)
  10475. {
  10476. if (string.IsNullOrEmpty(groupCostContents[i].Date))
  10477. {
  10478. int index = i - 1;
  10479. if (index >= 0)
  10480. {
  10481. groupCostContents[i].Date = groupCostContents[index].Date;
  10482. var dtBool = DateTime.TryParse(groupCostContents[i].Date, out DateTime _dateTime);
  10483. if (dtBool) groupCostContents[i].CurrTime = _dateTime;
  10484. }
  10485. }
  10486. else
  10487. {
  10488. var dtBool = DateTime.TryParse(groupCostContents[i].Date, out DateTime _dateTime);
  10489. if (dtBool) groupCostContents[i].CurrTime = _dateTime;
  10490. }
  10491. var item = groupCostContents[i];
  10492. airFeeLabel.AppendLine($"{item.Date}");
  10493. airFeeLabel.AppendLine($"{item.ITIN.Replace("\n", " ")}");
  10494. }
  10495. airFeeLabel.AppendLine($"注:费用:位置:航班号或者航班时间后面; 组成:经济舱/公务舱;");
  10496. airFeeLabel.AppendLine($"取出“{airInfo.FlightsDate}”费用金额,按照经济舱/公务舱格式返回,如果不存在的话则返回0.00/0.00,只返回金额格式文本;不需要其他文字描述;");
  10497. //访问Kimi AI 返回价格结果
  10498. var msgs = new List<SeedMessages>()
  10499. {
  10500. new ()
  10501. {
  10502. Role = KimiRole.user,
  10503. Content = airFeeLabel.ToString()
  10504. }
  10505. };
  10506. var client = new KiMiApiClient();
  10507. var kimiApiResult = await client.SeedMessage(msgs);
  10508. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  10509. string clients = kimiApiResult_JObject["content"].ToString();
  10510. decimal ecoPri_kimiAI = 0.00M,
  10511. bizPri_kimiAI = 0.00M;
  10512. //单个价格: 经济舱价格
  10513. if (decimal.TryParse(clients, out ecoPri_kimiAI)) { }
  10514. //价格文本包含/:/前经济舱价格 /后公务舱价格
  10515. if (clients.Contains('/'))
  10516. {
  10517. var priArray = clients.Split('/');
  10518. decimal.TryParse(priArray[0], out ecoPri_kimiAI); //
  10519. decimal.TryParse(priArray[1], out bizPri_kimiAI); //经济舱价格
  10520. }
  10521. else return (false, "价格文本不存在价格或KIMI-AI未识别出价格,不可自动审核!");
  10522. var isAutoAudit = false;
  10523. //价格验证处理
  10524. //经济舱
  10525. if (ecoTypeIds.Contains(airInfo.CType))
  10526. {
  10527. if (airInfo.PrePrice <= ecoPri_kimiAI) isAutoAudit = true;
  10528. }
  10529. //公务舱
  10530. else if (bizTypeIds.Contains(airInfo.CType))
  10531. {
  10532. if (airInfo.PrePrice <= bizPri_kimiAI) isAutoAudit = true;
  10533. }
  10534. else return (false, "该舱位类型不在自动审核范围内,不可自动审核!");
  10535. //是否执行自动审核
  10536. if (isAutoAudit)
  10537. {
  10538. var auditStatus = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  10539. .SetColumns(x => x.IsAuditGM == 3)
  10540. .SetColumns(x => x.AuditGMOperate == 4)
  10541. .SetColumns(x => x.AuditGMDate == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  10542. .Where(x => x.Id == airInfo.CcpId)
  10543. .ExecuteCommandAsync();
  10544. if (auditStatus > 0) return (true, "机票自动审核(KIMI-AI识别方式)执行成功!");
  10545. }
  10546. return (false, "当前费用超过成本费用,不可自动审核!");
  10547. }
  10548. /// <summary>
  10549. /// 机票费用录入
  10550. /// 自动审核测试 - AI 识别
  10551. /// </summary>
  10552. /// <param name="groupId"></param>
  10553. /// <param name="Id"></param>
  10554. /// <returns></returns>
  10555. [HttpPost]
  10556. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10557. public async Task<IActionResult> AirTicketResAutoAuditTest(int groupId, int Id)
  10558. {
  10559. (bool status, string msg) = await AirTicketResAutoAudit(groupId, Id);
  10560. return Ok(JsonView(status, msg));
  10561. }
  10562. /// <summary>
  10563. /// 根据舱位类型查询接团客户名单信息
  10564. /// </summary>
  10565. /// <param name="dto"></param>
  10566. /// <returns></returns>
  10567. [HttpPost]
  10568. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10569. public async Task<IActionResult> TankType(AirTicketResByIdDto dto)
  10570. {
  10571. try
  10572. {
  10573. List<Crm_GroupCustomer> crm_Groups = _sqlSugar.Queryable<Crm_GroupCustomer>().Where(a => a.IsDel == 0 && a.AirType == dto.Id).ToList();
  10574. if (crm_Groups.Count != 0)
  10575. {
  10576. var Customer = new List<dynamic>();
  10577. foreach (var item in crm_Groups)
  10578. {
  10579. var data = new
  10580. {
  10581. item.Id,
  10582. item.Pinyin,
  10583. Name = item.LastName + item.FirstName
  10584. };
  10585. Customer.Add(data);
  10586. }
  10587. return Ok(JsonView(true, "查询成功!", Customer));
  10588. }
  10589. return Ok(JsonView(true, "暂无数据", crm_Groups));
  10590. }
  10591. catch (Exception ex)
  10592. {
  10593. return Ok(JsonView(false, "程序错误!"));
  10594. throw;
  10595. }
  10596. }
  10597. /// <summary>
  10598. /// 根据团号获取客户信息
  10599. /// </summary>
  10600. /// <param name="dto"></param>
  10601. /// <returns></returns>
  10602. [HttpPost]
  10603. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10604. public IActionResult QueryClientInfoByDIID(QueryClientInfoByDIIDDto dto)
  10605. {
  10606. var jw = JsonView(false);
  10607. if (dto.DIID < 1)
  10608. {
  10609. jw.Msg += "请输入正确的diid";
  10610. return Ok(jw);
  10611. }
  10612. var arr = GetSimplClientList(dto.DIID);
  10613. jw = JsonView(true, "获取成功!", arr);
  10614. return Ok(jw);
  10615. }
  10616. private List<SimplClientInfo> GetSimplClientList(int diId)
  10617. {
  10618. 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);
  10619. List<SimplClientInfo> arr = _sqlSugar.SqlQueryable<SimplClientInfo>(sql).ToList();
  10620. foreach (var item in arr)
  10621. {
  10622. EncryptionProcessor.DecryptProperties(item);
  10623. }
  10624. return arr;
  10625. }
  10626. private static string GetClientNameStr(List<SimplClientInfo> list, string origin)
  10627. {
  10628. string result = origin;
  10629. if (Regex.Match(origin, @"\d+,?").Value.Length > 0)
  10630. {
  10631. string[] temparr = origin.Split(',');
  10632. string fistrStr = temparr[0];
  10633. int count = temparr.Length;
  10634. bool success = int.TryParse(fistrStr, out int tempId);
  10635. if (success)
  10636. {
  10637. SimplClientInfo tempInfo = list.FirstOrDefault(s => s.Id == tempId);
  10638. if (tempInfo != null)
  10639. {
  10640. if (count > 1)
  10641. {
  10642. result = string.Format(@"{0}{1}等{2}人", tempInfo.LastName, tempInfo.FirstName, count);
  10643. }
  10644. else
  10645. {
  10646. result = string.Format(@"{0}{1}", tempInfo.LastName, tempInfo.FirstName);
  10647. }
  10648. }
  10649. }
  10650. }
  10651. return result;
  10652. }
  10653. private static string GetClientNameStr1(List<SimplClientInfo> list, string origin)
  10654. {
  10655. string result = origin;
  10656. if (Regex.Match(origin, @"\d+,?").Value.Length > 0)
  10657. {
  10658. string[] temparr = origin.Split(',');
  10659. result = "";
  10660. foreach (var item in temparr)
  10661. {
  10662. bool success = int.TryParse(item, out int tempId);
  10663. if (success)
  10664. {
  10665. SimplClientInfo tempInfo = list.FirstOrDefault(s => s.Id == tempId);
  10666. if (tempInfo != null)
  10667. {
  10668. result += string.Format(@"{0}{1}、", tempInfo.LastName, tempInfo.FirstName);
  10669. }
  10670. }
  10671. }
  10672. }
  10673. if (result.Length > 0) result = result.Substring(0, result.Length - 1);
  10674. return result;
  10675. }
  10676. /// <summary>
  10677. /// 机票费用录入,删除
  10678. /// </summary>
  10679. /// <param name="dto"></param>
  10680. /// <returns></returns>
  10681. [HttpPost]
  10682. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10683. public async Task<IActionResult> DelAirTicketRes(DelBaseDto dto)
  10684. {
  10685. try
  10686. {
  10687. //验证
  10688. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 85);
  10689. if (!valid) return Ok(JsonView(false, msg));
  10690. var res = await _airTicketResRep.SoftDeleteByIdAsync<Grp_AirTicketReservations>(dto.Id.ToString(), dto.DeleteUserId);
  10691. if (res)
  10692. {
  10693. var result = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == dto.Id && a.CTable == 85).SetColumns(a => new Grp_CreditCardPayment()
  10694. {
  10695. IsDel = 1,
  10696. DeleteUserId = dto.DeleteUserId,
  10697. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  10698. }).ExecuteCommandAsync();
  10699. return Ok(JsonView(true, "删除成功!"));
  10700. }
  10701. return Ok(JsonView(false, "删除失败!"));
  10702. }
  10703. catch (Exception ex)
  10704. {
  10705. return Ok(JsonView(false, "程序错误!"));
  10706. }
  10707. }
  10708. /// <summary>
  10709. /// 导出机票录入报表
  10710. /// </summary>
  10711. /// <param name="dto"></param>
  10712. /// <returns></returns>
  10713. [HttpPost]
  10714. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10715. public async Task<IActionResult> DeriveAirTicketRes(AirTicketResDto dto)
  10716. {
  10717. try
  10718. {
  10719. Result groupData = await _airTicketResRep.DeriveAirTicketRes(dto);
  10720. if (groupData.Code != 0)
  10721. {
  10722. return Ok(JsonView(StatusCodes.Status400BadRequest, groupData.Msg, ""));
  10723. }
  10724. else
  10725. {
  10726. List<AirTicketReservationsPayView> AirTicketReservations = groupData.Data.GetType().GetProperty("AirTicketRes").GetValue(groupData.Data);
  10727. if (AirTicketReservations.Count != 0)
  10728. {
  10729. Grp_DelegationInfo DelegationInfo = groupData.Data.GetType().GetProperty("Delegation").GetValue(groupData.Data);
  10730. Sys_Users _Users = groupData.Data.GetType().GetProperty("Users").GetValue(groupData.Data);
  10731. string diCode = DelegationInfo != null ? DelegationInfo.TourCode : "XXX";
  10732. string diName = DelegationInfo != null ? DelegationInfo.TeamName : "XXX";
  10733. var designer = new WorkbookDesigner
  10734. {
  10735. Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/机票预订费用报表模板.xlsx")
  10736. };
  10737. decimal countCost = 0;
  10738. foreach (var item in AirTicketReservations)
  10739. {
  10740. #region 处理客人姓名
  10741. string clientNames = _tourClientListRep.ResolveCustomerName(item.ClientName);
  10742. item.ClientName = clientNames;
  10743. #endregion
  10744. if (item.BankType == "其他")
  10745. {
  10746. item.BankNo = "--";
  10747. }
  10748. else
  10749. {
  10750. if (!string.IsNullOrEmpty(item.BankType))
  10751. {
  10752. item.BankNo = $"{item.BankType}:{item.BankNo?[..3]}";
  10753. }
  10754. }
  10755. item.PrePrice = System.Decimal.Round(item.PrePrice, 2);
  10756. item.Price = System.Decimal.Round(item.Price, 2);
  10757. countCost += Convert.ToDecimal(item.Price);
  10758. }
  10759. designer.SetDataSource("Export", AirTicketReservations);
  10760. designer.SetDataSource("ExportDiCode", diCode);
  10761. designer.SetDataSource("ExportDiName", diName);
  10762. designer.SetDataSource("ExportOpUserName", _Users.CnName);
  10763. designer.SetDataSource("ExportCountCost", countCost + "(" + AirTicketReservations[0].CurrencyStr);
  10764. designer.Process();
  10765. string fileName = ("AirfareStatement/" + diName + "机票费用报表" + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx").Replace(":", "");
  10766. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  10767. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  10768. return Ok(JsonView(true, "成功", url = rst));
  10769. }
  10770. else
  10771. {
  10772. return Ok(JsonView(StatusCodes.Status400BadRequest, "暂无数据!", ""));
  10773. }
  10774. }
  10775. }
  10776. catch (Exception ex)
  10777. {
  10778. return Ok(JsonView(StatusCodes.Status400BadRequest, ex.Message, ""));
  10779. throw;
  10780. }
  10781. }
  10782. private Dictionary<string, string> transDic = new Dictionary<string, string>();
  10783. /// <summary>
  10784. /// 行程单导出
  10785. /// </summary>
  10786. /// <param name="dto"></param>
  10787. /// <returns></returns>
  10788. [HttpPost]
  10789. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10790. public async Task<IActionResult> ItineraryAirTicketRes(ItineraryAirTicketResDto dto)
  10791. {
  10792. try
  10793. {
  10794. Result groupData = await _airTicketResRep.ItineraryAirTicketRes(dto);
  10795. if (groupData.Code != 0)
  10796. {
  10797. return Ok(JsonView(StatusCodes.Status400BadRequest, groupData.Msg, ""));
  10798. }
  10799. else
  10800. {
  10801. List<AirTicketReservationsView> _AirTicketReservations = groupData.Data;
  10802. if (dto.Language == "CN")
  10803. {
  10804. var doc = new Document(AppSettingsHelper.Get("WordBasePath") + "Template/电子客票行程单模板_CN.docx");
  10805. var builder = new DocumentBuilder(doc);
  10806. int tableIndex = 0;//表格索引
  10807. //得到文档中的第一个表格
  10808. Table table = (Table)doc.GetChild(NodeType.Table, tableIndex, true);
  10809. foreach (var item in _AirTicketReservations)
  10810. {
  10811. #region 处理固定数据
  10812. string[] FlightsCode = item.FlightsCode.Split('/');
  10813. if (FlightsCode.Length != 0)
  10814. {
  10815. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  10816. if (_AirCompany != null)
  10817. {
  10818. table.Range.Bookmarks["AirlineCompany"].Text = _AirCompany.CnName;
  10819. }
  10820. else
  10821. {
  10822. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  10823. }
  10824. }
  10825. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  10826. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  10827. string[] nameArray = Regex.Split(item.ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  10828. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  10829. string name = "";
  10830. foreach (string clientName in nameArray)
  10831. {
  10832. if (!name.Contains(clientName))
  10833. {
  10834. name += clientName + ",";
  10835. }
  10836. }
  10837. if (!string.IsNullOrWhiteSpace(name))
  10838. {
  10839. table.Range.Bookmarks["ClientName"].Text = name.Substring(0, name.Length - 1);
  10840. }
  10841. else
  10842. {
  10843. table.Range.Bookmarks["ClientName"].Text = "--";
  10844. }
  10845. table.Range.Bookmarks["TicketNumber"].Text = "--";
  10846. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  10847. table.Range.Bookmarks["JointTicket"].Text = "--";
  10848. table.Range.Bookmarks["TimeIssue"].Text = "--";
  10849. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  10850. table.Range.Bookmarks["NavigationCode"].Text = "--";
  10851. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  10852. table.Range.Bookmarks["AgentPhone"].Text = "--";
  10853. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  10854. #endregion
  10855. #region 循环数据处理
  10856. var airs = new List<AirInfo>();
  10857. string[] DayArray = Regex.Split(item.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase);
  10858. DayArray = DayArray.Where(s => s != " " && s != "" && !string.IsNullOrEmpty(s)).ToArray();
  10859. for (int i = 0; i < FlightsCode.Length; i++)
  10860. {
  10861. var air = new AirInfo();
  10862. string[] tempstr = DayArray[i]
  10863. .Replace("\r\n", string.Empty)
  10864. .Replace("\\r\\n", string.Empty)
  10865. .TrimStart().TrimEnd()
  10866. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  10867. Res_ThreeCode star_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(0, 3));
  10868. string starCity = "";
  10869. if (star_Three != null)
  10870. {
  10871. starCity = star_Three.AirPort;
  10872. }
  10873. Res_ThreeCode End_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(3, 3));
  10874. string EndCity = "";
  10875. if (End_Three != null)
  10876. {
  10877. EndCity = End_Three.AirPort;
  10878. }
  10879. air.Destination = starCity + "/" + EndCity;
  10880. air.Flight = FlightsCode[i];
  10881. air.SeatingClass = item.CTypeName;
  10882. string dateTime = tempstr[2];
  10883. string DateTemp = dateTime.Substring(2, 5).ToUpper();
  10884. air.FlightDate = DateTemp;
  10885. air.DepartureTime = tempstr[5];
  10886. air.LandingTime = tempstr[6];
  10887. air.ValidityPeriod = DateTemp + "/" + DateTemp;
  10888. air.TicketStatus = "--";
  10889. air.Luggage = "--";
  10890. air.DepartureTerminal = "--";
  10891. air.LandingTerminal = "--";
  10892. airs.Add(air);
  10893. }
  10894. int row = 13;
  10895. for (int i = 0; i < airs.Count; i++)
  10896. {
  10897. if (airs.Count > 2)
  10898. {
  10899. for (int j = 0; j < airs.Count - 2; j++)
  10900. {
  10901. var CopyRow = table.Rows[12].Clone(true);
  10902. table.Rows.Add(CopyRow);
  10903. }
  10904. }
  10905. PropertyInfo[] properties = airs[i].GetType().GetProperties();
  10906. int index = 0;
  10907. foreach (PropertyInfo property in properties)
  10908. {
  10909. string value = property.GetValue(airs[i]).ToString();
  10910. Cell ishcel0 = table.Rows[row].Cells[index];
  10911. var p = new Paragraph(doc);
  10912. string s = value;
  10913. p.AppendChild(new Run(doc, s));
  10914. p.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐
  10915. ishcel0.AppendChild(p);
  10916. ishcel0.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
  10917. index++;
  10918. }
  10919. row++;
  10920. }
  10921. #endregion
  10922. var lastParagraph = new Paragraph(doc);
  10923. //第一个表格末尾加段落
  10924. table.ParentNode.InsertAfter(lastParagraph, table);
  10925. //复制第一个表格
  10926. Table cloneTable = (Table)table.Clone(true);
  10927. //在文档末尾段落后面加入复制的表格
  10928. table.ParentNode.InsertAfter(cloneTable, lastParagraph);
  10929. if (item != _AirTicketReservations[_AirTicketReservations.Count - 1])
  10930. {
  10931. int rownewsIndex = 13;
  10932. for (int i = 0; i < 2; i++)
  10933. {
  10934. var CopyRow = table.Rows[12].Clone(true);
  10935. table.Rows.RemoveAt(13);
  10936. table.Rows.Add(CopyRow);
  10937. rownewsIndex++;
  10938. }
  10939. }
  10940. else
  10941. {
  10942. table.Rows.RemoveAt(12);
  10943. }
  10944. cloneTable.Rows.RemoveAt(12);
  10945. }
  10946. if (_AirTicketReservations.Count != 0)
  10947. {
  10948. string[] FlightsCode = _AirTicketReservations[0].FlightsCode.Split('/');
  10949. if (FlightsCode.Length != 0)
  10950. {
  10951. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  10952. if (_AirCompany != null)
  10953. {
  10954. table.Range.Bookmarks["AirlineCompany"].Text = _AirCompany.CnName;
  10955. }
  10956. else
  10957. {
  10958. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  10959. }
  10960. }
  10961. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  10962. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  10963. string[] nameArray = Regex.Split(_AirTicketReservations[0].ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  10964. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  10965. string name = "";
  10966. foreach (string clientName in nameArray)
  10967. {
  10968. if (!name.Contains(clientName))
  10969. {
  10970. name += clientName + ",";
  10971. }
  10972. }
  10973. if (!string.IsNullOrWhiteSpace(name))
  10974. {
  10975. table.Range.Bookmarks["ClientName"].Text = name.Substring(0, name.Length - 1);
  10976. }
  10977. else
  10978. {
  10979. table.Range.Bookmarks["ClientName"].Text = "--";
  10980. }
  10981. table.Range.Bookmarks["TicketNumber"].Text = "--";
  10982. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  10983. table.Range.Bookmarks["JointTicket"].Text = "--";
  10984. table.Range.Bookmarks["TimeIssue"].Text = "--";
  10985. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  10986. table.Range.Bookmarks["NavigationCode"].Text = "--";
  10987. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  10988. table.Range.Bookmarks["AgentPhone"].Text = "--";
  10989. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  10990. }
  10991. doc.MailMerge.Execute(new[] { "PageCount" }, new object[] { doc.PageCount });
  10992. //保存合并后的文档
  10993. string fileName = "AirItinerary/电子客票中文行程单_CN.docx";
  10994. string rst = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + fileName;
  10995. doc.Save(AppSettingsHelper.Get("WordBasePath") + fileName);
  10996. return Ok(JsonView(true, "成功!", rst));
  10997. }
  10998. else
  10999. {
  11000. var doc = new Document(AppSettingsHelper.Get("WordBasePath") + "Template/电子客票行程单模板_EN.docx");
  11001. var builder = new DocumentBuilder(doc);
  11002. int tableIndex = 0;//表格索引
  11003. //得到文档中的第一个表格
  11004. Table table = (Table)doc.GetChild(NodeType.Table, tableIndex, true);
  11005. var texts = new List<string>();
  11006. foreach (var item in _AirTicketReservations)
  11007. {
  11008. string[] FlightsCode = item.FlightsCode.Split('/');
  11009. if (FlightsCode.Length != 0)
  11010. {
  11011. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  11012. if (_AirCompany != null)
  11013. {
  11014. if (!transDic.ContainsKey(_AirCompany.CnName))
  11015. {
  11016. transDic.Add(_AirCompany.CnName, _AirCompany.EnName);
  11017. }
  11018. }
  11019. else
  11020. {
  11021. if (!transDic.ContainsKey("--"))
  11022. {
  11023. transDic.Add("--", "--");
  11024. }
  11025. }
  11026. }
  11027. string[] nameArray = Regex.Split(item.ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  11028. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  11029. string name = "";
  11030. foreach (string clientName in nameArray)
  11031. {
  11032. name += clientName + ",";
  11033. }
  11034. if (!texts.Contains(name))
  11035. {
  11036. texts.Add(name);
  11037. }
  11038. var airs = new List<AirInfo>();
  11039. string[] DayArray = Regex.Split(item.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase);
  11040. DayArray = DayArray.Where(s => s != " " && s != "" && !string.IsNullOrEmpty(s)).ToArray();
  11041. for (int i = 0; i < FlightsCode.Length; i++)
  11042. {
  11043. var air = new AirInfo();
  11044. string[] tempstr = DayArray[i]
  11045. .Replace("\r\n", string.Empty)
  11046. .Replace("\\r\\n", string.Empty)
  11047. .TrimStart().TrimEnd()
  11048. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  11049. Res_ThreeCode star_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(0, 3));
  11050. if (star_Three != null)
  11051. {
  11052. if (!transDic.ContainsKey(star_Three.AirPort))
  11053. {
  11054. transDic.Add(star_Three.AirPort, star_Three.AirPort_En);
  11055. }
  11056. }
  11057. Res_ThreeCode End_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(3, 3));
  11058. if (End_Three != null)
  11059. {
  11060. if (!transDic.ContainsKey(End_Three.AirPort))
  11061. {
  11062. transDic.Add(End_Three.AirPort, End_Three.AirPort_En);
  11063. }
  11064. }
  11065. if (!texts.Contains(item.CTypeName))
  11066. {
  11067. texts.Add(item.CTypeName);
  11068. }
  11069. }
  11070. }
  11071. List<TranslateResult> transData = await _airTicketResRep.ReTransBatch(texts, "en");
  11072. if (transData.Count > 0)
  11073. {
  11074. foreach (TranslateResult item in transData)
  11075. {
  11076. if (!transDic.ContainsKey(item.Query))
  11077. {
  11078. transDic.Add(item.Query, item.Translation);
  11079. }
  11080. }
  11081. }
  11082. foreach (var item in _AirTicketReservations)
  11083. {
  11084. #region 处理固定数据
  11085. string[] FlightsCode = item.FlightsCode.Split('/');
  11086. if (FlightsCode.Length != 0)
  11087. {
  11088. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  11089. if (_AirCompany != null)
  11090. {
  11091. string str = "--";
  11092. string translateResult = transDic.Where(s => s.Key == _AirCompany.CnName).FirstOrDefault().Value;
  11093. if (!string.IsNullOrEmpty(translateResult))
  11094. {
  11095. str = translateResult;
  11096. str = _airTicketResRep.Processing(str);
  11097. }
  11098. table.Range.Bookmarks["AirlineCompany"].Text = str;
  11099. }
  11100. else
  11101. {
  11102. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  11103. }
  11104. }
  11105. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  11106. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  11107. string[] nameArray = Regex.Split(item.ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  11108. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  11109. string names = "";
  11110. foreach (string clientName in nameArray)
  11111. {
  11112. names += clientName + ",";
  11113. }
  11114. if (!string.IsNullOrWhiteSpace(names))
  11115. {
  11116. string str = "--";
  11117. string translateResult = transDic.Where(s => s.Key == names).FirstOrDefault().Value;
  11118. if (!string.IsNullOrEmpty(translateResult))
  11119. {
  11120. str = translateResult;
  11121. str = _airTicketResRep.Processing(str);
  11122. }
  11123. table.Range.Bookmarks["ClientName"].Text = str;
  11124. }
  11125. else
  11126. {
  11127. table.Range.Bookmarks["ClientName"].Text = "--";
  11128. }
  11129. table.Range.Bookmarks["TicketNumber"].Text = "--";
  11130. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  11131. table.Range.Bookmarks["JointTicket"].Text = "--";
  11132. table.Range.Bookmarks["TimeIssue"].Text = "--";
  11133. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  11134. table.Range.Bookmarks["NavigationCode"].Text = "--";
  11135. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  11136. table.Range.Bookmarks["AgentPhone"].Text = "--";
  11137. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  11138. #endregion
  11139. #region 循环数据处理
  11140. var airs = new List<AirInfo>();
  11141. string[] DayArray = Regex.Split(item.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase);
  11142. DayArray = DayArray.Where(s => s != " " && s != "" && !string.IsNullOrEmpty(s)).ToArray();
  11143. for (int i = 0; i < FlightsCode.Length; i++)
  11144. {
  11145. var air = new AirInfo();
  11146. string[] tempstr = DayArray[i]
  11147. .Replace("\r\n", string.Empty)
  11148. .Replace("\\r\\n", string.Empty)
  11149. .TrimStart().TrimEnd()
  11150. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  11151. Res_ThreeCode star_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(0, 3));
  11152. string starCity = "";
  11153. if (star_Three != null)
  11154. {
  11155. string str2 = "--";
  11156. string translateResult2 = transDic.Where(s => s.Key == star_Three.AirPort).FirstOrDefault().Value;
  11157. if (!string.IsNullOrEmpty(translateResult2))
  11158. {
  11159. str2 = translateResult2;
  11160. str2 = _airTicketResRep.Processing(str2);
  11161. }
  11162. starCity = str2;
  11163. }
  11164. Res_ThreeCode End_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(3, 3));
  11165. string EndCity = "";
  11166. if (End_Three != null)
  11167. {
  11168. string str1 = "--";
  11169. string translateResult1 = transDic.Where(s => s.Key == End_Three.AirPort).FirstOrDefault().Value;
  11170. if (!string.IsNullOrEmpty(translateResult1))
  11171. {
  11172. str1 = translateResult1;
  11173. str1 = _airTicketResRep.Processing(str1);
  11174. }
  11175. EndCity = str1;
  11176. }
  11177. air.Destination = starCity + "/" + EndCity;
  11178. air.Flight = FlightsCode[i];
  11179. string str = "--";
  11180. string translateResult = transDic.Where(s => s.Key == item.CTypeName).FirstOrDefault().Value;
  11181. if (!string.IsNullOrEmpty(translateResult))
  11182. {
  11183. str = translateResult;
  11184. str = _airTicketResRep.Processing(str);
  11185. }
  11186. air.SeatingClass = str;
  11187. string dateTime = tempstr[2];
  11188. string DateTemp = dateTime.Substring(2, 5).ToUpper();
  11189. air.FlightDate = DateTemp;
  11190. air.DepartureTime = tempstr[5];
  11191. air.LandingTime = tempstr[6];
  11192. air.ValidityPeriod = DateTemp + "/" + DateTemp;
  11193. air.TicketStatus = "--";
  11194. air.Luggage = "--";
  11195. air.DepartureTerminal = "--";
  11196. air.LandingTerminal = "--";
  11197. airs.Add(air);
  11198. }
  11199. int row = 13;
  11200. for (int i = 0; i < airs.Count; i++)
  11201. {
  11202. if (airs.Count > 2)
  11203. {
  11204. for (int j = 0; j < airs.Count - 2; j++)
  11205. {
  11206. var CopyRow = table.Rows[12].Clone(true);
  11207. table.Rows.Add(CopyRow);
  11208. }
  11209. }
  11210. PropertyInfo[] properties = airs[i].GetType().GetProperties();
  11211. int index = 0;
  11212. foreach (PropertyInfo property in properties)
  11213. {
  11214. string value = property.GetValue(airs[i]).ToString();
  11215. Cell ishcel0 = table.Rows[row].Cells[index];
  11216. var p = new Paragraph(doc);
  11217. string s = value;
  11218. p.AppendChild(new Run(doc, s));
  11219. p.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐
  11220. ishcel0.AppendChild(p);
  11221. ishcel0.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
  11222. //ishcel0.CellFormat.VerticalAlignment=
  11223. index++;
  11224. }
  11225. row++;
  11226. }
  11227. #endregion
  11228. var lastParagraph = new Paragraph(doc);
  11229. //第一个表格末尾加段落
  11230. table.ParentNode.InsertAfter(lastParagraph, table);
  11231. //复制第一个表格
  11232. Table cloneTable = (Table)table.Clone(true);
  11233. //在文档末尾段落后面加入复制的表格
  11234. table.ParentNode.InsertAfter(cloneTable, lastParagraph);
  11235. if (item != _AirTicketReservations[_AirTicketReservations.Count - 1])
  11236. {
  11237. int rownewsIndex = 13;
  11238. for (int i = 0; i < 2; i++)
  11239. {
  11240. var CopyRow = table.Rows[12].Clone(true);
  11241. table.Rows.RemoveAt(13);
  11242. table.Rows.Add(CopyRow);
  11243. rownewsIndex++;
  11244. }
  11245. }
  11246. else
  11247. {
  11248. table.Rows.RemoveAt(12);
  11249. }
  11250. cloneTable.Rows.RemoveAt(12);
  11251. }
  11252. if (_AirTicketReservations.Count != 0)
  11253. {
  11254. string[] FlightsCode = _AirTicketReservations[0].FlightsCode.Split('/');
  11255. if (FlightsCode.Length != 0)
  11256. {
  11257. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  11258. if (_AirCompany != null)
  11259. {
  11260. string str = "--";
  11261. string translateResult = transDic.Where(s => s.Key == _AirCompany.CnName).FirstOrDefault().Value;
  11262. if (!string.IsNullOrEmpty(translateResult))
  11263. {
  11264. str = translateResult;
  11265. str = _airTicketResRep.Processing(str);
  11266. }
  11267. table.Range.Bookmarks["AirlineCompany"].Text = str;
  11268. }
  11269. else
  11270. {
  11271. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  11272. }
  11273. }
  11274. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  11275. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  11276. string[] nameArray = Regex.Split(_AirTicketReservations[0].ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  11277. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  11278. string names = "";
  11279. foreach (string clientName in nameArray)
  11280. {
  11281. names += clientName + ",";
  11282. }
  11283. if (!string.IsNullOrWhiteSpace(names))
  11284. {
  11285. string str = "--";
  11286. string translateResult = transDic.Where(s => s.Key == names).FirstOrDefault().Value;
  11287. if (!string.IsNullOrEmpty(translateResult))
  11288. {
  11289. str = translateResult;
  11290. str = _airTicketResRep.Processing(str);
  11291. }
  11292. table.Range.Bookmarks["ClientName"].Text = str;
  11293. }
  11294. else
  11295. {
  11296. table.Range.Bookmarks["ClientName"].Text = "--";
  11297. }
  11298. table.Range.Bookmarks["TicketNumber"].Text = "--";
  11299. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  11300. table.Range.Bookmarks["JointTicket"].Text = "--";
  11301. table.Range.Bookmarks["TimeIssue"].Text = "--";
  11302. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  11303. table.Range.Bookmarks["NavigationCode"].Text = "--";
  11304. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  11305. table.Range.Bookmarks["AgentPhone"].Text = "--";
  11306. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  11307. }
  11308. doc.MailMerge.Execute(new[] { "PageCount" }, new object[] { doc.PageCount });
  11309. //保存合并后的文档
  11310. string fileName = "AirItinerary/电子客票英文行程单_EN.docx";
  11311. string rst = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + fileName;
  11312. doc.Save(AppSettingsHelper.Get("WordBasePath") + fileName);
  11313. return Ok(JsonView(true, "成功!", rst));
  11314. }
  11315. }
  11316. }
  11317. catch (Exception ex)
  11318. {
  11319. return Ok(JsonView(StatusCodes.Status400BadRequest, "程序错误!", ""));
  11320. throw;
  11321. }
  11322. }
  11323. #endregion
  11324. #region 团组增减款项 --> 其他款项
  11325. /// <summary>
  11326. /// 团组增减款项下拉框绑定
  11327. /// </summary>
  11328. /// <param name="dto"></param>
  11329. /// <returns></returns>
  11330. [HttpPost]
  11331. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11332. public async Task<IActionResult> DecreasePaymentsSelect(DecreasePaymentsDto dto)
  11333. {
  11334. #region 参数验证
  11335. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  11336. if (dto.CTId < 1) return Ok(JsonView(false, "请传入有效的CTId参数!"));
  11337. #endregion
  11338. return Ok(await _decreasePaymentsRep.DecreasePaymentsSelect(dto));
  11339. }
  11340. /// <summary>
  11341. /// 根据团组Id查询团组增减款项
  11342. /// </summary>
  11343. /// <param name="dto"></param>
  11344. /// <returns></returns>
  11345. [HttpPost]
  11346. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11347. public async Task<IActionResult> DecreasePaymentsList(DecreasePaymentsListDto dto)
  11348. {
  11349. #region 参数验证
  11350. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  11351. if (dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId参数!"));
  11352. #endregion
  11353. return Ok(await _decreasePaymentsRep.DecreasePaymentsList(dto));
  11354. }
  11355. /// <summary>
  11356. /// 团组增减款项操作(Status:1.新增,2.修改)
  11357. /// </summary>
  11358. /// <param name="dto"></param>
  11359. /// <returns></returns>
  11360. [HttpPost]
  11361. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11362. public async Task<IActionResult> OpDecreasePayments(DecreasePaymentsOpDto dto)
  11363. {
  11364. JsonView groupData = await _decreasePaymentsRep.OpDecreasePayments(dto);
  11365. if (groupData.Code != 200)
  11366. {
  11367. return Ok(JsonView(false, groupData.Msg));
  11368. }
  11369. #region 应用推送
  11370. //int otherId = (int)groupData.Data.GetType().GetProperty("dataId").GetValue(groupData.Data, null);
  11371. //int ccpId = (int)groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  11372. //int sign = (int)groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  11373. int otherId = Convert.ToInt32(groupData.Data.GetType().GetProperty("dataId").GetValue(groupData.Data, null) ?? 0);
  11374. int ccpId = Convert.ToInt32(groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null) ?? 0);
  11375. int sign = Convert.ToInt32(groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null) ?? 0);
  11376. bool recheck = Convert.ToBoolean(groupData.Data.GetType().GetProperty("recheck").GetValue(groupData.Data, null) ?? "True");
  11377. if (recheck)
  11378. {
  11379. //自动审核
  11380. var autoAdit = await _feeAuditRep.FeeAutomaticAudit(3, dto.DiId, otherId);
  11381. }
  11382. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  11383. //2024-10-21 新增LZ UID
  11384. var userIds = new List<int>() { 21 };
  11385. string title = $"系统通知";
  11386. string content = "";
  11387. var diId = dto.DiId;
  11388. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  11389. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  11390. if (dto.Status == 1) content = $"[新增-其他款项({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  11391. else if (dto.Status == 2) content = $"[更新-其他款项({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  11392. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  11393. //await APNsTools.iOS_PushNotifications1("051", $"其他款项费用审核", "", content);
  11394. #endregion
  11395. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  11396. }
  11397. /// <summary>
  11398. /// 团组增减款项操作 删除
  11399. /// </summary>
  11400. /// <param name="dto"></param>
  11401. /// <returns></returns>
  11402. [HttpPost]
  11403. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11404. public async Task<IActionResult> DelDecreasePayments(DelBaseDto dto)
  11405. {
  11406. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数!"));
  11407. if (dto.DeleteUserId < 1) return Ok(JsonView(false, "请传入有效的DeleteUserId参数!"));
  11408. var res = await _decreasePaymentsRep._Del(dto.Id, dto.DeleteUserId);
  11409. if (res.Code == 0) return Ok(JsonView(true, "删除成功!"));
  11410. return Ok(JsonView(false, res?.Msg ?? "删除失败!"));
  11411. }
  11412. /// <summary>
  11413. /// 根据团组增减款项Id查询
  11414. /// </summary>
  11415. /// <param name="dto"></param>
  11416. /// <returns></returns>
  11417. [HttpPost]
  11418. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11419. public async Task<IActionResult> QueryDecreasePaymentsById(DecreasePaymentsByIdDto dto)
  11420. {
  11421. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的数据Id!"));
  11422. return Ok(await _decreasePaymentsRep.QueryDecreasePaymentsById(dto));
  11423. }
  11424. /// <summary>
  11425. /// 查询供应商名称
  11426. /// </summary>
  11427. /// <param name="dto"></param>
  11428. /// <returns></returns>
  11429. [HttpPost]
  11430. public IActionResult QueryAssociateSupplier(AssociateSupplierDto dto)
  11431. {
  11432. var dbResult = _sqlSugar.Queryable<Grp_DecreasePayments>()
  11433. .Where(x => x.SupplierName.Contains(dto.param) && x.IsDel == 0).ToList()
  11434. ?? new List<Grp_DecreasePayments>();
  11435. dbResult = dbResult.Distinct(new
  11436. ProductComparer()).ToList();
  11437. var jw = JsonView(true, "success", dbResult.OrderByDescending(x => x.Id).Select(x => new
  11438. {
  11439. x.Id,
  11440. x.SupplierAddress,
  11441. x.SupplierArea,
  11442. x.SupplierContact,
  11443. x.SupplierContactNumber,
  11444. x.SupplierEmail,
  11445. x.SupplierName,
  11446. x.SupplierSocialAccount,
  11447. x.SupplierTypeId,
  11448. }).ToList());
  11449. return Ok(jw);
  11450. }
  11451. /// <summary>
  11452. /// 团组增减款项 OTA匹配
  11453. /// </summary>
  11454. /// <param name="file"></param>
  11455. /// <returns></returns>
  11456. [HttpPost]
  11457. public async Task<IActionResult> DecreasePaymentsOTAMate(IFormFile file)
  11458. {
  11459. if (file.Length < 1) return Ok(JsonView(false, "请上传文件!"));
  11460. string fileName = file.FileName;
  11461. if (!fileName.EndsWith(".xlsx") && !fileName.EndsWith(".xls"))
  11462. {
  11463. return Ok(JsonView(false, "请上传Excel文件!"));
  11464. }
  11465. //D:\FTP\File\OA2023\Office\GrpFile\团组增减款项相关文件\团组其他款项(OTA)
  11466. var path = @$"{AppSettingsHelper.Get("GrpFileBasePath")}团组增减款项相关文件/团组其他款项(OTA)";
  11467. if (!Directory.Exists(path))
  11468. {
  11469. Directory.CreateDirectory(path);
  11470. }
  11471. var filePath = @$"{path}/{fileName}";
  11472. //保存文件
  11473. using (FileStream fs = System.IO.File.Create(filePath))
  11474. {
  11475. file.CopyTo(fs);
  11476. fs.Flush();
  11477. }
  11478. if (!System.IO.File.Exists(filePath)) return Ok(JsonView(false, "文件不存在!"));
  11479. //读取ExcelFile
  11480. DataTable dt = ConvertExcelToDataTable(filePath);
  11481. if (dt == null) return Ok(JsonView(false, $"您上传的Excel工作表没有内容,请检查!!!"));
  11482. dt.TableName = "TB";
  11483. //修改table列名
  11484. dt.Columns[0].ColumnName = "OrderNo"; // 订单号
  11485. dt.Columns[1].ColumnName = "OTAOrderNo"; // OTA订单号
  11486. dt.Columns[2].ColumnName = "PackageName"; // 套餐名
  11487. dt.Columns[3].ColumnName = "IsPay"; // 是否支付
  11488. dt.Columns[4].ColumnName = "IsShipments"; // 是否发货
  11489. dt.Columns[5].ColumnName = "IsSendBack"; // 是否寄回
  11490. dt.Columns[6].ColumnName = "OpUser"; // 使用人信息
  11491. dt.Columns[7].ColumnName = "OrderTime"; // 下单时间
  11492. dt.Columns[8].ColumnName = "UseTime"; // 使用时间
  11493. dt.Columns[9].ColumnName = "Quantity"; // 台数
  11494. dt.Columns[10].ColumnName = "Days"; // 租赁天数
  11495. dt.Columns[11].ColumnName = "QuantityShipped";// 发货数量
  11496. dt.Columns[12].ColumnName = "TotalPrice"; // 总金额
  11497. dt.Columns[13].ColumnName = "GroupName"; // 团组名称
  11498. dt.Columns[14].ColumnName = "OATotalPrice"; // OA金额
  11499. var otaOrderNos = new List<string>();
  11500. foreach (DataRow item in dt.Rows)
  11501. {
  11502. otaOrderNos.Add(item["OTAOrderNo"].ToString());
  11503. }
  11504. var oaDatas = await _sqlSugar.Queryable<Grp_DecreasePayments>()
  11505. .LeftJoin<Grp_DelegationInfo>((dp, di) => dp.DiId == di.Id)
  11506. .Where((dp, di) => dp.IsDel == 0 && dp.PriceName.Contains("wifi") || otaOrderNos.Contains(dp.OTAOrderNo))
  11507. .Select((dp, di) => new
  11508. {
  11509. dp.PriceName,
  11510. dp.OTAOrderNo,
  11511. dp.FeeTotal,
  11512. di.TeamName,
  11513. })
  11514. .ToListAsync();
  11515. foreach (DataRow item in dt.Rows)
  11516. {
  11517. var otaOrderNo = item["OTAOrderNo"].ToString();
  11518. var oaData = oaDatas.Find(x => !string.IsNullOrEmpty(x.OTAOrderNo) && x.OTAOrderNo.Contains(otaOrderNo));
  11519. if (oaData == null) continue;
  11520. item["GroupName"] = oaData.TeamName;
  11521. item["OATotalPrice"] = oaData.FeeTotal.ToString("#0.00");
  11522. }
  11523. string fileName1 = $"OTA_WIFI费用{DateTime.Now:yyyyMMddHHmmss}.xls";
  11524. var pairs = new Dictionary<string, object>();
  11525. var datas = new List<DataTable>
  11526. {
  11527. dt
  11528. };
  11529. url = AsposeHelper.ExpertExcelToModel("WIFI费用清单-模板.xlsx", $"GrpFile/团组增减款项相关文件/团组其他款项(OTA)", fileName1, pairs, datas);
  11530. return Ok(JsonView(true, "操作成功", new { url }));
  11531. }
  11532. #region
  11533. private static DataTable ConvertExcelToDataTable(string excelFilePath)
  11534. {
  11535. // 创建Workbook对象
  11536. var workbook = new Workbook(excelFilePath);
  11537. // 获取第一个工作表
  11538. var worksheet = workbook.Worksheets[0];
  11539. // 将工作表转换为DataTable
  11540. DataTable dataTable = worksheet.Cells.ExportDataTable(1, 0, worksheet.Cells.MaxDataRow + 1, worksheet.Cells.MaxDataColumn + 1);
  11541. return dataTable;
  11542. }
  11543. #endregion
  11544. /// <summary>
  11545. /// 世运会数据
  11546. /// </summary>
  11547. /// <returns></returns>
  11548. [HttpGet]
  11549. public IActionResult WorldGamesData()
  11550. {
  11551. var setData = _sqlSugar.Queryable<Grp_GamesBudgetMaster>().Where(x => x.IsDel == 0).ToList();
  11552. var groupMenu = setData.GroupBy(x => x.T0);
  11553. var resultArr = new List<DecreasePaymentsWorldGamesDataView>();
  11554. foreach (var item in groupMenu)
  11555. {
  11556. resultArr.Add(new DecreasePaymentsWorldGamesDataView
  11557. {
  11558. Data = new SetDataView
  11559. {
  11560. Name = item.Key
  11561. },
  11562. Child = item.Select(x => x.CalculationContent).ToList() ?? new List<string>()
  11563. });
  11564. }
  11565. return Ok(JsonView(true, "success", resultArr));
  11566. }
  11567. #endregion
  11568. #region 文件上传、删除
  11569. /// <summary>
  11570. /// region 文件上传 可以带参数
  11571. /// </summary>
  11572. /// <param name="file"></param>
  11573. /// <returns></returns>
  11574. [HttpPost]
  11575. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11576. public async Task<IActionResult> UploadProject(IFormFile file)
  11577. {
  11578. //var TypeName = Request.Headers["TypeName"].ToString();
  11579. //if (file == null) return Ok(JsonView(false, "文件不存在!"));
  11580. //var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  11581. ////文件名称
  11582. //string projectFileName = file.FileName;
  11583. ////上传的文件的路径
  11584. //string filePath = $"{fileDir}/{projectFileName}";
  11585. //if (TypeName == "A")//A代表团组增减款项
  11586. //{
  11587. // filePath = fileDir + $@"\团组增减款项相关文件";
  11588. // if (!Directory.Exists(filePath))
  11589. // {
  11590. // Directory.CreateDirectory(filePath);
  11591. // }
  11592. // //上传的文件的路径
  11593. // filePath += $@"\{projectFileName}";
  11594. //}
  11595. //else if (TypeName == "B")//B代表商邀相关文件
  11596. //{
  11597. // //上传的文件的路径
  11598. // filePath = fileDir + $@"\商邀相关文件\{projectFileName}";
  11599. // if (!Directory.Exists(filePath))
  11600. // {
  11601. // Directory.CreateDirectory(filePath);
  11602. // }
  11603. // //上传的文件的路径
  11604. // filePath = $@"\{projectFileName}";
  11605. //}
  11606. //try
  11607. //{
  11608. // using (FileStream fs = System.IO.File.Create(filePath))
  11609. // {
  11610. // file.CopyTo(fs);
  11611. // fs.Flush();
  11612. // }
  11613. //}
  11614. //catch (Exception ex)
  11615. //{
  11616. // return Ok(JsonView(false, $"文件上传失败! Error:{ex.Message}"));
  11617. //}
  11618. //return Ok(JsonView(true, "上传成功!", projectFileName));
  11619. try
  11620. {
  11621. var TypeName = Request.Headers["TypeName"].ToString();
  11622. if (file != null)
  11623. {
  11624. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  11625. //文件名称
  11626. string projectFileName = file.FileName;
  11627. //上传的文件的路径
  11628. string filePath = $"{fileDir}/{projectFileName}";
  11629. if (TypeName == "A")//A代表团组增减款项
  11630. {
  11631. if (!Directory.Exists(fileDir))
  11632. {
  11633. Directory.CreateDirectory(fileDir);
  11634. }
  11635. //上传的文件的路径
  11636. filePath = fileDir + $@"\团组增减款项相关文件\{projectFileName}";
  11637. }
  11638. else if (TypeName == "B")//B代表商邀相关文件
  11639. {
  11640. if (!Directory.Exists(fileDir))
  11641. {
  11642. Directory.CreateDirectory(fileDir);
  11643. }
  11644. //上传的文件的路径
  11645. filePath = fileDir + $@"\商邀相关文件\{projectFileName}";
  11646. }
  11647. using (FileStream fs = System.IO.File.Create(filePath))
  11648. {
  11649. file.CopyTo(fs);
  11650. fs.Flush();
  11651. }
  11652. return Ok(JsonView(true, "上传成功!", projectFileName));
  11653. }
  11654. else
  11655. {
  11656. return Ok(JsonView(false, "上传失败!"));
  11657. }
  11658. }
  11659. catch (Exception ex)
  11660. {
  11661. return Ok(JsonView(false, ex.Message));
  11662. }
  11663. }
  11664. /// <summary>
  11665. /// 删除指定文件
  11666. /// </summary>
  11667. /// <param name="dto"></param>
  11668. /// <returns></returns>
  11669. [HttpPost]
  11670. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11671. public async Task<IActionResult> DelFile(DelFileDto dto)
  11672. {
  11673. try
  11674. {
  11675. var TypeName = Request.Headers["TypeName"].ToString();
  11676. if (string.IsNullOrEmpty(TypeName)) return Ok(JsonView(false, "请选择选组对应模块!"));
  11677. string filePath = "";
  11678. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  11679. // 返回与指定虚拟路径相对应的物理路径即绝对路径
  11680. int id = 0;
  11681. if (TypeName == "A")
  11682. {
  11683. filePath = fileDir + "/团组增减款项相关文件/" + dto.fileName;
  11684. // 删除该文件
  11685. System.IO.File.Delete(filePath);
  11686. id = await _sqlSugar.Updateable<Grp_DecreasePayments>()
  11687. .Where(a => a.Id == dto.Id)
  11688. .SetColumns(a => new Grp_DecreasePayments { FilePath = "" })
  11689. .ExecuteCommandAsync();
  11690. }
  11691. else if (TypeName == "B")
  11692. {
  11693. filePath = fileDir + "/商邀相关文件/" + dto.fileName;
  11694. // 删除该文件
  11695. System.IO.File.Delete(filePath);
  11696. var info = await _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(x => x.Id == dto.Id && x.IsDel == 0).FirstAsync();
  11697. if (info != null)
  11698. {
  11699. string[] files = Array.Empty<string>();
  11700. if (!string.IsNullOrEmpty(info.Attachment))
  11701. {
  11702. try
  11703. {
  11704. files = JsonConvert.DeserializeObject<string[]>(info.Attachment);
  11705. }
  11706. catch (Exception)
  11707. {
  11708. files = new List<string>() { info.Attachment }.ToArray();
  11709. }
  11710. }
  11711. if (files.Length > 0)
  11712. {
  11713. var files1 = files.Where(x => !x.Equals(dto.fileName)).ToArray();
  11714. string filePath2 = string.Empty;
  11715. if (files1.Length > 0)
  11716. {
  11717. filePath2 = JsonConvert.SerializeObject(files1);
  11718. }
  11719. id = await _sqlSugar.Updateable<Grp_InvitationOfficialActivities>()
  11720. .Where(a => a.Id == dto.Id)
  11721. .SetColumns(a => new Grp_InvitationOfficialActivities { Attachment = filePath2 })
  11722. .ExecuteCommandAsync();
  11723. }
  11724. }
  11725. }
  11726. if (id != 0)
  11727. {
  11728. return Ok(JsonView(true, "成功!"));
  11729. }
  11730. else
  11731. {
  11732. return Ok(JsonView(false, "失败!"));
  11733. }
  11734. }
  11735. catch (Exception ex)
  11736. {
  11737. return Ok(JsonView(false, "程序错误!"));
  11738. throw;
  11739. }
  11740. }
  11741. /// <summary>
  11742. /// 文件上传多个文件 可以带参数
  11743. /// </summary>
  11744. /// <param name="files"></param>
  11745. /// <returns></returns>
  11746. [HttpPost]
  11747. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11748. public async Task<IActionResult> UploadProjects(IFormFile[] files)
  11749. {
  11750. try
  11751. {
  11752. var TypeName = Request.Headers["TypeName"].ToString();
  11753. if (string.IsNullOrEmpty(TypeName)) return Ok(JsonView(false, "请选择选组对应模块!"));
  11754. if (files.Length < 1) return Ok(JsonView(false, "请选择文件!"));
  11755. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  11756. var filePahts = new List<string>();
  11757. foreach (var file in files)
  11758. {
  11759. //文件名称
  11760. string projectFileName = file.FileName;
  11761. //上传的文件的路径
  11762. string filePath = $"{fileDir}/{projectFileName}";
  11763. if (TypeName == "A")//A代表团组增减款项
  11764. {
  11765. if (!Directory.Exists(fileDir))
  11766. {
  11767. Directory.CreateDirectory(fileDir);
  11768. }
  11769. //上传的文件的路径
  11770. filePath = fileDir + $@"\团组增减款项相关文件\{projectFileName}";
  11771. }
  11772. else if (TypeName == "B")//B代表商邀相关文件
  11773. {
  11774. if (!Directory.Exists(fileDir))
  11775. {
  11776. Directory.CreateDirectory(fileDir);
  11777. }
  11778. //上传的文件的路径
  11779. filePath = fileDir + $@"\商邀相关文件\{projectFileName}";
  11780. }
  11781. using (FileStream fs = System.IO.File.Create(filePath))
  11782. {
  11783. file.CopyTo(fs);
  11784. fs.Flush();
  11785. }
  11786. filePahts.Add(projectFileName);
  11787. }
  11788. return Ok(JsonView(true, "上传成功!", filePahts));
  11789. }
  11790. catch (Exception ex)
  11791. {
  11792. return Ok(JsonView(false, ex.Message));
  11793. }
  11794. }
  11795. #endregion
  11796. #region 商邀费用录入
  11797. /// <summary>
  11798. /// 根据团组Id查询商邀费用列表
  11799. /// </summary>
  11800. /// <param name="dto"></param>
  11801. /// <returns></returns>
  11802. [HttpPost]
  11803. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11804. public async Task<IActionResult> InvitationOfficialActivitiesList(InvitationOfficialActivitiesListDto dto)
  11805. {
  11806. Result groupData = await _InvitationOfficialActivitiesRep.InvitationOfficialActivitiesList(dto);
  11807. if (groupData.Code != 0)
  11808. {
  11809. return Ok(JsonView(false, groupData.Msg));
  11810. }
  11811. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  11812. }
  11813. /// <summary>
  11814. /// 商邀费用列表
  11815. /// 下载文件
  11816. /// </summary>
  11817. /// <param name="id"></param>
  11818. /// <returns></returns>
  11819. [HttpGet("{id}")]
  11820. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11821. public async Task<IActionResult> InvitationOfficialActivitiesListDownFile(int id)
  11822. {
  11823. if (id < 1) return Ok(JsonView(false, "请传入有效的Id!"));
  11824. var info = await _InvitationOfficialActivitiesRep.Query(x => x.Id == id).FirstAsync();
  11825. if (info == null) return Ok(JsonView(false, "数据不存在!"));
  11826. if (string.IsNullOrEmpty(info.Attachment)) return Ok(JsonView(false, "文件不存在!"));
  11827. var filePaths = new List<string>();
  11828. var filePathBase = @$"{AppSettingsHelper.Get("GrpFileBasePath")}/商邀相关文件/";
  11829. try
  11830. {
  11831. filePaths = JsonConvert.DeserializeObject<List<string>>(info.Attachment);
  11832. }
  11833. catch (Exception ex)
  11834. {
  11835. filePaths.Add(info.Attachment);
  11836. }
  11837. if (filePaths != null && filePaths.Count < 1) return Ok(JsonView(false, "文件不存在!"));
  11838. for (int i = 0; i < filePaths.Count; i++)
  11839. {
  11840. filePaths[i] = $"{filePathBase}{filePaths[i]}";
  11841. }
  11842. var zipFilePathGuid = $"{Guid.NewGuid()}.zip";
  11843. var zipFilePath = $"{AppSettingsHelper.Get("GrpFileBasePath")}/商邀相关文件/{zipFilePathGuid}";
  11844. using (var zipFileStream = new FileStream(zipFilePath, FileMode.Create))
  11845. {
  11846. using (var zipArchive = new ZipArchive(zipFileStream, ZipArchiveMode.Create))
  11847. {
  11848. foreach (string filePath in filePaths)
  11849. {
  11850. if (System.IO.File.Exists(filePath))
  11851. {
  11852. // 获取文件名
  11853. string fileName = Path.GetFileName(filePath);
  11854. // 将文件添加到ZIP归档中
  11855. zipArchive.CreateEntryFromFile(filePath, fileName);
  11856. }
  11857. }
  11858. }
  11859. }
  11860. return Ok(JsonView(new { url = @$"{AppSettingsHelper.Get("OfficeBaseUrl")}{AppSettingsHelper.Get("GrpFileFtpPath")}/商邀相关文件/{zipFilePathGuid}" }));
  11861. }
  11862. /// <summary>
  11863. /// 商邀费用 Info Page 基础数据源
  11864. /// </summary>
  11865. /// <returns></returns>
  11866. [HttpPost]
  11867. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11868. public async Task<IActionResult> InvitationOfficialActivityInitBasicData()
  11869. {
  11870. try
  11871. {
  11872. Result groupData = await _InvitationOfficialActivitiesRep.InitBasicData();
  11873. if (groupData.Code != 0)
  11874. {
  11875. return Ok(JsonView(false, groupData.Msg));
  11876. }
  11877. return Ok(JsonView(true, "操作成功", groupData.Data));
  11878. }
  11879. catch (Exception ex)
  11880. {
  11881. return Ok(JsonView(false, ex.Message));
  11882. throw;
  11883. }
  11884. }
  11885. /// <summary>
  11886. /// 根据商邀费用ID查询C表和商邀费用数据
  11887. /// </summary>
  11888. /// <param name="dto"></param>
  11889. /// <returns></returns>
  11890. [HttpPost]
  11891. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11892. public async Task<IActionResult> InvitationOfficialActivitiesById(InvitationOfficialActivitiesByIdDto dto)
  11893. {
  11894. try
  11895. {
  11896. Result groupData = await _InvitationOfficialActivitiesRep.InvitationOfficialActivitiesById(dto);
  11897. if (groupData.Code != 0)
  11898. {
  11899. return Ok(JsonView(false, groupData.Msg));
  11900. }
  11901. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  11902. }
  11903. catch (Exception ex)
  11904. {
  11905. return Ok(JsonView(false, ex.Message));
  11906. throw;
  11907. }
  11908. }
  11909. /// <summary>
  11910. /// 商邀费用录入操作(Status:1.新增,2.修改)
  11911. /// </summary>
  11912. /// <param name="dto"></param>
  11913. /// <returns></returns>
  11914. [HttpPost]
  11915. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11916. public async Task<IActionResult> OpInvitationOfficialActivities(OpInvitationOfficialActivitiesDto dto)
  11917. {
  11918. //验证
  11919. if (dto.Status == 2)
  11920. {
  11921. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 81);
  11922. if (!valid) return Ok(JsonView(false, msg));
  11923. }
  11924. Result groupData = await _InvitationOfficialActivitiesRep.OpInvitationOfficialActivities(dto, _setDataRep.PostCurrencyByDiid);
  11925. if (groupData.Code != 0)
  11926. {
  11927. return Ok(JsonView(false, groupData.Msg));
  11928. }
  11929. #region 应用推送
  11930. try
  11931. {
  11932. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  11933. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  11934. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  11935. //2024-10-21 新增LZ UID
  11936. var userIds = new List<int>() { 21 };
  11937. string title = $"系统通知";
  11938. string content = "";
  11939. var diId = dto.DiId;
  11940. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  11941. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  11942. if (dto.Status == 1) content = $"[新增-商邀费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  11943. else if (dto.Status == 2) content = $"[更新-商邀费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  11944. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  11945. var h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "81" };
  11946. await APNsTools.iOS_PushNotifications1("051", $"商邀费用审核", "", content, true, "ExpenseAuditWebView", h5);
  11947. }
  11948. catch (Exception ex)
  11949. {
  11950. }
  11951. #endregion
  11952. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  11953. }
  11954. /// <summary>
  11955. /// 商邀删除
  11956. /// </summary>
  11957. /// <param name="dto"></param>
  11958. /// <returns></returns>
  11959. [HttpPost]
  11960. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11961. public async Task<IActionResult> DelInvitationOfficialActivities(DelBaseDto dto)
  11962. {
  11963. try
  11964. {
  11965. //验证
  11966. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 81);
  11967. if (!valid) return Ok(JsonView(false, msg));
  11968. _sqlSugar.BeginTran();
  11969. var res1 = _sqlSugar.Updateable<Grp_InvitationOfficialActivities>()
  11970. .SetColumns(it => new Grp_InvitationOfficialActivities()
  11971. {
  11972. IsDel = 1,
  11973. DeleteUserId = dto.DeleteUserId,
  11974. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  11975. })
  11976. .Where(it => it.Id == dto.Id)
  11977. .ExecuteCommand();
  11978. if (res1 > 0)
  11979. {
  11980. int _diId = 0;
  11981. var _ioaInfo = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(it => it.Id == dto.Id).First();
  11982. if (_ioaInfo != null)
  11983. {
  11984. _diId = _ioaInfo.DiId;
  11985. }
  11986. var res2 = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  11987. .SetColumns(a => new Grp_CreditCardPayment()
  11988. {
  11989. IsDel = 1,
  11990. DeleteUserId = dto.DeleteUserId,
  11991. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  11992. })
  11993. .Where(a => a.CId == dto.Id && a.DIId == _diId && a.CTable == 81)
  11994. .ExecuteCommand();
  11995. if (res2 > 0)
  11996. {
  11997. _sqlSugar.CommitTran();
  11998. return Ok(JsonView(true, "删除成功!"));
  11999. }
  12000. }
  12001. _sqlSugar.RollbackTran();
  12002. return Ok(JsonView(false, "删除失败"));
  12003. }
  12004. catch (Exception ex)
  12005. {
  12006. _sqlSugar.RollbackTran();
  12007. return Ok(JsonView(false, ex.Message));
  12008. }
  12009. }
  12010. #endregion
  12011. #region 商邀Ai
  12012. /// <summary>
  12013. /// 请示文件生成
  12014. /// </summary>
  12015. /// <param name="dto"></param>
  12016. /// <returns></returns>
  12017. [HttpPost]
  12018. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12019. public async Task<IActionResult> BusinessInvitationInstructionsFile(BusinessInvitationInstructionsFileDto dto)
  12020. {
  12021. var jw = JsonView(false);
  12022. if (dto.Diid < 1)
  12023. {
  12024. jw.Msg = "团组Id不能为空!";
  12025. return Ok(jw);
  12026. }
  12027. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.IsDel == 0 && x.Id == dto.Diid);
  12028. if (groupInfo == null)
  12029. {
  12030. jw.Msg = "团组信息不存在!";
  12031. return Ok(jw);
  12032. }
  12033. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  12034. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  12035. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  12036. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.Diid)
  12037. .Select((tcl, dc, cc) => new ClientInfo
  12038. {
  12039. LastName = dc.LastName,
  12040. FirstName = dc.FirstName,
  12041. Sex = dc.Sex,
  12042. Birthday = dc.BirthDay,
  12043. Company = cc.CompanyFullName,
  12044. Job = dc.Job
  12045. })
  12046. .ToList();
  12047. foreach (var item in DeleClientList)
  12048. {
  12049. EncryptionProcessor.DecryptProperties(item);
  12050. }
  12051. if (!DeleClientList.Any())
  12052. {
  12053. jw.Msg = "团组客户信息不存在!";
  12054. return Ok(jw);
  12055. }
  12056. var travelList = await _sqlSugar.Queryable<Grp_ApprovalTravel>()
  12057. .LeftJoin<Grp_ApprovalTravelDetails>((x, a) => x.Id == a.ParentId && a.IsDel == 0)
  12058. .Where((x, a) => x.IsDel == 0 && x.Diid == dto.Diid)
  12059. .Select((x, a) => new
  12060. {
  12061. 日期 = x.Date,
  12062. 具体时间 = a.Time,
  12063. 行程安排 = a.Details,
  12064. 数据id = a.Id,
  12065. })
  12066. .ToListAsync();
  12067. if (!travelList.Any())
  12068. {
  12069. jw.Msg = "团组行程信息不存在!";
  12070. return Ok(jw);
  12071. }
  12072. string chat = string.Empty;
  12073. var templateSetting = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == 1550 && x.IsDel == 0);
  12074. if (templateSetting != null && !string.IsNullOrEmpty(templateSetting.Remark))
  12075. {
  12076. var stringFormatResp = await GeneralMethod.StringFormatAsync(new StringFormatDto
  12077. {
  12078. FormatTemplate = templateSetting.Remark,
  12079. Parameters = new List<string> {
  12080. JsonConvert.SerializeObject(DeleClientList),
  12081. JsonConvert.SerializeObject(travelList)
  12082. }
  12083. });
  12084. if (stringFormatResp.Success)
  12085. {
  12086. chat = stringFormatResp.FormattedResult;
  12087. }
  12088. else
  12089. {
  12090. jw.Msg = "对话内容模板格式化失败! templateSetting.Id: " + templateSetting.Id + ",错误:" + stringFormatResp.Message;
  12091. return Ok(jw);
  12092. }
  12093. }
  12094. else
  12095. {
  12096. jw.Msg = "获取对话内容模板失败! templateSetting.Id: " + templateSetting.Id;
  12097. return Ok(jw);
  12098. }
  12099. //Console.WriteLine(chat);
  12100. // var chatResult = await _doubaoService.CompleteChatAsync(new List<DouBaoChatMessage> { new DouBaoChatMessage { Role = DouBaoRole.user, Content = chat } });
  12101. var apiResp = await _deepSeekService.ChatAsync(chat, false, "deepseek-reasoner", 0.7f, 60000);
  12102. var chatResult = apiResp.Answer;
  12103. if (string.IsNullOrEmpty(chatResult))
  12104. {
  12105. jw.Msg = "请示文件生成失败!";
  12106. return Ok(jw);
  12107. }
  12108. string outputPath = $"{AppSettingsHelper.Get("GrpFileBasePath")}/商邀相关文件/{groupInfo.TeamName}请示文件.docx";
  12109. string json = chatResult;
  12110. byte[] wordBytes = JsonToWordHelper.ConvertJsonToWord(json);
  12111. System.IO.File.WriteAllBytes(outputPath, wordBytes);
  12112. //WordExporter.MarkdownToWord(chatResult, outputPath);
  12113. string url = outputPath.Replace(AppSettingsHelper.Get("GrpFileBasePath"), AppSettingsHelper.Get("GrpFileBaseUrl") + AppSettingsHelper.Get("GrpFileFtpPath"));
  12114. return Ok(JsonView(true, "请示文件生成成功!", url));
  12115. }
  12116. /// <summary>
  12117. /// 请示文件内容生成 (AI 流式输出)。响应体为 NDJSON:每行 <c>{"phase":"reasoning"|"content","text":"..."}</c>,分别对应思考过程与正式结果。
  12118. /// </summary>
  12119. /// <param name="dto"></param>
  12120. /// <returns></returns>
  12121. [HttpPost]
  12122. public async Task<IActionResult> BusinessInvitationInstructionsFileContentStream([FromBody] BusinessInvitationInstructionsFileDto dto, CancellationToken cancellationToken = default)
  12123. {
  12124. if (dto.Diid < 1)
  12125. {
  12126. Response.ContentType = "text/plain; charset=utf-8";
  12127. await Response.WriteAsync("团组Id不能为空!");
  12128. return new EmptyResult();
  12129. }
  12130. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.IsDel == 0 && x.Id == dto.Diid);
  12131. if (groupInfo == null)
  12132. {
  12133. Response.ContentType = "text/plain; charset=utf-8";
  12134. await Response.WriteAsync("团组信息不存在!");
  12135. return new EmptyResult();
  12136. }
  12137. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  12138. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  12139. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  12140. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.Diid)
  12141. .Select((tcl, dc, cc) => new ClientInfo
  12142. {
  12143. LastName = dc.LastName,
  12144. FirstName = dc.FirstName,
  12145. Sex = dc.Sex,
  12146. Birthday = dc.BirthDay,
  12147. Company = cc.CompanyFullName,
  12148. Job = dc.Job
  12149. })
  12150. .ToList();
  12151. foreach (var item in DeleClientList)
  12152. {
  12153. EncryptionProcessor.DecryptProperties(item);
  12154. }
  12155. if (!DeleClientList.Any())
  12156. {
  12157. Response.ContentType = "text/plain; charset=utf-8";
  12158. await Response.WriteAsync("团组客户信息不存在!");
  12159. return new EmptyResult();
  12160. }
  12161. var travelList = await _sqlSugar.Queryable<Grp_ApprovalTravel>()
  12162. .LeftJoin<Grp_ApprovalTravelDetails>((x, a) => x.Id == a.ParentId && a.IsDel == 0)
  12163. .Where((x, a) => x.IsDel == 0 && x.Diid == dto.Diid)
  12164. .Select((x, a) => new
  12165. {
  12166. 日期 = x.Date,
  12167. 具体时间 = a.Time,
  12168. 行程安排 = a.Details,
  12169. 数据id = a.Id,
  12170. })
  12171. .ToListAsync();
  12172. if (!travelList.Any())
  12173. {
  12174. Response.ContentType = "text/plain; charset=utf-8";
  12175. await Response.WriteAsync("团组行程信息不存在!");
  12176. return new EmptyResult();
  12177. }
  12178. string chat = string.Empty;
  12179. var templateSetting = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == 1550 && x.IsDel == 0);
  12180. if (templateSetting != null && !string.IsNullOrEmpty(templateSetting.Remark))
  12181. {
  12182. var stringFormatResp = await GeneralMethod.StringFormatAsync(new StringFormatDto
  12183. {
  12184. FormatTemplate = templateSetting.Remark,
  12185. Parameters = new List<string> {
  12186. JsonConvert.SerializeObject(DeleClientList),
  12187. JsonConvert.SerializeObject(travelList)
  12188. }
  12189. });
  12190. if (stringFormatResp.Success)
  12191. {
  12192. chat = stringFormatResp.FormattedResult;
  12193. }
  12194. else
  12195. {
  12196. Response.ContentType = "text/plain; charset=utf-8";
  12197. await Response.WriteAsync("对话内容模板格式化失败! templateSetting.Id: " + templateSetting.Id + ",错误:" + stringFormatResp.Message);
  12198. return new EmptyResult();
  12199. }
  12200. }
  12201. else
  12202. {
  12203. Response.ContentType = "text/plain; charset=utf-8";
  12204. await Response.WriteAsync("获取对话内容模板失败! templateSetting.Id: " + (templateSetting?.Id.ToString() ?? "无"));
  12205. return new EmptyResult();
  12206. }
  12207. //Console.WriteLine(chat);
  12208. Response.ContentType = "application/x-ndjson; charset=utf-8";
  12209. Response.Headers["Cache-Control"] = "no-cache";
  12210. string NdjsonLine(DeepSeekStreamChunk c) => JsonConvert.SerializeObject(new
  12211. {
  12212. phase = c.Phase == DeepSeekStreamPhase.Reasoning ? "reasoning" : "content",
  12213. text = c.Text
  12214. });
  12215. try
  12216. {
  12217. cancellationToken.ThrowIfCancellationRequested();
  12218. await foreach (var chunk in _deepSeekService.ChatStreamAsync(chat, "deepseek-reasoner", 0.7f, 60000))
  12219. {
  12220. await Response.WriteAsync(NdjsonLine(chunk) + "\n");
  12221. await Response.Body.FlushAsync();
  12222. }
  12223. await Response.WriteAsync(JsonConvert.SerializeObject(new { phase = "success", text = "结束" }) + "\n");
  12224. await Response.Body.FlushAsync(cancellationToken);
  12225. }
  12226. catch (Exception ex)
  12227. {
  12228. await Response.WriteAsync(JsonConvert.SerializeObject(new { phase = "error", text = ex.Message }) + "\n");
  12229. await Response.Body.FlushAsync(cancellationToken);
  12230. }
  12231. return new EmptyResult();
  12232. }
  12233. /// <summary>
  12234. /// 请示文件下载
  12235. /// </summary>
  12236. /// <param name="dto"></param>
  12237. /// <returns></returns>
  12238. [HttpPost]
  12239. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12240. public async Task<IActionResult> BusinessInvitationInstructionsFileDown(BusinessInvitationInstructionsFileDownDto dto)
  12241. {
  12242. var jw = JsonView(false);
  12243. var content = dto.Content;
  12244. var diid = dto.Diid;
  12245. if (string.IsNullOrEmpty(content))
  12246. {
  12247. jw.Msg = "请示文件内容不能为空!";
  12248. return Ok(jw);
  12249. }
  12250. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.IsDel == 0 && x.Id == diid);
  12251. if (groupInfo == null)
  12252. {
  12253. jw.Msg = "团组信息不存在!";
  12254. return Ok(jw);
  12255. }
  12256. string outputPath = $"{AppSettingsHelper.Get("GrpFileBasePath")}/商邀相关文件/{groupInfo.TeamName}请示文件.docx";
  12257. try
  12258. {
  12259. string json = content;
  12260. byte[] wordBytes = JsonToWordHelper.ConvertJsonToWord(json);
  12261. System.IO.File.WriteAllBytes(outputPath, wordBytes);
  12262. //WordExporter.MarkdownToWord(chatResult, outputPath);
  12263. string url = outputPath.Replace(AppSettingsHelper.Get("GrpFileBasePath"), AppSettingsHelper.Get("GrpFileBaseUrl") + AppSettingsHelper.Get("GrpFileFtpPath"));
  12264. return Ok(JsonView(true, "请示文件生成成功!", url));
  12265. }
  12266. catch (Exception ex)
  12267. {
  12268. jw.Msg = "请示文件生成失败!" + ex.Message;
  12269. return Ok(jw);
  12270. }
  12271. }
  12272. // [HttpPost("export-word")]
  12273. // public IActionResult ExportWord([FromBody] string json)
  12274. // {
  12275. // var bytes = JsonToWordHelper.ConvertJsonToWord(json);
  12276. // return File(
  12277. // bytes,
  12278. // "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
  12279. // "出访请示.docx");
  12280. // }
  12281. /// <summary>
  12282. /// 企业拜访内容续写
  12283. /// </summary>
  12284. /// <param name="dto"></param>
  12285. /// <returns></returns>
  12286. [HttpPost]
  12287. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12288. public async Task<IActionResult> BusinessEnterpriseContinueWrite(BusinessEnterpriseContinueWriteDto dto)
  12289. {
  12290. var jw = JsonView(false);
  12291. var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  12292. .Where(x => x.IsDel == 0 && x.Id == dto.Diid)
  12293. .FirstAsync();
  12294. var resultArr = new ArrayList();
  12295. var content = _sqlSugar.Queryable<Grp_ApprovalTravel>().Where(x => x.Diid == dto.Diid && x.IsDel == 0).ToList();
  12296. const int chiNumber = 5;
  12297. if (!content.Any())
  12298. {
  12299. jw.Msg = "团组行程信息不存在!";
  12300. return Ok(jw);
  12301. }
  12302. foreach (var x in content)
  12303. {
  12304. var chiList = _sqlSugar.Queryable<Grp_ApprovalTravelDetails>().Where(x1 => x1.ParentId == x.Id && x1.IsDel == 0).ToList();
  12305. if (chiList.Count < chiNumber)
  12306. {
  12307. for (int i = chiList.Count; i < chiNumber; i++)
  12308. {
  12309. chiList.Add(new Grp_ApprovalTravelDetails());
  12310. }
  12311. }
  12312. resultArr.Add(new
  12313. {
  12314. x.Id,
  12315. x.Date,
  12316. x.Diid,
  12317. chiList = chiList.Select(x1 => new
  12318. {
  12319. timeInterval = string.IsNullOrWhiteSpace(x1.Time) ? new string[1] : x1.Time.Split('-'),
  12320. x1.Details,
  12321. x1.ParentId,
  12322. x1.Id
  12323. })
  12324. });
  12325. }
  12326. string chat = string.Empty;
  12327. var templateSetting = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == 1554 && x.IsDel == 0);
  12328. if (templateSetting != null && !string.IsNullOrEmpty(templateSetting.Remark))
  12329. {
  12330. var stringFormatResp = await GeneralMethod.StringFormatAsync(new StringFormatDto
  12331. {
  12332. FormatTemplate = templateSetting.Remark,
  12333. Parameters = new List<string> {
  12334. JsonConvert.SerializeObject(resultArr),
  12335. di.ClientName
  12336. }
  12337. });
  12338. if (stringFormatResp.Success)
  12339. {
  12340. chat = stringFormatResp.FormattedResult;
  12341. }
  12342. else
  12343. {
  12344. jw.Msg = "对话内容模板格式化失败! templateSetting.Id: " + templateSetting.Id + ",错误:" + stringFormatResp.Message;
  12345. return Ok(jw);
  12346. }
  12347. }
  12348. else
  12349. {
  12350. jw.Msg = "获取对话内容模板失败! templateSetting.Id: " + templateSetting.Id;
  12351. return Ok(jw);
  12352. }
  12353. var apiResult = await _deepSeekService.ChatAsync(chat, false, "deepseek-reasoner", 0.7f, 60000);
  12354. var chatResult = apiResult.Answer;
  12355. if (string.IsNullOrEmpty(chatResult))
  12356. {
  12357. jw.Msg = "企业拜访内容续写失败!";
  12358. return Ok(jw);
  12359. }
  12360. chatResult = GeneralMethod.ExtractJson(chatResult);
  12361. var JsonResult = JsonDocument.Parse(chatResult);
  12362. return Ok(JsonView(true, "企业拜访内容续写成功!", new
  12363. {
  12364. chatResult,
  12365. JsonResult
  12366. }));
  12367. }
  12368. // [HttpPost]
  12369. // public object ToOjbect(ToOjbectDto dto)
  12370. // {
  12371. // return JsonDocument.Parse(dto.Value);
  12372. // }
  12373. /// <summary>
  12374. /// 行程单位安排
  12375. /// </summary>
  12376. /// <param name="dto"></param>
  12377. /// <returns></returns>
  12378. [HttpPost]
  12379. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12380. public async Task<IActionResult> BusinessSynchronizationWrite(BusinessSynchronizationWriteDto dto)
  12381. {
  12382. var jw = JsonView(false);
  12383. var travelList = await _sqlSugar.Queryable<Grp_ApprovalTravel>()
  12384. .LeftJoin<Grp_ApprovalTravelDetails>((x, a) => x.Id == a.ParentId && a.IsDel == 0)
  12385. .Where((x, a) => x.IsDel == 0 && x.Diid == dto.Diid)
  12386. .Select((x, a) => new
  12387. {
  12388. 日期 = x.Date,
  12389. 具体时间 = a.Time,
  12390. 行程安排 = a.Details,
  12391. 数据id = a.Id,
  12392. })
  12393. .ToListAsync();
  12394. if (!travelList.Any())
  12395. {
  12396. jw.Msg = "团组行程信息不存在!";
  12397. return Ok(jw);
  12398. }
  12399. if (dto.EnterpriseNames == null || dto.EnterpriseNames.Count == 0)
  12400. {
  12401. jw.Msg = "企业名称列表不能为空!";
  12402. return Ok(jw);
  12403. }
  12404. string chat = string.Empty;
  12405. var templateSetting = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == 1552 && x.IsDel == 0);
  12406. if (templateSetting != null && !string.IsNullOrEmpty(templateSetting.Remark))
  12407. {
  12408. var stringFormatResp = await GeneralMethod.StringFormatAsync(new StringFormatDto
  12409. {
  12410. FormatTemplate = templateSetting.Remark,
  12411. Parameters = new List<string> {
  12412. JsonConvert.SerializeObject(dto.EnterpriseNames),
  12413. JsonConvert.SerializeObject(travelList)
  12414. }
  12415. });
  12416. if (stringFormatResp.Success)
  12417. {
  12418. chat = stringFormatResp.FormattedResult;
  12419. }
  12420. else
  12421. {
  12422. jw.Msg = "对话内容模板格式化失败! templateSetting.Id: " + templateSetting.Id + ",错误:" + stringFormatResp.Message;
  12423. return Ok(jw);
  12424. }
  12425. }
  12426. else
  12427. {
  12428. jw.Msg = "获取对话内容模板失败! templateSetting.Id: " + templateSetting.Id;
  12429. return Ok(jw);
  12430. }
  12431. //var chatResult = await _doubaoService.CompleteChatAsync(new List<DouBaoChatMessage> { new DouBaoChatMessage { Role = DouBaoRole.user, Content = chat } });
  12432. var apiResp = await _deepSeekService.ChatAsync(chat, false, "deepseek-reasoner", 0.7f, 20000);
  12433. var chatResult = apiResp.Answer;
  12434. if (string.IsNullOrEmpty(chatResult))
  12435. {
  12436. jw.Msg = "报批日程安排失败!";
  12437. return Ok(jw);
  12438. }
  12439. chatResult = GeneralMethod.ExtractJson(chatResult);
  12440. var jsonResult = JsonConvert.DeserializeObject<List<Grp_ApprovalTravelDetails>>(chatResult);
  12441. if (!jsonResult.Any())
  12442. {
  12443. jw.Msg = "AI报批日程安排失败!";
  12444. return Ok(jw);
  12445. }
  12446. _sqlSugar.Updateable<Grp_ApprovalTravelDetails>(jsonResult)
  12447. .UpdateColumns(x => new { x.Details })
  12448. .ExecuteCommand();
  12449. return Ok(JsonView(true, "报批日程安排成功!", chatResult));
  12450. }
  12451. [HttpGet("chat-stream")]
  12452. public async Task ChatStream([FromQuery] string question)
  12453. {
  12454. Response.ContentType = "application/x-ndjson; charset=utf-8";
  12455. Response.Headers.CacheControl = "no-cache";
  12456. string NdjsonLine(DeepSeekStreamChunk c) => JsonConvert.SerializeObject(new
  12457. {
  12458. phase = c.Phase == DeepSeekStreamPhase.Reasoning ? "reasoning" : "content",
  12459. text = c.Text
  12460. });
  12461. await foreach (var chunk in _deepSeekService.ChatStreamAsync(question))
  12462. {
  12463. await Response.WriteAsync(NdjsonLine(chunk) + "\n");
  12464. await Response.Body.FlushAsync();
  12465. }
  12466. }
  12467. /// <summary>
  12468. /// 商邀Ai行程框架导出
  12469. /// </summary>
  12470. /// <param name="dto"></param>
  12471. /// <returns></returns>
  12472. [HttpPost]
  12473. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12474. public async Task<IActionResult> BusinessJourneyFileDown(BusinessJourneyFileDownDto dto)
  12475. {
  12476. var jw = JsonView(false);
  12477. var Find = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid);
  12478. if (Find == null)
  12479. {
  12480. jw.Msg = "请选择正确的团组!";
  12481. return Ok(jw);
  12482. }
  12483. var travelList = await _sqlSugar.Queryable<Grp_ApprovalTravel>()
  12484. .LeftJoin<Grp_ApprovalTravelDetails>((x, a) => x.Id == a.ParentId && a.IsDel == 0)
  12485. .Where((x, a) => x.IsDel == 0 && x.Diid == dto.Diid)
  12486. .Select((x, a) => new
  12487. {
  12488. 日期 = x.Date,
  12489. 具体时间 = a.Time,
  12490. 行程安排 = a.Details,
  12491. 数据id = a.Id,
  12492. })
  12493. .ToListAsync();
  12494. if (!travelList.Any())
  12495. {
  12496. jw.Msg = "团组行程信息不存在!";
  12497. return Ok(jw);
  12498. }
  12499. var groupTraveList = travelList
  12500. .Where(x => !string.IsNullOrWhiteSpace(x.行程安排))
  12501. .GroupBy(x => x.日期).ToList();
  12502. var grouopTraveListByStr = groupTraveList.ToDictionary(
  12503. x => x.Key,
  12504. x => string.Join("\r\n", x.Select(y => $"{y.具体时间} {y.行程安排}".Trim()))
  12505. );
  12506. var groupTraveListByKey = grouopTraveListByStr.Select(x => new
  12507. {
  12508. key = x.Key,
  12509. value = x.Value,
  12510. }
  12511. ).ToList();
  12512. var blackCode = await _sqlSugar.Queryable<Air_TicketBlackCode>()
  12513. .Where(x => x.IsDel == 0 && x.Id == dto.BlackCodeId)
  12514. .FirstAsync();
  12515. if (blackCode == null)
  12516. {
  12517. jw.Msg = "黑屏代码不存在!";
  12518. return Ok(jw);
  12519. }
  12520. string chat = string.Empty;
  12521. var templateSetting = await _sqlSugar
  12522. .Queryable<Sys_SetData>()
  12523. .FirstAsync(x => x.Id == 1553 && x.IsDel == 0);
  12524. if (templateSetting != null && !string.IsNullOrEmpty(templateSetting.Remark))
  12525. {
  12526. var stringFormatResp = await GeneralMethod.StringFormatAsync(new StringFormatDto
  12527. {
  12528. FormatTemplate = templateSetting.Remark,
  12529. Parameters = new List<string> {
  12530. JsonConvert.SerializeObject(groupTraveListByKey),
  12531. blackCode.BlackCode,
  12532. }
  12533. });
  12534. if (stringFormatResp.Success)
  12535. {
  12536. chat = stringFormatResp.FormattedResult;
  12537. }
  12538. else
  12539. {
  12540. jw.Msg = "对话内容模板格式化失败! templateSetting.Id: " + templateSetting.Id + ",错误:" + stringFormatResp.Message;
  12541. return Ok(jw);
  12542. }
  12543. }
  12544. else
  12545. {
  12546. jw.Msg = "获取对话内容模板失败! templateSetting.Id: " + templateSetting.Id;
  12547. return Ok(jw);
  12548. }
  12549. // var chatResult = await _doubaoService.CompleteChatAsync(new List<DouBaoChatMessage> { new DouBaoChatMessage { Role = DouBaoRole.user, Content = chat } });
  12550. var apiResp = await _deepSeekService.ChatAsync(chat, false, "deepseek-reasoner", 0.7f, 40000);
  12551. var chatResult = apiResp.Answer;
  12552. if (string.IsNullOrEmpty(chatResult))
  12553. {
  12554. jw.Msg = "行程框架导出失败!";
  12555. return Ok(jw);
  12556. }
  12557. chatResult = GeneralMethod.ExtractJson(chatResult);
  12558. var _travelList = new List<TravelPlan>();
  12559. try
  12560. {
  12561. var jsonResult = JsonConvert.DeserializeObject<List<TravelPlan>>(chatResult);
  12562. _travelList = jsonResult;
  12563. }
  12564. catch (Exception ex)
  12565. {
  12566. jw.Msg = "AI行程框架导出失败!(JSON转换失败!)";
  12567. return Ok(jw);
  12568. }
  12569. //创建数据源Table
  12570. var dtSource = new DataTable();
  12571. dtSource.Columns.Add("Days", typeof(string));
  12572. dtSource.Columns.Add("Date", typeof(string));
  12573. dtSource.Columns.Add("Week", typeof(string));
  12574. dtSource.Columns.Add("Traffic", typeof(string));
  12575. dtSource.Columns.Add("Trip", typeof(string));
  12576. var days = 1;
  12577. //获取数据,放到datatable
  12578. foreach (var item in _travelList)
  12579. {
  12580. DataRow dr = dtSource.NewRow();
  12581. dr["Days"] = days;
  12582. dr["Date"] = item.Date;
  12583. dr["Week"] = item.WeekDay;
  12584. dr["Traffic"] = string.Join("\r\n", item.Traffic);
  12585. dr["Trip"] = item.Trip;
  12586. dtSource.Rows.Add(dr);
  12587. days++;
  12588. }
  12589. var dic = new Dictionary<string, string>
  12590. {
  12591. { "Dele", Find.TeamName.ToString() + GetNum(Find.VisitDays.ToString()) },
  12592. { "City", GeneralMethod.GetGroupCityLine(dto.Diid, "/") },
  12593. { "Days", Find.VisitDays.ToString() },
  12594. { "DeleCode", Find.TourCode },
  12595. { "Pnum", Find.VisitPNumber.ToString() }
  12596. };
  12597. //模板路径
  12598. string tempPath = AppSettingsHelper.Get("WordBasePath") + "Travel/日行程3.docx";
  12599. //载入模板
  12600. Document doc = null;
  12601. DocumentBuilder builder = null;
  12602. try
  12603. {
  12604. //载入模板
  12605. doc = new Document(tempPath);
  12606. builder = new DocumentBuilder(doc);
  12607. }
  12608. catch (Exception)
  12609. {
  12610. jw.Msg = "模板位置不存在!";
  12611. return Ok(jw);
  12612. }
  12613. foreach (var key in dic.Keys)
  12614. {
  12615. Bookmark bookmark = doc.Range.Bookmarks[key];
  12616. if (bookmark != null)
  12617. {
  12618. builder.MoveToBookmark(key);
  12619. builder.Write(dic[key]);
  12620. }
  12621. }
  12622. //获取word里所有表格
  12623. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  12624. //获取所填表格的序数
  12625. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  12626. try
  12627. {
  12628. //循环赋值
  12629. for (int i = 0; i < dtSource.Rows.Count; i++)
  12630. {
  12631. builder.MoveToCell(0, i + 1, 0, 0);
  12632. builder.Write(dtSource.Rows[i]["Days"].ToString());
  12633. builder.MoveToCell(0, i + 1, 1, 0);
  12634. builder.Write(dtSource.Rows[i]["Date"].ToString() + "\r\n" + dtSource.Rows[i]["Week"].ToString());
  12635. builder.MoveToCell(0, i + 1, 2, 0);
  12636. builder.Write(dtSource.Rows[i]["Traffic"].ToString());
  12637. var trip = dtSource.Rows[i]["Trip"].ToString();
  12638. builder.MoveToCell(0, i + 1, 3, 0);
  12639. builder.Write(trip);
  12640. var cell = (Aspose.Words.Tables.Cell)doc.GetChild(NodeType.Cell, ((i + 2) * 4) - 1, true);
  12641. var paragraphs = cell.GetChildNodes(NodeType.Paragraph, true);
  12642. // 获取特定索引的段落
  12643. Paragraph paragraph = (Paragraph)paragraphs[0];
  12644. Run run = paragraph.Runs[0];
  12645. Aspose.Words.Font font = run.Font;
  12646. font.Name = "黑体";
  12647. //设置双休红色
  12648. cell = (Aspose.Words.Tables.Cell)doc.GetChild(NodeType.Cell, ((i + 2) * 4) - 3, true);
  12649. paragraphs = cell.GetChildNodes(NodeType.Paragraph, true);
  12650. paragraph = (Paragraph)paragraphs[1];
  12651. if (paragraph.GetText().Contains("星期六") || paragraph.GetText().Contains("星期日"))
  12652. {
  12653. run = paragraph.Runs[0];
  12654. font = run.Font;
  12655. font.Color = Color.Red;
  12656. }
  12657. }
  12658. }
  12659. catch (Exception ex)
  12660. {
  12661. }
  12662. //删除多余行
  12663. while (tableOne.Rows.Count > 1 + dtSource.Rows.Count)
  12664. {
  12665. tableOne.Rows.RemoveAt(1 + dtSource.Rows.Count);//(1+dtSource.Rows.Count + 1)-1
  12666. }
  12667. string savePath = AppSettingsHelper.Get("WordBasePath") + "Travel/export/";
  12668. if (!Directory.Exists(savePath))
  12669. {
  12670. try
  12671. {
  12672. Directory.CreateDirectory(savePath);
  12673. }
  12674. catch
  12675. {
  12676. }
  12677. }
  12678. string path = savePath + Find.TeamName + "出访日程";
  12679. string ftpPath = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + "Travel/export/" + Find.TeamName + "出访日程";
  12680. try
  12681. {
  12682. Aspose.Words.SaveFormat saveFormat = Aspose.Words.SaveFormat.Doc;
  12683. string postfix = ".docx";
  12684. doc.Save(path + postfix, saveFormat);
  12685. jw = JsonView(true, "导出成功", ftpPath + postfix);
  12686. }
  12687. catch (Exception ex)
  12688. {
  12689. jw = JsonView(false, $"导出失败! ({ex.Message}) ");
  12690. }
  12691. return Ok(jw);
  12692. }
  12693. #endregion
  12694. #region 票据上传
  12695. /// <summary>
  12696. /// 团组模块文件上传
  12697. /// </summary>
  12698. /// <param name="dto"></param>
  12699. /// <returns></returns>
  12700. [HttpPost]
  12701. public IActionResult CommonSaveFile([FromForm] CommonSaveFileDto dto)
  12702. {
  12703. var jw = JsonView(false);
  12704. long M = 1024 * 1024;
  12705. if (dto.Files == null || dto.Files.Count == 0)
  12706. {
  12707. jw.Msg = "无文件信息!";
  12708. return Ok(jw);
  12709. }
  12710. if (dto.Files.Sum(x => x.Length) > 20 * M)
  12711. {
  12712. jw.Msg = "文件大小超过20M!";
  12713. return Ok(jw);
  12714. }
  12715. //var nameSp = dto.File.FileName.Split(".");
  12716. //if (nameSp.Length < 2)
  12717. //{
  12718. // jw.Msg = "拓展名称有误!";
  12719. // return Ok(jw);
  12720. //}
  12721. //var existsName = new string[]{ "RAR", "ZIP", "ARJ","GZ","Z","7Z","TAR" };
  12722. //if (!existsName.Contains(nameSp[1].ToUpper()))
  12723. //{
  12724. // jw.Msg = $"请使用指定拓展名!({string.Join("-",existsName)})";
  12725. // return Ok(jw);
  12726. //}
  12727. var Ctable = _sqlSugar.Queryable<Sys_SetData>().First(x => x.STid == 16 && x.IsDel == 0 && x.Id == dto.Ctable);
  12728. if (Ctable == null)
  12729. {
  12730. jw.Msg = "Ctable指向有误!";
  12731. return Ok(jw);
  12732. }
  12733. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  12734. if (groupInfo == null)
  12735. {
  12736. jw.Msg = "团组信息不存在!";
  12737. return Ok(jw);
  12738. }
  12739. Ctable.Name = Regex.Replace(Ctable.Name, @"[^\w\.@-]", "",
  12740. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  12741. groupInfo.TeamName = Regex.Replace(groupInfo.TeamName, @"[^\w\.@-]", "",
  12742. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  12743. var path = "\\GroupModelFiles\\" + groupInfo.TeamName + "\\" + Ctable.Name;
  12744. var fileBase = AppSettingsHelper.Get("GrpFileBasePath") + path;
  12745. try
  12746. {
  12747. if (!Directory.Exists(fileBase))
  12748. {
  12749. Directory.CreateDirectory(fileBase);
  12750. }
  12751. var saveArr = new List<Grp_GroupModelFile>();
  12752. foreach (var fileStream in dto.Files)
  12753. {
  12754. var fileName = fileStream.FileName;
  12755. string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
  12756. string extension = Path.GetExtension(fileName);
  12757. int counter = 0;
  12758. //文件重命名验证
  12759. string newFilePath;
  12760. string currFileName;
  12761. do
  12762. {
  12763. string newFileName;
  12764. if (counter == 0) newFileName = $"{fileNameWithoutExtension}{extension}";
  12765. else newFileName = $"{fileNameWithoutExtension} ({counter}){extension}";
  12766. currFileName = newFileName;
  12767. newFilePath = Path.Combine(fileBase, newFileName);
  12768. counter++;
  12769. } while (System.IO.File.Exists(newFilePath));
  12770. var saveFilePath = fileBase + "\\" + currFileName;
  12771. var file = new Grp_GroupModelFile()
  12772. {
  12773. Cid = dto.Cid,
  12774. CreateTime = DateTime.Now,
  12775. CreateUserId = dto.Userid,
  12776. Ctable = dto.Ctable,
  12777. Diid = dto.Diid,
  12778. IsDel = 0,
  12779. FilePath = saveFilePath,
  12780. FileName = currFileName
  12781. };
  12782. using (FileStream fs = System.IO.File.Create(saveFilePath))
  12783. {
  12784. fileStream.CopyTo(fs);
  12785. fs.Flush();
  12786. }
  12787. saveArr.Add(file);
  12788. }
  12789. var addResult = _sqlSugar.Insertable<Grp_GroupModelFile>(saveArr).ExecuteCommand();
  12790. //url = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("GrpFileFtpPath") + path + "\\" + dto.File.FileName
  12791. jw = JsonView(true, "保存成功!", new
  12792. {
  12793. count = addResult,
  12794. filesName = saveArr.Select(x => x.FileName)
  12795. });
  12796. }
  12797. catch (Exception ex)
  12798. {
  12799. jw = JsonView(false, $"保存失败! ({ex.Message}) ", new
  12800. {
  12801. count = 0,
  12802. filesName = Array.Empty<string>(),
  12803. });
  12804. }
  12805. return Ok(jw);
  12806. }
  12807. /// <summary>
  12808. /// 查询各模块已保存文件
  12809. /// </summary>
  12810. /// <param name="dto"></param>
  12811. /// <returns></returns>
  12812. [HttpPost]
  12813. public IActionResult QueryGroupModelFile(QueryGroupModelFileDto dto)
  12814. {
  12815. var expression = Expressionable.Create<Grp_GroupModelFile>()
  12816. .AndIF(dto.UserId != -1, x => x.CreateUserId == dto.UserId);
  12817. var visaIds = _sqlSugar.Queryable<Sys_Users>().Where(x => x.JobPostId == 26).Select(x => x.Id).ToList();
  12818. if (visaIds.Contains(dto.UserId) && dto.Ctable == 80)
  12819. {
  12820. expression = Expressionable.Create<Grp_GroupModelFile>()
  12821. .And(x => visaIds.Contains(x.CreateUserId));
  12822. }
  12823. var dbQuery = _sqlSugar.Queryable<Grp_GroupModelFile>()
  12824. .Where(x => x.IsDel == 0 && x.Cid == dto.Cid && x.Ctable == dto.Ctable && x.Diid == dto.Diid)
  12825. .Where(expression.ToExpression())
  12826. .ToList();
  12827. //.ToPageList(pagenumber, pageSize, ref totalCount, ref totalPage)
  12828. return Ok(JsonView(true, "success", dbQuery.Select(x => new
  12829. {
  12830. x.FileName,
  12831. x.Id,
  12832. Url = AppSettingsHelper.Get("GrpFileBaseUrl") + x.FilePath.Replace(AppSettingsHelper.Get("GrpFileBasePath"), AppSettingsHelper.Get("GrpFileFtpPath")),
  12833. CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH-mm"),
  12834. })));
  12835. }
  12836. /// <summary>
  12837. /// 下载该团组下的所有文件
  12838. /// </summary>
  12839. /// <param name="dto"></param>
  12840. /// <returns></returns>
  12841. [HttpPost]
  12842. public IActionResult ExportGroupZip(ExportGroupZipDto dto)
  12843. {
  12844. var jw = JsonView(false);
  12845. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.IsDel == 0 && x.Id == dto.Diid);
  12846. if (groupInfo == null)
  12847. {
  12848. jw.Msg = "团组信息不存在!";
  12849. return Ok(jw);
  12850. }
  12851. var dbQuery = _sqlSugar.Queryable<Grp_GroupModelFile>().Where(x => x.IsDel == 0 && x.Diid == dto.Diid).ToList();
  12852. var isModule = Convert.ToBoolean(dto.isModule);
  12853. var Zips = new Dictionary<string, Stream>();
  12854. var io = new IOOperatorHelper();
  12855. if (isModule)
  12856. {
  12857. var moduleGroup = dbQuery.GroupBy(x => x.Ctable);
  12858. foreach (var moduleArr in moduleGroup)
  12859. {
  12860. var key = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == moduleArr.Key && x.IsDel == 0);
  12861. key.Name = Regex.Replace(key.Name, @"[^\w\.@-]", "",
  12862. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  12863. var chiZips = new Dictionary<string, Stream>();
  12864. foreach (var item in moduleArr)
  12865. {
  12866. if (System.IO.File.Exists(item.FilePath))
  12867. {
  12868. using (var fileStream = new FileStream(item.FilePath, FileMode.Open, FileAccess.Read))
  12869. {
  12870. byte[] bytes = new byte[fileStream.Length];
  12871. fileStream.Read(bytes, 0, bytes.Length);
  12872. fileStream.Close();
  12873. Stream stream = new MemoryStream(bytes);
  12874. chiZips.Add(item.FileName, stream);
  12875. }
  12876. }
  12877. }
  12878. if (chiZips.Count > 0)
  12879. {
  12880. var byts = io.ConvertZipStream(chiZips);
  12881. Stream stream = new MemoryStream(byts);
  12882. Zips.Add(key.Name + "_.zip", stream);
  12883. }
  12884. }
  12885. }
  12886. else
  12887. {
  12888. foreach (var item in dbQuery)
  12889. {
  12890. using (var fileStream = new FileStream(item.FilePath, FileMode.Open, FileAccess.Read))
  12891. {
  12892. byte[] bytes = new byte[fileStream.Length];
  12893. fileStream.Read(bytes, 0, bytes.Length);
  12894. fileStream.Close();
  12895. var stream = new MemoryStream(bytes);
  12896. while (Zips.ContainsKey(item.FileName))
  12897. {
  12898. item.FileName = new Random().Next(100) + "_" + item.FileName;
  12899. }
  12900. Zips.Add(item.FileName, stream);
  12901. }
  12902. }
  12903. }
  12904. groupInfo.TeamName = Regex.Replace(groupInfo.TeamName, @"[^\w\.@-]", "",
  12905. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  12906. if (Zips.Count > 0)
  12907. {
  12908. var byts = io.ConvertZipStream(Zips);
  12909. var path = "\\GroupModelFiles\\" + groupInfo.TeamName;
  12910. io.ByteToFile(byts, AppSettingsHelper.Get("GrpFileBasePath") + $"{path}\\{groupInfo.TeamName}_.Zip");
  12911. jw = JsonView(true, "success", new { url = AppSettingsHelper.Get("GrpFileBaseUrl") + $"{AppSettingsHelper.Get("GrpFileFtpPath")}{path}\\{groupInfo.TeamName}_.zip" });
  12912. }
  12913. else
  12914. {
  12915. jw.Msg = "暂无生成文件!";
  12916. }
  12917. return Ok(jw);
  12918. }
  12919. /// <summary>
  12920. /// 下载该团组下此模块的所有文件
  12921. /// </summary>
  12922. /// <param name="dto"></param>
  12923. /// <returns></returns>
  12924. [HttpPost]
  12925. public IActionResult ExportGroupByModule(ExportGroupByModuleDto dto)
  12926. {
  12927. var jw = JsonView(false);
  12928. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.IsDel == 0 && x.Id == dto.Diid);
  12929. if (groupInfo == null)
  12930. {
  12931. jw.Msg = "团组信息不存在!";
  12932. return Ok(jw);
  12933. }
  12934. var dbQuery = _sqlSugar.Queryable<Grp_GroupModelFile>().Where(x => x.IsDel == 0 && x.Diid == dto.Diid && x.Ctable == dto.Ctable).ToList();
  12935. var key = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == dto.Ctable
  12936. && x.IsDel == 0);
  12937. if (key == null)
  12938. {
  12939. jw.Msg = "Ctable指向错误!";
  12940. return Ok(jw);
  12941. }
  12942. key.Name = Regex.Replace(key.Name, @"[^\w\.@-]", "",
  12943. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  12944. groupInfo.TeamName = Regex.Replace(groupInfo.TeamName, @"[^\w\.@-]", "",
  12945. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  12946. var io = new IOOperatorHelper();
  12947. var Zips = new Dictionary<string, Stream>();
  12948. foreach (var item in dbQuery)
  12949. {
  12950. if (System.IO.File.Exists(item.FilePath))
  12951. {
  12952. using (var fileStream = new FileStream(item.FilePath, FileMode.Open, FileAccess.Read))
  12953. {
  12954. byte[] bytes = new byte[fileStream.Length];
  12955. fileStream.Read(bytes, 0, bytes.Length);
  12956. fileStream.Close();
  12957. var stream = new MemoryStream(bytes);
  12958. while (Zips.ContainsKey(item.FileName))
  12959. {
  12960. item.FileName = new Random().Next(100) + "_" + item.FileName;
  12961. }
  12962. Zips.Add(item.FileName, stream);
  12963. }
  12964. }
  12965. }
  12966. if (Zips.Count > 0)
  12967. {
  12968. var byts = io.ConvertZipStream(Zips);
  12969. var path = "\\GroupModelFiles\\" + groupInfo.TeamName;
  12970. io.ByteToFile(byts, AppSettingsHelper.Get("GrpFileBasePath") + $"{path}\\{groupInfo.TeamName}_{key.Name}_.Zip");
  12971. jw = JsonView(true, "success", new { url = AppSettingsHelper.Get("GrpFileBaseUrl") + $"{AppSettingsHelper.Get("GrpFileFtpPath")}{path}\\{groupInfo.TeamName}_{key.Name}_.Zip" });
  12972. }
  12973. else
  12974. {
  12975. jw.Msg = "暂无生成文件!";
  12976. }
  12977. return Ok(jw);
  12978. }
  12979. /// <summary>
  12980. /// 删除该团组下的指定文件
  12981. /// </summary>
  12982. /// <param name="dto"></param>
  12983. /// <returns></returns>
  12984. [HttpPost]
  12985. public IActionResult DeleteGroupFile(DeleteGroupFileDto dto)
  12986. {
  12987. var jw = JsonView(false);
  12988. var sing = _sqlSugar.Queryable<Grp_GroupModelFile>().First(x => x.Id == dto.Id && x.IsDel == 0);
  12989. if (sing == null)
  12990. {
  12991. jw.Msg = "暂无";
  12992. return Ok(jw);
  12993. }
  12994. if (System.IO.File.Exists(sing.FilePath))
  12995. {
  12996. try
  12997. {
  12998. System.IO.File.Delete(sing.FilePath);
  12999. }
  13000. catch (Exception ex)
  13001. {
  13002. jw.Msg = "删除失败!" + ex.Message;
  13003. return Ok(jw);
  13004. }
  13005. }
  13006. sing.IsDel = 1;
  13007. sing.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  13008. sing.DeleteUserId = dto.UserId;
  13009. _sqlSugar.Updateable<Grp_GroupModelFile>(sing).ExecuteCommand();
  13010. jw = JsonView(true, "删除成功!");
  13011. return Ok(jw);
  13012. }
  13013. #endregion
  13014. #region 共享文件上传
  13015. /// <summary>
  13016. /// 超支通知推送
  13017. /// </summary>
  13018. /// <param name="dto"></param>
  13019. /// <returns></returns>
  13020. [HttpPost]
  13021. public async Task<IActionResult> qyWeChatNotification(qyWeChatNotificationDto dto)
  13022. {
  13023. //81 邀请/公务活动
  13024. var syCTable = new List<int> { 81 };
  13025. //76 酒店预订
  13026. //79 车/导游地接
  13027. //85 机票预订
  13028. var gjCTable = new List<int> { 76, 79, 85 };
  13029. var jw = JsonView(false);
  13030. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.IsDel == 0 && x.Id == dto.Diid);
  13031. if (di == null)
  13032. {
  13033. jw.Msg = "团组信息不存在!";
  13034. return Ok(jw);
  13035. }
  13036. var user = _sqlSugar.Queryable<Sys_Users>().First(x => x.IsDel == 0 && x.Id == dto.UserId);
  13037. if (user == null)
  13038. {
  13039. jw.Msg = "用户信息不存在!";
  13040. return Ok(jw);
  13041. }
  13042. if (syCTable.Contains(dto.CTable))
  13043. {
  13044. await AppNoticeLibrary.SendChatMsg_ExpenseOverrunsChat(dto.Diid, dto.UserId, dto.CTable, QiyeWeChatEnum.ExpenseOverrunsChat02);
  13045. }
  13046. else if (gjCTable.Contains(dto.CTable))
  13047. {
  13048. await AppNoticeLibrary.SendChatMsg_ExpenseOverrunsChat(dto.Diid, dto.UserId, dto.CTable, QiyeWeChatEnum.ExpenseOverrunsChat01);
  13049. }
  13050. else
  13051. {
  13052. jw.Msg = "CTABLE类型有误!";
  13053. }
  13054. jw = JsonView(true, "推送成功!", "");
  13055. return Ok(jw);
  13056. }
  13057. /// <summary>
  13058. /// 共享文件数据初始化
  13059. /// </summary>
  13060. /// <returns></returns>
  13061. [HttpGet]
  13062. public async Task<IActionResult> SharedFileInit(int userid, int portType)
  13063. {
  13064. var marketingDepartmentIds = new List<int> { 6, 26, 27, 28 };
  13065. var isMarketingDepartment = _sqlSugar.Queryable<Sys_Users>()
  13066. .Where(x => x.IsDel == 0 && marketingDepartmentIds.Contains(x.DepId))
  13067. .Select(x => x.Id)
  13068. .ToList()
  13069. .Contains(userid);
  13070. var dropDownType = _sqlSugar.Queryable<Sys_SetData>()
  13071. .Where(x => x.STid == 111 && x.IsDel == 0)
  13072. .Select(x => new
  13073. {
  13074. x.Name,
  13075. x.Id,
  13076. }).ToList();
  13077. if (isMarketingDepartment)
  13078. {
  13079. dropDownType = dropDownType.Where(x => x.Id == 1412).ToList();
  13080. }
  13081. if (portType == 1)
  13082. {
  13083. var provCityDatas = await _groupRepository.ProvinceCityBasicSource();
  13084. var dropDownGroupList = _sqlSugar.Queryable<Grp_DelegationInfo>()
  13085. .Where(x => x.IsDel == 0)
  13086. .OrderByDescending(x => x.VisitDate)
  13087. .Select(x => new
  13088. {
  13089. x.TeamName,
  13090. x.Id,
  13091. x.CityId,
  13092. })
  13093. .ToList()
  13094. .Select(x =>
  13095. {
  13096. var provinceId = x.CityId;
  13097. var isDefualtVal = true;
  13098. if (provinceId > 0)
  13099. {
  13100. var parentId = _groupRepository.FindParentIdByChildId(provCityDatas, provinceId);
  13101. if (parentId != null)
  13102. {
  13103. isDefualtVal = false;
  13104. provinceId = (int)parentId;
  13105. }
  13106. }
  13107. if (isDefualtVal)
  13108. {
  13109. provinceId = 122; //默认四川
  13110. }
  13111. return new
  13112. {
  13113. x.TeamName,
  13114. x.Id,
  13115. provinceId,
  13116. };
  13117. })
  13118. .ToList();
  13119. return Ok(JsonView(true, "SUCCESS!", new
  13120. {
  13121. dropDownType,
  13122. dropDownGroupList,
  13123. isMarketingDepartment
  13124. }));
  13125. }
  13126. else if (portType == 2 || portType == 3)
  13127. {
  13128. return Ok(JsonView(true, "SUCCESS!", new
  13129. {
  13130. dropDownType,
  13131. isMarketingDepartment
  13132. }));
  13133. }
  13134. else
  13135. {
  13136. return Ok(JsonView(false, "portType有误!"));
  13137. }
  13138. }
  13139. /// <summary>
  13140. /// 共享文件上传
  13141. /// </summary>
  13142. /// <param name="dto"></param>
  13143. /// <returns></returns>
  13144. [HttpPost]
  13145. public IActionResult SharedFileUpload([FromForm] SharedFileUploadDto dto)
  13146. {
  13147. var isGroup = new List<int> { 1412 };
  13148. if (isGroup.Contains(dto.FileType) && dto.Diid < 1)
  13149. {
  13150. return Ok(JsonView(false, "该文件需要关联团组!"));
  13151. }
  13152. if (dto.Files == null || dto.Files.Count == 0)
  13153. {
  13154. return Ok(JsonView(false, "无文件信息!"));
  13155. }
  13156. if (dto.Files.Sum(x => x.Length) > 20 * 1024 * 1024)
  13157. {
  13158. return Ok(JsonView(false, "文件大小超过20M!"));
  13159. }
  13160. if (dto.Userid < 1)
  13161. {
  13162. return Ok(JsonView(false, "请传入有效的Userid!"));
  13163. }
  13164. var jobInfo = _sqlSugar.Queryable<Sys_Users, Sys_JobPost>((u, j) => u.JobPostId == j.Id && j.IsDel == 0)
  13165. .Where(u => u.IsDel == 0 && u.Id == dto.Userid)
  13166. .Select((u, j) => new
  13167. {
  13168. u.CnName,
  13169. UserId = u.Id,
  13170. j.JobName,
  13171. })
  13172. .First();
  13173. if (jobInfo == null)
  13174. {
  13175. return Ok(JsonView(false, "请传入有效的Userid!"));
  13176. }
  13177. var commonFileExtensions = new List<string>
  13178. {
  13179. // 文本文件
  13180. ".txt", ".doc", ".docx", ".odt", ".pdf", ".rtf", ".md", ".log",
  13181. // 图片文件
  13182. ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".svg",
  13183. // 视频文件
  13184. ".mp4", ".avi", ".mov", ".mkv", ".wmv", ".flv", ".mpg", ".mpeg",
  13185. // 音频文件
  13186. ".mp3", ".wav", ".ogg", ".aac", ".flac",
  13187. // 压缩文件
  13188. ".zip", ".rar", ".7z", ".tar", ".gz", ".bz2",
  13189. // 数据文件
  13190. ".csv", ".xls", ".xlsx", ".json", ".xml", ".yaml", ".ini",
  13191. };
  13192. try
  13193. {
  13194. var setting = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == 1416);
  13195. var settingExtend = JsonConvert.DeserializeObject<List<string>>(setting.Remark);
  13196. commonFileExtensions.AddRange(settingExtend);
  13197. }
  13198. catch (Exception)
  13199. { }
  13200. var setdata = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == dto.FileType);
  13201. if (setdata == null)
  13202. {
  13203. return Ok(JsonView(false, "请传入有效的FileType!"));
  13204. }
  13205. var insertList = new List<Grp_GroupShareFile>();
  13206. string winPath = AppSettingsHelper.Get("ShareFileBasePath") + $"{setdata.Name}/";
  13207. if (!Directory.Exists(winPath))
  13208. {
  13209. Directory.CreateDirectory(winPath);
  13210. }
  13211. foreach (var item in dto.Files)
  13212. {
  13213. var houzui = Path.GetExtension(item.FileName);
  13214. if (!commonFileExtensions.Contains(houzui))
  13215. {
  13216. return Ok(JsonView(false, "未知后缀名称!"));
  13217. }
  13218. var fileName = $"{jobInfo.JobName}-{jobInfo.CnName}-{item.FileName}";
  13219. var saveFilePath = winPath + fileName;
  13220. using (FileStream fs = System.IO.File.Create(saveFilePath))
  13221. {
  13222. item.CopyTo(fs);
  13223. fs.Flush();
  13224. }
  13225. var fileDetail = new Grp_GroupShareFile()
  13226. {
  13227. CreateUserId = dto.Userid,
  13228. CreateTime = DateTime.Now,
  13229. UploadJob = jobInfo.JobName,
  13230. FileName = fileName,
  13231. FileType = dto.FileType,
  13232. Diid = dto.Diid,
  13233. FilePath = winPath + fileName,
  13234. };
  13235. insertList.Add(fileDetail);
  13236. }
  13237. _sqlSugar.Insertable<Grp_GroupShareFile>(insertList).ExecuteCommand();
  13238. return Ok(JsonView(true, "保存成功!"));
  13239. }
  13240. /// <summary>
  13241. /// 查询共享文件列表
  13242. /// </summary>
  13243. /// <param name="dto"></param>
  13244. /// <returns></returns>
  13245. [HttpPost]
  13246. public IActionResult QuerySharedFile(QuerySharedFileDto dto)
  13247. {
  13248. var isGroup = new List<int> { 1412 };
  13249. if (!isGroup.Contains(dto.FileType)) dto.Diid = 0;
  13250. var queryExpression = Expressionable.Create<Grp_GroupShareFile>()
  13251. .And(x => x.Diid == dto.Diid)
  13252. .And(x => x.FileType == dto.FileType)
  13253. .And(x => x.IsDel == 0)
  13254. .AndIF(!dto.FileName.IsNullOrWhiteSpace(), x => x.FileName.Contains(dto.FileName))
  13255. .AndIF(DateTime.TryParse(dto.StartTime, out DateTime Start), x => x.CreateTime >= Start)
  13256. .AndIF(DateTime.TryParse(dto.EndTime, out DateTime End), x => x.CreateTime <= End);
  13257. int totalCount = 0;
  13258. var dbQuery = _sqlSugar.Queryable<Grp_GroupShareFile>()
  13259. .Where(queryExpression.ToExpression())
  13260. .OrderBy(x => x.UploadJob)
  13261. .Select(x => new
  13262. {
  13263. x.Id,
  13264. FilePath = AppSettingsHelper.Get("ShareFileBaseUrl") + x.FilePath.Replace(AppSettingsHelper.Get("ShareFileBasePath"), AppSettingsHelper.Get("ShareFileFtpPath")),
  13265. x.FileName,
  13266. x.FileType,
  13267. x.CreateTime,
  13268. })
  13269. .ToPageList(dto.PageIndex, dto.PageSize, ref totalCount);
  13270. return Ok(JsonView(true, "SUCCESS!", new
  13271. {
  13272. FileList = dbQuery,
  13273. dto.PageSize,
  13274. dto.PageIndex,
  13275. totalCount
  13276. }));
  13277. }
  13278. /// <summary>
  13279. /// 删除共享文件模块下的指定文件
  13280. /// </summary>
  13281. /// <param name="dto"></param>
  13282. /// <returns></returns>
  13283. [HttpPost]
  13284. public IActionResult DeleteSharedFile(DeleteGroupFileDto dto)
  13285. {
  13286. var jw = JsonView(false);
  13287. var sing = _sqlSugar.Queryable<Grp_GroupShareFile>().First(x => x.Id == dto.Id && x.IsDel == 0);
  13288. if (sing == null)
  13289. {
  13290. jw.Msg = "暂无文件信息!";
  13291. return Ok(jw);
  13292. }
  13293. if (sing.CreateUserId != dto.UserId)
  13294. {
  13295. jw.Msg = "只能删除自己上传的文件!";
  13296. return Ok(jw);
  13297. }
  13298. if (System.IO.File.Exists(sing.FilePath))
  13299. {
  13300. try
  13301. {
  13302. System.IO.File.Delete(sing.FilePath);
  13303. }
  13304. catch (Exception ex)
  13305. {
  13306. jw.Msg = "删除失败!" + ex.Message;
  13307. return Ok(jw);
  13308. }
  13309. }
  13310. sing.IsDel = 1;
  13311. sing.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  13312. sing.DeleteUserId = dto.UserId;
  13313. _sqlSugar.Updateable<Grp_GroupShareFile>(sing).ExecuteCommand();
  13314. jw = JsonView(true, "删除成功!");
  13315. return Ok(jw);
  13316. }
  13317. #endregion
  13318. #region 团组英文资料
  13319. /// <summary>
  13320. /// 查询团组英文所有资料
  13321. /// </summary>
  13322. /// <param name="dto"></param>
  13323. /// <returns></returns>
  13324. [HttpPost]
  13325. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13326. public async Task<IActionResult> QueryDelegationEnData(QueryDelegationEnDataDto dto)
  13327. {
  13328. try
  13329. {
  13330. Result groupData = await _delegationEnDataRep.QueryDelegationEnData(dto);
  13331. if (groupData.Code != 0)
  13332. {
  13333. return Ok(JsonView(false, groupData.Msg));
  13334. }
  13335. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  13336. }
  13337. catch (Exception ex)
  13338. {
  13339. return Ok(JsonView(false, ex.Message));
  13340. throw;
  13341. }
  13342. }
  13343. /// <summary>
  13344. /// 团组英文资料操作(Status:1.新增,2.修改)
  13345. /// </summary>
  13346. /// <param name="dto"></param>
  13347. /// <returns></returns>
  13348. [HttpPost]
  13349. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13350. public async Task<IActionResult> OpDelegationEnData(OpDelegationEnDataDto dto)
  13351. {
  13352. try
  13353. {
  13354. Result groupData = await _delegationEnDataRep.OpDelegationEnData(dto);
  13355. if (groupData.Code != 0)
  13356. {
  13357. return Ok(JsonView(false, groupData.Msg));
  13358. }
  13359. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  13360. }
  13361. catch (Exception ex)
  13362. {
  13363. return Ok(JsonView(false, ex.Message));
  13364. throw;
  13365. }
  13366. }
  13367. /// <summary>
  13368. /// 团组英文资料Id查询数据
  13369. /// </summary>
  13370. /// <param name="dto"></param>
  13371. /// <returns></returns>
  13372. [HttpPost]
  13373. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13374. public async Task<IActionResult> QueryDelegationEnDataById(QueryDelegationEnDataByIdDto dto)
  13375. {
  13376. try
  13377. {
  13378. Grp_DelegationEnData _DelegationEnData = await _sqlSugar.Queryable<Grp_DelegationEnData>().FirstAsync(it => it.Id == dto.Id && it.IsDel == 0);
  13379. if (_DelegationEnData != null)
  13380. {
  13381. return Ok(JsonView(true, "查询成功!", _DelegationEnData));
  13382. }
  13383. return Ok(JsonView(true, "暂无数据!", _DelegationEnData));
  13384. }
  13385. catch (Exception ex)
  13386. {
  13387. return Ok(JsonView(false, "程序错误!"));
  13388. throw;
  13389. }
  13390. }
  13391. /// <summary>
  13392. /// 团组英文资料删除
  13393. /// </summary>
  13394. /// <param name="dto"></param>
  13395. /// <returns></returns>
  13396. [HttpPost]
  13397. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13398. public async Task<IActionResult> DelDelegationEnData(DelBaseDto dto)
  13399. {
  13400. try
  13401. {
  13402. var res = await _delegationEnDataRep.SoftDeleteByIdAsync<Grp_DelegationEnData>(dto.Id.ToString(), dto.DeleteUserId);
  13403. if (!res)
  13404. {
  13405. return Ok(JsonView(false, "删除失败"));
  13406. }
  13407. return Ok(JsonView(true, "删除成功!"));
  13408. }
  13409. catch (Exception ex)
  13410. {
  13411. return Ok(JsonView(false, ex.Message));
  13412. throw;
  13413. }
  13414. }
  13415. #endregion
  13416. #region 导出邀请函
  13417. /// <summary>
  13418. /// 导出邀请函页面初始化
  13419. /// </summary>
  13420. /// <param name="dto"></param>
  13421. /// <returns></returns>
  13422. [HttpPost]
  13423. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13424. public async Task<IActionResult> QueryinvitationLetter(DecreasePaymentsListDto dto)
  13425. {
  13426. try
  13427. {
  13428. var grp_Delegations = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(a => a.IsDel == 0).OrderBy(a => a.VisitStartDate, OrderByType.Desc).ToList();
  13429. var crm_Deles = new List<Crm_DeleClient>();
  13430. if (dto.DiId == 0)
  13431. {
  13432. crm_Deles = await _sqlSugar.Queryable<Crm_DeleClient>().Where(a => a.DiId == grp_Delegations[0].Id && a.IsDel == 0).ToListAsync();
  13433. }
  13434. else
  13435. {
  13436. crm_Deles = await _sqlSugar.Queryable<Crm_DeleClient>().Where(a => a.DiId == dto.DiId && a.IsDel == 0).ToListAsync();
  13437. }
  13438. return Ok(JsonView(true, "查询成功!", new
  13439. {
  13440. deleClient = crm_Deles,
  13441. delegations = grp_Delegations
  13442. }));
  13443. }
  13444. catch (Exception ex)
  13445. {
  13446. return Ok(JsonView(false, "程序错误!"));
  13447. throw;
  13448. }
  13449. }
  13450. /// <summary>
  13451. /// 导出邀请函
  13452. /// </summary>
  13453. /// <param name="dto"></param>
  13454. /// <returns></returns>
  13455. [HttpPost]
  13456. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13457. public async Task<IActionResult> invitationLetter(DecreasePaymentsListDto dto)
  13458. {
  13459. #region 参数验证
  13460. //if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  13461. if (dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId参数!"));
  13462. #endregion
  13463. try
  13464. {
  13465. var transDic = new Dictionary<string, string>();
  13466. string sql = string.Format(@"Select tcl.Id,tcl.DiId,temp.*,tcl.ShippingSpaceTypeId,tcl.ShippingSpaceSpecialNeeds,
  13467. tcl.HotelSpecialNeeds,tcl.MealSpecialNeeds,tcl.Remark
  13468. From Grp_TourClientList tcl
  13469. Left Join
  13470. (Select dc.Id As DcId,dc.LastName,dc.FirstName,dc.Pinyin,dc.Sex,ccom.CompanyFullName,dc.Job,
  13471. cc1.CertNo As IDCardNo,dc.Phone,dc.BirthDay,cc2.PassportType,cc2.CertNo As PassportNo,cc2.Country,
  13472. cc2.Area,cc2.IssueDt,cc2.ExpiryDt
  13473. From Crm_DeleClient dc
  13474. Left Join Crm_CustomerCompany ccom On dc.CrmCompanyId = ccom.Id And ccom.IsDel = 0
  13475. Left Join Crm_CustomerCert cc1 On dc.Id = cc1.DcId And cc1.SdId = 773 And cc1.IsDel = 0
  13476. Left Join Crm_CustomerCert cc2 On dc.Id = cc2.DcId And cc2.SdId = 774 And cc2.IsDel = 0
  13477. Where dc.IsDel = 0) temp
  13478. On temp.DcId =tcl.ClientId
  13479. Where tcl.IsDel = 0 And tcl.DiId = {0}", dto.DiId);
  13480. var datas = _sqlSugar.SqlQueryable<TourClientListDetailsView>(sql).ToList();
  13481. var texts = new List<string>();
  13482. if (datas.Count != 0)
  13483. {
  13484. foreach (TourClientListDetailsView item in datas)
  13485. {
  13486. if (!string.IsNullOrWhiteSpace(item.Pinyin))
  13487. {
  13488. transDic.Add(item.LastName + item.FirstName, item.Pinyin);
  13489. }
  13490. else
  13491. {
  13492. string name = item.LastName + item.FirstName;
  13493. texts.Add(name);
  13494. }
  13495. if (!string.IsNullOrEmpty(item.Job) && !texts.Contains(item.Job))
  13496. {
  13497. if (!transDic.ContainsKey(item.Job))
  13498. {
  13499. texts.Add(item.Job);
  13500. }
  13501. }
  13502. if (!string.IsNullOrEmpty(item.CompanyFullName))
  13503. {
  13504. texts.Add(item.CompanyFullName);
  13505. }
  13506. }
  13507. var transData = await _airTicketResRep.ReTransBatch(texts, "en");
  13508. if (transData.Count > 0)
  13509. {
  13510. foreach (TranslateResult item in transData)
  13511. {
  13512. if (!transDic.ContainsKey(item.Query))
  13513. {
  13514. transDic.Add(item.Query, item.Translation);
  13515. }
  13516. }
  13517. }
  13518. var list = new List<GuestList>();
  13519. foreach (var dele in datas)
  13520. {
  13521. var guestList = new GuestList();
  13522. if (!string.IsNullOrWhiteSpace(dele.Pinyin))
  13523. {
  13524. guestList.Name = dele.Pinyin;
  13525. }
  13526. else
  13527. {
  13528. string Name = transDic.Where(s => s.Key == dele.LastName + dele.FirstName).FirstOrDefault().Value;
  13529. guestList.Name = Name;
  13530. }
  13531. if (dele.Sex == 0)
  13532. {
  13533. guestList.Sex = "Male";
  13534. }
  13535. else if (dele.Sex == 1)
  13536. {
  13537. guestList.Sex = "Female";
  13538. }
  13539. guestList.DOB = dele.BirthDay.Replace('-', '.');
  13540. if (!string.IsNullOrEmpty(dele.Job))
  13541. {
  13542. guestList.Job = dele.Job;
  13543. }
  13544. list.Add(guestList);
  13545. }
  13546. //载入模板
  13547. var doc = new Document(AppSettingsHelper.Get("WordBasePath") + "Template/邀请函模板0210.docx");
  13548. var builder = new DocumentBuilder(doc);
  13549. //获取word里所有表格
  13550. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  13551. //获取所填表格的序数
  13552. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  13553. var rowStart = tableOne.Rows[0]; //获取第1行
  13554. //循环赋值
  13555. for (int i = 0; i < list.Count; i++)
  13556. {
  13557. builder.MoveToCell(0, i + 1, 0, 0);
  13558. builder.Write(list[i].Name.ToString());
  13559. builder.MoveToCell(0, i + 1, 1, 0);
  13560. builder.Write(list[i].Sex.ToString());
  13561. builder.MoveToCell(0, i + 1, 2, 0);
  13562. builder.Write(list[i].DOB.ToString());
  13563. builder.MoveToCell(0, i + 1, 3, 0);
  13564. builder.Write(list[i].Job.ToString());
  13565. }
  13566. //删除多余行
  13567. while (tableOne.Rows.Count > list.Count + 1)
  13568. {
  13569. tableOne.Rows.RemoveAt(list.Count + 1);
  13570. }
  13571. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  13572. string fileName = "邀请函" + DateTime.Now.ToString("yyyy-MM-dd") + ".docx";
  13573. string filePath = fileDir + $@"商邀相关文件/{fileName}";
  13574. doc.Save(filePath);
  13575. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/GrpFile/商邀相关文件/" + fileName;
  13576. return Ok(JsonView(true, "操作成功!", Url));
  13577. }
  13578. else
  13579. {
  13580. return Ok(JsonView(false, "该团组客户名单暂未录入!"));
  13581. }
  13582. }
  13583. catch (Exception ex)
  13584. {
  13585. return Ok(JsonView(false, ex.Message));
  13586. throw;
  13587. }
  13588. }
  13589. #endregion
  13590. #region 团组经理模块 出入境费用
  13591. /// <summary>
  13592. /// 团组模块 - 出入境费用 - 省份基础数据源
  13593. /// </summary>
  13594. /// <returns></returns>
  13595. [HttpGet]
  13596. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13597. public async Task<IActionResult> GetEnterExitProvBelongCostDataSource()
  13598. {
  13599. return Ok(JsonView(await _groupRepository.ProvinceBasicSource()));
  13600. }
  13601. /// <summary>
  13602. /// 团组模块 - 出入境费用 - 基础数据源(团组名称/币种类型)
  13603. /// </summary>
  13604. /// <param name="dto"></param>
  13605. /// <returns></returns>
  13606. [HttpPost]
  13607. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13608. public async Task<IActionResult> GetEnterExitCostDataSource(EnterExitCostDataSourceDto dto)
  13609. {
  13610. var groupNameData = await _groupRepository.EnterExitCostGroupNameAsync();
  13611. var groupNamFirst = groupNameData.FirstOrDefault();
  13612. //SetDataInfoView
  13613. var dataSource = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToListAsync();
  13614. var currencyData = dataSource.Where(it => it.STid == 66).ToList(); //所有币种
  13615. List<SetDataInfoView> _CurrencyData = _mapper.Map<List<SetDataInfoView>>(currencyData);
  13616. //验证城市归属并给默认值
  13617. int provinceId = 122;
  13618. if (groupNamFirst != null) provinceId = groupNamFirst.ProvinceId;
  13619. (SetDataInfoView[] wordTypeData, SetDataInfoView[] excelTypeData) = await _enterExitCostRep.FileOwner(provinceId);
  13620. var _currencyInfos = await GeneralMethod.EnterExitCostInitRate();
  13621. var viewPermissionData = await _enterExitCostRep.PermissionViewUsersAsync();
  13622. return Ok(JsonView(true, "查询成功!", new
  13623. {
  13624. GroupNameData = groupNameData,
  13625. CurrencyData = _CurrencyData,
  13626. WordTypeData = wordTypeData,
  13627. ExcelTypeData = excelTypeData,
  13628. CurrencyInit = _currencyInfos
  13629. }));
  13630. }
  13631. /// <summary>
  13632. /// 团组模块 - 出入境费用 - 文件类型list 跟据省份Id获取
  13633. /// </summary>
  13634. /// <returns></returns>
  13635. [HttpGet("{provinceId}")]
  13636. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13637. public async Task<IActionResult> EnterExitCostFileOwner([FromRoute] int provinceId = 122)
  13638. {
  13639. //验证城市归属并给默认值
  13640. if (provinceId < 1) provinceId = 122;
  13641. /*
  13642. * 122 四川
  13643. * 108 贵州
  13644. * 103 重庆
  13645. * 132 云南
  13646. */
  13647. (SetDataInfoView[] wordTypeData, SetDataInfoView[] excelTypeData) = await _enterExitCostDraftRep.FileOwner(provinceId);
  13648. return Ok(JsonView(true, "查询成功!", new
  13649. {
  13650. WordTypeData = wordTypeData,
  13651. ExcelTypeData = excelTypeData,
  13652. }));
  13653. }
  13654. /// <summary>
  13655. /// 团组模块 - 出入境费用
  13656. /// 实时汇率 tips
  13657. /// 签证费用 tips
  13658. /// 机票费用 tips
  13659. /// </summary>
  13660. /// <returns></returns>
  13661. [HttpPost]
  13662. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13663. public async Task<IActionResult> GetEnterExitCostCorrelationTips(EnterExitCostInfobyDiIdDto dto)
  13664. {
  13665. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(it => it.Id == dto.DiId && it.IsDel == 0);
  13666. //默认币种显示
  13667. var reteInfos = await GeneralMethod.EnterExitCostLiveRate();
  13668. var visaData = await _visaFeeInfoRep.EnterExitCostVisaTips(dto.DiId);
  13669. var airData = await GeneralMethod.EntryAndExitTips(dto.DiId);
  13670. return Ok(JsonView(true, "查询成功!", new
  13671. {
  13672. //GroupNameData = groupNameData.Data,
  13673. visaData = visaData.Data,
  13674. airData,
  13675. reteInfos
  13676. }));
  13677. }
  13678. #region 城市区间交通费
  13679. /// <summary>
  13680. /// 团组模块 - 出入境费用 - 基础数据源(境外用车)
  13681. /// </summary>
  13682. /// <param name="groupId"></param>
  13683. /// <returns></returns>
  13684. [HttpGet("{groupId}")]
  13685. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13686. public async Task<IActionResult> GetEnterExitCostOVByGroupId(int groupId)
  13687. {
  13688. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  13689. if (groupInfo == null)
  13690. {
  13691. return Ok(JsonView(false, "团组信息为空"));
  13692. }
  13693. var countryies = _groupRepository.GroupSplitCountry(groupInfo.VisitCountry);
  13694. if (countryies?.Any() != true)
  13695. {
  13696. return Ok(JsonView(false, "团组出访国家信息为空"));
  13697. }
  13698. var currencies = await GeneralMethod.EnterExitCostOVFeeUsedCurrencyAsync(groupId);
  13699. var currencyData = await _sqlSugar.Queryable<Sys_SetData>()
  13700. .Where(x => x.IsDel == 0 && x.STid == 66)
  13701. .ToListAsync();
  13702. var overseaVehicles = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  13703. .Where(x => x.IsDel == 0 && countryies.Contains(x.CountryName))
  13704. .ToListAsync();
  13705. var overseaVehicleIds = overseaVehicles.Select(x => x.Id).ToList();
  13706. //只返回接送机的数据
  13707. var overseaVehicleTypes = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  13708. .Where(x => x.IsDel == 0 && x.ServiceType == VehicleServiceTypeEnum.TransferService && overseaVehicleIds.Contains(x.OvId))
  13709. .ToListAsync();
  13710. var sysUers = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToListAsync();
  13711. var overseaVehicleCityDatas = new List<dynamic>() {
  13712. new
  13713. {
  13714. Id = 0,
  13715. area= "未选择",
  13716. CarTypeName = "",
  13717. serviceType = "",
  13718. Price = 0.00M,
  13719. guidePrice = 0.00M,
  13720. otherPrice = 0.00M,
  13721. currency = 0,
  13722. currencyName = "",
  13723. currRate = 1.0000M,
  13724. LastUpdateUserName = "",
  13725. LastUpdateTime = "",
  13726. Remark = ""
  13727. }};
  13728. foreach (var item in overseaVehicleTypes)
  13729. {
  13730. var parentInfo = overseaVehicles.FirstOrDefault(x => x.Id == item.OvId);
  13731. string area = string.Empty,
  13732. serviceType = "未设置",
  13733. currencyName = string.Empty;
  13734. decimal otherPrice = 0.00M;
  13735. if (parentInfo != null)
  13736. {
  13737. if (parentInfo.CountryName == parentInfo.CityName) area = parentInfo.CountryName;
  13738. else area = $"{parentInfo.CountryName}-{parentInfo.CityName}";
  13739. serviceType = item.ServiceType.GetDescription();
  13740. currencyName = currencyData.FirstOrDefault(x => x.Id == parentInfo.Currency)?.Name ?? "-";
  13741. otherPrice = parentInfo.OtherPrice1 + parentInfo.OtherPrice2;
  13742. }
  13743. //当前币种汇率值
  13744. var currRate = 1.0000M;
  13745. var currencyInfo = currencies.FirstOrDefault(x => x.CurrencyCode == currencyName);
  13746. if (currencyInfo != null) currRate = currencyInfo.Rate;
  13747. overseaVehicleCityDatas.add(new
  13748. {
  13749. item.Id,
  13750. area,
  13751. item.CarTypeName,
  13752. serviceType,
  13753. item.Price,
  13754. guidePrice = parentInfo?.GuidePrice ?? 0.00M,
  13755. otherPrice,
  13756. currency = parentInfo?.Currency ?? 0,
  13757. currencyName,
  13758. currRate,
  13759. LastUpdateUserName = sysUers.FirstOrDefault(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-",
  13760. item.LastUpdateTime,
  13761. item.Remark
  13762. });
  13763. }
  13764. var total = overseaVehicleCityDatas.Count;
  13765. var view = new
  13766. {
  13767. visitCountries = string.Join("、", countryies),
  13768. groupSize = groupInfo.VisitPNumber, //出访人数
  13769. defAirportTransferCoeff = Def_AirportTransferCoeff, //接送机默认报价系数
  13770. defServiceCount = Def_ServiceCount, //接送机默认服务次数
  13771. defTrainCoeff = Def_TrainCoeff, //火车默认报价系数
  13772. defPullCartCoeff = Def_PullCartCoeff, //拉车默认报价系数
  13773. defCityFlightCoeff = Def_CityFlightCoeff, //城市机票默认报价系数
  13774. Currencies = currencies,
  13775. data = overseaVehicleCityDatas
  13776. };
  13777. if (overseaVehicleCityDatas.Count == 0)
  13778. {
  13779. return Ok(JsonView(true, "暂无数据!", view));
  13780. }
  13781. return Ok(JsonView(true, "查询成功!", view, total));
  13782. }
  13783. /// <summary>
  13784. /// 团组模块 - 出入境费用 - 境外用车计算详细信息
  13785. /// </summary>
  13786. /// <param name="groupId"></param>
  13787. /// <param name="currUserId"></param>
  13788. /// <returns></returns>
  13789. [HttpGet("{groupId}")]
  13790. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13791. public async Task<IActionResult> GetEnterExitCostOVFeeDetails(int groupId, int currUserId)
  13792. {
  13793. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  13794. if (groupInfo == null)
  13795. {
  13796. return Ok(JsonView(false, "团组信息为空"));
  13797. }
  13798. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).FirstAsync();
  13799. //CityIntervalInfo
  13800. var info = new CityIntervalInfo();
  13801. if (eecInfo != null && !string.IsNullOrEmpty(eecInfo.CityIntervalFeeDetails))
  13802. {
  13803. info = JsonConvert.DeserializeObject<CityIntervalInfo>(eecInfo.CityIntervalFeeDetails);
  13804. return Ok(JsonView(true, "查询成功!", info));
  13805. }
  13806. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == currUserId).FirstAsync();
  13807. var userName = userInfo?.CnName ?? "-";
  13808. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  13809. //返回默认数据
  13810. info = new CityIntervalInfo()
  13811. {
  13812. APTFeeDetails = new List<RoundTripTransferInfo>() { new() { No = 1, Coefficient = Def_AirportTransferCoeff, ServiceCount = Def_ServiceCount } },
  13813. PullCartFeeDetails = new List<PullCartInfo>() { new() { No = 1, Coefficient = Def_PullCartCoeff } },
  13814. TrainFeeDetails = new List<TrainInfo>() { new() { No = 1, Coefficient = Def_TrainCoeff } },
  13815. CityAirTicketFeeDetails = new List<CityAirTicketInfo>() { new() { No = 1, Coefficient = Def_CityFlightCoeff } },
  13816. LastUpdateUserName = userName,
  13817. LastUpdateTime = nowTime,
  13818. CreateUserName = userName,
  13819. Currencies = await GeneralMethod.EnterExitCostOVFeeUsedCurrencyAsync(groupId),
  13820. CreateTime = nowTime
  13821. };
  13822. return Ok(JsonView(true, "查询成功!", info));
  13823. }
  13824. /// <summary>
  13825. /// 团组模块 - 出入境费用 - 境外用车计算 保存
  13826. /// </summary>
  13827. /// <param name="dto"></param>
  13828. /// <returns></returns>
  13829. [HttpPost]
  13830. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13831. public async Task<IActionResult> GetEnterExitCostOVFeeSave(GetEnterExitCostOVFeeSaveDto dto)
  13832. {
  13833. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == dto.GroupId).FirstAsync();
  13834. if (groupInfo == null)
  13835. {
  13836. return Ok(JsonView(false, "团组信息为空"));
  13837. }
  13838. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == dto.CurrUserId).FirstAsync();
  13839. if (userInfo == null)
  13840. {
  13841. return Ok(JsonView(false, "员工信息为空"));
  13842. }
  13843. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == dto.GroupId).FirstAsync();
  13844. if (eecInfo == null)
  13845. {
  13846. return Ok(JsonView(false, "出入境费用信息为空"));
  13847. }
  13848. var oldData = new CityIntervalInfo();
  13849. if (!string.IsNullOrEmpty(eecInfo.CityIntervalFeeDetails))
  13850. {
  13851. oldData = JsonConvert.DeserializeObject<CityIntervalInfo>(eecInfo.CityIntervalFeeDetails);
  13852. }
  13853. var userName = userInfo?.CnName ?? "-";
  13854. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  13855. var info = new CityIntervalInfo()
  13856. {
  13857. APTFeeTotal = dto.APTFeeTotal,
  13858. APTFeeDetails = dto.APTFeeDetails,
  13859. PullCartFeeTotal = dto.PullCartFeeTotal,
  13860. PullCartFeeDetails = dto.PullCartFeeDetails,
  13861. TrainFeeTotal = dto.TrainFeeTotal,
  13862. TrainFeeDetails = dto.TrainFeeDetails,
  13863. CityAirTicketFeeTotal = dto.CityAirTicketFeeTotal,
  13864. CityAirTicketFeeDetails = dto.CityAirTicketFeeDetails,
  13865. Currencies = dto.Currencies,
  13866. LastUpdateUserName = userName,
  13867. LastUpdateTime = nowTime,
  13868. CreateUserName = oldData?.CreateUserName ?? userName,
  13869. CreateTime = oldData?.CreateTime ?? nowTime
  13870. };
  13871. eecInfo.CityIntervalFeeDetails = JsonConvert.SerializeObject(info);
  13872. var upd = await _sqlSugar.Updateable<Grp_EnterExitCost>()
  13873. .SetColumns(it => it.CityIntervalFeeDetails == eecInfo.CityIntervalFeeDetails)
  13874. .SetColumns(it => it.LastUpdateUserId == dto.CurrUserId)
  13875. .SetColumns(it => it.LastUpdateTime == nowTime)
  13876. .Where(x => x.Id == eecInfo.Id)
  13877. .ExecuteCommandAsync();
  13878. if (upd < 1)
  13879. {
  13880. return Ok(JsonView(false));
  13881. }
  13882. //返回数据处理
  13883. var label = new StringBuilder();
  13884. //接送机
  13885. if (dto.APTFeeDetails?.Any() == true)
  13886. {
  13887. var ovIds = dto.APTFeeDetails.Select(x => x.OvId).ToList();
  13888. var areas = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  13889. .LeftJoin<Res_OverseaVehicle>((ovtp, ov) => ovtp.OvId == ov.Id)
  13890. .Where((ovtp, ov) => ovtp.IsDel == 0 && ovIds.Contains(ovtp.Id))
  13891. .Select((ovtp, ov) => new
  13892. {
  13893. ovtp.Id,
  13894. ov.CountryName,
  13895. ov.CityName
  13896. }).ToListAsync();
  13897. var items = dto.APTFeeDetails
  13898. .Select(item =>
  13899. {
  13900. var areaInfo = areas.FirstOrDefault(x => x.Id == item.OvId);
  13901. if (areaInfo == null) return null;
  13902. return areaInfo.CountryName == areaInfo.CityName
  13903. ? $"{areaInfo.CountryName}({item.Quote:#0.00} CNY)"
  13904. : $"{areaInfo.CountryName}-{areaInfo.CityName}({item.Quote:#0.00} CNY)";
  13905. })
  13906. .Where(item => item != null)
  13907. .ToList();
  13908. label.AppendLine($"接送机({string.Join("、", items)});");
  13909. }
  13910. //拉车
  13911. if (dto.PullCartFeeDetails?.Any() == true)
  13912. {
  13913. var feeLabel = string.Join("、",
  13914. dto.PullCartFeeDetails.Select(x =>
  13915. $"{x.Quote:#0.00} CNY"
  13916. ));
  13917. label.AppendLine($"拉车({feeLabel});");
  13918. }
  13919. //火车
  13920. if (dto.TrainFeeDetails?.Any() == true)
  13921. {
  13922. var feeLabel = string.Join("、",
  13923. dto.TrainFeeDetails.Select(x =>
  13924. $"{x.Quote:#0.00} CNY"
  13925. ));
  13926. label.AppendLine($"火车票({feeLabel});");
  13927. }
  13928. //城市机票
  13929. if (dto.CityAirTicketFeeDetails?.Any() == true)
  13930. {
  13931. var feeLabel = string.Join("、",
  13932. dto.CityAirTicketFeeDetails.Select(x =>
  13933. $"{x.Quote:#0.00} CNY"
  13934. ));
  13935. label.AppendLine($"城市机票({feeLabel});");
  13936. }
  13937. //费用
  13938. decimal quote = (dto.APTFeeTotal + dto.PullCartFeeTotal + dto.TrainFeeTotal + dto.CityAirTicketFeeTotal).ConvertToDecimal1();
  13939. decimal jjcQuote = quote;
  13940. decimal gwcQuote = quote;
  13941. decimal tdcQuote = quote;
  13942. var view = new
  13943. {
  13944. label = label.ToString(),
  13945. jjcQuote,
  13946. gwcQuote,
  13947. tdcQuote
  13948. };
  13949. return Ok(JsonView(view));
  13950. }
  13951. #endregion
  13952. /// <summary>
  13953. /// 团组模块 - 出入境费用 - Info
  13954. /// </summary>
  13955. /// <param name="dto"></param>
  13956. /// <returns></returns>
  13957. [HttpPost]
  13958. //[ApiLog("Grp_EnterExitCost", OperationEnum.Details)]
  13959. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13960. public async Task<IActionResult> GetEnterExitCostInfobyDiId(EnterExitCostInfobyDiIdDto dto)
  13961. {
  13962. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  13963. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  13964. return Ok(await _enterExitCostRep.GetEnterExitCostInfoByDiId(dto));
  13965. }
  13966. /// <summary>
  13967. /// 团组模块 - 出入境费用 - 设置view权限
  13968. /// </summary>
  13969. /// <returns></returns>
  13970. [HttpPost]
  13971. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13972. public async Task<IActionResult> EnterExitCostSetViewPermissiion(EnterExitCostSetViewPermissiionDto dto)
  13973. {
  13974. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  13975. if (dto.GroupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  13976. if (dto.UserIds.Length < 1) return Ok(JsonView(false, "请传入有效的userId;"));
  13977. var permissions = new List<Grp_EnterExitCostPermission>();
  13978. foreach (var userId in dto.UserIds)
  13979. {
  13980. permissions.Add(new Grp_EnterExitCostPermission { Permission = 1, GroupId = dto.GroupId, UserId = userId, CreateUserId = dto.CurrUserId });
  13981. }
  13982. if (permissions.Any())
  13983. {
  13984. _sqlSugar.BeginTran();
  13985. try
  13986. {
  13987. await _sqlSugar.Deleteable<Grp_EnterExitCostPermission>().Where(it => it.GroupId == dto.GroupId).ExecuteCommandAsync();
  13988. var result = await _sqlSugar.Insertable(permissions).ExecuteCommandAsync();
  13989. if (result < 1)
  13990. {
  13991. _sqlSugar.RollbackTran();
  13992. return Ok(JsonView(false));
  13993. }
  13994. }
  13995. catch (Exception ex)
  13996. {
  13997. _sqlSugar.RollbackTran();
  13998. return Ok(JsonView(false, ex.Message));
  13999. }
  14000. _sqlSugar.CommitTran();
  14001. return Ok(JsonView(true));
  14002. }
  14003. return Ok(JsonView(false));
  14004. }
  14005. /// <summary>
  14006. /// 团组模块 - 出入境费用 - Add And Update
  14007. /// </summary>
  14008. /// <returns></returns>
  14009. [HttpPost]
  14010. [ApiLog("Grp_EnterExitCost", OperationEnum.Add)]
  14011. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14012. public async Task<IActionResult> PostEnterExitCostOperate(EnterExitCostOperateDto dto)
  14013. {
  14014. try
  14015. {
  14016. var rateRecords = new List<RateRecordInfo>();
  14017. #region 汇率保存前存储
  14018. var info = await _sqlSugar.Queryable<Grp_EnterExitCost>().FirstAsync(x => x.IsDel == 0 && x.DiId == dto.DiId);
  14019. if (info != null)
  14020. {
  14021. var cacheRateInfos = CommonFun.GetCurrencyChinaToList(info.CurrencyRemark);
  14022. if (cacheRateInfos != null && cacheRateInfos.Count > 0)
  14023. {
  14024. rateRecords = cacheRateInfos.Select(x => new RateRecordInfo()
  14025. {
  14026. CurrencyCode = x.CurrencyCode,
  14027. CurrencyName = x.CurrencyName,
  14028. UpdatePreRate = x.Rate,
  14029. UpdateBreRate = dto.Currencys.Where(x1 => x1.CurrencyName.Equals(x.CurrencyName)).FirstOrDefault()?.Rate ?? 0.00M
  14030. }).ToList();
  14031. }
  14032. else
  14033. {
  14034. rateRecords = dto.Currencys.Select(x => new RateRecordInfo()
  14035. {
  14036. CurrencyCode = x.CurrencyCode,
  14037. CurrencyName = x.CurrencyName,
  14038. UpdatePreRate = 0.00M,
  14039. UpdateBreRate = x.Rate
  14040. }).ToList();
  14041. }
  14042. }
  14043. else
  14044. {
  14045. rateRecords = dto.Currencys.Select(x => new RateRecordInfo()
  14046. {
  14047. CurrencyCode = x.CurrencyCode,
  14048. CurrencyName = x.CurrencyName,
  14049. UpdatePreRate = 0.00M,
  14050. UpdateBreRate = x.Rate
  14051. }).ToList();
  14052. }
  14053. #endregion
  14054. var data = await _enterExitCostRep.PostEnterExitCostOperate(dto);
  14055. if (dto.DayOtherPriceData.Any())
  14056. {
  14057. var inserList = dto.DayOtherPriceData
  14058. .Where(x => x.Id == 0)
  14059. .Select(x => new Grp_DayOtherPrice
  14060. {
  14061. Cost = x.Cost,
  14062. Id = x.Id,
  14063. CreateTime = DateTime.Now,
  14064. CreateUserId = dto.UserId,
  14065. Currency = x.Currency,
  14066. Diid = x.DiId,
  14067. Index = x.Index,
  14068. IsDel = 0,
  14069. SetDataId = x.SetDataId,
  14070. SubTotal = x.SubTotal,
  14071. Remark = x.Remark
  14072. })
  14073. .ToList();
  14074. var updateList = dto.DayOtherPriceData
  14075. .Where(x => x.Id != 0)
  14076. .Select(x => new Grp_DayOtherPrice
  14077. {
  14078. Cost = x.Cost,
  14079. Id = x.Id,
  14080. CreateTime = DateTime.Now,
  14081. CreateUserId = dto.UserId,
  14082. Currency = x.Currency,
  14083. Diid = x.DiId,
  14084. Index = x.Index,
  14085. IsDel = 0,
  14086. SetDataId = x.SetDataId,
  14087. SubTotal = x.SubTotal,
  14088. Remark = x.Remark
  14089. })
  14090. .ToList();
  14091. //添加
  14092. _sqlSugar.BeginTran();
  14093. if (inserList.Any())
  14094. {
  14095. var rowCount = _sqlSugar.Insertable<Grp_DayOtherPrice>(inserList).ExecuteCommand();
  14096. }
  14097. if (updateList.Any())
  14098. {
  14099. var rowCount = _sqlSugar.Updateable<Grp_DayOtherPrice>(updateList).ExecuteCommand();
  14100. }
  14101. _sqlSugar.CommitTran();
  14102. }
  14103. if (data.Code != 0)
  14104. {
  14105. return Ok(JsonView(false, data.Msg));
  14106. }
  14107. //生成默认文件pdf并且通知人员
  14108. var fileView = await GeneralMethod.EnterExitCostDownload(new EnterExitCostDownloadDto()
  14109. {
  14110. DiId = dto.DiId,
  14111. ExportType = 1,
  14112. SubTypeId = 1005
  14113. }, "pdf");
  14114. //发送通知
  14115. string fileUrl = (string)fileView.Data.GetType().GetProperty("Url").GetValue(fileView.Data, null);
  14116. int sign = (int)data.Data.GetType().GetProperty("sign").GetValue(data.Data, null);
  14117. string md5Sign = GeneralMethod.Encrypt($"{sign}&fileName={fileUrl}");
  14118. string url = string.Format("http://oa.pan-american-intl.com:4399/#/Sankunginfo?sign={0}&fileName={1}", sign, fileUrl);
  14119. await AppNoticeLibrary.SendUserMsg_GroupShare_ToGM(dto.DiId, new List<string>() { "208", "233", "21" }, dto.UserId, url);
  14120. //汇率信息记录
  14121. await GeneralMethod.RateRecordSave(dto.UserId, sign, "出入境费用");
  14122. var checkCurrencys = await _enterExitCostRep.GetCheckCurrencies(dto.DiId);
  14123. //汇率验证、反推
  14124. (bool isSendMsg, string msgContent, List<CurrencyInfo> liveRates) = await GeneralMethod.EnterExitCostCheckRate(dto.DiId, checkCurrencys);
  14125. if (isSendMsg)
  14126. {
  14127. //消息推送
  14128. await AppNoticeLibrary.SendUserMsg_GroupShare_ToFin(dto.DiId, dto.UserId, msgContent);
  14129. }
  14130. #region 日志汇率记录
  14131. //按照已使用币种记录
  14132. if (checkCurrencys != null && checkCurrencys.Count > 0)
  14133. {
  14134. rateRecords = rateRecords.Where(x => checkCurrencys.Select(x1 => x1.CurrencyName).ToList().Contains(x.CurrencyName)).ToList();
  14135. //汇率记录中加入实时汇率
  14136. if (liveRates != null && liveRates.Count > 0)
  14137. {
  14138. foreach (var item in rateRecords)
  14139. {
  14140. item.CurrLiveRate = liveRates.Where(x => x.CurrencyName.Equals(item.CurrencyName)).FirstOrDefault()?.Rate ?? 0.00M;
  14141. }
  14142. }
  14143. var teamName = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == dto.DiId && x.IsDel == 0).Select(x => x.TeamName).FirstAsync();
  14144. var operationName = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == dto.UserId && x.IsDel == 0).Select(x => x.CnName).FirstAsync();
  14145. var logContent = new StringBuilder();
  14146. foreach (var item in rateRecords)
  14147. {
  14148. var blRate = (item.CurrLiveRate * 1.0350M).TruncDecimals(4);
  14149. string msg = $">- {item.CurrencyName}汇率:(页面保存前){item.UpdatePreRate:#0.0000}/(页面保存){item.UpdateBreRate:#0.0000}/实时汇率(已上浮1.0350):{blRate:#0.0000}【注:原接口输出汇率为:{item.CurrLiveRate:#0.0000}】";
  14150. logContent.AppendLine(msg);
  14151. }
  14152. _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());
  14153. }
  14154. #endregion
  14155. return Ok(JsonView(true, data.Msg, data.Data));
  14156. }
  14157. catch (Exception ex)
  14158. {
  14159. return Ok(JsonView(false, ex.Message));
  14160. }
  14161. }
  14162. /// <summary>
  14163. /// 团组模块 - 出入境费用 - Confirm 费用
  14164. /// </summary>
  14165. /// <returns></returns>
  14166. [HttpPost]
  14167. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14168. public async Task<IActionResult> PostEnterExitCostIsConfirm(ConfirmCostDto dto)
  14169. {
  14170. //TODO:测试完毕需把对应的用户ID更改
  14171. //1、数据表添加字段
  14172. //2、更改字段接口()
  14173. var _view = await _enterExitCostRep.ConfirmCost(dto);
  14174. //3、确认成功 给财务发送消息
  14175. if (_view.Code == 200)
  14176. {
  14177. if (dto.Type == 1)
  14178. {
  14179. int diId = _enterExitCostRep._sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.Id == dto.Id).First()?.DiId ?? 0;
  14180. await AppNoticeLibrary.SendUserMsg_GroupShare_ToFinance(diId);
  14181. }
  14182. }
  14183. return Ok(_view);
  14184. }
  14185. /// <summary>
  14186. /// 团组模块 - 出入境费用 - File download
  14187. /// </summary>
  14188. /// <param name="dto"></param>
  14189. /// <returns></returns>
  14190. [HttpPost]
  14191. //[ApiLog("Grp_EnterExitCost", OperationEnum.Download)]
  14192. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14193. public async Task<IActionResult> PostEnterExitCostDownload(EnterExitCostDownloadDto dto)
  14194. {
  14195. try
  14196. {
  14197. if (dto.DiId < 1) return Ok(JsonView(400, "请传入有效的DiId参数;", ""));
  14198. if (dto.ExportType < 1) return Ok(JsonView(400, "请传入有效的ExportType参数; 1 明细表 2 表格", ""));
  14199. if (dto.SubTypeId < 1) return Ok(JsonView(400, @"请传入有效的SubTypeId参数;
  14200. 1 明细表 --> 1005(默认明细表) 1006(因公出国(境)经费测算明细表) 1007(四川省商务厅出国经费财政先行审核表)
  14201. 2 表格 --> 1008(派员单位出(境)任务和预算审批意见表) 1009(省级单位出(境)经费报销单)
  14202. 3 团组成员名单 1 团组成员名单", ""));
  14203. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).OrderByDescending(x => x.CreateTime).First();
  14204. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).ToList();
  14205. if (_EnterExitCosts == null) return Ok(JsonView(400, "该团组未填写出入境费用;", ""));
  14206. var currencyInit = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToList();
  14207. var enterExitCostCurrencys = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(_EnterExitCosts.CurrencyRemark);
  14208. //数据源
  14209. // 住宿费
  14210. var dac1 = _EnterExitCosts.ChoiceThree == 1 ? _DayAndCosts.Where(it => it.Type == 1).ToList() : new List<Grp_DayAndCost>();
  14211. // 伙食费
  14212. var dac2 = _EnterExitCosts.ChoiceFour == 1 ? _DayAndCosts.Where(it => it.Type == 2).ToList() : new List<Grp_DayAndCost>();
  14213. // 公杂费
  14214. var dac3 = _EnterExitCosts.ChoiceFive == 1 ? _DayAndCosts.Where(it => it.Type == 3).ToList() : new List<Grp_DayAndCost>();
  14215. // 培训费
  14216. var dac4 = _EnterExitCosts.ChoiceSix == 1 ? _DayAndCosts.Where(it => it.Type == 4).ToList() : new List<Grp_DayAndCost>();
  14217. // 其他款项费
  14218. var dac5 = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  14219. .LeftJoin<Sys_SetData>((x, a) => a.IsDel == 0 && a.Id == x.SetDataId)
  14220. .LeftJoin<Sys_SetData>((x, a, b) => b.IsDel == 0 && b.Id == x.Currency)
  14221. .Where((x, a, b) => x.IsDel == 0 && x.Diid == dto.DiId)
  14222. .Select((x, a, b) => new
  14223. {
  14224. x.Index,
  14225. itemName = a.Name,
  14226. CurrencyStr = b.Name,
  14227. x.Cost,
  14228. x.SubTotal,
  14229. x.Remark
  14230. })
  14231. .OrderBy((x) => x.Index)
  14232. .ToList();
  14233. var peiceItemCurrencys = new List<string>();
  14234. if (_DayAndCosts.Any())
  14235. {
  14236. var currencyIds = _DayAndCosts.Select(x => x.Currency).Distinct().ToList();
  14237. if (currencyIds.Any()) peiceItemCurrencys.AddRange(currencyInit.Where(x => currencyIds.Contains(x.Id)).Select(x => x.Name).ToList());
  14238. }
  14239. if (dac5.Any()) peiceItemCurrencys.AddRange(dac5.Select(x => x.CurrencyStr).Distinct().ToList());
  14240. var peiceItemCurrencyInfos = new List<CurrencyInfo>();
  14241. if (enterExitCostCurrencys.Any() && peiceItemCurrencys.Any())
  14242. {
  14243. peiceItemCurrencyInfos = enterExitCostCurrencys.Where(x => peiceItemCurrencys.Contains(x.CurrencyCode)).ToList();
  14244. }
  14245. var _CurrDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  14246. var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == dto.DiId).First();
  14247. if (_DelegationInfo == null)
  14248. {
  14249. return Ok(JsonView(400, "团组信息为空!", ""));
  14250. }
  14251. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  14252. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  14253. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  14254. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
  14255. .Select((tcl, dc, cc) => new ClientInfo
  14256. {
  14257. LastName = dc.LastName,
  14258. FirstName = dc.FirstName,
  14259. Sex = dc.Sex,
  14260. Birthday = dc.BirthDay,
  14261. Company = cc.CompanyFullName,
  14262. Job = dc.Job
  14263. })
  14264. .ToList();
  14265. foreach (var item in DeleClientList)
  14266. {
  14267. EncryptionProcessor.DecryptProperties(item);
  14268. }
  14269. var blackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  14270. var threeCodes = _sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList();
  14271. var placeData = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  14272. var rateDatas = await _EnterExitCosts.CurrencyRemark.SplitExchangeRate();
  14273. _DelegationInfo.VisitCountry = _DelegationInfo.VisitCountry.Replace("|", "、");
  14274. if (dto.ExportType == 1) //明细表
  14275. {
  14276. if (dto.SubTypeId == 1005) //1005(默认明细表)
  14277. {
  14278. //获取模板
  14279. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/出入境费用表模板.docx");
  14280. //载入模板
  14281. var doc = new Document(tempPath);
  14282. var builder = new DocumentBuilder(doc);
  14283. var dic = new Dictionary<string, string>();
  14284. decimal stayFeeTotal = _EnterExitCosts.ChoiceThree == 1 ? _DayAndCosts.Where(it => it.Type == 1).Sum(it => it.SubTotal) : 0.00M; // 住宿费
  14285. decimal mealsFeeTotal = _EnterExitCosts.ChoiceFour == 1 ? _DayAndCosts.Where(it => it.Type == 2).Sum(it => it.SubTotal) : 0.00M; // 伙食费费
  14286. decimal miscellaneousFeeTotal = _EnterExitCosts.ChoiceFive == 1 ? _DayAndCosts.Where(it => it.Type == 3).Sum(it => it.SubTotal) : 0.00M; // 公杂费
  14287. decimal tainFeeTotal = _EnterExitCosts.ChoiceSix == 1 ? _DayAndCosts.Where(it => it.Type == 4).Sum(it => it.SubTotal) : 0.00M; // 培训费
  14288. decimal otherPriceTotal = _EnterExitCosts.OtherExpenses_Checked == 1 ? dac5.Sum(x => x.SubTotal) : 0.00M; //其他费用
  14289. decimal insidePayTotal = _EnterExitCosts.ChoiceOne == 1 ? _EnterExitCosts.InsidePay : 0.00M;
  14290. //境内费用(其他费用)
  14291. if (_EnterExitCosts.ChoiceOne == 1)
  14292. {
  14293. string row1 = "";
  14294. if (_EnterExitCosts.Visa > 0)
  14295. {
  14296. //insidePayTotal += _EnterExitCosts.Visa;
  14297. row1 = $"签证费:{_EnterExitCosts.Visa:#0.00} 元/人\r\n";
  14298. //if (!string.IsNullOrEmpty(_EnterExitCosts.VisaRemark))
  14299. //{
  14300. // row1_1 += $"\t签证费用描述: {_EnterExitCosts.VisaRemark} 人民币/人";
  14301. //}
  14302. }
  14303. if (_EnterExitCosts.YiMiao > 0)
  14304. {
  14305. //insidePayTotal += _EnterExitCosts.YiMiao;
  14306. row1 += $"疫苗费:{_EnterExitCosts.YiMiao:#0.00} 元/人\r\n";
  14307. }
  14308. if (_EnterExitCosts.HeSuan > 0)
  14309. {
  14310. //insidePayTotal += _EnterExitCosts.HeSuan;
  14311. row1 += $"核酸检测费:{_EnterExitCosts.HeSuan:#0.00} 元/人\r\n";
  14312. }
  14313. if (_EnterExitCosts.Service > 0)
  14314. {
  14315. //insidePayTotal += _EnterExitCosts.Service;
  14316. row1 += $"服务费:{_EnterExitCosts.Service:#0.00} 元/人\r\n";
  14317. }
  14318. if (_EnterExitCosts.Safe > 0)
  14319. {
  14320. //insidePayTotal += _EnterExitCosts.Safe;
  14321. row1 += $"保险费:{_EnterExitCosts.Safe:#0.00} 元/人\r\n";
  14322. }
  14323. if (_EnterExitCosts.Ticket > 0)
  14324. {
  14325. //insidePayTotal += _EnterExitCosts.Ticket;
  14326. row1 += $"参展门票:{_EnterExitCosts.Ticket:#0.00} 元/人\r\n";
  14327. }
  14328. row1 += $"备注:{_EnterExitCosts.FirstItemRemark}";
  14329. dic.Add("InsidePay", insidePayTotal.ToString("#0.00"));
  14330. dic.Add("Row1Str", row1);
  14331. }
  14332. var airTotalStr = new StringBuilder();
  14333. var airPriceStr = new StringBuilder();
  14334. var cityTrafficLabel = new StringBuilder();
  14335. //经济舱
  14336. if (_EnterExitCosts.SumJJC == 1)
  14337. {
  14338. airTotalStr.AppendFormat($"{_EnterExitCosts.OutsideJJPay:#0.00}元/人(经济舱)");
  14339. airPriceStr.AppendFormat($"{_EnterExitCosts.AirJJ:#0.00}元/人(经济舱)");
  14340. cityTrafficLabel.AppendFormat("经济舱:{0:#0.00} 元/人 ", _EnterExitCosts.CityTranffic);
  14341. }
  14342. //公务舱
  14343. if (_EnterExitCosts.SumGWC == 1)
  14344. {
  14345. airTotalStr.AppendFormat($"{_EnterExitCosts.OutsideGWPay:#0.00} 元/人(公务舱)");
  14346. airPriceStr.AppendFormat($"{_EnterExitCosts.AirGW:#0.00} 元/人(公务舱)");
  14347. cityTrafficLabel.AppendFormat("公务舱:{0:#0.00} 元/人 ", _EnterExitCosts.CityTranffic1);
  14348. }
  14349. //头等舱
  14350. if (_EnterExitCosts.SumTDC == 1)
  14351. {
  14352. airTotalStr.AppendFormat($"{_EnterExitCosts.OutsideTDPay:#0.00} 元/人(头等舱)");
  14353. airPriceStr.AppendFormat($"{_EnterExitCosts.AirTD:#0.00} 元/人(头等舱)");
  14354. cityTrafficLabel.AppendFormat("头等舱:{0:#0.00} 元/人 ", _EnterExitCosts.CityTranffic2);
  14355. }
  14356. //描述
  14357. var remarkLable = new StringBuilder();
  14358. //第二项描述
  14359. remarkLable.Append("备注:");
  14360. if (!string.IsNullOrEmpty(_EnterExitCosts.TwoItemRemark)) remarkLable.AppendFormat(_EnterExitCosts.TwoItemRemark);
  14361. //汇率描述
  14362. if (peiceItemCurrencyInfos.Any())
  14363. {
  14364. remarkLable.AppendLine();
  14365. remarkLable.AppendFormat("汇率描述:");
  14366. foreach (var item in peiceItemCurrencyInfos)
  14367. {
  14368. remarkLable.AppendFormat($"{item.CurrencyName}({item.CurrencyCode}):{item.Rate:#0.0000} ");
  14369. }
  14370. }
  14371. dic.Add("AirTotalStr", airTotalStr.ToString());
  14372. dic.Add("AirPriceStr", airPriceStr.ToString());
  14373. dic.Add("CityTranffic", cityTrafficLabel.ToString());
  14374. dic.Add("TwoItemRemark", remarkLable.ToString());
  14375. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  14376. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  14377. int table1Row = 0,
  14378. table2Row = 0,
  14379. table3Row = 0,
  14380. table4Row = 0,
  14381. table5Row = 0;
  14382. //住宿费
  14383. if (_EnterExitCosts.ChoiceThree == 1)
  14384. {
  14385. dic.Add("SubZS", stayFeeTotal.ToString("#0.00"));
  14386. table1Row = dac1.Count;
  14387. #region 填充word表格内容
  14388. for (int i = 0; i < dac1.Count; i++)
  14389. {
  14390. Grp_DayAndCost dac = dac1[i];
  14391. if (dac == null) continue;
  14392. builder.MoveToCell(0, i, 0, 0);
  14393. builder.Write("第" + dac.Days.ToString() + "晚:");
  14394. builder.MoveToCell(0, i, 1, 0);
  14395. //builder.Write(placeData.Find(it => it.Id == dac.NationalTravelFeeId)?.Country ?? "Unknown");
  14396. //builder.Write(dac.Place == null ? "" : dac.Place);
  14397. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  14398. builder.MoveToCell(0, i, 2, 0);
  14399. builder.Write("费用标准:");
  14400. string curr = "";
  14401. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  14402. if (currData != null)
  14403. {
  14404. curr = currData.Name;
  14405. }
  14406. builder.MoveToCell(0, i, 3, 0);
  14407. builder.Write(dac.Cost.ToString("#0.00") + curr);
  14408. builder.MoveToCell(0, i, 4, 0);
  14409. builder.Write("费用小计:");
  14410. builder.MoveToCell(0, i, 5, 0);
  14411. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  14412. }
  14413. #endregion
  14414. }
  14415. else dic.Add("SubZS", "0.00");
  14416. //删除多余行
  14417. while (table1 != null && table1.Rows.Count > table1Row)
  14418. {
  14419. table1.Rows.RemoveAt(table1Row);
  14420. }
  14421. //伙食费
  14422. Aspose.Words.Tables.Table table2 = allTables[1] as Aspose.Words.Tables.Table;
  14423. if (_EnterExitCosts.ChoiceFour == 1)
  14424. {
  14425. dic.Add("SubHS", mealsFeeTotal.ToString("#0.00"));
  14426. table2Row = dac2.Count;
  14427. #region 填充word表格内容
  14428. for (int i = 0; i < dac2.Count; i++)
  14429. {
  14430. Grp_DayAndCost dac = dac2[i];
  14431. if (dac == null) continue;
  14432. builder.MoveToCell(1, i, 0, 0);
  14433. builder.Write("第" + dac.Days.ToString() + "天:");
  14434. builder.MoveToCell(1, i, 1, 0);
  14435. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  14436. builder.MoveToCell(1, i, 2, 0);
  14437. builder.Write("费用标准:");
  14438. string curr = "";
  14439. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  14440. if (currData != null)
  14441. {
  14442. curr = currData.Name;
  14443. }
  14444. builder.MoveToCell(1, i, 3, 0);
  14445. builder.Write(dac.Cost.ToString("#0.00") + curr);
  14446. builder.MoveToCell(1, i, 4, 0);
  14447. builder.Write("费用小计:");
  14448. builder.MoveToCell(1, i, 5, 0);
  14449. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  14450. }
  14451. #endregion
  14452. }
  14453. else dic.Add("SubHS", "0.00");
  14454. //删除多余行
  14455. while (table2 != null && table2.Rows.Count > table2Row)
  14456. {
  14457. table2.Rows.RemoveAt(table2Row);
  14458. }
  14459. //公杂费
  14460. Aspose.Words.Tables.Table table3 = allTables[2] as Aspose.Words.Tables.Table;
  14461. if (_EnterExitCosts.ChoiceFive == 1)
  14462. {
  14463. dic.Add("SubGZF", miscellaneousFeeTotal.ToString("#0.00"));
  14464. table3Row = dac3.Count;
  14465. #region 填充word表格内容
  14466. for (int i = 0; i < dac3.Count; i++)
  14467. {
  14468. Grp_DayAndCost dac = dac3[i];
  14469. if (dac == null) continue;
  14470. builder.MoveToCell(2, i, 0, 0);
  14471. builder.Write("第" + dac.Days.ToString() + "天:");
  14472. builder.MoveToCell(2, i, 1, 0);
  14473. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  14474. builder.MoveToCell(2, i, 2, 0);
  14475. builder.Write("费用标准:");
  14476. string curr = "";
  14477. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  14478. if (currData != null)
  14479. {
  14480. curr = currData.Name;
  14481. }
  14482. builder.MoveToCell(2, i, 3, 0);
  14483. builder.Write(dac.Cost.ToString("#0.00") + curr);
  14484. builder.MoveToCell(2, i, 4, 0);
  14485. builder.Write("费用小计:");
  14486. builder.MoveToCell(2, i, 5, 0);
  14487. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  14488. }
  14489. //删除多余行
  14490. while (table3.Rows.Count > table3Row)
  14491. {
  14492. table3.Rows.RemoveAt(table3Row);
  14493. }
  14494. #endregion
  14495. }
  14496. else dic.Add("SubGZF", "0.00");
  14497. //删除多余行
  14498. while (table3 != null && table3.Rows.Count > table3Row)
  14499. {
  14500. table3.Rows.RemoveAt(table3Row);
  14501. }
  14502. //培训费
  14503. Aspose.Words.Tables.Table table4 = allTables[3] as Aspose.Words.Tables.Table;
  14504. if (_EnterExitCosts.ChoiceSix == 1)
  14505. {
  14506. string pxStr = $"六、培训费合计: {tainFeeTotal:#0.00} 元/人";
  14507. dic.Add("SubPX", pxStr);
  14508. table4Row = dac4.Count;
  14509. #region 填充word表格内容
  14510. for (int i = 0; i < dac4.Count; i++)
  14511. {
  14512. Grp_DayAndCost dac = dac4[i];
  14513. if (dac == null) continue;
  14514. builder.MoveToCell(3, i, 0, 0);
  14515. builder.Write("第" + dac.Days.ToString() + "天:");
  14516. builder.MoveToCell(3, i, 1, 0);
  14517. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  14518. builder.MoveToCell(3, i, 2, 0);
  14519. builder.Write("费用标准:");
  14520. string curr = "";
  14521. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  14522. if (currData != null)
  14523. {
  14524. curr = currData.Name;
  14525. }
  14526. builder.MoveToCell(3, i, 3, 0);
  14527. builder.Write(dac.Cost.ToString("#0.00") + curr);
  14528. builder.MoveToCell(3, i, 4, 0);
  14529. builder.Write("费用小计:");
  14530. builder.MoveToCell(3, i, 5, 0);
  14531. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  14532. }
  14533. #endregion
  14534. }
  14535. //else dic.Add("SubPX", $"六、培训费合计: 0.00 元/人");
  14536. //删除多余行
  14537. while (table4 != null && table4.Rows.Count > table4Row)
  14538. {
  14539. table4.Rows.RemoveAt(table4Row);
  14540. }
  14541. //其他费用
  14542. Aspose.Words.Tables.Table table5 = allTables[4] as Aspose.Words.Tables.Table;
  14543. if (_EnterExitCosts.OtherExpenses_Checked == 1)
  14544. {
  14545. string qtStr = $"七、其他费用合计: {otherPriceTotal:#0.00} 元/人";
  14546. dic.Add("titleQi", qtStr);
  14547. table5Row = dac5.Count;
  14548. #region 填充word表格内容
  14549. for (int i = 0; i < dac5.Count; i++)
  14550. {
  14551. var dac = dac5[i];
  14552. if (dac == null) continue;
  14553. builder.MoveToCell(4, i, 0, 0);
  14554. builder.Write("第" + dac.Index.ToString() + "项:");
  14555. builder.MoveToCell(4, i, 1, 0);
  14556. builder.Write(dac.itemName);
  14557. builder.MoveToCell(4, i, 2, 0);
  14558. builder.Write("费用标准:");
  14559. builder.MoveToCell(4, i, 3, 0);
  14560. builder.Write(dac.Cost.ToString("#0.00") + dac.CurrencyStr);
  14561. builder.MoveToCell(4, i, 4, 0);
  14562. builder.Write("费用小计:");
  14563. builder.MoveToCell(4, i, 5, 0);
  14564. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  14565. builder.MoveToCell(4, i, 6, 0);
  14566. builder.Write("备注:");
  14567. builder.MoveToCell(4, i, 7, 0);
  14568. builder.Write(dac.Remark);
  14569. }
  14570. #endregion
  14571. }
  14572. //else dic.Add("SubQT", "七、其他费用合计: 0 元/人");
  14573. //删除多余行
  14574. while (table5 != null && table5.Rows.Count > table5Row)
  14575. {
  14576. table5.Rows.RemoveAt(table5Row);
  14577. }
  14578. //加上其他费用
  14579. decimal otherFeeTotal = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + otherPriceTotal;
  14580. decimal subJJC = 0.00M,
  14581. subGWC = 0.00M,
  14582. subTDC = 0.00M;
  14583. //全部费用总计: 元 / 人(经济舱) 元 / 人(公务舱) 元 / 人(头等舱)
  14584. string totalLabel = string.Format("全部费用总计:");
  14585. //经济舱
  14586. if (_EnterExitCosts.SumJJC == 1)
  14587. {
  14588. subJJC = otherFeeTotal + _EnterExitCosts.OutsideJJPay;
  14589. totalLabel += $"{subJJC:#0.00} 元/人(经济舱)";
  14590. }
  14591. //公务舱
  14592. if (_EnterExitCosts.SumGWC == 1)
  14593. {
  14594. subGWC = otherFeeTotal + _EnterExitCosts.OutsideGWPay;
  14595. totalLabel += $"{subGWC:#0.00} 元/人(公务舱)";
  14596. }
  14597. //头等舱
  14598. if (_EnterExitCosts.SumTDC == 1)
  14599. {
  14600. subTDC = otherFeeTotal + _EnterExitCosts.OutsideTDPay;
  14601. totalLabel += $"{subTDC:#0.00} 元/人(头等舱)";
  14602. }
  14603. //TotalLabel
  14604. dic.Add("TotalLabel", totalLabel);
  14605. //dic.Add("SubJJC", subJJC.ToString("#0.00"));
  14606. //dic.Add("SubGWC", subGWC.ToString("#0.00"));
  14607. //dic.Add("SubTDC", subTDC.ToString("#0.00"));
  14608. #region 填充word模板书签内容
  14609. foreach (var key in dic.Keys)
  14610. {
  14611. Bookmark bookmark = doc.Range.Bookmarks[key];
  14612. if (bookmark != null)
  14613. {
  14614. builder.MoveToBookmark(key);
  14615. builder.Write(dic[key]);
  14616. }
  14617. }
  14618. #endregion
  14619. #region 设置页眉
  14620. string userLabel = string.Empty;
  14621. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  14622. if (currUserInfo != null)
  14623. {
  14624. var userInfo = await _usersRep.GetUserBriefInfo(currUserInfo.UserId);
  14625. if (userInfo != null)
  14626. {
  14627. string ext = string.IsNullOrEmpty(userInfo.ExtensionNumber) ? "-" : userInfo.ExtensionNumber;
  14628. //userLabel = $"联系人:{userInfo.Name} 职位:{userInfo.Job}\r\n座机/分机号:{ext} 手机号:{userInfo.Tel} 公司邮箱:{userInfo.Email}";
  14629. userLabel = $"联系人:{userInfo.Name} 职 位:{userInfo.Job} 手机号:{userInfo.Tel}\r\n公司邮箱:{userInfo.Email}";
  14630. }
  14631. }
  14632. //设置页脚
  14633. //GeneralMethod.AsposeWordSetFooter(builder, userLabel, "华文仿宋", 10);
  14634. #endregion
  14635. var guid = CommonFun.GUID.Substring(0, 8);
  14636. //文件名
  14637. string strFileName = CommonFun.ValidFileName($"{_DelegationInfo.TeamName}出入境费用{guid}.docx");
  14638. AsposeHelper.removewatermark_v2180();
  14639. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  14640. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  14641. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  14642. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  14643. }
  14644. else if (dto.SubTypeId == 1006)//1006(因公出国(境)经费测算明细表)
  14645. {
  14646. //获取模板
  14647. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/因公出国(境)经费测算明细表.docx");
  14648. //载入模板
  14649. var doc = new Document(tempPath);
  14650. var builder = new DocumentBuilder(doc);
  14651. var dic = new Dictionary<string, string>();
  14652. if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  14653. {
  14654. var list = new List<string>();
  14655. try
  14656. {
  14657. var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  14658. foreach (var item in spilitArr)
  14659. {
  14660. var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  14661. var depCode = spDotandEmpty[2].Substring(0, 3);
  14662. var arrCode = spDotandEmpty[2].Substring(3, 3);
  14663. string depName = threeCodes.Find(it => it.Three.Equals(depCode)).City,
  14664. arrName = threeCodes.Find(it => it.Three.Equals(arrCode)).City;
  14665. list.Add(depName);
  14666. list.Add(arrName);
  14667. }
  14668. list = list.Distinct().ToList();
  14669. dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  14670. }
  14671. catch (Exception)
  14672. {
  14673. dic.Add("ReturnCode", "行程录入不正确!");
  14674. }
  14675. }
  14676. else
  14677. {
  14678. dic.Add("ReturnCode", "未录入行程!");
  14679. }
  14680. dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  14681. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  14682. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  14683. if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  14684. {
  14685. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  14686. dic.Add("Day", sp.Days.ToString());
  14687. }
  14688. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  14689. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  14690. //var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  14691. //dic.Add("Names", Names);
  14692. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  14693. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  14694. decimal dac1totalPrice = 0.00M;
  14695. int accommodationStartIndex = 6, foodandotherStartIndex = 22;
  14696. foreach (var dac in dac1)
  14697. {
  14698. if (dac.SubTotal == 0.00M)
  14699. {
  14700. continue;
  14701. }
  14702. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  14703. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  14704. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  14705. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  14706. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  14707. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  14708. builder.Write(currency);//币种
  14709. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  14710. builder.Write(dac.Cost.ToString("#0.00"));//标准
  14711. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  14712. builder.Write("");//人数
  14713. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  14714. builder.Write("");//天数
  14715. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  14716. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  14717. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  14718. decimal rate = 0.00M;
  14719. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  14720. builder.Write(rate.ToString("#0.0000"));//汇率
  14721. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  14722. decimal rbmPrice = dac.SubTotal;
  14723. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  14724. accommodationStartIndex++;
  14725. dac1totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  14726. }
  14727. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  14728. for (int i = 21; i > (dac1.Count == 0 ? 1 : dac1.Count) + 6; i--)
  14729. {
  14730. table1.Rows.RemoveAt(i - 1);
  14731. foodandotherStartIndex--;
  14732. }
  14733. if (dac2.Count == dac3.Count)//国家 币种 金额
  14734. {
  14735. for (int i = 0; i < dac2.Count; i++)
  14736. {
  14737. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  14738. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  14739. }
  14740. }
  14741. decimal dac2totalPrice = 0.00M;
  14742. foreach (var dac in dac2)
  14743. {
  14744. if (dac.SubTotal == 0)
  14745. {
  14746. continue;
  14747. }
  14748. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  14749. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  14750. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  14751. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  14752. builder.Write(currency);//币种
  14753. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  14754. builder.Write(dac.Cost.ToString("#0.00"));//标准
  14755. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  14756. builder.Write("");//人数
  14757. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  14758. builder.Write("");//天数
  14759. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  14760. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  14761. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  14762. decimal rate = 0.00M;
  14763. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  14764. builder.Write(rate.ToString("#0.0000"));//汇率
  14765. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  14766. decimal rbmPrice = dac.SubTotal;
  14767. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  14768. foodandotherStartIndex++;
  14769. dac2totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  14770. }
  14771. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  14772. for (int i = foodandotherStartIndex + (15 - dac2.Count); i > (dac2.Count == 0 ? 1 : 0) + foodandotherStartIndex; i--)
  14773. {
  14774. table1.Rows.RemoveAt(i - 1);
  14775. }
  14776. var cityTrafficLabel = new StringBuilder()
  14777. .AppendFormat(" 经济舱:{0:#0.00} 元", _EnterExitCosts.CityTranffic)
  14778. .AppendFormat(" 公务舱:{0:#0.00} 元", _EnterExitCosts.CityTranffic1)
  14779. .AppendFormat(" 头等舱:{0:#0.00} ", _EnterExitCosts.CityTranffic2)
  14780. .ToString();
  14781. dic.Add("CityTranffic", cityTrafficLabel);
  14782. string otherFeeStr = "";
  14783. if (_EnterExitCosts.Visa > 0) otherFeeStr += $"签证费:{_EnterExitCosts.Visa:#0.00} 元,";
  14784. if (_EnterExitCosts.Safe > 0) otherFeeStr += $"保险费:{_EnterExitCosts.Safe:#0.00} 元,";
  14785. if (_EnterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费:{_EnterExitCosts.Ticket:#0.00} 元,";
  14786. #region 其他款项费用 增加位置:模板第6项其他费用字符串追加
  14787. foreach (var otherInfo in dac5)
  14788. {
  14789. otherFeeStr += $"{otherInfo.itemName}:{otherInfo.SubTotal.ToString("#0.00")} 元,";
  14790. }
  14791. #endregion
  14792. if (otherFeeStr.Length > 0)
  14793. {
  14794. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  14795. otherFeeStr = $"({otherFeeStr})";
  14796. dic.Add("OtherFeeStr", otherFeeStr);
  14797. }
  14798. //总计
  14799. decimal allPrice = dac1totalPrice + dac2totalPrice + _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket;
  14800. //国际旅费
  14801. string outsideAir = string.Empty;
  14802. string allPriceAir = string.Empty;
  14803. if (_EnterExitCosts.SumJJC == 1)
  14804. {
  14805. outsideAir += string.Format(@"经济舱:{0} 元/人;", _EnterExitCosts.AirJJ.ToString("#0.00"));
  14806. allPriceAir += string.Format(@"经济舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideJJPay).ToString("#0.00"));
  14807. }
  14808. if (_EnterExitCosts.SumGWC == 1)
  14809. {
  14810. outsideAir += string.Format(@"公务舱:{0} 元/人;", _EnterExitCosts.AirGW.ToString("#0.00"));
  14811. allPriceAir += string.Format(@"公务舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  14812. }
  14813. if (_EnterExitCosts.SumTDC == 1)
  14814. {
  14815. outsideAir += string.Format(@"头等舱:{0} 元/人;", _EnterExitCosts.AirTD.ToString("#0.00"));
  14816. allPriceAir += string.Format(@"头等舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideTDPay).ToString("#0.00"));
  14817. }
  14818. dic.Add("InTravelPrice", $"({outsideAir})");
  14819. dic.Add("FinalSumPrice", $"({allPriceAir})");
  14820. //dic.Add("VisaPay", _EnterExitCosts.Visa.ToString("#0.00"));
  14821. //dic.Add("SafePay", _EnterExitCosts.Safe.ToString("#0.00"));
  14822. //dic.Add("YiMiao", _EnterExitCosts.YiMiao.ToString("#0.00"));
  14823. foreach (var key in dic.Keys)
  14824. {
  14825. builder.MoveToBookmark(key);
  14826. builder.Write(dic[key]);
  14827. }
  14828. //模板文件名
  14829. string strFileName = $"{_DelegationInfo.TeamName}因公出国(境)经费测算明细表{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
  14830. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  14831. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  14832. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  14833. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  14834. }
  14835. else if (dto.SubTypeId == 1007) //1007(四川省商务厅出国经费财政先行审核表)
  14836. {
  14837. //获取模板
  14838. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/四川省商务厅出国经费财政先行审核表.xls");
  14839. //载入模板
  14840. var designer = new WorkbookDesigner
  14841. {
  14842. Workbook = new Workbook(tempPath)
  14843. };
  14844. var dic = new Dictionary<string, string>();
  14845. if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  14846. {
  14847. var list = new List<string>();
  14848. try
  14849. {
  14850. var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  14851. foreach (var item in spilitArr)
  14852. {
  14853. var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  14854. var depCode = spDotandEmpty[2].Substring(0, 3);
  14855. var arrCode = spDotandEmpty[2].Substring(3, 3);
  14856. string depName = threeCodes.Find(it => it.Three.Equals(depCode))?.City ?? "Unknwon",
  14857. arrName = threeCodes.Find(it => it.Three.Equals(arrCode))?.City ?? "Unknown";
  14858. list.Add(depName);
  14859. list.Add(arrName);
  14860. }
  14861. list = list.Distinct().ToList();
  14862. dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  14863. }
  14864. catch (Exception)
  14865. {
  14866. dic.Add("ReturnCode", "行程录入不正确!");
  14867. }
  14868. }
  14869. else
  14870. {
  14871. dic.Add("ReturnCode", "未录入行程!");
  14872. }
  14873. dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  14874. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  14875. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  14876. if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  14877. {
  14878. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  14879. dic.Add("Day", sp.Days.ToString());
  14880. }
  14881. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  14882. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  14883. var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  14884. designer.SetDataSource("ClientUnit", _DelegationInfo.ClientUnit);
  14885. designer.SetDataSource("VisitCountry", _DelegationInfo.VisitCountry);
  14886. designer.SetDataSource("Group", _DelegationInfo.TeamName);
  14887. designer.SetDataSource("ClientUnitTitle", _DelegationInfo.TeamName);
  14888. designer.SetDataSource("Name", Names);
  14889. designer.SetDataSource("VisitStartDate", dic["VisitStartDate"] + "-" + dic["VisitEndDate"]);
  14890. designer.SetDataSource("Day", dic["Day"] + "天");
  14891. designer.SetDataSource("ReturnCode", dic["ReturnCode"]);
  14892. designer.SetDataSource("ReturnCodeAir", dic["ReturnCodeAir"]);
  14893. int startIndex = 10;
  14894. const int startIndexcopy = 10;
  14895. if (dac2.Count == dac3.Count)//国家 币种 金额
  14896. {
  14897. for (int i = 0; i < dac2.Count; i++)
  14898. {
  14899. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  14900. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  14901. }
  14902. }
  14903. var dtdac1 = new DataTable();
  14904. var place = new List<string>();
  14905. dtdac1.Columns.AddRange(new DataColumn[] {
  14906. new(){ ColumnName = "city"},
  14907. new(){ ColumnName = "curr"},
  14908. new(){ ColumnName = "criterion"},
  14909. new(){ ColumnName = "number",DataType = typeof(int)},
  14910. new(){ ColumnName = "day",DataType = typeof(int)},
  14911. new(){ ColumnName = "cost", DataType = typeof(decimal)},
  14912. new(){ ColumnName = "rate", DataType = typeof(decimal) },
  14913. new(){ ColumnName = "costRMB", DataType = typeof(decimal) },
  14914. });
  14915. var dtdac2 = new DataTable();
  14916. dtdac2.Columns.AddRange(new DataColumn[] {
  14917. new(){ ColumnName = "city"},
  14918. new(){ ColumnName = "curr"},
  14919. new(){ ColumnName = "criterion"},
  14920. new(){ ColumnName = "number",DataType = typeof(int)},
  14921. new(){ ColumnName = "day",DataType = typeof(int)},
  14922. new(){ ColumnName = "cost", DataType = typeof(decimal)},
  14923. new(){ ColumnName = "rate", DataType = typeof(decimal) },
  14924. new(){ ColumnName = "costRMB",DataType = typeof(decimal)},
  14925. });
  14926. dtdac1.TableName = "tb1";
  14927. dtdac2.TableName = "tb2";
  14928. decimal dac1totalPrice = 0.00M, dac2totalPrice = 0.00M;
  14929. foreach (var item in dac1)
  14930. {
  14931. item.Place = GetEnterExitCostExportCity(placeData, item.NationalTravelFeeId);
  14932. if (place.Contains(item.Place))
  14933. {
  14934. continue;
  14935. }
  14936. DataRow row = dtdac1.NewRow();
  14937. row["city"] = item.Place;
  14938. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  14939. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  14940. row["curr"] = currency;
  14941. row["rate"] = rate.ToString("#0.0000");
  14942. row["criterion"] = item.Cost.ToString("#0.00");
  14943. row["number"] = 1;
  14944. row["day"] = dac1.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  14945. //row["costRMB"] = rbmPrice;
  14946. dtdac1.Rows.Add(row);
  14947. place.Add(item.Place);
  14948. }
  14949. place = new List<string>();
  14950. foreach (var item in dac2)
  14951. {
  14952. item.Place = GetEnterExitCostExportCity(placeData, item.NationalTravelFeeId);
  14953. if (place.Contains(item.Place))
  14954. {
  14955. continue;
  14956. }
  14957. DataRow row = dtdac2.NewRow();
  14958. row["city"] = item.Place;
  14959. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  14960. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  14961. row["curr"] = currency;
  14962. row["rate"] = rate.ToString("#0.0000");
  14963. row["criterion"] = item.Cost.ToString("#0.00");
  14964. row["number"] = 1;
  14965. row["day"] = dac2.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  14966. //row["cost"] = item.SubTotal;
  14967. //row["costRMB"] = rbmPrice;
  14968. dtdac2.Rows.Add(row);
  14969. place.Add(item.Place);
  14970. //dac2totalPrice += rbmPrice;
  14971. }
  14972. dac1totalPrice = dac1.Sum(it => it.SubTotal);
  14973. dac2totalPrice = dac2.Sum(it => it.SubTotal);
  14974. designer.SetDataSource("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  14975. designer.SetDataSource("dac2totalPrice", dac2totalPrice);
  14976. var cityTrafficLabel = new StringBuilder()
  14977. .AppendFormat(" 其中:国外城市间")
  14978. .AppendFormat(" 经济舱费:{0:#0.00} 元、", _EnterExitCosts.CityTranffic)
  14979. .AppendFormat(" 公务舱费:{0:#0.00} 元、", _EnterExitCosts.CityTranffic1)
  14980. .AppendFormat(" 头等舱费:{0:#0.00} 元", _EnterExitCosts.CityTranffic2)
  14981. .ToString();
  14982. //decimal cityTraffic =_EnterExitCosts.CityTranffic + _EnterExitCosts.CityTranffic1 + _EnterExitCosts.CityTranffic2;
  14983. designer.SetDataSource("cityTranffic", cityTrafficLabel);
  14984. // designer.SetDataSource("sumCityTranffic", @$"{cityTraffic:#0.00} ");
  14985. string cell4Str1 = string.Empty;
  14986. if (_EnterExitCosts.SumJJC == 1) cell4Str1 += $"经济舱:{_EnterExitCosts.AirJJ:#0.00} 元/人;";
  14987. if (_EnterExitCosts.SumGWC == 1) cell4Str1 += $"公务舱:{_EnterExitCosts.AirGW:#0.00} 元/人;";
  14988. if (_EnterExitCosts.SumTDC == 1) cell4Str1 += $"公务舱:{_EnterExitCosts.AirTD:#0.00} 元/人;";
  14989. string cell4Str = $" 4.国际旅费:{cell4Str1}";
  14990. string cellStr = $" 5.其他费用(";
  14991. if (_EnterExitCosts.Visa > 0) cellStr += $"签证费:{_EnterExitCosts.Visa:#0.00}元,";
  14992. if (_EnterExitCosts.YiMiao > 0) cellStr += $"疫苗费:{_EnterExitCosts.YiMiao:#0.00}元,";
  14993. if (_EnterExitCosts.HeSuan > 0) cellStr += $"核酸费:{_EnterExitCosts.HeSuan:#0.00}元,";
  14994. if (_EnterExitCosts.Safe > 0) cellStr += $"保险费:{_EnterExitCosts.Safe:#0.00}元,";
  14995. if (_EnterExitCosts.Ticket > 0) cellStr += $"参展门票费:{_EnterExitCosts.Ticket:#0.00}元,";
  14996. if (_EnterExitCosts.Service > 0) cellStr += $"服务费:{_EnterExitCosts.Service:#0.00}元,";
  14997. #region 其他款项费用 增加位置:模板第5项其他费用字符串追加
  14998. var otherPriceTotal = dac5.Sum(x => x.SubTotal);
  14999. foreach (var otherInfo in dac5)
  15000. {
  15001. cellStr += $"{otherInfo.itemName}:{otherInfo.SubTotal.ToString("#0.00")} 元,";
  15002. }
  15003. #endregion
  15004. if (cellStr.Length > 8)
  15005. {
  15006. cellStr = cellStr.Substring(0, cellStr.Length - 1);
  15007. }
  15008. cellStr += ")";
  15009. decimal otherFee = _EnterExitCosts.Visa + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.Service + otherPriceTotal;
  15010. decimal s = dac1totalPrice + dac2totalPrice + _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay + otherFee;
  15011. decimal pxFee = dac4.Sum(it => it.Cost);
  15012. decimal glvFee = _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay;
  15013. string celllastStr1 = "";
  15014. if (dac1totalPrice > 0) celllastStr1 += $"住宿费 {dac1totalPrice:#0.00} 元";
  15015. if (dac2totalPrice > 0) celllastStr1 += $",伙食费和公杂费 {dac2totalPrice:#0.00} 元";
  15016. if (pxFee > 0) celllastStr1 += $",培训费 {pxFee:#0.00} 元";
  15017. celllastStr1 += $",国际旅费 元";
  15018. if (otherFee > 0) celllastStr1 += $",其他费用 {otherFee:#0.00} 元";
  15019. string celllastStr = $" 经审核,{celllastStr1},本次出国经费预算合计为 元。其中:市本级安排 。";
  15020. designer.SetDataSource("cell4Str", cell4Str);
  15021. designer.SetDataSource("cellStr", cellStr);
  15022. designer.SetDataSource("cellSum", otherFee.ToString("#0.00"));
  15023. designer.SetDataSource("cellSum4", (_EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  15024. designer.SetDataSource("celllastStr", celllastStr);
  15025. Workbook wb = designer.Workbook;
  15026. var sheet = wb.Worksheets[0];
  15027. //绑定datatable数据集
  15028. designer.SetDataSource(dtdac1);
  15029. designer.SetDataSource(dtdac2);
  15030. designer.Process();
  15031. var rowStart = dtdac1.Rows.Count;
  15032. while (rowStart > 0)
  15033. {
  15034. sheet.Cells[startIndex, 8].Formula = $"=G{startIndex + 1} * H{startIndex + 1}";
  15035. sheet.Cells[startIndex, 6].Formula = $"=E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  15036. startIndex++;
  15037. rowStart--;
  15038. }
  15039. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + 1}: I{startIndex})";
  15040. startIndex += 1; //总计行
  15041. rowStart = dtdac2.Rows.Count;
  15042. while (rowStart > 0)
  15043. {
  15044. sheet.Cells[startIndex, 8].Formula = $"= G{startIndex + 1} * H{startIndex + 1}";
  15045. sheet.Cells[startIndex, 6].Formula = $"= E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  15046. startIndex++;
  15047. rowStart--;
  15048. }
  15049. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + dtdac1.Rows.Count + 2}: I{startIndex})";
  15050. wb.CalculateFormula(true);
  15051. //模板文件名
  15052. string strFileName = $"{_DelegationInfo.TeamName}-四川省商务厅出国经费财政先行审核表{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  15053. designer.Workbook.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  15054. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  15055. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  15056. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  15057. }
  15058. else if (dto.SubTypeId == 1066) //成都市因公临时出国任务和预算审批意见表(外专培训团专用)
  15059. {
  15060. //获取模板
  15061. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/成都市因公临时出国任务和预算审批意见表.docx");
  15062. //载入模板
  15063. var doc = new Document(tempPath);
  15064. var builder = new DocumentBuilder(doc);
  15065. var dic = new Dictionary<string, string>
  15066. {
  15067. { "GroupName", _DelegationInfo.TeamName },
  15068. { "ClientUnit", _DelegationInfo.ClientUnit }
  15069. };
  15070. string missionLeader = ""; //团负责人默认接团客户名单第一个人
  15071. string missionLeaderJob = "";//负责人job
  15072. //int groupNumber = 0; //团人数
  15073. if (DeleClientList.Count > 0)
  15074. {
  15075. missionLeader = DeleClientList[0]?.Name ?? "";
  15076. missionLeaderJob = DeleClientList[0]?.Job ?? "";
  15077. }
  15078. dic.Add("MissionLeader", missionLeader); //团负责人
  15079. dic.Add("MissionLeaderJob", missionLeaderJob); //团负责人job
  15080. dic.Add("GroupNumber", _DelegationInfo.VisitPNumber.ToString()); //团人数
  15081. #region MyRegion
  15082. //if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  15083. //{
  15084. // List<string> list = new List<string>();
  15085. // try
  15086. // {
  15087. // var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  15088. // foreach (var item in spilitArr)
  15089. // {
  15090. // var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  15091. // var depCode = spDotandEmpty[2].Substring(0, 3);
  15092. // var arrCode = spDotandEmpty[2].Substring(3, 3);
  15093. // string depName = threeCodes.Find(it => it.Three.Equals(depCode)).City,
  15094. // arrName = threeCodes.Find(it => it.Three.Equals(arrCode)).City;
  15095. // list.Add(depName);
  15096. // list.Add(arrName);
  15097. // }
  15098. // list = list.Distinct().ToList();
  15099. // dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  15100. // }
  15101. // catch (Exception)
  15102. // {
  15103. // dic.Add("ReturnCode", "行程录入不正确!");
  15104. // }
  15105. //}
  15106. //else
  15107. //{
  15108. // dic.Add("ReturnCode", "未录入行程!");
  15109. //}
  15110. List<string> countrys = _groupRepository.GroupSplitCountry(_DelegationInfo.VisitCountry);
  15111. dic.Add("ReturnCode", string.Join("、", countrys));
  15112. #endregion
  15113. //dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  15114. //dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  15115. //dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  15116. //if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  15117. //{
  15118. // TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  15119. // dic.Add("Day", sp.Days.ToString());
  15120. //}
  15121. dic.Add("Day", _DelegationInfo.VisitDays.ToString());
  15122. dic.Add("CultivateDay", dac4.Count.ToString()); //培训天数
  15123. // dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  15124. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  15125. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  15126. //培训人员名单
  15127. int cultivateRowIndex = 7;
  15128. foreach (var item in DeleClientList)
  15129. {
  15130. builder.MoveToCell(0, cultivateRowIndex, 0, 0);
  15131. builder.Write(item.Name);
  15132. builder.MoveToCell(0, cultivateRowIndex, 1, 0);
  15133. builder.Write(item.Sex == 0 ? "男" : item.Sex == 1 ? "女" : "");
  15134. builder.MoveToCell(0, cultivateRowIndex, 2, 0);
  15135. string birthDay = "";
  15136. if (item.Birthday != null)
  15137. {
  15138. DateTime dt = Convert.ToDateTime(item.Birthday);
  15139. birthDay = $"{dt.Year}.{dt.Month}";
  15140. }
  15141. builder.Write(birthDay);
  15142. builder.MoveToCell(0, cultivateRowIndex, 3, 0);
  15143. builder.Write(item.Company);
  15144. builder.MoveToCell(0, cultivateRowIndex, 4, 0);
  15145. builder.Write(item.Job);
  15146. cultivateRowIndex++;
  15147. }
  15148. //删除多余行
  15149. //cultivateRowIndex -= 2;
  15150. int delRows = 10 + 7 - cultivateRowIndex;
  15151. if (delRows > 0)
  15152. {
  15153. for (int i = 0; i < delRows; i++)
  15154. {
  15155. table1.Rows.RemoveAt(cultivateRowIndex);
  15156. //cultivateRowIndex++;
  15157. }
  15158. }
  15159. decimal hotelFeeTotal = dac1.Sum(it => it.SubTotal);//住宿费
  15160. dic.Add("HotelFeeTotal", hotelFeeTotal.ToString("#0.00"));
  15161. decimal mealsFeeTotal = dac2.Sum(it => it.SubTotal);//伙食费
  15162. dic.Add("MealsFeeTotal", mealsFeeTotal.ToString("#0.00"));
  15163. decimal miscellaneousFeeTotal = dac3.Sum(it => it.SubTotal);//公杂费
  15164. dic.Add("MiscellaneousFeeTotal", miscellaneousFeeTotal.ToString("#0.00"));
  15165. decimal trainingFeeTotal = dac4.Sum(it => it.SubTotal);//培训费
  15166. dic.Add("TrainingFeeTotal", trainingFeeTotal.ToString("#0.00"));
  15167. //decimal cityTranfficFeeToatal = _EnterExitCosts.CityTranffic; //城市区间交通费
  15168. decimal cityTranfficFeeToatal = 0.00M;
  15169. //dic.Add("CityTranfficFeeToatal", cityTranfficFeeToatal.ToString("#0.00"));
  15170. //其他费用
  15171. decimal otherFeeTotal = _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Service + dac5.Sum(x => x.SubTotal);
  15172. dic.Add("OtherFeeTotal", otherFeeTotal.ToString("#0.00"));
  15173. //其他费用合计
  15174. decimal _otherFeeTotal = hotelFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + trainingFeeTotal + cityTranfficFeeToatal + otherFeeTotal;
  15175. decimal _jjcFeeToatal = _EnterExitCosts.OutsideJJPay + _otherFeeTotal; //经济舱
  15176. decimal _gwcFeeToatal = _EnterExitCosts.OutsideGWPay + _otherFeeTotal; //公务舱
  15177. //公务舱合计
  15178. //国际旅费
  15179. //string outsideJJ = "";
  15180. //string allPriceJJ = "";
  15181. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 0)
  15182. {
  15183. dic.Add("AirFeeTotal", _EnterExitCosts.OutsideJJPay.ToString("#0.00"));
  15184. dic.Add("FeeTotal", _jjcFeeToatal.ToString("#0.00"));
  15185. }
  15186. if (_EnterExitCosts.SumGWC == 1 && _EnterExitCosts.SumJJC == 0)
  15187. {
  15188. dic.Add("AirFeeTotal", _EnterExitCosts.OutsideGWPay.ToString("#0.00"));
  15189. dic.Add("FeeTotal", _gwcFeeToatal.ToString("#0.00"));
  15190. }
  15191. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 1)
  15192. {
  15193. string airFeeTotalStr = string.Format(@$"经济舱:{_EnterExitCosts.OutsideJJPay:#0.00} 公务舱:{_EnterExitCosts.OutsideGWPay:#0.00}");
  15194. dic.Add("AirFeeTotal", airFeeTotalStr);
  15195. string feeTotalStr = string.Format(@$"经济舱:{_jjcFeeToatal:#0.00} 公务舱:{_gwcFeeToatal:#0.00}");
  15196. dic.Add("FeeTotal", feeTotalStr);
  15197. }
  15198. foreach (var key in dic.Keys)
  15199. {
  15200. builder.MoveToBookmark(key);
  15201. builder.Write(dic[key]);
  15202. }
  15203. //模板文件名
  15204. string strFileName = $"{_DelegationInfo.TeamName}-成都市因公临时出国任务和预算审批意见表(外专培训团专用).docx";
  15205. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  15206. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  15207. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  15208. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  15209. }
  15210. }
  15211. else if (dto.ExportType == 2) //表格
  15212. {
  15213. //利用键值对存放数据
  15214. Dictionary<string, string> dic = new Dictionary<string, string>();
  15215. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  15216. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  15217. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  15218. dic.Add("Day", sp.Days.ToString());
  15219. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  15220. if (dto.SubTypeId == 1008) //1008(派员单位出(境)任务和预算审批意见表)
  15221. {
  15222. //获取模板
  15223. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/派员单位出(境)任务和预算审批意见表.docx");
  15224. //载入模板
  15225. var doc = new Document(tempPath);
  15226. var builder = new DocumentBuilder(doc);
  15227. dic.Add("TeamName", _DelegationInfo.TeamName);
  15228. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  15229. //dic.Add("TellPhone", _DelegationInfo.TellPhone);
  15230. string missionLeaderName = "",
  15231. missionLeaderJob = "";
  15232. if (DeleClientList.Count > 0)
  15233. {
  15234. missionLeaderName = DeleClientList[0].Name;
  15235. missionLeaderJob = DeleClientList[0].Job;
  15236. }
  15237. dic.Add("MissionLeaderName", missionLeaderName);
  15238. dic.Add("MissionLeaderJob", missionLeaderJob);
  15239. dic.Add("VisitPNumber", _DelegationInfo.VisitPNumber.ToString());
  15240. dic.Add("VisitPurpose", _DelegationInfo.VisitPurpose);
  15241. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  15242. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  15243. int rowCount = 10;//总人数行
  15244. int startRowIndex = 7; //起始行
  15245. for (int i = 0; i < DeleClientList.Count; i++)
  15246. {
  15247. builder.MoveToCell(0, startRowIndex, 0, 0);
  15248. builder.Write(DeleClientList[i].Name); //出国人员姓名
  15249. builder.MoveToCell(0, startRowIndex, 1, 0);
  15250. string sex = DeleClientList[i].Sex == 0 ? "男" : DeleClientList[i].Sex == 1 ? "女" : "";
  15251. builder.Write(sex);//性别
  15252. builder.MoveToCell(0, startRowIndex, 2, 0);
  15253. builder.Write(Convert.ToDateTime(DeleClientList[i].Birthday).ToString("yyyy年MM月dd日"));//出生年月
  15254. builder.MoveToCell(0, startRowIndex, 3, 0);
  15255. builder.Write(DeleClientList[i].Company);//工作单位
  15256. builder.MoveToCell(0, startRowIndex, 4, 0);
  15257. builder.Write(DeleClientList[i].Job);//职务及级别
  15258. builder.MoveToCell(0, startRowIndex, 5, 0);
  15259. builder.Write("");//人员属性
  15260. builder.MoveToCell(0, startRowIndex, 6, 0);
  15261. builder.Write("");//上次出国时间
  15262. startRowIndex++;
  15263. }
  15264. int nullRow = rowCount - DeleClientList.Count;//空行
  15265. for (int i = 0; i < nullRow; i++)
  15266. {
  15267. table1.Rows.Remove(table1.Rows[startRowIndex]);
  15268. }
  15269. foreach (var key in dic.Keys)
  15270. {
  15271. builder.MoveToBookmark(key);
  15272. builder.Write(dic[key]);
  15273. }
  15274. //模板文件名
  15275. string strFileName = $"派员单位出(境)任务和预算审批意见表.docx";
  15276. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  15277. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  15278. if (dto.PortType == 1) return Ok(JsonView(true, "成功", new { Url = url }));
  15279. else if (dto.PortType == 2 || dto.PortType == 3) return Ok(JsonView(true, "成功", url));
  15280. }
  15281. else if (dto.SubTypeId == 1009)//1009(省级单位出(境)经费报销单)
  15282. {
  15283. //获取模板
  15284. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/省级单位出(境)经费报销单.docx");
  15285. //载入模板
  15286. var doc = new Document(tempPath);
  15287. var builder = new DocumentBuilder(doc);
  15288. dic.Add("GroupClient", _DelegationInfo.ClientUnit);
  15289. var Names = string.Join("、", DeleClientList.Select(x => x.Name)).TrimEnd('、');
  15290. dic.Add("Names", Names);
  15291. int accommodationRows = 12;
  15292. //int foodandotherRows = 12;
  15293. var Dac1currCn = dac1.GroupBy(x => x.Currency).Select(x => x.Key).ToList();
  15294. var Dac2currCn = dac2.GroupBy(x => x.Currency).Select(x => x.Key).ToList();
  15295. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  15296. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  15297. int accommodationStartIndex = 6;
  15298. decimal dac1totalPrice = 0.00M;
  15299. foreach (var dac in dac1)
  15300. {
  15301. if (dac.SubTotal == 0)
  15302. {
  15303. continue;
  15304. }
  15305. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  15306. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  15307. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  15308. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));//城市
  15309. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  15310. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknwon";
  15311. builder.Write(currency);//币种
  15312. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  15313. builder.Write(dac.Cost.ToString("#0.00"));//标准
  15314. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  15315. builder.Write("");//人数
  15316. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  15317. builder.Write("");//天数
  15318. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  15319. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  15320. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  15321. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  15322. builder.Write(rate.ToString("#0.0000"));//汇率
  15323. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  15324. decimal rbmPrice = rate * dac.SubTotal;
  15325. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  15326. accommodationStartIndex++;
  15327. dac1totalPrice += rbmPrice;
  15328. }
  15329. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  15330. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  15331. builder.Write("小计");
  15332. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  15333. builder.Write(dac1totalPrice.ToString("#0.00"));
  15334. accommodationStartIndex++;
  15335. int nullRow = accommodationRows - dac1.Count;
  15336. //删除空行
  15337. //if (nullRow > 0)
  15338. //{
  15339. // int rowIndex = accommodationStartIndex;
  15340. // for (int i = 0; i < nullRow; i++)
  15341. // {
  15342. // Aspose.Words.Tables.Row row = table1.Rows[rowIndex];
  15343. // row.Remove();
  15344. // rowIndex++;
  15345. // }
  15346. //}
  15347. if (dac2.Count == dac3.Count)//国家 币种 金额
  15348. {
  15349. for (int i = 0; i < dac2.Count; i++)
  15350. {
  15351. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  15352. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  15353. }
  15354. }
  15355. int foodandotherStartIndex = 19;//
  15356. decimal dac2totalPrice = 0.00M;
  15357. foreach (var dac in dac2)
  15358. {
  15359. if (dac.SubTotal == 0)
  15360. {
  15361. continue;
  15362. }
  15363. //foodandotherStartIndex = 12;
  15364. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  15365. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));//城市
  15366. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  15367. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknwon";
  15368. builder.Write(currency);//币种
  15369. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  15370. builder.Write(dac.Cost.ToString("#0.00"));//标准
  15371. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  15372. builder.Write("");//人数
  15373. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  15374. builder.Write("");//天数
  15375. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  15376. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  15377. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  15378. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  15379. builder.Write(rate.ToString("#0.0000"));//汇率
  15380. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  15381. decimal rbmPrice = rate * dac.SubTotal;
  15382. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  15383. foodandotherStartIndex++;
  15384. dac2totalPrice += rbmPrice;
  15385. }
  15386. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  15387. Aspose.Words.Tables.Table table2 = allTables[1] as Aspose.Words.Tables.Table;
  15388. //删除空行
  15389. //if (dac2.Count < foodandotherRows)
  15390. //{
  15391. // while (table2.Rows.Count > dac2.Count)
  15392. // {
  15393. // table2.Rows.RemoveAt(dac2.Count);
  15394. // }
  15395. //}
  15396. var citytrafficLable = new StringBuilder()
  15397. .AppendFormat($"经济舱费用:{_EnterExitCosts.CityTranffic:#0.00} 元、")
  15398. .AppendFormat($"公务舱费用:{_EnterExitCosts.CityTranffic1:#0.00}元、")
  15399. .AppendFormat($"头等舱费用:{_EnterExitCosts.CityTranffic2:#0.00}")
  15400. .ToString();
  15401. dic.Add("CityTranffic", citytrafficLable);
  15402. string otherFeeStr = "";
  15403. if (_EnterExitCosts.Visa > 0) otherFeeStr += $"签证费:{_EnterExitCosts.Visa:#0.00}元,";
  15404. if (_EnterExitCosts.YiMiao > 0) otherFeeStr += $"疫苗费:{_EnterExitCosts.YiMiao:#0.00}元,";
  15405. if (_EnterExitCosts.HeSuan > 0) otherFeeStr += $"核酸费:{_EnterExitCosts.HeSuan:#0.00}元,";
  15406. if (_EnterExitCosts.Safe > 0) otherFeeStr += $"保险费:{_EnterExitCosts.Safe:#0.00}元,";
  15407. if (_EnterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费:{_EnterExitCosts.Ticket:#0.00}元,";
  15408. if (_EnterExitCosts.Service > 0) otherFeeStr += $"服务费:{_EnterExitCosts.Service:#0.00}元,";
  15409. #region 其他款项费用 增加位置:模板第6项其他费用字符串追加
  15410. foreach (var otherInfo in dac5)
  15411. {
  15412. otherFeeStr += $"{otherInfo.itemName}:{otherInfo.SubTotal:#0.00} 元,";
  15413. }
  15414. #endregion
  15415. if (otherFeeStr.Length > 0)
  15416. {
  15417. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  15418. otherFeeStr = $"({otherFeeStr})";
  15419. dic.Add("OtherFeeStr", otherFeeStr);
  15420. }
  15421. foreach (var key in dic.Keys)
  15422. {
  15423. builder.MoveToBookmark(key);
  15424. builder.Write(dic[key]);
  15425. }
  15426. //模板文件名
  15427. string strFileName = $"省级单位出(境)经费报销单{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
  15428. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  15429. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  15430. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  15431. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  15432. }
  15433. else if (dto.SubTypeId == 1538)// 1538 省级单位出国经费报销单
  15434. {
  15435. // 获取模板
  15436. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/省级单位出国经费报销单.xls");
  15437. // 载入模板
  15438. var designer = new WorkbookDesigner
  15439. {
  15440. Workbook = new Workbook(tempPath)
  15441. };
  15442. Workbook workbook = designer.Workbook;
  15443. var worksheet1 = workbook.Worksheets[0];
  15444. var worksheet2 = workbook.Worksheets[1];
  15445. var worksheet3 = workbook.Worksheets[2];
  15446. // 日期格式化
  15447. var dateFormat = "yyyy年MM月dd日";
  15448. designer.SetDataSource("DeptOffice", ""); // 处室
  15449. // 报销日期
  15450. var currDateStr = DateTime.Now.ToString(dateFormat);
  15451. designer.SetDataSource("ReimbDate", currDateStr);
  15452. designer.SetDataSource("GroupUnit", _DelegationInfo.ClientUnit); // 组团单位
  15453. // 出国人员姓名
  15454. var overseasName = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  15455. if (string.IsNullOrEmpty(overseasName)) overseasName = "-";
  15456. designer.SetDataSource("OverseasName", overseasName);
  15457. // 国家和地区(含经停)
  15458. string countryRegionStops = _groupRepository.FormartTeamName(_DelegationInfo.VisitCountry);
  15459. designer.SetDataSource("CountryRegionStops", countryRegionStops);
  15460. // 具体线路
  15461. string specificLine = "";
  15462. if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  15463. {
  15464. var list = new List<string>();
  15465. try
  15466. {
  15467. var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  15468. foreach (var item in spilitArr)
  15469. {
  15470. var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  15471. var depCode = spDotandEmpty[2].Substring(0, 3);
  15472. var arrCode = spDotandEmpty[2].Substring(3, 3);
  15473. string depName = threeCodes.Find(it => it.Three.Equals(depCode)).City;
  15474. string arrName = threeCodes.Find(it => it.Three.Equals(arrCode)).City;
  15475. list.Add(depName);
  15476. list.Add(arrName);
  15477. }
  15478. list = list.Distinct().ToList();
  15479. specificLine = string.Join("-", list);
  15480. }
  15481. catch (Exception)
  15482. {
  15483. specificLine = "行程录入不正确!";
  15484. }
  15485. }
  15486. else
  15487. {
  15488. specificLine = "未录入行程!";
  15489. }
  15490. designer.SetDataSource("SpecRoute", specificLine);
  15491. // 出国时间
  15492. string overseasTime = $"{_DelegationInfo.VisitStartDate.ToString(dateFormat)} - {_DelegationInfo.VisitEndDate.ToString(dateFormat)}";
  15493. designer.SetDataSource("OverseasTime", overseasTime);
  15494. // 实际天数
  15495. TimeSpan overseasActualDays_ts = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  15496. designer.SetDataSource("OverseasActualDays", $"{overseasActualDays_ts.Days}天");
  15497. // 数据整理
  15498. // 住宿费
  15499. var accomFees = dac1.GroupBy(x => x.NationalTravelFeeId)
  15500. .Select(group =>
  15501. {
  15502. var currData = group.FirstOrDefault();
  15503. // 币种信息
  15504. var currencyInfo = _CurrDatas.Where(x => x.Id == currData.Currency).FirstOrDefault();
  15505. // 币种名称
  15506. string currencyName = currencyInfo?.Remark ?? "";
  15507. // 币种Code
  15508. string currencyCode = currencyInfo?.Name ?? "";
  15509. // 币种汇率信息
  15510. var currencyRateInfo = enterExitCostCurrencys.Where(x => x.CurrencyName.Equals(currencyName)).FirstOrDefault();
  15511. // 币种汇率
  15512. decimal currencyRate = currencyRateInfo != null ? currencyRateInfo.Rate : 1.00M;
  15513. // 城市信息 Grp_NationalTravelFee
  15514. var placeName = GetEnterExitCostExportCity(placeData, group.Key);
  15515. // 天数
  15516. int totalDays = group.Count();
  15517. // 原始币种小计
  15518. decimal totalAmount = group.Sum(x => x.Cost);
  15519. // 人名币金额
  15520. decimal totalCNY = totalDays * totalAmount * currencyRate;
  15521. return new
  15522. {
  15523. TravelFeeId = group.Key,
  15524. PlaceName = placeName,
  15525. TotalDays = totalDays,
  15526. currData.Cost,
  15527. TotalAmount = totalAmount,
  15528. currData.Currency,
  15529. CurrencyCode = currencyCode,
  15530. CurrencyName = currencyName,
  15531. CurrencyRate = currencyRate,
  15532. TotalCNY = totalCNY,
  15533. Details = group.ToList()
  15534. };
  15535. })
  15536. .ToList();
  15537. // 伙食费和公杂费
  15538. var foodSundCosts = _DayAndCosts.Where(x => x.Type == 2 || x.Type == 3)
  15539. .GroupBy(x => x.NationalTravelFeeId)
  15540. .Select(group =>
  15541. {
  15542. var currData = group.FirstOrDefault();
  15543. // 币种信息
  15544. var currencyInfo = _CurrDatas.Where(x => x.Id == currData.Currency).FirstOrDefault();
  15545. // 币种名称
  15546. string currencyName = currencyInfo?.Remark ?? "";
  15547. // 币种Code
  15548. string currencyCode = currencyInfo?.Name ?? "";
  15549. // 币种汇率信息
  15550. var currencyRateInfo = enterExitCostCurrencys.Where(x => x.CurrencyName.Equals(currencyName)).FirstOrDefault();
  15551. // 币种汇率
  15552. decimal currencyRate = currencyRateInfo != null ? currencyRateInfo.Rate : 1.00M;
  15553. // 城市信息 Grp_NationalTravelFee
  15554. var placeName = GetEnterExitCostExportCity(placeData, group.Key);
  15555. // 天数
  15556. int totalDays = group.Count() / 2;
  15557. // 原始币种小计
  15558. decimal totalAmount = group.Sum(x => x.Cost);
  15559. // 原始伙食费、公杂费单价合计
  15560. decimal cost = totalAmount / totalDays;
  15561. // 人名币金额
  15562. decimal totalCNY = totalDays * totalAmount * currencyRate;
  15563. return new
  15564. {
  15565. TravelFeeId = group.Key,
  15566. PlaceName = placeName,
  15567. TotalDays = totalDays,
  15568. Cost = cost,
  15569. TotalAmount = totalAmount,
  15570. currData.Currency,
  15571. CurrencyCode = currencyCode,
  15572. CurrencyName = currencyName,
  15573. CurrencyRate = currencyRate,
  15574. TotalCNY = totalCNY,
  15575. Details = group.ToList()
  15576. };
  15577. })
  15578. .ToList();
  15579. // 其他费用
  15580. var otherFeestrs = new List<string>();
  15581. decimal totalOtherFee = 0.00M;
  15582. if (_EnterExitCosts.Visa > 0)
  15583. {
  15584. otherFeestrs.Add($"签证费:{_EnterExitCosts.Visa:#0.00}元/人");
  15585. totalOtherFee += _EnterExitCosts.Visa;
  15586. }
  15587. if (_EnterExitCosts.YiMiao > 0)
  15588. {
  15589. otherFeestrs.Add($"疫苗费:{_EnterExitCosts.YiMiao:#0.00}元/人");
  15590. totalOtherFee += _EnterExitCosts.YiMiao;
  15591. }
  15592. if (_EnterExitCosts.HeSuan > 0)
  15593. {
  15594. otherFeestrs.Add($"核酸费:{_EnterExitCosts.HeSuan:#0.00}元/人");
  15595. totalOtherFee += _EnterExitCosts.HeSuan;
  15596. }
  15597. if (_EnterExitCosts.Safe > 0)
  15598. {
  15599. otherFeestrs.Add($"保险费:{_EnterExitCosts.Safe:#0.00}元/人");
  15600. totalOtherFee += _EnterExitCosts.Safe;
  15601. }
  15602. if (_EnterExitCosts.Ticket > 0)
  15603. {
  15604. otherFeestrs.Add($"参展门票费:{_EnterExitCosts.Ticket:#0.00}元/人");
  15605. totalOtherFee += _EnterExitCosts.Ticket;
  15606. }
  15607. if (_EnterExitCosts.Service > 0)
  15608. {
  15609. otherFeestrs.Add($"服务费:{_EnterExitCosts.Service:#0.00}元/人");
  15610. totalOtherFee += _EnterExitCosts.Service;
  15611. }
  15612. #region 其他款项费用 增加位置:模板第5项其他费用字符串追加
  15613. var otherPriceTotal = dac5.Sum(x => x.SubTotal);
  15614. foreach (var otherInfo in dac5)
  15615. {
  15616. otherFeestrs.Add($"{otherInfo.itemName}:{otherInfo.SubTotal:#0.00}元/人");
  15617. totalOtherFee += otherInfo.SubTotal;
  15618. }
  15619. #endregion
  15620. designer.SetDataSource("TotalOtherFeeLabel", $"5.其他费用({string.Join(";", otherFeestrs)})");
  15621. designer.SetDataSource("TotalOtherFee", $"{totalOtherFee:0.00}");
  15622. // 住宿费、伙食费和公杂费合计
  15623. decimal grandTotalFee = foodSundCosts.Sum(x => x.TotalCNY) + foodSundCosts.Sum(x => x.TotalCNY);
  15624. //其他费用合计
  15625. decimal otherFee = _EnterExitCosts.Visa + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.Service + otherPriceTotal;
  15626. // 国际旅行费 - 经济舱
  15627. var cellLabel4_jjc = new StringBuilder()
  15628. .AppendFormat($"4.国际旅费(经济舱:{_EnterExitCosts.AirJJ:0.00}/人;城市间交通费:{_EnterExitCosts.CityTranffic:0.00}元/人)")
  15629. .ToString();
  15630. decimal totalAirJJC = _EnterExitCosts.AirJJ + _EnterExitCosts.CityTranffic;
  15631. designer.SetDataSource("TotalAirLabel_JJC", cellLabel4_jjc);
  15632. designer.SetDataSource("TotalAir_JJC", $"{totalAirJJC:#0.00}");
  15633. decimal totalPrice_jjc = grandTotalFee + totalAirJJC + totalOtherFee;
  15634. designer.SetDataSource("TotalFeeLabel_JJC", $"大写 :{CommonFun.ToChinese(totalPrice_jjc)}整"); // 合计金额中文大写
  15635. designer.SetDataSource("TotalFee_JJC", $"{totalPrice_jjc:0.00}"); // 合计金额
  15636. designer.SetDataSource("ActualAmount_JJC", $"{totalPrice_jjc:0.00}元"); // 合计金额
  15637. // 国际旅行费 - 公务舱
  15638. var cellLabel4_gwc = new StringBuilder()
  15639. .AppendFormat($"4.国际旅费(公务舱:{_EnterExitCosts.AirGW:0.00}/人;城市间交通费:{_EnterExitCosts.CityTranffic1:0.00}元/人)")
  15640. .ToString();
  15641. decimal totalAir_gwc = _EnterExitCosts.AirGW + _EnterExitCosts.CityTranffic1;
  15642. designer.SetDataSource("TotalAirLabel_GWC", cellLabel4_gwc);
  15643. designer.SetDataSource("TotalAir_GWC", $"{totalAir_gwc:#0.00}");
  15644. decimal totalPrice_gwc = grandTotalFee + totalAir_gwc + totalOtherFee;
  15645. designer.SetDataSource("TotalFeeLabel_GWC", $"大写 :{CommonFun.ToChinese(totalPrice_gwc)}整"); // 合计金额中文大写
  15646. designer.SetDataSource("TotalFee_GWC", $"{totalPrice_gwc:0.00}"); // 合计金额
  15647. designer.SetDataSource("ActualAmount_GWC", $"{totalPrice_gwc:0.00}元"); // 合计金额
  15648. // 国际旅行费 - 头等舱
  15649. var cellLabel4_tdc = new StringBuilder()
  15650. .AppendFormat($"4.国际旅费(头等舱:{_EnterExitCosts.AirTD:0.00}/人;城市间交通费:{_EnterExitCosts.CityTranffic2:0.00}元/人)")
  15651. .ToString();
  15652. decimal totalAir_tdc = _EnterExitCosts.AirTD + _EnterExitCosts.CityTranffic2;
  15653. designer.SetDataSource("TotalAirLabel_TDC", cellLabel4_tdc);
  15654. designer.SetDataSource("TotalAir_TDC", $"{totalAir_tdc:#0.00}");
  15655. decimal totalPrice_tdc = grandTotalFee + totalAir_tdc + totalOtherFee;
  15656. designer.SetDataSource("TotalFeeLabel_TDC", $"大写 :{CommonFun.ToChinese(totalPrice_tdc)}整"); // 合计金额中文大写
  15657. designer.SetDataSource("TotalFee_TDC", $"{totalPrice_tdc:0.00}"); // 合计金额
  15658. designer.SetDataSource("ActualAmount_TDC", $"{totalPrice_tdc:0.00}元"); // 合计金额
  15659. designer.Process();
  15660. #region 设置 住宿费、伙食费和公杂显示值
  15661. // 开始行
  15662. int startRow = 8;
  15663. // 开始列
  15664. int startColumn = 1;
  15665. // 数据展示默认行 含小计行
  15666. int defualtRow = 4;
  15667. // 设置住宿费
  15668. for (int i = 0; i < accomFees.Count; i++)
  15669. {
  15670. var currData = accomFees[i];
  15671. int startRow1 = startRow + i;
  15672. // 插入数据到对应列
  15673. worksheet1.Cells[startRow1, startColumn].PutValue(currData.PlaceName); // 国家(地区)/城市
  15674. worksheet1.Cells[startRow1, startColumn + 1].PutValue(currData.CurrencyName); // 币种
  15675. worksheet1.Cells[startRow1, startColumn + 2].PutValue($"{currData.Cost:0.00}"); // 标准
  15676. worksheet1.Cells[startRow1, startColumn + 3].PutValue("1"); // 人数
  15677. worksheet1.Cells[startRow1, startColumn + 4].PutValue(currData.TotalDays); // 天数
  15678. worksheet1.Cells[startRow1, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}"); // 小计
  15679. worksheet1.Cells[startRow1, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
  15680. worksheet1.Cells[startRow1, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}"); // 折合人民币(元)
  15681. worksheet2.Cells[startRow1, startColumn].PutValue(currData.PlaceName); // 国家(地区)/城市
  15682. worksheet2.Cells[startRow1, startColumn + 1].PutValue(currData.CurrencyName); // 币种
  15683. worksheet2.Cells[startRow1, startColumn + 2].PutValue($"{currData.Cost:0.00}"); // 标准
  15684. worksheet2.Cells[startRow1, startColumn + 3].PutValue("1"); // 人数
  15685. worksheet2.Cells[startRow1, startColumn + 4].PutValue(currData.TotalDays); // 天数
  15686. worksheet2.Cells[startRow1, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}"); // 小计
  15687. worksheet2.Cells[startRow1, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
  15688. worksheet2.Cells[startRow1, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}"); // 折合人民币(元)
  15689. worksheet3.Cells[startRow1, startColumn].PutValue(currData.PlaceName); // 国家(地区)/城市
  15690. worksheet3.Cells[startRow1, startColumn + 1].PutValue(currData.CurrencyName); // 币种
  15691. worksheet3.Cells[startRow1, startColumn + 2].PutValue($"{currData.Cost:0.00}"); // 标准
  15692. worksheet3.Cells[startRow1, startColumn + 3].PutValue("1"); // 人数
  15693. worksheet3.Cells[startRow1, startColumn + 4].PutValue(currData.TotalDays); // 天数
  15694. worksheet3.Cells[startRow1, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}"); // 小计
  15695. worksheet3.Cells[startRow1, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
  15696. worksheet3.Cells[startRow1, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}"); // 折合人民币(元)
  15697. }
  15698. //设置小计行 合计金额 固定单元格
  15699. worksheet1.Cells[11, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}"); // 折合人民币(元)
  15700. worksheet2.Cells[11, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}"); // 折合人民币(元)
  15701. worksheet3.Cells[11, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}"); // 折合人民币(元)
  15702. // 新增小计行
  15703. if (accomFees.Count == (defualtRow - 1)) startRow += 1;
  15704. else startRow += defualtRow;
  15705. // 设置伙食费和公杂费行
  15706. for (int i = 0; i < foodSundCosts.Count; i++)
  15707. {
  15708. var currData = foodSundCosts[i];
  15709. int startRow2 = startRow + i;
  15710. // 插入数据到对应列
  15711. worksheet1.Cells[startRow2, startColumn].PutValue(currData.PlaceName); // 国家(地区)/城市
  15712. worksheet1.Cells[startRow2, startColumn + 1].PutValue(currData.CurrencyName); // 币种
  15713. worksheet1.Cells[startRow2, startColumn + 2].PutValue($"{currData.Cost:0.00}"); // 标准
  15714. worksheet1.Cells[startRow2, startColumn + 3].PutValue("1"); // 人数
  15715. worksheet1.Cells[startRow2, startColumn + 4].PutValue(currData.TotalDays); // 天数
  15716. worksheet1.Cells[startRow2, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}"); // 小计
  15717. worksheet1.Cells[startRow2, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
  15718. worksheet1.Cells[startRow2, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}"); // 折合人民币(元)
  15719. worksheet2.Cells[startRow2, startColumn].PutValue(currData.PlaceName); // 国家(地区)/城市
  15720. worksheet2.Cells[startRow2, startColumn + 1].PutValue(currData.CurrencyName); // 币种
  15721. worksheet2.Cells[startRow2, startColumn + 2].PutValue($"{currData.Cost:0.00}"); // 标准
  15722. worksheet2.Cells[startRow2, startColumn + 3].PutValue("1"); // 人数
  15723. worksheet2.Cells[startRow2, startColumn + 4].PutValue(currData.TotalDays); // 天数
  15724. worksheet2.Cells[startRow2, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}"); // 小计
  15725. worksheet2.Cells[startRow2, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
  15726. worksheet2.Cells[startRow2, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}"); // 折合人民币(元)
  15727. worksheet3.Cells[startRow2, startColumn].PutValue(currData.PlaceName); // 国家(地区)/城市
  15728. worksheet3.Cells[startRow2, startColumn + 1].PutValue(currData.CurrencyName); // 币种
  15729. worksheet3.Cells[startRow2, startColumn + 2].PutValue($"{currData.Cost:0.00}"); // 标准
  15730. worksheet3.Cells[startRow2, startColumn + 3].PutValue("1"); // 人数
  15731. worksheet3.Cells[startRow2, startColumn + 4].PutValue(currData.TotalDays); // 天数
  15732. worksheet3.Cells[startRow2, startColumn + 5].PutValue($"{currData.TotalAmount:0.00}"); // 小计
  15733. worksheet3.Cells[startRow2, startColumn + 6].PutValue($"{currData.CurrencyRate:0.0000}"); // 汇率
  15734. worksheet3.Cells[startRow2, startColumn + 7].PutValue($"{currData.TotalCNY:0.00}"); // 折合人民币(元)
  15735. }
  15736. //设置小计行 合计金额 固定单元格
  15737. worksheet1.Cells[15, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}"); // 折合人民币(元)
  15738. worksheet2.Cells[15, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}"); // 折合人民币(元)
  15739. worksheet3.Cells[15, startColumn + 7].PutValue($"{accomFees.Sum(x => x.TotalCNY):0.00}"); // 折合人民币(元)
  15740. #endregion
  15741. workbook.CalculateFormula(true);
  15742. // 根据舱位选择,删除指定的sheet
  15743. if (_EnterExitCosts.SumJJC == 0)
  15744. {
  15745. var sheetNameToDelete1 = "经济舱";
  15746. if (workbook.Worksheets[sheetNameToDelete1] != null)
  15747. {
  15748. workbook.Worksheets.RemoveAt(sheetNameToDelete1);
  15749. }
  15750. }
  15751. if (_EnterExitCosts.SumGWC == 0)
  15752. {
  15753. var sheetNameToDelete2 = "公务舱";
  15754. if (workbook.Worksheets[sheetNameToDelete2] != null)
  15755. {
  15756. workbook.Worksheets.RemoveAt(sheetNameToDelete2);
  15757. }
  15758. }
  15759. if (_EnterExitCosts.SumTDC == 0)
  15760. {
  15761. var sheetNameToDelete3 = "头等舱";
  15762. if (workbook.Worksheets[sheetNameToDelete3] != null)
  15763. {
  15764. workbook.Worksheets.RemoveAt(sheetNameToDelete3);
  15765. }
  15766. }
  15767. // 模板文件名
  15768. string strFileName = $"{_DelegationInfo.TeamName}_省级单位出国经费报销单_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  15769. designer.Workbook.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  15770. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  15771. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  15772. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  15773. }
  15774. }
  15775. else if (dto.ExportType == 3)
  15776. {
  15777. if (dto.SubTypeId == 1) //团组成员名单
  15778. {
  15779. if (!DeleClientList.Any()) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组成员暂未录入!!!", ""));
  15780. //获取模板
  15781. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/dwon_团组人员列表模板.doc");
  15782. //载入模板
  15783. var doc = new Document(tempPath);
  15784. var builder = new DocumentBuilder(doc);
  15785. //获取word里所有表格
  15786. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  15787. //获取所填表格的序数
  15788. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  15789. var rowStart = tableOne.Rows[0]; //获取第1行
  15790. //循环赋值
  15791. for (int i = 0; i < DeleClientList.Count; i++)
  15792. {
  15793. builder.MoveToCell(0, i + 1, 0, 0);
  15794. builder.Write(DeleClientList[i].Name);
  15795. builder.MoveToCell(0, i + 1, 1, 0);
  15796. string sex = DeleClientList[i].Sex == 0 ? "男" : DeleClientList[i].Sex == 1 ? "女" : "";
  15797. builder.Write(sex);
  15798. builder.MoveToCell(0, i + 1, 2, 0);
  15799. builder.Write(Convert.ToDateTime(DeleClientList[i].Birthday).ToString("yyyy年MM月dd日"));
  15800. builder.MoveToCell(0, i + 1, 3, 0);
  15801. builder.Write(DeleClientList[i].Company);
  15802. builder.MoveToCell(0, i + 1, 4, 0);
  15803. builder.Write(DeleClientList[i].Job);
  15804. }
  15805. //删除多余行
  15806. while (tableOne.Rows.Count > DeleClientList.Count + 1)
  15807. {
  15808. tableOne.Rows.RemoveAt(DeleClientList.Count + 1);
  15809. }
  15810. string strFileName = $"{_DelegationInfo.TeamName}组团人员名单({DateTime.Now.ToString("yyyyMMddHHmmss")}).doc";
  15811. //C:/Server/File/OA2023/Office/Word/EnterExitCost/File/
  15812. //C:\Server\File\OA2023\Office\Word\EnterExitCost\File\
  15813. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  15814. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  15815. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  15816. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  15817. }
  15818. }
  15819. return Ok(JsonView(400, "操作失败!", ""));
  15820. }
  15821. catch (Exception ex)
  15822. {
  15823. return Ok(JsonView(400, ex.Message, ""));
  15824. }
  15825. }
  15826. /// <summary>
  15827. /// 获取三公费用标准city
  15828. /// </summary>
  15829. /// <param name="placeData"></param>
  15830. /// <param name="nationalTravelFeeId"></param>
  15831. /// <returns></returns>
  15832. private static string GetEnterExitCostExportCity(List<Grp_NationalTravelFee> placeData, int nationalTravelFeeId)
  15833. {
  15834. string _city = string.Empty;
  15835. if (placeData.Count < 1) return _city;
  15836. var data = placeData.Find(it => it.Id == nationalTravelFeeId);
  15837. if (data == null) return _city;
  15838. string country = data.Country;
  15839. string city = data.City;
  15840. if (city.Contains("其他城市") || city.Contains("所有城市")) _city = $"{country}-{city}";
  15841. else _city = city;
  15842. return _city;
  15843. }
  15844. ///// <summary>
  15845. ///// 团组模块 - 出入境费用 - 明细表导出
  15846. ///// </summary>
  15847. ///// <returns></returns>
  15848. //[HttpPost]
  15849. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15850. //public async Task<IActionResult> PostEnterExitCostExportDetailsList(EnterExitCostOperateDto dto)
  15851. //{
  15852. // var data = await _enterExitCostRep.PostEnterExitCostOperate(dto);
  15853. // if (data.Code != 0)
  15854. // {
  15855. // return Ok(JsonView(false, data.Msg));
  15856. // }
  15857. // return Ok(JsonView(true, data.Msg, data.Data));
  15858. //}
  15859. /// <summary>
  15860. /// 团组模块 - 出入境费用 - 一键清空
  15861. /// </summary>
  15862. /// <returns></returns>
  15863. [HttpPost]
  15864. //[ApiLog("Grp_EnterExitCost", OperationEnum.Del)]
  15865. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15866. public async Task<IActionResult> PostEnterExitCostOneClickClear(EnterExitCostOneClickClearDto dto)
  15867. {
  15868. if (dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId参数;"));
  15869. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数;"));
  15870. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数;"));
  15871. var _view = await _enterExitCostRep.OneClickClear(dto.Id, dto.DiId, dto.UserId);
  15872. await _sqlSugar.Updateable<Grp_DayOtherPrice>()
  15873. .Where(x => x.Diid == dto.DiId && x.IsDel == 0)
  15874. .SetColumns(x => new Grp_DayOtherPrice
  15875. {
  15876. IsDel = 1,
  15877. DeleteUserId = dto.UserId,
  15878. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  15879. })
  15880. .ExecuteCommandAsync();
  15881. if (_view.Code == 0)
  15882. {
  15883. return Ok(JsonView(true, "操作成功"));
  15884. }
  15885. return Ok(JsonView(false, "操作失败"));
  15886. }
  15887. /// <summary>
  15888. /// 团组模块 - 出入境费用 - 子项删除
  15889. /// </summary>
  15890. /// <returns></returns>
  15891. [HttpPost]
  15892. //[ApiLog("Grp_EnterExitCost", OperationEnum.Del)]
  15893. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15894. public async Task<IActionResult> PostEnterExitCostSubItemDel(EnterExitCostSubItemDelDto dto)
  15895. {
  15896. var data = await _enterExitCostRep.PostEnterExitCostSubItemDel(dto);
  15897. if (data.Code != 0)
  15898. {
  15899. return Ok(JsonView(false, data.Msg));
  15900. }
  15901. return Ok(JsonView(true, "操作成功!", data.Data));
  15902. }
  15903. /// <summary>
  15904. /// 删除三公其他费用
  15905. /// </summary>
  15906. /// <param name="dto"></param>
  15907. /// <returns></returns>
  15908. [HttpPost]
  15909. //[ApiLog("Grp_EnterExitCost", OperationEnum.Del)]
  15910. public IActionResult DeleteOtherExpenses(EnterExitCostSubItemDelDto dto)
  15911. {
  15912. var jw = JsonView(false, "删除失败!");
  15913. var data = new Grp_DayOtherPrice()
  15914. {
  15915. Id = dto.Id,
  15916. IsDel = 1,
  15917. DeleteUserId = dto.DeleteUserId,
  15918. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  15919. };
  15920. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  15921. if (del > 0)
  15922. {
  15923. jw.Code = 200;
  15924. jw.Msg = "删除成功!";
  15925. }
  15926. return Ok(jw);
  15927. }
  15928. /// <summary>
  15929. /// 团组模块 - 出入境国家费用标准 List
  15930. /// </summary>
  15931. /// <returns></returns>
  15932. [HttpPost]
  15933. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15934. public async Task<IActionResult> GetNationalTravelFeeData(NationalTravelFeeDataDto dto)
  15935. {
  15936. int provinceId = dto.ProvinceId;
  15937. if (provinceId < 1) provinceId = 122; //默认四川省数据
  15938. var nftData = await _sqlSugar
  15939. .Queryable<Grp_NationalTravelFee, Sys_SetData, Sys_Users, Sys_Cities>((ntf, sd1, u, c) => new JoinQueryInfos(
  15940. JoinType.Left, ntf.Currency == sd1.Id,
  15941. JoinType.Left, ntf.LastUpdateUserId == u.Id,
  15942. JoinType.Left, ntf.ProvinceId == c.Id
  15943. ))
  15944. .Where((ntf, sd1, u, c) => ntf.IsDel == 0 && ntf.ProvinceId == provinceId)
  15945. .Select((ntf, sd1, u, c) => new NationalTravelFeeInfoView
  15946. {
  15947. Id = ntf.Id,
  15948. ProvinceId = ntf.ProvinceId,
  15949. ProvinceName = c.Name_CN,
  15950. Continent = ntf.Continent,
  15951. Country = ntf.Country,
  15952. City = ntf.City,
  15953. Currency = ntf.Currency,
  15954. CurrencyCode = sd1.Name,
  15955. CurrencyName = sd1.Remark,
  15956. RoomCost = ntf.RoomCost,
  15957. FoodCost = ntf.FoodCost,
  15958. PublicCost = ntf.PublicCost,
  15959. LastUpdateUserId = ntf.LastUpdateUserId,
  15960. LastUpdateUserName = u.CnName,
  15961. LastUpdateTime = ntf.LastUpdateTime
  15962. })
  15963. .ToListAsync();
  15964. return Ok(JsonView(true, "查询成功!", nftData));
  15965. }
  15966. /// <summary>
  15967. /// 团组模块 - 出入境国家费用标准 Page List Data Source
  15968. /// </summary>
  15969. /// <returns></returns>
  15970. [HttpPost]
  15971. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15972. public async Task<IActionResult> GetNationalTravelFeePageDataSource()
  15973. {
  15974. string sql = string.Format(@"Select * From Grp_NationalTravelFee Where Isdel = 0 ");
  15975. var nationalTravelFeeData = await _groupRepository._sqlSugar.SqlQueryable<Grp_NationalTravelFee>(sql).ToListAsync();
  15976. List<string> countryData = new List<string>();
  15977. countryData.AddRange(nationalTravelFeeData.Select(it => it.Country!).ToList());
  15978. countryData = countryData.Distinct().ToList();
  15979. List<dynamic> dataSource = new List<dynamic>();
  15980. foreach (var item in countryData)
  15981. {
  15982. var cityData1 = new List<string>();
  15983. cityData1 = nationalTravelFeeData.Where(it => it.Country == item).Select(it => it.City ?? "").ToList();
  15984. var countryData2 = new
  15985. {
  15986. CountryName = item,
  15987. CityData = cityData1
  15988. };
  15989. if (!dataSource.Contains(countryData2))
  15990. {
  15991. dataSource.Add(countryData2);
  15992. }
  15993. }
  15994. return Ok(JsonView(true, "查询成功!", dataSource));
  15995. }
  15996. /// <summary>
  15997. /// 团组模块 - 出入境国家费用标准 Page List
  15998. /// </summary>
  15999. /// <returns></returns>
  16000. [HttpPost]
  16001. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16002. public async Task<IActionResult> PostNationalTravelFeePage(NationalTravelFeePageDto dto)
  16003. {
  16004. int portId = dto.PortType,
  16005. pageIndex = dto.PageIndex,
  16006. pageSize = dto.PageSize;
  16007. if (portId != 1 && portId != 2 && portId != 3) return Ok(JsonView(false, "请输入正确的端口号!\r\n请求端口分类1 Web 2 Android 3 IOS"));
  16008. if (pageIndex == 0) pageIndex = 1;
  16009. if (pageSize == 0) pageSize = 10;
  16010. RefAsync<int> total = 0;
  16011. var nationalTravelFeeData = await _sqlSugar
  16012. .Queryable<Grp_NationalTravelFee, Sys_SetData, Sys_Users, Sys_Cities>((ntf, sd1, u, sd2) => new JoinQueryInfos(
  16013. JoinType.Left, ntf.Currency == sd1.Id,
  16014. JoinType.Left, ntf.LastUpdateUserId == u.Id,
  16015. JoinType.Left, ntf.ProvinceId == sd2.Id
  16016. ))
  16017. .Where((ntf, sd1, u, sd2) => ntf.IsDel == 0)
  16018. .WhereIF(dto.ProvinceId > 0, (ntf, sd1, u, sd2) => ntf.ProvinceId == dto.ProvinceId)
  16019. .WhereIF(!string.IsNullOrEmpty(dto.Country), (ntf, sd1, u, sd2) => ntf.Country.Contains(dto.Country))
  16020. .WhereIF(!string.IsNullOrEmpty(dto.City), (ntf, sd1, u, sd2) => ntf.City.Contains(dto.City))
  16021. .OrderByDescending((ntf, sd1, u, sd2) => ntf.LastUpdateTime)
  16022. .Select((ntf, sd1, u, sd2) => new NationalTravelFeePageInfoView
  16023. {
  16024. RowNumber = SqlFunc.RowNumber($"{ntf.LastUpdateTime} Desc"),
  16025. Id = ntf.Id,
  16026. ProvinceId = ntf.ProvinceId,
  16027. ProvinceName = sd2.Name_CN,
  16028. Continent = ntf.Continent,
  16029. Country = ntf.Country,
  16030. City = ntf.City,
  16031. Currency = ntf.Currency,
  16032. CurrencyCode = sd1.Name,
  16033. CurrencyName = sd1.Remark,
  16034. RoomCost = ntf.RoomCost,
  16035. FoodCost = ntf.FoodCost,
  16036. PublicCost = ntf.PublicCost,
  16037. LastUpdateUserId = ntf.LastUpdateUserId,
  16038. LastUpdateUserName = u.CnName,
  16039. LastUpdateTime = ntf.LastUpdateTime,
  16040. Remark = ntf.Remark
  16041. })
  16042. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  16043. return Ok(JsonView(true, "查询成功!", nationalTravelFeeData, (int)total));
  16044. }
  16045. /// <summary>
  16046. /// 团组模块 - 出入境国家费用标准 根据城市查询
  16047. /// </summary>
  16048. /// <returns></returns>
  16049. [HttpPost]
  16050. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16051. public async Task<IActionResult> PostNationalTravelFeeInfoByCountryAndCity(NationalTravelFeeByCountryAndCityDto dto)
  16052. {
  16053. if (dto == null) return Ok(JsonView(false, "请传入参数!"));
  16054. int portId = dto.PortType;
  16055. if (portId != 1 && portId != 2 && portId != 3) return Ok(JsonView(false, "请输入正确的端口号!\r\n请求端口分类1 Web 2 Android 3 IOS"));
  16056. string whereSql = string.Empty;
  16057. if (!string.IsNullOrEmpty(dto.Country))
  16058. {
  16059. whereSql = string.Format(@"And Country = '{0}' ", dto.Country);
  16060. }
  16061. if (!string.IsNullOrEmpty(dto.City))
  16062. {
  16063. whereSql = string.Format(@"And City = '{0}' ", dto.City);
  16064. }
  16065. string sql = string.Format(@"Select gntf.Country,gntf.City,gntf.Currency,ssd.Name as CurrencyCode,
  16066. ssd.Remark as CurrencyName,gntf.RoomCost,gntf.FoodCost,gntf.PublicCost,gntf.TrainCost,
  16067. gntf.LastUpdateUserId,su.CnName as LastUpdateUserName,gntf.LastUpdateTime
  16068. From Grp_NationalTravelFee gntf
  16069. Left Join Sys_SetData ssd On ssd.STid = 66 And gntf.Currency = ssd.Id
  16070. Left Join Sys_Users su On gntf.LastUpdateUserId = su.Id
  16071. Where gntf.Isdel = 0 {0} ", whereSql);
  16072. var nationalTravelFeeData = await _groupRepository._sqlSugar.SqlQueryable<NationalTravelFeeInfoByCountryAndCityView>(sql).FirstAsync();
  16073. return Ok(JsonView(true, "查询成功!", nationalTravelFeeData));
  16074. }
  16075. /// <summary>
  16076. /// 团组模块 - 出入境国家费用标准 - Add Or Update
  16077. /// </summary>
  16078. /// <returns></returns>
  16079. [HttpPost]
  16080. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16081. public async Task<IActionResult> PostNationalTravelFeeOperate(NationalTravelFeeOperateDto dto)
  16082. {
  16083. return Ok(await _enterExitCostRep.PostNationalTravelFeeOperate(dto));
  16084. }
  16085. /// <summary>
  16086. /// 团组模块 - 出入境国家费用标准 - Del
  16087. /// </summary>
  16088. /// <returns></returns>
  16089. [HttpPost]
  16090. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16091. public async Task<IActionResult> PostNationalTravelFeeDel(NationalTravelFeeDelDto dto)
  16092. {
  16093. Grp_NationalTravelFee _nationalTravelFee = new Grp_NationalTravelFee()
  16094. {
  16095. Id = dto.Id,
  16096. DeleteUserId = dto.DeleteUserId,
  16097. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  16098. IsDel = 1
  16099. };
  16100. var delStatus = await _enterExitCostRep._sqlSugar.Updateable<Grp_NationalTravelFee>(_nationalTravelFee)
  16101. .UpdateColumns(it => new { it.DeleteTime, it.DeleteUserId, it.IsDel })
  16102. .WhereColumns(it => new { it.Id })
  16103. .ExecuteCommandAsync();
  16104. if (delStatus <= 0)
  16105. {
  16106. return Ok(JsonView(false, "删除失败!"));
  16107. }
  16108. return Ok(JsonView(true, "操作成功!"));
  16109. }
  16110. /// <summary>
  16111. /// 团组模块 - 出入境国家费用标准 - 费用导入收款账单
  16112. /// 注:Get 请求Headers 加 Token
  16113. /// </summary>
  16114. /// <param name="groupId"></param>
  16115. /// <returns></returns>
  16116. [HttpGet("{groupId}")]
  16117. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16118. public async Task<IActionResult> NationalTravelFeeImportReceivables(int groupId)
  16119. {
  16120. var _currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  16121. if (_currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  16122. var data = await GeneralMethod.ReceivablesImportFeeAsync(groupId);
  16123. data.ForEach(x =>
  16124. {
  16125. x.CreateUserId = _currUserInfo.UserId;
  16126. });
  16127. if (data.Any())
  16128. {
  16129. var add = await _sqlSugar.Insertable(data).ExecuteCommandAsync();
  16130. if (add > 0)
  16131. {
  16132. return Ok(JsonView(true, "操作成功!"));
  16133. }
  16134. }
  16135. return Ok(JsonView(false, "未操作!"));
  16136. }
  16137. #endregion
  16138. #region 团组经理模块 出入境费用-草稿
  16139. /// <summary>
  16140. /// 团组模块-出入境费用-草稿
  16141. /// 基础数据源-省份归属
  16142. /// </summary>
  16143. /// <returns></returns>
  16144. [HttpGet]
  16145. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16146. public async Task<IActionResult> EnterExitDraftProvBelongCostDataSource()
  16147. {
  16148. var provData = await _groupRepository.ProvinceBasicSource();
  16149. return Ok(JsonView(true, "查询成功!", provData));
  16150. }
  16151. /// <summary>
  16152. /// 团组模块-出入境费用-草稿
  16153. /// 文件类型list 根据省份Id获取
  16154. /// </summary>
  16155. /// <returns></returns>
  16156. [HttpGet("{provinceId}")]
  16157. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16158. public async Task<IActionResult> EnterExitCostDraftFileOwner([FromRoute] int provinceId = 122)
  16159. {
  16160. //验证城市归属并给默认值
  16161. if (provinceId < 1) provinceId = 122;
  16162. /*
  16163. * 122 四川
  16164. * 108 贵州
  16165. * 103 重庆
  16166. * 132 云南
  16167. */
  16168. (SetDataInfoView[] wordTypeData, SetDataInfoView[] excelTypeData) = await _enterExitCostDraftRep.FileOwner(provinceId);
  16169. return Ok(JsonView(true, "查询成功!", new
  16170. {
  16171. WordTypeData = wordTypeData,
  16172. ExcelTypeData = excelTypeData,
  16173. }));
  16174. }
  16175. /// <summary>
  16176. /// 团组模块 - 出入境费用-草稿
  16177. /// 基础数据源(团组名称/币种类型)
  16178. /// </summary>
  16179. /// <returns></returns>
  16180. [HttpPost]
  16181. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16182. public async Task<IActionResult> EnterExitCostDraftDataSource(EnterExitCostDraftDataSourceDto dto)
  16183. {
  16184. var draftNameDatas = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>()
  16185. .Where(x => x.IsDel == 0)
  16186. .OrderByDescending(x => x.CreateTime)
  16187. .Select(x => new { x.Id, x.DraftName })
  16188. .ToListAsync();
  16189. string sql = string.Format("Select * From Sys_SetData Where IsDel = 0");
  16190. //SetDataInfoView
  16191. var dataSource = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToListAsync();
  16192. var currencyData = dataSource.Where(it => it.STid == 66).ToList(); //所有币种
  16193. var _CurrencyData = _mapper.Map<List<SetDataInfoView>>(currencyData);
  16194. int provinceId = dto.ProvinceId;
  16195. if (provinceId < 1) provinceId = 122;
  16196. /*
  16197. * 122 四川
  16198. * 108 贵州
  16199. * 103 重庆
  16200. * 132 云南
  16201. */
  16202. (SetDataInfoView[] wordTypeData, SetDataInfoView[] excelTypeData) = await _enterExitCostRep.FileOwner(provinceId);
  16203. //默认币种显示
  16204. var _currencyInfos = await GeneralMethod.EnterExitCostInitRate();
  16205. var viewPermissionData = await _enterExitCostDraftRep.PermissionViewUsersAsync();
  16206. return Ok(JsonView(true, "查询成功!", new
  16207. {
  16208. DraftNameDatas = draftNameDatas,
  16209. CurrencyData = _CurrencyData,
  16210. WordTypeData = wordTypeData,
  16211. ExcelTypeData = excelTypeData,
  16212. CurrencyInit = _currencyInfos,
  16213. ViewPermissionData = viewPermissionData
  16214. }));
  16215. }
  16216. /// <summary>
  16217. /// 团组模块 - 出入境费用-草稿
  16218. /// 实时汇率 tips、机票费用 tips
  16219. /// </summary>
  16220. /// <returns></returns>
  16221. [HttpPost]
  16222. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16223. public async Task<IActionResult> EnterExitCostDraftCorrelationTips(EnterExitCostDraftCorrelationTipsDto dto)
  16224. {
  16225. //var airData = await _ticketBlackCodeRep.EntryAndExitTips(dto.DiId);
  16226. return Ok(JsonView(true, "查询成功!", new
  16227. {
  16228. //GroupNameData = groupNameData.Data,
  16229. //visaData = visaData.Data,
  16230. //airData = airData.Data,
  16231. reteInfos = await GeneralMethod.EnterExitCostLiveRate()
  16232. }));
  16233. }
  16234. /// <summary>
  16235. /// 团组模块 - 出入境费用-草稿
  16236. /// 签证费用 tips
  16237. /// </summary>
  16238. /// <returns></returns>
  16239. [HttpPost]
  16240. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16241. public async Task<IActionResult> EnterExitCostDraftVisaTips(EnterExitCostDraftVisaTipsDto dto)
  16242. {
  16243. //if (dto.DraftId < 1) return Ok(JsonView(false,MsgTips.Id));
  16244. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  16245. .Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId)
  16246. .Select(x => x.NationalTravelFeeId)
  16247. .Distinct()
  16248. .ToListAsync();
  16249. //if (!cityIds.Any()) return Ok(JsonView(false, "请先录入出入境费用明细!"));
  16250. var countrys = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  16251. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  16252. .Select(x => x.Country)
  16253. .Distinct()
  16254. .ToArrayAsync();
  16255. //if (!countrys.Any()) return Ok(JsonView(false, "请先录入出入境费用明细!"));
  16256. (decimal totalAmt, string remark) = await _visaFeeInfoRep.EnterExitCostDraftVisaTips(countrys);
  16257. return Ok(JsonView(true, "查询成功!", new
  16258. {
  16259. totalAmt,
  16260. remark
  16261. }));
  16262. }
  16263. #region 城市区间交通费
  16264. /// <summary>
  16265. /// 团组模块 - 出入境费用-草稿
  16266. /// 境外用车 基础数据源
  16267. /// </summary>
  16268. /// <param name="draftId">草稿Id</param>
  16269. /// <returns></returns>
  16270. [HttpGet("{draftId}")]
  16271. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16272. public async Task<IActionResult> EnterExitCostDraftOVByGroupId(int draftId)
  16273. {
  16274. var draftInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == draftId).FirstAsync();
  16275. if (draftInfo == null)
  16276. {
  16277. return Ok(JsonView(false, "三公费用草稿信息为空"));
  16278. }
  16279. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  16280. .Where(x => x.IsDel == 0 && x.ParentId == draftId)
  16281. .Select(x => x.NationalTravelFeeId)
  16282. .Distinct()
  16283. .ToListAsync();
  16284. var countries = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  16285. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  16286. .Select(x => x.Country)
  16287. .Distinct()
  16288. .ToListAsync();
  16289. if (countries?.Any() != true)
  16290. {
  16291. return Ok(JsonView(false, "草稿选择城市信息为空"));
  16292. }
  16293. var currencies = await GeneralMethod.EnterExitCostDrafOVFeeUsedCurrencyAsync(draftId);
  16294. var currencyData = await _sqlSugar.Queryable<Sys_SetData>()
  16295. .Where(x => x.IsDel == 0 && x.STid == 66)
  16296. .ToListAsync();
  16297. var overseaVehicles = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  16298. .Where(x => x.IsDel == 0 && countries.Contains(x.CountryName))
  16299. .ToListAsync();
  16300. var overseaVehicleIds = overseaVehicles.Select(x => x.Id).ToList();
  16301. //只返回接送机的数据
  16302. var overseaVehicleTypes = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  16303. .Where(x => x.IsDel == 0 && x.ServiceType == VehicleServiceTypeEnum.TransferService && overseaVehicleIds.Contains(x.OvId))
  16304. .ToListAsync();
  16305. var sysUers = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToListAsync();
  16306. var overseaVehicleCityDatas = new List<dynamic>() {
  16307. new
  16308. {
  16309. Id = 0,
  16310. area= "未选择",
  16311. CarTypeName = "",
  16312. serviceType = "",
  16313. Price = 0.00M,
  16314. guidePrice = 0.00M,
  16315. otherPrice = 0.00M,
  16316. currency = 0,
  16317. currencyName = "",
  16318. currRate = 1.0000M,
  16319. LastUpdateUserName = "",
  16320. LastUpdateTime = "",
  16321. Remark = ""
  16322. }};
  16323. foreach (var item in overseaVehicleTypes)
  16324. {
  16325. var parentInfo = overseaVehicles.FirstOrDefault(x => x.Id == item.OvId);
  16326. string area = string.Empty,
  16327. serviceType = "未设置",
  16328. currencyName = string.Empty;
  16329. decimal otherPrice = 0.00M;
  16330. if (parentInfo != null)
  16331. {
  16332. if (parentInfo.CountryName == parentInfo.CityName) area = parentInfo.CountryName;
  16333. else area = $"{parentInfo.CountryName}-{parentInfo.CityName}";
  16334. serviceType = item.ServiceType.GetDescription();
  16335. currencyName = currencyData.FirstOrDefault(x => x.Id == parentInfo.Currency)?.Name ?? "-";
  16336. otherPrice = parentInfo.OtherPrice1 + parentInfo.OtherPrice2;
  16337. }
  16338. //当前币种汇率值
  16339. var currRate = 1.0000M;
  16340. var currencyInfo = currencies.FirstOrDefault(x => x.CurrencyCode == currencyName);
  16341. if (currencyInfo != null) currRate = currencyInfo.Rate;
  16342. overseaVehicleCityDatas.add(new
  16343. {
  16344. item.Id,
  16345. area,
  16346. item.CarTypeName,
  16347. serviceType,
  16348. item.Price,
  16349. guidePrice = parentInfo?.GuidePrice ?? 0.00M,
  16350. otherPrice,
  16351. currency = parentInfo?.Currency ?? 0,
  16352. currencyName,
  16353. currRate,
  16354. LastUpdateUserName = sysUers.FirstOrDefault(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-",
  16355. item.LastUpdateTime,
  16356. item.Remark
  16357. });
  16358. }
  16359. var total = overseaVehicleCityDatas.Count;
  16360. var view = new
  16361. {
  16362. visitCountries = string.Join("、", countries),
  16363. groupSize = 0, //出访人数
  16364. defAirportTransferCoeff = Def_AirportTransferCoeff, //接送机默认报价系数
  16365. defServiceCount = Def_ServiceCount, //接送机默认服务次数
  16366. defTrainCoeff = Def_TrainCoeff, //火车默认报价系数
  16367. defPullCartCoeff = Def_PullCartCoeff, //拉车默认报价系数
  16368. defCityFlightCoeff = Def_CityFlightCoeff, //城市机票默认报价系数
  16369. Currencies = currencies,
  16370. data = overseaVehicleCityDatas
  16371. };
  16372. if (overseaVehicleCityDatas.Count == 0)
  16373. {
  16374. return Ok(JsonView(true, "暂无数据!", view));
  16375. }
  16376. return Ok(JsonView(true, "查询成功!", view, total));
  16377. }
  16378. /// <summary>
  16379. /// 团组模块 - 出入境费用-草稿
  16380. /// 境外用车 计算详细信息
  16381. /// </summary>
  16382. /// <param name="draftId"></param>
  16383. /// <param name="currUserId"></param>
  16384. /// <returns></returns>
  16385. [HttpGet("{draftId}")]
  16386. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16387. public async Task<IActionResult> EnterExitCostDraftOVFeeDetails(int draftId, int currUserId)
  16388. {
  16389. // 1. 验证草稿是否存在
  16390. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>()
  16391. .Where(x => x.Id == draftId && x.IsDel == 0)
  16392. .FirstAsync();
  16393. if (eecInfo == null)
  16394. {
  16395. return Ok(JsonView(false, "草稿信息为空"));
  16396. }
  16397. // 2. 获取用户信息
  16398. var userInfo = await _sqlSugar.Queryable<Sys_Users>()
  16399. .Where(x => x.IsDel == 0 && x.Id == currUserId)
  16400. .FirstAsync();
  16401. var userName = userInfo?.CnName ?? "-";
  16402. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  16403. // 3. 处理草稿信息
  16404. CityIntervalDraftInfo info;
  16405. if (eecInfo.CityIntervalFeeDetails != null)
  16406. {
  16407. info = eecInfo.CityIntervalFeeDetails;
  16408. // 检查费用详情是否为空
  16409. bool isEmpty = !info.APTFeeDetails.Any() &&
  16410. !info.PullCartFeeDetails.Any() &&
  16411. !info.TrainFeeDetails.Any() &&
  16412. !info.CityAirTicketFeeDetails.Any();
  16413. if (isEmpty)
  16414. {
  16415. info = await CreateDefaultCityIntervalDraftInfo(draftId, userName, nowTime);
  16416. }
  16417. else
  16418. {
  16419. // 更新时间和用户信息
  16420. info.LastUpdateUserName = userName;
  16421. info.LastUpdateTime = nowTime;
  16422. }
  16423. }
  16424. else
  16425. {
  16426. // 创建默认信息
  16427. info = await CreateDefaultCityIntervalDraftInfo(draftId, userName, nowTime);
  16428. }
  16429. return Ok(JsonView(true, "查询成功!", info));
  16430. }
  16431. /// <summary>
  16432. /// 创建默认的城市区间费用草稿信息
  16433. /// </summary>
  16434. private static async Task<CityIntervalDraftInfo> CreateDefaultCityIntervalDraftInfo(
  16435. int draftId,
  16436. string userName,
  16437. string nowTime)
  16438. {
  16439. return new CityIntervalDraftInfo()
  16440. {
  16441. APTFeeDetails = new List<RoundTripTransferInfo>()
  16442. {
  16443. new()
  16444. {
  16445. No = 1,
  16446. Coefficient = Def_AirportTransferCoeff,
  16447. ServiceCount = Def_ServiceCount
  16448. }
  16449. },
  16450. PullCartFeeDetails = new List<PullCartInfo>()
  16451. {
  16452. new()
  16453. {
  16454. No = 1,
  16455. Coefficient = Def_PullCartCoeff
  16456. }
  16457. },
  16458. TrainFeeDetails = new List<TrainInfo>()
  16459. {
  16460. new()
  16461. {
  16462. No = 1,
  16463. Coefficient = Def_TrainCoeff
  16464. }
  16465. },
  16466. CityAirTicketFeeDetails = new List<CityAirTicketInfo>()
  16467. {
  16468. new()
  16469. {
  16470. No = 1,
  16471. Coefficient = Def_CityFlightCoeff
  16472. }
  16473. },
  16474. LastUpdateUserName = userName,
  16475. LastUpdateTime = nowTime,
  16476. CreateUserName = userName,
  16477. CreateTime = nowTime,
  16478. Currencies = await GeneralMethod.EnterExitCostDrafOVFeeUsedCurrencyAsync(draftId)
  16479. };
  16480. }
  16481. /// <summary>
  16482. /// 团组模块 - 出入境费用-草稿
  16483. /// 境外用车 保存
  16484. /// </summary>
  16485. /// <param name="dto"></param>
  16486. /// <returns></returns>
  16487. [HttpPost]
  16488. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16489. public async Task<IActionResult> EnterExitCostDraftOVFeeSave(EnterExitCostDraftOVFeeSaveDto dto)
  16490. {
  16491. var draftInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == dto.DraftId).FirstAsync();
  16492. if (draftInfo == null)
  16493. {
  16494. return Ok(JsonView(false, "草稿信息为空"));
  16495. }
  16496. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == dto.CurrUserId).FirstAsync();
  16497. if (userInfo == null)
  16498. {
  16499. return Ok(JsonView(false, "员工信息为空"));
  16500. }
  16501. var userName = userInfo?.CnName ?? "-";
  16502. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  16503. var info = new CityIntervalDraftInfo()
  16504. {
  16505. GroupSize = dto.GroupSize,
  16506. APTFeeTotal = dto.APTFeeTotal,
  16507. APTFeeDetails = dto.APTFeeDetails,
  16508. PullCartFeeTotal = dto.PullCartFeeTotal,
  16509. PullCartFeeDetails = dto.PullCartFeeDetails,
  16510. TrainFeeTotal = dto.TrainFeeTotal,
  16511. TrainFeeDetails = dto.TrainFeeDetails,
  16512. CityAirTicketFeeTotal = dto.CityAirTicketFeeTotal,
  16513. CityAirTicketFeeDetails = dto.CityAirTicketFeeDetails,
  16514. Currencies = dto.Currencies,
  16515. LastUpdateUserName = userName,
  16516. LastUpdateTime = nowTime,
  16517. CreateUserName = draftInfo.CityIntervalFeeDetails?.CreateUserName ?? userName,
  16518. CreateTime = draftInfo.CityIntervalFeeDetails?.CreateTime ?? nowTime
  16519. };
  16520. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>()
  16521. .SetColumns(it => it.CityIntervalFeeDetails == info)
  16522. .Where(x => x.Id == draftInfo.Id)
  16523. .ExecuteCommandAsync();
  16524. if (upd < 1)
  16525. {
  16526. return Ok(JsonView(false));
  16527. }
  16528. //返回参数处理
  16529. var label = new StringBuilder();
  16530. if (dto.APTFeeDetails.Any())
  16531. {
  16532. var ovIds = dto.APTFeeDetails.Select(x => x.OvId).ToList();
  16533. var areas = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  16534. .LeftJoin<Res_OverseaVehicle>((ovtp, ov) => ovtp.OvId == ov.Id)
  16535. .Where((ovtp, ov) => ovtp.IsDel == 0 && ovIds.Contains(ovtp.Id))
  16536. .Select((ovtp, ov) => new
  16537. {
  16538. ovtp.Id,
  16539. ov.CountryName,
  16540. ov.CityName
  16541. })
  16542. .ToListAsync();
  16543. if (areas.Any())
  16544. {
  16545. var items = dto.APTFeeDetails
  16546. .Select(item =>
  16547. {
  16548. var areaInfo = areas.FirstOrDefault(x => x.Id == item.OvId);
  16549. if (areaInfo == null) return null;
  16550. return areaInfo.CountryName == areaInfo.CityName
  16551. ? $"{areaInfo.CountryName}({item.Quote:#0.00} CNY)"
  16552. : $"{areaInfo.CountryName}-{areaInfo.CityName}({item.Quote:#0.00} CNY)";
  16553. })
  16554. .Where(item => item != null)
  16555. .ToList();
  16556. string areaLabel = $"接送机({string.Join("、", items)});";
  16557. label.AppendLine(areaLabel);
  16558. }
  16559. }
  16560. if (dto.PullCartFeeDetails.Any())
  16561. {
  16562. var amounts = dto.PullCartFeeDetails.Select(item => $"{item.Quote:#0.00}");
  16563. string subLabel = $"拉车({string.Join("、", amounts)});";
  16564. label.AppendLine(subLabel);
  16565. }
  16566. if (dto.TrainFeeDetails.Any())
  16567. {
  16568. var amounts = dto.TrainFeeDetails.Select(item => $"{item.Quote:#0.00}");
  16569. string subLabel = $"火车票({string.Join("、", amounts)});";
  16570. label.AppendLine(subLabel);
  16571. }
  16572. if (dto.CityAirTicketFeeDetails.Any())
  16573. {
  16574. var amounts = dto.CityAirTicketFeeDetails.Select(item => $"{item.Quote:#0.00}");
  16575. string subLabel = $"城市机票({string.Join("、", amounts)});";
  16576. label.AppendLine(subLabel);
  16577. }
  16578. //费用
  16579. decimal quote = (dto.APTFeeTotal + dto.PullCartFeeTotal + dto.TrainFeeTotal + dto.CityAirTicketFeeTotal).ConvertToDecimal1();
  16580. decimal jjcQuote = quote;
  16581. decimal gwcQuote = quote;
  16582. decimal tdcQuote = quote;
  16583. var view = new
  16584. {
  16585. label = label.ToString(),
  16586. jjcQuote,
  16587. gwcQuote,
  16588. tdcQuote
  16589. };
  16590. return Ok(JsonView(view));
  16591. }
  16592. #endregion
  16593. /// <summary>
  16594. /// 团组模块 - 出入境费用-草稿
  16595. /// Info
  16596. /// </summary>
  16597. /// <returns></returns>
  16598. [HttpPost]
  16599. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Details)]
  16600. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16601. public async Task<IActionResult> EnterExitCostDraftInfoById(EnterExitCostDraftInfoByIdDto dto)
  16602. {
  16603. return Ok(await _enterExitCostDraftRep.EnterExitCostDraftInfoById(dto));
  16604. }
  16605. /// <summary>
  16606. /// 团组模块 - 出入境费用-草稿
  16607. /// 设置view权限
  16608. /// </summary>
  16609. /// <returns></returns>
  16610. [HttpPost]
  16611. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16612. public async Task<IActionResult> EnterExitCostDraftSetViewPermissiion(EnterExitCostDraftSetViewPermissiionDto dto)
  16613. {
  16614. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16615. if (dto.DraftId < 1) return Ok(JsonView(false, "请传入有效的DraftId;"));
  16616. if (dto.UserIds.Length < 1) return Ok(JsonView(false, "请传入有效的userId;"));
  16617. var permissions = new List<Grp_EnterExitCostDraftPermission>();
  16618. foreach (var userId in dto.UserIds)
  16619. {
  16620. permissions.Add(new Grp_EnterExitCostDraftPermission { Permission = 1, DraftId = dto.DraftId, UserId = userId, CreateUserId = dto.CurrUserId });
  16621. }
  16622. if (permissions.Any())
  16623. {
  16624. _sqlSugar.BeginTran();
  16625. try
  16626. {
  16627. await _sqlSugar.Deleteable<Grp_EnterExitCostDraftPermission>().Where(it => it.DraftId == dto.DraftId).ExecuteCommandAsync();
  16628. var result = await _sqlSugar.Insertable(permissions).ExecuteCommandAsync();
  16629. if (result < 1)
  16630. {
  16631. _sqlSugar.RollbackTran();
  16632. return Ok(JsonView(false));
  16633. }
  16634. }
  16635. catch (Exception ex)
  16636. {
  16637. _sqlSugar.RollbackTran();
  16638. return Ok(JsonView(false, ex.Message));
  16639. }
  16640. _sqlSugar.CommitTran();
  16641. return Ok(JsonView(true));
  16642. }
  16643. return Ok(JsonView(false));
  16644. }
  16645. /// <summary>
  16646. /// 团组模块 - 出入境费用-草稿
  16647. /// Add And Update
  16648. /// </summary>
  16649. /// <returns></returns>
  16650. [HttpPost]
  16651. [ApiLog("Grp_EnterExitCostDraft", OperationEnum.Add)]
  16652. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16653. public async Task<IActionResult> EnterExitCostDraftOp(EnterExitCostDraftOpDto dto)
  16654. {
  16655. var data = await _enterExitCostDraftRep.EnterExitCostDraftOp(dto);
  16656. if (data.Code != 0)
  16657. {
  16658. return Ok(JsonView(false, data.Msg));
  16659. }
  16660. int sign = (int)data.Data.GetType().GetProperty("sign").GetValue(data.Data, null);
  16661. //汇率信息记录
  16662. await GeneralMethod.RateRecordSave(dto.UserId, sign, "出入境费用");
  16663. return Ok(JsonView(true, data.Msg, data.Data));
  16664. }
  16665. /// <summary>
  16666. /// 团组模块 - 出入境费用-草稿
  16667. /// File downlaod
  16668. /// </summary>
  16669. /// <param name="dto"></param>
  16670. /// <returns></returns>
  16671. [HttpPost]
  16672. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Download)]
  16673. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16674. public async Task<IActionResult> EnterExitCostDraftDownload(EnterExitCostDraftDownloadDto dto)
  16675. {
  16676. try
  16677. {
  16678. var id = dto.Id;
  16679. if (id < 1) return Ok(JsonView(400, "请传入有效的DiId参数;", ""));
  16680. if (dto.ExportType < 1) return Ok(JsonView(400, "请传入有效的ExportType参数; 1 明细表 2 表格", ""));
  16681. if (dto.SubTypeId < 1) return Ok(JsonView(400, @"请传入有效的SubTypeId参数;
  16682. 1 明细表 --> 1005(默认明细表) 1006(因公出国(境)经费测算明细表) 1007(四川省商务厅出国经费财政先行审核表)
  16683. 2 表格 --> 1008(派员单位出(境)任务和预算审批意见表) 1009(省级单位出(境)经费报销单)
  16684. 3 团组成员名单 1 团组成员名单", ""));
  16685. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(it => it.IsDel == 0 && it.Id == id).OrderByDescending(x => x.CreateTime).First();
  16686. if (_EnterExitCosts == null) return Ok(JsonView(400, "未填写出入境费用-草稿;", ""));
  16687. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCostDraft>().Where(it => it.IsDel == 0 && it.ParentId == id).ToList();
  16688. var countryIds = _DayAndCosts.Select(x => x.NationalTravelFeeId).ToList();
  16689. var nationalTravelFeeData = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0 && countryIds.Contains(it.Id)).ToList();
  16690. var enterExitCostCurrencys = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(_EnterExitCosts.CurrencyRemark);
  16691. //数据源
  16692. var dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  16693. var dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  16694. var dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  16695. var dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  16696. var dac5 = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>()
  16697. .LeftJoin<Sys_SetData>((x, a) => a.IsDel == 0 && a.Id == x.SetDataId)
  16698. .LeftJoin<Sys_SetData>((x, a, b) => b.IsDel == 0 && b.Id == x.Currency)
  16699. .Where((x, a, b) => x.IsDel == 0 && x.ParentId == id)
  16700. .Select((x, a, b) => new
  16701. {
  16702. x.Index,
  16703. itemName = a.Name,
  16704. CurrencyStr = b.Name,
  16705. x.Cost,
  16706. x.SubTotal,
  16707. x.Remark
  16708. })
  16709. .OrderBy((x) => x.Index)
  16710. .ToList(); //其他款项费用
  16711. var _CurrDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  16712. var peiceItemCurrencys = new List<string>();
  16713. if (_DayAndCosts.Any())
  16714. {
  16715. var currencyIds = _DayAndCosts.Select(x => x.Currency).Distinct().ToList();
  16716. if (currencyIds.Any()) peiceItemCurrencys.AddRange(_CurrDatas.Where(x => currencyIds.Contains(x.Id)).Select(x => x.Name).ToList());
  16717. }
  16718. if (dac5.Any()) peiceItemCurrencys.AddRange(dac5.Select(x => x.CurrencyStr).Distinct().ToList());
  16719. var peiceItemCurrencyInfos = new List<CurrencyInfo>();
  16720. if (enterExitCostCurrencys.Any() && peiceItemCurrencys.Any())
  16721. {
  16722. peiceItemCurrencyInfos = enterExitCostCurrencys.Where(x => peiceItemCurrencys.Contains(x.CurrencyCode)).ToList();
  16723. }
  16724. var threeCodes = _sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList();
  16725. var placeData = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  16726. var rateDatas = await _EnterExitCosts.CurrencyRemark.SplitExchangeRate();
  16727. if (dto.ExportType == 1) //明细表
  16728. {
  16729. if (dto.SubTypeId == 1005) //1005(默认明细表)
  16730. {
  16731. //获取模板
  16732. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/出入境费用表模板.docx");
  16733. //载入模板
  16734. Document doc = new Document(tempPath);
  16735. DocumentBuilder builder = new DocumentBuilder(doc);
  16736. //利用键值对存放数据
  16737. Dictionary<string, string> dic = new Dictionary<string, string>();
  16738. decimal stayFeeTotal = _EnterExitCosts.ChoiceThree == 1 ? _DayAndCosts.Where(it => it.Type == 1).Sum(it => it.SubTotal) : 0.00M; // 住宿费
  16739. decimal mealsFeeTotal = _EnterExitCosts.ChoiceFour == 1 ? _DayAndCosts.Where(it => it.Type == 2).Sum(it => it.SubTotal) : 0.00M; // 伙食费费
  16740. decimal miscellaneousFeeTotal = _EnterExitCosts.ChoiceFive == 1 ? _DayAndCosts.Where(it => it.Type == 3).Sum(it => it.SubTotal) : 0.00M; // 公杂费
  16741. decimal tainFeeTotal = _EnterExitCosts.ChoiceSix == 1 ? _DayAndCosts.Where(it => it.Type == 4).Sum(it => it.SubTotal) : 0.00M; // 培训费
  16742. decimal otherPriceTotal = _EnterExitCosts.OtherExpenses_Checked == 1 ? dac5.Sum(x => x.SubTotal) : 0.00M; //其他费用
  16743. decimal insidePayTotal = _EnterExitCosts.ChoiceOne == 1 ? _EnterExitCosts.InsidePay : 0.00M;
  16744. //境内费用(其他费用)
  16745. if (_EnterExitCosts.ChoiceOne == 1)
  16746. {
  16747. string row1_1 = "";
  16748. if (_EnterExitCosts.Visa > 0)
  16749. {
  16750. //insidePayTotal += _EnterExitCosts.Visa;
  16751. row1_1 = $"签证费:{_EnterExitCosts.Visa.ToString("#0.00")} 人民币/人";
  16752. //if (!string.IsNullOrEmpty(_EnterExitCosts.VisaRemark))
  16753. //{
  16754. // row1_1 += $"\t签证费用描述: {_EnterExitCosts.VisaRemark} 人民币/人";
  16755. //}
  16756. }
  16757. string row1_2 = "";
  16758. if (_EnterExitCosts.YiMiao > 0)
  16759. {
  16760. //insidePayTotal += _EnterExitCosts.YiMiao;
  16761. row1_2 += $"疫苗费:{_EnterExitCosts.YiMiao.ToString("#0.00")} 人民币/人";
  16762. }
  16763. if (_EnterExitCosts.HeSuan > 0)
  16764. {
  16765. //insidePayTotal += _EnterExitCosts.HeSuan;
  16766. row1_2 += $"核酸检测费:{_EnterExitCosts.HeSuan.ToString("#0.00")} 人民币/人";
  16767. }
  16768. if (_EnterExitCosts.Service > 0)
  16769. {
  16770. //insidePayTotal += _EnterExitCosts.Service;
  16771. row1_2 += $"服务费:{_EnterExitCosts.Service.ToString("#0.00")} 人民币/人";
  16772. }
  16773. string row1_3 = "";
  16774. if (_EnterExitCosts.Safe > 0)
  16775. {
  16776. //insidePayTotal += _EnterExitCosts.Safe;
  16777. row1_3 += $"保险费:{_EnterExitCosts.Safe.ToString("#0.00")} 人民币/人";
  16778. }
  16779. if (_EnterExitCosts.Ticket > 0)
  16780. {
  16781. //insidePayTotal += _EnterExitCosts.Ticket;
  16782. row1_3 += $"参展门票:{_EnterExitCosts.Ticket.ToString("#0.00")} 人民币/人";
  16783. }
  16784. string row1 = "";
  16785. if (!string.IsNullOrEmpty(row1_1)) row1 += $"{row1_1}\r\n";
  16786. if (!string.IsNullOrEmpty(row1_2)) row1 += $"{row1_2}\r\n";
  16787. if (!string.IsNullOrEmpty(row1_3)) row1 += $"{row1_3}\r\n";
  16788. row1 += $"备注:{_EnterExitCosts.Remark}";
  16789. dic.Add("InsidePay", insidePayTotal.ToString("#0.00"));
  16790. dic.Add("Row1Str", row1);
  16791. }
  16792. string airTotalStr = string.Empty,
  16793. airPriceStr = string.Empty;
  16794. //经济舱
  16795. if (_EnterExitCosts.SumJJC == 1)
  16796. {
  16797. airTotalStr += $"{_EnterExitCosts.OutsideJJPay.ToString("#0.00")}元/人(经济舱)";
  16798. airPriceStr += $"{_EnterExitCosts.AirJJ.ToString("#0.00")}元/人(经济舱)";
  16799. }
  16800. //公务舱
  16801. if (_EnterExitCosts.SumGWC == 1)
  16802. {
  16803. airTotalStr += $" {_EnterExitCosts.OutsideGWPay.ToString("#0.00")} 元/人(公务舱)";
  16804. airPriceStr += $" {_EnterExitCosts.AirGW.ToString("#0.00")} 元/人(公务舱)";
  16805. }
  16806. //头等舱
  16807. if (_EnterExitCosts.SumTDC == 1)
  16808. {
  16809. airTotalStr += $" {_EnterExitCosts.OutsideTDPay.ToString("#0.00")} 元/人(头等舱)";
  16810. airPriceStr += $" {_EnterExitCosts.AirTD.ToString("#0.00")} 元/人(头等舱)";
  16811. }
  16812. //汇率描述
  16813. string rateStr = "";
  16814. if (peiceItemCurrencyInfos.Any())
  16815. {
  16816. rateStr = "\r\n汇率描述:";
  16817. foreach (var item in peiceItemCurrencyInfos)
  16818. {
  16819. rateStr += $"{item.CurrencyName}({item.CurrencyCode}):{item.Rate.ToString("#0.0000")} ";
  16820. }
  16821. }
  16822. string twoItemRemark = "备注:";
  16823. if (!string.IsNullOrEmpty(_EnterExitCosts.TwoItemRemark)) twoItemRemark += _EnterExitCosts.TwoItemRemark;
  16824. if (!string.IsNullOrEmpty(rateStr)) twoItemRemark += rateStr;
  16825. dic.Add("AirTotalStr", airTotalStr);
  16826. dic.Add("AirPriceStr", airPriceStr);
  16827. dic.Add("CityTranffic", _EnterExitCosts.CityTranffic.ToString("#0.00"));
  16828. dic.Add("TwoItemRemark", twoItemRemark);
  16829. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  16830. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  16831. int table1Row = 0,
  16832. table2Row = 0,
  16833. table3Row = 0,
  16834. table4Row = 0,
  16835. table5Row = 0;
  16836. //住宿费
  16837. if (_EnterExitCosts.ChoiceThree == 1)
  16838. {
  16839. dic.Add("SubZS", stayFeeTotal.ToString("#0.00"));
  16840. table1Row = dac1.Count;
  16841. #region 填充word表格内容
  16842. for (int i = 0; i < dac1.Count; i++)
  16843. {
  16844. var dac = dac1[i];
  16845. if (dac == null) continue;
  16846. builder.MoveToCell(0, i, 0, 0);
  16847. builder.Write("第" + dac.Days.ToString() + "晚:");
  16848. builder.MoveToCell(0, i, 1, 0);
  16849. //builder.Write(placeData.Find(it => it.Id == dac.NationalTravelFeeId)?.Country ?? "Unknown");
  16850. //builder.Write(dac.Place == null ? "" : dac.Place);
  16851. builder.Write(GetEnterExitCostDraftExportCity(placeData, dac.NationalTravelFeeId));
  16852. builder.MoveToCell(0, i, 2, 0);
  16853. builder.Write("费用标准:");
  16854. string curr = "";
  16855. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  16856. if (currData != null)
  16857. {
  16858. curr = currData.Name;
  16859. }
  16860. builder.MoveToCell(0, i, 3, 0);
  16861. builder.Write(dac.Cost.ToString("#0.00") + curr);
  16862. builder.MoveToCell(0, i, 4, 0);
  16863. builder.Write("费用小计:");
  16864. builder.MoveToCell(0, i, 5, 0);
  16865. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  16866. }
  16867. #endregion
  16868. }
  16869. else dic.Add("SubZS", "0.00");
  16870. if (table1 != null && table1.Rows.Count > 0)
  16871. {
  16872. //删除多余行
  16873. while (table1.Rows.Count > table1Row)
  16874. {
  16875. table1.Rows.RemoveAt(table1Row);
  16876. }
  16877. }
  16878. //伙食费
  16879. Aspose.Words.Tables.Table table2 = allTables[1] as Aspose.Words.Tables.Table;
  16880. if (_EnterExitCosts.ChoiceFour == 1)
  16881. {
  16882. dic.Add("SubHS", mealsFeeTotal.ToString("#0.00"));
  16883. table2Row = dac2.Count;
  16884. #region 填充word表格内容
  16885. for (int i = 0; i < dac2.Count; i++)
  16886. {
  16887. var dac = dac2[i];
  16888. if (dac == null) continue;
  16889. builder.MoveToCell(1, i, 0, 0);
  16890. builder.Write("第" + dac.Days.ToString() + "天:");
  16891. builder.MoveToCell(1, i, 1, 0);
  16892. builder.Write(GetEnterExitCostDraftExportCity(placeData, dac.NationalTravelFeeId));
  16893. builder.MoveToCell(1, i, 2, 0);
  16894. builder.Write("费用标准:");
  16895. string curr = "";
  16896. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  16897. if (currData != null)
  16898. {
  16899. curr = currData.Name;
  16900. }
  16901. builder.MoveToCell(1, i, 3, 0);
  16902. builder.Write(dac.Cost.ToString("#0.00") + curr);
  16903. builder.MoveToCell(1, i, 4, 0);
  16904. builder.Write("费用小计:");
  16905. builder.MoveToCell(1, i, 5, 0);
  16906. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  16907. }
  16908. #endregion
  16909. }
  16910. else dic.Add("SubHS", "0.00");
  16911. if (table2 != null && table2.Rows.Count > 0)
  16912. {
  16913. //删除多余行
  16914. while (table2.Rows.Count > table2Row)
  16915. {
  16916. table2.Rows.RemoveAt(table2Row);
  16917. }
  16918. }
  16919. //公杂费
  16920. Aspose.Words.Tables.Table table3 = allTables[2] as Aspose.Words.Tables.Table;
  16921. if (_EnterExitCosts.ChoiceFive == 1)
  16922. {
  16923. dic.Add("SubGZF", miscellaneousFeeTotal.ToString("#0.00"));
  16924. table3Row = dac3.Count;
  16925. #region 填充word表格内容
  16926. for (int i = 0; i < dac3.Count; i++)
  16927. {
  16928. var dac = dac3[i];
  16929. if (dac == null) continue;
  16930. builder.MoveToCell(2, i, 0, 0);
  16931. builder.Write("第" + dac.Days.ToString() + "天:");
  16932. builder.MoveToCell(2, i, 1, 0);
  16933. builder.Write(GetEnterExitCostDraftExportCity(placeData, dac.NationalTravelFeeId));
  16934. builder.MoveToCell(2, i, 2, 0);
  16935. builder.Write("费用标准:");
  16936. string curr = "";
  16937. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  16938. if (currData != null)
  16939. {
  16940. curr = currData.Name;
  16941. }
  16942. builder.MoveToCell(2, i, 3, 0);
  16943. builder.Write(dac.Cost.ToString("#0.00") + curr);
  16944. builder.MoveToCell(2, i, 4, 0);
  16945. builder.Write("费用小计:");
  16946. builder.MoveToCell(2, i, 5, 0);
  16947. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  16948. }
  16949. //删除多余行
  16950. while (table3.Rows.Count > table3Row)
  16951. {
  16952. table3.Rows.RemoveAt(table3Row);
  16953. }
  16954. #endregion
  16955. }
  16956. else dic.Add("SubGZF", "0.00");
  16957. if (table3 != null && table3.Rows.Count > 0)
  16958. {
  16959. //删除多余行
  16960. while (table3.Rows.Count > table3Row)
  16961. {
  16962. table3.Rows.RemoveAt(table3Row);
  16963. }
  16964. }
  16965. //培训费
  16966. Aspose.Words.Tables.Table table4 = allTables[3] as Aspose.Words.Tables.Table;
  16967. if (_EnterExitCosts.ChoiceSix == 1)
  16968. {
  16969. string pxStr = $"六、培训费合计: {tainFeeTotal.ToString("#0.00")} 元/人";
  16970. dic.Add("SubPX", pxStr);
  16971. table4Row = dac4.Count;
  16972. #region 填充word表格内容
  16973. for (int i = 0; i < dac4.Count; i++)
  16974. {
  16975. var dac = dac4[i];
  16976. if (dac == null) continue;
  16977. builder.MoveToCell(3, i, 0, 0);
  16978. builder.Write("第" + dac.Days.ToString() + "天:");
  16979. builder.MoveToCell(3, i, 1, 0);
  16980. builder.Write(GetEnterExitCostDraftExportCity(placeData, dac.NationalTravelFeeId));
  16981. builder.MoveToCell(3, i, 2, 0);
  16982. builder.Write("费用标准:");
  16983. string curr = "";
  16984. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  16985. if (currData != null)
  16986. {
  16987. curr = currData.Name;
  16988. }
  16989. builder.MoveToCell(3, i, 3, 0);
  16990. builder.Write(dac.Cost.ToString("#0.00") + curr);
  16991. builder.MoveToCell(3, i, 4, 0);
  16992. builder.Write("费用小计:");
  16993. builder.MoveToCell(3, i, 5, 0);
  16994. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  16995. }
  16996. #endregion
  16997. }
  16998. //else dic.Add("SubPX", $"六、培训费合计: 0 元/人");
  16999. //删除多余行
  17000. if (table4 != null && table4.Rows.Count > 0)
  17001. {
  17002. while (table4.Rows.Count > table4Row)
  17003. {
  17004. table4.Rows.RemoveAt(table4Row);
  17005. }
  17006. }
  17007. //其他费用
  17008. Aspose.Words.Tables.Table table5 = allTables[4] as Aspose.Words.Tables.Table;
  17009. if (_EnterExitCosts.OtherExpenses_Checked == 1)
  17010. {
  17011. string qtStr = $"七、其他费用合计: {otherPriceTotal.ToString("#0.00")} 元/人";
  17012. dic.Add("titleQi", qtStr);
  17013. table5Row = dac5.Count;
  17014. #region 填充word表格内容
  17015. for (int i = 0; i < dac5.Count; i++)
  17016. {
  17017. var dac = dac5[i];
  17018. if (dac == null) continue;
  17019. builder.MoveToCell(4, i, 0, 0);
  17020. builder.Write("第" + dac.Index.ToString() + "项:");
  17021. builder.MoveToCell(4, i, 1, 0);
  17022. builder.Write(dac.itemName);
  17023. builder.MoveToCell(4, i, 2, 0);
  17024. builder.Write("费用标准:");
  17025. builder.MoveToCell(4, i, 3, 0);
  17026. builder.Write(dac.Cost.ToString("#0.00") + dac.CurrencyStr);
  17027. builder.MoveToCell(4, i, 4, 0);
  17028. builder.Write("费用小计:");
  17029. builder.MoveToCell(4, i, 5, 0);
  17030. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  17031. builder.MoveToCell(4, i, 6, 0);
  17032. builder.Write("备注:");
  17033. builder.MoveToCell(4, i, 7, 0);
  17034. builder.Write(dac.Remark);
  17035. }
  17036. #endregion
  17037. }
  17038. //else dic.Add("SubQT", "七、其他费用合计: 0 元/人");
  17039. if (table5 != null && table5.Rows.Count > 0)
  17040. {
  17041. //删除多余行
  17042. while (table5.Rows.Count > table5Row)
  17043. {
  17044. table5.Rows.RemoveAt(table5Row);
  17045. }
  17046. }
  17047. //加上其他费用
  17048. decimal otherFeeTotal = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + otherPriceTotal;
  17049. decimal subJJC = 0.00M,
  17050. subGWC = 0.00M,
  17051. subTDC = 0.00M;
  17052. //全部费用总计: 元 / 人(经济舱) 元 / 人(公务舱) 元 / 人(头等舱)
  17053. string totalLabel = string.Format("全部费用总计:");
  17054. //经济舱
  17055. if (_EnterExitCosts.SumJJC == 1)
  17056. {
  17057. subJJC = otherFeeTotal + _EnterExitCosts.OutsideJJPay;
  17058. totalLabel += $"{subJJC.ToString("#0.00")} 元/人(经济舱)";
  17059. }
  17060. //公务舱
  17061. if (_EnterExitCosts.SumGWC == 1)
  17062. {
  17063. subGWC = otherFeeTotal + _EnterExitCosts.OutsideGWPay;
  17064. totalLabel += $"{subGWC.ToString("#0.00")} 元/人(公务舱)";
  17065. }
  17066. //头等舱
  17067. if (_EnterExitCosts.SumTDC == 1)
  17068. {
  17069. subTDC = otherFeeTotal + _EnterExitCosts.OutsideTDPay;
  17070. totalLabel += $"{subTDC.ToString("#0.00")} 元/人(头等舱)";
  17071. }
  17072. //TotalLabel
  17073. dic.Add("TotalLabel", totalLabel);
  17074. #region 填充word模板书签内容
  17075. foreach (var key in dic.Keys)
  17076. {
  17077. Bookmark bookmark = doc.Range.Bookmarks[key];
  17078. if (bookmark != null)
  17079. {
  17080. builder.MoveToBookmark(key);
  17081. builder.Write(dic[key]);
  17082. }
  17083. }
  17084. #endregion
  17085. //文件名
  17086. string strFileName = $"{_EnterExitCosts.DraftName}_出入境费用-草稿{Guid.NewGuid().ToString()}.docx";
  17087. strFileName = CommonFun.ValidFileName(strFileName);
  17088. AsposeHelper.removewatermark_v2180();
  17089. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  17090. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  17091. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  17092. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  17093. }
  17094. else if (dto.SubTypeId == 1006)//1006(因公出国(境)经费测算明细表)
  17095. {
  17096. //获取模板
  17097. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/因公出国(境)经费测算明细表.docx");
  17098. //载入模板
  17099. Document doc = new Document(tempPath);
  17100. DocumentBuilder builder = new DocumentBuilder(doc);
  17101. Dictionary<string, string> dic = new Dictionary<string, string>();
  17102. string returnCodeLabel = string.Empty;
  17103. if (nationalTravelFeeData.Any())
  17104. {
  17105. List<string> list = new List<string>();
  17106. foreach (var item in nationalTravelFeeData)
  17107. {
  17108. list.Add($"{item.Country}({item.City})");
  17109. }
  17110. list = list.Distinct().ToList();
  17111. returnCodeLabel = string.Join("-", list).TrimEnd('-');
  17112. }
  17113. var countryLabel = string.Empty;
  17114. var countryData = nationalTravelFeeData.Select(x => x.Country).Distinct().ToList();
  17115. if (countryData.Any())
  17116. {
  17117. countryLabel = string.Join("、", countryData);
  17118. }
  17119. dic.Add("ReturnCodeAir", returnCodeLabel);
  17120. dic.Add("VisitStartDate", "-");
  17121. dic.Add("VisitEndDate", "-");
  17122. dic.Add("Day", "-");
  17123. dic.Add("VisitCountry", countryLabel);
  17124. dic.Add("ClientUnit", "-");
  17125. //var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  17126. //dic.Add("Names", Names);
  17127. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  17128. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  17129. decimal dac1totalPrice = 0.00M;
  17130. int accommodationStartIndex = 6, foodandotherStartIndex = 22;
  17131. foreach (var dac in dac1)
  17132. {
  17133. if (dac.SubTotal == 0.00M)
  17134. {
  17135. continue;
  17136. }
  17137. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  17138. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  17139. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  17140. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  17141. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  17142. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  17143. builder.Write(currency);//币种
  17144. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  17145. builder.Write(dac.Cost.ToString("#0.00"));//标准
  17146. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  17147. builder.Write("");//人数
  17148. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  17149. builder.Write("");//天数
  17150. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  17151. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  17152. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  17153. decimal rate = 0.00M;
  17154. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  17155. builder.Write(rate.ToString("#0.0000"));//汇率
  17156. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  17157. decimal rbmPrice = dac.SubTotal;
  17158. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  17159. accommodationStartIndex++;
  17160. dac1totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  17161. }
  17162. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  17163. for (int i = 21; i > (dac1.Count == 0 ? 1 : dac1.Count) + 6; i--)
  17164. {
  17165. table1.Rows.RemoveAt(i - 1);
  17166. foodandotherStartIndex--;
  17167. }
  17168. if (dac2.Count == dac3.Count)//国家 币种 金额
  17169. {
  17170. for (int i = 0; i < dac2.Count; i++)
  17171. {
  17172. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  17173. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  17174. }
  17175. }
  17176. decimal dac2totalPrice = 0.00M;
  17177. foreach (var dac in dac2)
  17178. {
  17179. if (dac.SubTotal == 0)
  17180. {
  17181. continue;
  17182. }
  17183. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  17184. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  17185. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  17186. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  17187. builder.Write(currency);//币种
  17188. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  17189. builder.Write(dac.Cost.ToString("#0.00"));//标准
  17190. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  17191. builder.Write("");//人数
  17192. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  17193. builder.Write("");//天数
  17194. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  17195. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  17196. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  17197. decimal rate = 0.00M;
  17198. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  17199. builder.Write(rate.ToString("#0.0000"));//汇率
  17200. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  17201. decimal rbmPrice = dac.SubTotal;
  17202. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  17203. foodandotherStartIndex++;
  17204. dac2totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  17205. }
  17206. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  17207. for (int i = foodandotherStartIndex + (15 - dac2.Count); i > (dac2.Count == 0 ? 1 : 0) + foodandotherStartIndex; i--)
  17208. {
  17209. table1.Rows.RemoveAt(i - 1);
  17210. }
  17211. dic.Add("CityTranffic", _EnterExitCosts.CityTranffic.ToString("#0.00"));
  17212. string otherFeeStr = "";
  17213. if (_EnterExitCosts.Visa > 0) otherFeeStr += $"签证费:{_EnterExitCosts.Visa.ToString("#0.00")} 元,";
  17214. if (_EnterExitCosts.Safe > 0) otherFeeStr += $"保险费:{_EnterExitCosts.Safe.ToString("#0.00")} 元,";
  17215. if (_EnterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费:{_EnterExitCosts.Ticket.ToString("#0.00")} 元,";
  17216. #region 其他款项费用 增加位置:模板第6项其他费用字符串追加
  17217. foreach (var otherInfo in dac5)
  17218. {
  17219. otherFeeStr += $"{otherInfo.itemName}:{otherInfo.SubTotal.ToString("#0.00")} 元,";
  17220. }
  17221. #endregion
  17222. if (otherFeeStr.Length > 0)
  17223. {
  17224. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  17225. otherFeeStr = $"({otherFeeStr})";
  17226. dic.Add("OtherFeeStr", otherFeeStr);
  17227. }
  17228. //总计
  17229. decimal allPrice = dac1totalPrice + dac2totalPrice + _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket;
  17230. //国际旅费
  17231. string outsideAir = string.Empty;
  17232. string allPriceAir = string.Empty;
  17233. if (_EnterExitCosts.SumJJC == 1)
  17234. {
  17235. outsideAir += string.Format(@"经济舱:{0} 元/人;", _EnterExitCosts.AirJJ.ToString("#0.00"));
  17236. allPriceAir += string.Format(@"经济舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideJJPay).ToString("#0.00"));
  17237. }
  17238. if (_EnterExitCosts.SumGWC == 1)
  17239. {
  17240. outsideAir += string.Format(@"公务舱:{0} 元/人;", _EnterExitCosts.AirGW.ToString("#0.00"));
  17241. allPriceAir += string.Format(@"公务舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  17242. }
  17243. if (_EnterExitCosts.SumTDC == 1)
  17244. {
  17245. outsideAir += string.Format(@"头等舱:{0} 元/人;", _EnterExitCosts.AirTD.ToString("#0.00"));
  17246. allPriceAir += string.Format(@"头等舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideTDPay).ToString("#0.00"));
  17247. }
  17248. dic.Add("InTravelPrice", $"({outsideAir})");
  17249. dic.Add("FinalSumPrice", $"({allPriceAir})");
  17250. //dic.Add("VisaPay", _EnterExitCosts.Visa.ToString("#0.00"));
  17251. //dic.Add("SafePay", _EnterExitCosts.Safe.ToString("#0.00"));
  17252. //dic.Add("YiMiao", _EnterExitCosts.YiMiao.ToString("#0.00"));
  17253. foreach (var key in dic.Keys)
  17254. {
  17255. builder.MoveToBookmark(key);
  17256. builder.Write(dic[key]);
  17257. }
  17258. //模板文件名
  17259. string strFileName = $"草稿_{_EnterExitCosts.DraftName}_因公出国(境)经费测算明细表{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
  17260. strFileName = CommonFun.ValidFileName(strFileName);
  17261. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  17262. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  17263. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  17264. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  17265. }
  17266. else if (dto.SubTypeId == 1007) //1007(四川省商务厅出国经费财政先行审核表)
  17267. {
  17268. //获取模板
  17269. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/四川省商务厅出国经费财政先行审核表.xls");
  17270. //载入模板
  17271. WorkbookDesigner designer = new WorkbookDesigner();
  17272. designer.Workbook = new Workbook(tempPath);
  17273. Dictionary<string, string> dic = new Dictionary<string, string>();
  17274. string returnCodeLabel = string.Empty;
  17275. if (nationalTravelFeeData.Any())
  17276. {
  17277. List<string> list = new List<string>();
  17278. foreach (var item in nationalTravelFeeData)
  17279. {
  17280. list.Add($"{item.Country}({item.City})");
  17281. }
  17282. list = list.Distinct().ToList();
  17283. returnCodeLabel = string.Join("-", list).TrimEnd('-');
  17284. }
  17285. var countryLabel = string.Empty;
  17286. var countryData = nationalTravelFeeData.Select(x => x.Country).Distinct().ToList();
  17287. if (countryData.Any())
  17288. {
  17289. countryLabel = string.Join("、", countryData);
  17290. }
  17291. dic.Add("ReturnCodeAir", returnCodeLabel);
  17292. dic.Add("VisitStartDate", "-");
  17293. dic.Add("VisitEndDate", "-");
  17294. dic.Add("Day", "0");
  17295. dic.Add("VisitCountry", countryLabel);
  17296. dic.Add("ClientUnit", "-");
  17297. designer.SetDataSource("ClientUnit", "-");
  17298. designer.SetDataSource("VisitCountry", countryLabel);
  17299. designer.SetDataSource("Group", "-");
  17300. designer.SetDataSource("ClientUnitTitle", "-");
  17301. designer.SetDataSource("Name", "-");
  17302. designer.SetDataSource("VisitStartDate", "-");
  17303. designer.SetDataSource("Day", "0");
  17304. designer.SetDataSource("ReturnCode", returnCodeLabel);
  17305. designer.SetDataSource("ReturnCodeAir", "-");
  17306. int startIndex = 10;
  17307. const int startIndexcopy = 10;
  17308. if (dac2.Count == dac3.Count)//国家 币种 金额
  17309. {
  17310. for (int i = 0; i < dac2.Count; i++)
  17311. {
  17312. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  17313. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  17314. }
  17315. }
  17316. DataTable dtdac1 = new DataTable();
  17317. List<string> place = new List<string>();
  17318. dtdac1.Columns.AddRange(new DataColumn[] {
  17319. new DataColumn(){ ColumnName = "city"},
  17320. new DataColumn(){ ColumnName = "curr"},
  17321. new DataColumn(){ ColumnName = "criterion"},
  17322. new DataColumn(){ ColumnName = "number",DataType = typeof(int)},
  17323. new DataColumn(){ ColumnName = "day",DataType = typeof(int)},
  17324. new DataColumn(){ ColumnName = "cost", DataType = typeof(decimal)},
  17325. new DataColumn(){ ColumnName = "rate", DataType = typeof(decimal) },
  17326. new DataColumn(){ ColumnName = "costRMB", DataType = typeof(decimal) },
  17327. });
  17328. DataTable dtdac2 = new DataTable();
  17329. dtdac2.Columns.AddRange(new DataColumn[] {
  17330. new DataColumn(){ ColumnName = "city"},
  17331. new DataColumn(){ ColumnName = "curr"},
  17332. new DataColumn(){ ColumnName = "criterion"},
  17333. new DataColumn(){ ColumnName = "number",DataType = typeof(int)},
  17334. new DataColumn(){ ColumnName = "day",DataType = typeof(int)},
  17335. new DataColumn(){ ColumnName = "cost", DataType = typeof(decimal)},
  17336. new DataColumn(){ ColumnName = "rate", DataType = typeof(decimal) },
  17337. new DataColumn(){ ColumnName = "costRMB",DataType = typeof(decimal)},
  17338. });
  17339. dtdac1.TableName = "tb1";
  17340. dtdac2.TableName = "tb2";
  17341. decimal dac1totalPrice = 0.00M, dac2totalPrice = 0.00M;
  17342. foreach (var item in dac1)
  17343. {
  17344. item.Place = GetEnterExitCostDraftExportCity(placeData, item.NationalTravelFeeId);
  17345. if (place.Contains(item.Place))
  17346. {
  17347. continue;
  17348. }
  17349. DataRow row = dtdac1.NewRow();
  17350. row["city"] = item.Place;
  17351. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  17352. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  17353. row["curr"] = currency;
  17354. row["rate"] = rate.ToString("#0.0000");
  17355. row["criterion"] = item.Cost.ToString("#0.00");
  17356. row["number"] = 1;
  17357. row["day"] = dac1.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  17358. //row["costRMB"] = rbmPrice;
  17359. dtdac1.Rows.Add(row);
  17360. place.Add(item.Place);
  17361. }
  17362. place = new List<string>();
  17363. foreach (var item in dac2)
  17364. {
  17365. item.Place = GetEnterExitCostDraftExportCity(placeData, item.NationalTravelFeeId);
  17366. if (place.Contains(item.Place))
  17367. {
  17368. continue;
  17369. }
  17370. DataRow row = dtdac2.NewRow();
  17371. row["city"] = item.Place;
  17372. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  17373. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  17374. row["curr"] = currency;
  17375. row["rate"] = rate.ToString("#0.0000");
  17376. row["criterion"] = item.Cost.ToString("#0.00");
  17377. row["number"] = 1;
  17378. row["day"] = dac2.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  17379. //row["cost"] = item.SubTotal;
  17380. //row["costRMB"] = rbmPrice;
  17381. dtdac2.Rows.Add(row);
  17382. place.Add(item.Place);
  17383. //dac2totalPrice += rbmPrice;
  17384. }
  17385. dac1totalPrice = dac1.Sum(it => it.SubTotal);
  17386. dac2totalPrice = dac2.Sum(it => it.SubTotal);
  17387. designer.SetDataSource("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  17388. designer.SetDataSource("dac2totalPrice", dac2totalPrice);
  17389. designer.SetDataSource("cityTranffic", @$"其中:国外城市间机票费: {_EnterExitCosts.CityTranffic:#0.00} 元");
  17390. designer.SetDataSource("sumCityTranffic", @$"{_EnterExitCosts.CityTranffic:#0.00} ");
  17391. string cell4Str1 = string.Empty;
  17392. if (_EnterExitCosts.SumJJC == 1) cell4Str1 += $"经济舱:{_EnterExitCosts.AirJJ:#0.00} 元/人;";
  17393. if (_EnterExitCosts.SumGWC == 1) cell4Str1 += $"公务舱:{_EnterExitCosts.AirGW:#0.00} 元/人;";
  17394. if (_EnterExitCosts.SumTDC == 1) cell4Str1 += $"公务舱:{_EnterExitCosts.AirTD:#0.00} 元/人;";
  17395. string cell4Str = $" 4.国际旅费:{cell4Str1}";
  17396. string cellStr = $" 5.其他费用(";
  17397. if (_EnterExitCosts.Visa > 0) cellStr += $"签证费:{_EnterExitCosts.Visa:#0.00}元,";
  17398. if (_EnterExitCosts.YiMiao > 0) cellStr += $"疫苗费:{_EnterExitCosts.YiMiao:#0.00}元,";
  17399. if (_EnterExitCosts.HeSuan > 0) cellStr += $"核酸费:{_EnterExitCosts.HeSuan:#0.00}元,";
  17400. if (_EnterExitCosts.Safe > 0) cellStr += $"保险费:{_EnterExitCosts.Safe:#0.00}元,";
  17401. if (_EnterExitCosts.Ticket > 0) cellStr += $"参展门票费:{_EnterExitCosts.Ticket:#0.00}元,";
  17402. if (_EnterExitCosts.Service > 0) cellStr += $"服务费:{_EnterExitCosts.Service:#0.00}元,";
  17403. #region 其他款项费用 增加位置:模板第5项其他费用字符串追加
  17404. var otherPriceTotal = dac5.Sum(x => x.SubTotal);
  17405. foreach (var otherInfo in dac5)
  17406. {
  17407. cellStr += $"{otherInfo.itemName}:{otherInfo.SubTotal:#0.00} 元,";
  17408. }
  17409. #endregion
  17410. if (cellStr.Length > 8)
  17411. {
  17412. cellStr = cellStr.Substring(0, cellStr.Length - 1);
  17413. }
  17414. cellStr += ")";
  17415. decimal otherFee = _EnterExitCosts.Visa + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.Service + otherPriceTotal;
  17416. decimal s = dac1totalPrice + dac2totalPrice + _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay + otherFee;
  17417. decimal pxFee = dac4.Sum(it => it.Cost);
  17418. decimal glvFee = _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay;
  17419. string celllastStr1 = "";
  17420. if (dac1totalPrice > 0) celllastStr1 += $"住宿费 {dac1totalPrice:#0.00} 元";
  17421. if (dac2totalPrice > 0) celllastStr1 += $",伙食费和公杂费 {dac2totalPrice:#0.00} 元";
  17422. if (pxFee > 0) celllastStr1 += $",培训费 {pxFee:#0.00} 元";
  17423. celllastStr1 += $",国际旅费 元";
  17424. if (otherFee > 0) celllastStr1 += $",其他费用 {otherFee:#0.00} 元";
  17425. string celllastStr = $" 经审核,{celllastStr1},本次出国经费预算合计为 元。其中:市本级安排 。";
  17426. designer.SetDataSource("cell4Str", cell4Str);
  17427. designer.SetDataSource("cellStr", cellStr);
  17428. designer.SetDataSource("cellSum", otherFee.ToString("#0.00"));
  17429. designer.SetDataSource("cellSum4", (_EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  17430. designer.SetDataSource("celllastStr", celllastStr);
  17431. Workbook wb = designer.Workbook;
  17432. var sheet = wb.Worksheets[0];
  17433. //绑定datatable数据集
  17434. designer.SetDataSource(dtdac1);
  17435. designer.SetDataSource(dtdac2);
  17436. designer.Process();
  17437. var rowStart = dtdac1.Rows.Count;
  17438. while (rowStart > 0)
  17439. {
  17440. sheet.Cells[startIndex, 8].Formula = $"=G{startIndex + 1} * H{startIndex + 1}";
  17441. sheet.Cells[startIndex, 6].Formula = $"=E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  17442. startIndex++;
  17443. rowStart--;
  17444. }
  17445. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + 1}: I{startIndex})";
  17446. startIndex += 1; //总计行
  17447. rowStart = dtdac2.Rows.Count;
  17448. while (rowStart > 0)
  17449. {
  17450. sheet.Cells[startIndex, 8].Formula = $"= G{startIndex + 1} * H{startIndex + 1}";
  17451. sheet.Cells[startIndex, 6].Formula = $"= E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  17452. startIndex++;
  17453. rowStart--;
  17454. }
  17455. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + dtdac1.Rows.Count + 2}: I{startIndex})";
  17456. wb.CalculateFormula(true);
  17457. //模板文件名
  17458. string strFileName = $"草稿_{_EnterExitCosts.DraftName}_四川省商务厅出国经费财政先行审核表{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  17459. designer.Workbook.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  17460. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  17461. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  17462. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  17463. }
  17464. else if (dto.SubTypeId == 1066) //成都市因公临时出国任务和预算审批意见表(外专培训团专用)
  17465. {
  17466. //获取模板
  17467. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/成都市因公临时出国任务和预算审批意见表.docx");
  17468. //载入模板
  17469. Document doc = new Document(tempPath);
  17470. DocumentBuilder builder = new DocumentBuilder(doc);
  17471. Dictionary<string, string> dic = new Dictionary<string, string>();
  17472. dic.Add("GroupName", "-");
  17473. dic.Add("ClientUnit", "-");
  17474. //string missionLeader = ""; //团负责人默认接团客户名单第一个人
  17475. //string missionLeaderJob = "";//负责人job
  17476. //int groupNumber = 0; //团人数
  17477. dic.Add("MissionLeader", "-"); //团负责人
  17478. dic.Add("MissionLeaderJob", "-"); //团负责人job
  17479. dic.Add("GroupNumber", "0"); //团人数
  17480. dic.Add("Day", "0");
  17481. dic.Add("CultivateDay", dac4.Count.ToString()); //培训天数
  17482. // dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  17483. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  17484. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  17485. decimal hotelFeeTotal = dac1.Sum(it => it.SubTotal);//住宿费
  17486. dic.Add("HotelFeeTotal", hotelFeeTotal.ToString("#0.00"));
  17487. decimal mealsFeeTotal = dac2.Sum(it => it.SubTotal);//伙食费
  17488. dic.Add("MealsFeeTotal", mealsFeeTotal.ToString("#0.00"));
  17489. decimal miscellaneousFeeTotal = dac3.Sum(it => it.SubTotal);//公杂费
  17490. dic.Add("MiscellaneousFeeTotal", miscellaneousFeeTotal.ToString("#0.00"));
  17491. decimal trainingFeeTotal = dac4.Sum(it => it.SubTotal);//培训费
  17492. dic.Add("TrainingFeeTotal", trainingFeeTotal.ToString("#0.00"));
  17493. decimal cityTranfficFeeToatal = _EnterExitCosts.CityTranffic; //城市区间交通费
  17494. dic.Add("CityTranfficFeeToatal", cityTranfficFeeToatal.ToString("#0.00"));//
  17495. //其他费用
  17496. decimal otherFeeTotal = _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Service + dac5.Sum(x => x.SubTotal);
  17497. dic.Add("OtherFeeTotal", otherFeeTotal.ToString("#0.00"));
  17498. //其他费用合计
  17499. decimal _otherFeeTotal = hotelFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + trainingFeeTotal + cityTranfficFeeToatal + otherFeeTotal;
  17500. decimal _jjcFeeToatal = _EnterExitCosts.AirJJ + _otherFeeTotal; //经济舱
  17501. decimal _gwcFeeToatal = _EnterExitCosts.AirGW + _otherFeeTotal; //公务舱
  17502. //公务舱合计
  17503. //国际旅费
  17504. //string outsideJJ = "";
  17505. //string allPriceJJ = "";
  17506. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 0)
  17507. {
  17508. dic.Add("AirFeeTotal", _EnterExitCosts.AirJJ.ToString("#0.00"));
  17509. dic.Add("FeeTotal", _jjcFeeToatal.ToString("#0.00"));
  17510. }
  17511. if (_EnterExitCosts.SumGWC == 1 && _EnterExitCosts.SumJJC == 0)
  17512. {
  17513. dic.Add("AirFeeTotal", _EnterExitCosts.AirGW.ToString("#0.00"));
  17514. dic.Add("FeeTotal", _gwcFeeToatal.ToString("#0.00"));
  17515. }
  17516. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 1)
  17517. {
  17518. string airFeeTotalStr = string.Format(@$"经济舱:{_EnterExitCosts.AirJJ:#0.00} 公务舱:{_EnterExitCosts.AirGW:#0.00}");
  17519. dic.Add("AirFeeTotal", airFeeTotalStr);
  17520. string feeTotalStr = string.Format(@$"经济舱:{_jjcFeeToatal:#0.00} 公务舱:{_gwcFeeToatal:#0.00}");
  17521. dic.Add("FeeTotal", feeTotalStr);
  17522. }
  17523. foreach (var key in dic.Keys)
  17524. {
  17525. builder.MoveToBookmark(key);
  17526. builder.Write(dic[key]);
  17527. }
  17528. //模板文件名
  17529. string strFileName = $"草稿_{_EnterExitCosts.DraftName}_成都市因公临时出国任务和预算审批意见表(外专培训团专用).docx";
  17530. strFileName = CommonFun.ValidFileName(strFileName);
  17531. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  17532. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  17533. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  17534. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  17535. }
  17536. }
  17537. else if (dto.ExportType == 2) //表格
  17538. {
  17539. return Ok(JsonView(400, "因需关联团组信息和客户信息,请在出入境费用明细里下载!", ""));
  17540. }
  17541. else if (dto.ExportType == 3)
  17542. {
  17543. return Ok(JsonView(400, "因需关联团组信息和客户信息,请在出入境费用明细里下载!", ""));
  17544. }
  17545. return Ok(JsonView(400, "只可导出明细表!", ""));
  17546. }
  17547. catch (Exception ex)
  17548. {
  17549. return Ok(JsonView(400, ex.Message, ""));
  17550. }
  17551. }
  17552. /// <summary>
  17553. /// 团组模块 - 出入境费用-草稿
  17554. /// 获取三公费用标准city
  17555. /// </summary>
  17556. /// <param name="placeData"></param>
  17557. /// <param name="nationalTravelFeeId"></param>
  17558. /// <returns></returns>
  17559. private string GetEnterExitCostDraftExportCity(List<Grp_NationalTravelFee> placeData, int nationalTravelFeeId)
  17560. {
  17561. string _city = string.Empty;
  17562. if (!placeData.Any()) return _city;
  17563. var data = placeData.Find(it => it.Id == nationalTravelFeeId);
  17564. if (data == null) return _city;
  17565. string country = data.Country;
  17566. string city = data.City;
  17567. if (city.Contains("其他城市") || city.Contains("所有城市")) _city = $"{country}-{city}";
  17568. else _city = city;
  17569. return _city;
  17570. }
  17571. /// <summary>
  17572. /// 团组模块 - 出入境费用-草稿
  17573. /// 一键清空
  17574. /// </summary>
  17575. /// <returns></returns>
  17576. [HttpPost]
  17577. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Del)]
  17578. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17579. public async Task<IActionResult> EnterExitCostDraftOneClickEmpty(EnterExitCostDraftOneClickEmptyDto dto)
  17580. {
  17581. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数;"));
  17582. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数;"));
  17583. var _view = await _enterExitCostDraftRep.OneClickEmpty(dto.Id, dto.UserId);
  17584. if (_view.Code == 0)
  17585. {
  17586. return Ok(JsonView(true, "操作成功"));
  17587. }
  17588. return Ok(JsonView(false, "操作失败"));
  17589. }
  17590. /// <summary>
  17591. /// 团组模块 - 出入境费用-草稿
  17592. /// 子项删除
  17593. /// </summary>
  17594. /// <returns></returns>
  17595. [HttpPost]
  17596. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Del)]
  17597. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17598. public async Task<IActionResult> EnterExitCostDraftSubItemDel(EnterExitCostDraftSubItemDelDto dto)
  17599. {
  17600. var data = await _enterExitCostDraftRep.EnterExitCostDraftSubItemDel(dto);
  17601. if (data.Code != 0)
  17602. {
  17603. return Ok(JsonView(false, data.Msg));
  17604. }
  17605. return Ok(JsonView(true, "操作成功!", data.Data));
  17606. }
  17607. /// <summary>
  17608. /// 团组模块 - 出入境费用-草稿
  17609. /// 删除
  17610. /// </summary>
  17611. /// <param name="dto"></param>
  17612. /// <returns></returns>
  17613. [HttpPost]
  17614. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Del)]
  17615. public IActionResult EnterExitCostDraftOtherExpensesDel(EnterExitCostDraftOtherExpensesDelDto dto)
  17616. {
  17617. var jw = JsonView(false, "删除失败!");
  17618. var data = new Grp_DayOtherPriceDraft()
  17619. {
  17620. Id = dto.Id,
  17621. IsDel = 1,
  17622. DeleteUserId = dto.DeleteUserId,
  17623. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  17624. };
  17625. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  17626. if (del > 0)
  17627. {
  17628. jw.Code = 200;
  17629. jw.Msg = "删除成功!";
  17630. }
  17631. return Ok(jw);
  17632. }
  17633. /// <summary>
  17634. /// 团组模块 - 出入境费用-草稿
  17635. /// 导入正式出入境费用基础数据
  17636. /// </summary>
  17637. /// <returns></returns>
  17638. [HttpPost]
  17639. public async Task<IActionResult> EnterExitCostDraftImportDataInit()
  17640. {
  17641. var jw = JsonView(false);
  17642. var groupNameDatas = await _groupRepository.EnterExitCostGroupNameAsync();
  17643. var draftDatas = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.IsDel == 0).OrderByDescending(x => x.CreateTime).Select(x => new { x.Id, x.DraftName }).ToListAsync();
  17644. jw.Code = StatusCodes.Status200OK;
  17645. jw.Msg = "操作成功!";
  17646. jw.Data = new { groupNameDatas, draftNames = draftDatas };
  17647. return Ok(jw);
  17648. }
  17649. /// <summary>
  17650. /// 团组模块 - 出入境费用-草稿
  17651. /// 导入正式出入境费用
  17652. /// </summary>
  17653. /// <param name="dto"></param>
  17654. /// <returns></returns>
  17655. [HttpPost]
  17656. public async Task<IActionResult> EnterExitCostDraftImportData(EnterExitCostDraftImportDataDto dto)
  17657. {
  17658. int userId = dto.UserId,
  17659. portId = dto.PortType,
  17660. groupId = dto.GroupId,
  17661. draftId = dto.DraftId;
  17662. _portTypeData.Add(1);
  17663. if (userId < 1) return Ok(JsonView(false, MsgTips.UserId));
  17664. if (!_portTypeData.Contains(portId)) return Ok(JsonView(false, MsgTips.Port));
  17665. if (groupId < 1) return Ok(JsonView(false, "请传入有效的GroupId!"));
  17666. if (draftId < 1) return Ok(JsonView(false, "请传入有效的DraftId!"));
  17667. _sqlSugar.BeginTran();
  17668. try
  17669. {
  17670. var draftDatas = _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.IsDel == 0 && x.Id == draftId).First();
  17671. if (draftDatas == null)
  17672. {
  17673. _sqlSugar.RollbackTran();
  17674. return Ok(JsonView(false, "草稿数据为空,不可导入!"));
  17675. }
  17676. //验证可覆盖已有数据 两边创建人需为同一人;
  17677. int draftCreateUserId = draftDatas.CreateUserId,
  17678. formalCreateUserId = 0;
  17679. var formalData = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).First();
  17680. if (formalData != null)
  17681. {
  17682. formalCreateUserId = formalData.CreateUserId;
  17683. if (draftCreateUserId != formalCreateUserId)
  17684. {
  17685. _sqlSugar.RollbackTran();
  17686. return Ok(JsonView(false, "由草稿数据到入至正式数据,两边创建人为同一人才可导入正式版!"));
  17687. }
  17688. }
  17689. //默认添加查看、编辑权限(创建人、自己)
  17690. await _enterExitCostRep.InitPerm(dto.GroupId, dto.UserId);
  17691. var dayDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>().Where(x => x.IsDel == 0 && x.ParentId == draftId).ToList();
  17692. var otherDatas = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>().Where(x => x.IsDel == 0 && x.ParentId == draftId).ToList();
  17693. var newExterData = _mapper.Map<Grp_EnterExitCost>(draftDatas);
  17694. newExterData.DiId = groupId;
  17695. newExterData.CreateUserId = userId;
  17696. newExterData.Remark = $"由草稿数据导入;草稿数Id:{draftId}";
  17697. var newDayDatas = _mapper.Map<List<Grp_DayAndCost>>(dayDatas);
  17698. if (newDayDatas.Any()) newDayDatas.Select(x => { x.DiId = groupId; x.CreateUserId = userId; return x; }).ToList();
  17699. var newOtherDatas = _mapper.Map<List<Grp_DayOtherPrice>>(otherDatas);
  17700. if (newOtherDatas.Any()) newOtherDatas.Select(x => { x.Diid = groupId; x.CreateUserId = userId; return x; }).ToList();
  17701. var enterExitCostInfo = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).First();
  17702. //数据如果存在执行删除
  17703. if (enterExitCostInfo != null)
  17704. {
  17705. _sqlSugar.Updateable<Grp_EnterExitCost>()
  17706. .SetColumns(x => new Grp_EnterExitCost() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Remark = "由草稿数据导入前软删除数据!" })
  17707. .Where(x => x.Id == enterExitCostInfo.Id)
  17708. .ExecuteCommand();
  17709. _sqlSugar.Updateable<Grp_DayAndCost>()
  17710. .SetColumns(x => new Grp_DayAndCost() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
  17711. .Where(x => x.DiId == groupId)
  17712. .ExecuteCommand();
  17713. _sqlSugar.Updateable<Grp_DayOtherPrice>()
  17714. .SetColumns(x => new Grp_DayOtherPrice() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
  17715. .Where(x => x.Diid == groupId)
  17716. .ExecuteCommand();
  17717. _sqlSugar.Updateable<Grp_EnterExitCostPermission>()
  17718. .SetColumns(x => new Grp_EnterExitCostPermission() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
  17719. .Where(x => x.GroupId == groupId)
  17720. .ExecuteCommand();
  17721. }
  17722. //执行insert
  17723. var insertId = _sqlSugar.Insertable(newExterData).ExecuteReturnIdentity();
  17724. if (insertId < 1)
  17725. {
  17726. _sqlSugar.RollbackTran();
  17727. return Ok(JsonView(false, "草稿数据导入失败!"));
  17728. }
  17729. if (newDayDatas.Any()) _sqlSugar.Insertable(newDayDatas).ExecuteCommand();
  17730. if (newOtherDatas.Any()) _sqlSugar.Insertable(newOtherDatas).ExecuteCommand();
  17731. #region 默认添加权限
  17732. #endregion
  17733. _sqlSugar.CommitTran();
  17734. //执行操作之后
  17735. //生成默认文件pdf并且通知人员
  17736. var fileView = await GeneralMethod.EnterExitCostDownload(new EnterExitCostDownloadDto()
  17737. {
  17738. DiId = groupId,
  17739. ExportType = 1,
  17740. SubTypeId = 1005
  17741. }, "pdf");
  17742. //发送通知
  17743. string fileUrl = (string)fileView.Data.GetType().GetProperty("Url").GetValue(fileView.Data, null);
  17744. string md5Sign = GeneralMethod.Encrypt($"{insertId}&fileName={fileUrl}");
  17745. string url = string.Format("http://oa.pan-american-intl.com:4399/#/Sankunginfo?sign={0}&fileName={1}", insertId, fileUrl);
  17746. await AppNoticeLibrary.SendUserMsg_GroupShare_ToGM(groupId, new List<string>() { "208", "233", "21" }, dto.UserId, url);
  17747. //汇率信息记录
  17748. await GeneralMethod.RateRecordSave(userId, insertId, "出入境费用-草稿导入");
  17749. return Ok(JsonView(true));
  17750. }
  17751. catch (Exception ex)
  17752. {
  17753. _sqlSugar.RollbackTran();
  17754. return Ok(JsonView(false, ex.Message));
  17755. }
  17756. }
  17757. #endregion
  17758. #region 团组经理模块 出入境费用 移动端(Android/IOS)
  17759. #region 城市区间交通费
  17760. /// <summary>
  17761. /// 团组模块 - 出入境费用 - 移动端 - 基础数据源(境外用车)
  17762. /// </summary>
  17763. /// <param name="groupId"></param>
  17764. /// <returns></returns>
  17765. [HttpGet("{groupId}")]
  17766. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17767. public async Task<IActionResult> EnterExitCostMobileOVByGroupId(int groupId)
  17768. {
  17769. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  17770. if (groupInfo == null)
  17771. {
  17772. return Ok(JsonView(false, "团组信息为空"));
  17773. }
  17774. var countryies = _groupRepository.GroupSplitCountry(groupInfo.VisitCountry);
  17775. if (countryies?.Any() != true)
  17776. {
  17777. return Ok(JsonView(false, "团组出访国家信息为空"));
  17778. }
  17779. var currencies = await GeneralMethod.EnterExitCostOVFeeUsedCurrencyAsync(groupId);
  17780. var currencyData = await _sqlSugar.Queryable<Sys_SetData>()
  17781. .Where(x => x.IsDel == 0 && x.STid == 66)
  17782. .ToListAsync();
  17783. var overseaVehicles = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  17784. .Where(x => x.IsDel == 0 && countryies.Contains(x.CountryName))
  17785. .ToListAsync();
  17786. var overseaVehicleIds = overseaVehicles.Select(x => x.Id).ToList();
  17787. //只返回接送机的数据
  17788. var overseaVehicleTypes = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  17789. .Where(x => x.IsDel == 0 && x.ServiceType == VehicleServiceTypeEnum.TransferService && overseaVehicleIds.Contains(x.OvId))
  17790. .ToListAsync();
  17791. var sysUers = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToListAsync();
  17792. var overseaVehicleCityDatas = new List<dynamic>() {
  17793. new
  17794. {
  17795. Id = 0,
  17796. area= "未选择",
  17797. CarTypeName = "",
  17798. serviceType = "",
  17799. Price = 0.00M,
  17800. guidePrice = 0.00M,
  17801. otherPrice = 0.00M,
  17802. currency = 0,
  17803. currencyName = "",
  17804. currRate = 1.0000M,
  17805. LastUpdateUserName = "",
  17806. LastUpdateTime = "",
  17807. Remark = ""
  17808. }};
  17809. foreach (var item in overseaVehicleTypes)
  17810. {
  17811. var parentInfo = overseaVehicles.FirstOrDefault(x => x.Id == item.OvId);
  17812. string area = string.Empty,
  17813. serviceType = "未设置",
  17814. currencyName = string.Empty;
  17815. decimal otherPrice = 0.00M;
  17816. if (parentInfo != null)
  17817. {
  17818. if (parentInfo.CountryName == parentInfo.CityName) area = parentInfo.CountryName;
  17819. else area = $"{parentInfo.CountryName}-{parentInfo.CityName}";
  17820. serviceType = item.ServiceType.GetDescription();
  17821. currencyName = currencyData.FirstOrDefault(x => x.Id == parentInfo.Currency)?.Name ?? "-";
  17822. otherPrice = parentInfo.OtherPrice1 + parentInfo.OtherPrice2;
  17823. }
  17824. //当前币种汇率值
  17825. var currRate = 1.0000M;
  17826. var currencyInfo = currencies.FirstOrDefault(x => x.CurrencyCode == currencyName);
  17827. if (currencyInfo != null) currRate = currencyInfo.Rate;
  17828. overseaVehicleCityDatas.add(new
  17829. {
  17830. item.Id,
  17831. area,
  17832. item.CarTypeName,
  17833. serviceType,
  17834. item.Price,
  17835. guidePrice = parentInfo?.GuidePrice ?? 0.00M,
  17836. otherPrice,
  17837. currency = parentInfo?.Currency ?? 0,
  17838. currencyName,
  17839. currRate,
  17840. LastUpdateUserName = sysUers.FirstOrDefault(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-",
  17841. item.LastUpdateTime,
  17842. item.Remark
  17843. });
  17844. }
  17845. var total = overseaVehicleCityDatas.Count;
  17846. var view = new
  17847. {
  17848. visitCountries = string.Join("、", countryies),
  17849. groupSize = groupInfo.VisitPNumber, //出访人数
  17850. defAirportTransferCoeff = Def_AirportTransferCoeff, //接送机默认报价系数
  17851. defServiceCount = Def_ServiceCount, //接送机默认服务次数
  17852. defTrainCoeff = Def_TrainCoeff, //火车默认报价系数
  17853. defPullCartCoeff = Def_PullCartCoeff, //拉车默认报价系数
  17854. defCityFlightCoeff = Def_CityFlightCoeff, //城市机票默认报价系数
  17855. Currencies = currencies,
  17856. data = overseaVehicleCityDatas
  17857. };
  17858. if (overseaVehicleCityDatas.Count == 0)
  17859. {
  17860. return Ok(JsonView(true, "暂无数据!", view));
  17861. }
  17862. return Ok(JsonView(true, "查询成功!", view, total));
  17863. }
  17864. /// <summary>
  17865. /// 团组模块 - 出入境费用 - 移动端 - 境外用车计算详细信息
  17866. /// </summary>
  17867. /// <param name="groupId"></param>
  17868. /// <param name="currUserId"></param>
  17869. /// <returns></returns>
  17870. [HttpGet("{groupId}")]
  17871. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17872. public async Task<IActionResult> EnterExitCostMobileOVFeeDetails(int groupId, int currUserId)
  17873. {
  17874. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  17875. if (groupInfo == null)
  17876. {
  17877. return Ok(JsonView(false, "团组信息为空"));
  17878. }
  17879. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).FirstAsync();
  17880. //CityIntervalInfo
  17881. var info = new CityIntervalInfo();
  17882. if (eecInfo != null && !string.IsNullOrEmpty(eecInfo.CityIntervalFeeDetails))
  17883. {
  17884. info = JsonConvert.DeserializeObject<CityIntervalInfo>(eecInfo.CityIntervalFeeDetails);
  17885. return Ok(JsonView(true, "查询成功!", info));
  17886. }
  17887. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == currUserId).FirstAsync();
  17888. var userName = userInfo?.CnName ?? "-";
  17889. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  17890. //返回默认数据
  17891. info = new CityIntervalInfo()
  17892. {
  17893. APTFeeDetails = new List<RoundTripTransferInfo>() { new() { No = 1, Coefficient = Def_AirportTransferCoeff, ServiceCount = Def_ServiceCount } },
  17894. PullCartFeeDetails = new List<PullCartInfo>() { new() { No = 1, Coefficient = Def_PullCartCoeff } },
  17895. TrainFeeDetails = new List<TrainInfo>() { new() { No = 1, Coefficient = Def_TrainCoeff } },
  17896. CityAirTicketFeeDetails = new List<CityAirTicketInfo>() { new() { No = 1, Coefficient = Def_CityFlightCoeff } },
  17897. LastUpdateUserName = userName,
  17898. LastUpdateTime = nowTime,
  17899. CreateUserName = userName,
  17900. Currencies = await GeneralMethod.EnterExitCostOVFeeUsedCurrencyAsync(groupId),
  17901. CreateTime = nowTime
  17902. };
  17903. return Ok(JsonView(true, "查询成功!", info));
  17904. }
  17905. /// <summary>
  17906. /// 团组模块 - 出入境费用 - 移动端 - 境外用车计算 保存
  17907. /// </summary>
  17908. /// <param name="dto"></param>
  17909. /// <returns></returns>
  17910. [HttpPost]
  17911. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17912. public async Task<IActionResult> EnterExitCostMobileOVFeeSave(GetEnterExitCostOVFeeSaveDto dto)
  17913. {
  17914. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == dto.GroupId).FirstAsync();
  17915. if (groupInfo == null)
  17916. {
  17917. return Ok(JsonView(false, "团组信息为空"));
  17918. }
  17919. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == dto.CurrUserId).FirstAsync();
  17920. if (userInfo == null)
  17921. {
  17922. return Ok(JsonView(false, "员工信息为空"));
  17923. }
  17924. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == dto.GroupId).FirstAsync();
  17925. if (eecInfo == null)
  17926. {
  17927. return Ok(JsonView(false, "出入境费用信息为空"));
  17928. }
  17929. var oldData = new CityIntervalInfo();
  17930. if (!string.IsNullOrEmpty(eecInfo.CityIntervalFeeDetails))
  17931. {
  17932. oldData = JsonConvert.DeserializeObject<CityIntervalInfo>(eecInfo.CityIntervalFeeDetails);
  17933. }
  17934. var userName = userInfo?.CnName ?? "-";
  17935. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  17936. var info = new CityIntervalInfo()
  17937. {
  17938. APTFeeTotal = dto.APTFeeTotal,
  17939. APTFeeDetails = dto.APTFeeDetails,
  17940. PullCartFeeTotal = dto.PullCartFeeTotal,
  17941. PullCartFeeDetails = dto.PullCartFeeDetails,
  17942. TrainFeeTotal = dto.TrainFeeTotal,
  17943. TrainFeeDetails = dto.TrainFeeDetails,
  17944. CityAirTicketFeeTotal = dto.CityAirTicketFeeTotal,
  17945. CityAirTicketFeeDetails = dto.CityAirTicketFeeDetails,
  17946. Currencies = dto.Currencies,
  17947. LastUpdateUserName = userName,
  17948. LastUpdateTime = nowTime,
  17949. CreateUserName = oldData?.CreateUserName ?? userName,
  17950. CreateTime = oldData?.CreateTime ?? nowTime
  17951. };
  17952. eecInfo.CityIntervalFeeDetails = JsonConvert.SerializeObject(info);
  17953. var upd = await _sqlSugar.Updateable<Grp_EnterExitCost>()
  17954. .SetColumns(it => it.CityIntervalFeeDetails == eecInfo.CityIntervalFeeDetails)
  17955. .SetColumns(it => it.LastUpdateUserId == dto.CurrUserId)
  17956. .SetColumns(it => it.LastUpdateTime == nowTime)
  17957. .Where(x => x.Id == eecInfo.Id)
  17958. .ExecuteCommandAsync();
  17959. if (upd < 1)
  17960. {
  17961. return Ok(JsonView(false));
  17962. }
  17963. //返回数据处理
  17964. var label = new StringBuilder();
  17965. //接送机
  17966. if (dto.APTFeeDetails?.Any() == true)
  17967. {
  17968. var ovIds = dto.APTFeeDetails.Select(x => x.OvId).ToList();
  17969. var areas = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  17970. .LeftJoin<Res_OverseaVehicle>((ovtp, ov) => ovtp.OvId == ov.Id)
  17971. .Where((ovtp, ov) => ovtp.IsDel == 0 && ovIds.Contains(ovtp.Id))
  17972. .Select((ovtp, ov) => new
  17973. {
  17974. ovtp.Id,
  17975. ov.CountryName,
  17976. ov.CityName
  17977. }).ToListAsync();
  17978. var items = dto.APTFeeDetails
  17979. .Select(item =>
  17980. {
  17981. var areaInfo = areas.FirstOrDefault(x => x.Id == item.OvId);
  17982. if (areaInfo == null) return null;
  17983. return areaInfo.CountryName == areaInfo.CityName
  17984. ? $"{areaInfo.CountryName}({item.Quote:#0.00} CNY)"
  17985. : $"{areaInfo.CountryName}-{areaInfo.CityName}({item.Quote:#0.00} CNY)";
  17986. })
  17987. .Where(item => item != null)
  17988. .ToList();
  17989. label.AppendLine($"接送机({string.Join("、", items)});");
  17990. }
  17991. //拉车
  17992. if (dto.PullCartFeeDetails?.Any() == true)
  17993. {
  17994. var feeLabel = string.Join("、",
  17995. dto.PullCartFeeDetails.Select(x =>
  17996. $"{x.Quote:#0.00} CNY"
  17997. ));
  17998. label.AppendLine($"拉车({feeLabel});");
  17999. }
  18000. //火车
  18001. if (dto.TrainFeeDetails?.Any() == true)
  18002. {
  18003. var feeLabel = string.Join("、",
  18004. dto.TrainFeeDetails.Select(x =>
  18005. $"{x.Quote:#0.00} CNY"
  18006. ));
  18007. label.AppendLine($"火车票({feeLabel});");
  18008. }
  18009. //城市机票
  18010. if (dto.CityAirTicketFeeDetails?.Any() == true)
  18011. {
  18012. var feeLabel = string.Join("、",
  18013. dto.CityAirTicketFeeDetails.Select(x =>
  18014. $"{x.Quote:#0.00} CNY"
  18015. ));
  18016. label.AppendLine($"城市机票({feeLabel});");
  18017. }
  18018. //费用
  18019. decimal quote = (dto.APTFeeTotal + dto.PullCartFeeTotal + dto.TrainFeeTotal + dto.CityAirTicketFeeTotal).ConvertToDecimal1();
  18020. decimal jjcQuote = quote;
  18021. decimal gwcQuote = quote;
  18022. decimal tdcQuote = quote;
  18023. var view = new
  18024. {
  18025. label = label.ToString(),
  18026. jjcQuote,
  18027. gwcQuote,
  18028. tdcQuote
  18029. };
  18030. return Ok(JsonView(view));
  18031. }
  18032. #endregion
  18033. /// <summary>
  18034. /// 获取币种基础数据(含逻辑处理)
  18035. /// </summary>
  18036. /// <returns></returns>
  18037. private async Task<List<CurrencyInfo>> EnterExitCostMobileGetCurrencyInit()
  18038. {
  18039. return await GeneralMethod.EnterExitCostInitRate();
  18040. }
  18041. /// <summary>
  18042. /// 团组模块 - 出入境费用-移动端 - 基础数据源(Word明细类型、Excel明细类型、默认币种显示)
  18043. /// </summary>
  18044. /// <returns></returns>
  18045. [HttpPost]
  18046. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18047. public async Task<IActionResult> EnterExitCostMobileDataSource(EnterExitCostMobileDataSourceDto dto)
  18048. {
  18049. //验证城市归属并给默认值
  18050. int provinceId = dto.ProvinceId;
  18051. if (provinceId < 1) provinceId = 122;
  18052. var dataSource = await _sqlSugar
  18053. .Queryable<Sys_SetData>()
  18054. .Where(x => x.IsDel == 0 && (x.STid == 72 || x.STid == 73) && x.Remark.Contains(provinceId.ToString()))
  18055. .ToListAsync();
  18056. var fileTypes = new List<EecSetDataInfoView>();
  18057. //三公费用-Word明细类型
  18058. var wordTypeData = dataSource
  18059. .Where(it => it.STid == 72)
  18060. .Select(x => new EecSetDataInfoView
  18061. {
  18062. ParentId = 1,
  18063. Id = x.Id,
  18064. Name = x.Name
  18065. })
  18066. .ToArray();
  18067. if (wordTypeData.Any()) fileTypes.AddRange(wordTypeData);
  18068. var excelTypeData = dataSource
  18069. .Where(it => it.STid == 73)
  18070. .Select(x => new EecSetDataInfoView
  18071. {
  18072. ParentId = 2,
  18073. Id = x.Id,
  18074. Name = x.Name
  18075. })
  18076. .ToArray();
  18077. if (excelTypeData.Any()) fileTypes.AddRange(excelTypeData);
  18078. var groupNameList = new EecSetDataInfoView() { ParentId = 3, Id = 1, Name = "团组成员名单" };
  18079. fileTypes.Add(groupNameList);
  18080. fileTypes = fileTypes.OrderBy(x => x.ParentId).ThenBy(x => x.Id).ToList();
  18081. //默认币种显示
  18082. var _currencyInfos = await EnterExitCostMobileGetCurrencyInit();
  18083. var viewPermissionData = await _enterExitCostRep.PermissionViewUsersAsync();
  18084. return Ok(JsonView(true, "查询成功!", new
  18085. {
  18086. FileTypeData = fileTypes,
  18087. CurrencyInit = _currencyInfos,
  18088. viewPermissionData = viewPermissionData
  18089. }));
  18090. }
  18091. /// <summary>
  18092. /// 团组模块 - 出入境费用-移动端 - 团组基础数据Data
  18093. /// </summary>
  18094. /// <returns></returns>
  18095. [HttpPost]
  18096. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18097. public async Task<IActionResult> EnterExitCostMobileGroupData(PostEnterExitCostMobileGroupDataDto dto)
  18098. {
  18099. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18100. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18101. RefAsync<int> total = 0;
  18102. int diId = 0;
  18103. var status = int.TryParse(dto.GroupName, out diId);
  18104. var basicUserId = await _enterExitCostRep.PermissionViewUsersAsync();
  18105. var data = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  18106. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.TeamName))
  18107. .WhereIF(!string.IsNullOrEmpty(dto.GroupName) && diId > 0, x => x.Id == diId)
  18108. .WhereIF(!string.IsNullOrEmpty(dto.GroupName) && !status, x => x.TeamName.Contains(dto.GroupName))
  18109. .OrderByDescending(x => x.VisitStartDate)
  18110. .Select(x => new EnterExitCostMobileGroupView()
  18111. {
  18112. Id = x.Id,
  18113. GroupName = x.TeamName,
  18114. IsNull = SqlFunc.Subqueryable<Grp_EnterExitCost>().Where(x1 => x1.DiId == x.Id && x1.IsDel == 0).Any() ? false : true,
  18115. IsView = SqlFunc.Subqueryable<Grp_EnterExitCostPermission>().Where(x1 => x1.GroupId == x.Id && x1.UserId == dto.CurrUserId).Any(),
  18116. ProvinceId = x.CityId
  18117. })
  18118. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  18119. //处理省份Id
  18120. if (data.Any())
  18121. {
  18122. var provCityDatas = await _groupRepository.ProvinceCityBasicSource();
  18123. if (provCityDatas.Any())
  18124. {
  18125. foreach (var item in data)
  18126. {
  18127. var provinceId = item.ProvinceId;
  18128. var isDefualtVal = true;
  18129. if (provinceId > 0)
  18130. {
  18131. var parentId = _groupRepository.FindParentIdByChildId(provCityDatas, provinceId);
  18132. if (parentId != null)
  18133. {
  18134. isDefualtVal = false;
  18135. item.ProvinceId = (int)parentId;
  18136. }
  18137. }
  18138. if (isDefualtVal)
  18139. {
  18140. item.ProvinceId = 122; //默认四川
  18141. }
  18142. }
  18143. }
  18144. }
  18145. //处理是否显示
  18146. if (basicUserId.Any(x => x.Id == dto.CurrUserId))
  18147. {
  18148. foreach (var item in data)
  18149. {
  18150. item.IsView = true;
  18151. }
  18152. }
  18153. return Ok(JsonView(true, "查询成功!", data, total));
  18154. }
  18155. /// <summary>
  18156. /// 团组模块 - 出入境费用-移动端 - 币种基础数据Data
  18157. /// </summary>
  18158. /// <returns></returns>
  18159. [HttpPost]
  18160. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18161. public async Task<IActionResult> EnterExitCostMobileCurrencyData(PostEnterExitCostMobileCurrencyDataDto dto)
  18162. {
  18163. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18164. RefAsync<int> total = 0;
  18165. var data = await _sqlSugar.Queryable<Sys_SetData>()
  18166. .Where(x => x.IsDel == 0 && x.STid == 66)
  18167. .WhereIF(!string.IsNullOrEmpty(dto.CurrencyName), x => x.Name.ToLower().Contains(dto.CurrencyName) || x.Remark.Contains(dto.CurrencyName))
  18168. .Select(x => new
  18169. {
  18170. id = x.Id,
  18171. name = x.Name,
  18172. remark = x.Remark,
  18173. })
  18174. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  18175. return Ok(JsonView(true, "查询成功!", data, total));
  18176. }
  18177. /// <summary>
  18178. /// 团组模块 - 出入境费用-移动端 - 其他款项 - 币种、费用类型基础数据Data
  18179. /// </summary>
  18180. /// <returns></returns>
  18181. [HttpPost]
  18182. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18183. public async Task<IActionResult> EnterExitCostMobileOtherItemCurrencyData(PostEnterExitCostMobileOtherItemCurrencyDataDto dto)
  18184. {
  18185. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18186. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18187. var groupRateData = await GeneralMethod.PostGroupTeamRateByDiIdAndCTableId(dto.PortType, dto.DiId, 98);
  18188. if (groupRateData == null) return Ok(JsonView(false, "请填写“团组汇率-->其他款项”汇率!"));
  18189. var groupOtherRateData = groupRateData.TeamRates;
  18190. var enterExitCostInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().FirstAsync(it => it.DiId == dto.DiId && it.IsDel == 0);
  18191. if (enterExitCostInfo == null) return Ok(JsonView(groupOtherRateData));
  18192. var eecRateData = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(enterExitCostInfo.CurrencyRemark);
  18193. groupOtherRateData = groupOtherRateData
  18194. .Select(x => new TeamRateDescAddCurrencyIdView
  18195. {
  18196. CurrencyId = x.CurrencyId,
  18197. CurrencyName = x.CurrencyName,
  18198. CurrencyCode = x.CurrencyCode,
  18199. Rate = eecRateData.Find(it => it.CurrencyCode.ToUpper().Equals(x.CurrencyCode.ToUpper()))?.Rate ?? x.Rate
  18200. }).ToList();
  18201. var otherFeeTypeData = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 92).Select(x => new { x.Id, x.Name }).ToListAsync();
  18202. return Ok(JsonView(true, "查询成功!", new { groupOtherRateData = groupOtherRateData, otherFeeTypeData = otherFeeTypeData }));
  18203. }
  18204. /// <summary>
  18205. /// 团组模块 - 出入境费用-移动端 - 实时汇率、签证费用、机票费用 Tips
  18206. /// </summary>
  18207. /// <returns></returns>
  18208. [HttpPost]
  18209. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18210. public async Task<IActionResult> EnterExitCostMobileFeeTips(GetEnterExitCostMobileFeeTipsDto dto)
  18211. {
  18212. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18213. if (dto.GroupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18214. var tipsData = new List<int>() { 1, 2, 3 };
  18215. if (!tipsData.Contains(dto.TipsType)) return Ok(JsonView(false, $"请传入有效的TipsType参数;1 实时汇率;2 签证费用;3 机票费用;"));
  18216. if (dto.TipsType == 1)
  18217. {
  18218. return Ok(JsonView(true, "查询成功!", await GeneralMethod.EnterExitCostLiveRate()));
  18219. }
  18220. else if (dto.TipsType == 2)
  18221. {
  18222. var visaData = await _visaFeeInfoRep.EnterExitCostVisaTips(dto.GroupId);
  18223. return Ok(JsonView(true, "查询成功!", visaData.Data));
  18224. }
  18225. else if (dto.TipsType == 3)
  18226. {
  18227. var airData = await GeneralMethod.EntryAndExitTips(dto.GroupId);
  18228. return Ok(JsonView(true, "查询成功!", airData));
  18229. }
  18230. return Ok(JsonView(false));
  18231. }
  18232. /// <summary>
  18233. /// 团组模块 - 出入境国家费用标准-移动端 List
  18234. /// </summary>
  18235. /// <returns></returns>
  18236. [HttpPost]
  18237. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18238. public async Task<IActionResult> NationalTravelFeeMobileData(PostNationalTravelFeeMobileDataDto dto)
  18239. {
  18240. Stopwatch sw = new Stopwatch();
  18241. sw.Start();
  18242. int provinceId = dto.ProvinceId;
  18243. if (provinceId < 1) provinceId = 122; // 默认四川
  18244. RefAsync<int> total = 0;
  18245. var data = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  18246. .LeftJoin<Sys_SetData>((ntf, sd) => ntf.Currency == sd.Id)
  18247. .LeftJoin<Sys_Users>((ntf, sd, u) => ntf.CreateUserId == u.Id)
  18248. .LeftJoin<Sys_Cities>((ntf, sd, u, sd1) => ntf.ProvinceId == sd1.Id)
  18249. .Where((ntf, sd, u, sd1) => ntf.IsDel == 0 && ntf.ProvinceId == provinceId)
  18250. .WhereIF(!string.IsNullOrEmpty(dto.Search), (ntf, sd, u, sd1) => dto.Search.Contains(ntf.Country) || dto.Search.Contains(ntf.City))
  18251. .Select((ntf, sd, u, sd1) => new
  18252. {
  18253. Id = ntf.Id,
  18254. Area = $"{ntf.Country}-{ntf.City}",
  18255. Currency = ntf.Currency,
  18256. CurrencyCode = sd.Name,
  18257. CurrencyName = sd.Remark,
  18258. RoomCost = ntf.RoomCost,
  18259. FoodCost = ntf.FoodCost,
  18260. PublicCost = ntf.PublicCost,
  18261. TrainCost = ntf.TrainCost,
  18262. LastUpdateUserId = ntf.LastUpdateUserId,
  18263. LastUpdateUserName = u.CnName,
  18264. LastUpdateTime = ntf.LastUpdateTime
  18265. })
  18266. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  18267. sw.Stop();
  18268. return Ok(JsonView(true, "查询成功!耗时:" + sw.ElapsedMilliseconds + "ms", data, total));
  18269. }
  18270. /// <summary>
  18271. /// 团组模块 - 出入境费用-移动端 - Info
  18272. /// </summary>
  18273. /// <returns></returns>
  18274. [HttpPost]
  18275. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18276. public async Task<IActionResult> EnterExitCostMobileInfo(EnterExitCostInfobyDiIdDto dto)
  18277. {
  18278. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18279. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18280. var data = await _enterExitCostRep.GetEnterExitCostInfoByDiId(dto);
  18281. return Ok(data);
  18282. }
  18283. /// <summary>
  18284. /// 团组模块 - 出入境费用-移动端 - ParentInfo
  18285. /// </summary>
  18286. /// <returns></returns>
  18287. [HttpPost]
  18288. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18289. public async Task<IActionResult> EnterExitCostMobileParentInfo(EnterExitCostInfobyDiIdDto dto)
  18290. {
  18291. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18292. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18293. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18294. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.DiId == dto.DiId && it.IsDel == 0);
  18295. var mobileInfo = new EnterExitCostMobileParentInfoView();
  18296. mobileInfo.DiId = dto.DiId;
  18297. mobileInfo.Currencys = await EnterExitCostMobileGetCurrencyInit();
  18298. if (eecInfo == null) return Ok(mobileInfo);
  18299. //验证查看权限
  18300. (bool isView, bool isSet) = await _enterExitCostRep.PermissionValidationAsync(dto.DiId, dto.CurrUserId);
  18301. if (!isView) return Ok(JsonView(false, "没有查看权限!"));
  18302. mobileInfo = _mapper.Map<EnterExitCostMobileParentInfoView>(eecInfo);
  18303. mobileInfo.IsAssignPerm = isSet;
  18304. var dayAndCostData = _sqlSugar.Queryable<Grp_DayAndCost>()
  18305. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  18306. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  18307. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId)
  18308. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  18309. {
  18310. SubId = dac.Id,
  18311. DiId = dac.DiId,
  18312. Type = dac.Type,
  18313. Days = dac.Days,
  18314. NationalTravelFeeId = dac.NationalTravelFeeId,
  18315. Arae = $"{ntf.Country}-{ntf.City}",
  18316. Cost = dac.Cost,
  18317. Currency = dac.Currency,
  18318. CurrencyName = sd.Name,
  18319. SubTotal = dac.SubTotal,
  18320. })
  18321. .ToList();
  18322. mobileInfo.ChoiceOneTotalCost = eecInfo.InsidePay;
  18323. mobileInfo.ChoiceTwoJJ = eecInfo.SumJJC;
  18324. mobileInfo.ChoiceTwoGW = eecInfo.SumGWC;
  18325. mobileInfo.ChoiceTwoTD = eecInfo.SumTDC;
  18326. mobileInfo.Currencys = !string.IsNullOrEmpty(eecInfo.CurrencyRemark) ? CommonFun.GetCurrencyChinaToList(eecInfo.CurrencyRemark) : mobileInfo.Currencys;
  18327. mobileInfo.ChoiceThreeTotalCost = dayAndCostData.Where(it => it.Type == 1).Sum(x => x.SubTotal); //住宿费 1
  18328. mobileInfo.ChoiceFourTotalCost = dayAndCostData.Where(it => it.Type == 2).Sum(x => x.SubTotal); //伙食费 2
  18329. mobileInfo.ChoiceFiveTotalCost = dayAndCostData.Where(it => it.Type == 3).Sum(x => x.SubTotal); //公杂费 3
  18330. mobileInfo.ChoiceSixTotalCost = dayAndCostData.Where(it => it.Type == 4).Sum(x => x.SubTotal); //培训费 4
  18331. //其他款项
  18332. var otherData = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  18333. .LeftJoin<Sys_SetData>((dop, sd1) => dop.SetDataId == sd1.Id)
  18334. .LeftJoin<Sys_SetData>((dop, sd1, sd2) => dop.Currency == sd2.Id)
  18335. .Where((dop, sd1, sd2) => dop.IsDel == 0 && dop.Diid == dto.DiId)
  18336. .OrderBy((dop, sd1, sd2) => dop.Index)
  18337. .Select((dop, sd1, sd2) => new DayOtherPriceMobileInfoView
  18338. {
  18339. SubId = dop.Id,
  18340. DiId = dop.Diid,
  18341. Index = dop.Index,
  18342. SetDataId = dop.SetDataId,
  18343. SetDataName = sd1.Name,
  18344. Cost = dop.Cost,
  18345. Currency = dop.Currency,
  18346. CurrencyName = sd2.Remark,
  18347. SubTotal = dop.SubTotal,
  18348. Remark = dop.Remark,
  18349. })
  18350. .ToArray();
  18351. mobileInfo.OtherExpensesTotalCost = otherData.Sum(x => x.SubTotal);
  18352. return Ok(mobileInfo);
  18353. }
  18354. /// <summary>
  18355. /// 团组模块 - 出入境费用-移动端 - 查看权限用户
  18356. /// </summary>
  18357. /// <returns></returns>
  18358. [HttpPost]
  18359. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18360. public async Task<IActionResult> EnterExitCostMobileViewPermissionUsers(EnterExitCostMobileViewPermissionUsersDto dto)
  18361. {
  18362. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18363. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18364. //验证查看权限
  18365. (bool viewPerm, bool assignPerm) = await _enterExitCostRep.PermissionValidationAsync(dto.DiId, dto.CurrUserId);//分配权限
  18366. if (!viewPerm) return Ok(JsonView(false, "未分配查看权限,如要查看,请联系市场部或国交部负责人!"));
  18367. var userIds = await _sqlSugar
  18368. .Queryable<Grp_EnterExitCostPermission>()
  18369. .Where(x => x.IsDel == 0 && x.GroupId == dto.DiId)
  18370. .Select(x => x.UserId)
  18371. .ToArrayAsync();
  18372. var perUsers = await _enterExitCostRep.PermissionViewUsersAsync();
  18373. var perUsersView = new List<dynamic>();
  18374. foreach (var item in perUsers)
  18375. {
  18376. bool isView1 = false;
  18377. if (userIds.Any(x => x == item.Id)) isView1 = true;
  18378. perUsersView.Add(new { Id = item.Id, Name = item.Name, IsView = isView1 });
  18379. }
  18380. return Ok(JsonView(perUsersView));
  18381. }
  18382. /// <summary>
  18383. /// 团组模块 - 出入境费用-移动端 - SubInfo
  18384. /// </summary>
  18385. /// <returns></returns>
  18386. [HttpPost]
  18387. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18388. public async Task<IActionResult> EnterExitCostMobileSubInfo(PostEnterExitCostMobileSubInfoDto dto)
  18389. {
  18390. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18391. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18392. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18393. var subTypes = new List<int>() { 1, 2, 3, 4, 5, 6, 7 };
  18394. if (!subTypes.Contains(dto.SubType)) return Ok(JsonView(false, $"请传入有效的subTypeId!"));
  18395. //验证查看权限
  18396. //(bool isView, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId);
  18397. //if (!isView) return Ok(JsonView(false, msg));
  18398. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.DiId == dto.DiId && it.IsDel == 0);
  18399. if (eecInfo == null) return Ok(JsonView(false, $"出入境费用明细未录入!"));
  18400. var subType = dto.SubType;
  18401. if (subType == 1) //1:境内费用
  18402. {
  18403. var oneData = new ChoiceOneMobileSubInfoView()
  18404. {
  18405. Id = eecInfo.Id,
  18406. ChoiceOne = eecInfo.ChoiceOne,
  18407. ChoiceOneTotalCost = eecInfo.InsidePay,
  18408. Visa = eecInfo.Visa,
  18409. VisaRemark = eecInfo.VisaRemark,
  18410. YiMiao = eecInfo.YiMiao,
  18411. HeSuan = eecInfo.HeSuan,
  18412. Service = eecInfo.Service,
  18413. Ticket = eecInfo.Ticket,
  18414. Safe = eecInfo.Safe,
  18415. FirstItemRemark = eecInfo.FirstItemRemark
  18416. };
  18417. return Ok(JsonView(oneData));
  18418. }
  18419. else if (subType == 2) //2:国际旅费
  18420. {
  18421. var twoData = new ChoiceTwoMobileSubInfoView()
  18422. {
  18423. Id = eecInfo.Id,
  18424. ChoiceTwoJJ = eecInfo.SumJJC,
  18425. OutsideJJPay = eecInfo.OutsideJJPay,
  18426. ChoiceTwoGW = eecInfo.SumGWC,
  18427. OutsideGWPay = eecInfo.OutsideGWPay,
  18428. ChoiceTwoTD = eecInfo.SumTDC,
  18429. OutsideTDPay = eecInfo.OutsideTDPay,
  18430. AirJJ = eecInfo.AirJJ,
  18431. AirGW = eecInfo.AirGW,
  18432. AirTD = eecInfo.AirTD,
  18433. CityTranffic = eecInfo.CityTranffic,
  18434. CityTranffic1 = eecInfo.CityTranffic1,
  18435. CityTranffic2 = eecInfo.CityTranffic2,
  18436. TwoItemRemark = eecInfo.TwoItemRemark
  18437. };
  18438. return Ok(JsonView(twoData));
  18439. }
  18440. else if (subType == 3) //3:住宿费
  18441. {
  18442. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCost>()
  18443. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  18444. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  18445. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId && dac.Type == 1)
  18446. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  18447. {
  18448. SubId = dac.Id,
  18449. DiId = dac.DiId,
  18450. Type = dac.Type,
  18451. Days = dac.Days,
  18452. NationalTravelFeeId = dac.NationalTravelFeeId,
  18453. Arae = $"{ntf.Country}-{ntf.City}",
  18454. Cost = dac.Cost,
  18455. Currency = dac.Currency,
  18456. CurrencyName = sd.Name,
  18457. SubTotal = dac.SubTotal,
  18458. })
  18459. .ToArray();
  18460. var data = new ChoiceMobileSubInfo3To6View()
  18461. {
  18462. ParentId = eecInfo.Id,
  18463. Choice = eecInfo.ChoiceThree,
  18464. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  18465. Details = dayAndCostDatas
  18466. };
  18467. return Ok(JsonView(data));
  18468. }
  18469. else if (subType == 4) //4:伙食费
  18470. {
  18471. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCost>()
  18472. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  18473. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  18474. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId && dac.Type == 2)
  18475. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  18476. {
  18477. SubId = dac.Id,
  18478. DiId = dac.DiId,
  18479. Type = dac.Type,
  18480. Days = dac.Days,
  18481. NationalTravelFeeId = dac.NationalTravelFeeId,
  18482. Arae = $"{ntf.Country}-{ntf.City}",
  18483. Cost = dac.Cost,
  18484. Currency = dac.Currency,
  18485. CurrencyName = sd.Name,
  18486. SubTotal = dac.SubTotal,
  18487. })
  18488. .ToArray();
  18489. var data = new ChoiceMobileSubInfo3To6View()
  18490. {
  18491. ParentId = eecInfo.Id,
  18492. Choice = eecInfo.ChoiceFour,
  18493. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  18494. Details = dayAndCostDatas
  18495. };
  18496. return Ok(JsonView(data));
  18497. }
  18498. else if (subType == 5) //5:公杂费
  18499. {
  18500. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCost>()
  18501. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  18502. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  18503. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId && dac.Type == 3)
  18504. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  18505. {
  18506. SubId = dac.Id,
  18507. DiId = dac.DiId,
  18508. Type = dac.Type,
  18509. Days = dac.Days,
  18510. NationalTravelFeeId = dac.NationalTravelFeeId,
  18511. Arae = $"{ntf.Country}-{ntf.City}",
  18512. Cost = dac.Cost,
  18513. Currency = dac.Currency,
  18514. CurrencyName = sd.Name,
  18515. SubTotal = dac.SubTotal,
  18516. })
  18517. .ToArray();
  18518. var data = new ChoiceMobileSubInfo3To6View()
  18519. {
  18520. ParentId = eecInfo.Id,
  18521. Choice = eecInfo.ChoiceFive,
  18522. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  18523. Details = dayAndCostDatas
  18524. };
  18525. return Ok(JsonView(data));
  18526. }
  18527. else if (subType == 6) //6:培训费
  18528. {
  18529. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCost>()
  18530. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  18531. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  18532. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId && dac.Type == 4)
  18533. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  18534. {
  18535. SubId = dac.Id,
  18536. DiId = dac.DiId,
  18537. Type = dac.Type,
  18538. Days = dac.Days,
  18539. NationalTravelFeeId = dac.NationalTravelFeeId,
  18540. Arae = $"{ntf.Country}-{ntf.City}",
  18541. Cost = dac.Cost,
  18542. Currency = dac.Currency,
  18543. CurrencyName = sd.Name,
  18544. SubTotal = dac.SubTotal,
  18545. })
  18546. .ToArray();
  18547. var data = new ChoiceMobileSubInfo3To6View()
  18548. {
  18549. ParentId = eecInfo.Id,
  18550. Choice = eecInfo.ChoiceSix,
  18551. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  18552. Details = dayAndCostDatas
  18553. };
  18554. return Ok(JsonView(data));
  18555. }
  18556. else if (subType == 7) //7:其他
  18557. {
  18558. //其他款项
  18559. var otherData = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  18560. .LeftJoin<Sys_SetData>((dop, sd1) => dop.SetDataId == sd1.Id)
  18561. .LeftJoin<Sys_SetData>((dop, sd1, sd2) => dop.Currency == sd2.Id)
  18562. .Where((dop, sd1, sd2) => dop.IsDel == 0 && dop.Diid == dto.DiId)
  18563. .OrderBy((dop, sd1, sd2) => dop.Index)
  18564. .Select((dop, sd1, sd2) => new DayOtherPriceMobileInfoView
  18565. {
  18566. SubId = dop.Id,
  18567. DiId = dop.Diid,
  18568. Index = dop.Index,
  18569. SetDataId = dop.SetDataId,
  18570. SetDataName = sd1.Name,
  18571. Cost = dop.Cost,
  18572. Currency = dop.Currency,
  18573. CurrencyName = sd2.Name,
  18574. SubTotal = dop.SubTotal,
  18575. Remark = dop.Remark,
  18576. })
  18577. .ToArray();
  18578. var data = new ChoiceSevenMobileSubInfoView()
  18579. {
  18580. ParentId = eecInfo.Id,
  18581. OtherExpenses_Checked = eecInfo.OtherExpenses_Checked,
  18582. OtherExpensesTotalCost = otherData.Sum(x => x.SubTotal),
  18583. Details = otherData
  18584. };
  18585. return Ok(JsonView(data));
  18586. }
  18587. return Ok(JsonView(false));
  18588. }
  18589. #region op
  18590. ///// <summary>
  18591. ///// 移动端更新费用消息通知
  18592. ///// </summary>
  18593. ///// <param name="diid"></param>
  18594. ///// <param name="id"></param>
  18595. ///// <param name="currUserId"></param>
  18596. //private async Task EnterExitCostMobileOpNotice(int diid, int id, int currUserId)
  18597. //{
  18598. // try
  18599. // {
  18600. // ////生成默认文件pdf并且通知人员
  18601. // //var fileView = await GeneralMethod.EnterExitCostDownload(new EnterExitCostDownloadDto()
  18602. // //{
  18603. // // DiId = diid,
  18604. // // ExportType = 1,
  18605. // // SubTypeId = 1005
  18606. // //}, "pdf");
  18607. // ////发送通知
  18608. // //string fileUrl = (string)fileView.Data.GetType().GetProperty("Url").GetValue(fileView.Data, null);
  18609. // //string md5Sign = GeneralMethod.Encrypt($"{id}&fileName={fileUrl}");
  18610. // //string url = string.Format("http://oa.pan-american-intl.com:4399/#/Sankunginfo?sign={0}&fileName={1}", id, fileUrl);
  18611. // //await AppNoticeLibrary.SendUserMsg_GroupShare_ToGM(diid, new List<string>() { "208", "233", "21" }, currUserId, url);
  18612. // ////汇率信息记录
  18613. // //await GeneralMethod.RateRecordSave(currUserId, id, "出入境费用");
  18614. // }
  18615. // catch (Exception ex)
  18616. // {
  18617. // //记录日志
  18618. // throw;
  18619. // }
  18620. //}
  18621. /// <summary>
  18622. /// 验证出入境费用数据是否存在
  18623. /// 不存在添加
  18624. /// </summary>
  18625. /// <param name="diId"></param>
  18626. /// <param name="currUserId"></param>
  18627. /// <returns></returns>
  18628. private async Task<int> EnterExitCostVerifyIsNull(int diId, int currUserId)
  18629. {
  18630. var parentId = 0;
  18631. var info = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == diId).OrderByDescending(x => x.CreateTime).FirstAsync();
  18632. if (info != null)
  18633. {
  18634. parentId = info.Id;
  18635. }
  18636. else
  18637. {
  18638. var currencys = await EnterExitCostMobileGetCurrencyInit();
  18639. int addId = await _sqlSugar.Insertable(new Grp_EnterExitCost() { DiId = diId, CreateUserId = currUserId, CurrencyRemark = JsonConvert.SerializeObject(currencys) }).ExecuteReturnIdentityAsync();
  18640. parentId = addId;
  18641. }
  18642. return parentId;
  18643. }
  18644. /// <summary>
  18645. /// 团组模块 - 出入境费用-移动端 - 设置view权限
  18646. /// </summary>
  18647. /// <returns></returns>
  18648. [HttpPost]
  18649. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18650. public async Task<IActionResult> EnterExitCostMobileSetViewPermissiion(EnterExitCostMobileSetViewPermissiionDto dto)
  18651. {
  18652. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18653. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18654. if (dto.UserIds.Length < 1) return Ok(JsonView(false, "请传入有效的userId;"));
  18655. //验证编辑权限
  18656. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  18657. //if (!isEdit) return Ok(JsonView(false, msg));
  18658. var permissions = new List<Grp_EnterExitCostPermission>();
  18659. foreach (var userId in dto.UserIds)
  18660. {
  18661. permissions.Add(new Grp_EnterExitCostPermission { Permission = 1, GroupId = dto.DiId, UserId = userId, CreateUserId = dto.CurrUserId });
  18662. }
  18663. if (permissions.Any())
  18664. {
  18665. if (!permissions.Any(x => x.UserId == dto.CurrUserId))
  18666. {
  18667. permissions.Add(new Grp_EnterExitCostPermission { Permission = 1, GroupId = dto.DiId, UserId = dto.CurrUserId, CreateUserId = dto.CurrUserId });
  18668. }
  18669. _sqlSugar.BeginTran();
  18670. await _sqlSugar.Deleteable<Grp_EnterExitCostPermission>().Where(it => it.GroupId == dto.DiId).ExecuteCommandAsync();
  18671. var result = await _sqlSugar.Insertable(permissions).ExecuteCommandAsync();
  18672. if (result < 1)
  18673. {
  18674. _sqlSugar.RollbackTran();
  18675. return Ok(JsonView(false));
  18676. }
  18677. _sqlSugar.CommitTran();
  18678. return Ok(JsonView(true));
  18679. }
  18680. return Ok(JsonView(false));
  18681. }
  18682. /// <summary>
  18683. /// 团组模块 - 出入境费用-移动端 - OP --> 汇率
  18684. /// </summary>
  18685. /// <returns></returns>
  18686. [HttpPost]
  18687. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18688. public async Task<IActionResult> EnterExitCostMobileOpRate(PostEnterExitCostMobileFeeRateOpDto dto)
  18689. {
  18690. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18691. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18692. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18693. if (dto.Currencys.Length < 1) return Ok(JsonView(false, "请传入有效的汇率信息!"));
  18694. var currencyStr = CommonFun.GetCurrencyChinaToString(dto.Currencys.ToList());
  18695. int id = dto.Id;
  18696. if (id <= 0) //add
  18697. {
  18698. //int provinceId = dto.ProvinceId;
  18699. int groupId = dto.DiId;
  18700. //if (provinceId < 1) provinceId = 122;
  18701. var info = new Grp_EnterExitCost() { DiId = groupId, CurrencyRemark = currencyStr, CreateUserId = dto.CurrUserId };
  18702. info.LastUpdateUserId = dto.CurrUserId;
  18703. info.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  18704. var add = await _sqlSugar.Insertable(info).ExecuteCommandAsync();
  18705. if (add < 1) return Ok(JsonView(false));
  18706. id = add;
  18707. }
  18708. else //update
  18709. {
  18710. ////验证编辑权限
  18711. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  18712. //if (!isEdit) return Ok(JsonView(false, msg));
  18713. var upd = await _sqlSugar.Updateable<Grp_EnterExitCost>().SetColumns(x => new Grp_EnterExitCost()
  18714. {
  18715. CurrencyRemark = currencyStr,
  18716. LastUpdateUserId = dto.CurrUserId,
  18717. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  18718. }).Where(x => x.Id == dto.Id).ExecuteCommandAsync();
  18719. if (upd < 1) return Ok(JsonView(false));
  18720. }
  18721. #region 汇率变更时更改币种相关费用
  18722. var opDayCosts = new List<Grp_DayAndCost>();
  18723. var opDayOtherCosts = new List<Grp_DayOtherPrice>();
  18724. var eecCurrencys = dto.Currencys.Select(x => x.CurrencyCode.ToUpper()).ToList();
  18725. var dayCosts = _sqlSugar.Queryable<Grp_DayAndCost>()
  18726. .LeftJoin<Sys_SetData>((dac, sd) => dac.Currency == sd.Id)
  18727. .Where((dac, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId)
  18728. .Select((dac, sd) => new
  18729. {
  18730. dac.Id,
  18731. dac.DiId,
  18732. CurrencyCode = sd.Name,
  18733. dac.Cost
  18734. })
  18735. .ToList();
  18736. var dayOtherCosts = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  18737. .LeftJoin<Sys_SetData>((dop, sd) => dop.Currency == sd.Id)
  18738. .Where((dop, sd) => dop.IsDel == 0 && dop.Diid == dto.DiId)
  18739. .Select((dop, sd) => new
  18740. {
  18741. dop.Id,
  18742. dop.Diid,
  18743. CurrencyCode = sd.Name,
  18744. dop.Cost
  18745. })
  18746. .ToList();
  18747. if (dayCosts.Count > 0)
  18748. {
  18749. var new_dayCosts = dayCosts.Where(x => eecCurrencys.Contains(x.CurrencyCode.ToUpper())).GroupBy(x => x.CurrencyCode);
  18750. foreach (var dc in new_dayCosts)
  18751. {
  18752. var thisCurrency = dc.Key.ToUpper();
  18753. var thisRate = dto.Currencys.Where(x => x.CurrencyCode.ToUpper().Equals(thisCurrency)).First()?.Rate ?? 0.00M;
  18754. if (thisRate == 0.00M) continue;
  18755. foreach (var dcSub in dc)
  18756. {
  18757. opDayCosts.Add(new Grp_DayAndCost()
  18758. {
  18759. Id = dcSub.Id,
  18760. DiId = dcSub.DiId,
  18761. Cost = dcSub.Cost,
  18762. SubTotal = dcSub.Cost * thisRate,
  18763. Remark = $"[移动端->汇率变更时费用变更][变更信息:currency:{thisCurrency}、opDatetime:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}、opUserId:{dto.CurrUserId}]"
  18764. });
  18765. }
  18766. }
  18767. if (opDayCosts.Count > 0)
  18768. {
  18769. await _sqlSugar.Updateable(opDayCosts).UpdateColumns(x => new { x.SubTotal, x.Remark }).WhereColumns(x => new { x.Id }).ExecuteCommandAsync();
  18770. }
  18771. }
  18772. if (dayOtherCosts.Count > 0)
  18773. {
  18774. var new_dayOtherCosts = dayOtherCosts.Where(x => eecCurrencys.Contains(x.CurrencyCode.ToUpper())).GroupBy(x => x.CurrencyCode);
  18775. foreach (var dc in new_dayOtherCosts)
  18776. {
  18777. var thisCurrency = dc.Key.ToUpper();
  18778. var thisRate = dto.Currencys.Where(x => x.CurrencyCode.ToUpper().Equals(thisCurrency)).First()?.Rate ?? 0.00M;
  18779. if (thisRate == 0.00M) continue;
  18780. foreach (var dcSub in dc)
  18781. {
  18782. opDayOtherCosts.Add(new Grp_DayOtherPrice()
  18783. {
  18784. Id = dcSub.Id,
  18785. Diid = dcSub.Diid,
  18786. Cost = dcSub.Cost,
  18787. SubTotal = dcSub.Cost * thisRate,
  18788. // Remark = $"[移动端->汇率变更时费用变更][变更信息:currency:{thisCurrency}、opDatetime:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}、opUserId:{dto.CurrUserId}]"
  18789. });
  18790. }
  18791. }
  18792. if (opDayOtherCosts.Count > 0)
  18793. {
  18794. await _sqlSugar.Updateable(opDayOtherCosts).UpdateColumns(x => new { x.SubTotal }).WhereColumns(x => new { x.Id }).ExecuteCommandAsync();
  18795. }
  18796. }
  18797. #endregion
  18798. //消息通知
  18799. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  18800. //汇率信息记录
  18801. await GeneralMethod.RateRecordSave(dto.CurrUserId, id, "出入境费用");
  18802. return Ok(JsonView(new { parentId = id }));
  18803. }
  18804. /// <summary>
  18805. /// 团组模块 - 出入境费用-移动端 - OP --> 复选框
  18806. /// </summary>
  18807. /// <returns></returns>
  18808. [HttpPost]
  18809. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18810. public async Task<IActionResult> EnterExitCostMobileOpCheckbox(PostEnterExitCostMobileFeeOpCheckboxDto dto)
  18811. {
  18812. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18813. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18814. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18815. //if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  18816. var checkboxInfo = _mapper.Map<Grp_EnterExitCost>(dto);
  18817. checkboxInfo.LastUpdateUserId = dto.CurrUserId;
  18818. checkboxInfo.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  18819. int id = dto.Id;
  18820. if (id <= 0) //add
  18821. {
  18822. checkboxInfo.CreateUserId = dto.CurrUserId;
  18823. checkboxInfo.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  18824. var add = await _sqlSugar.Insertable(checkboxInfo).ExecuteCommandAsync();
  18825. if (add < 1) return Ok(JsonView(false));
  18826. }
  18827. else //update
  18828. {
  18829. ////验证编辑权限
  18830. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  18831. //if (!isEdit) return Ok(JsonView(false, msg));
  18832. var upd = await _sqlSugar.Updateable(checkboxInfo)
  18833. .UpdateColumns(x => new
  18834. {
  18835. x.ChoiceOne,
  18836. x.ChoiceTwo,
  18837. x.SumJJC,
  18838. x.SumGWC,
  18839. x.SumTDC,
  18840. x.ChoiceThree,
  18841. x.ChoiceFour,
  18842. x.ChoiceFive,
  18843. x.ChoiceSix,
  18844. x.OtherExpenses_Checked
  18845. })
  18846. .Where(x => x.Id == id)
  18847. .ExecuteCommandAsync();
  18848. if (upd < 1) return Ok(JsonView(false));
  18849. }
  18850. return Ok(JsonView(new { parentId = id }));
  18851. }
  18852. /// <summary>
  18853. /// 团组模块 - 出入境费用-移动端 - OP --> 3-7项复选框单个复选框更改
  18854. /// </summary>
  18855. /// <returns></returns>
  18856. [HttpPost]
  18857. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18858. public async Task<IActionResult> EnterExitCostMobileOpSingleCheckbox(EnterExitCostMobileOpSingleCheckboxDto dto)
  18859. {
  18860. int itemTypeId = dto.ItemType, id = dto.Id, currUserId = dto.CurrUserId, diId = dto.DiId, isSelected = dto.IsSelected;
  18861. // if (provinceId < 1) provinceId = 122;
  18862. var itemTypes = new List<int>() { 3, 4, 5, 6, 7 };
  18863. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18864. if (diId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18865. if (currUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18866. if (!itemTypes.Contains(itemTypeId)) return Ok(JsonView(false, $"请传入要修改的项类型;3:住宿费; 4:伙食费; 5:公杂费; 6:培训费;7:其他;"));
  18867. var checkboxInfo = new Grp_EnterExitCost()
  18868. {
  18869. Id = id,
  18870. //ProvinceId = provinceId,
  18871. DiId = diId,
  18872. CreateUserId = currUserId,
  18873. LastUpdateUserId = dto.CurrUserId,
  18874. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  18875. };
  18876. if (itemTypeId == 3) checkboxInfo.ChoiceThree = isSelected;
  18877. else if (itemTypeId == 4) checkboxInfo.ChoiceFour = isSelected;
  18878. else if (itemTypeId == 5) checkboxInfo.ChoiceFive = isSelected;
  18879. else if (itemTypeId == 6) checkboxInfo.ChoiceSix = isSelected;
  18880. else if (itemTypeId == 7) checkboxInfo.OtherExpenses_Checked = isSelected;
  18881. if (id <= 0) //add
  18882. {
  18883. checkboxInfo.CreateUserId = dto.CurrUserId;
  18884. checkboxInfo.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  18885. var add = await _sqlSugar.Insertable(checkboxInfo).ExecuteCommandAsync();
  18886. if (add < 1) return Ok(JsonView(false));
  18887. }
  18888. else //update
  18889. {
  18890. ////验证编辑权限
  18891. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  18892. //if (!isEdit) return Ok(JsonView(false, msg));
  18893. var upd = await _sqlSugar.Updateable<Grp_EnterExitCost>()
  18894. .SetColumns(it => it.LastUpdateUserId == dto.CurrUserId)
  18895. .SetColumns(it => it.LastUpdateTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  18896. .SetColumnsIF(itemTypeId == 3, it => it.ChoiceThree == isSelected)
  18897. .SetColumnsIF(itemTypeId == 4, it => it.ChoiceFour == isSelected)
  18898. .SetColumnsIF(itemTypeId == 5, it => it.ChoiceFive == isSelected)
  18899. .SetColumnsIF(itemTypeId == 6, it => it.ChoiceSix == isSelected)
  18900. .SetColumnsIF(itemTypeId == 7, it => it.OtherExpenses_Checked == isSelected)
  18901. .Where(x => x.Id == id)
  18902. .ExecuteCommandAsync();
  18903. if (upd < 1) return Ok(JsonView(false));
  18904. }
  18905. return Ok(JsonView(new { parentId = id }));
  18906. }
  18907. /// <summary>
  18908. /// 团组模块 - 出入境费用-移动端 - OP --> 境内费用 Step1
  18909. /// </summary>
  18910. /// <returns></returns>
  18911. [HttpPost]
  18912. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18913. public async Task<IActionResult> EnterExitCostMobileOpStep1(PostEnterExitCostMobileOpStep1Dto dto)
  18914. {
  18915. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18916. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18917. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18918. //if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  18919. var info = _mapper.Map<Grp_EnterExitCost>(dto);
  18920. info.FirstItemRemark = dto.FirstItemRemark;
  18921. info.LastUpdateUserId = dto.CurrUserId;
  18922. info.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  18923. info.InsidePay = dto.Visa + dto.Service + dto.Safe + dto.Ticket + dto.HeSuan + dto.YiMiao;
  18924. int id = dto.Id;
  18925. if (id <= 0) //add
  18926. {
  18927. info.CreateUserId = dto.CurrUserId;
  18928. info.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  18929. var add = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  18930. if (add < 1) return Ok(JsonView(false));
  18931. id = add;
  18932. }
  18933. else //update
  18934. {
  18935. ////验证编辑权限
  18936. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  18937. //if (!isEdit) return Ok(JsonView(false, msg));
  18938. var upd = await _sqlSugar.Updateable(info)
  18939. .UpdateColumns(x => new
  18940. {
  18941. x.ChoiceOne,
  18942. x.InsidePay,
  18943. x.VisaRemark,
  18944. x.Visa,
  18945. x.Service,
  18946. x.Safe,
  18947. x.Ticket,
  18948. x.HeSuan,
  18949. x.YiMiao,
  18950. x.FirstItemRemark,
  18951. x.LastUpdateUserId,
  18952. x.LastUpdateTime
  18953. })
  18954. .Where(x => x.Id == id)
  18955. .ExecuteCommandAsync();
  18956. if (upd < 1) return Ok(JsonView(false));
  18957. }
  18958. //消息通知
  18959. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  18960. return Ok(JsonView(new { parentId = id, itemTotal = info.InsidePay }));
  18961. }
  18962. /// <summary>
  18963. /// 团组模块 - 出入境费用-移动端 - OP --> 国际旅费 Step2
  18964. /// </summary>
  18965. /// <returns></returns>
  18966. [HttpPost]
  18967. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  18968. public async Task<IActionResult> EnterExitCostMobileOpStep2(PostEnterExitCostMobileOpStep2Dto dto)
  18969. {
  18970. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  18971. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  18972. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  18973. //if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  18974. var info = _mapper.Map<Grp_EnterExitCost>(dto);
  18975. info.DiId = dto.DiId;
  18976. //info.ProvinceId = dto.ProvinceId;
  18977. info.OutsideJJPay = dto.OutsideJJPay;
  18978. info.OutsideGWPay = dto.OutsideGWPay;
  18979. info.OutsideTDPay = dto.OutsideTDPay;
  18980. info.AirJJ = dto.AirJJ;
  18981. info.AirGW = dto.AirGW;
  18982. info.AirTD = dto.AirTD;
  18983. info.CityTranffic = dto.CityTranffic;
  18984. info.CityTranffic1 = dto.CityTranffic1;
  18985. info.CityTranffic2 = dto.CityTranffic2;
  18986. info.TwoItemRemark = dto.TwoItemRemark;
  18987. info.SumJJC = dto.ChoiceTwoJJ;
  18988. info.SumGWC = dto.ChoiceTwoGW;
  18989. info.SumTDC = dto.ChoiceTwoTD;
  18990. info.LastUpdateUserId = dto.CurrUserId;
  18991. info.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  18992. int id = dto.Id;
  18993. decimal jjcItemTotal = 0.00M, gwcItemTotal = 0.00M, tdcItemTotal = 0.00M;
  18994. if (id <= 0) //add i
  18995. {
  18996. info.CreateUserId = dto.CurrUserId;
  18997. info.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  18998. var addId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  18999. if (addId <= 0) return Ok(JsonView(false));
  19000. id = addId;
  19001. }
  19002. else //update
  19003. {
  19004. ////验证编辑权限
  19005. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  19006. //if (!isEdit) return Ok(JsonView(false, msg));
  19007. var upd = await _sqlSugar.Updateable(info)
  19008. .UpdateColumns(x => new
  19009. {
  19010. x.SumJJC,
  19011. x.OutsideJJPay,
  19012. x.SumGWC,
  19013. x.OutsideGWPay,
  19014. x.SumTDC,
  19015. x.OutsideTDPay,
  19016. x.AirJJ,
  19017. x.AirGW,
  19018. x.AirTD,
  19019. x.CityTranffic,
  19020. x.CityTranffic1,
  19021. x.CityTranffic2,
  19022. x.TwoItemRemark,
  19023. x.LastUpdateTime,
  19024. x.LastUpdateUserId
  19025. })
  19026. .Where(x => x.Id == id)
  19027. .ExecuteCommandAsync();
  19028. if (upd < 1) return Ok(JsonView(false));
  19029. }
  19030. jjcItemTotal = info.AirJJ + info.CityTranffic;
  19031. gwcItemTotal = info.AirGW + info.CityTranffic1;
  19032. tdcItemTotal = info.AirTD + info.CityTranffic2;
  19033. //消息通知
  19034. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  19035. return Ok(JsonView(new
  19036. {
  19037. parentId = id,
  19038. choiceTwoJJ = dto.ChoiceTwoJJ,
  19039. jjcItemTotal = jjcItemTotal,
  19040. choiceTwoGW = dto.ChoiceTwoGW,
  19041. gwcItemTotal = gwcItemTotal,
  19042. choiceTwoTD = dto.ChoiceTwoTD,
  19043. tdcItemTotal = tdcItemTotal
  19044. }));
  19045. }
  19046. /// <summary>
  19047. /// 团组模块 - 出入境费用-移动端 - OP --> 批量(住宿、伙食、公杂、培训) Step3-Step6
  19048. /// </summary>
  19049. /// <returns></returns>
  19050. [HttpPost]
  19051. [ApiExplorerSettings(IgnoreApi = true)]
  19052. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19053. public async Task<IActionResult> EnterExitCostMobileOpBatchStep3To6(PostEnterExitCostMobileOpStep3To6Dto dto)
  19054. {
  19055. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19056. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  19057. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19058. if (dto.Infos.Length < 1) return Ok(JsonView(false, "请传入有效的费用信息!"));
  19059. var feeTypeIds = new List<int>() { 1, 2, 3, 4, };
  19060. if (!feeTypeIds.Contains(dto.FeeType)) return Ok(JsonView(false, "请传入有效的费用类型!"));
  19061. var infos1 = _mapper.Map<List<Grp_DayAndCost>>(dto.Infos);
  19062. var infos = infos1.Select(x => new Grp_DayAndCost
  19063. {
  19064. Id = x.Id,
  19065. DiId = dto.DiId,
  19066. Type = dto.FeeType,
  19067. Days = x.Days,
  19068. NationalTravelFeeId = x.NationalTravelFeeId,
  19069. Cost = x.Cost,
  19070. Currency = x.Currency,
  19071. SubTotal = x.SubTotal,
  19072. CreateUserId = dto.CurrUserId
  19073. })
  19074. .ToList();
  19075. var adds = infos.Where(x => x.Id <= 0).ToList();
  19076. var upds = infos.Where(x => x.Id > 0).ToList();
  19077. if (adds.Count > 0)
  19078. {
  19079. var add = await _sqlSugar.Insertable(adds).ExecuteCommandAsync();
  19080. if (add < 1) return Ok(JsonView(false));
  19081. }
  19082. if (upds.Count > 0)
  19083. {
  19084. var upd = await _sqlSugar.Updateable(adds)
  19085. .UpdateColumns(x => new
  19086. {
  19087. x.Days,
  19088. x.NationalTravelFeeId,
  19089. x.Cost,
  19090. x.Currency,
  19091. x.SubTotal
  19092. })
  19093. .WhereColumns(x => new { x.Id })
  19094. .ExecuteCommandAsync();
  19095. if (upd < 1) return Ok(JsonView(false));
  19096. }
  19097. var itemTotal = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.IsDel == 0 && x.DiId == dto.DiId && x.Type == dto.FeeType).Sum(x => x.SubTotal);
  19098. //消息通知
  19099. var id = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == dto.DiId).First()?.Id ?? 0;
  19100. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  19101. return Ok(JsonView(new { itemTotal = itemTotal }));
  19102. }
  19103. /// <summary>
  19104. /// 团组模块 - 出入境费用-移动端 - OP --> 单条(住宿、伙食、公杂、培训) Step3-Step6
  19105. /// </summary>
  19106. /// <returns></returns>
  19107. [HttpPost]
  19108. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19109. public async Task<IActionResult> EnterExitCostMobileOpSingleStep3To6(PostEnterExitCostMobileOpSingleStep3To6Dto dto)
  19110. {
  19111. var feeTypeIds = new List<int>() { 3, 4, 5, 6 };
  19112. int subId = dto.SubId, feeType = dto.FeeType;
  19113. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19114. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  19115. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19116. if (!feeTypeIds.Contains(dto.FeeType)) return Ok(JsonView(false, "请传入有效的费用类型!"));
  19117. var subInfo = _mapper.Map<Grp_DayAndCost>(dto);
  19118. subInfo.Id = subId;
  19119. subInfo.DiId = dto.DiId;
  19120. if (feeType == 3) subInfo.Type = 1;
  19121. else if (feeType == 4) subInfo.Type = 2;
  19122. else if (feeType == 5) subInfo.Type = 3;
  19123. else if (feeType == 6) subInfo.Type = 4;
  19124. subInfo.CreateUserId = dto.CurrUserId;
  19125. int parentId = await EnterExitCostVerifyIsNull(dto.DiId, dto.CurrUserId); //主表验证
  19126. if (parentId < 1) return Ok(JsonView(false));
  19127. //子表op
  19128. if (subId < 1)
  19129. {
  19130. var subAdd = await _sqlSugar.Insertable(subInfo).ExecuteCommandAsync();
  19131. if (subAdd < 1) return Ok(JsonView(false));
  19132. }
  19133. else
  19134. {
  19135. ////验证编辑权限
  19136. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  19137. //if (!isEdit) return Ok(JsonView(false, msg));
  19138. var subUpd = await _sqlSugar.Updateable(subInfo)
  19139. .UpdateColumns(x => new
  19140. {
  19141. x.Days,
  19142. x.NationalTravelFeeId,
  19143. x.Cost,
  19144. x.Currency,
  19145. x.SubTotal
  19146. })
  19147. .WhereColumns(x => new { x.Id })
  19148. .ExecuteCommandAsync();
  19149. if (subUpd < 1) return Ok(JsonView(false));
  19150. }
  19151. var itemTotal = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.IsDel == 0 && x.DiId == dto.DiId && x.Type == feeType).Sum(x => x.SubTotal);
  19152. //await EnterExitCostMobileOpNotice(dto.DiId, parentId, dto.CurrUserId);
  19153. return Ok(JsonView(new { parentId = parentId, itemTotal = itemTotal }));
  19154. }
  19155. /// <summary>
  19156. /// 团组模块 - 出入境费用-移动端 - OP --> 其他费用-批量 Step7
  19157. /// </summary>
  19158. /// <returns></returns>
  19159. [HttpPost]
  19160. [ApiExplorerSettings(IgnoreApi = true)]
  19161. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19162. public async Task<IActionResult> EnterExitCostMobileOpBatchStep7(PostEnterExitCostMobileOpStep7Dto dto)
  19163. {
  19164. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19165. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  19166. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19167. var infos1 = _mapper.Map<List<Grp_DayOtherPrice>>(dto.Infos);
  19168. var infos = infos1.Select(x => new Grp_DayOtherPrice()
  19169. {
  19170. Id = x.Id,
  19171. Diid = dto.DiId,
  19172. SetDataId = x.SetDataId,
  19173. Index = x.Index,
  19174. Cost = x.Cost,
  19175. Currency = x.Currency,
  19176. SubTotal = x.SubTotal,
  19177. CreateUserId = dto.CurrUserId,
  19178. Remark = x.Remark
  19179. }).ToList();
  19180. var adds = infos.Where(x => x.Id <= 0).ToList();
  19181. var upds = infos.Where(x => x.Id > 0).ToList();
  19182. if (adds.Count > 0)
  19183. {
  19184. var add = await _sqlSugar.Insertable(adds).ExecuteCommandAsync();
  19185. if (add < 1) return Ok(JsonView(false));
  19186. }
  19187. if (upds.Count > 0)
  19188. {
  19189. var upd = await _sqlSugar.Updateable(adds)
  19190. .UpdateColumns(x => new
  19191. {
  19192. x.Index,
  19193. x.SetDataId,
  19194. x.Cost,
  19195. x.Currency,
  19196. x.SubTotal,
  19197. x.Remark
  19198. })
  19199. .WhereColumns(x => new { x.Id })
  19200. .ExecuteCommandAsync();
  19201. if (upd < 1) return Ok(JsonView(false));
  19202. }
  19203. var itemTotal = _sqlSugar.Queryable<Grp_DayOtherPrice>().Where(x => x.IsDel == 0 && x.Diid == dto.DiId).Sum(x => x.SubTotal);
  19204. //消息通知
  19205. var id = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == dto.DiId).First()?.Id ?? 0;
  19206. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  19207. return Ok(JsonView(new { itemTotal = itemTotal }));
  19208. }
  19209. /// <summary>
  19210. /// 团组模块 - 出入境费用-移动端 - OP --> 其他费用-单条 Step7
  19211. /// </summary>
  19212. /// <returns></returns>
  19213. [HttpPost]
  19214. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19215. public async Task<IActionResult> EnterExitCostMobileOpSingleStep7(PostEnterExitCostMobileOpSingleStep7Dto dto)
  19216. {
  19217. int subId = dto.SubId;
  19218. int diId = dto.Diid;
  19219. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19220. if (diId < 1) return Ok(JsonView(false, MsgTips.DiId));
  19221. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19222. var subInfo = _mapper.Map<Grp_DayOtherPrice>(dto);
  19223. subInfo.Id = subId;
  19224. subInfo.Diid = dto.Diid;
  19225. subInfo.CreateUserId = dto.CurrUserId;
  19226. int parentId = await EnterExitCostVerifyIsNull(diId, dto.CurrUserId); //主表验证
  19227. if (parentId < 1) return Ok(JsonView(false));
  19228. #region 子表op
  19229. if (subId < 1)//add
  19230. {
  19231. var subAdd = await _sqlSugar.Insertable(subInfo).ExecuteCommandAsync();
  19232. if (subAdd < 1) return Ok(JsonView(false));
  19233. }
  19234. else //upd
  19235. {
  19236. ////验证编辑权限
  19237. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.Diid, dto.CurrUserId, 2);
  19238. //if (!isEdit) return Ok(JsonView(false, msg));
  19239. var subUpd = await _sqlSugar.Updateable(subInfo)
  19240. .UpdateColumns(x => new
  19241. {
  19242. x.Index,
  19243. x.SetDataId,
  19244. x.Cost,
  19245. x.Currency,
  19246. x.SubTotal,
  19247. x.Remark
  19248. })
  19249. .WhereColumns(x => new { x.Id })
  19250. .ExecuteCommandAsync();
  19251. if (subUpd < 1) return Ok(JsonView(false));
  19252. }
  19253. #endregion
  19254. var itemTotal = _sqlSugar.Queryable<Grp_DayOtherPrice>().Where(x => x.IsDel == 0 && x.Diid == diId).Sum(x => x.SubTotal);
  19255. //消息通知
  19256. //await EnterExitCostMobileOpNotice(dto.Diid, parentId, dto.CurrUserId);
  19257. return Ok(JsonView(new { parentId = parentId, itemTotal = itemTotal }));
  19258. }
  19259. /// <summary>
  19260. /// 团组模块 - 出入境费用-移动端 - 3-6子项删除
  19261. /// </summary>
  19262. /// <returns></returns>
  19263. [HttpPost]
  19264. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19265. public async Task<IActionResult> EnterExitCostMobileSubItemDel(EnterExitCostSubItemDelDto dto)
  19266. {
  19267. var data = await _enterExitCostRep.PostEnterExitCostSubItemDel(dto);
  19268. if (data.Code != 0)
  19269. {
  19270. return Ok(JsonView(false, data.Msg));
  19271. }
  19272. return Ok(JsonView(true, "操作成功!", data.Data));
  19273. }
  19274. /// <summary>
  19275. /// 团组模块 - 出入境费用-移动端 - 其他费用删除
  19276. /// </summary>
  19277. /// <param name="dto"></param>
  19278. /// <returns></returns>
  19279. [HttpPost]
  19280. public IActionResult EnterExitCostMobileOtherFeeDel(EnterExitCostSubItemDelDto dto)
  19281. {
  19282. var data = new Grp_DayOtherPrice()
  19283. {
  19284. Id = dto.Id,
  19285. IsDel = 1,
  19286. DeleteUserId = dto.DeleteUserId,
  19287. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  19288. };
  19289. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  19290. if (del > 0) return Ok(JsonView(true, "删除成功!"));
  19291. return Ok(JsonView(false, "删除失败!"));
  19292. }
  19293. #endregion
  19294. #endregion
  19295. #region 团组经理模块 出入境费用-草稿 移动端(Android/IOS)
  19296. /// <summary>
  19297. /// 团组模块 - 出入境费用-草稿 - 基础数据源 - 省份归属
  19298. /// </summary>
  19299. /// <returns></returns>
  19300. [HttpGet]
  19301. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19302. public async Task<IActionResult> EnterExitDraftMobileProvBelongCostDataSource()
  19303. {
  19304. var provData = await _groupRepository.ProvinceBasicSource();
  19305. return Ok(JsonView(true, "查询成功!", provData));
  19306. }
  19307. /// <summary>
  19308. /// 团组模块 - 出入境费用-草稿-移动端 - 草稿名称数据Data
  19309. /// </summary>
  19310. /// <returns></returns>
  19311. [HttpPost]
  19312. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19313. public async Task<IActionResult> EnterExitCostDraftMobileNameData(EnterExitCostDraftMobileNameDataDto dto)
  19314. {
  19315. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19316. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19317. RefAsync<int> total = 0;
  19318. var data = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>()
  19319. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.DraftName))
  19320. .WhereIF(!string.IsNullOrEmpty(dto.DraftName), x => x.DraftName.Contains(dto.DraftName))
  19321. .Select(x => new
  19322. {
  19323. Id = x.Id,
  19324. DraftName = x.DraftName,
  19325. IsViewOrEdit = SqlFunc.Subqueryable<Grp_EnterExitCostDraftPermission>()
  19326. .Where(x1 => x1.IsDel == 0 && x1.Permission == 1 && x1.DraftId == x.Id && x1.UserId == dto.CurrUserId)
  19327. .Any()
  19328. })
  19329. .OrderByDescending(x => x.Id)
  19330. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  19331. return Ok(JsonView(true, "查询成功!", data, total));
  19332. }
  19333. /// <summary>
  19334. /// 出入境费用-草稿 移动端
  19335. /// 获取币种基础数据(含逻辑处理)
  19336. /// </summary>
  19337. /// <returns></returns>
  19338. private async Task<List<CurrencyInfo>> EnterExitCostDraftMobileGetCurrencyInit()
  19339. {
  19340. return await GeneralMethod.EnterExitCostInitRate();
  19341. }
  19342. /// <summary>
  19343. /// 团组模块 - 出入境费用-草稿-移动端 - 基础数据源(Word明细类型、Excel明细类型、默认币种显示)
  19344. /// </summary>
  19345. /// <returns></returns>
  19346. [HttpPost]
  19347. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19348. public async Task<IActionResult> EnterExitCostDraftMobileDataSource(EnterExitCostDraftMobileDataSourceDto dto)
  19349. {
  19350. //验证城市归属并给默认值
  19351. int provinceId = dto.ProvinceId;
  19352. if (provinceId < 1) provinceId = 122;
  19353. var dataSource = await _sqlSugar
  19354. .Queryable<Sys_SetData>()
  19355. .Where(x => x.IsDel == 0 && (x.STid == 72 || x.STid == 73) && x.Remark.Contains(provinceId.ToString()))
  19356. .ToListAsync();
  19357. //三公费用-Word明细类型
  19358. var wordTypeData = dataSource.Where(it => it.STid == 72)
  19359. .Select(x => new SetDataInfoView
  19360. {
  19361. Id = x.Id,
  19362. Name = x.Name,
  19363. Remark = x.Remark
  19364. })
  19365. .ToList();
  19366. //三公费用-Excel明细类型
  19367. var excelTypeData = dataSource.Where(it => it.STid == 73)
  19368. .Select(x => new SetDataInfoView
  19369. {
  19370. Id = x.Id,
  19371. Name = x.Name,
  19372. Remark = x.Remark
  19373. })
  19374. .ToList();
  19375. //默认币种显示
  19376. var _currencyInfos = await EnterExitCostMobileGetCurrencyInit();
  19377. var viewPermissionData = await _enterExitCostRep.PermissionViewUsersAsync();
  19378. return Ok(JsonView(true, "查询成功!", new
  19379. {
  19380. WordTypeData = wordTypeData,
  19381. ExcelTypeData = excelTypeData,
  19382. CurrencyInit = _currencyInfos,
  19383. viewPermissionData = viewPermissionData
  19384. }));
  19385. }
  19386. /// <summary>
  19387. /// 团组模块 - 出入境费用-草稿-移动端 - 团组基础数据Data
  19388. /// </summary>
  19389. /// <returns></returns>
  19390. [HttpPost]
  19391. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19392. public async Task<IActionResult> EnterExitCostDraftMobileGroupData(PostEnterExitCostDraftMobileGroupDataDto dto)
  19393. {
  19394. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19395. RefAsync<int> total = 0;
  19396. int diId = 0;
  19397. var status = int.TryParse(dto.GroupName, out diId);
  19398. var data = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  19399. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.TeamName))
  19400. .WhereIF(!string.IsNullOrEmpty(dto.GroupName) && diId > 0, x => x.Id == diId)
  19401. .WhereIF(!string.IsNullOrEmpty(dto.GroupName) && !status, x => x.TeamName.Contains(dto.GroupName))
  19402. .OrderByDescending(x => x.VisitStartDate)
  19403. .Select(x => new
  19404. {
  19405. Id = x.Id,
  19406. GroupName = x.TeamName
  19407. })
  19408. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  19409. return Ok(JsonView(true, "查询成功!", data, total));
  19410. }
  19411. /// <summary>
  19412. /// 团组模块 - 出入境费用-草稿-移动端 - 币种基础数据Data
  19413. /// </summary>
  19414. /// <returns></returns>
  19415. [HttpPost]
  19416. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19417. public async Task<IActionResult> EnterExitCostDraftMobileCurrencyData(PostEnterExitCostDraftMobileCurrencyDataDto dto)
  19418. {
  19419. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19420. RefAsync<int> total = 0;
  19421. var data = await _sqlSugar.Queryable<Sys_SetData>()
  19422. .Where(x => x.IsDel == 0 && x.STid == 66)
  19423. .WhereIF(!string.IsNullOrEmpty(dto.CurrencyName), x => x.Name.ToLower().Contains(dto.CurrencyName) || x.Remark.Contains(dto.CurrencyName))
  19424. .Select(x => new
  19425. {
  19426. id = x.Id,
  19427. name = x.Name,
  19428. remark = x.Remark,
  19429. })
  19430. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  19431. return Ok(JsonView(true, "查询成功!", data, total));
  19432. }
  19433. /// <summary>
  19434. /// 团组模块 - 出入境费用-草稿-移动端 - 其他款项 - 币种、费用类型基础数据Data
  19435. /// </summary>
  19436. /// <returns></returns>
  19437. [HttpPost]
  19438. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19439. public async Task<IActionResult> EnterExitCostDraftMobileOtherItemCurrencyData(PostEnterExitCostDraftMobileOtherItemCurrencyDataDto dto)
  19440. {
  19441. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19442. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  19443. var groupRateData = await GeneralMethod.PostGroupTeamRateByDiIdAndCTableId(1, 2477, 98);
  19444. if (groupRateData == null) return Ok(JsonView(false, "请填写“团组汇率-->其他款项”汇率!"));
  19445. var groupOtherRateData = groupRateData.TeamRates;
  19446. var enterExitCostInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().FirstAsync(it => it.Id == dto.DraftId && it.IsDel == 0);
  19447. if (enterExitCostInfo == null) return Ok(JsonView(groupOtherRateData));
  19448. var eecRateData = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(enterExitCostInfo.CurrencyRemark);
  19449. groupOtherRateData = groupOtherRateData
  19450. .Select(x => new TeamRateDescAddCurrencyIdView
  19451. {
  19452. CurrencyId = x.CurrencyId,
  19453. CurrencyName = x.CurrencyName,
  19454. CurrencyCode = x.CurrencyCode,
  19455. Rate = eecRateData.Find(it => it.CurrencyCode.ToUpper().Equals(x.CurrencyCode.ToUpper()))?.Rate ?? x.Rate
  19456. }).ToList();
  19457. var otherFeeTypeData = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 92).Select(x => new { x.Id, x.Name }).ToListAsync();
  19458. return Ok(JsonView(true, "查询成功!", new { groupOtherRateData = groupOtherRateData, otherFeeTypeData = otherFeeTypeData }));
  19459. }
  19460. /// <summary>
  19461. /// 团组模块 - 出入境费用-草稿-移动端 - 实时汇率、签证费用、机票费用 Tips
  19462. /// </summary>
  19463. /// <returns></returns>
  19464. [HttpPost]
  19465. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19466. public async Task<IActionResult> EnterExitCostDraftMobileFeeTips(EnterExitCostDraftMobileFeeTipsDto dto)
  19467. {
  19468. int portType = dto.PortType;
  19469. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19470. var tipsData = new List<int>() { 1, 2, 3 };
  19471. if (!tipsData.Contains(dto.TipsType)) return Ok(JsonView(false, $"请传入有效的TipsType参数;1 实时汇率;2 签证费用;3 机票费用;"));
  19472. if (dto.TipsType == 1)
  19473. {
  19474. return Ok(JsonView(true, "查询成功!", await GeneralMethod.EnterExitCostLiveRate()));
  19475. }
  19476. else if (dto.TipsType == 2)
  19477. {
  19478. if (portType == 2)
  19479. {
  19480. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  19481. }
  19482. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  19483. .Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId)
  19484. .Select(x => x.NationalTravelFeeId)
  19485. .Distinct()
  19486. .ToListAsync();
  19487. if (portType == 2)
  19488. {
  19489. if (!cityIds.Any()) return Ok(JsonView(false, "请先录入出入境费用明细!"));
  19490. }
  19491. var countrys = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  19492. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  19493. .Select(x => x.Country)
  19494. .Distinct()
  19495. .ToArrayAsync();
  19496. if (portType == 2)
  19497. {
  19498. if (!countrys.Any()) return Ok(JsonView(false, "请先录入出入境费用明细!"));
  19499. }
  19500. (decimal totalAmt, string remark) = await _visaFeeInfoRep.EnterExitCostDraftVisaTips(countrys);
  19501. return Ok(JsonView(true, "查询成功!", new
  19502. {
  19503. totalAmt = totalAmt,
  19504. remark = remark
  19505. }));
  19506. }
  19507. else if (dto.TipsType == 3)
  19508. {
  19509. return Ok(JsonView(false, "暂无机票费用提示信息!"));
  19510. }
  19511. return Ok(JsonView(false));
  19512. }
  19513. #region 城市区间交通费
  19514. /// <summary>
  19515. /// 团组模块 - 出入境费用 - 草稿 - 移动端 - 基础数据源(境外用车)
  19516. /// </summary>
  19517. /// <param name="draftId">草稿Id</param>
  19518. /// <returns></returns>
  19519. [HttpGet("{darfId}")]
  19520. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19521. public async Task<IActionResult> EnterExitCostDraftOVMobileByGroupId(int draftId)
  19522. {
  19523. var groupInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == draftId).FirstAsync();
  19524. if (groupInfo == null)
  19525. {
  19526. return Ok(JsonView(false, "三公费用草稿信息为空"));
  19527. }
  19528. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  19529. .Where(x => x.IsDel == 0 && x.ParentId == draftId)
  19530. .Select(x => x.NationalTravelFeeId)
  19531. .Distinct()
  19532. .ToListAsync();
  19533. var countries = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  19534. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  19535. .Select(x => x.Country)
  19536. .Distinct()
  19537. .ToListAsync();
  19538. if (countries?.Any() != true)
  19539. {
  19540. return Ok(JsonView(false, "草稿选择城市信息为空"));
  19541. }
  19542. var currencies = await GeneralMethod.EnterExitCostDrafOVFeeUsedCurrencyAsync(draftId);
  19543. var currencyData = await _sqlSugar.Queryable<Sys_SetData>()
  19544. .Where(x => x.IsDel == 0 && x.STid == 66)
  19545. .ToListAsync();
  19546. var overseaVehicles = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  19547. .Where(x => x.IsDel == 0 && countries.Contains(x.CountryName))
  19548. .ToListAsync();
  19549. var overseaVehicleIds = overseaVehicles.Select(x => x.Id).ToList();
  19550. //只返回接送机的数据
  19551. var overseaVehicleTypes = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  19552. .Where(x => x.IsDel == 0 && x.ServiceType == VehicleServiceTypeEnum.TransferService && overseaVehicleIds.Contains(x.OvId))
  19553. .ToListAsync();
  19554. var sysUers = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToListAsync();
  19555. var overseaVehicleCityDatas = new List<dynamic>() {
  19556. new
  19557. {
  19558. Id = 0,
  19559. area= "未选择",
  19560. CarTypeName = "",
  19561. serviceType = "",
  19562. Price = 0.00M,
  19563. guidePrice = 0.00M,
  19564. otherPrice = 0.00M,
  19565. currency = 0,
  19566. currencyName = "",
  19567. currRate = 1.0000M,
  19568. LastUpdateUserName = "",
  19569. LastUpdateTime = "",
  19570. Remark = ""
  19571. }};
  19572. foreach (var item in overseaVehicleTypes)
  19573. {
  19574. var parentInfo = overseaVehicles.FirstOrDefault(x => x.Id == item.OvId);
  19575. string area = string.Empty,
  19576. serviceType = "未设置",
  19577. currencyName = string.Empty;
  19578. decimal otherPrice = 0.00M;
  19579. if (parentInfo != null)
  19580. {
  19581. if (parentInfo.CountryName == parentInfo.CityName) area = parentInfo.CountryName;
  19582. else area = $"{parentInfo.CountryName}-{parentInfo.CityName}";
  19583. serviceType = item.ServiceType.GetDescription();
  19584. currencyName = currencyData.FirstOrDefault(x => x.Id == parentInfo.Currency)?.Name ?? "-";
  19585. otherPrice = parentInfo.OtherPrice1 + parentInfo.OtherPrice2;
  19586. }
  19587. //当前币种汇率值
  19588. var currRate = 1.0000M;
  19589. var currencyInfo = currencies.FirstOrDefault(x => x.CurrencyCode == currencyName);
  19590. if (currencyInfo != null) currRate = currencyInfo.Rate;
  19591. overseaVehicleCityDatas.add(new
  19592. {
  19593. item.Id,
  19594. area,
  19595. item.CarTypeName,
  19596. serviceType,
  19597. item.Price,
  19598. guidePrice = parentInfo?.GuidePrice ?? 0.00M,
  19599. otherPrice,
  19600. currency = parentInfo?.Currency ?? 0,
  19601. currencyName,
  19602. currRate,
  19603. LastUpdateUserName = sysUers.FirstOrDefault(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-",
  19604. item.LastUpdateTime,
  19605. item.Remark
  19606. });
  19607. }
  19608. var total = overseaVehicleCityDatas.Count;
  19609. var view = new
  19610. {
  19611. visitCountries = string.Join("、", countries),
  19612. //groupSize = 0, //出访人数
  19613. defAirportTransferCoeff = Def_AirportTransferCoeff, //接送机默认报价系数
  19614. defServiceCount = Def_ServiceCount, //接送机默认服务次数
  19615. defTrainCoeff = Def_TrainCoeff, //火车默认报价系数
  19616. defPullCartCoeff = Def_PullCartCoeff, //拉车默认报价系数
  19617. defCityFlightCoeff = Def_CityFlightCoeff, //城市机票默认报价系数
  19618. Currencies = currencies,
  19619. data = overseaVehicleCityDatas
  19620. };
  19621. if (overseaVehicleCityDatas.Count == 0)
  19622. {
  19623. return Ok(JsonView(true, "暂无数据!", view));
  19624. }
  19625. return Ok(JsonView(true, "查询成功!", view, total));
  19626. }
  19627. /// <summary>
  19628. /// 团组模块 - 出入境费用 - 草稿 - 境外用车计算详细信息
  19629. /// </summary>
  19630. /// <param name="draftId"></param>
  19631. /// <param name="currUserId"></param>
  19632. /// <returns></returns>
  19633. [HttpGet("{groupId}")]
  19634. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19635. public async Task<IActionResult> EnterExitCostDraftOVFeeMobileDetails(int draftId, int currUserId)
  19636. {
  19637. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == draftId && x.IsDel == 0).FirstAsync();
  19638. if (eecInfo == null)
  19639. {
  19640. return Ok(JsonView(false, "草稿信息为空"));
  19641. }
  19642. var info = new CityIntervalDraftInfo();
  19643. if (eecInfo != null)
  19644. {
  19645. info = eecInfo.CityIntervalFeeDetails;
  19646. return Ok(JsonView(true, "查询成功!", info));
  19647. }
  19648. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == currUserId).FirstAsync();
  19649. var userName = userInfo?.CnName ?? "-";
  19650. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  19651. //返回默认数据
  19652. info = new CityIntervalDraftInfo()
  19653. {
  19654. APTFeeDetails = new List<RoundTripTransferInfo>() { new() { No = 1, Coefficient = Def_AirportTransferCoeff, ServiceCount = Def_ServiceCount } },
  19655. PullCartFeeDetails = new List<PullCartInfo>() { new() { No = 1, Coefficient = Def_PullCartCoeff } },
  19656. TrainFeeDetails = new List<TrainInfo>() { new() { No = 1, Coefficient = Def_TrainCoeff } },
  19657. CityAirTicketFeeDetails = new List<CityAirTicketInfo>() { new() { No = 1, Coefficient = Def_CityFlightCoeff } },
  19658. LastUpdateUserName = userName,
  19659. LastUpdateTime = nowTime,
  19660. CreateUserName = userName,
  19661. Currencies = await GeneralMethod.EnterExitCostDrafOVFeeUsedCurrencyAsync(draftId),
  19662. CreateTime = nowTime
  19663. };
  19664. return Ok(JsonView(true, "查询成功!", info));
  19665. }
  19666. /// <summary>
  19667. /// 团组模块 - 出入境费用 - 草稿 - 境外用车计算 保存
  19668. /// </summary>
  19669. /// <param name="dto"></param>
  19670. /// <returns></returns>
  19671. [HttpPost]
  19672. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19673. public async Task<IActionResult> EnterExitCostDraftOVFeeMobileSave(EnterExitCostDraftOVFeeSaveDto dto)
  19674. {
  19675. var draftInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == dto.DraftId).FirstAsync();
  19676. if (draftInfo == null)
  19677. {
  19678. return Ok(JsonView(false, "草稿信息为空"));
  19679. }
  19680. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == dto.CurrUserId).FirstAsync();
  19681. if (userInfo == null)
  19682. {
  19683. return Ok(JsonView(false, "员工信息为空"));
  19684. }
  19685. var userName = userInfo?.CnName ?? "-";
  19686. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  19687. var info = new CityIntervalDraftInfo()
  19688. {
  19689. GroupSize = dto.GroupSize,
  19690. APTFeeTotal = dto.APTFeeTotal,
  19691. APTFeeDetails = dto.APTFeeDetails,
  19692. PullCartFeeTotal = dto.PullCartFeeTotal,
  19693. PullCartFeeDetails = dto.PullCartFeeDetails,
  19694. TrainFeeTotal = dto.TrainFeeTotal,
  19695. TrainFeeDetails = dto.TrainFeeDetails,
  19696. CityAirTicketFeeTotal = dto.CityAirTicketFeeTotal,
  19697. CityAirTicketFeeDetails = dto.CityAirTicketFeeDetails,
  19698. Currencies = dto.Currencies,
  19699. LastUpdateUserName = userName,
  19700. LastUpdateTime = nowTime,
  19701. CreateUserName = draftInfo.CityIntervalFeeDetails?.CreateUserName ?? userName,
  19702. CreateTime = draftInfo.CityIntervalFeeDetails?.CreateTime ?? nowTime
  19703. };
  19704. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>()
  19705. .SetColumns(it => it.CityIntervalFeeDetails == info)
  19706. .Where(x => x.Id == draftInfo.Id)
  19707. .ExecuteCommandAsync();
  19708. if (upd < 1)
  19709. {
  19710. return Ok(JsonView(false));
  19711. }
  19712. //返回参数处理
  19713. var label = new StringBuilder();
  19714. if (dto.APTFeeDetails.Any())
  19715. {
  19716. var ovIds = dto.APTFeeDetails.Select(x => x.OvId).ToList();
  19717. var areas = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  19718. .LeftJoin<Res_OverseaVehicle>((ovtp, ov) => ovtp.OvId == ov.Id)
  19719. .Where((ovtp, ov) => ovtp.IsDel == 0 && ovIds.Contains(ovtp.Id))
  19720. .Select((ovtp, ov) => new
  19721. {
  19722. ovtp.Id,
  19723. ov.CountryName,
  19724. ov.CityName
  19725. })
  19726. .ToListAsync();
  19727. if (areas.Any())
  19728. {
  19729. var items = dto.APTFeeDetails
  19730. .Select(item =>
  19731. {
  19732. var areaInfo = areas.FirstOrDefault(x => x.Id == item.OvId);
  19733. if (areaInfo == null) return null;
  19734. return areaInfo.CountryName == areaInfo.CityName
  19735. ? $"{areaInfo.CountryName}({item.Quote:#0.00} CNY)"
  19736. : $"{areaInfo.CountryName}-{areaInfo.CityName}({item.Quote:#0.00} CNY)";
  19737. })
  19738. .Where(item => item != null)
  19739. .ToList();
  19740. string areaLabel = $"接送机({string.Join("、", items)});";
  19741. label.AppendLine(areaLabel);
  19742. }
  19743. }
  19744. if (dto.PullCartFeeDetails.Any())
  19745. {
  19746. var amounts = dto.PullCartFeeDetails.Select(item => $"{item.Quote:#0.00}");
  19747. string subLabel = $"拉车({string.Join("、", amounts)});";
  19748. label.AppendLine(subLabel);
  19749. }
  19750. if (dto.TrainFeeDetails.Any())
  19751. {
  19752. var amounts = dto.TrainFeeDetails.Select(item => $"{item.Quote:#0.00}");
  19753. string subLabel = $"火车票({string.Join("、", amounts)});";
  19754. label.AppendLine(subLabel);
  19755. }
  19756. if (dto.CityAirTicketFeeDetails.Any())
  19757. {
  19758. var amounts = dto.CityAirTicketFeeDetails.Select(item => $"{item.Quote:#0.00}");
  19759. string subLabel = $"城市机票({string.Join("、", amounts)});";
  19760. label.AppendLine(subLabel);
  19761. }
  19762. //费用
  19763. decimal quote = (dto.APTFeeTotal + dto.PullCartFeeTotal + dto.TrainFeeTotal + dto.CityAirTicketFeeTotal).ConvertToDecimal1();
  19764. decimal jjcQuote = quote;
  19765. decimal gwcQuote = quote;
  19766. decimal tdcQuote = quote;
  19767. var view = new
  19768. {
  19769. label = label.ToString(),
  19770. jjcQuote,
  19771. gwcQuote,
  19772. tdcQuote
  19773. };
  19774. return Ok(JsonView(view));
  19775. }
  19776. #endregion
  19777. /// <summary>
  19778. /// 团组模块 - 出入境费用-草稿-移动端 - 创建
  19779. /// </summary>
  19780. /// <returns></returns>
  19781. [HttpPost]
  19782. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19783. public async Task<IActionResult> EnterExitCostDraftMobileCreate(EnterExitCostDraftMobileCreateDto dto)
  19784. {
  19785. if (string.IsNullOrEmpty(dto.DraftName)) return Ok(JsonView(false, "草稿名称为空!"));
  19786. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19787. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  19788. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.DraftName.Equals(dto.DraftName) && it.IsDel == 0);
  19789. if (eecInfo != null) return Ok(JsonView(false, "草稿名称重复!"));
  19790. var rateInfos = await EnterExitCostMobileGetCurrencyInit();
  19791. var info = new Grp_EnterExitCostDraft()
  19792. {
  19793. ProvinceId = dto.ProvinceId,
  19794. DraftName = dto.DraftName,
  19795. CurrencyRemark = CommonFun.GetCurrencyChinaToString(rateInfos),
  19796. CreateUserId = dto.CurrUserId
  19797. };
  19798. _sqlSugar.BeginTran();
  19799. var draftId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  19800. if (draftId < 1)
  19801. {
  19802. _sqlSugar.RollbackTran();
  19803. return Ok(JsonView(false, "草稿创建失败!"));
  19804. }
  19805. //添加默认权限
  19806. await _enterExitCostDraftRep.InitPerm(draftId, dto.CurrUserId);
  19807. _sqlSugar.CommitTran();
  19808. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(draftId, dto.CurrUserId);
  19809. var mobileInfo = new EnterExitCostDraftMobileParentInfoView();
  19810. mobileInfo.Id = draftId;
  19811. mobileInfo.DraftName = dto.DraftName;
  19812. mobileInfo.Currencys = rateInfos;
  19813. mobileInfo.IsAssignPerm = assignPerm;
  19814. return Ok(JsonView(mobileInfo));
  19815. }
  19816. /// <summary>
  19817. /// 出入境费用-草稿-移动端 查看编辑提示消息
  19818. /// </summary>
  19819. private static string _viewPermStr = $"未分配查看权限,如要查看,请联系市场部或国交部负责人!";
  19820. /// <summary>
  19821. /// 团组模块 - 出入境费用-草稿-移动端 - ParentInfo
  19822. /// </summary>
  19823. /// <returns></returns>
  19824. [HttpPost]
  19825. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19826. public async Task<IActionResult> EnterExitCostDraftMobileParentInfo(EnterExitCostDraftMobileParentInfoDto dto)
  19827. {
  19828. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  19829. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19830. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.Id == dto.DraftId && it.IsDel == 0);
  19831. var mobileInfo = new EnterExitCostDraftMobileParentInfoView();
  19832. mobileInfo.Currencys = await EnterExitCostMobileGetCurrencyInit();
  19833. if (eecInfo == null) return Ok(JsonView(mobileInfo));
  19834. //验证查看编辑权限
  19835. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  19836. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  19837. mobileInfo = _mapper.Map<EnterExitCostDraftMobileParentInfoView>(eecInfo);
  19838. mobileInfo.ProvinceId = eecInfo.ProvinceId;
  19839. mobileInfo.IsAssignPerm = assignPerm;
  19840. var dayAndCostData = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  19841. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  19842. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  19843. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId)
  19844. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  19845. {
  19846. ParentId = dac.ParentId,
  19847. SubId = dac.Id,
  19848. Type = dac.Type,
  19849. Days = dac.Days,
  19850. NationalTravelFeeId = dac.NationalTravelFeeId,
  19851. Arae = $"{ntf.Country}-{ntf.City}",
  19852. Cost = dac.Cost,
  19853. Currency = dac.Currency,
  19854. CurrencyName = sd.Name,
  19855. SubTotal = dac.SubTotal,
  19856. })
  19857. .ToList();
  19858. mobileInfo.ChoiceOneTotalCost = eecInfo.InsidePay;
  19859. mobileInfo.ChoiceTwoJJ = eecInfo.SumJJC;
  19860. mobileInfo.ChoiceTwoGW = eecInfo.SumGWC;
  19861. mobileInfo.ChoiceTwoTD = eecInfo.SumTDC;
  19862. mobileInfo.Currencys = !string.IsNullOrEmpty(eecInfo.CurrencyRemark) ? CommonFun.GetCurrencyChinaToList(eecInfo.CurrencyRemark) : mobileInfo.Currencys;
  19863. mobileInfo.ChoiceThreeTotalCost = dayAndCostData.Where(it => it.Type == 1).Sum(x => x.SubTotal); //住宿费 1
  19864. mobileInfo.ChoiceFourTotalCost = dayAndCostData.Where(it => it.Type == 2).Sum(x => x.SubTotal); //伙食费 2
  19865. mobileInfo.ChoiceFiveTotalCost = dayAndCostData.Where(it => it.Type == 3).Sum(x => x.SubTotal); //公杂费 3
  19866. mobileInfo.ChoiceSixTotalCost = dayAndCostData.Where(it => it.Type == 4).Sum(x => x.SubTotal); //培训费 4
  19867. //其他款项
  19868. var otherData = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>()
  19869. .LeftJoin<Sys_SetData>((dop, sd1) => dop.SetDataId == sd1.Id)
  19870. .LeftJoin<Sys_SetData>((dop, sd1, sd2) => dop.Currency == sd2.Id)
  19871. .Where((dop, sd1, sd2) => dop.IsDel == 0 && dop.ParentId == dto.DraftId)
  19872. .OrderBy((dop, sd1, sd2) => dop.Index)
  19873. .Select((dop, sd1, sd2) => new DayOtherPriceDraftMobileInfoView
  19874. {
  19875. ParentId = dop.ParentId,
  19876. SubId = dop.Id,
  19877. Index = dop.Index,
  19878. SetDataId = dop.SetDataId,
  19879. SetDataName = sd1.Name,
  19880. Cost = dop.Cost,
  19881. Currency = dop.Currency,
  19882. CurrencyName = sd2.Remark,
  19883. SubTotal = dop.SubTotal,
  19884. Remark = dop.Remark,
  19885. })
  19886. .ToArray();
  19887. mobileInfo.OtherExpensesTotalCost = otherData.Sum(x => x.SubTotal);
  19888. return Ok(mobileInfo);
  19889. }
  19890. /// <summary>
  19891. /// 团组模块 - 出入境费用-草稿-移动端 - SubInfo
  19892. /// </summary>
  19893. /// <returns></returns>
  19894. [HttpPost]
  19895. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  19896. public async Task<IActionResult> EnterExitCostDraftMobileSubInfo(PostEnterExitCostDraftMobileSubInfoDto dto)
  19897. {
  19898. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  19899. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  19900. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  19901. var subTypes = new List<int>() { 1, 2, 3, 4, 5, 6, 7 };
  19902. if (!subTypes.Contains(dto.SubType)) return Ok(JsonView(false, $"请传入有效的subTypeId!"));
  19903. //验证查看编辑权限
  19904. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  19905. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  19906. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.Id == dto.DraftId && it.IsDel == 0);
  19907. if (eecInfo == null) return Ok(JsonView(false, $"出入境费用明细未录入!"));
  19908. var subType = dto.SubType;
  19909. if (subType == 1) //1:境内费用
  19910. {
  19911. var oneData = new ChoiceOneMobileSubInfoView()
  19912. {
  19913. Id = eecInfo.Id,
  19914. ChoiceOne = eecInfo.ChoiceOne,
  19915. ChoiceOneTotalCost = eecInfo.InsidePay,
  19916. Visa = eecInfo.Visa,
  19917. VisaRemark = eecInfo.VisaRemark,
  19918. YiMiao = eecInfo.YiMiao,
  19919. HeSuan = eecInfo.HeSuan,
  19920. Service = eecInfo.Service,
  19921. Ticket = eecInfo.Ticket,
  19922. Safe = eecInfo.Safe,
  19923. FirstItemRemark = eecInfo.FirstItemRemark
  19924. };
  19925. return Ok(JsonView(oneData));
  19926. }
  19927. else if (subType == 2) //2:国际旅费
  19928. {
  19929. var twoData = new ChoiceTwoMobileSubInfoView()
  19930. {
  19931. Id = eecInfo.Id,
  19932. ChoiceTwoJJ = eecInfo.SumJJC,
  19933. OutsideJJPay = eecInfo.OutsideJJPay,
  19934. ChoiceTwoGW = eecInfo.SumGWC,
  19935. OutsideGWPay = eecInfo.OutsideGWPay,
  19936. ChoiceTwoTD = eecInfo.SumTDC,
  19937. OutsideTDPay = eecInfo.OutsideTDPay,
  19938. AirJJ = eecInfo.AirJJ,
  19939. AirGW = eecInfo.AirGW,
  19940. AirTD = eecInfo.AirTD,
  19941. CityTranffic = eecInfo.CityTranffic,
  19942. CityTranffic1 = eecInfo.CityTranffic1,
  19943. CityTranffic2 = eecInfo.CityTranffic2,
  19944. TwoItemRemark = eecInfo.TwoItemRemark
  19945. };
  19946. return Ok(JsonView(twoData));
  19947. }
  19948. else if (subType == 3) //3:住宿费
  19949. {
  19950. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  19951. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  19952. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  19953. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId && dac.Type == 1)
  19954. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  19955. {
  19956. ParentId = dac.ParentId,
  19957. SubId = dac.Id,
  19958. Type = dac.Type,
  19959. Days = dac.Days,
  19960. NationalTravelFeeId = dac.NationalTravelFeeId,
  19961. Arae = $"{ntf.Country}-{ntf.City}",
  19962. Cost = dac.Cost,
  19963. Currency = dac.Currency,
  19964. CurrencyName = sd.Name,
  19965. SubTotal = dac.SubTotal,
  19966. })
  19967. .ToArray();
  19968. var data = new ChoiceDraftMobileSubInfo3To6View()
  19969. {
  19970. ParentId = eecInfo.Id,
  19971. Choice = eecInfo.ChoiceThree,
  19972. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  19973. Details = dayAndCostDatas
  19974. };
  19975. return Ok(JsonView(data));
  19976. }
  19977. else if (subType == 4) //4:伙食费
  19978. {
  19979. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  19980. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  19981. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  19982. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId && dac.Type == 2)
  19983. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  19984. {
  19985. ParentId = dac.ParentId,
  19986. SubId = dac.Id,
  19987. Type = dac.Type,
  19988. Days = dac.Days,
  19989. NationalTravelFeeId = dac.NationalTravelFeeId,
  19990. Arae = $"{ntf.Country}-{ntf.City}",
  19991. Cost = dac.Cost,
  19992. Currency = dac.Currency,
  19993. CurrencyName = sd.Name,
  19994. SubTotal = dac.SubTotal,
  19995. })
  19996. .ToArray();
  19997. var data = new ChoiceDraftMobileSubInfo3To6View()
  19998. {
  19999. ParentId = eecInfo.Id,
  20000. Choice = eecInfo.ChoiceFour,
  20001. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  20002. Details = dayAndCostDatas
  20003. };
  20004. return Ok(JsonView(data));
  20005. }
  20006. else if (subType == 5) //5:公杂费
  20007. {
  20008. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  20009. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  20010. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  20011. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId && dac.Type == 3)
  20012. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  20013. {
  20014. ParentId = dac.ParentId,
  20015. SubId = dac.Id,
  20016. Type = dac.Type,
  20017. Days = dac.Days,
  20018. NationalTravelFeeId = dac.NationalTravelFeeId,
  20019. Arae = $"{ntf.Country}-{ntf.City}",
  20020. Cost = dac.Cost,
  20021. Currency = dac.Currency,
  20022. CurrencyName = sd.Name,
  20023. SubTotal = dac.SubTotal,
  20024. })
  20025. .ToArray();
  20026. var data = new ChoiceDraftMobileSubInfo3To6View()
  20027. {
  20028. ParentId = eecInfo.Id,
  20029. Choice = eecInfo.ChoiceFive,
  20030. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  20031. Details = dayAndCostDatas
  20032. };
  20033. return Ok(JsonView(data));
  20034. }
  20035. else if (subType == 6) //6:培训费
  20036. {
  20037. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  20038. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  20039. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  20040. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId && dac.Type == 4)
  20041. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  20042. {
  20043. ParentId = dac.ParentId,
  20044. SubId = dac.Id,
  20045. Type = dac.Type,
  20046. Days = dac.Days,
  20047. NationalTravelFeeId = dac.NationalTravelFeeId,
  20048. Arae = $"{ntf.Country}-{ntf.City}",
  20049. Cost = dac.Cost,
  20050. Currency = dac.Currency,
  20051. CurrencyName = sd.Name,
  20052. SubTotal = dac.SubTotal,
  20053. })
  20054. .ToArray();
  20055. var data = new ChoiceDraftMobileSubInfo3To6View()
  20056. {
  20057. ParentId = eecInfo.Id,
  20058. Choice = eecInfo.ChoiceSix,
  20059. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  20060. Details = dayAndCostDatas
  20061. };
  20062. return Ok(JsonView(data));
  20063. }
  20064. else if (subType == 7) //7:其他
  20065. {
  20066. //其他款项
  20067. var otherData = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>()
  20068. .LeftJoin<Sys_SetData>((dop, sd1) => dop.SetDataId == sd1.Id)
  20069. .LeftJoin<Sys_SetData>((dop, sd1, sd2) => dop.Currency == sd2.Id)
  20070. .Where((dop, sd1, sd2) => dop.IsDel == 0 && dop.ParentId == dto.DraftId)
  20071. .OrderBy((dop, sd1, sd2) => dop.Index)
  20072. .Select((dop, sd1, sd2) => new DayOtherPriceDraftMobileInfoView
  20073. {
  20074. ParentId = dop.ParentId,
  20075. SubId = dop.Id,
  20076. Index = dop.Index,
  20077. SetDataId = dop.SetDataId,
  20078. SetDataName = sd1.Name,
  20079. Cost = dop.Cost,
  20080. Currency = dop.Currency,
  20081. CurrencyName = sd2.Name,
  20082. SubTotal = dop.SubTotal,
  20083. Remark = dop.Remark,
  20084. })
  20085. .ToArray();
  20086. var data = new ChoiceSevenDraftMobileSubInfoView()
  20087. {
  20088. ParentId = eecInfo.Id,
  20089. OtherExpenses_Checked = eecInfo.OtherExpenses_Checked,
  20090. OtherExpensesTotalCost = otherData.Sum(x => x.SubTotal),
  20091. Details = otherData
  20092. };
  20093. return Ok(JsonView(data));
  20094. }
  20095. return Ok(JsonView(false));
  20096. }
  20097. #region op
  20098. ///// <summary>
  20099. ///// 移动端更新费用消息通知
  20100. ///// </summary>
  20101. ///// <param name="draftId"></param>
  20102. ///// <param name="id"></param>
  20103. ///// <param name="currUserId"></param>
  20104. //private async Task EnterExitCostDraftMobileOpNotice(int draftId, int id, int currUserId)
  20105. //{
  20106. // try
  20107. // {
  20108. // ////生成默认文件pdf并且通知人员
  20109. // //var fileView = await GeneralMethod.EnterExitCostDownload(new EnterExitCostDownloadDto()
  20110. // //{
  20111. // // DiId = draftId,
  20112. // // ExportType = 1,
  20113. // // SubTypeId = 1005
  20114. // //}, "pdf");
  20115. // ////发送通知
  20116. // //string fileUrl = (string)fileView.Data.GetType().GetProperty("Url").GetValue(fileView.Data, null);
  20117. // //string md5Sign = GeneralMethod.Encrypt($"{id}&fileName={fileUrl}");
  20118. // //string url = string.Format("http://oa.pan-american-intl.com:4399/#/Sankunginfo?sign={0}&fileName={1}", id, fileUrl);
  20119. // //await AppNoticeLibrary.SendUserMsg_GroupShare_ToGM(draftId, new List<string>() { "208", "233", "21" }, currUserId, url);
  20120. // ////汇率信息记录
  20121. // //await GeneralMethod.RateRecordSave(currUserId, id, "出入境费用");
  20122. // }
  20123. // catch (Exception ex)
  20124. // {
  20125. // //记录日志
  20126. // throw;
  20127. // }
  20128. //}
  20129. /// <summary>
  20130. /// 验证出入境费用数据是否存在
  20131. /// 不存在添加
  20132. /// </summary>
  20133. /// <param name="draftId"></param>
  20134. /// <param name="currUserId"></param>
  20135. /// <returns></returns>
  20136. private async Task<int> EnterExitCostDraftVerifyIsNull(int draftId, int currUserId)
  20137. {
  20138. var parentId = 0;
  20139. var info = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.IsDel == 0 && x.Id == draftId).OrderByDescending(x => x.CreateTime).FirstAsync();
  20140. if (info != null) parentId = info.Id;
  20141. else
  20142. {
  20143. var currencys = await EnterExitCostDraftMobileGetCurrencyInit();
  20144. int addId = await _sqlSugar.Insertable(new Grp_EnterExitCostDraft() { CreateUserId = currUserId, CurrencyRemark = JsonConvert.SerializeObject(currencys) }).ExecuteReturnIdentityAsync();
  20145. parentId = addId;
  20146. }
  20147. return parentId;
  20148. }
  20149. /// <summary>
  20150. /// 团组模块 - 出入境费用-草稿-移动端 - 查看权限用户
  20151. /// </summary>
  20152. /// <returns></returns>
  20153. [HttpPost]
  20154. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20155. public async Task<IActionResult> EnterExitCostDraftMobileViewPermissionUsers(EnterExitCostDraftMobileViewPermissionUsersDto dto)
  20156. {
  20157. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  20158. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20159. //验证查看权限
  20160. (bool isView, bool isSet) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  20161. if (!isView) return Ok(JsonView(false, _viewPermStr));
  20162. var userIds = await _sqlSugar
  20163. .Queryable<Grp_EnterExitCostDraftPermission>()
  20164. .Where(x => x.IsDel == 0 && x.DraftId == dto.DraftId)
  20165. .Select(x => x.UserId)
  20166. .ToArrayAsync();
  20167. var perUsers = await _enterExitCostDraftRep.PermissionViewUsersAsync();
  20168. var perUsersView = new List<dynamic>();
  20169. var feeBasePerm = AppSettingsHelper.Get<FeeBasePermView>("FeeBasePerm");
  20170. var viewPermissionData = new List<PermissionViewUserview>();
  20171. if (feeBasePerm.Any())
  20172. {
  20173. foreach (var item in feeBasePerm)
  20174. {
  20175. if (item.Users.Any())
  20176. {
  20177. viewPermissionData.AddRange(item.Users);
  20178. }
  20179. }
  20180. }
  20181. foreach (var item in perUsers)
  20182. {
  20183. bool isView1 = false;
  20184. if (userIds.Any(x => x == item.Id)) isView1 = true;
  20185. else if (viewPermissionData.Any(x => x.Id == dto.CurrUserId) && item.Id == dto.CurrUserId) isView1 = true;
  20186. perUsersView.Add(new { Id = item.Id, Name = item.Name, IsView = isView1 });
  20187. }
  20188. return Ok(JsonView(perUsersView));
  20189. }
  20190. /// <summary>
  20191. /// 团组模块 - 出入境费用-草稿-移动端 - 设置view权限
  20192. /// </summary>
  20193. /// <returns></returns>
  20194. [HttpPost]
  20195. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20196. public async Task<IActionResult> EnterExitCostDraftMobileSetViewPermissiion(EnterExitCostDraftMobileSetViewPermissiionDto dto)
  20197. {
  20198. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20199. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  20200. if (dto.UserIds.Length < 1) return Ok(JsonView(false, "请传入有效的userId;"));
  20201. //验证查看编辑权限
  20202. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  20203. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  20204. var permissions = new List<Grp_EnterExitCostDraftPermission>() { };
  20205. foreach (var userId in dto.UserIds)
  20206. {
  20207. permissions.Add(new Grp_EnterExitCostDraftPermission { Permission = 1, DraftId = dto.DraftId, UserId = userId, CreateUserId = dto.CurrUserId });
  20208. }
  20209. if (permissions.Any())
  20210. {
  20211. if (!permissions.Any(x => x.UserId == dto.CurrUserId))
  20212. {
  20213. permissions.Add(new Grp_EnterExitCostDraftPermission { Permission = 1, DraftId = dto.DraftId, UserId = dto.CurrUserId, CreateUserId = dto.CurrUserId });
  20214. }
  20215. _sqlSugar.BeginTran();
  20216. await _sqlSugar.Deleteable<Grp_EnterExitCostDraftPermission>().Where(it => it.DraftId == dto.DraftId).ExecuteCommandAsync();
  20217. var result = await _sqlSugar.Insertable(permissions).ExecuteCommandAsync();
  20218. if (result < 1)
  20219. {
  20220. _sqlSugar.RollbackTran();
  20221. return Ok(JsonView(false));
  20222. }
  20223. _sqlSugar.CommitTran();
  20224. return Ok(JsonView(true));
  20225. }
  20226. return Ok(JsonView(false));
  20227. }
  20228. /// <summary>
  20229. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 省份
  20230. /// </summary>
  20231. /// <returns></returns>
  20232. [HttpPost]
  20233. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20234. public async Task<IActionResult> EnterExitCostDraftMobileOpProv(EnterExitCostDraftMobileOpProvDto dto)
  20235. {
  20236. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  20237. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20238. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20239. if (dto.ProvinceId < 1) return Ok(JsonView(false, "请传入有效的省份Id!"));
  20240. int id = dto.DraftId;
  20241. if (id <= 0) //add
  20242. {
  20243. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  20244. var add = await _sqlSugar.Insertable(new Grp_EnterExitCostDraft() { ProvinceId = dto.ProvinceId, CreateUserId = dto.CurrUserId }).ExecuteCommandAsync();
  20245. if (add < 1) return Ok(JsonView(false));
  20246. id = add;
  20247. }
  20248. else //update
  20249. {
  20250. //验证查看编辑权限
  20251. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  20252. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  20253. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>().SetColumns(x => new Grp_EnterExitCostDraft() { ProvinceId = dto.ProvinceId }).Where(x => x.Id == dto.DraftId).ExecuteCommandAsync();
  20254. if (upd < 1) return Ok(JsonView(false));
  20255. }
  20256. return Ok(JsonView(new { parentId = id }));
  20257. }
  20258. /// <summary>
  20259. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 汇率
  20260. /// </summary>
  20261. /// <returns></returns>
  20262. [HttpPost]
  20263. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20264. public async Task<IActionResult> EnterExitCostDraftMobileOpRate(PostEnterExitCostDraftMobileFeeRateOpDto dto)
  20265. {
  20266. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  20267. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20268. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20269. if (dto.Currencys.Length < 1) return Ok(JsonView(false, "请传入有效的汇率信息!"));
  20270. var currencyStr = CommonFun.GetCurrencyChinaToString(dto.Currencys.ToList());
  20271. int id = dto.DraftId;
  20272. if (id <= 0) //add
  20273. {
  20274. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  20275. var add = await _sqlSugar.Insertable(new Grp_EnterExitCostDraft() { ProvinceId = dto.ProvinceId, CurrencyRemark = currencyStr, CreateUserId = dto.CurrUserId }).ExecuteCommandAsync();
  20276. if (add < 1) return Ok(JsonView(false));
  20277. id = add;
  20278. }
  20279. else //update
  20280. {
  20281. //验证查看编辑权限
  20282. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  20283. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  20284. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>().SetColumns(x => new Grp_EnterExitCostDraft() { CurrencyRemark = currencyStr }).Where(x => x.Id == dto.DraftId).ExecuteCommandAsync();
  20285. if (upd < 1) return Ok(JsonView(false));
  20286. }
  20287. #region 汇率变更时更改币种相关费用
  20288. var opDayCosts = new List<Grp_DayAndCostDraft>();
  20289. var opDayOtherCosts = new List<Grp_DayOtherPriceDraft>();
  20290. var eecCurrencys = dto.Currencys.Select(x => x.CurrencyCode.ToUpper()).ToList();
  20291. var dayCosts = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  20292. .LeftJoin<Sys_SetData>((dac, sd) => dac.Currency == sd.Id)
  20293. .Where((dac, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId)
  20294. .Select((dac, sd) => new
  20295. {
  20296. dac.Id,
  20297. dac.ParentId,
  20298. CurrencyCode = sd.Name,
  20299. dac.Cost
  20300. })
  20301. .ToList();
  20302. var dayOtherCosts = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>()
  20303. .LeftJoin<Sys_SetData>((dop, sd) => dop.Currency == sd.Id)
  20304. .Where((dop, sd) => dop.IsDel == 0 && dop.ParentId == dto.DraftId)
  20305. .Select((dop, sd) => new
  20306. {
  20307. dop.Id,
  20308. dop.ParentId,
  20309. CurrencyCode = sd.Name,
  20310. dop.Cost
  20311. })
  20312. .ToList();
  20313. if (dayCosts.Count > 0)
  20314. {
  20315. var new_dayCosts = dayCosts.Where(x => eecCurrencys.Contains(x.CurrencyCode.ToUpper())).GroupBy(x => x.CurrencyCode);
  20316. foreach (var dc in new_dayCosts)
  20317. {
  20318. var thisCurrency = dc.Key.ToUpper();
  20319. var thisRate = dto.Currencys.Where(x => x.CurrencyCode.ToUpper().Equals(thisCurrency)).First()?.Rate ?? 0.00M;
  20320. if (thisRate == 0.00M) continue;
  20321. foreach (var dcSub in dc)
  20322. {
  20323. opDayCosts.Add(new Grp_DayAndCostDraft()
  20324. {
  20325. Id = dcSub.Id,
  20326. ParentId = dcSub.ParentId,
  20327. Cost = dcSub.Cost,
  20328. SubTotal = dcSub.Cost * thisRate,
  20329. Remark = $"[移动端->汇率变更时费用变更][变更信息:currency:{thisCurrency}、opDatetime:{DateTime.Now:yyyy-MM-dd HH:mm:ss}、opUserId:{dto.CurrUserId}]"
  20330. });
  20331. }
  20332. }
  20333. if (opDayCosts.Count > 0)
  20334. {
  20335. await _sqlSugar.Updateable(opDayCosts).UpdateColumns(x => new { x.SubTotal, x.Remark }).WhereColumns(x => new { x.Id }).ExecuteCommandAsync();
  20336. }
  20337. }
  20338. if (dayOtherCosts.Count > 0)
  20339. {
  20340. var new_dayOtherCosts = dayOtherCosts.Where(x => eecCurrencys.Contains(x.CurrencyCode.ToUpper())).GroupBy(x => x.CurrencyCode);
  20341. foreach (var dc in new_dayOtherCosts)
  20342. {
  20343. var thisCurrency = dc.Key.ToUpper();
  20344. var thisRate = dto.Currencys.Where(x => x.CurrencyCode.ToUpper().Equals(thisCurrency)).First()?.Rate ?? 0.00M;
  20345. if (thisRate == 0.00M) continue;
  20346. foreach (var dcSub in dc)
  20347. {
  20348. opDayOtherCosts.Add(new Grp_DayOtherPriceDraft()
  20349. {
  20350. Id = dcSub.Id,
  20351. ParentId = dcSub.ParentId,
  20352. Cost = dcSub.Cost,
  20353. SubTotal = dcSub.Cost * thisRate,
  20354. // Remark = $"[移动端->汇率变更时费用变更][变更信息:currency:{thisCurrency}、opDatetime:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}、opUserId:{dto.CurrUserId}]"
  20355. });
  20356. }
  20357. }
  20358. if (opDayOtherCosts.Count > 0)
  20359. {
  20360. await _sqlSugar.Updateable(opDayOtherCosts).UpdateColumns(x => new { x.SubTotal }).WhereColumns(x => new { x.Id }).ExecuteCommandAsync();
  20361. }
  20362. }
  20363. #endregion
  20364. ////消息通知
  20365. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  20366. ////汇率信息记录
  20367. //await GeneralMethod.RateRecordSave(dto.CurrUserId, id, "出入境费用");
  20368. return Ok(JsonView(new { parentId = id }));
  20369. }
  20370. /// <summary>
  20371. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 复选框
  20372. /// </summary>
  20373. /// <returns></returns>
  20374. [HttpPost]
  20375. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20376. public async Task<IActionResult> EnterExitCostDraftMobileOpCheckbox(PostEnterExitCostDraftMobileFeeOpCheckboxDto dto)
  20377. {
  20378. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  20379. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  20380. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20381. var checkboxInfo = _mapper.Map<Grp_EnterExitCostDraft>(dto);
  20382. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  20383. int id = dto.DraftId;
  20384. if (id <= 0) //add
  20385. {
  20386. checkboxInfo.ProvinceId = dto.ProvinceId;
  20387. checkboxInfo.CreateUserId = dto.CurrUserId;
  20388. checkboxInfo.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostDraftMobileGetCurrencyInit());
  20389. var add = await _sqlSugar.Insertable(checkboxInfo).ExecuteCommandAsync();
  20390. if (add < 1) return Ok(JsonView(false));
  20391. }
  20392. else //update
  20393. {
  20394. var upd = await _sqlSugar.Updateable(checkboxInfo)
  20395. .UpdateColumns(x => new
  20396. {
  20397. x.ChoiceOne,
  20398. x.ChoiceTwo,
  20399. x.SumJJC,
  20400. x.SumGWC,
  20401. x.SumTDC,
  20402. x.ChoiceThree,
  20403. x.ChoiceFour,
  20404. x.ChoiceFive,
  20405. x.ChoiceSix,
  20406. x.OtherExpenses_Checked
  20407. })
  20408. .Where(x => x.Id == id)
  20409. .ExecuteCommandAsync();
  20410. if (upd < 1) return Ok(JsonView(false));
  20411. }
  20412. return Ok(JsonView(new { parentId = id }));
  20413. }
  20414. /// <summary>
  20415. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 3-7项复选框单个复选框
  20416. /// </summary>
  20417. /// <returns></returns>
  20418. [HttpPost]
  20419. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20420. public async Task<IActionResult> EnterExitCostDraftMobileOpSingleCheckbox(EnterExitCostDarftMobileOpSingleCheckboxDto dto)
  20421. {
  20422. int itemTypeId = dto.ItemType, currUserId = dto.CurrUserId, draftId = dto.DraftId, isSelected = dto.IsSelected;
  20423. var itemTypes = new List<int>() { 3, 4, 5, 6, 7 };
  20424. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  20425. if (draftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  20426. if (currUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20427. if (!itemTypes.Contains(itemTypeId)) return Ok(JsonView(false, $"请传入要修改的项类型;3:住宿费; 4:伙食费; 5:公杂费; 6:培训费;7:其他;"));
  20428. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  20429. var checkboxInfo = new Grp_EnterExitCostDraft()
  20430. {
  20431. Id = draftId,
  20432. ProvinceId = dto.ProvinceId,
  20433. CreateUserId = currUserId
  20434. };
  20435. if (itemTypeId == 3) checkboxInfo.ChoiceThree = isSelected;
  20436. else if (itemTypeId == 4) checkboxInfo.ChoiceFour = isSelected;
  20437. else if (itemTypeId == 5) checkboxInfo.ChoiceFive = isSelected;
  20438. else if (itemTypeId == 6) checkboxInfo.ChoiceSix = isSelected;
  20439. else if (itemTypeId == 7) checkboxInfo.OtherExpenses_Checked = isSelected;
  20440. if (draftId <= 0) //add
  20441. {
  20442. checkboxInfo.CreateUserId = dto.CurrUserId;
  20443. checkboxInfo.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  20444. var add = await _sqlSugar.Insertable(checkboxInfo).ExecuteCommandAsync();
  20445. if (add < 1) return Ok(JsonView(false));
  20446. }
  20447. else //update
  20448. {
  20449. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>()
  20450. .SetColumnsIF(itemTypeId == 3, it => it.ChoiceThree == isSelected)
  20451. .SetColumnsIF(itemTypeId == 4, it => it.ChoiceFour == isSelected)
  20452. .SetColumnsIF(itemTypeId == 5, it => it.ChoiceFive == isSelected)
  20453. .SetColumnsIF(itemTypeId == 6, it => it.ChoiceSix == isSelected)
  20454. .SetColumnsIF(itemTypeId == 7, it => it.OtherExpenses_Checked == isSelected)
  20455. .Where(x => x.Id == draftId)
  20456. .ExecuteCommandAsync();
  20457. if (upd < 1) return Ok(JsonView(false));
  20458. }
  20459. return Ok(JsonView(new { parentId = draftId }));
  20460. }
  20461. /// <summary>
  20462. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 境内费用 Step1
  20463. /// </summary>
  20464. /// <returns></returns>
  20465. [HttpPost]
  20466. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20467. public async Task<IActionResult> EnterExitCostDraftMobileOpStep1(PostEnterExitCostDraftMobileOpStep1Dto dto)
  20468. {
  20469. int id = dto.DraftId, currUserId = dto.CurrUserId;
  20470. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  20471. if (id < 1) return Ok(JsonView(false, MsgTips.DiId));
  20472. if (currUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20473. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  20474. var info = _mapper.Map<Grp_EnterExitCostDraft>(dto);
  20475. info.ProvinceId = dto.ProvinceId;
  20476. info.FirstItemRemark = dto.FirstItemRemark;
  20477. info.InsidePay = dto.Visa + dto.Service + dto.Safe + dto.Ticket + dto.HeSuan + dto.YiMiao;
  20478. if (id <= 0) //add
  20479. {
  20480. info.CreateUserId = dto.CurrUserId;
  20481. info.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  20482. var add = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  20483. if (add < 1) return Ok(JsonView(false));
  20484. id = add;
  20485. }
  20486. else //update
  20487. {
  20488. var upd = await _sqlSugar.Updateable(info)
  20489. .UpdateColumns(x => new
  20490. {
  20491. x.ChoiceOne,
  20492. x.InsidePay,
  20493. x.VisaRemark,
  20494. x.Visa,
  20495. x.Service,
  20496. x.Safe,
  20497. x.Ticket,
  20498. x.HeSuan,
  20499. x.YiMiao,
  20500. x.FirstItemRemark
  20501. })
  20502. .Where(x => x.Id == id)
  20503. .ExecuteCommandAsync();
  20504. if (upd < 1) return Ok(JsonView(false));
  20505. }
  20506. ////消息通知
  20507. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  20508. return Ok(JsonView(new { parentId = id, itemTotal = info.InsidePay }));
  20509. }
  20510. /// <summary>
  20511. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 国际旅费 Step2
  20512. /// </summary>
  20513. /// <returns></returns>
  20514. [HttpPost]
  20515. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20516. public async Task<IActionResult> EnterExitCostDraftMobileOpStep2(PostEnterExitCostDraftMobileOpStep2Dto dto)
  20517. {
  20518. int id = dto.DraftId;
  20519. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  20520. if (id < 1) return Ok(JsonView(false, MsgTips.DiId));
  20521. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20522. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  20523. var info = _mapper.Map<Grp_EnterExitCostDraft>(dto);
  20524. info.ProvinceId = dto.ProvinceId;
  20525. info.OutsideJJPay = dto.OutsideJJPay;
  20526. info.OutsideGWPay = dto.OutsideGWPay;
  20527. info.OutsideTDPay = dto.OutsideTDPay;
  20528. info.AirJJ = dto.AirJJ;
  20529. info.AirGW = dto.AirGW;
  20530. info.AirTD = dto.AirTD;
  20531. info.CityTranffic = dto.CityTranffic;
  20532. info.CityTranffic1 = dto.CityTranffic1;
  20533. info.CityTranffic2 = dto.CityTranffic2;
  20534. info.TwoItemRemark = dto.TwoItemRemark;
  20535. info.SumJJC = dto.ChoiceTwoJJ;
  20536. info.SumGWC = dto.ChoiceTwoGW;
  20537. info.SumTDC = dto.ChoiceTwoTD;
  20538. decimal jjcItemTotal = 0.00M, gwcItemTotal = 0.00M, tdcItemTotal = 0.00M;
  20539. if (id <= 0) //add
  20540. {
  20541. info.CreateUserId = dto.CurrUserId;
  20542. info.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  20543. var addId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  20544. if (addId <= 0) return Ok(JsonView(false));
  20545. id = addId;
  20546. }
  20547. else //update
  20548. {
  20549. var upd = await _sqlSugar.Updateable(info)
  20550. .UpdateColumns(x => new
  20551. {
  20552. x.SumJJC,
  20553. x.OutsideJJPay,
  20554. x.SumGWC,
  20555. x.OutsideGWPay,
  20556. x.SumTDC,
  20557. x.OutsideTDPay,
  20558. x.AirJJ,
  20559. x.AirGW,
  20560. x.AirTD,
  20561. x.CityTranffic,
  20562. x.CityTranffic1,
  20563. x.CityTranffic2,
  20564. x.TwoItemRemark
  20565. })
  20566. .Where(x => x.Id == id)
  20567. .ExecuteCommandAsync();
  20568. if (upd < 1) return Ok(JsonView(false));
  20569. }
  20570. jjcItemTotal = info.AirJJ + info.CityTranffic;
  20571. gwcItemTotal = info.AirGW + info.CityTranffic;
  20572. tdcItemTotal = info.AirTD + info.CityTranffic;
  20573. ////消息通知
  20574. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  20575. return Ok(JsonView(new
  20576. {
  20577. parentId = id,
  20578. choiceTwoJJ = dto.ChoiceTwoJJ,
  20579. jjcItemTotal = jjcItemTotal,
  20580. choiceTwoGW = dto.ChoiceTwoGW,
  20581. gwcItemTotal = gwcItemTotal,
  20582. choiceTwoTD = dto.ChoiceTwoTD,
  20583. tdcItemTotal = tdcItemTotal
  20584. }));
  20585. }
  20586. /// <summary>
  20587. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 批量(住宿、伙食、公杂、培训) Step3-Step6
  20588. /// </summary>
  20589. /// <returns></returns>
  20590. [HttpPost]
  20591. [ApiExplorerSettings(IgnoreApi = true)]
  20592. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20593. public async Task<IActionResult> EnterExitCostDraftMobileOpBatchStep3To6(PostEnterExitCostDraftMobileOpStep3To6Dto dto)
  20594. {
  20595. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  20596. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  20597. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20598. if (dto.Infos.Length < 1) return Ok(JsonView(false, "请传入有效的费用信息!"));
  20599. var feeTypeIds = new List<int>() { 1, 2, 3, 4, };
  20600. if (!feeTypeIds.Contains(dto.FeeType)) return Ok(JsonView(false, "请传入有效的费用类型!"));
  20601. var infos1 = _mapper.Map<List<Grp_DayAndCostDraft>>(dto.Infos);
  20602. var infos = infos1.Select(x => new Grp_DayAndCostDraft
  20603. {
  20604. Id = x.Id,
  20605. ParentId = dto.DraftId,
  20606. Type = dto.FeeType,
  20607. Days = x.Days,
  20608. NationalTravelFeeId = x.NationalTravelFeeId,
  20609. Cost = x.Cost,
  20610. Currency = x.Currency,
  20611. SubTotal = x.SubTotal,
  20612. CreateUserId = dto.CurrUserId
  20613. })
  20614. .ToList();
  20615. var adds = infos.Where(x => x.Id <= 0).ToList();
  20616. var upds = infos.Where(x => x.Id > 0).ToList();
  20617. if (adds.Count > 0)
  20618. {
  20619. var add = await _sqlSugar.Insertable(adds).ExecuteCommandAsync();
  20620. if (add < 1) return Ok(JsonView(false));
  20621. }
  20622. if (upds.Count > 0)
  20623. {
  20624. var upd = await _sqlSugar.Updateable(adds)
  20625. .UpdateColumns(x => new
  20626. {
  20627. x.Days,
  20628. x.NationalTravelFeeId,
  20629. x.Cost,
  20630. x.Currency,
  20631. x.SubTotal
  20632. })
  20633. .WhereColumns(x => new { x.Id })
  20634. .ExecuteCommandAsync();
  20635. if (upd < 1) return Ok(JsonView(false));
  20636. }
  20637. var itemTotal = _sqlSugar.Queryable<Grp_DayAndCostDraft>().Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId && x.Type == dto.FeeType).Sum(x => x.SubTotal);
  20638. ////消息通知
  20639. //var id = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId).First()?.Id ?? 0;
  20640. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  20641. return Ok(JsonView(new { itemTotal = itemTotal }));
  20642. }
  20643. /// <summary>
  20644. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 单条(住宿、伙食、公杂、培训) Step3-Step6
  20645. /// </summary>
  20646. /// <returns></returns>
  20647. [HttpPost]
  20648. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20649. public async Task<IActionResult> EnterExitCostDraftMobileOpSingleStep3To6(PostEnterExitCostDraftMobileOpSingleStep3To6Dto dto)
  20650. {
  20651. var feeTypeIds = new List<int>() { 3, 4, 5, 6 };
  20652. int subId = dto.SubId, feeType = dto.FeeType;
  20653. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  20654. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  20655. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20656. if (!feeTypeIds.Contains(dto.FeeType)) return Ok(JsonView(false, "请传入有效的费用类型!"));
  20657. var subInfo = _mapper.Map<Grp_DayAndCostDraft>(dto);
  20658. subInfo.Id = subId;
  20659. subInfo.ParentId = dto.DraftId;
  20660. if (feeType == 3) subInfo.Type = 1;
  20661. else if (feeType == 4) subInfo.Type = 2;
  20662. else if (feeType == 5) subInfo.Type = 3;
  20663. else if (feeType == 6) subInfo.Type = 4;
  20664. subInfo.CreateUserId = dto.CurrUserId;
  20665. int parentId = await EnterExitCostDraftVerifyIsNull(dto.DraftId, dto.CurrUserId); //主表验证
  20666. if (parentId < 1) return Ok(JsonView(false));
  20667. //子表op
  20668. if (subId < 1)
  20669. {
  20670. var subAdd = await _sqlSugar.Insertable(subInfo).ExecuteCommandAsync();
  20671. if (subAdd < 1) return Ok(JsonView(false));
  20672. }
  20673. else
  20674. {
  20675. var subUpd = await _sqlSugar.Updateable(subInfo)
  20676. .UpdateColumns(x => new
  20677. {
  20678. x.Days,
  20679. x.NationalTravelFeeId,
  20680. x.Cost,
  20681. x.Currency,
  20682. x.SubTotal
  20683. })
  20684. .WhereColumns(x => new { x.Id })
  20685. .ExecuteCommandAsync();
  20686. if (subUpd < 1) return Ok(JsonView(false));
  20687. }
  20688. var itemTotal = _sqlSugar.Queryable<Grp_DayAndCostDraft>().Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId && x.Type == feeType).Sum(x => x.SubTotal);
  20689. return Ok(JsonView(new { parentId = parentId, itemTotal = itemTotal }));
  20690. }
  20691. /// <summary>
  20692. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 其他费用-批量 Step7
  20693. /// </summary>
  20694. /// <returns></returns>
  20695. [HttpPost]
  20696. [ApiExplorerSettings(IgnoreApi = true)]
  20697. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20698. public async Task<IActionResult> EnterExitCostDraftMobileOpBatchStep7(PostEnterExitCostDraftMobileOpStep7Dto dto)
  20699. {
  20700. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  20701. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  20702. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20703. var infos1 = _mapper.Map<List<Grp_DayOtherPriceDraft>>(dto.Infos);
  20704. var infos = infos1.Select(x => new Grp_DayOtherPriceDraft()
  20705. {
  20706. Id = x.Id,
  20707. ParentId = dto.DraftId,
  20708. SetDataId = x.SetDataId,
  20709. Index = x.Index,
  20710. Cost = x.Cost,
  20711. Currency = x.Currency,
  20712. SubTotal = x.SubTotal,
  20713. CreateUserId = dto.CurrUserId,
  20714. Remark = x.Remark
  20715. }).ToList();
  20716. var adds = infos.Where(x => x.Id <= 0).ToList();
  20717. var upds = infos.Where(x => x.Id > 0).ToList();
  20718. if (adds.Count > 0)
  20719. {
  20720. var add = await _sqlSugar.Insertable(adds).ExecuteCommandAsync();
  20721. if (add < 1) return Ok(JsonView(false));
  20722. }
  20723. if (upds.Count > 0)
  20724. {
  20725. var upd = await _sqlSugar.Updateable(adds)
  20726. .UpdateColumns(x => new
  20727. {
  20728. x.Index,
  20729. x.SetDataId,
  20730. x.Cost,
  20731. x.Currency,
  20732. x.SubTotal,
  20733. x.Remark
  20734. })
  20735. .WhereColumns(x => new { x.Id })
  20736. .ExecuteCommandAsync();
  20737. if (upd < 1) return Ok(JsonView(false));
  20738. }
  20739. var itemTotal = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>().Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId).Sum(x => x.SubTotal);
  20740. //消息通知
  20741. //var id = _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.IsDel == 0 && x.Id == dto.DraftId).First()?.Id ?? 0;
  20742. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  20743. return Ok(JsonView(new { itemTotal = itemTotal }));
  20744. }
  20745. /// <summary>
  20746. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 其他费用-单条 Step7
  20747. /// </summary>
  20748. /// <returns></returns>
  20749. [HttpPost]
  20750. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20751. public async Task<IActionResult> EnterExitCostDraftMobileOpSingleStep7(PostEnterExitCostDraftMobileOpSingleStep7Dto dto)
  20752. {
  20753. int subId = dto.SubId, id = dto.DraftId;
  20754. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  20755. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  20756. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  20757. var subInfo = _mapper.Map<Grp_DayOtherPriceDraft>(dto);
  20758. subInfo.Id = subId;
  20759. subInfo.ParentId = id;
  20760. subInfo.CreateUserId = dto.CurrUserId;
  20761. int parentId = await EnterExitCostDraftVerifyIsNull(id, dto.CurrUserId); //主表验证
  20762. if (parentId < 1) return Ok(JsonView(false));
  20763. #region 子表op
  20764. if (subId < 1)//add
  20765. {
  20766. var subAdd = await _sqlSugar.Insertable(subInfo).ExecuteCommandAsync();
  20767. if (subAdd < 1) return Ok(JsonView(false));
  20768. }
  20769. else //upd
  20770. {
  20771. var subUpd = await _sqlSugar.Updateable(subInfo)
  20772. .UpdateColumns(x => new
  20773. {
  20774. x.Index,
  20775. x.SetDataId,
  20776. x.Cost,
  20777. x.Currency,
  20778. x.SubTotal,
  20779. x.Remark
  20780. })
  20781. .WhereColumns(x => new { x.Id })
  20782. .ExecuteCommandAsync();
  20783. if (subUpd < 1) return Ok(JsonView(false));
  20784. }
  20785. #endregion
  20786. var itemTotal = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>().Where(x => x.IsDel == 0 && x.ParentId == id).Sum(x => x.SubTotal);
  20787. ////消息通知
  20788. //await EnterExitCostMobileOpNotice(dto.Diid, parentId, dto.CurrUserId);
  20789. return Ok(JsonView(new { parentId = parentId, itemTotal = itemTotal }));
  20790. }
  20791. /// <summary>
  20792. /// 团组模块 - 出入境费用-草稿-移动端 - 3-6子项删除
  20793. /// </summary>
  20794. /// <returns></returns>
  20795. [HttpPost]
  20796. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20797. public async Task<IActionResult> EnterExitCostDraftMobileSubItemDel(EnterExitCostDraftSubItemDelDto dto)
  20798. {
  20799. var data = await _enterExitCostDraftRep.EnterExitCostDraftSubItemDel(dto);
  20800. if (data.Code != 0)
  20801. {
  20802. return Ok(JsonView(false, data.Msg));
  20803. }
  20804. return Ok(JsonView(true, "操作成功!", data.Data));
  20805. }
  20806. /// <summary>
  20807. /// 团组模块 - 出入境费用-草稿-移动端 - 其他费用删除
  20808. /// </summary>
  20809. /// <param name="dto"></param>
  20810. /// <returns></returns>
  20811. [HttpPost]
  20812. public IActionResult EnterExitCostDraftMobileOtherFeeDel(EnterExitCostDraftSubItemDelDto dto)
  20813. {
  20814. var data = new Grp_DayOtherPriceDraft()
  20815. {
  20816. Id = dto.Id,
  20817. IsDel = 1,
  20818. DeleteUserId = dto.DeleteUserId,
  20819. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  20820. };
  20821. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  20822. if (del > 0) return Ok(JsonView(true, "删除成功!"));
  20823. return Ok(JsonView(false, "删除失败!"));
  20824. }
  20825. #endregion
  20826. #endregion
  20827. #region 团组经理模块 出入境费用报价表
  20828. /// <summary>
  20829. /// 团组模块 - 出入境费用报价表 - 初始化数据源(币种类型)
  20830. /// </summary>
  20831. /// <returns></returns>
  20832. [HttpPost]
  20833. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20834. public async Task<IActionResult> EnterExitCostQuoteInitData(PortDtoBase dto)
  20835. {
  20836. var initRates = await GeneralMethod.EnterExitCostInitRate();
  20837. var liveRates = await GeneralMethod.EnterExitCostLiveRate();
  20838. var cnyInfo = new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.0000M };
  20839. initRates.Insert(0, cnyInfo);
  20840. liveRates.Insert(0, cnyInfo);
  20841. return Ok(JsonView(true, "查询成功!", new
  20842. {
  20843. InitRates = initRates,
  20844. LiveRates = liveRates
  20845. }));
  20846. }
  20847. /// <summary>
  20848. /// 团组模块 - 出入境费用报价表 - 报价表名称列表
  20849. /// </summary>
  20850. /// <returns></returns>
  20851. [HttpPost]
  20852. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20853. public async Task<IActionResult> EnterExitCostQuoteNameList(EnterExitCostQuoteNameListDto dto)
  20854. {
  20855. return Ok(await _enterExitCostQuoteRep.QuoteNameListAsync(dto));
  20856. }
  20857. /// <summary>
  20858. /// 团组模块 - 出入境费用报价表 - 团组名称列表
  20859. /// </summary>
  20860. /// <returns></returns>
  20861. [HttpPost]
  20862. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20863. public async Task<IActionResult> EnterExitCostQuoteGroupNameList(EnterExitCostQuoteGroupNameListDto dto)
  20864. {
  20865. return Ok(await _enterExitCostQuoteRep.GroupNameListAsync(dto));
  20866. }
  20867. /// <summary>
  20868. /// 团组模块 - 出入境费用报价表 - 根据团组Id获出入境费用相关信息
  20869. /// </summary>
  20870. /// <returns></returns>
  20871. [HttpPost]
  20872. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20873. public async Task<IActionResult> EnterExitCostQuoteEntryExitCosts(EnterExitCostInfobyDiIdDto dto)
  20874. {
  20875. int groupId = dto.DiId,
  20876. currUserId = dto.CurrUserId;
  20877. if (groupId < 1) return Ok(JsonView(false, "请传入有效的GroupId;"));
  20878. if (currUserId < 1) return Ok(JsonView(false, "请传入有效的CurrUserId;"));
  20879. //验证报价数据是否存在
  20880. var isNull = await _sqlSugar.Queryable<Grp_EnterExitCostQuote>().FirstAsync(x => x.IsDel == 0 && x.GroupId == dto.DiId);
  20881. if (isNull != null)
  20882. {
  20883. var info1 = await _enterExitCostQuoteRep.InfoAsync(new EnterExitCostQuoteInfoDto() { Id = isNull.Id });
  20884. if (!info1.Rates.Any())
  20885. {
  20886. var rates = await GeneralMethod.EnterExitCostInitRate();
  20887. rates.Insert(0, new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
  20888. info1.Rates = rates.ToArray();
  20889. }
  20890. return Ok(JsonView(info1));
  20891. }
  20892. var result = await _enterExitCostQuoteRep.InfoByGroupIdAsync(dto.DiId);
  20893. result.GroupId = groupId;
  20894. //处理报价名称
  20895. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.DiId && x.IsDel == 0);
  20896. if (groupInfo != null)
  20897. {
  20898. var visitCountry = groupInfo.VisitCountry;
  20899. if (!string.IsNullOrEmpty(visitCountry))
  20900. {
  20901. string quoteName = string.Empty;
  20902. if (visitCountry.Contains("|"))
  20903. {
  20904. var countrys = visitCountry.Split("|");
  20905. quoteName = string.Join("、", countrys);
  20906. }
  20907. else quoteName = visitCountry;
  20908. quoteName += $"团组报价表";
  20909. result.Name = quoteName;
  20910. }
  20911. }
  20912. var info = await _enterExitCostRep.GetEnterExitCostInfoByDiId(dto);
  20913. if (info.Code != StatusCodes.Status200OK)
  20914. {
  20915. if (!result.Rates.Any())
  20916. {
  20917. var rates = await GeneralMethod.EnterExitCostInitRate();
  20918. result.Rates = rates.ToArray();
  20919. }
  20920. return Ok(JsonView(true, $"出入境费用明细未填写!", result));
  20921. }
  20922. var infoView = info.Data as EnterExitCostInfoView;
  20923. if (infoView == null) return Ok(JsonView(false, "数据类型转换失败!;"));
  20924. var countryFees = await _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x => x.IsDel == 0).ToListAsync();
  20925. var cityFilter = new List<string>() { "全部城市", "其他城市" };
  20926. var currencys = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToListAsync();
  20927. var eecRates = infoView.Currencys;
  20928. //默认添加人名币
  20929. if (!eecRates.Any(x => x.CurrencyCode.Equals("CNY")))
  20930. {
  20931. eecRates.Insert(0, new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
  20932. }
  20933. //处理团组人数
  20934. int pplNum = 1;
  20935. if (groupInfo != null) pplNum = groupInfo.VisitPNumber;
  20936. var views = new List<QuoteSubItemInfo>();
  20937. #region 数据填充
  20938. var intTravelCosts = new List<QuoteSubItemInfo>();
  20939. #region 机票费用 1354
  20940. int intTravelIndex = 1;
  20941. if (infoView.SumJJC == 1)
  20942. {
  20943. intTravelCosts.Add(new QuoteSubItemInfo
  20944. {
  20945. ItemId = 1354,
  20946. Index = intTravelIndex,
  20947. FeeName = "经济舱",
  20948. UnitPrice = infoView.AirJJ,
  20949. Currency = "CNY",
  20950. Quantity = 1,
  20951. PplNum = 1,
  20952. TotalAmt = infoView.AirJJ,
  20953. Remark = "",
  20954. });
  20955. intTravelIndex++;
  20956. }
  20957. if (infoView.SumGWC == 1)
  20958. {
  20959. intTravelCosts.Add(new QuoteSubItemInfo
  20960. {
  20961. ItemId = 1354,
  20962. Index = intTravelIndex,
  20963. FeeName = "公务舱",
  20964. UnitPrice = infoView.AirGW,
  20965. Currency = "CNY",
  20966. Quantity = 1,
  20967. PplNum = 1,
  20968. TotalAmt = infoView.AirGW,
  20969. Remark = "",
  20970. });
  20971. intTravelIndex++;
  20972. }
  20973. if (infoView.SumTDC == 1)
  20974. {
  20975. intTravelCosts.Add(new QuoteSubItemInfo
  20976. {
  20977. ItemId = 1354,
  20978. Index = intTravelIndex,
  20979. FeeName = "头等舱",
  20980. UnitPrice = infoView.AirTD,
  20981. Currency = "CNY",
  20982. Quantity = 1,
  20983. PplNum = 1,
  20984. TotalAmt = infoView.AirTD,
  20985. Remark = "",
  20986. });
  20987. intTravelIndex++;
  20988. }
  20989. intTravelCosts.Add(new QuoteSubItemInfo
  20990. {
  20991. ItemId = 1354,
  20992. Index = intTravelIndex,
  20993. FeeName = "城市间交通费用(经济舱)",
  20994. UnitPrice = infoView.CityTranffic,
  20995. Currency = "CNY",
  20996. Quantity = 1,
  20997. PplNum = pplNum,
  20998. TotalAmt = infoView.CityTranffic * pplNum,
  20999. Remark = "",
  21000. });
  21001. intTravelCosts.Add(new QuoteSubItemInfo
  21002. {
  21003. ItemId = 1354,
  21004. Index = intTravelIndex,
  21005. FeeName = "城市间交通费用(公务舱)",
  21006. UnitPrice = infoView.CityTranffic1,
  21007. Currency = "CNY",
  21008. Quantity = 1,
  21009. PplNum = pplNum,
  21010. TotalAmt = infoView.CityTranffic1 * pplNum,
  21011. Remark = "",
  21012. });
  21013. intTravelCosts.Add(new QuoteSubItemInfo
  21014. {
  21015. ItemId = 1354,
  21016. Index = intTravelIndex,
  21017. FeeName = "城市间交通费用(头等舱)",
  21018. UnitPrice = infoView.CityTranffic2,
  21019. Currency = "CNY",
  21020. Quantity = 1,
  21021. PplNum = pplNum,
  21022. TotalAmt = infoView.CityTranffic2 * pplNum,
  21023. Remark = "",
  21024. });
  21025. views.AddRange(intTravelCosts);
  21026. #endregion
  21027. var accomCosts = new List<QuoteSubItemInfo>();
  21028. #region 住宿费 1355
  21029. if (infoView.QuarterageData.Any())
  21030. {
  21031. int accomIndex = 1;
  21032. int accomItemTypeId = 1355;
  21033. var groupData = infoView.QuarterageData.GroupBy(x => x.NationalTravelFeeId);
  21034. foreach (var item in groupData)
  21035. {
  21036. string feeName = string.Empty;
  21037. var countryInfo = countryFees.FirstOrDefault(x => x.Id == item.Key);
  21038. if (countryInfo != null)
  21039. {
  21040. feeName = countryInfo.Country;
  21041. var city = countryInfo.City;
  21042. if (!string.IsNullOrEmpty(city) && cityFilter.Any(x => !x.Contains(city)))
  21043. {
  21044. feeName += $"-{city}";
  21045. }
  21046. }
  21047. var hotelInfo = item.FirstOrDefault();
  21048. if (hotelInfo == null) continue;
  21049. var thisCurrency = currencys.FirstOrDefault(x => x.Id == hotelInfo.Currency)?.Name ?? "nuknow";
  21050. var thisRate = eecRates.FirstOrDefault(x => x.CurrencyCode.Equals(thisCurrency))?.Rate ?? 1.0000M;
  21051. int quantity = item.ToList().Count;
  21052. accomCosts.Add(new QuoteSubItemInfo
  21053. {
  21054. ItemId = accomItemTypeId,
  21055. Index = accomIndex,
  21056. FeeName = feeName,
  21057. UnitPrice = hotelInfo.Cost,
  21058. Currency = thisCurrency,
  21059. Quantity = quantity,
  21060. PplNum = pplNum,
  21061. TotalAmt = hotelInfo.Cost * thisRate * quantity * pplNum,
  21062. Remark = "",
  21063. });
  21064. accomIndex++;
  21065. }
  21066. views.AddRange(accomCosts);
  21067. }
  21068. #endregion
  21069. var mealCosts = new List<QuoteSubItemInfo>();
  21070. #region 餐饮费 1356
  21071. if (infoView.BoardWagesData.Any())
  21072. {
  21073. var mealIndex = 1;
  21074. int mealItemTypeId = 1356;
  21075. var groupData = infoView.BoardWagesData.GroupBy(x => x.NationalTravelFeeId);
  21076. foreach (var item in groupData)
  21077. {
  21078. string feeName = string.Empty;
  21079. var countryInfo = countryFees.FirstOrDefault(x => x.Id == item.Key);
  21080. if (countryInfo != null)
  21081. {
  21082. feeName = countryInfo.Country;
  21083. var city = countryInfo.City;
  21084. if (!string.IsNullOrEmpty(city) && cityFilter.Any(x => !x.Contains(city)))
  21085. {
  21086. feeName += $"-{city}";
  21087. }
  21088. }
  21089. var mealInfo = item.FirstOrDefault();
  21090. if (mealInfo == null) continue;
  21091. var thisCurrency = currencys.FirstOrDefault(x => x.Id == mealInfo.Currency)?.Name ?? "nuknow";
  21092. var thisRate = eecRates.FirstOrDefault(x => x.CurrencyCode.Equals(thisCurrency))?.Rate ?? 1.0000M;
  21093. int quantity = item.ToList().Count;
  21094. mealCosts.Add(new QuoteSubItemInfo
  21095. {
  21096. ItemId = mealItemTypeId,
  21097. Index = mealIndex,
  21098. FeeName = feeName,
  21099. UnitPrice = mealInfo.Cost,
  21100. Currency = thisCurrency,
  21101. Quantity = quantity,
  21102. PplNum = pplNum,
  21103. TotalAmt = mealInfo.Cost * thisRate * quantity * pplNum,
  21104. Remark = "",
  21105. });
  21106. mealIndex++;
  21107. }
  21108. views.AddRange(mealCosts);
  21109. }
  21110. #endregion
  21111. var miscCosts = new List<QuoteSubItemInfo>();
  21112. #region 公杂费 1364
  21113. if (infoView.MiscellaneousFeeData.Any())
  21114. {
  21115. var miscIndex = 1;
  21116. int miscItemTypeId = 1364;
  21117. var groupData = infoView.MiscellaneousFeeData.GroupBy(x => x.NationalTravelFeeId);
  21118. foreach (var item in groupData)
  21119. {
  21120. string feeName = string.Empty;
  21121. var countryInfo = countryFees.FirstOrDefault(x => x.Id == item.Key);
  21122. if (countryInfo != null)
  21123. {
  21124. feeName = countryInfo.Country;
  21125. var city = countryInfo.City;
  21126. if (!string.IsNullOrEmpty(city) && cityFilter.Any(x => !x.Contains(city)))
  21127. {
  21128. feeName += $"-{city}";
  21129. }
  21130. }
  21131. var miscInfo = item.FirstOrDefault();
  21132. if (miscInfo == null) continue;
  21133. var thisCurrency = currencys.FirstOrDefault(x => x.Id == miscInfo.Currency)?.Name ?? "nuknow";
  21134. var thisRate = eecRates.FirstOrDefault(x => x.CurrencyCode.Equals(thisCurrency))?.Rate ?? 1.0000M;
  21135. int quantity = item.ToList().Count;
  21136. miscCosts.Add(new QuoteSubItemInfo
  21137. {
  21138. ItemId = miscItemTypeId,
  21139. Index = miscIndex,
  21140. FeeName = feeName,
  21141. UnitPrice = miscInfo.Cost,
  21142. Currency = thisCurrency,
  21143. Quantity = quantity,
  21144. PplNum = pplNum,
  21145. TotalAmt = miscInfo.Cost * thisRate * quantity * pplNum,
  21146. Remark = "",
  21147. });
  21148. miscIndex++;
  21149. }
  21150. views.AddRange(miscCosts);
  21151. }
  21152. #endregion
  21153. #region 签证+保险 1362
  21154. int visaInsIndex = 1;
  21155. int visaInsItemTypeId = 1362;
  21156. if (infoView.Visa > 0)
  21157. {
  21158. views.Add(new QuoteSubItemInfo()
  21159. {
  21160. ItemId = visaInsItemTypeId,
  21161. Index = visaInsIndex,
  21162. FeeName = $"签证",
  21163. UnitPrice = infoView.Visa,
  21164. Currency = $"CNY",
  21165. Quantity = 1,
  21166. PplNum = pplNum,
  21167. TotalAmt = infoView.Visa * pplNum,
  21168. Remark = "",
  21169. });
  21170. visaInsIndex++;
  21171. }
  21172. if (infoView.Safe > 0)
  21173. {
  21174. views.Add(new QuoteSubItemInfo()
  21175. {
  21176. ItemId = visaInsItemTypeId,
  21177. Index = visaInsIndex,
  21178. FeeName = $"保险",
  21179. UnitPrice = infoView.Safe,
  21180. Currency = $"CNY",
  21181. Quantity = 1,
  21182. PplNum = pplNum,
  21183. TotalAmt = infoView.Safe * pplNum,
  21184. Remark = "",
  21185. });
  21186. }
  21187. #endregion
  21188. #region 服务费 1363
  21189. int serviceFeeIndex = 1;
  21190. int serviceFeeItemTypeId = 1363;
  21191. if (infoView.Service > 0)
  21192. {
  21193. views.Add(new QuoteSubItemInfo()
  21194. {
  21195. ItemId = serviceFeeItemTypeId,
  21196. Index = serviceFeeIndex,
  21197. FeeName = $"服务费",
  21198. UnitPrice = infoView.Service,
  21199. Currency = $"CNY",
  21200. Quantity = 1,
  21201. PplNum = pplNum,
  21202. TotalAmt = infoView.Service * pplNum,
  21203. Remark = "",
  21204. });
  21205. }
  21206. #endregion
  21207. #endregion
  21208. if (result.FeeItems.Any())
  21209. {
  21210. result.FeeItems.Select(x =>
  21211. {
  21212. var feeInfos = views.Where(y => y.ItemId == x.ItemId).OrderBy(y => y.Index).ToArray();
  21213. if (feeInfos.Any()) x.Infos = feeInfos;
  21214. return x;
  21215. }
  21216. ).OrderBy(x => x.Index)
  21217. .ToList();
  21218. if (!result.Rates.Any())
  21219. {
  21220. if (eecRates.Any()) result.Rates = eecRates?.ToArray() ?? Array.Empty<CurrencyInfo>();
  21221. else
  21222. {
  21223. var rates = await GeneralMethod.EnterExitCostInitRate();
  21224. rates.Insert(0, new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
  21225. result.Rates = rates.ToArray();
  21226. }
  21227. }
  21228. }
  21229. return Ok(JsonView(result));
  21230. }
  21231. /// <summary>
  21232. /// 团组模块 - 出入境费用报价表 - Info
  21233. /// </summary>
  21234. /// <returns></returns>
  21235. [HttpPost]
  21236. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21237. public async Task<IActionResult> EnterExitCostQuoteInfo(EnterExitCostQuoteInfoDto dto)
  21238. {
  21239. var info = await _enterExitCostQuoteRep.InfoAsync(dto);
  21240. if (!info.Rates.Any())
  21241. {
  21242. var rates = await GeneralMethod.EnterExitCostInitRate();
  21243. rates.Add(new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
  21244. info.Rates = rates.ToArray();
  21245. }
  21246. return Ok(JsonView(info));
  21247. }
  21248. /// <summary>
  21249. /// 团组模块 - 出入境费用报价表 - OP
  21250. /// </summary>
  21251. /// <returns></returns>
  21252. [HttpPost]
  21253. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21254. public async Task<IActionResult> EnterExitCostQuoteOp(EnterExitCostQuoteOpDto dto)
  21255. {
  21256. return Ok(await _enterExitCostQuoteRep.OpAsync(dto));
  21257. }
  21258. /// <summary>
  21259. /// 团组模块 - 出入境费用报价表 - 删除 项
  21260. /// </summary>
  21261. /// <returns></returns>
  21262. [HttpPost]
  21263. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21264. public async Task<IActionResult> EnterExitCostQuoteItemDel(EnterExitCostQuoteItemDelDto dto)
  21265. {
  21266. if (dto.Id < 1) return Ok(JsonView(false, MsgTips.Id));
  21267. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  21268. return Ok(await _enterExitCostQuoteRep.ItemDelAsync(dto));
  21269. }
  21270. /// <summary>
  21271. /// 团组模块 - 出入境费用报价表 - 导出
  21272. /// </summary>
  21273. /// <returns></returns>
  21274. [HttpPost]
  21275. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21276. public async Task<IActionResult> EnterExitCostQuoteExcelExport(EnterExitCostQuoteExcelExportDto dto)
  21277. {
  21278. if (dto.Id < 1) return Ok(JsonView(false, MsgTips.Id));
  21279. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  21280. var info = await _enterExitCostQuoteRep.InfoAsync(new EnterExitCostQuoteInfoDto() { Id = dto.Id });
  21281. if (info == null) return Ok(JsonView(false, "报价信息未填写!"));
  21282. var rates = info.Rates;
  21283. var intTravelCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1354);//国际旅费
  21284. var accomCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1355); //住宿费
  21285. var mealCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1356); //餐饮费
  21286. var vehArranges = info.FeeItems.FirstOrDefault(x => x.ItemId == 1357); //车辆安排
  21287. var inviteTo = info.FeeItems.FirstOrDefault(x => x.ItemId == 1358); //邀请函发放对象
  21288. var inviteCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1359); //邀请函费用
  21289. var inviteTime = info.FeeItems.FirstOrDefault(x => x.ItemId == 1360); //邀请函发放时间
  21290. var officialActs = info.FeeItems.FirstOrDefault(x => x.ItemId == 1361); //公务活动
  21291. var visaIns = info.FeeItems.FirstOrDefault(x => x.ItemId == 1362); //签证+保险
  21292. var serviceCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1363); //服务费
  21293. var pubMiscs = info.FeeItems.FirstOrDefault(x => x.ItemId == 1364); //公杂费
  21294. var taxCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1365); //税费
  21295. //获取模板
  21296. string tempPath = AppSettingsHelper.Get("ExcelBasePath") + "Template/出入境费用明细报价表模板.xlsx";
  21297. var designer = new WorkbookDesigner();
  21298. designer.Workbook = new Workbook(tempPath);
  21299. designer.SetDataSource("QuoteName", info.Name);
  21300. designer.SetDataSource("CompanyTitle", "公司名称");
  21301. designer.SetDataSource("CompanyLabel", "");
  21302. #region 国际旅费
  21303. designer.SetDataSource("IntTravelTitle", intTravelCosts?.ItemWrapName ?? "国际旅费\r\n(公务舱和经济舱分别罗列)");
  21304. if (intTravelCosts != null && intTravelCosts.Infos.Any())
  21305. {
  21306. var cabClassFilter = new string[] { "经济舱", "公务舱", "头等舱" };
  21307. var label = new StringBuilder();
  21308. var infos = intTravelCosts.Infos.Where(x => cabClassFilter.Contains(x.FeeName)).ToArray();
  21309. if (infos.Any())
  21310. {
  21311. label.Append(infos.Sum(x => x.PplNum));
  21312. label.Append("人全程机票:");
  21313. label.Append(infos.Sum(x => x.TotalAmt).TruncDecimals(2));
  21314. label.AppendLine("元");
  21315. }
  21316. foreach (var item in intTravelCosts.Infos)
  21317. {
  21318. label.Append(item.FeeName);
  21319. label.Append(":");
  21320. label.Append(item.UnitPrice.TruncDecimals(2));
  21321. label.Append("元/人*");
  21322. label.Append(item.PplNum);
  21323. label.AppendLine("人");
  21324. }
  21325. if (label.HasValue())
  21326. {
  21327. label.Append("\r\n以上小计:");
  21328. label.Append(intTravelCosts.TotalAmt.TruncDecimals(2));
  21329. label.Append("元");
  21330. }
  21331. designer.SetDataSource("IntTravelLabel", label.ToString());
  21332. }
  21333. #endregion
  21334. #region 住宿费
  21335. designer.SetDataSource("AccomTitle", accomCosts?.ItemWrapName ?? "住宿费\r\n(请备注明酒店星级)");
  21336. if (accomCosts != null && accomCosts.Infos.Any())
  21337. {
  21338. string currencyName = string.Empty,
  21339. countryName = string.Empty;
  21340. decimal rate = 1.0000M;
  21341. var label = new StringBuilder();
  21342. label.AppendLine("全程五星酒店,每人1间房");
  21343. foreach (var item in accomCosts.Infos)
  21344. {
  21345. //乌兹别克斯坦: 塔什干:120美金/间/晚*2*6人
  21346. string name = string.Empty, thisCountryName = string.Empty;
  21347. if (item.FeeName.Contains('-'))
  21348. {
  21349. var feeName = item.FeeName.Split('-');
  21350. thisCountryName = feeName[0];
  21351. if (!thisCountryName.Equals(countryName)) countryName = feeName[0];
  21352. name = feeName[1];
  21353. }
  21354. else name = item.FeeName;
  21355. string thisFeeName = string.Empty;
  21356. if (!thisCountryName.Equals(countryName)) thisFeeName = $"{countryName}:\r\n{name}:";
  21357. else thisFeeName = $"\r\n{name}:";
  21358. var rateInfo = rates.FirstOrDefault(x => item.Currency.Equals(x.CurrencyCode));
  21359. currencyName = rateInfo?.CurrencyName ?? "UnKnow";
  21360. rate = rateInfo?.Rate ?? 1.0000M;
  21361. string subLabel = string.Format("{0}{1}{2}/间/晚*{3}*{4}人", thisFeeName, item.UnitPrice.TruncDecimals(2), currencyName, item.Quantity.ToString("#0"), item.PplNum.ToString("#0"));
  21362. label.AppendLine(subLabel);
  21363. }
  21364. if (label.HasValue())
  21365. {
  21366. //以上小计:52440元(美金汇率:7.5 )
  21367. string subLabel = string.Format("\r\n以上小计:{0}元({1}汇率:{2})", accomCosts.TotalAmt.TruncDecimals(2), currencyName, rate.TruncDecimals(4));
  21368. label.AppendLine(subLabel);
  21369. }
  21370. designer.SetDataSource("AccomLabel", label.ToString());
  21371. }
  21372. #endregion
  21373. #region 餐饮费
  21374. designer.SetDataSource("MealTitle", mealCosts?.ItemWrapName ?? "餐饮费");
  21375. if (mealCosts != null && mealCosts.Infos.Any())
  21376. {
  21377. string currencyName = string.Empty;
  21378. decimal rate = 1.0000M;
  21379. var label = new StringBuilder();
  21380. label.Append("全程酒店含早,\r\n若因航班过早,\r\n酒店准备路早。\r\n\r\n");
  21381. foreach (var item in mealCosts.Infos)
  21382. {
  21383. string name = string.Empty;
  21384. if (item.FeeName.Contains('-'))
  21385. {
  21386. var feeName = item.FeeName.Split('-');
  21387. name = $"\r\n{feeName[0]}:\r\n{feeName[1]}:";
  21388. }
  21389. else name = $"\r\n{item.FeeName}:";
  21390. var rateInfo = rates.FirstOrDefault(x => item.Currency.Equals(x.CurrencyCode));
  21391. currencyName = rateInfo?.CurrencyName ?? "UnKnow";
  21392. rate = rateInfo?.Rate ?? 1.0000M;
  21393. label.Append(name);
  21394. label.Append(item.UnitPrice.TruncDecimals(2));
  21395. label.Append(currencyName);
  21396. label.Append("/天*");
  21397. label.Append(item.Quantity.ToString("#0"));
  21398. label.Append('*');
  21399. label.Append(item.PplNum);
  21400. label.Append("人\r\n");
  21401. }
  21402. if (label.HasValue())
  21403. {
  21404. label.Append("\r\n以上小计:");
  21405. label.Append(accomCosts.TotalAmt.TruncDecimals(2));
  21406. label.Append("元\r\n(");
  21407. label.Append("汇率:");
  21408. label.Append(rate.TruncDecimals(4));
  21409. label.Append(')');
  21410. }
  21411. designer.SetDataSource("MealLabel", label.ToString());
  21412. }
  21413. #endregion
  21414. #region 车辆安排
  21415. designer.SetDataSource("VehArrangeTitle", vehArranges?.ItemWrapName ?? "车辆安排\r\n(司兼导分开的情况下,车辆品牌、座位及费用)");
  21416. if (vehArranges != null && vehArranges.Infos.Any())
  21417. {
  21418. string currencyName = string.Empty;
  21419. //decimal rate = 1.0000M;
  21420. var label = new StringBuilder();
  21421. foreach (var item in vehArranges.Infos)
  21422. {
  21423. label.AppendLine();
  21424. label.AppendLine();
  21425. label.Append(item.FeeName);
  21426. label.Append($"\r\n\r\n费用:{item.TotalAmt.TruncDecimals(2)}元");
  21427. }
  21428. designer.SetDataSource("VehArrangeLabel", label.ToString());
  21429. }
  21430. #endregion
  21431. #region 邀请函发放对象
  21432. designer.SetDataSource("InviteToTitle", inviteTo?.ItemWrapName ?? "邀请函发放对象");
  21433. designer.SetDataSource("InviteToContent", "");
  21434. #endregion
  21435. #region 邀请函费
  21436. designer.SetDataSource("InviteCostTitle", inviteCosts?.ItemWrapName ?? "邀请函费用");
  21437. var is_label = new StringBuilder();
  21438. if (inviteCosts != null && inviteCosts.Infos.Any())
  21439. {
  21440. string currencyName = string.Empty;
  21441. decimal rate = 1.0000M;
  21442. foreach (var item in inviteCosts.Infos)
  21443. {
  21444. //乌兹别克斯坦:2000美金
  21445. currencyName = item.Currency;
  21446. rate = rates.FirstOrDefault(x => currencyName.Equals(x.CurrencyCode))?.Rate ?? 1.0000M;
  21447. string label = string.Format("{0}:{1}{2}", item.FeeName, item.UnitPrice.TruncDecimals(2), currencyName);
  21448. is_label.AppendLine(label);
  21449. }
  21450. if (is_label.HasValue())
  21451. {
  21452. //以上小计:28500元(美金汇率:7.5)
  21453. string label = string.Format("以上小计:{0}{1}({2}汇率:{3})", inviteCosts.TotalAmt.TruncDecimals(2), "元", currencyName, rate.TruncDecimals(4));
  21454. is_label.AppendLine(label);
  21455. }
  21456. }
  21457. designer.SetDataSource("InviteCostContent", is_label.ToString());
  21458. #endregion
  21459. #region 邀请函发放时间
  21460. designer.SetDataSource("InviteToTimeTitle", inviteTime?.ItemWrapName ?? "邀请函发放时间");
  21461. designer.SetDataSource("InviteToTimeContent", "拿到团员名单10-15工作日");
  21462. #endregion
  21463. #region 公务活动(含翻译)
  21464. designer.SetDataSource("OfficialActsTitle", officialActs?.ItemWrapName ?? "公务活动(含翻译)");
  21465. var oa_label = new StringBuilder();
  21466. if (officialActs != null && officialActs.Infos.Any())
  21467. {
  21468. string currencyName = string.Empty;
  21469. decimal rate = 1.0000M;
  21470. string label_title = string.Empty, label_content = "超出报价部分需额付费:\r\n";
  21471. foreach (var item in officialActs.Infos)
  21472. {
  21473. //乌兹别克斯坦:1000美金/场
  21474. currencyName = item.Currency;
  21475. rate = rates.FirstOrDefault(x => currencyName.Equals(x.CurrencyCode))?.Rate ?? 1.0000M;
  21476. string label_remark = string.Empty;
  21477. if (!string.IsNullOrEmpty(item.Remark)) label_remark = $"({item.Remark})";
  21478. label_content += string.Format("{0}:{1}{2}/场{3}\r\n", item.FeeName, item.UnitPrice.TruncDecimals(2), currencyName, label_remark);
  21479. }
  21480. label_content += "*总费用中未含超出公务活动价格";
  21481. //8场公务活动(以上小计:60000元)
  21482. var quantity = officialActs.Infos.Sum(x => x.Quantity);
  21483. label_title = string.Format("{0}场公务活动(以上小计:{1}元)", quantity, officialActs.TotalAmt.TruncDecimals(2));
  21484. oa_label.AppendLine(label_title);
  21485. oa_label.AppendLine(label_content);
  21486. }
  21487. designer.SetDataSource("OfficialActsContent", oa_label.ToString());
  21488. #endregion
  21489. #region 签证+保险
  21490. designer.SetDataSource("VisaInsTitle", visaIns?.ItemWrapName ?? "签证+保险\r\n(单位:元)");
  21491. var vi_label = new StringBuilder();
  21492. if (visaIns != null && visaIns.Infos.Any())
  21493. {
  21494. foreach (var item in visaIns.Infos)
  21495. {
  21496. //签证:500元/人
  21497. string label = string.Format("{0}:{1}元/人*{2}人", item.FeeName, item.UnitPrice.TruncDecimals(2), item.PplNum);
  21498. vi_label.AppendLine(label);
  21499. }
  21500. if (vi_label.HasValue())
  21501. {
  21502. //以上小计:6000元
  21503. string label = string.Format("以上小计:{0}元", visaIns.TotalAmt.TruncDecimals(2));
  21504. vi_label.AppendLine(label);
  21505. }
  21506. }
  21507. designer.SetDataSource("VisaInsContent", vi_label.ToString());
  21508. #endregion
  21509. #region 服务费
  21510. designer.SetDataSource("ServiceCostTitle", serviceCosts?.ItemWrapName ?? "服务费");
  21511. designer.SetDataSource("ServiceCostContent", serviceCosts?.TotalAmt.TruncDecimals(2) ?? 0.00M);
  21512. #endregion
  21513. #region 公杂费
  21514. designer.SetDataSource("PubMiscsTitle", pubMiscs?.ItemWrapName ?? "公杂费\r\n(发给团组成员)");
  21515. var pm_label = new StringBuilder();
  21516. if (pubMiscs != null && pubMiscs.Infos.Any())
  21517. {
  21518. string currencyName = string.Empty,
  21519. countryName = string.Empty;
  21520. decimal rate = 1.0000M;
  21521. foreach (var item in pubMiscs.Infos)
  21522. {
  21523. //乌兹别克斯坦:塔什干:32美金 / 天 * 3 * 6人
  21524. string name = string.Empty, thisCountryName = string.Empty;
  21525. if (item.FeeName.Contains('-'))
  21526. {
  21527. var feeName = item.FeeName.Split('-');
  21528. thisCountryName = feeName[0];
  21529. if (!thisCountryName.Equals(countryName)) countryName = feeName[0];
  21530. name = feeName[1];
  21531. }
  21532. else name = item.FeeName;
  21533. string thisFeeName = string.Empty;
  21534. if (!thisCountryName.Equals(countryName)) thisFeeName = $"{countryName}:\r\n{name}:";
  21535. else thisFeeName = $"\r\n{name}:";
  21536. var rateInfo = rates.FirstOrDefault(x => item.Currency.Equals(x.CurrencyCode));
  21537. currencyName = rateInfo?.CurrencyName ?? "UnKnow";
  21538. rate = rateInfo?.Rate ?? 1.0000M;
  21539. string label = string.Format("{0}:{1}{2}/天*{3}*{4}人", thisFeeName, item.UnitPrice.TruncDecimals(2), currencyName, item.Quantity, item.PplNum);
  21540. pm_label.AppendLine(label);
  21541. }
  21542. if (pm_label.HasValue())
  21543. {
  21544. //以上小计:13497.6元\r\n(美金汇率:7.5 )\r\n部分发放成员
  21545. pm_label.AppendLine(string.Format("以上小计:{0}元", pubMiscs.TotalAmt.TruncDecimals(2)));
  21546. pm_label.AppendLine(string.Format("({0}汇率:{1})", currencyName, rate.TruncDecimals(4)));
  21547. pm_label.AppendLine(string.Format("部分发放成员"));
  21548. }
  21549. }
  21550. designer.SetDataSource("PubMiscsContent", pm_label.ToString());
  21551. #endregion
  21552. #region 税费
  21553. designer.SetDataSource("TaxCostTitle", taxCosts?.ItemWrapName ?? "税费");
  21554. designer.SetDataSource("TaxCostContent", taxCosts?.TotalAmt.TruncDecimals(2) ?? 0.00M);
  21555. #endregion
  21556. #region 合计(单位:元)
  21557. designer.SetDataSource("CostTotalTitle", "合计\r\n(单位:元)");
  21558. designer.SetDataSource("CostTotalContent", info.FeeItems.Sum(x => x.TotalAmt).TruncDecimals(2));
  21559. #endregion
  21560. #region 汇率 Remark
  21561. var rate_label = new StringBuilder();
  21562. var rateGroups = rates.GroupBy(x => x.CurrencyName);
  21563. foreach (var item in rateGroups)
  21564. {
  21565. //美元汇率按\r\n1:7.5
  21566. string label = string.Format("{0}汇率按\r\n1:{1}", item.Key, item.FirstOrDefault()?.Rate.TruncDecimals(4) ?? 0.0000M);
  21567. rate_label.AppendLine(label);
  21568. }
  21569. designer.SetDataSource("RateLabel", rate_label.ToString());
  21570. #endregion
  21571. designer.Process();
  21572. //文件名
  21573. string fileName = $"{info.Name}{DateTime.Now:yyyyMMddHHmmss}.xls";
  21574. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + "EnterExitCostQuote/" + fileName);
  21575. string url = AppSettingsHelper.Get("ExcelBaseUrl") + "Office/Excel/EnterExitCostQuote/" + fileName;
  21576. return Ok(JsonView(true, "成功", url));
  21577. }
  21578. #endregion
  21579. #region 签证费用录入
  21580. /// <summary>
  21581. /// 根据diid查询签证费用列表
  21582. /// </summary>
  21583. /// <param name="dto"></param>
  21584. /// <returns></returns>
  21585. [HttpPost]
  21586. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21587. public async Task<IActionResult> QueryVisaByDiId(VisaPriceDto dto)
  21588. {
  21589. Result groupData = await _visaPriceRep.PostVisaByDiId(dto);
  21590. if (groupData.Code != 0)
  21591. {
  21592. return Ok(JsonView(false, groupData.Msg));
  21593. }
  21594. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  21595. }
  21596. /// <summary>
  21597. /// 根据签证费用Id查询单条数据及c表数据
  21598. /// </summary>
  21599. /// <param name="dto"></param>
  21600. /// <returns></returns>
  21601. [HttpPost]
  21602. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21603. public async Task<IActionResult> QueryVisaById(PostVisaByIdDto dto)
  21604. {
  21605. Result groupData = await _visaPriceRep.PostVisaById(dto);
  21606. if (groupData.Code != 0)
  21607. {
  21608. return Ok(JsonView(false, groupData.Msg));
  21609. }
  21610. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  21611. }
  21612. /// <summary>
  21613. /// 签证费用删除
  21614. /// </summary>
  21615. /// <param name="dto"></param>
  21616. /// <returns></returns>
  21617. [HttpPost]
  21618. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21619. public async Task<IActionResult> DelVisaPrice(DelBaseDto dto)
  21620. {
  21621. _sqlSugar.BeginTran();
  21622. //验证
  21623. (bool vaild, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 80);
  21624. if (!vaild)
  21625. {
  21626. _sqlSugar.RollbackTran();
  21627. return Ok(JsonView(false, msg));
  21628. }
  21629. var res = await _visaPriceRep.SoftDeleteByIdAsync<Grp_VisaInfo>(dto.Id.ToString(), dto.DeleteUserId);
  21630. if (!res)
  21631. {
  21632. _sqlSugar.RollbackTran();
  21633. return Ok(JsonView(false, "删除失败"));
  21634. }
  21635. var resSub = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  21636. .Where(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 80)
  21637. .SetColumns(a => new Grp_CreditCardPayment()
  21638. {
  21639. IsDel = 1,
  21640. DeleteUserId = dto.DeleteUserId,
  21641. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  21642. })
  21643. .ExecuteCommand();
  21644. if (resSub < 1)
  21645. {
  21646. _sqlSugar.RollbackTran();
  21647. return Ok(JsonView(false, "删除失败"));
  21648. }
  21649. _sqlSugar.CommitTran();
  21650. return Ok(JsonView(true, "删除成功!"));
  21651. }
  21652. /// <summary>
  21653. /// 签证费用录入下拉框初始化
  21654. /// </summary>
  21655. /// <returns></returns>
  21656. [HttpPost]
  21657. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21658. public async Task<IActionResult> VisaPriceAddSelect()
  21659. {
  21660. //支付方式
  21661. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  21662. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  21663. //币种
  21664. List<Sys_SetData> CurrencyList = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 66 && a.IsDel == 0).ToList();
  21665. List<SetDataInfoView> _CurrencyList = _mapper.Map<List<SetDataInfoView>>(CurrencyList);
  21666. //乘客类型
  21667. List<Sys_SetData> PassengerType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 69 && a.IsDel == 0).ToList();
  21668. List<SetDataInfoView> _PassengerType = _mapper.Map<List<SetDataInfoView>>(PassengerType);
  21669. //卡类型
  21670. List<Sys_SetData> BankCard = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  21671. List<SetDataInfoView> _BankCard = _mapper.Map<List<SetDataInfoView>>(BankCard);
  21672. //代办费类型
  21673. var agencyFeeTypeData = new List<dynamic>() {
  21674. new { id = 0 , Text = "未选择" },
  21675. new { id = 1 , Text = "小公务" },
  21676. new { id = 2 , Text = "大公务" },
  21677. };
  21678. //签证费用标准国家Data
  21679. var visaSql = string.Format(@"select
  21680. id,
  21681. case
  21682. when FeeType = 0 then Country+'(因公)'
  21683. when FeeType = 1 then Country+'(因私)'
  21684. else Country+'(未设置)'
  21685. end as 'country'
  21686. from Res_VisaFeeStandard where isdel = 0");
  21687. var visaCountryFeeData = _sqlSugar.SqlQueryable<dynamic>(visaSql).ToList();
  21688. var data = new
  21689. {
  21690. Payment = _Payment,
  21691. CurrencyList = _CurrencyList,
  21692. PassengerType = _PassengerType,
  21693. BankCard = _BankCard,
  21694. AgencyFeeType = agencyFeeTypeData,
  21695. CountryFeeData = visaCountryFeeData
  21696. };
  21697. return Ok(JsonView(true, "查询成功!", data));
  21698. }
  21699. /// <summary>
  21700. /// 签证费用录入操作(Status:1.新增,2.修改)
  21701. /// </summary>
  21702. /// <param name="dto"></param>
  21703. /// <returns></returns>
  21704. [HttpPost]
  21705. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21706. public async Task<IActionResult> OpVisaPrice(OpVisaPriceDto dto)
  21707. {
  21708. //修改验证
  21709. if (dto.Status == 2)
  21710. {
  21711. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 80);
  21712. if (!valid) return Ok(JsonView(false, msg));
  21713. }
  21714. Result groupData = await _visaPriceRep.OpVisaPrice(dto);
  21715. if (groupData.Code != 0)
  21716. {
  21717. return Ok(JsonView(false, groupData.Msg));
  21718. }
  21719. #region 应用推送
  21720. try
  21721. {
  21722. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  21723. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  21724. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  21725. //2024-10-21 新增LZ UID
  21726. var userIds = new List<int>() { 21 };
  21727. string title = $"系统通知";
  21728. string content = "";
  21729. var diId = dto.DiId;
  21730. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  21731. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  21732. if (dto.Status == 1) content = $"[新增-签证费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate):#0.00} CNY;";
  21733. else if (dto.Status == 2) content = $"[更新-签证费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate):#0.00} CNY;";
  21734. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  21735. var h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "80" };
  21736. await APNsTools.iOS_PushNotifications1("051", $"签证费用审核", "", content, true, "ExpenseAuditWebView", h5);
  21737. }
  21738. catch (Exception ex)
  21739. {
  21740. }
  21741. #endregion
  21742. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  21743. }
  21744. #endregion
  21745. #region 签证提成录入
  21746. /// <summary>
  21747. /// 签证提成录入
  21748. /// 基础数据
  21749. /// </summary>
  21750. /// <returns></returns>
  21751. [HttpGet]
  21752. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21753. public async Task<IActionResult> VisaCommissionInit()
  21754. {
  21755. return Ok(await _visaCommissionRep.Init());
  21756. }
  21757. /// <summary>
  21758. /// 签证提成录入
  21759. /// Item
  21760. /// </summary>
  21761. /// <param name="_dto"></param>
  21762. /// <returns></returns>
  21763. [HttpPost]
  21764. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21765. public async Task<IActionResult> VisaCommissionItem(VisaCommissionItemDto _dto)
  21766. {
  21767. var validator = new VisaCommissionItemDtoValidator();
  21768. var validatorRes = await validator.ValidateAsync(_dto);
  21769. if (!validatorRes.IsValid)
  21770. {
  21771. var sb = new StringBuilder();
  21772. foreach (var item in validatorRes.Errors)
  21773. {
  21774. sb.AppendLine(item.ErrorMessage);
  21775. }
  21776. return Ok(JsonView(false, sb.ToString()));
  21777. }
  21778. return Ok(await _visaCommissionRep.Item(_dto));
  21779. }
  21780. /// <summary>
  21781. /// 签证提成录入
  21782. /// Save
  21783. /// </summary>
  21784. /// <param name="_dto"></param>
  21785. /// <returns></returns>
  21786. [HttpPost]
  21787. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21788. public async Task<IActionResult> VisaCommissionSave(VisaCommissionSaveDto _dto)
  21789. {
  21790. //参数验证
  21791. if (_dto.Items.Length < 1) return Ok(JsonView(false, "请输入有效的请求!"));
  21792. foreach (var item in _dto.Items)
  21793. {
  21794. if (item.CurrUserId < 1) return Ok(JsonView(false, "请输入有效的CurrUserId!"));
  21795. if (item.DiId < 1) return Ok(JsonView(false, "请输入有效的DiId!"));
  21796. if (string.IsNullOrEmpty(item.Country)) return Ok(JsonView(false, "国家为空!"));
  21797. //if (item.Quantity < 1) return Ok(JsonView(false, "请输入有效的Qauntity!"));
  21798. }
  21799. return Ok(await _visaCommissionRep.Save(_dto));
  21800. }
  21801. /// <summary>
  21802. /// 签证提成录入
  21803. /// Create
  21804. /// </summary>
  21805. /// <param name="_dto"></param>
  21806. /// <returns></returns>
  21807. [HttpPost]
  21808. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21809. public async Task<IActionResult> VisaCommissionCreate(VisaCommissionCreateDto _dto)
  21810. {
  21811. var validator = new VisaCommissionCreateDtoValidator();
  21812. var validatorRes = await validator.ValidateAsync(_dto);
  21813. if (!validatorRes.IsValid)
  21814. {
  21815. var sb = new StringBuilder();
  21816. foreach (var item in validatorRes.Errors)
  21817. {
  21818. sb.AppendLine(item.ErrorMessage);
  21819. }
  21820. return Ok(JsonView(false, sb.ToString()));
  21821. }
  21822. return Ok(await _visaCommissionRep.Create(_dto));
  21823. }
  21824. /// <summary>
  21825. /// 签证提成录入
  21826. /// Put(编辑)
  21827. /// </summary>
  21828. /// <param name="id"></param>
  21829. /// <param name="_dto"></param>
  21830. /// <returns></returns>
  21831. [HttpPut]
  21832. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21833. public async Task<IActionResult> VisaCommissionEdit(int id, VisaCommissionCreateDto _dto)
  21834. {
  21835. if (id < 1) return Ok(JsonView(false, "请输入正确的id参数!"));
  21836. var validator = new VisaCommissionCreateDtoValidator();
  21837. var validatorRes = await validator.ValidateAsync(_dto);
  21838. if (!validatorRes.IsValid)
  21839. {
  21840. var sb = new StringBuilder();
  21841. foreach (var item in validatorRes.Errors)
  21842. {
  21843. sb.AppendLine(item.ErrorMessage);
  21844. }
  21845. return Ok(JsonView(false, sb.ToString()));
  21846. }
  21847. return Ok(await _visaCommissionRep.Edit(id, _dto));
  21848. }
  21849. /// <summary>
  21850. /// 签证提成录入
  21851. /// Del
  21852. /// </summary>
  21853. /// <param name="id"></param>
  21854. /// <param name="currUserId"></param>
  21855. /// <returns></returns>
  21856. [HttpPost]
  21857. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21858. public async Task<IActionResult> VisaCommissionDel(int id, int currUserId)
  21859. {
  21860. if (id < 1) return Ok(JsonView(false, "请输入正确的id参数!"));
  21861. if (currUserId < 1) return Ok(JsonView(false, "请输入正确的currUserId参数!"));
  21862. return Ok(await _visaCommissionRep.Del(id, currUserId));
  21863. }
  21864. #endregion
  21865. #region op费用录入
  21866. /// <summary>
  21867. /// 根据diid查询op费用列表
  21868. /// </summary>
  21869. /// <param name="dto"></param>
  21870. /// <returns></returns>
  21871. [HttpPost]
  21872. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21873. public async Task<IActionResult> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  21874. {
  21875. Result groupData = await _carTouristGuideGroundRep.QueryCarTouristGuideGroundByDiId(dto);
  21876. if (groupData.Code != 0)
  21877. {
  21878. return Ok(JsonView(false, groupData.Msg));
  21879. }
  21880. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  21881. }
  21882. /// <summary>
  21883. /// 根据op费用Id查询单条数据及c表数据
  21884. /// </summary>
  21885. /// <param name="dto"></param>
  21886. /// <returns></returns>
  21887. [HttpPost]
  21888. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21889. public async Task<IActionResult> QueryCarTouristGuideGroundById(CarTouristGuideGroundIdDto dto)
  21890. {
  21891. try
  21892. {
  21893. Grp_CarTouristGuideGroundReservations _groupData = await _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().FirstAsync(a => a.Id == dto.Id && a.IsDel == 0);
  21894. Grp_CreditCardPayment _creditCardPayment = await _sqlSugar.Queryable<Grp_CreditCardPayment>().FirstAsync(a => a.CId == dto.Id && a.CTable == 79 && a.IsDel == 0);
  21895. var data = new
  21896. {
  21897. CarTouristGuideGround = _groupData,
  21898. CreditCardPayment = _creditCardPayment
  21899. };
  21900. return Ok(JsonView(true, "查询成功!", data));
  21901. }
  21902. catch (Exception ex)
  21903. {
  21904. return Ok(JsonView(false, "程序错误!"));
  21905. }
  21906. }
  21907. /// <summary>
  21908. /// op费用删除
  21909. /// </summary>
  21910. /// <param name="dto"></param>
  21911. /// <returns></returns>
  21912. [HttpPost]
  21913. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21914. public async Task<IActionResult> DelCarTouristGuideGround(DelBaseDto dto)
  21915. {
  21916. try
  21917. {
  21918. _sqlSugar.BeginTran();
  21919. //验证
  21920. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 79);
  21921. if (!valid)
  21922. {
  21923. _sqlSugar.RollbackTran();
  21924. return Ok(JsonView(false, msg));
  21925. }
  21926. var res = await _carTouristGuideGroundRep.SoftDeleteByIdAsync<Grp_CarTouristGuideGroundReservations>(dto.Id.ToString(), dto.DeleteUserId);
  21927. if (!res)
  21928. {
  21929. _sqlSugar.RollbackTran();
  21930. return Ok(JsonView(false, "删除失败"));
  21931. }
  21932. var result = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.CTGGRId == dto.Id && a.IsDel == 0).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent()
  21933. {
  21934. IsDel = 1,
  21935. DeleteUserId = dto.DeleteUserId,
  21936. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  21937. }).ExecuteCommandAsync();
  21938. var resultC = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79).SetColumns(a => new Grp_CreditCardPayment()
  21939. {
  21940. IsDel = 1,
  21941. DeleteUserId = dto.DeleteUserId,
  21942. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  21943. }).ExecuteCommandAsync();
  21944. #region 删除超支相关数据
  21945. //删除导入的超支数据
  21946. var ids = _sqlSugar.Queryable<Fin_LocalGuideRelevancyOverspend>().Where(x => x.LocalGuideId == dto.Id && x.IsDel == 0).Select(x => x.OverspendId).ToList();
  21947. var count = _sqlSugar.Updateable<Fin_GroupExtraCost>().Where(x => ids.Contains(x.Id) && x.IsDel == 0).SetColumns(x => new Fin_GroupExtraCost
  21948. {
  21949. IsDel = 1,
  21950. DeleteUserId = dto.DeleteUserId,
  21951. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  21952. }).ExecuteCommand();
  21953. count = _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(x => x.CTable == 1015 && x.IsDel == 0 && ids.Contains(x.CId)).SetColumns(x => new Grp_CreditCardPayment
  21954. {
  21955. IsDel = 1,
  21956. DeleteUserId = dto.DeleteUserId,
  21957. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  21958. }).ExecuteCommand();
  21959. count = _sqlSugar.Updateable<Fin_LocalGuideRelevancyOverspend>().Where(x => x.IsDel == 0 && x.LocalGuideId == dto.Id).SetColumns(x => new Fin_LocalGuideRelevancyOverspend
  21960. {
  21961. IsDel = 1,
  21962. DeleteUserId = dto.DeleteUserId,
  21963. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  21964. }).ExecuteCommand();
  21965. #endregion
  21966. _sqlSugar.CommitTran();
  21967. return Ok(JsonView(true, "删除成功!"));
  21968. }
  21969. catch (Exception ex)
  21970. {
  21971. _sqlSugar.RollbackTran();
  21972. return Ok(JsonView(false, "程序错误!" + ex.Message));
  21973. }
  21974. }
  21975. /// <summary>
  21976. /// op费用录入操作(Status:1.新增,2.修改)
  21977. /// </summary>
  21978. /// <param name="dto"></param>
  21979. /// <returns></returns>
  21980. [HttpPost]
  21981. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21982. public async Task<IActionResult> OpCarTouristGuideGround(OpCarTouristGuideGroundDto dto)
  21983. {
  21984. Result groupData = await _carTouristGuideGroundRep.OpCarTouristGuideGround(dto);
  21985. if (groupData.Code != 0)
  21986. {
  21987. return Ok(JsonView(false, groupData.Msg));
  21988. }
  21989. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  21990. }
  21991. /// <summary>
  21992. /// 填写费用详细页面初始化绑定
  21993. /// </summary>
  21994. /// <param name="dto"></param>
  21995. /// <returns></returns>
  21996. [HttpPost]
  21997. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  21998. public IActionResult CarTouristGuideGroundContentInitialize(CarTouristGuideGroundContentDto dto)
  21999. {
  22000. try
  22001. {
  22002. Result groupData = _carTouristGuideGroundRep.CarTouristGuideGroundContent(dto);
  22003. if (groupData.Code != 0)
  22004. {
  22005. return Ok(JsonView(false, groupData.Msg));
  22006. }
  22007. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  22008. }
  22009. catch (Exception ex)
  22010. {
  22011. return Ok(JsonView(false, ex.Message));
  22012. }
  22013. }
  22014. /// <summary>
  22015. /// 根据op费用Id查询详细数据
  22016. /// </summary>
  22017. /// <param name="dto"></param>
  22018. /// <returns></returns>
  22019. [HttpPost]
  22020. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22021. public IActionResult OpCarTouristGuideGroundContentById(CarTouristGuideGroundIdDto dto)
  22022. {
  22023. try
  22024. {
  22025. Result groupData = _carTouristGuideGroundRep.OpCarTouristGuideGroundContentById(dto);
  22026. if (groupData.Code != 0)
  22027. {
  22028. return Ok(JsonView(false, groupData.Msg));
  22029. }
  22030. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  22031. }
  22032. catch (Exception ex)
  22033. {
  22034. return Ok(JsonView(false, ex.Message));
  22035. }
  22036. }
  22037. /// <summary>
  22038. /// OP费用录入填写详情
  22039. /// </summary>
  22040. /// <param name="dto"></param>
  22041. /// <returns></returns>
  22042. [HttpPost]
  22043. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22044. public async Task<IActionResult> OpCarTouristGuideGroundContent(OpCarTouristGuideGroundContentDto dto)
  22045. {
  22046. try
  22047. {
  22048. #region 参数校验
  22049. if (dto.Currency <= 0) return Ok(JsonView(false, "币种错误!"));
  22050. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.DiId && x.IsDel == 0);
  22051. if (di == null) return Ok(JsonView(false, "团组错误!"));
  22052. #endregion
  22053. //验证
  22054. // (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.CTGGRId, 79);
  22055. // if (!valid)
  22056. // {
  22057. // _sqlSugar.RollbackTran();
  22058. // return Ok(JsonView(false, msg));
  22059. // }
  22060. Result groupData = await _carTouristGuideGroundRep.OpCarTouristGuideGroundContent(dto);
  22061. if (groupData.Code != 0)
  22062. {
  22063. return Ok(JsonView(false, groupData.Msg));
  22064. }
  22065. //自动审核
  22066. await _feeAuditRep.FeeAutomaticAudit(2, dto.DiId, dto.CTGGRId);
  22067. #region 尾款自动审核
  22068. var opinfos = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  22069. .First(x => x.IsDel == 0 && x.DiId == dto.DiId && x.Id == dto.CTGGRId);
  22070. if (opinfos.PriceType == 1062)
  22071. {
  22072. var isAuto = false;
  22073. //找对应的首付款
  22074. var firstPrice = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  22075. .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))
  22076. .First(x => x.IsDel == 0 && x.DiId == dto.DiId && x.PriceName == opinfos.PriceName &&
  22077. x.ServiceStartTime == opinfos.ServiceStartTime && x.ServiceEndTime == opinfos.ServiceEndTime && x.Area == opinfos.Area &&
  22078. x.PriceType == 1061 && x.DiId == dto.DiId);
  22079. if (firstPrice != null && !(opinfos.SelectCheck.Contains("超时") || opinfos.SelectCheck.Contains("超支")) && firstPrice.CId == opinfos.CId)
  22080. {
  22081. var cprice = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(x => x.IsDel == 0 && x.CId == firstPrice.Id && x.CTable == 79);
  22082. var balance = firstPrice.ServiceQuotedPrice * (100 - cprice.PayPercentage) / 100;
  22083. //合计中排除城市税
  22084. var cityPrice = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>()
  22085. .Where(x => x.SId == 1452 && x.IsDel == 0 && x.DiId == dto.DiId && x.CTGGRId == dto.CTGGRId)
  22086. .Sum(x => x.Price * x.Count);
  22087. opinfos.ServiceQuotedPrice = opinfos.ServiceQuotedPrice - cityPrice;
  22088. if (balance >= opinfos.ServiceQuotedPrice)
  22089. {
  22090. isAuto = true;
  22091. }
  22092. }
  22093. if (isAuto)
  22094. {
  22095. var execCount = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  22096. .SetColumns(a => new Grp_CreditCardPayment
  22097. {
  22098. IsAuditGM = 3, //自动审核通过
  22099. AuditGMOperate = 4,
  22100. AuditGMDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  22101. })
  22102. .Where(a => a.CId == dto.CTGGRId && a.CTable == 79 && a.DIId == dto.DiId)
  22103. .ExecuteCommand();
  22104. }
  22105. }
  22106. #endregion
  22107. #region 应用推送
  22108. try
  22109. {
  22110. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  22111. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  22112. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  22113. //2024-10-21 新增LZ UID
  22114. var userIds = new List<int>() { 21 };
  22115. string title = $"系统通知";
  22116. var diId = dto.DiId;
  22117. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  22118. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  22119. string content = $"[更新-OP费用录入填写详情({groupInfo?.TeamName ?? "-"})]一项费用:{(((ccpInfo.PayMoney * ccpInfo.DayRate) / 100) * ccpInfo.PayPercentage):#0.00} CNY;";
  22120. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  22121. var h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "79" };
  22122. await APNsTools.iOS_PushNotifications1("051", $"OP费用审核", "", content, true, "ExpenseAuditWebView", h5);
  22123. }
  22124. catch (Exception ex)
  22125. {
  22126. }
  22127. #endregion
  22128. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  22129. }
  22130. catch (Exception ex)
  22131. {
  22132. return Ok(JsonView(false, ex.Message));
  22133. }
  22134. }
  22135. /// <summary>
  22136. /// 获取三公详细所有城市
  22137. /// </summary>
  22138. /// <returns></returns>
  22139. [HttpGet]
  22140. public IActionResult OpCarCityResult()
  22141. {
  22142. var jw = JsonView(false);
  22143. var data = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x => x.IsDel == 0).Select(x => new
  22144. {
  22145. x.Id,
  22146. x.Country,
  22147. x.City,
  22148. }).ToList();
  22149. if (data.Count > 0)
  22150. {
  22151. jw = JsonView(true, "获取成功!", data);
  22152. }
  22153. else
  22154. {
  22155. jw.Msg = "城市数据为空!";
  22156. jw.Data = Array.Empty<string>();
  22157. }
  22158. return Ok(jw);
  22159. }
  22160. /// <summary>
  22161. /// 导出地接费用明细
  22162. /// </summary>
  22163. /// <param name="dto"></param>
  22164. /// <returns></returns>
  22165. [HttpPost]
  22166. public IActionResult ExportLocalGuidePriceDetail(ExportLocalGuidePriceDetailDto dto)
  22167. {
  22168. var jw = JsonView(false);
  22169. if (dto.Diid < 1)
  22170. {
  22171. jw.Msg = "请输入正确的diid!";
  22172. return Ok(jw);
  22173. }
  22174. var group = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  22175. if (group == null)
  22176. {
  22177. jw.Msg = "未找到团组信息!";
  22178. return Ok(jw);
  22179. }
  22180. var localGuideArr = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(x => x.DiId == dto.Diid && x.IsDel == 0).ToList();
  22181. if (localGuideArr.Count == 0)
  22182. {
  22183. jw.Msg = "该团组暂无地接信息!";
  22184. return Ok(jw);
  22185. }
  22186. var localGroup = localGuideArr.GroupBy(x => x.Area).ToList();
  22187. var overspendSoure = new Dictionary<int, int>
  22188. {
  22189. { 91, 982 }, //车
  22190. { 92 , 1059} ,//导游
  22191. { 994 , 1073}, //翻译
  22192. { 988 , 1074 }, //早餐
  22193. { 93 , 1075 }, //午餐
  22194. { 989 , 1076 }, //晚餐
  22195. };
  22196. var Zips = new Dictionary<string, Stream>();
  22197. foreach (var groupArr in localGroup)
  22198. {
  22199. var keyValue = groupArr.Key;
  22200. if (int.TryParse(keyValue, out int cityid))
  22201. {
  22202. var city = _sqlSugar.Queryable<Grp_NationalTravelFee>().First(x => x.Id == cityid && x.IsDel == 0);
  22203. keyValue = city == null ? keyValue : city.Country + "-" + city.City;
  22204. }
  22205. var contentArr = new List<List<Grp_CarTouristGuideGroundReservationsContentExtend>>();
  22206. foreach (var item in groupArr)
  22207. {
  22208. var content = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent, Sys_SetData>((a, b) => a.SId == b.Id
  22209. ).Where((a, b) => a.CTGGRId == item.Id && a.Price != 0M && a.IsDel == 0 && b.IsDel == 0).Select((a, b) =>
  22210. new Grp_CarTouristGuideGroundReservationsContentExtend
  22211. {
  22212. Count = a.Count,
  22213. CreateTime = a.CreateTime,
  22214. CreateUserId = a.CreateUserId,
  22215. CTGGRId = a.CTGGRId,
  22216. Currency = a.Currency,
  22217. DatePrice = a.DatePrice,
  22218. DeleteTime = a.DeleteTime,
  22219. DeleteUserId = a.DeleteUserId,
  22220. DiId = a.DiId,
  22221. Id = a.Id,
  22222. IsDel = a.IsDel,
  22223. Price = a.Price,
  22224. PriceContent = a.PriceContent,
  22225. Remark = a.Remark,
  22226. SId = a.SId,
  22227. SidName = b.Name,
  22228. Units = a.Units,
  22229. }
  22230. ).ToList();
  22231. if (content.Count > 0)
  22232. {
  22233. contentArr.Add(content);
  22234. }
  22235. }
  22236. //open excel
  22237. //set excel
  22238. //save excel
  22239. try
  22240. {
  22241. string filePath = AppSettingsHelper.Get("ExcelBasePath") + "\\Template\\地接费用明细.xlsx";
  22242. IWorkbook workbook;
  22243. if (Path.GetExtension(filePath).ToLower() == ".xls")
  22244. {
  22245. workbook = new NPOI.HSSF.UserModel.HSSFWorkbook(new FileStream(filePath, FileMode.Open, FileAccess.Read));
  22246. }
  22247. else
  22248. {
  22249. workbook = new XSSFWorkbook(new FileStream(filePath, FileMode.Open, FileAccess.Read));
  22250. }
  22251. ISheet sheet = workbook.GetSheetAt(0);
  22252. var rowStartIndex = 2;
  22253. var clounmCount = 10;
  22254. var initStyleRow = sheet.GetRow(2);
  22255. var arr = contentArr.SelectMany(x => x).OrderBy(x => x.SId).ToList();
  22256. //var overspendArrDetail =
  22257. var existsId = new List<CarCompare>();
  22258. var lastElem = arr.Last();
  22259. var thisSid = -1;
  22260. var curr = arr.Count > 0 ? arr[0].Currency : -1;
  22261. var currObj = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == curr && x.IsDel == 0) ?? new Sys_SetData
  22262. {
  22263. Name = "未知币种!",
  22264. Remark = "未知币种!",
  22265. };
  22266. sheet.GetRow(0).GetCell(1).SetCellValue($"{keyValue}费用明细(货币:{currObj.Remark})");
  22267. Action cloneRowFn = () =>
  22268. {
  22269. rowStartIndex++;
  22270. var cloneRow = sheet.CreateRow(rowStartIndex);
  22271. // 复制样式
  22272. for (int i = initStyleRow.FirstCellNum; i < initStyleRow.LastCellNum; i++)
  22273. {
  22274. ICell sourceCell = initStyleRow.GetCell(i);
  22275. ICell targetCell = cloneRow.GetCell(i) ?? cloneRow.CreateCell(i);
  22276. // 确保单元格存在样式
  22277. if (sourceCell.CellStyle != null)
  22278. {
  22279. targetCell.CellStyle = sourceCell.CellStyle;
  22280. }
  22281. }
  22282. };
  22283. var mergeRow = () =>
  22284. {
  22285. for (int i = 2; i < sheet.LastRowNum; i++)
  22286. {
  22287. var row = sheet.GetRow(i);
  22288. var cellFirst = row.GetCell(0);
  22289. var thisIndex = i + 1;
  22290. while (thisIndex < sheet.LastRowNum)
  22291. {
  22292. var nextRow = sheet.GetRow(thisIndex);
  22293. var nextCellFirst = nextRow.GetCell(0);
  22294. if (cellFirst != null && nextCellFirst != null && cellFirst.ToString().Trim() == nextCellFirst.ToString().Trim())
  22295. {
  22296. thisIndex++;
  22297. }
  22298. else
  22299. {
  22300. break;
  22301. }
  22302. }
  22303. thisIndex--;
  22304. if (thisIndex != i)
  22305. {
  22306. //合并row
  22307. var cellRangeAddress = new CellRangeAddress(
  22308. i, // 起始行索引(0-based)
  22309. thisIndex, // 结束行索引(0-based)
  22310. 0, // 起始列索引(0-based)
  22311. 0 // 结束列索引(0-based)
  22312. );
  22313. sheet.AddMergedRegion(cellRangeAddress);
  22314. i = thisIndex;
  22315. }
  22316. }
  22317. };
  22318. var chaoshiNumber = 0;
  22319. var totalNumber = 0.00M;
  22320. string lastStr = "";
  22321. var queryCarArrByCityAndDiid = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations, Grp_CreditCardPayment>((x, b) => x.Id == b.CId && b.IsDel == 0 && b.CTable == 79)
  22322. .Where(x => x.DiId == dto.Diid && x.Area == groupArr.Key).Select((x, b) => new
  22323. {
  22324. b.IsAuditGM,
  22325. x.Id,
  22326. x.Area,
  22327. b.PayPercentage,
  22328. b.PayMoney,
  22329. }).ToList();
  22330. string yesPayment = "", noPayment = "";
  22331. foreach (var item in queryCarArrByCityAndDiid)
  22332. {
  22333. if (item.IsAuditGM == 1)
  22334. {
  22335. yesPayment += $"已支付团款({(int)item.PayPercentage}%):{item.PayMoney} {currObj.Remark}(如有需要,请在此处填写明细)\r\n";
  22336. }
  22337. else
  22338. {
  22339. noPayment += $"剩余团款:{item.PayMoney}{currObj.Remark}(如有需要,请在此处填写明细)\r\n";
  22340. }
  22341. }
  22342. lastStr = yesPayment + noPayment;
  22343. foreach (var item in arr)
  22344. {
  22345. if (existsId.FirstOrDefault(x => x.Sid == item.SId && DateTime.Compare(x.DataPrice, item.DatePrice.ObjToDate()) == 0) == null && !overspendSoure.ContainsValue(item.SId))
  22346. {
  22347. if (thisSid != item.SId)
  22348. {
  22349. if (thisSid == -1)
  22350. {
  22351. thisSid = item.SId;
  22352. }
  22353. else
  22354. {
  22355. //合并小计行
  22356. //创建合并区域的实例
  22357. var cellRangeAddress = new CellRangeAddress(
  22358. rowStartIndex, // 起始行索引(0-based)
  22359. rowStartIndex, // 结束行索引(0-based)
  22360. 0, // 起始列索引(0-based)
  22361. 3 // 结束列索引(0-based)
  22362. );
  22363. sheet.AddMergedRegion(cellRangeAddress);
  22364. var CellStyle = workbook.CreateCellStyle();
  22365. CellStyle.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(0).CellStyle);
  22366. CellStyle.FillForegroundColor = IndexedColors.Yellow.Index; // 选择填充颜色
  22367. CellStyle.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground; // 填充方式
  22368. for (int i = 0; i <= clounmCount; i++)
  22369. {
  22370. if (i > 6)
  22371. {
  22372. var CellStyle1 = workbook.CreateCellStyle();
  22373. CellStyle1.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(0).CellStyle);
  22374. IFont Font = workbook.CreateFont(); // 创建字体
  22375. Font.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(i).CellStyle.GetFont(workbook));
  22376. Font.Color = IndexedColors.Red.Index; // 选择字体颜色
  22377. CellStyle1.SetFont(Font);
  22378. sheet.GetRow(rowStartIndex).GetCell(i).CellStyle = CellStyle1;
  22379. }
  22380. else
  22381. {
  22382. sheet.GetRow(rowStartIndex).GetCell(i).CellStyle = CellStyle;
  22383. }
  22384. }
  22385. sheet.GetRow(rowStartIndex).GetCell(0).SetCellValue("合计:");
  22386. sheet.GetRow(rowStartIndex).GetCell(4).SetCellValue(arr.Where(x => x.SId == thisSid).Sum(x => x.Count * x.Price).ToString("F2"));
  22387. //超时合计
  22388. sheet.GetRow(rowStartIndex).GetCell(7).SetCellValue("超时合计:");
  22389. //超时数
  22390. sheet.GetRow(rowStartIndex).GetCell(8).SetCellValue(chaoshiNumber == 0 ? "" : chaoshiNumber.ToString());
  22391. //超时合计费用
  22392. sheet.GetRow(rowStartIndex).GetCell(9).SetCellValue(totalNumber == 0 ? "" : totalNumber.ToString());
  22393. thisSid = item.SId;
  22394. cloneRowFn();
  22395. chaoshiNumber = 0;
  22396. totalNumber = 0;
  22397. }
  22398. }
  22399. IRow row = sheet.GetRow(rowStartIndex);
  22400. var whereForResult = arr.Where(x => x.SId == item.SId && DateTime.Compare(x.DatePrice.ObjToDate(), item.DatePrice.ObjToDate()) == 0).ToList();
  22401. var isOpenOverspendSoure = overspendSoure.ContainsKey(item.SId);
  22402. List<Grp_CarTouristGuideGroundReservationsContentExtend> overspendWhereForResult = null;
  22403. if (isOpenOverspendSoure)
  22404. {
  22405. overspendWhereForResult = arr.Where(x => x.SId == overspendSoure[item.SId] && DateTime.Compare(x.DatePrice.ObjToDate(), item.DatePrice.ObjToDate()) == 0).ToList();
  22406. chaoshiNumber += overspendWhereForResult.Sum(x => x.Count);
  22407. totalNumber += overspendWhereForResult.Sum(x => x.Count * x.Price);
  22408. }
  22409. for (int i = 0; i <= clounmCount; i++)
  22410. {
  22411. var cell = row.GetCell(i);
  22412. var setCellValue = InIndexOutFunction(i, whereForResult, overspendWhereForResult);
  22413. if (cell == null)
  22414. {
  22415. cell = row.CreateCell(i);
  22416. }
  22417. var fontRed = workbook.CreateCellStyle(); // 创建单元格样式
  22418. fontRed.CloneStyleFrom(cell.CellStyle);
  22419. IFont Font = workbook.CreateFont(); // 创建字体
  22420. Font.CloneStyleFrom(cell.CellStyle.GetFont(workbook));
  22421. Font.Color = IndexedColors.Red.Index; // 选择字体颜色
  22422. fontRed.SetFont(Font);
  22423. byte[] rgb = new byte[3] { 255, 242, 204 };
  22424. var BackgroundColor255_242_204 = workbook.CreateCellStyle();
  22425. BackgroundColor255_242_204.CloneStyleFrom(cell.CellStyle);
  22426. byte[] rgb1 = new byte[3] { 189, 215, 238 };
  22427. if (workbook is XSSFWorkbook)
  22428. {
  22429. BackgroundColor255_242_204.FillForegroundColor = 0;
  22430. ((XSSFColor)BackgroundColor255_242_204.FillForegroundColorColor).SetRgb(rgb);
  22431. BackgroundColor255_242_204.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
  22432. }
  22433. else
  22434. {
  22435. BackgroundColor255_242_204.FillForegroundColor = (((NPOI.HSSF.UserModel.HSSFWorkbook)workbook).GetCustomPalette().FindSimilarColor(rgb[0], rgb[1], rgb[2])).Indexed;
  22436. }
  22437. if (i == 1 || i > 6)
  22438. {
  22439. if (i > 6)
  22440. {
  22441. fontRed.FillForegroundColor = 0;
  22442. ((XSSFColor)fontRed.FillForegroundColorColor).SetRgb(rgb1);
  22443. fontRed.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
  22444. }
  22445. cell.CellStyle = fontRed;
  22446. }
  22447. if (i > 2 && i < 7)
  22448. {
  22449. cell.CellStyle = BackgroundColor255_242_204;
  22450. }
  22451. cell.SetCellValue(setCellValue); //写入单元格
  22452. }
  22453. if (overspendSoure.ContainsKey(thisSid))
  22454. {
  22455. var overspendId = overspendSoure[thisSid];
  22456. whereForResult = arr.Where(x => x.SId == item.SId && DateTime.Compare(x.DatePrice.ObjToDate(), item.DatePrice.ObjToDate()) == 0).ToList();
  22457. }
  22458. cloneRowFn();
  22459. existsId.Add(new CarCompare
  22460. {
  22461. DataPrice = item.DatePrice.ObjToDate(),
  22462. Sid = item.SId
  22463. });
  22464. }
  22465. if (item.Equals(lastElem))
  22466. {
  22467. //合并小计行
  22468. //创建合并区域的实例
  22469. var cellRangeAddress = new CellRangeAddress(
  22470. rowStartIndex, // 起始行索引(0-based)
  22471. rowStartIndex, // 结束行索引(0-based)
  22472. 0, // 起始列索引(0-based)
  22473. 3 // 结束列索引(0-based)
  22474. );
  22475. sheet.AddMergedRegion(cellRangeAddress);
  22476. var CellStyle = workbook.CreateCellStyle();
  22477. CellStyle.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(0).CellStyle);
  22478. CellStyle.FillForegroundColor = IndexedColors.Yellow.Index; // 选择填充颜色
  22479. CellStyle.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground; // 填充方式
  22480. for (int i = 0; i <= clounmCount; i++)
  22481. {
  22482. if (i > 6)
  22483. {
  22484. var CellStyle1 = workbook.CreateCellStyle();
  22485. CellStyle1.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(0).CellStyle);
  22486. IFont Font = workbook.CreateFont(); // 创建字体
  22487. Font.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(i).CellStyle.GetFont(workbook));
  22488. Font.Color = IndexedColors.Red.Index; // 选择字体颜色
  22489. CellStyle1.SetFont(Font);
  22490. sheet.GetRow(rowStartIndex).GetCell(i).CellStyle = CellStyle1;
  22491. }
  22492. else
  22493. {
  22494. sheet.GetRow(rowStartIndex).GetCell(i).CellStyle = CellStyle;
  22495. }
  22496. }
  22497. sheet.GetRow(rowStartIndex).GetCell(0).SetCellValue("合计:");
  22498. sheet.GetRow(rowStartIndex).GetCell(4).SetCellValue(arr.Where(x => x.SId == thisSid).Sum(x => x.Count * x.Price).ToString("F2"));
  22499. //超时合计
  22500. sheet.GetRow(rowStartIndex).GetCell(7).SetCellValue("超时合计:");
  22501. //超时数
  22502. sheet.GetRow(rowStartIndex).GetCell(8).SetCellValue(chaoshiNumber == 0 ? "" : chaoshiNumber.ToString());
  22503. //超时合计费用
  22504. sheet.GetRow(rowStartIndex).GetCell(9).SetCellValue(totalNumber == 0 ? "" : totalNumber.ToString());
  22505. cloneRowFn();
  22506. // 创建合并区域的实例
  22507. cellRangeAddress = new CellRangeAddress(
  22508. rowStartIndex, // 起始行索引(0-based)
  22509. rowStartIndex, // 结束行索引(0-based)
  22510. 0, // 起始列索引(0-based)
  22511. initStyleRow.LastCellNum - 1 // 结束列索引(0-based)
  22512. );
  22513. // 添加合并区域
  22514. sheet.AddMergedRegion(cellRangeAddress);
  22515. sheet.GetRow(rowStartIndex).Height = 30 * 30;
  22516. sheet.GetRow(rowStartIndex).GetCell(0).SetCellValue(lastStr);
  22517. }
  22518. }
  22519. mergeRow();
  22520. // 保存修改后的Excel文件到新文件
  22521. //string newFilePath = Path.Combine(Path.GetDirectoryName(filePath), keyValue +"_" + Path.GetFileName(filePath));
  22522. // new FileStream(newFilePath, FileMode.CreateNew)
  22523. using (var stream = new MemoryStream())
  22524. {
  22525. workbook.Write(stream, true);
  22526. stream.Flush();
  22527. stream.Seek(0, SeekOrigin.Begin);
  22528. var memoryStream = new MemoryStream();
  22529. stream.CopyTo(memoryStream);
  22530. memoryStream.Seek(0, SeekOrigin.Begin);
  22531. Zips.Add(keyValue + "_" + "费用明细表.xlsx", memoryStream);
  22532. }
  22533. workbook.Close();
  22534. workbook.Dispose();
  22535. }
  22536. catch (Exception ex)
  22537. {
  22538. jw.Msg = "出现异常!" + ex.Message;
  22539. return Ok(jw);
  22540. }
  22541. }
  22542. if (Zips.Count > 0)
  22543. {
  22544. var io = new IOOperatorHelper();
  22545. var byts = io.ConvertZipStream(Zips);
  22546. io.ByteToFile(byts, AppSettingsHelper.Get("ExcelBasePath") + $"\\ExportLocalGuidePriceDetail\\{group.TeamName}_地接费用明细.zip");
  22547. //http://132.232.92.186:24/Office/Word/EnterExitCost/File/
  22548. jw = JsonView(true, "success", new { url = AppSettingsHelper.Get("OfficeBaseUrl") + $"\\Office\\Excel\\ExportLocalGuidePriceDetail\\{group.TeamName}_地接费用明细.zip" });
  22549. }
  22550. else
  22551. {
  22552. jw.Msg = "暂无生成文件!";
  22553. }
  22554. return Ok(jw);
  22555. }
  22556. private string InIndexOutFunction(int i, List<Grp_CarTouristGuideGroundReservationsContentExtend> arr, List<Grp_CarTouristGuideGroundReservationsContentExtend> arrOverspendSoure)
  22557. {
  22558. string outStr = string.Empty;
  22559. switch (i)
  22560. {
  22561. case 0:
  22562. outStr = arr[0].SidName;
  22563. break;
  22564. case 1:
  22565. outStr = arr[0].DataPriceStr;
  22566. break;
  22567. case 2:
  22568. outStr = string.Join("-", arr.Select(x => x.PriceContent));
  22569. break;
  22570. case 4:
  22571. outStr = arr.Sum(x => x.Subtotal).ToString("F2");
  22572. break;
  22573. case 7:
  22574. if (arrOverspendSoure != null && arrOverspendSoure.Count > 0)
  22575. {
  22576. var curr = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == arrOverspendSoure[0].Currency && x.IsDel == 0);
  22577. var unit = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == arrOverspendSoure[0].Units && x.IsDel == 0);
  22578. outStr = arrOverspendSoure.Sum(x => x.Price).ToString("F2") + curr?.Remark + "/" + unit?.Name;
  22579. }
  22580. break;
  22581. case 8:
  22582. if (arrOverspendSoure != null && arrOverspendSoure.Count > 0)
  22583. {
  22584. outStr = arrOverspendSoure.Sum(x => x.Count).ToString();
  22585. }
  22586. break;
  22587. case 9:
  22588. if (arrOverspendSoure != null && arrOverspendSoure.Count > 0)
  22589. {
  22590. outStr = arrOverspendSoure.Sum(x => x.Count * x.Price).ToString();
  22591. }
  22592. break;
  22593. case 10:
  22594. if (arrOverspendSoure != null && arrOverspendSoure.Count > 0)
  22595. {
  22596. outStr = string.Join("-", arrOverspendSoure.Select(x => x.PriceContent));
  22597. }
  22598. break;
  22599. }
  22600. return outStr;
  22601. }
  22602. #region OP行程单
  22603. /// <summary>
  22604. /// OP行程单初始化
  22605. /// </summary>
  22606. /// <param name="dto"></param>
  22607. /// <returns></returns>
  22608. [HttpPost]
  22609. public IActionResult InitOpTravel(InitOpTravelDto dto)
  22610. {
  22611. var jw = JsonView(false);
  22612. var groupList = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0).OrderByDescending(x => x.VisitStartDate).ToList();
  22613. var group = groupList.First();
  22614. var diid = dto.Diid == -1 ? group?.Id : dto.Diid;
  22615. if (group == null)
  22616. {
  22617. jw.Msg = "暂无团组!";
  22618. return Ok(jw);
  22619. }
  22620. group = groupList.Find(x => x.Id == diid);
  22621. if (group == null)
  22622. {
  22623. jw.Msg = "请输入正确的团组ID!";
  22624. return Ok(jw);
  22625. }
  22626. string city = string.Empty;
  22627. var blackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && x.DiId == diid).ToList();
  22628. if (blackCode.Count > 0)
  22629. {
  22630. var black = blackCode.First();
  22631. black.BlackCode = black.BlackCode ?? "";
  22632. var blackSp = Regex.Split(black.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  22633. if (blackSp.Length > 0)
  22634. {
  22635. try
  22636. {
  22637. var cityArrCode = new List<string>(20);
  22638. foreach (var item in blackSp)
  22639. {
  22640. var itemSp = item.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  22641. var IndexSelect = itemSp[2];
  22642. var cityArrCodeLength = cityArrCode.Count - 1;
  22643. var startCity = IndexSelect.Substring(0, 3);
  22644. if (cityArrCodeLength > 0)
  22645. {
  22646. var arrEndCity = cityArrCode[cityArrCodeLength];
  22647. if (arrEndCity != startCity)
  22648. {
  22649. cityArrCode.Add(startCity.ToUpper());
  22650. }
  22651. }
  22652. else
  22653. {
  22654. cityArrCode.Add(startCity.ToUpper());
  22655. }
  22656. var endCity = IndexSelect.Substring(3, 3);
  22657. cityArrCode.Add(endCity.ToUpper());
  22658. }
  22659. var cityThree = string.Empty;
  22660. cityArrCode.ForEach(x => cityThree += "'" + x + "',");
  22661. cityThree = cityThree.TrimEnd(',');
  22662. if (string.IsNullOrWhiteSpace(cityThree))
  22663. {
  22664. throw new
  22665. Exception("error");
  22666. }
  22667. string sql = $"SELECT * FROM Res_ThreeCode rtc WHERE UPPER(rtc.Three) in ({cityThree}) ";
  22668. var cityArr = _sqlSugar.SqlQueryable<Res_ThreeCode>(sql).ToList();
  22669. foreach (var item in cityArrCode)
  22670. {
  22671. var find = cityArr.Find(x => x.Three.ToUpper() == item.ToUpper());
  22672. if (find != null)
  22673. {
  22674. city += find.City + "/";
  22675. }
  22676. else
  22677. {
  22678. city += item + "三字码未收入/";
  22679. }
  22680. }
  22681. city = city.TrimEnd('/');
  22682. }
  22683. catch (Exception e)
  22684. {
  22685. city = "黑屏代码格式不正确!";
  22686. }
  22687. }
  22688. }
  22689. else
  22690. {
  22691. city = "未录入黑屏代码";
  22692. }
  22693. var OpTravelList = _sqlSugar.Queryable<Grp_TravelList>().Where(x => x.Diid == diid && x.IsDel == 0).OrderBy(x => x.Days).Select(x => new TravelArrView
  22694. {
  22695. Date = x.Date,
  22696. Days = x.Days,
  22697. Diffgroup = x.Diffgroup,
  22698. Diid = x.Diid,
  22699. Traffic_First = x.Traffic_First,
  22700. Traffic_Second = x.Traffic_Second,
  22701. Trip = x.Trip,
  22702. WeekDay = x.WeekDay,
  22703. Id = x.Id
  22704. }).ToList();
  22705. jw.Data = new
  22706. {
  22707. groupList = groupList.Select(x => new
  22708. {
  22709. x.Id,
  22710. x.TeamName,
  22711. x.TourCode
  22712. }).ToList(),
  22713. groupInfo = new
  22714. {
  22715. group.VisitDays,
  22716. group.TourCode,
  22717. group.VisitPNumber,
  22718. group.TeamName,
  22719. city
  22720. },
  22721. OpTravelList
  22722. };
  22723. jw.Code = 200;
  22724. jw.Msg = "操作成功!";
  22725. return Ok(jw);
  22726. }
  22727. /// <summary>
  22728. /// 删除团组行程单
  22729. /// </summary>
  22730. /// <returns></returns>
  22731. [HttpPost]
  22732. public IActionResult DelTravel(DelOpTravelDto dto)
  22733. {
  22734. var jw = JsonView(false);
  22735. if (dto.UserId <= 0 || dto.Diid <= 0)
  22736. {
  22737. jw.Msg = "请输入正确的参数!";
  22738. return Ok(jw);
  22739. }
  22740. var isTrue = _sqlSugar.Updateable<Grp_TravelList>().Where(x => x.Diid == dto.Diid && x.IsDel == 0)
  22741. .SetColumns(x => new Grp_TravelList
  22742. {
  22743. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  22744. DeleteUserId = dto.UserId,
  22745. IsDel = 1,
  22746. }).ExecuteCommand();
  22747. jw = JsonView(true);
  22748. return Ok(jw);
  22749. }
  22750. /// <summary>
  22751. /// 行程单保存
  22752. /// </summary>
  22753. /// <returns></returns>
  22754. [HttpPost]
  22755. public IActionResult TravelSave(TravelSaveDto dto)
  22756. {
  22757. var jw = JsonView(false);
  22758. if (dto.Arr.Count > 0)
  22759. {
  22760. try
  22761. {
  22762. var travelList_DB = _sqlSugar.Queryable<Grp_TravelList>()
  22763. .Where(x => dto.Arr.Select(x => x.Id).Contains(x.Id))
  22764. .ToList();
  22765. _sqlSugar.BeginTran();
  22766. foreach (var item in dto.Arr)
  22767. {
  22768. if (item.Id == 0)
  22769. {
  22770. throw new Exception("请传入正确的Id");
  22771. }
  22772. //比较上一次的差异
  22773. var findTravel = travelList_DB.Find(x => x.Id == item.Id);
  22774. if (findTravel != null)
  22775. {
  22776. item.Trip = item.Trip.Replace("[++]", string.Empty);
  22777. findTravel.Trip = findTravel.Trip.Replace("[++]", string.Empty);
  22778. item.Trip = CheckStr(findTravel.Trip, item.Trip);
  22779. }
  22780. _sqlSugar.Updateable<Grp_TravelList>().Where(x => x.Id == item.Id)
  22781. .SetColumns(x => new Grp_TravelList
  22782. {
  22783. Trip = item.Trip
  22784. }).ExecuteCommand();
  22785. }
  22786. _sqlSugar.CommitTran();
  22787. jw = JsonView(true);
  22788. }
  22789. catch (Exception ex)
  22790. {
  22791. _sqlSugar.RollbackTran();
  22792. jw.Msg = "程序异常!" + ex.Message;
  22793. }
  22794. }
  22795. else
  22796. {
  22797. jw.Msg = "请传入正确的参数!";
  22798. }
  22799. return Ok(jw);
  22800. }
  22801. private static string CheckStr(string original, string changed)
  22802. {
  22803. // 创建diff_match_patch对象
  22804. var dmp = new diff_match_patch();
  22805. // 计算差异
  22806. List<Diff> diffs = dmp.diff_main(original, changed);
  22807. // 清理和合并差异
  22808. dmp.diff_cleanupSemantic(diffs);
  22809. // 使用StringBuilder构建最终的字符串
  22810. var finalString = new StringBuilder();
  22811. // 输出差异结果,并构建变动后的字符串
  22812. foreach (Diff diff in diffs)
  22813. {
  22814. switch (diff.operation)
  22815. {
  22816. case Operation.EQUAL:
  22817. // 相等的部分,直接添加到最终字符串
  22818. finalString.Append(diff.text);
  22819. break;
  22820. case Operation.INSERT:
  22821. // 插入的部分,添加标记并添加到最终字符串
  22822. finalString.Append("[++]" + diff.text + "[++]");
  22823. break;
  22824. case Operation.DELETE:
  22825. // 删除的部分,不添加到最终字符串
  22826. //finalString.Append("[++]" + diff.text + "[++]");
  22827. break;
  22828. }
  22829. }
  22830. // 输出变动后的字符串
  22831. return finalString.ToString();
  22832. }
  22833. private class tagContent
  22834. {
  22835. public DateTime Date { get; set; }
  22836. public string StartTag { get; set; }
  22837. public string EndTag { get; set; }
  22838. public string Content { get; set; }
  22839. public static int tagLength { get { return 3; } }
  22840. public static Tuple<string, string> TagFormat { get { return new Tuple<string, string>("【#", "#】"); } }
  22841. public string QueryTag { get { return this.StartTag + this.EndTag; } }
  22842. public bool IsFinally { get; set; }
  22843. }
  22844. private static List<string> ExtractContentBetweenTags(string input, string tag)
  22845. {
  22846. var results = new List<string>();
  22847. // 构造正则表达式,匹配形如 [++]内容[++] 的部分
  22848. string pattern = $@"{Regex.Escape(tag)}(.*?){Regex.Escape(tag)}";
  22849. // 添加 RegexOptions.Singleline 选项使 . 匹配包括换行符在内的所有字符
  22850. MatchCollection matches = Regex.Matches(input, pattern, RegexOptions.Singleline);
  22851. string[] strValueArr = new string[1];
  22852. foreach (System.Text.RegularExpressions.Match match in matches)
  22853. {
  22854. var strValue = match.Groups[1].Value;
  22855. strValueArr = Regex.Split(strValue, @"\r\n|\n");
  22856. }
  22857. results.AddRange(strValueArr.Where(x => !string.IsNullOrWhiteSpace(x)));
  22858. return results;
  22859. }
  22860. /// <summary>
  22861. /// 导出行程单
  22862. /// </summary>
  22863. /// <param name="dto"></param>
  22864. /// <returns></returns>
  22865. [HttpPost]
  22866. public IActionResult ExportTravel(ExportTravelDto dto)
  22867. {
  22868. var jw = JsonView(false);
  22869. jw.Data = "";
  22870. int diid = 0;
  22871. var Find = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid);
  22872. if (Find == null)
  22873. {
  22874. jw.Msg = "请选择正确的团组!";
  22875. return Ok(jw);
  22876. }
  22877. else
  22878. {
  22879. diid = Find.Id;
  22880. }
  22881. //数据源
  22882. var _travelList = new List<Grp_TravelList>();
  22883. DataTable dtBlack = null;
  22884. try
  22885. {
  22886. dtBlack = GeneralMethod.GetTableByBlackCode(diid);
  22887. }
  22888. catch (Exception)
  22889. {
  22890. jw.Msg = "机票黑屏代码有误!";
  22891. return Ok(jw);
  22892. }
  22893. string CityStr = string.Empty;
  22894. if (dtBlack.Rows.Count == 0)
  22895. {
  22896. jw.Msg = "机票黑屏代码有误!";
  22897. return Ok(jw);
  22898. }
  22899. else
  22900. {
  22901. foreach (DataRow row in dtBlack.Rows)
  22902. {
  22903. if (!string.IsNullOrWhiteSpace(row["Error"].ToString()))
  22904. {
  22905. jw.Msg = "机票黑屏代码有误!" + row["Error"].ToString();
  22906. return Ok(jw);
  22907. }
  22908. }
  22909. CityStr = GeneralMethod.GetGroupCityLine(diid, "/");
  22910. _travelList = _sqlSugar.Queryable<Grp_TravelList>().Where(x => x.Diid == diid && x.IsDel == 0 && x.Issel == 1).ToList();
  22911. }
  22912. // 指定的文字
  22913. var targetTextDic = new Dictionary<string, List<string>>();
  22914. //创建数据源Table
  22915. var dtSource = new DataTable();
  22916. dtSource.Columns.Add("Days", typeof(string));
  22917. dtSource.Columns.Add("Date", typeof(string));
  22918. dtSource.Columns.Add("Week", typeof(string));
  22919. dtSource.Columns.Add("Traffic", typeof(string));
  22920. dtSource.Columns.Add("Trip", typeof(string));
  22921. //获取数据,放到datatable
  22922. foreach (var item in _travelList)
  22923. {
  22924. targetTextDic.Add(item.Date, ExtractContentBetweenTags(item.Trip, "[++]"));
  22925. item.Trip = item.Trip.Replace(tagContent.TagFormat.Item1, string.Empty)
  22926. .Replace(tagContent.TagFormat.Item2, string.Empty)
  22927. .Replace("[++]", string.Empty);
  22928. DataRow dr = dtSource.NewRow();
  22929. dr["Days"] = item.Days;
  22930. dr["Date"] = item.Date;
  22931. dr["Week"] = item.WeekDay;
  22932. dr["Traffic"] = item.Traffic_First
  22933. + "\r\n"
  22934. + item.Traffic_Second;
  22935. dr["Trip"] = item.Trip;
  22936. dtSource.Rows.Add(dr);
  22937. }
  22938. var dic = new Dictionary<string, string>
  22939. {
  22940. { "Dele", Find.TeamName.ToString() + GetNum(Find.VisitDays.ToString()) },
  22941. { "City", CityStr },
  22942. { "Days", Find.VisitDays.ToString() },
  22943. { "DeleCode", Find.TourCode },
  22944. { "Pnum", Find.VisitPNumber.ToString() }
  22945. };
  22946. //模板路径
  22947. string tempPath = AppSettingsHelper.Get("WordBasePath") + "Travel/日行程3.docx";
  22948. //载入模板
  22949. Document doc = null;
  22950. DocumentBuilder builder = null;
  22951. try
  22952. {
  22953. //载入模板
  22954. doc = new Document(tempPath);
  22955. builder = new DocumentBuilder(doc);
  22956. }
  22957. catch (Exception)
  22958. {
  22959. jw.Msg = "模板位置不存在!";
  22960. return Ok(jw);
  22961. }
  22962. foreach (var key in dic.Keys)
  22963. {
  22964. Bookmark bookmark = doc.Range.Bookmarks[key];
  22965. if (bookmark != null)
  22966. {
  22967. builder.MoveToBookmark(key);
  22968. builder.Write(dic[key]);
  22969. }
  22970. }
  22971. //获取word里所有表格
  22972. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  22973. //获取所填表格的序数
  22974. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  22975. try
  22976. {
  22977. //循环赋值
  22978. for (int i = 0; i < dtSource.Rows.Count; i++)
  22979. {
  22980. builder.MoveToCell(0, i + 1, 0, 0);
  22981. builder.Write(dtSource.Rows[i]["Days"].ToString());
  22982. builder.MoveToCell(0, i + 1, 1, 0);
  22983. builder.Write(dtSource.Rows[i]["Date"].ToString() + "\r\n" + dtSource.Rows[i]["Week"].ToString());
  22984. builder.MoveToCell(0, i + 1, 2, 0);
  22985. builder.Write(dtSource.Rows[i]["Traffic"].ToString());
  22986. var trip = dtSource.Rows[i]["Trip"].ToString();
  22987. builder.MoveToCell(0, i + 1, 3, 0);
  22988. builder.Write(trip);
  22989. var cell = (Aspose.Words.Tables.Cell)doc.GetChild(NodeType.Cell, ((i + 2) * 4) - 1, true);
  22990. var paragraphs = cell.GetChildNodes(NodeType.Paragraph, true);
  22991. // 获取特定索引的段落
  22992. Paragraph paragraph = (Paragraph)paragraphs[0];
  22993. Run run = paragraph.Runs[0];
  22994. Aspose.Words.Font font = run.Font;
  22995. font.Name = "黑体";
  22996. //设置双休红色
  22997. cell = (Aspose.Words.Tables.Cell)doc.GetChild(NodeType.Cell, ((i + 2) * 4) - 3, true);
  22998. paragraphs = cell.GetChildNodes(NodeType.Paragraph, true);
  22999. paragraph = (Paragraph)paragraphs[1];
  23000. if (paragraph.GetText().Contains("星期六") || paragraph.GetText().Contains("星期日"))
  23001. {
  23002. run = paragraph.Runs[0];
  23003. font = run.Font;
  23004. font.Color = Color.Red;
  23005. }
  23006. }
  23007. }
  23008. catch (Exception ex)
  23009. {
  23010. }
  23011. //删除多余行
  23012. while (tableOne.Rows.Count > 1 + dtSource.Rows.Count)
  23013. {
  23014. tableOne.Rows.RemoveAt(1 + dtSource.Rows.Count);//(1+dtSource.Rows.Count + 1)-1
  23015. }
  23016. var targetTextList = new List<string>();
  23017. // 遍历文档中的表格
  23018. foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
  23019. {
  23020. foreach (Aspose.Words.Tables.Row row in table.Rows)
  23021. {
  23022. var cellIndex = 0;
  23023. foreach (Cell cell in row.Cells)
  23024. {
  23025. if (cellIndex == 1 && row.Cells.Count == 4)
  23026. {
  23027. foreach (var target in targetTextDic.Keys)
  23028. {
  23029. if (cell.GetText().Contains(target))
  23030. {
  23031. targetTextList = targetTextDic[target];
  23032. break;
  23033. }
  23034. }
  23035. }
  23036. // 遍历单元格中的所有段落
  23037. foreach (Paragraph paragraph in cell.Paragraphs)
  23038. {
  23039. // 使用临时列表存储原始 Runs,避免修改时影响遍历
  23040. var runs = new List<Run>();
  23041. foreach (Run run in paragraph.Runs)
  23042. {
  23043. runs.Add(run);
  23044. }
  23045. foreach (Run run in runs)
  23046. {
  23047. foreach (var targetText in targetTextList)
  23048. {
  23049. // 检查文字是否包含指定文字
  23050. if (run.Text.Contains(targetText))
  23051. {
  23052. // 将包含的部分设置为红色
  23053. HighlightText(run, targetText, Color.Red);
  23054. }
  23055. }
  23056. }
  23057. }
  23058. cellIndex++;
  23059. }
  23060. }
  23061. }
  23062. string savePath = AppSettingsHelper.Get("WordBasePath") + "Travel/export/";
  23063. if (!Directory.Exists(savePath))
  23064. {
  23065. try
  23066. {
  23067. Directory.CreateDirectory(savePath);
  23068. }
  23069. catch
  23070. {
  23071. }
  23072. }
  23073. string path = savePath + Find.TeamName + "出访日程";
  23074. string ftpPath = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + "Travel/export/" + Find.TeamName + "出访日程";
  23075. try
  23076. {
  23077. Aspose.Words.SaveFormat saveFormat = Aspose.Words.SaveFormat.Doc;
  23078. string postfix = ".docx";
  23079. if (dto.IsPDF == 1)
  23080. {
  23081. saveFormat = Aspose.Words.SaveFormat.Pdf;
  23082. postfix = ".pdf";
  23083. }
  23084. doc.Save(path + postfix, saveFormat);
  23085. jw = JsonView(true, "导出成功", ftpPath + postfix);
  23086. }
  23087. catch (Exception)
  23088. {
  23089. jw = JsonView(false);
  23090. }
  23091. return Ok(jw);
  23092. }
  23093. /// <summary>
  23094. /// 根据大写数字返回小写数字或根据小写数字返回大写数字
  23095. /// </summary>
  23096. /// <param name="num"></param>
  23097. /// <returns></returns>
  23098. static string GetNum(string num)
  23099. {
  23100. string str = "";
  23101. switch (num)
  23102. {
  23103. case "1":
  23104. str = "一";
  23105. break;
  23106. case "2":
  23107. str = "二";
  23108. break;
  23109. case "3":
  23110. str = "三";
  23111. break;
  23112. case "4":
  23113. str = "四";
  23114. break;
  23115. case "5":
  23116. str = "五";
  23117. break;
  23118. case "6":
  23119. str = "六";
  23120. break;
  23121. case "7":
  23122. str = "七";
  23123. break;
  23124. case "8":
  23125. str = "八";
  23126. break;
  23127. case "9":
  23128. str = "九";
  23129. break;
  23130. case "10":
  23131. str = "十";
  23132. break;
  23133. case "11":
  23134. str = "十一";
  23135. break;
  23136. case "12":
  23137. str = "十二";
  23138. break;
  23139. case "一":
  23140. str = "1";
  23141. break;
  23142. case "二":
  23143. str = "2";
  23144. break;
  23145. case "三":
  23146. str = "3";
  23147. break;
  23148. case "四":
  23149. str = "4";
  23150. break;
  23151. case "五":
  23152. str = "5";
  23153. break;
  23154. case "六":
  23155. str = "6";
  23156. break;
  23157. case "七":
  23158. str = "7";
  23159. break;
  23160. case "八":
  23161. str = "8";
  23162. break;
  23163. case "九":
  23164. str = "9";
  23165. break;
  23166. case "十":
  23167. str = "10";
  23168. break;
  23169. case "十一":
  23170. str = "11";
  23171. break;
  23172. case "十二":
  23173. str = "12";
  23174. break;
  23175. }
  23176. return str;
  23177. }
  23178. /// <summary>
  23179. /// 高亮包含指定文字的部分
  23180. /// </summary>
  23181. /// <param name="run"></param>
  23182. /// <param name="targetText"></param>
  23183. /// <param name="color"></param>
  23184. static void HighlightText(Run run, string targetText, Color color)
  23185. {
  23186. string text = run.Text;
  23187. int startIndex = text.IndexOf(targetText, StringComparison.Ordinal);
  23188. if (startIndex >= 0)
  23189. {
  23190. Paragraph parentParagraph = (Paragraph)run.ParentNode;
  23191. // 前部分
  23192. if (startIndex > 0)
  23193. {
  23194. Run beforeRun = (Run)run.Clone(true);
  23195. beforeRun.Text = text.Substring(0, startIndex);
  23196. parentParagraph.InsertBefore(beforeRun, run);
  23197. }
  23198. // 匹配部分
  23199. Run matchRun = (Run)run.Clone(true);
  23200. matchRun.Text = text.Substring(startIndex, targetText.Length);
  23201. matchRun.Font.Color = color;
  23202. parentParagraph.InsertBefore(matchRun, run);
  23203. // 后部分
  23204. if (startIndex + targetText.Length < text.Length)
  23205. {
  23206. Run afterRun = (Run)run.Clone(true);
  23207. afterRun.Text = text.Substring(startIndex + targetText.Length);
  23208. parentParagraph.InsertBefore(afterRun, run);
  23209. }
  23210. // 删除原始Run
  23211. run.Remove();
  23212. }
  23213. }
  23214. #endregion
  23215. #endregion
  23216. #region 团组成本
  23217. /// <summary>
  23218. /// 团组成本数据初始化
  23219. /// </summary>
  23220. /// <param name="dto"></param>
  23221. /// <returns></returns>
  23222. [HttpPost]
  23223. public async Task<IActionResult> GroupCostInit(GroupCostInItDto dto)
  23224. {
  23225. var groupList = _sqlSugar.SqlQueryable<DelegationInfoAndIsTrueView>($@"
  23226. Select a.Id,TeamName GroupName,b.isTrue From Grp_DelegationInfo a left join (select top 100 percent Diid, CASE
  23227. WHEN COUNT(*) >= 0 THEN 'True'
  23228. ELSE 'False' END as isTrue from Grp_GroupCost where Isdel = 0 and date != '' group by Diid) b on a.Id = b.Diid
  23229. Where TeamName != '' And IsDel = 0 Order By a.VisitStartDate Desc
  23230. ").ToList(); //团组列表
  23231. int diid = dto.Diid == -1 ? groupList.First().Id : dto.Diid;
  23232. var groupInfo = await _groupRepository.PostShareGroupInfo(new ShareGroupInfoDto { PortType = 1, Id = diid }); //团组信息
  23233. var visaCountryInfoArr = new ArrayList();
  23234. var groupinfoValue = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == diid && x.IsDel == 0);
  23235. if (groupinfoValue != null)
  23236. {
  23237. var countryArr = groupinfoValue.VisitCountry ??= string.Empty;
  23238. var dicity = _sqlSugar.Queryable<Sys_Cities>().First(x => x.IsDel == 0 && x.Id == groupinfoValue.CityId);
  23239. dicity ??= new Sys_Cities()
  23240. {
  23241. ParentId = 122
  23242. };
  23243. var diparent = _sqlSugar.Queryable<Sys_Cities>().First(x => x.IsDel == 0 && x.Id == dicity.ParentId);
  23244. var spArr = new string[1] { countryArr };
  23245. if (countryArr.Contains("|"))
  23246. {
  23247. spArr = countryArr.Split("|");
  23248. }
  23249. else if (countryArr.Contains("、"))
  23250. {
  23251. spArr = countryArr.Split("、");
  23252. }
  23253. foreach (var item in spArr.Where(x => !string.IsNullOrWhiteSpace(x)).ToList())
  23254. {
  23255. try
  23256. {
  23257. var visa = _sqlSugar.Queryable<Res_VisaFeeStandard>()
  23258. .Where(x => x.IsDel == 0 && x.Country == item)
  23259. .ToList();
  23260. if (!visa.Any())
  23261. {
  23262. visa = _sqlSugar.Queryable<Res_VisaFeeStandard>()
  23263. .Where(x => x.IsDel == 0 && x.Country.Contains(item))
  23264. .ToList();
  23265. }
  23266. if (visa.Any())
  23267. {
  23268. var visainfo = _sqlSugar.Queryable<Res_VisaFeeStandardDetails>()
  23269. .LeftJoin<Res_VisaFeeStandard>((x, y) => x.ParentId == y.Id && y.IsDel == 0)
  23270. .Where(x => x.IsDel == 0 && visa.Select(x => x.Id).Contains(x.ParentId))
  23271. .Select((x, y) => new
  23272. {
  23273. x.Id,
  23274. x.ParentId,
  23275. x.ProvinceId,
  23276. x.VisaAddress,
  23277. x.IsVisaOnArrival,
  23278. x.IsElectronicSign,
  23279. x.VisaTime,
  23280. x.IsVisaExemptionLarge,
  23281. x.LargeVisaPrice,
  23282. x.LargeAgencyFee,
  23283. x.IsVisaExemptionSmall,
  23284. x.SmallVisaPrice,
  23285. x.SmallAgencyFee,
  23286. x.NormExtFee,
  23287. x.UrgExtFee,
  23288. x.IsUrgent,
  23289. x.UrgentTime,
  23290. x.UrgentPrice,
  23291. x.UrgentPriceDesc,
  23292. y.FeeType,
  23293. x.Remark
  23294. })
  23295. .ToList();
  23296. var visaMain = visainfo.FirstOrDefault(x => x.ProvinceId == diparent.Id && x.FeeType == 0);
  23297. var visayinsiValue = visainfo.FirstOrDefault(x => x.ParentId == visa.FirstOrDefault(x => x.FeeType == 1)?.Id);
  23298. visaCountryInfoArr.Add(new
  23299. {
  23300. country = item,
  23301. yinsi = new
  23302. {
  23303. Id = visayinsiValue.Id,
  23304. value = visayinsiValue.SmallVisaPrice
  23305. },
  23306. visaMain = new
  23307. {
  23308. Id = visaMain.Id,
  23309. IsVisaOnArrival = visaMain.IsVisaOnArrival ? "是" : "否",
  23310. IsElectronicSign = visaMain.IsElectronicSign ? "是" : "否",
  23311. VisaTime = visaMain.VisaTime,
  23312. IsVisaExemptionLarge = visaMain.IsVisaExemptionLarge ? "是" : "否",
  23313. LargeVisaPrice = visaMain.LargeVisaPrice,
  23314. LargeAgencyFee = visaMain.LargeAgencyFee,
  23315. IsVisaExemptionSmall = visaMain.IsVisaExemptionSmall ? "是" : "否",
  23316. SmallVisaPrice = visaMain.SmallVisaPrice,
  23317. SmallAgencyFee = visaMain.SmallAgencyFee,
  23318. NormExtFee = visaMain.NormExtFee,
  23319. UrgExtFee = visaMain.UrgExtFee,
  23320. IsUrgent = visaMain.IsUrgent ? "是" : "否",
  23321. UrgentTime = visaMain.UrgentTime,
  23322. UrgentPrice = visaMain.UrgentPrice,
  23323. UrgentPriceDesc = visaMain.UrgentPriceDesc,
  23324. Remark = visaMain.Remark,
  23325. }
  23326. });
  23327. }
  23328. }
  23329. catch (Exception ex)
  23330. {
  23331. //写入日志
  23332. _logger.LogError(ex, "团组成本解析签证异常!");
  23333. }
  23334. }
  23335. }
  23336. var groupChecks = _checkBoxs.GetCheckBoxsByDiid(diid); //团组选中信息 可枚举
  23337. var groupCost = _GroupCostRepository.GetAllByDiid(diid); //团组列表信息
  23338. #region 屏蔽黑屏代码生成
  23339. //var create = _GroupCostRepository.
  23340. // CreateGroupCostByBlackCode(dto.Diid);
  23341. //if (groupCost.Count == 0 && create.Code == 0)
  23342. //{
  23343. // groupCost = (create.Data as List<Grp_GroupCost>) ?? new List<Grp_GroupCost>();
  23344. //}
  23345. #endregion
  23346. var groupCostMap = _mapper.Map<List<Grp_GroupCostDto>>(groupCost);
  23347. var hotelNumber = _CostTypeHotelNumberRepository.GetCostTypeHotelNumberByDiid(diid); //酒店数量 可枚举
  23348. var GroupCostParameter = _GroupCostParameterRepository.GetGroupCostParameterListByDiid(diid); //成本系数 可枚举
  23349. groupCostMap = groupCostMap.Select(x =>
  23350. {
  23351. if (DateTime.TryParse(x.Date, out DateTime dataForamt))
  23352. {
  23353. x.Date = dataForamt.ToString("yyyy-MM-dd");
  23354. }
  23355. return x;
  23356. }).ToList();
  23357. //GroupCostParameter.Add(new
  23358. // Grp_GroupCostParameter());
  23359. var GroupCostParameterMap = _mapper.Map<List<Grp_GroupCostParameterDto>>(GroupCostParameter);
  23360. bool hotelIsTrue = _sqlSugar.Queryable<Grp_HotelInquiry>().Where(x => x.DiId == diid && x.IsDel == 0).Count() > 0;
  23361. var groupModuleOperators = GeneralMethod.GetGroupModuleOperators(diid);
  23362. return Ok(JsonView(new
  23363. {
  23364. groupList,
  23365. groupInfo,
  23366. groupChecks,
  23367. groupCost = groupCostMap,
  23368. hotelNumber,
  23369. GroupCostParameter = GroupCostParameterMap,
  23370. visaCountryInfoArr = visaCountryInfoArr,
  23371. baoPi = _GroupCostParameterRepository.GetBaoPi(diid),
  23372. blackCodeIsTrue = _sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && x.DiId == diid).Any(), //create.Code == 0 ? true : false,
  23373. hotelIsTrue,
  23374. groupModuleOperators
  23375. }));
  23376. }
  23377. /// <summary>
  23378. /// 团组成本信息保存
  23379. /// </summary>
  23380. /// <param name="dto"></param>
  23381. /// <returns></returns>
  23382. [HttpPost]
  23383. public async Task<IActionResult> SaveGroupCost(GroupCostSavaDto dto)
  23384. {
  23385. if (dto.Diid <= 0 || dto.Userid <= 0)
  23386. {
  23387. return Ok(JsonView(false));
  23388. }
  23389. JsonView jw = null;
  23390. bool isTrue = false;
  23391. #region 复制团组成本
  23392. //if (dto.Diid == 2581)
  23393. //{
  23394. // dto.Diid = 2599;
  23395. // dto.CheckBoxs.ForEach(x =>
  23396. // {
  23397. // x.Diid = 2599;
  23398. // });
  23399. // dto.GroupCosts.ForEach(x =>
  23400. // {
  23401. // x.Diid = 2599;
  23402. // });
  23403. // dto.CostTypeHotelNumbers.ForEach(x =>
  23404. // {
  23405. // x.Diid = 2599;
  23406. // });
  23407. // dto.GroupCostParameters.ForEach(x =>
  23408. // {
  23409. // x.DiId = 2599;
  23410. // });
  23411. //}
  23412. #endregion
  23413. var Grp_groups = _mapper.Map<List<Grp_GroupCost>>(dto.GroupCosts);
  23414. Grp_groups.ForEach(x => { x.CreateUserId = dto.Userid; x.CreateTime = DateTime.Now; }); //.ToString("yyyy-MM-dd HH:mm:ss")
  23415. var Grp_CheckBoxs = _mapper.Map<List<Grp_CheckBoxs>>(dto.CheckBoxs);
  23416. Grp_CheckBoxs.ForEach(x => { x.CreateUserId = dto.Userid; x.CreateTime = DateTime.Now; });
  23417. var Grp_HotelNumber = _mapper.Map<List<Grp_CostTypeHotelNumber>>(dto.CostTypeHotelNumbers);
  23418. var Grp_CostParameters = _mapper.Map<List<Grp_GroupCostParameter>>(dto.GroupCostParameters);
  23419. try
  23420. {
  23421. _sqlSugar.BeginTran();
  23422. isTrue = await _GroupCostRepository.
  23423. SaveGroupCostList(Grp_groups, dto.Diid, dto.Userid); //列表
  23424. isTrue = await _checkBoxs.SaveCheckBoxs(Grp_CheckBoxs, dto.Diid); //选中项
  23425. isTrue = await _CostTypeHotelNumberRepository.SaveHotelNumber(Grp_HotelNumber, dto.Userid, dto.Diid); //酒店房间数量
  23426. isTrue = await _GroupCostParameterRepository.SaveAsync(Grp_CostParameters, dto.Userid, dto.Diid); //系数
  23427. _sqlSugar.CommitTran();
  23428. jw = JsonView(true, "保存成功!", isTrue);
  23429. }
  23430. catch (Exception)
  23431. {
  23432. _sqlSugar.RollbackTran();
  23433. jw = JsonView(false);
  23434. }
  23435. return Ok(jw);
  23436. }
  23437. /// <summary>
  23438. /// 复制团组成本信息
  23439. /// </summary>
  23440. /// <param name="dto"></param>
  23441. /// <returns></returns>
  23442. [HttpPost]
  23443. public async Task<IActionResult> CopyGroupCost(CopyGroupCostDto dto)
  23444. {
  23445. if (dto.Diid <= 0 || dto.Userid <= 0 || dto.ToGroupId <= 0)
  23446. {
  23447. return Ok(JsonView(false, "参数有误!"));
  23448. }
  23449. #region 复制团组成本
  23450. dto.Diid = dto.ToGroupId;
  23451. dto.CheckBoxs.ForEach(x =>
  23452. {
  23453. x.Diid = dto.ToGroupId;
  23454. });
  23455. dto.GroupCosts.ForEach(x =>
  23456. {
  23457. x.Diid = dto.ToGroupId;
  23458. });
  23459. dto.CostTypeHotelNumbers.ForEach(x =>
  23460. {
  23461. x.Diid = dto.ToGroupId;
  23462. });
  23463. dto.GroupCostParameters.ForEach(x =>
  23464. {
  23465. x.DiId = dto.ToGroupId;
  23466. });
  23467. #endregion
  23468. JsonView jw = null;
  23469. bool isTrue = false;
  23470. var Grp_groups = _mapper.Map<List<Grp_GroupCost>>(dto.GroupCosts);
  23471. Grp_groups.ForEach(x => { x.CreateUserId = dto.Userid; x.CreateTime = DateTime.Now; }); //.ToString("yyyy-MM-dd HH:mm:ss")
  23472. var Grp_CheckBoxs = _mapper.Map<List<Grp_CheckBoxs>>(dto.CheckBoxs);
  23473. Grp_CheckBoxs.ForEach(x => { x.CreateUserId = dto.Userid; x.CreateTime = DateTime.Now; });
  23474. var Grp_HotelNumber = _mapper.Map<List<Grp_CostTypeHotelNumber>>(dto.CostTypeHotelNumbers);
  23475. var Grp_CostParameters = _mapper.Map<List<Grp_GroupCostParameter>>(dto.GroupCostParameters);
  23476. try
  23477. {
  23478. _sqlSugar.BeginTran();
  23479. isTrue = await _GroupCostRepository.
  23480. SaveGroupCostList(Grp_groups, dto.Diid, dto.Userid); //列表
  23481. isTrue = await _checkBoxs.SaveCheckBoxs(Grp_CheckBoxs, dto.Diid); //选中项
  23482. isTrue = await _CostTypeHotelNumberRepository.SaveHotelNumber(Grp_HotelNumber, dto.Userid, dto.Diid); //酒店房间数量
  23483. isTrue = await _GroupCostParameterRepository.SaveAsync(Grp_CostParameters, dto.Userid, dto.Diid); //系数
  23484. _sqlSugar.CommitTran();
  23485. jw = JsonView(true, "保存成功!", isTrue);
  23486. }
  23487. catch (Exception)
  23488. {
  23489. _sqlSugar.RollbackTran();
  23490. jw = JsonView(false);
  23491. }
  23492. return Ok(jw);
  23493. }
  23494. /// <summary>
  23495. /// 司兼导数据
  23496. /// </summary>
  23497. /// <param name="dto"></param>
  23498. /// <returns></returns>
  23499. [HttpPost]
  23500. public IActionResult GetCarGuides(CarGuidesDto dto)
  23501. {
  23502. var Data = _sqlSugar.SqlQueryable<Grp_CarGuides>($@" select * from Grp_CarGuides where isdel = 0 ").ToList();
  23503. return Ok(JsonView(true, "获取成功!", Data));
  23504. }
  23505. /// <summary>
  23506. /// 导游数据
  23507. /// </summary>
  23508. /// <param name="dto"></param>
  23509. /// <returns></returns>
  23510. [HttpPost]
  23511. public IActionResult GetGuidesInfo(CarGuidesDto dto)
  23512. {
  23513. //var Data = _sqlSugar.SqlQueryable<Grp_GuidesInfo>($@" SELECT* FROM (
  23514. // 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
  23515. // where RowNumber BETWEEN {(dto.Page - 1) * dto.Size + 1} and {(dto.Page) * dto.Size}").ToList();
  23516. var Data = _sqlSugar.SqlQueryable<Grp_GuidesInfo>($@" select * from Grp_GuidesInfo where isdel = 0 ").ToList();
  23517. return Ok(JsonView(true, "获取成功!", Data));
  23518. }
  23519. /// <summary>
  23520. /// 成本车数据
  23521. /// </summary>
  23522. /// <param name="dto"></param>
  23523. /// <returns></returns>
  23524. [HttpPost]
  23525. public IActionResult GetCarInfo(CarGuidesDto dto)
  23526. {
  23527. var Data = _sqlSugar.SqlQueryable<Grp_CarInfo>($@" select * from Grp_CarInfo where isdel = 0 ").ToList();
  23528. return Ok(JsonView(true, "获取成功!", Data));
  23529. }
  23530. /// <summary>
  23531. /// 景点数据
  23532. /// </summary>
  23533. /// <param name="dto"></param>
  23534. /// <returns></returns>
  23535. [HttpPost]
  23536. public IActionResult GetScenicSpotInfo(CarGuidesDto dto)
  23537. {
  23538. var Data = _sqlSugar.SqlQueryable<Grp_ScenicSpotInfo>($@" select * from Grp_ScenicSpotInfo where isdel = 0 ").ToList();
  23539. return Ok(JsonView(true, "获取成功!", Data));
  23540. }
  23541. /// <summary>
  23542. /// 成本通知
  23543. /// </summary>
  23544. /// <param name="dto"></param>
  23545. /// <returns></returns>
  23546. [HttpPost]
  23547. public async Task<IActionResult> GroupIsShare(GroupIsShareDto dto)
  23548. {
  23549. if (dto.Diid < 0)
  23550. {
  23551. return Ok(JsonView(false));
  23552. }
  23553. JsonView jw;
  23554. var GroupCostParameter = _GroupCostParameterRepository.GetGroupCostParameterMainByDiid(dto.Diid);
  23555. if (GroupCostParameter != null)
  23556. {
  23557. int IsShare = 0;
  23558. if (GroupCostParameter.IsShare == 0) IsShare = 1;
  23559. else if (GroupCostParameter.IsShare == 1) IsShare = 0;
  23560. bool isTrue = await _GroupCostParameterRepository.UpdateIsShareById(GroupCostParameter.Id, IsShare);
  23561. string msg = string.Empty;
  23562. if (isTrue)
  23563. {
  23564. if (IsShare == 0)
  23565. {
  23566. msg = "禁止通知,其他模块操作人员不可见此成本信息!";
  23567. }
  23568. else
  23569. {
  23570. #region 企微通知对应岗位用户
  23571. try
  23572. {
  23573. await AppNoticeLibrary.SendUserMsg_GroupShare_ToJob(dto.Diid);
  23574. //机票预算群通知
  23575. await AppNoticeLibrary.SendChatMsg_AirCostChat(dto.Diid, QiyeWeChatEnum.AirCostChat01);
  23576. }
  23577. catch (Exception)
  23578. {
  23579. }
  23580. #endregion
  23581. msg = "通知成功,其他模块操作人员可见此成本信息!";
  23582. }
  23583. jw = JsonView(isTrue, msg, new { IsShare });
  23584. }
  23585. else
  23586. {
  23587. msg = "修改失败!";
  23588. jw = JsonView(isTrue, msg);
  23589. }
  23590. }
  23591. else
  23592. {
  23593. jw = JsonView(false, "该团没有数据,请添加数据,保存后再操作!");
  23594. }
  23595. return Ok(jw);
  23596. }
  23597. /// <summary>
  23598. /// 导出报价单
  23599. /// </summary>
  23600. /// <param name="dto"></param>
  23601. /// <returns></returns>
  23602. [HttpPost]
  23603. public async Task<IActionResult> ExportPriceCheckWordFile(GroupCostExportWordFile dto)
  23604. {
  23605. if (dto.Diid == 0)
  23606. {
  23607. return Ok(JsonView(false, "请传递团组id"));
  23608. }
  23609. var deleInfo = await _groupRepository.PostGroupInfo(new GroupInfoDto { Id = dto.Diid, PortType = 1 });
  23610. if (deleInfo.Code != 0)
  23611. {
  23612. return Ok(JsonView(false, "团组信息查询失败!"));
  23613. }
  23614. var di = deleInfo.Data as DelegationInfoWebView;
  23615. if (di != null)
  23616. {
  23617. di.TeamName = di.TeamName.Replace("|", "、");
  23618. di.VisitCountry = di.VisitCountry.Replace("|", "、");
  23619. //文件名
  23620. string strFileName = di.TeamName + "-收款账单.doc";
  23621. //获取模板
  23622. string tmppath = (AppSettingsHelper.Get("WordBasePath") + "Template/收款账单(四川)模板.doc");
  23623. //载入模板
  23624. Document doc = new Document(tmppath);
  23625. decimal TotalPrice = 0.00M;
  23626. string itemStr = string.Empty;
  23627. Dictionary<string, string> airSouer = new Dictionary<string, string>();
  23628. //airSouer.Add("JJCTBR", "经济舱及酒店双人间");
  23629. airSouer.Add("JJCTBR", "经济舱及酒店双人间");
  23630. airSouer.Add("JJCSGR", "经济舱及酒店单人间");
  23631. airSouer.Add("GWCSGR", "公务舱及酒店单人间");
  23632. airSouer.Add("GWCJSES", "公务舱及酒店小套房");
  23633. airSouer.Add("GWCSUITE", "公务舱及酒店套房");
  23634. airSouer.Add("JJCSUITE", "经济舱及酒店套房");
  23635. var groupCostType = dto.airs.GroupBy(x => x.costType).OrderBy(x => x.Key);
  23636. foreach (var cost in groupCostType)
  23637. {
  23638. var List = cost.ToList();
  23639. if (cost.Key == "A")
  23640. {
  23641. foreach (var ListItem in List)
  23642. {
  23643. if (ListItem.number > 0)
  23644. {
  23645. if (ListItem.code.Contains("TBR"))
  23646. {
  23647. itemStr += "团费(" + airSouer[ListItem.code] + ") RMB " + ListItem.price.ToString("F2") + "/人*" + ListItem.number + "(" + (ListItem.number / 2) + "间) ............合计 RMB " + (ListItem.number * ListItem.price).ToString("#0.00") + "\n";
  23648. }
  23649. else
  23650. {
  23651. itemStr += "团费(" + airSouer[ListItem.code] + ") RMB " + ListItem.price.ToString("F2") + "/人*" + ListItem.number + "(" + ListItem.number + "间) ............合计 RMB " + (ListItem.number * ListItem.price).ToString("#0.00") + "\n";
  23652. }
  23653. TotalPrice += (ListItem.number * ListItem.price);
  23654. }
  23655. }
  23656. }
  23657. else
  23658. {
  23659. itemStr = itemStr.Insert(0, "A段\r\n");
  23660. itemStr += "B段\r\n";
  23661. foreach (var ListItem in List)
  23662. {
  23663. if (ListItem.number > 0)
  23664. {
  23665. if (ListItem.code.Contains("TBR"))
  23666. {
  23667. itemStr += "团费(" + airSouer[ListItem.code] + ") RMB " + ListItem.price.ToString("F2") + "/人*" + ListItem.number + "(" + (ListItem.number / 2) + "间) ............合计 RMB " + (ListItem.number * ListItem.price).ToString("#0.00") + "\n";
  23668. }
  23669. else
  23670. {
  23671. itemStr += "团费(" + airSouer[ListItem.code] + ") RMB " + ListItem.price.ToString("F2") + "/人*" + ListItem.number + "(" + ListItem.number + "间) ............合计 RMB " + (ListItem.number * ListItem.price).ToString("#0.00") + "\n";
  23672. }
  23673. TotalPrice += (ListItem.number * ListItem.price);
  23674. }
  23675. }
  23676. }
  23677. }
  23678. #region 替换Word模板书签内容
  23679. Dictionary<string, string> marks = new Dictionary<string, string>();
  23680. marks.Add("To", di.ClientUnit);//付款方
  23681. marks.Add("ToTel", di.TellPhone);//付款方电话
  23682. marks.Add("Date", DateTime.Now.ToString("yyyy-MM-dd"));//导出时间
  23683. marks.Add("Team", di.VisitCountry.Replace(" ", "、"));//团队名称
  23684. marks.Add("TontractTime", (di.VisitDate).ToString("yyyy年MM月dd日"));//付款日期
  23685. marks.Add("PayDay", (di.PayDay).ToString());//付款预期
  23686. marks.Add("PaymentMoney", (di.PaymentMoney).ToString("#0.00"));//付款金额
  23687. marks.Add("WeChat", di.WeChatNo ?? "");//微信号
  23688. marks.Add("PayItemContent", itemStr);//详细信息
  23689. marks.Add("Total", TotalPrice.ToString("F2"));//合计
  23690. #endregion
  23691. ////注
  23692. //if (doc.Range.Bookmarks["Attention"] != null)
  23693. //{
  23694. // Bookmark mark = doc.Range.Bookmarks["Attention"];
  23695. // mark.Text = frList[0].Attention;
  23696. //}
  23697. foreach (var item in marks.Keys)
  23698. {
  23699. if (doc.Range.Bookmarks[item] != null)
  23700. {
  23701. Bookmark mark = doc.Range.Bookmarks[item];
  23702. mark.Text = marks[item];
  23703. }
  23704. }
  23705. byte[] bytes = null;
  23706. using (MemoryStream stream = new MemoryStream())
  23707. {
  23708. doc.Save(stream, Aspose.Words.SaveFormat.Doc);
  23709. bytes = stream.ToArray();
  23710. }
  23711. //doc.Save((AppSettingsHelper.Get("WordBasePath") + "Template/") + strFileName);
  23712. return Ok(JsonView(true, "", new
  23713. {
  23714. Data = bytes,
  23715. strFileName,
  23716. }));
  23717. }
  23718. else
  23719. {
  23720. return Ok(JsonView(false, "团组信息不存在!"));
  23721. }
  23722. }
  23723. /// <summary>
  23724. /// 导出团组成本
  23725. /// </summary>
  23726. /// <param name="dto"></param>
  23727. /// <returns></returns>
  23728. [HttpPost]
  23729. public async Task<IActionResult> ExportGroupCostExcelFile(GroupCostExportExcelFile dto)
  23730. {
  23731. var jw = JsonView(false);
  23732. if (dto.Diid == 0)
  23733. {
  23734. return Ok(JsonView(false, "请传递团组id"));
  23735. }
  23736. var deleInfo = await _groupRepository.PostGroupInfo(new GroupInfoDto { Id = dto.Diid, PortType = 1 });
  23737. if (deleInfo.Code != 0)
  23738. {
  23739. return Ok(JsonView(false, "团组信息查询失败!"));
  23740. }
  23741. var di = deleInfo.Data as DelegationInfoWebView;
  23742. if (di == null)
  23743. {
  23744. return Ok(JsonView(false, "团组信息查询失败!"));
  23745. }
  23746. List<GroupCost_Excel> List_GC1 = new List<GroupCost_Excel>();
  23747. WorkbookDesigner designer = new WorkbookDesigner();
  23748. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + ("Template/团组-成本.xls"));
  23749. var List_GC = _GroupCostRepository.GetAllByDiid(dto.Diid);
  23750. List<int> hideColumnList = new List<int>();
  23751. var ColumnSetting = new[]
  23752. {
  23753. new { tag = "VF", Index = 4, P = "CarCost" },
  23754. new { tag = "VN", Index = 5, P = "CarNumber" },
  23755. new { tag = "VRD", Index = 6, P = "CarTiming" },
  23756. new { tag = "T/G S", Index = 7, P = "TGS" },
  23757. new { tag = "TGWH", Index = 8, P = "TGWH" },
  23758. new { tag = "T/G OF", Index = 9, P = "TGOF" },
  23759. new { tag = "T/G M", Index = 10, P = "TGM" },
  23760. new { tag = "T/G A", Index = 11, P = "TGA" },
  23761. new { tag = "T/G TF", Index = 12, P = "TGTF" },
  23762. new { tag = "T/G EF", Index = 13, P = "TGEF" },
  23763. new { tag = "C/F S", Index = 14, P = "CFS" },
  23764. new { tag = "C/F M", Index = 15, P = "CFM" },
  23765. new { tag = "C/F OF", Index = 16, P = "CFOF" },
  23766. new { tag = "B", Index = 17, P = "B" },
  23767. new { tag = "L", Index = 18, P = "L" },
  23768. new { tag = "D", Index = 19, P = "D" },
  23769. new { tag = "TBR", Index = 20, P = "TBR" },
  23770. new { tag = "SGR", Index = 21, P = "SGR" },
  23771. new { tag = "JS/ES", Index = 22, P = "JS_ES" },
  23772. new { tag = "Suite", Index = 23, P = "Suite" },
  23773. new { tag = "ACCO N", Index = 24, P = "ACCON" },
  23774. new { tag = "T/V", Index = 25, P = "TV" },
  23775. new { tag = "1/L", Index = 26, P = "iL" },
  23776. new { tag = "I/F", Index = 27, P = "IF" },
  23777. new { tag = "EF", Index = 28, P = "EF" },
  23778. new { tag = "B/R/F", Index = 29, P = "B_R_F" },
  23779. new { tag = "TE", Index = 30, P = "TE" },
  23780. new { tag = "T/G T", Index = 31, P = "TGTips" },
  23781. new { tag = "DRV T", Index = 32, P = "DRVTips" },
  23782. new { tag = "P/C", Index = 33, P = "PC" },
  23783. new { tag = "T/L F", Index = 34, P = "TLF" },
  23784. new { tag = "E/C T", Index = 35, P = "ECT" }
  23785. };
  23786. Func<string, bool> isEmpty = (str) =>
  23787. {
  23788. if (decimal.TryParse(str, out decimal str_De) && str_De == 0)
  23789. {
  23790. return true;
  23791. }
  23792. if (string.IsNullOrWhiteSpace(str))
  23793. {
  23794. return true;
  23795. }
  23796. return false;
  23797. };
  23798. for (int i = 0; i < List_GC.Count; i++)
  23799. {
  23800. GroupCost_Excel gc = new GroupCost_Excel();
  23801. gc.Id = List_GC[i].Id;
  23802. gc.Diid = List_GC[i].Diid.ToString();
  23803. gc.DAY = List_GC[i].DAY;
  23804. string week = "";
  23805. if (!string.IsNullOrEmpty(List_GC[i].Date.Trim()))
  23806. week = CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(Convert.ToDateTime(List_GC[i].Date).DayOfWeek);
  23807. gc.Date = (List_GC[i].Date + "\n" + week).ToString();
  23808. gc.ITIN = List_GC[i].ITIN;
  23809. gc.CarType = List_GC[i].CarType;
  23810. gc.CarTiming = isEmpty(List_GC[i].CarTiming.ToString()) ? "" : List_GC[i].CarTiming.ToString();
  23811. gc.CarCost = isEmpty(List_GC[i].CarCost.ToString()) ? "" : List_GC[i].CarCost.ToString();
  23812. gc.CarNumber = isEmpty(List_GC[i].CarNumber.ToString()) ? "" : List_GC[i].CarNumber.ToString();
  23813. gc.TGS = isEmpty(List_GC[i].TGS.ToString()) ? "" : List_GC[i].TGS.ToString();
  23814. gc.TGWH = isEmpty(List_GC[i].TGWH.ToString()) ? "" : List_GC[i].TGWH.ToString();
  23815. gc.TGN = isEmpty(List_GC[i].TGN.ToString()) ? "" : List_GC[i].TGN.ToString();
  23816. gc.TGOF = isEmpty(List_GC[i].TGOF.ToString()) ? "" : List_GC[i].TGOF.ToString();
  23817. gc.TGM = isEmpty(List_GC[i].TGM.ToString()) ? "" : List_GC[i].TGM.ToString();
  23818. gc.TGA = isEmpty(List_GC[i].TGA.ToString()) ? "" : List_GC[i].TGA.ToString();
  23819. gc.TGTF = isEmpty(List_GC[i].TGTF.ToString()) ? "" : List_GC[i].TGTF.ToString();
  23820. gc.TGEF = isEmpty(List_GC[i].TGEF.ToString()) ? "" : List_GC[i].TGEF.ToString();
  23821. gc.CFS = isEmpty(List_GC[i].CFS.ToString()) ? "" : List_GC[i].CFS.ToString();
  23822. gc.CFM = isEmpty(List_GC[i].CFM.ToString()) ? "" : List_GC[i].CFM.ToString();
  23823. gc.CFOF = isEmpty(List_GC[i].CFOF.ToString()) ? "" : List_GC[i].CFOF.ToString();
  23824. gc.B = isEmpty(List_GC[i].B.ToString()) ? "" : List_GC[i].B.ToString();
  23825. gc.L = isEmpty(List_GC[i].L.ToString()) ? "" : List_GC[i].L.ToString();
  23826. gc.D = isEmpty(List_GC[i].D.ToString()) ? "" : List_GC[i].D.ToString();
  23827. gc.TBR = isEmpty(List_GC[i].TBR.ToString()) ? "" : List_GC[i].TBR.ToString();
  23828. gc.SGR = isEmpty(List_GC[i].SGR.ToString()) ? "" : List_GC[i].SGR.ToString();
  23829. gc.JS_ES = isEmpty(List_GC[i].JS_ES.ToString()) ? "" : List_GC[i].JS_ES.ToString();
  23830. gc.Suite = isEmpty(List_GC[i].Suite.ToString()) ? "" : List_GC[i].Suite.ToString();
  23831. gc.ACCON = isEmpty(List_GC[i].ACCON.ToString()) ? "" : List_GC[i].ACCON.ToString();
  23832. gc.TV = isEmpty(List_GC[i].TV.ToString()) ? "" : List_GC[i].TV.ToString();
  23833. gc.iL = isEmpty(List_GC[i].iL.ToString()) ? "" : List_GC[i].iL.ToString();
  23834. gc.IF = isEmpty(List_GC[i].IF.ToString()) ? "" : List_GC[i].IF.ToString();
  23835. gc.EF = isEmpty(List_GC[i].EF.ToString()) ? "" : List_GC[i].EF.ToString();
  23836. gc.B_R_F = isEmpty(List_GC[i].B_R_F.ToString()) ? "" : List_GC[i].B_R_F.ToString();
  23837. gc.TE = isEmpty(List_GC[i].TE.ToString()) ? "" : List_GC[i].TE.ToString();
  23838. gc.TGTips = isEmpty(List_GC[i].TGTips.ToString()) ? "" : List_GC[i].TGTips.ToString();
  23839. gc.DRVTips = isEmpty(List_GC[i].DRVTips.ToString()) ? "" : List_GC[i].DRVTips.ToString();
  23840. gc.PC = isEmpty(List_GC[i].PC.ToString()) ? "" : List_GC[i].PC.ToString();
  23841. gc.TLF = isEmpty(List_GC[i].TLF.ToString()) ? "" : List_GC[i].TLF.ToString();
  23842. gc.ECT = isEmpty(List_GC[i].ECT.ToString()) ? "" : List_GC[i].ECT.ToString();
  23843. gc.EFR = List_GC[i].EFR;
  23844. List_GC1.Add(gc);
  23845. }
  23846. if (List_GC1.Count > 0)
  23847. {
  23848. var p = List_GC1[0];
  23849. var prs = p.GetType().GetProperties();
  23850. foreach (var item in prs)
  23851. {
  23852. var tp = item.PropertyType;
  23853. if (tp == typeof(int))
  23854. {
  23855. var val = List_GC1.Sum(x =>
  23856. {
  23857. var raw = x.GetType().GetProperty(item.Name).GetValue(x);
  23858. return raw == null ? 0 : (int)raw;
  23859. });
  23860. if (val == 0)
  23861. {
  23862. var columnSetting = ColumnSetting.FirstOrDefault(x => x.P == item.Name);
  23863. if (columnSetting != null)
  23864. {
  23865. hideColumnList.Add(columnSetting.Index);
  23866. }
  23867. }
  23868. }
  23869. if (tp == typeof(decimal))
  23870. {
  23871. var val = List_GC1.Sum(x =>
  23872. {
  23873. var raw = x.GetType().GetProperty(item.Name).GetValue(x);
  23874. return raw == null ? 0m : (decimal)raw;
  23875. });
  23876. if (val == 0)
  23877. {
  23878. var columnSetting = ColumnSetting.FirstOrDefault(x => x.P == item.Name);
  23879. if (columnSetting != null)
  23880. {
  23881. hideColumnList.Add(columnSetting.Index);
  23882. }
  23883. }
  23884. }
  23885. if (tp == typeof(string))
  23886. {
  23887. var val = List_GC1.Sum(x =>
  23888. {
  23889. var str = (string)x.GetType().GetProperty(item.Name).GetValue(x);
  23890. if (decimal.TryParse(str, out decimal str_De))
  23891. {
  23892. return str_De;
  23893. }
  23894. else
  23895. {
  23896. return string.IsNullOrEmpty((string)x.GetType().GetProperty(item.Name).GetValue(x)) ? 0 : 1;
  23897. }
  23898. });
  23899. if (val == 0)
  23900. {
  23901. var columnSetting = ColumnSetting.FirstOrDefault(x => x.P == item.Name);
  23902. if (columnSetting != null)
  23903. {
  23904. hideColumnList.Add(columnSetting.Index);
  23905. }
  23906. }
  23907. }
  23908. }
  23909. }
  23910. var dt = CommonFun.GetDataTableFromIList(List_GC1);
  23911. dt.TableName = "TB";
  23912. //报表标题等不用dt的值
  23913. designer.SetDataSource("TeamName", dto.title.TeamName);
  23914. designer.SetDataSource("Pnumber", dto.title.GroupNumber);
  23915. designer.SetDataSource("Tax", dto.title.Tax);
  23916. //designer.SetDataSource("FFYS", lblHotelCB.Text);
  23917. designer.SetDataSource("Currency", dto.title.Currency);
  23918. //designer.SetDataSource("HotelXS", txtHotelXS.Text);
  23919. designer.SetDataSource("Rate", dto.title.Rate);
  23920. var hotels = _CostTypeHotelNumberRepository.GetCostTypeHotelNumberByDiid(dto.Diid);
  23921. var Aparams = hotels.Find(x => x.Type == "Default");
  23922. if (Aparams == null)
  23923. {
  23924. return Ok(jw);
  23925. }
  23926. //酒店数量
  23927. var txtSGRNumber = Aparams.SGR.ToString();
  23928. var txtTBRNumber = Aparams.TBR.ToString();
  23929. var txtJSESNumber = Aparams.JSES.ToString();
  23930. var txtSUITENumbe = Aparams.SUITE.ToString();
  23931. if (dto.costType == "B")
  23932. {
  23933. Aparams = hotels.Find(x => x.Type == "A");
  23934. var Bparams = hotels.Find(x => x.Type == "B");
  23935. if (Aparams == null || Bparams == null)
  23936. {
  23937. return Ok(jw);
  23938. }
  23939. txtSGRNumber = "A段人数:" + Aparams.SGR.ToString() + " B段人数:" + Bparams.SGR.ToString();
  23940. txtTBRNumber = "A段人数:" + Aparams.TBR.ToString() + " B段人数:" + Bparams.TBR.ToString();
  23941. txtJSESNumber = "A段人数:" + Aparams.JSES.ToString() + " B段人数:" + Bparams.JSES.ToString();
  23942. txtSUITENumbe = "A段人数:" + Aparams.SUITE.ToString() + " B段人数:" + Bparams.SUITE.ToString();
  23943. }
  23944. designer.SetDataSource("SGRNumber", txtSGRNumber);
  23945. designer.SetDataSource("TBRNumber", txtTBRNumber);
  23946. designer.SetDataSource("JSESNumber", txtJSESNumber);
  23947. designer.SetDataSource("SUITENumber", txtSUITENumbe);
  23948. var ws = designer.Workbook.Worksheets[1];
  23949. int Row = List_GC.Count;
  23950. int startIndex = 0;
  23951. int HideRows = 0;
  23952. Row = 0;
  23953. List<int> hideRowsList = new List<int>();
  23954. decimal TzZCB2 = 0.00M, TzZLR2 = 0.00M, TzZBJ2 = 0.00M;
  23955. #region A段left数据
  23956. var left = dto.leftInfo.Find(x => x.Type == "A");
  23957. if (left == null)
  23958. {
  23959. return Ok(jw);
  23960. }
  23961. var leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("签证"));
  23962. if (leftBindData != null)
  23963. {
  23964. designer.SetDataSource("VisaDRCB", leftBindData.cb);
  23965. designer.SetDataSource("VisaRS", leftBindData.rs);
  23966. designer.SetDataSource("VisaXS", leftBindData.xs);
  23967. designer.SetDataSource("VisaZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23968. designer.SetDataSource("VisaDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23969. designer.SetDataSource("VisaZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23970. designer.SetDataSource("VisaDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23971. designer.SetDataSource("VisaZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23972. }
  23973. else
  23974. {
  23975. hideRowsList.Add(Row + startIndex + HideRows);
  23976. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  23977. }
  23978. HideRows += 2;
  23979. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("保险"));
  23980. if (leftBindData != null)
  23981. {
  23982. designer.SetDataSource("BXDRCB", leftBindData.cb);
  23983. designer.SetDataSource("BXRS", leftBindData.rs);
  23984. designer.SetDataSource("BXXS", leftBindData.xs);
  23985. designer.SetDataSource("BXZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  23986. designer.SetDataSource("BXDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  23987. designer.SetDataSource("BXZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  23988. designer.SetDataSource("BXDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  23989. designer.SetDataSource("BXZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  23990. }
  23991. else
  23992. {
  23993. hideRowsList.Add(Row + startIndex + HideRows);
  23994. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  23995. }
  23996. HideRows += 2;
  23997. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("核酸"));
  23998. if (leftBindData != null)
  23999. {
  24000. designer.SetDataSource("HSDRCB", leftBindData.cb);
  24001. designer.SetDataSource("HSRS", leftBindData.rs);
  24002. designer.SetDataSource("HSXS", leftBindData.xs);
  24003. designer.SetDataSource("HSZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24004. designer.SetDataSource("HSDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24005. designer.SetDataSource("HSZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24006. designer.SetDataSource("HSDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24007. designer.SetDataSource("HSZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24008. }
  24009. else
  24010. {
  24011. hideRowsList.Add(Row + startIndex + HideRows);
  24012. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  24013. }
  24014. HideRows += 2;
  24015. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("经济舱"));
  24016. if (leftBindData != null)
  24017. {
  24018. designer.SetDataSource("JPJJCCB", leftBindData.cb);
  24019. designer.SetDataSource("JPJJCPnum", leftBindData.rs);
  24020. designer.SetDataSource("JPJJCXS", leftBindData.xs);
  24021. designer.SetDataSource("JPJJCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24022. designer.SetDataSource("JPJJCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24023. designer.SetDataSource("JPJJCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24024. designer.SetDataSource("JPJJCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24025. designer.SetDataSource("JPJJCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24026. }
  24027. else
  24028. {
  24029. hideRowsList.Add(Row + startIndex + HideRows);
  24030. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  24031. }
  24032. HideRows += 2;
  24033. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("公务舱"));
  24034. if (leftBindData != null)
  24035. {
  24036. designer.SetDataSource("JPGWCCB", leftBindData.cb);
  24037. designer.SetDataSource("JPGWCPNum", leftBindData.rs);
  24038. designer.SetDataSource("JPGWCXS", leftBindData.xs);
  24039. designer.SetDataSource("JPGWCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24040. designer.SetDataSource("JPGWCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24041. designer.SetDataSource("JPGWCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24042. designer.SetDataSource("JPGWCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24043. designer.SetDataSource("JPGWCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24044. }
  24045. else
  24046. {
  24047. hideRowsList.Add(Row + startIndex + HideRows);
  24048. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  24049. }
  24050. HideRows += 2;
  24051. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("头等舱"));
  24052. if (leftBindData != null)
  24053. {
  24054. designer.SetDataSource("JPTDCCB", leftBindData.cb);
  24055. designer.SetDataSource("JPTDCPNum", leftBindData.rs);
  24056. designer.SetDataSource("JPTDCXS", leftBindData.xs);
  24057. designer.SetDataSource("JPTDCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24058. designer.SetDataSource("JPTDCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24059. designer.SetDataSource("JPTDCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24060. designer.SetDataSource("JPTDCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24061. designer.SetDataSource("JPTDCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24062. }
  24063. else
  24064. {
  24065. hideRowsList.Add(Row + startIndex + HideRows);
  24066. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  24067. }
  24068. HideRows += 2;
  24069. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("TBR"));
  24070. if (leftBindData != null)
  24071. {
  24072. ////TBR
  24073. designer.SetDataSource("HotelTBRDRCB", leftBindData.cb);
  24074. designer.SetDataSource("HotelTBRRS", leftBindData.rs);
  24075. designer.SetDataSource("HotelTBRXS", leftBindData.xs);
  24076. designer.SetDataSource("HotelTBRCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24077. designer.SetDataSource("HotelTBRDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24078. designer.SetDataSource("HotelTBRZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24079. designer.SetDataSource("HotelTBRDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24080. designer.SetDataSource("HotelTBRZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24081. }
  24082. else
  24083. {
  24084. hideRowsList.Add(Row + startIndex + HideRows);
  24085. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  24086. }
  24087. HideRows += 2;
  24088. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("SGR"));
  24089. if (leftBindData != null)
  24090. {
  24091. ////SGR
  24092. designer.SetDataSource("HotelSGRDRCB", leftBindData.cb);
  24093. designer.SetDataSource("HotelSGRRS", leftBindData.rs);
  24094. designer.SetDataSource("HotelSGRXS", leftBindData.xs);
  24095. designer.SetDataSource("HotelSGRCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24096. designer.SetDataSource("HotelSGRDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24097. designer.SetDataSource("HotelSGRZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24098. designer.SetDataSource("HotelSGRDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24099. designer.SetDataSource("HotelSGRZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24100. }
  24101. else
  24102. {
  24103. hideRowsList.Add(Row + startIndex + HideRows);
  24104. // ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  24105. }
  24106. HideRows += 2;
  24107. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("JSES"));
  24108. if (leftBindData != null)
  24109. {
  24110. ////JS/ES
  24111. designer.SetDataSource("HotelJSESDRCB", leftBindData.cb);
  24112. designer.SetDataSource("HotelJSESRS", leftBindData.rs);
  24113. designer.SetDataSource("HotelJSESXS", leftBindData.xs);
  24114. designer.SetDataSource("HotelJSESCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24115. designer.SetDataSource("HotelJSESDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24116. designer.SetDataSource("HotelJSESZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24117. designer.SetDataSource("HotelJSESDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24118. designer.SetDataSource("HotelJSESZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24119. }
  24120. else
  24121. {
  24122. hideRowsList.Add(Row + startIndex + HideRows);
  24123. // ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  24124. }
  24125. HideRows += 2;
  24126. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("SUITE"));
  24127. if (leftBindData != null)
  24128. {
  24129. ////SUITE
  24130. designer.SetDataSource("HotelSUITEDRCB", leftBindData.cb);
  24131. designer.SetDataSource("HotelSUITERS", leftBindData.rs);
  24132. designer.SetDataSource("HotelSUITEXS", leftBindData.xs);
  24133. designer.SetDataSource("HotelSUITECB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24134. designer.SetDataSource("HotelSUITEDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24135. designer.SetDataSource("HotelSUITEZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24136. designer.SetDataSource("HotelSUITEDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24137. designer.SetDataSource("HotelSUITEZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24138. }
  24139. else
  24140. {
  24141. hideRowsList.Add(Row + startIndex + HideRows);
  24142. // ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  24143. }
  24144. HideRows += 2;
  24145. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("地接"));
  24146. if (leftBindData != null)
  24147. {
  24148. designer.SetDataSource("DJDRCB", leftBindData.cb);
  24149. designer.SetDataSource("DJRS", leftBindData.rs);
  24150. designer.SetDataSource("DJXS", leftBindData.xs);
  24151. designer.SetDataSource("DJCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24152. designer.SetDataSource("DJDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24153. designer.SetDataSource("DJZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24154. designer.SetDataSource("DJDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24155. designer.SetDataSource("DJZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24156. }
  24157. else
  24158. {
  24159. hideRowsList.Add(Row + startIndex + HideRows);
  24160. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  24161. }
  24162. HideRows += 2;
  24163. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("火车票"));
  24164. if (leftBindData != null)
  24165. {
  24166. designer.SetDataSource("HCPCB", leftBindData.cb);
  24167. designer.SetDataSource("HCPRS", leftBindData.rs);
  24168. designer.SetDataSource("HCPXS", leftBindData.xs);
  24169. designer.SetDataSource("HCPZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24170. designer.SetDataSource("HCPDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24171. designer.SetDataSource("HCPZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24172. designer.SetDataSource("HCPDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24173. designer.SetDataSource("HCPZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24174. }
  24175. else
  24176. {
  24177. hideRowsList.Add(Row + startIndex + HideRows);
  24178. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  24179. }
  24180. HideRows += 2;
  24181. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("船票"));
  24182. if (leftBindData != null)
  24183. {
  24184. designer.SetDataSource("CPCB", leftBindData.cb);
  24185. designer.SetDataSource("CPRS", leftBindData.rs);
  24186. designer.SetDataSource("CPXS", leftBindData.xs);
  24187. designer.SetDataSource("CPZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24188. designer.SetDataSource("CPDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24189. designer.SetDataSource("CPZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24190. designer.SetDataSource("CPDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24191. designer.SetDataSource("CPZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24192. }
  24193. else
  24194. {
  24195. hideRowsList.Add(Row + startIndex + HideRows);
  24196. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  24197. }
  24198. HideRows += 2;
  24199. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("公务单人"));
  24200. if (leftBindData != null)
  24201. {
  24202. designer.SetDataSource("GWDRCD", leftBindData.cb);
  24203. designer.SetDataSource("GWRS", leftBindData.rs);
  24204. designer.SetDataSource("GWXS", leftBindData.xs);
  24205. designer.SetDataSource("GWCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24206. designer.SetDataSource("GWDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24207. designer.SetDataSource("GWZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24208. designer.SetDataSource("GWDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24209. designer.SetDataSource("GWZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24210. }
  24211. else
  24212. {
  24213. hideRowsList.Add(Row + startIndex + HideRows);
  24214. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  24215. }
  24216. HideRows += 2;
  24217. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("零用金"));
  24218. if (leftBindData != null)
  24219. {
  24220. designer.SetDataSource("LYJDRCB", leftBindData.cb);
  24221. designer.SetDataSource("LYJRS", leftBindData.rs);
  24222. designer.SetDataSource("LYJXS", leftBindData.xs);
  24223. designer.SetDataSource("LYJCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24224. designer.SetDataSource("LYJDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24225. designer.SetDataSource("LYJZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24226. designer.SetDataSource("LYJDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24227. designer.SetDataSource("LYJZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24228. }
  24229. else
  24230. {
  24231. hideRowsList.Add(Row + startIndex + HideRows);
  24232. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  24233. }
  24234. #endregion
  24235. #region A段Right信息
  24236. var right = dto.rightInfo.Find(x => x.Type == "A");
  24237. if (right == null)
  24238. {
  24239. return Ok(jw);
  24240. }
  24241. HideRows += 4;
  24242. var rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 TBR"));
  24243. if (rightBindData != null)
  24244. {
  24245. //经济舱 + 双人间 TBR
  24246. designer.SetDataSource("lblJJCTBRDRCB", rightBindData.cb);
  24247. designer.SetDataSource("txtJJCTBRRS", rightBindData.rs);
  24248. designer.SetDataSource("lblJJCTBRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24249. designer.SetDataSource("lblJJCTBRDRBJ", rightBindData.bj);
  24250. designer.SetDataSource("lblJJCTBRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24251. designer.SetDataSource("lblJJCTBRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24252. designer.SetDataSource("lblJJCTBRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24253. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24254. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24255. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24256. }
  24257. else
  24258. {
  24259. hideRowsList.Add(Row + startIndex + HideRows);
  24260. }
  24261. HideRows += 2;
  24262. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 SGR"));
  24263. if (rightBindData != null)
  24264. {
  24265. //经济舱 + 单人间 SGR
  24266. designer.SetDataSource("lblJJCSGRDRCB", rightBindData.cb);
  24267. designer.SetDataSource("txtJJCSGRRS", rightBindData.rs);
  24268. designer.SetDataSource("lblJJCSGRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24269. designer.SetDataSource("lblJJCSGRDRBJ", rightBindData.bj);
  24270. designer.SetDataSource("lblJJCSGRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24271. designer.SetDataSource("lblJJCSGRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24272. designer.SetDataSource("lblJJCSGRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24273. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24274. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24275. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24276. }
  24277. else
  24278. {
  24279. hideRowsList.Add(Row + startIndex + HideRows);
  24280. }
  24281. HideRows += 2;
  24282. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 SGR"));
  24283. if (rightBindData != null)
  24284. {
  24285. //公务舱 + 单人间 SGR
  24286. designer.SetDataSource("lblGWCSGRCB", rightBindData.cb);
  24287. designer.SetDataSource("lblGWCSGRRS", rightBindData.rs);
  24288. designer.SetDataSource("lblGWCSGRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24289. designer.SetDataSource("lblGWCSGRDRBJ", rightBindData.bj);
  24290. designer.SetDataSource("lblGWCSGRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24291. designer.SetDataSource("lblGWCSGRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24292. designer.SetDataSource("lblGWCSGRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24293. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24294. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24295. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24296. }
  24297. else
  24298. {
  24299. hideRowsList.Add(Row + startIndex + HideRows);
  24300. }
  24301. HideRows += 2;
  24302. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 JS/ES"));
  24303. if (rightBindData != null)
  24304. {
  24305. //公务舱 + 小套房 JSES
  24306. designer.SetDataSource("lblGWCJSESDRCB", rightBindData.cb);
  24307. designer.SetDataSource("txtGWCJSESRS", rightBindData.rs);
  24308. designer.SetDataSource("lblGWCJSESZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24309. designer.SetDataSource("lblGWCJSESDRBJ", rightBindData.bj);
  24310. designer.SetDataSource("lblGWCJSESZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24311. designer.SetDataSource("lblGWCJSESDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24312. designer.SetDataSource("lblGWCJSESZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24313. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24314. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24315. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24316. }
  24317. else
  24318. {
  24319. hideRowsList.Add(Row + startIndex + HideRows);
  24320. }
  24321. HideRows += 2;
  24322. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 SUITE"));
  24323. if (rightBindData != null)
  24324. {
  24325. //公务舱 + 小套房 JSES
  24326. designer.SetDataSource("lblGWCSUITEDRCB", rightBindData.cb);
  24327. designer.SetDataSource("txtGWCSUITERS", rightBindData.rs);
  24328. designer.SetDataSource("lblGWCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24329. designer.SetDataSource("lblGWCSUITEDRBJ", rightBindData.bj);
  24330. designer.SetDataSource("lblGWCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24331. designer.SetDataSource("lblGWCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24332. designer.SetDataSource("lblGWCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24333. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24334. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24335. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24336. }
  24337. else
  24338. {
  24339. hideRowsList.Add(Row + startIndex + HideRows);
  24340. }
  24341. HideRows += 2;
  24342. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 SUITE"));
  24343. if (rightBindData != null)
  24344. {
  24345. //经济舱 + 大套房
  24346. designer.SetDataSource("lblJJCSUITEDRCB", rightBindData.cb);
  24347. designer.SetDataSource("txtJJCSUITERS", rightBindData.rs);
  24348. designer.SetDataSource("lblJJCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24349. designer.SetDataSource("lblJJCSUITEDRBJ", rightBindData.bj);
  24350. designer.SetDataSource("lblJJCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24351. designer.SetDataSource("lblJJCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24352. designer.SetDataSource("lblJJCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24353. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24354. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24355. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24356. }
  24357. else
  24358. {
  24359. hideRowsList.Add(Row + startIndex + HideRows);
  24360. }
  24361. HideRows += 2;
  24362. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("头等舱 JS/ES"));
  24363. if (rightBindData != null)
  24364. {
  24365. //头等舱 + 小套房 JSES
  24366. designer.SetDataSource("lblTDCJSESDRCB", rightBindData.cb);
  24367. designer.SetDataSource("txtTDCJSESRS", rightBindData.rs);
  24368. designer.SetDataSource("lblTDCJSESZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24369. designer.SetDataSource("lblTDCJSESDRBJ", rightBindData.bj);
  24370. designer.SetDataSource("lblTDCJSESZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24371. designer.SetDataSource("lblTDCJSESDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24372. designer.SetDataSource("lblTDCJSESZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24373. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24374. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24375. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24376. }
  24377. else
  24378. {
  24379. hideRowsList.Add(Row + startIndex + HideRows);
  24380. }
  24381. HideRows += 2;
  24382. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("头等舱 SUITE"));
  24383. if (rightBindData != null)
  24384. {
  24385. //头等舱 + 大套房
  24386. designer.SetDataSource("lblTDCSUITEDRCB", rightBindData.cb);
  24387. designer.SetDataSource("txtTDCSUITERS", rightBindData.rs);
  24388. designer.SetDataSource("lblTDCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24389. designer.SetDataSource("lblTDCSUITEDRBJ", rightBindData.bj);
  24390. designer.SetDataSource("lblTDCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24391. designer.SetDataSource("lblTDCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24392. designer.SetDataSource("lblTDCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24393. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24394. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24395. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24396. }
  24397. else
  24398. {
  24399. hideRowsList.Add(Row + startIndex + HideRows);
  24400. }
  24401. #endregion
  24402. #region B段标题清空
  24403. designer.SetDataSource("CostBDRCB", "");
  24404. designer.SetDataSource("CostBRS", "");
  24405. designer.SetDataSource("CostBXS", "");
  24406. designer.SetDataSource("CostBZCB", "");
  24407. designer.SetDataSource("CostBDRBJ", "");
  24408. designer.SetDataSource("CostBZBJ", "");
  24409. designer.SetDataSource("CostBDRLR", "");
  24410. designer.SetDataSource("CostBZLR", "");
  24411. designer.SetDataSource("CostBDRCBOM", "");
  24412. designer.SetDataSource("CostBRSOM", "");
  24413. designer.SetDataSource("CostBZCBOM", "");
  24414. designer.SetDataSource("CostBDRBJOM", "");
  24415. designer.SetDataSource("CostBZBJOM", "");
  24416. designer.SetDataSource("CostBDRLROM", "");
  24417. designer.SetDataSource("CostBZLROM", "");
  24418. #endregion
  24419. designer.SetDataSource("HotelTBRName", "酒店TBR单间成本(CNY)");
  24420. designer.SetDataSource("HotelSGRName", "酒店SGR单间成本(CNY)");
  24421. designer.SetDataSource("HotelJSESName", "酒店JSES单间成本(CNY)");
  24422. designer.SetDataSource("HotelSUITEName", "酒店SUITE单间成本(CNY)");
  24423. designer.SetDataSource("DJName", "地接(CNY)");
  24424. designer.SetDataSource("HCPName", "地接-火车票(CNY)");
  24425. designer.SetDataSource("CPName", "地接-船票(CNY)");
  24426. designer.SetDataSource("GWName", "公务(CNY)");
  24427. designer.SetDataSource("YQHName", "邀请函(CNY)");
  24428. designer.SetDataSource("LYJName", "零用金(CNY)");
  24429. designer.SetDataSource("HSName", "核酸检测(CNY)");
  24430. designer.SetDataSource("AirGWCName", "机票-公务舱(CNY)");
  24431. designer.SetDataSource("AirJJCName", "机票-经济舱(CNY)");
  24432. designer.SetDataSource("AirTDCName", "机票-头等舱(CNY)");
  24433. designer.SetDataSource("BXName", "保险(CNY)");
  24434. designer.SetDataSource("VisaName", "签证(CNY)");
  24435. #region B段基本数据
  24436. if (dto.costType == "B")
  24437. {
  24438. left = dto.leftInfo.Find(x => x.Type == "B");
  24439. if (left == null)
  24440. {
  24441. return Ok(jw);
  24442. }
  24443. #region B段left数据
  24444. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("核酸"));
  24445. if (leftBindData != null)
  24446. {
  24447. designer.SetDataSource("BHSDRCB", leftBindData.cb);
  24448. designer.SetDataSource("BHSRS", leftBindData.rs);
  24449. designer.SetDataSource("BHSXS", leftBindData.xs);
  24450. designer.SetDataSource("BHSZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24451. designer.SetDataSource("BHSDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24452. designer.SetDataSource("BHSZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24453. designer.SetDataSource("BHSDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24454. designer.SetDataSource("BHSZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24455. }
  24456. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("经济舱"));
  24457. if (leftBindData != null)
  24458. {
  24459. designer.SetDataSource("BJPJJCCB", leftBindData.cb);
  24460. designer.SetDataSource("BJPJJCPnum", leftBindData.rs);
  24461. designer.SetDataSource("BJPJJCXS", leftBindData.xs);
  24462. designer.SetDataSource("BJPJJCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24463. designer.SetDataSource("BJPJJCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24464. designer.SetDataSource("BJPJJCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24465. designer.SetDataSource("BJPJJCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24466. designer.SetDataSource("BJPJJCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24467. }
  24468. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("公务舱"));
  24469. if (leftBindData != null)
  24470. {
  24471. designer.SetDataSource("BJPGWCCB", leftBindData.cb);
  24472. designer.SetDataSource("BJPGWCPNum", leftBindData.rs);
  24473. designer.SetDataSource("BJPGWCXS", leftBindData.xs);
  24474. designer.SetDataSource("BJPGWCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24475. designer.SetDataSource("BJPGWCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24476. designer.SetDataSource("BJPGWCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24477. designer.SetDataSource("BJPGWCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24478. designer.SetDataSource("BJPGWCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24479. }
  24480. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("头等舱"));
  24481. if (leftBindData != null)
  24482. {
  24483. designer.SetDataSource("BJPTDCCB", leftBindData.cb);
  24484. designer.SetDataSource("BJPTDCPNum", leftBindData.rs);
  24485. designer.SetDataSource("BJPTDCXS", leftBindData.xs);
  24486. designer.SetDataSource("BJPTDCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24487. designer.SetDataSource("BJPTDCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24488. designer.SetDataSource("BJPTDCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24489. designer.SetDataSource("BJPTDCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24490. designer.SetDataSource("BJPTDCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24491. }
  24492. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("火车票"));
  24493. if (leftBindData != null)
  24494. {
  24495. designer.SetDataSource("BHCPCB", leftBindData.cb);
  24496. designer.SetDataSource("BHCPRS", leftBindData.rs);
  24497. designer.SetDataSource("BHCPXS", leftBindData.xs);
  24498. designer.SetDataSource("BHCPZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24499. designer.SetDataSource("BHCPDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24500. designer.SetDataSource("BHCPZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24501. designer.SetDataSource("BHCPDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24502. designer.SetDataSource("BHCPZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24503. }
  24504. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("船票"));
  24505. if (leftBindData != null)
  24506. {
  24507. designer.SetDataSource("BCPCB", leftBindData.cb);
  24508. designer.SetDataSource("BCPRS", leftBindData.rs);
  24509. designer.SetDataSource("BCPXS", leftBindData.xs);
  24510. designer.SetDataSource("BCPZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24511. designer.SetDataSource("BCPDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24512. designer.SetDataSource("BCPZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24513. designer.SetDataSource("BCPDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24514. designer.SetDataSource("BCPZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24515. }
  24516. //TBR
  24517. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("TBR"));
  24518. if (leftBindData != null)
  24519. {
  24520. designer.SetDataSource("BHotelTBRDRCB", leftBindData.cb);
  24521. designer.SetDataSource("BHotelTBRRS", leftBindData.rs);
  24522. designer.SetDataSource("BHotelTBRXS", leftBindData.xs);
  24523. designer.SetDataSource("BHotelTBRCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24524. designer.SetDataSource("BHotelTBRDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24525. designer.SetDataSource("BHotelTBRZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24526. designer.SetDataSource("BHotelTBRDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24527. designer.SetDataSource("BHotelTBRZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24528. }
  24529. //SGR
  24530. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("SGR"));
  24531. if (leftBindData != null)
  24532. {
  24533. designer.SetDataSource("BHotelSGRDRCB", leftBindData.cb);
  24534. designer.SetDataSource("BHotelSGRRS", leftBindData.rs);
  24535. designer.SetDataSource("BHotelSGRXS", leftBindData.xs);
  24536. designer.SetDataSource("BHotelSGRCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24537. designer.SetDataSource("BHotelSGRDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24538. designer.SetDataSource("BHotelSGRZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24539. designer.SetDataSource("BHotelSGRDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24540. designer.SetDataSource("BHotelSGRZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24541. }
  24542. //JS/ES
  24543. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("JSES"));
  24544. if (leftBindData != null)
  24545. {
  24546. designer.SetDataSource("BHotelJSESDRCB", leftBindData.cb);
  24547. designer.SetDataSource("BHotelJSESRS", leftBindData.rs);
  24548. designer.SetDataSource("BHotelJSESXS", leftBindData.xs);
  24549. designer.SetDataSource("BHotelJSESCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24550. designer.SetDataSource("BHotelJSESDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24551. designer.SetDataSource("BHotelJSESZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24552. designer.SetDataSource("BHotelJSESDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24553. designer.SetDataSource("BHotelJSESZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24554. }
  24555. //SUITE
  24556. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("SUITE"));
  24557. if (leftBindData != null)
  24558. {
  24559. designer.SetDataSource("BHotelSUITEDRCB", leftBindData.cb);
  24560. designer.SetDataSource("BHotelSUITERS", leftBindData.rs);
  24561. designer.SetDataSource("BHotelSUITEXS", leftBindData.xs);
  24562. designer.SetDataSource("BHotelSUITECB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24563. designer.SetDataSource("BHotelSUITEDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24564. designer.SetDataSource("BHotelSUITEZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24565. designer.SetDataSource("BHotelSUITEDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24566. designer.SetDataSource("BHotelSUITEZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24567. }
  24568. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("地接"));
  24569. if (leftBindData != null)
  24570. {
  24571. designer.SetDataSource("BDJDRCB", leftBindData.cb);
  24572. designer.SetDataSource("BDJRS", leftBindData.rs);
  24573. designer.SetDataSource("BDJXS", leftBindData.xs);
  24574. designer.SetDataSource("BDJCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24575. designer.SetDataSource("BDJDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24576. designer.SetDataSource("BDJZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24577. designer.SetDataSource("BDJDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24578. designer.SetDataSource("BDJZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24579. }
  24580. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("公务单人"));
  24581. if (leftBindData != null)
  24582. {
  24583. designer.SetDataSource("BGWDRCD", leftBindData.cb);
  24584. designer.SetDataSource("BGWRS", leftBindData.rs);
  24585. designer.SetDataSource("BGWXS", leftBindData.xs);
  24586. designer.SetDataSource("BGWCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24587. designer.SetDataSource("BGWDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24588. designer.SetDataSource("BGWZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24589. designer.SetDataSource("BGWDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24590. designer.SetDataSource("BGWZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24591. }
  24592. #region 优化方案
  24593. //Dictionary<string, object> excelBind = new Dictionary<string, object>();
  24594. //excelBind.Add("零用金", new {
  24595. //cb="",
  24596. //rs="",
  24597. //xs ="",
  24598. //zcb = "",
  24599. //});
  24600. #endregion
  24601. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("零用金"));
  24602. if (leftBindData != null)
  24603. {
  24604. designer.SetDataSource("BLYJDRCB", leftBindData.cb);
  24605. designer.SetDataSource("BLYJRS", leftBindData.rs);
  24606. designer.SetDataSource("BLYJXS", leftBindData.xs);
  24607. designer.SetDataSource("BLYJCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  24608. designer.SetDataSource("BLYJDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  24609. designer.SetDataSource("BLYJZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  24610. designer.SetDataSource("BLYJDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  24611. designer.SetDataSource("BLYJZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  24612. }
  24613. #endregion
  24614. #region B段Right信息
  24615. right = dto.rightInfo.Find(x => x.Type == "B");
  24616. if (right == null)
  24617. {
  24618. return Ok(jw);
  24619. }
  24620. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 TBR"));
  24621. if (rightBindData != null)
  24622. {
  24623. //经济舱 + 双人间 TBR
  24624. designer.SetDataSource("BlblJJCTBRDRCB", rightBindData.cb);
  24625. designer.SetDataSource("BtxtJJCTBRRS", rightBindData.rs);
  24626. designer.SetDataSource("BlblJJCTBRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24627. designer.SetDataSource("BlblJJCTBRDRBJ", rightBindData.bj);
  24628. designer.SetDataSource("BlblJJCTBRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24629. designer.SetDataSource("BlblJJCTBRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24630. designer.SetDataSource("BlblJJCTBRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24631. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24632. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24633. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24634. }
  24635. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 SGR"));
  24636. if (rightBindData != null)
  24637. {
  24638. //经济舱 + 单人间 SGR
  24639. designer.SetDataSource("BlblJJCSGRDRCB", rightBindData.cb);
  24640. designer.SetDataSource("BtxtJJCSGRRS", rightBindData.rs);
  24641. designer.SetDataSource("BlblJJCSGRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24642. designer.SetDataSource("BlblJJCSGRDRBJ", rightBindData.bj);
  24643. designer.SetDataSource("BlblJJCSGRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24644. designer.SetDataSource("BlblJJCSGRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24645. designer.SetDataSource("BlblJJCSGRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24646. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24647. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24648. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24649. }
  24650. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 SGR"));
  24651. if (rightBindData != null)
  24652. {
  24653. //公务舱 + 单人间 SGR
  24654. designer.SetDataSource("BlblGWCSGRCB", rightBindData.cb);
  24655. designer.SetDataSource("BlblGWCSGRRS", rightBindData.rs);
  24656. designer.SetDataSource("BlblGWCSGRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24657. designer.SetDataSource("BlblGWCSGRDRBJ", rightBindData.bj);
  24658. designer.SetDataSource("BlblGWCSGRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24659. designer.SetDataSource("BlblGWCSGRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24660. designer.SetDataSource("BlblGWCSGRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24661. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24662. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24663. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24664. }
  24665. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 JS/ES"));
  24666. if (rightBindData != null)
  24667. {
  24668. //公务舱 + 小套房 JSES
  24669. designer.SetDataSource("BlblGWCJSESDRCB", rightBindData.cb);
  24670. designer.SetDataSource("BtxtGWCJSESRS", rightBindData.rs);
  24671. designer.SetDataSource("BlblGWCJSESZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24672. designer.SetDataSource("BlblGWCJSESDRBJ", rightBindData.bj);
  24673. designer.SetDataSource("BlblGWCJSESZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24674. designer.SetDataSource("BlblGWCJSESDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24675. designer.SetDataSource("BlblGWCJSESZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24676. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24677. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24678. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24679. }
  24680. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 SUITE"));
  24681. if (rightBindData != null)
  24682. {
  24683. //公务舱 + 小套房 JSES
  24684. designer.SetDataSource("BlblGWCSUITEDRCB", rightBindData.cb);
  24685. designer.SetDataSource("BtxtGWCSUITERS", rightBindData.rs);
  24686. designer.SetDataSource("BlblGWCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24687. designer.SetDataSource("BlblGWCSUITEDRBJ", rightBindData.bj);
  24688. designer.SetDataSource("BlblGWCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24689. designer.SetDataSource("BlblGWCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24690. designer.SetDataSource("BlblGWCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24691. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24692. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24693. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24694. }
  24695. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 SUITE"));
  24696. if (rightBindData != null)
  24697. {
  24698. //经济舱 + 大套房
  24699. designer.SetDataSource("BlblJJCSUITEDRCB", rightBindData.cb);
  24700. designer.SetDataSource("BtxtJJCSUITERS", rightBindData.rs);
  24701. designer.SetDataSource("BlblJJCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24702. designer.SetDataSource("BlblJJCSUITEDRBJ", rightBindData.bj);
  24703. designer.SetDataSource("BlblJJCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24704. designer.SetDataSource("BlblJJCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24705. designer.SetDataSource("BlblJJCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24706. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24707. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24708. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24709. }
  24710. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("头等舱 JS/ES"));
  24711. if (rightBindData != null)
  24712. {
  24713. //头等舱 + 小套房 JSES
  24714. designer.SetDataSource("BlblTDCJSESDRCB", rightBindData.cb);
  24715. designer.SetDataSource("BtxtTDCJSESRS", rightBindData.rs);
  24716. designer.SetDataSource("BlblTDCJSESZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24717. designer.SetDataSource("BlblTDCJSESDRBJ", rightBindData.bj);
  24718. designer.SetDataSource("BlblTDCJSESZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24719. designer.SetDataSource("BlblTDCJSESDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24720. designer.SetDataSource("BlblTDCJSESZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24721. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24722. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24723. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24724. }
  24725. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("头等舱 SUITE"));
  24726. if (rightBindData != null)
  24727. {
  24728. //头等舱 + 大套房
  24729. designer.SetDataSource("BlblTDCSUITEDRCB", rightBindData.cb);
  24730. designer.SetDataSource("BtxtTDCSUITERS", rightBindData.rs);
  24731. designer.SetDataSource("BlblTDCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  24732. designer.SetDataSource("BlblTDCSUITEDRBJ", rightBindData.bj);
  24733. designer.SetDataSource("BlblTDCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  24734. designer.SetDataSource("BlblTDCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  24735. designer.SetDataSource("BlblTDCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  24736. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  24737. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  24738. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  24739. }
  24740. #endregion
  24741. #region 标题
  24742. designer.SetDataSource("CostBDRCB", "单人成本");
  24743. designer.SetDataSource("CostBRS", "人数");
  24744. designer.SetDataSource("CostBXS", "系数");
  24745. designer.SetDataSource("CostBZCB", "总成本");
  24746. designer.SetDataSource("CostBDRBJ", "单人报价");
  24747. designer.SetDataSource("CostBZBJ", "总报价");
  24748. designer.SetDataSource("CostBDRLR", "单人利润");
  24749. designer.SetDataSource("CostBZLR", "总利润");
  24750. designer.SetDataSource("CostBDRCBOM", "单人成本");
  24751. designer.SetDataSource("CostBRSOM", "人数");
  24752. designer.SetDataSource("CostBZCBOM", "总成本");
  24753. designer.SetDataSource("CostBDRBJOM", "单人报价");
  24754. designer.SetDataSource("CostBZBJOM", "总报价");
  24755. designer.SetDataSource("CostBDRLROM", "单人利润");
  24756. designer.SetDataSource("CostBZLROM", "总利润");
  24757. #endregion
  24758. }
  24759. #endregion
  24760. designer.SetDataSource("TzZCB2", TzZCB2);
  24761. designer.SetDataSource("TzZBJ2", TzZBJ2);
  24762. designer.SetDataSource("TzZLR2", TzZLR2);
  24763. string[] dataSourceKeys = new string[]
  24764. {
  24765. "VF",
  24766. "TGS",
  24767. "TGOF",
  24768. "TGM",
  24769. "TGA",
  24770. "TGTF",
  24771. "TGEF",
  24772. "CFM",
  24773. "CFOF",
  24774. "B",
  24775. "L",
  24776. "D",
  24777. "TBR",
  24778. "SGR",
  24779. "JSES",
  24780. "Suite",
  24781. "TV",
  24782. "1L",
  24783. "IF",
  24784. "EF",
  24785. "BRF",
  24786. "TE",
  24787. "TGT",
  24788. "DRVT",
  24789. "PC",
  24790. "TLF",
  24791. "ECT"
  24792. };
  24793. foreach (var item in dataSourceKeys)
  24794. {
  24795. Func<TitleModel, bool> expr = x => x.label.Replace(" ", "").Replace("/", "") == item
  24796. || x.label.Replace(" ", "").Replace("/", "").ToUpper() == item.ToUpper();
  24797. var find = dto.titleModel.FirstOrDefault(expr);
  24798. if (find != null)
  24799. {
  24800. designer.SetDataSource(item, find.text);
  24801. }
  24802. else
  24803. {
  24804. designer.SetDataSource(item, 0);
  24805. }
  24806. }
  24807. designer.SetDataSource(dt);
  24808. //根据数据源处理生成报表内容
  24809. designer.Process();
  24810. designer.Workbook.Worksheets[0].Name = "费用明细";
  24811. designer.Workbook.Worksheets[1].Name = "费用总核算";
  24812. Worksheet sheet = designer.Workbook.Worksheets[0];
  24813. #region 隐藏舱位
  24814. var settingAir = new[]
  24815. {
  24816. new { key = "经济舱", index = 7 },
  24817. new { key = "公务舱", index = 19 },
  24818. new { key = "头等舱", index = 11 }
  24819. };
  24820. var airType = _sqlSugar.Queryable<Grp_TourClientList>()
  24821. .LeftJoin<Sys_SetData>((c, s) => s.IsDel == 0 && c.ShippingSpaceTypeId == s.Id)
  24822. .Where((c, s) => c.IsDel == 0 && c.DiId == di.Id)
  24823. .Select((c, s) => s.Name)
  24824. .ToList()
  24825. .GroupBy(x => x)
  24826. .Select(x => x.Key);
  24827. foreach (var item in settingAir)
  24828. {
  24829. if (!airType.Contains(item.key))
  24830. {
  24831. hideRowsList.Add(item.index);
  24832. }
  24833. }
  24834. #endregion
  24835. foreach (var Rowindex in hideRowsList)
  24836. {
  24837. ws.Cells.HideRows(Rowindex, 2);
  24838. }
  24839. ws = designer.Workbook.Worksheets[0];
  24840. foreach (var Column in hideColumnList)
  24841. {
  24842. ws.Cells.HideColumns(Column, 1);
  24843. }
  24844. byte[] bytes = null;
  24845. string strFileName = di.TeamName + "-团组-成本.xls";
  24846. using (MemoryStream stream = new MemoryStream())
  24847. {
  24848. designer.Workbook.Save(stream, Aspose.Cells.SaveFormat.Xlsx);
  24849. bytes = stream.ToArray();
  24850. }
  24851. return Ok(JsonView(true, "", new
  24852. {
  24853. Data = bytes,
  24854. strFileName,
  24855. }));
  24856. }
  24857. /// <summary>
  24858. /// 导出客户报表
  24859. /// </summary>
  24860. /// <returns></returns>
  24861. [HttpPost]
  24862. public async Task<IActionResult> ExportClientWordFile(ExportClientWordFileDto dto)
  24863. {
  24864. var jw = JsonView(false);
  24865. if (dto.Diid == 0)
  24866. {
  24867. return Ok(JsonView(false, "请传递团组id"));
  24868. }
  24869. var deleInfo = await _groupRepository.PostGroupInfo(new GroupInfoDto { Id = dto.Diid, PortType = 1 });
  24870. if (deleInfo.Code != 0)
  24871. {
  24872. return Ok(JsonView(false, "团组信息查询失败!"));
  24873. }
  24874. var di = deleInfo.Data as DelegationInfoWebView;
  24875. if (di == null)
  24876. {
  24877. return Ok(JsonView(false, "团组信息查询失败!"));
  24878. }
  24879. //文件名
  24880. //string strFileName = di.TeamName + "-团组-客户报价.doc";
  24881. //获取模板
  24882. string tmppath = (AppSettingsHelper.Get("WordBasePath") + "Template/团组-客户报价.doc");
  24883. //载入模板
  24884. Document doc = new Document(tmppath);
  24885. Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
  24886. Dictionary<string, string> DickeyValue = new Dictionary<string, string>();
  24887. DickeyValue.Add("DickeyValue", di.TeamName); //团组名
  24888. var ParameterList = _GroupCostParameterRepository.GetGroupCostParameterListByDiid(dto.Diid);
  24889. var AParameter = ParameterList.Find(x => x.CostType == "A");
  24890. var BParameter = ParameterList.Find(x => x.CostType == "B");
  24891. if (AParameter == null)
  24892. {
  24893. return Ok(JsonView(false, "系数不存在!"));
  24894. }
  24895. string CarGuides, TzNumber, CarGuides1, Meal, SubsidizedMeals, NightRepair, AttractionsTickets, MiscellaneousFees, ATip, TzHotelDesc, Offcial, PettyCash, Visa, TrainTicket, TicketPrice
  24896. , TzAirDesc, TzZCost;
  24897. CarGuides = TzNumber = CarGuides1 = Meal = SubsidizedMeals = NightRepair = AttractionsTickets = MiscellaneousFees = ATip = TzHotelDesc = Offcial = PettyCash = Visa = TrainTicket = TicketPrice
  24898. = TzAirDesc = TzZCost = string.Empty;
  24899. TzNumber = AParameter.CostTypenumber.ToString();
  24900. CarGuides = "RMB " + (AParameter.DJCB * AParameter.DJXS).ToString("#0.00");
  24901. CarGuides1 = dto.CarGuides1;
  24902. Meal = dto.Meal;
  24903. SubsidizedMeals = dto.SubsidizedMeals;
  24904. NightRepair = dto.NightRepair;
  24905. AttractionsTickets = dto.AttractionsTickets;
  24906. MiscellaneousFees = dto.MiscellaneousFees;
  24907. ATip = dto.ATip;
  24908. TzHotelDesc = "";
  24909. Offcial = "RMB " + (AParameter.GWCB * AParameter.GWXS).ToString("#0.00");
  24910. PettyCash = "RMB " + (AParameter.LYJCB * AParameter.LYJXS).ToString("#0.00");
  24911. Visa = "RMB " + (AParameter.VisaCB * AParameter.VisaXS + AParameter.HSCB * AParameter.HSXS + AParameter.BXCB * AParameter.BXXS).ToString("#0.00");
  24912. TrainTicket = "RMB " + (AParameter.HCPCB * AParameter.HCPXS).ToString("#0.00");
  24913. TicketPrice = "RMB " + (AParameter.CPCB * AParameter.CPXS).ToString("#0.00");
  24914. TzAirDesc = "";
  24915. TzZCost = dto.TzZCost;
  24916. var TzHotelDescArr = new string[] { "SGR", "JSES", "SUITE", "TBR" };
  24917. var TzAirDescArr = new string[] { "经济舱", "公务舱" };
  24918. var index = 1;
  24919. var AinfoArr = dto.leftInfo.Find(x => x.Type == "A");
  24920. foreach (var item in TzHotelDescArr)
  24921. {
  24922. if (AinfoArr != null)
  24923. {
  24924. var Ainfo = AinfoArr.leftinfoNumber.Find(x => x.title.Contains(item));
  24925. if (Ainfo != null)
  24926. {
  24927. if (int.Parse(Ainfo.rs) <= 0)
  24928. {
  24929. continue;
  24930. }
  24931. var hotelText = string.Empty;
  24932. switch (item)
  24933. {
  24934. case "SGR":
  24935. hotelText = "单人间";
  24936. break;
  24937. case "JSES":
  24938. hotelText = "小套房";
  24939. break;
  24940. case "SUITE":
  24941. hotelText = "套房";
  24942. break;
  24943. case "TBR":
  24944. hotelText = "双人间";
  24945. break;
  24946. }
  24947. if (item != "TBR")
  24948. {
  24949. 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";
  24950. }
  24951. else
  24952. {
  24953. 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";
  24954. }
  24955. index++;
  24956. }
  24957. }
  24958. }
  24959. index = 1;
  24960. foreach (var item in TzAirDescArr)
  24961. {
  24962. if (AinfoArr != null)
  24963. {
  24964. var Ainfo = AinfoArr.leftinfoNumber.Find(x => x.title.Contains(item));
  24965. if (Ainfo != null)
  24966. {
  24967. if (int.Parse(Ainfo.rs) <= 0)
  24968. {
  24969. continue;
  24970. }
  24971. 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";
  24972. index++;
  24973. }
  24974. }
  24975. }
  24976. if (dto.costType == "B")
  24977. {
  24978. if (BParameter == null)
  24979. {
  24980. return Ok(JsonView(false, "B段系数不存在!"));
  24981. }
  24982. CarGuides = CarGuides.Insert(0, "A段 ") + " B段 RMB" + (BParameter.DJCB * BParameter.DJXS).ToString("#0.00");
  24983. Offcial = Offcial.Insert(0, "A段 ") + " B段 RMB " + (BParameter.GWCB * BParameter.GWXS).ToString("#0.00");
  24984. PettyCash = PettyCash.Insert(0, "A段 ") + " B段 RMB " + (BParameter.LYJCB * BParameter.LYJXS).ToString("#0.00");
  24985. Visa = Visa.Insert(0, "A段 ") + " B段 RMB " + (BParameter.VisaCB * BParameter.VisaXS + BParameter.HSCB * BParameter.HSXS + BParameter.BXCB * BParameter.BXXS).ToString("#0.00");
  24986. TrainTicket = TrainTicket.Insert(0, "A段 ") + " B段 RMB " + (BParameter.HCPCB * BParameter.HCPXS).ToString("#0.00");
  24987. TicketPrice = TicketPrice.Insert(0, "A段 ") + " B段 RMB " + (BParameter.CPCB * BParameter.CPXS).ToString("#0.00");
  24988. AinfoArr = dto.leftInfo.Find(x => x.Type == "B");
  24989. foreach (var item in TzHotelDescArr)
  24990. {
  24991. if (AinfoArr != null)
  24992. {
  24993. TzHotelDesc += "B段信息 \r\n";
  24994. var Ainfo = AinfoArr.leftinfoNumber.Find(x => x.title.Contains(item));
  24995. if (Ainfo != null)
  24996. {
  24997. if (int.Parse(Ainfo.rs) <= 0)
  24998. {
  24999. continue;
  25000. }
  25001. var hotelText = string.Empty;
  25002. switch (item)
  25003. {
  25004. case "SGR":
  25005. hotelText = "单人间";
  25006. break;
  25007. case "JSES":
  25008. hotelText = "小套房";
  25009. break;
  25010. case "SUITE":
  25011. hotelText = "套房";
  25012. break;
  25013. case "TBR":
  25014. hotelText = "双人间";
  25015. break;
  25016. }
  25017. if (item != "TBR")
  25018. {
  25019. 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";
  25020. }
  25021. else
  25022. {
  25023. 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";
  25024. }
  25025. index++;
  25026. }
  25027. TzHotelDesc = TzHotelDesc.Insert(0, "A段信息 \r\n");
  25028. }
  25029. }
  25030. index = 1;
  25031. foreach (var item in TzAirDescArr)
  25032. {
  25033. if (AinfoArr != null)
  25034. {
  25035. var Ainfo = AinfoArr.leftinfoNumber.Find(x => x.title.Contains(item));
  25036. if (Ainfo != null)
  25037. {
  25038. if (int.Parse(Ainfo.rs) <= 0)
  25039. {
  25040. continue;
  25041. }
  25042. 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";
  25043. index++;
  25044. }
  25045. }
  25046. }
  25047. }
  25048. Visa = Visa.Insert(0, "签证及保险(含核酸检测): ");
  25049. DickeyValue.Add("TzNumber", TzNumber); //团组人数
  25050. DickeyValue.Add("CarGuides", CarGuides); //地接单人报价
  25051. DickeyValue.Add("CarGuides1", CarGuides1); // 地接 - 车导费
  25052. DickeyValue.Add("Meal", Meal); // 地接 - 餐费
  25053. DickeyValue.Add("SubsidizedMeals", SubsidizedMeals);// 地接 - 餐补
  25054. DickeyValue.Add("NightRepair", NightRepair); // 地接 - 宿补
  25055. DickeyValue.Add("AttractionsTickets", AttractionsTickets); // 地接 - 景点
  25056. DickeyValue.Add("MiscellaneousFees", MiscellaneousFees); // 地接 - 杂费
  25057. DickeyValue.Add("ATip", ATip); // 地接 - 小费
  25058. DickeyValue.Add("TzHotelDesc", TzHotelDesc); //酒店
  25059. DickeyValue.Add("Offcial", Offcial); // 公务单人报价
  25060. DickeyValue.Add("PettyCash", PettyCash); // 零用金单人报价
  25061. DickeyValue.Add("Visa", Visa); // 签证单人报价
  25062. DickeyValue.Add("TrainTicket", TrainTicket); //火车票
  25063. DickeyValue.Add("TicketPrice", TicketPrice); //船票
  25064. DickeyValue.Add("TzAirDesc", TzAirDesc); //机票
  25065. DickeyValue.Add("TzZCost", TzZCost);
  25066. foreach (var key in DickeyValue.Keys)
  25067. {
  25068. if (doc.Range.Bookmarks[key] != null)
  25069. {
  25070. Bookmark mark = doc.Range.Bookmarks[key];
  25071. mark.Text = DickeyValue[key];
  25072. }
  25073. }
  25074. byte[] bytes = null;
  25075. string strFileName = di.TeamName + "-客户报价.doc";
  25076. using (MemoryStream stream = new MemoryStream())
  25077. {
  25078. doc.Save(stream, Aspose.Words.SaveFormat.Doc);
  25079. bytes = stream.ToArray();
  25080. }
  25081. return Ok(JsonView(true, "", new
  25082. {
  25083. Data = bytes,
  25084. strFileName,
  25085. }));
  25086. }
  25087. /// <summary>
  25088. /// 团组成本 各模块(酒店,地接,机票)成本提示
  25089. /// </summary>
  25090. /// <param name="dto"></param>
  25091. /// <returns></returns>
  25092. [HttpPost]
  25093. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25094. public async Task<IActionResult> PostGroupCostModulePrompt(GroupCostModulePromptDto dto)
  25095. {
  25096. try
  25097. {
  25098. #region 参数验证
  25099. if (dto.DiId < 0)
  25100. {
  25101. return Ok(JsonView(false, "请传入有效的DiId参数!"));
  25102. }
  25103. List<int> cTableIds = new List<int>() {
  25104. 76 ,//酒店预订
  25105. 77 ,//行程
  25106. 79 ,//车/导游地接
  25107. 80 ,//签证
  25108. 81 ,//邀请/公务活
  25109. 82 ,//团组客户保险
  25110. 85 ,//机票预订
  25111. 98 ,//其他款项
  25112. 285 ,//收款退还
  25113. 751 ,//酒店早餐
  25114. 1015 // 超支费用
  25115. };
  25116. if (dto.CTable < 0 && !cTableIds.Contains(dto.CTable))
  25117. {
  25118. return Ok(JsonView(false, "请传入有效的CTable参数!"));
  25119. }
  25120. #endregion
  25121. //Grp_GroupCostParameter 预算表 Grp_GroupCost 详细费用列表
  25122. var _GroupCostParameters = _usersRep._sqlSugar.Queryable<Grp_GroupCostParameter>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).ToList();
  25123. if (_GroupCostParameters.Count <= 0)
  25124. {
  25125. return Ok(JsonView(false, "暂无该团组成本信息!", new List<dynamic>()));
  25126. }
  25127. if (_GroupCostParameters[0].IsShare == 0)
  25128. {
  25129. return Ok(JsonView(false, "该团组成本未完成!", new List<dynamic>()));
  25130. }
  25131. var _GroupCosts = _usersRep._sqlSugar.Queryable<Grp_GroupCost>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  25132. //处理date为空问题
  25133. if (_GroupCosts.Count > 0)
  25134. {
  25135. for (int i = 0; i < _GroupCosts.Count; i++)
  25136. {
  25137. if (string.IsNullOrEmpty(_GroupCosts[i].Date))
  25138. {
  25139. if (i > 0)
  25140. {
  25141. _GroupCosts[i].Date = _GroupCosts[i - 1].Date;
  25142. }
  25143. }
  25144. }
  25145. }
  25146. GroupCostModulePromptView _view = new GroupCostModulePromptView();
  25147. List<GroupCostModulePromptInfo> _ModulePromptInfos = new List<GroupCostModulePromptInfo>(); //机票存储多段
  25148. var currDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  25149. string currCode = "";
  25150. #region currCode 验证
  25151. bool isInt = int.TryParse(_GroupCostParameters[0].Currency, out int intCurrency);
  25152. if (isInt)
  25153. {
  25154. var currData = currDatas.Find(it => it.Id == intCurrency);
  25155. if (currData != null)
  25156. {
  25157. currCode = currData.Name;
  25158. }
  25159. }
  25160. else
  25161. {
  25162. currCode = _GroupCostParameters[0].Currency.Trim();
  25163. }
  25164. #endregion
  25165. //op,酒店单段模式存储
  25166. GroupCostModulePromptInfo _ModulePromptInfo = new GroupCostModulePromptInfo()
  25167. {
  25168. CurrencyCode = currCode,
  25169. Rate = _GroupCostParameters[0].Rate,
  25170. CostType = _GroupCostParameters[0].CostType,
  25171. CostTypeStartTime = Convert.ToDateTime(_GroupCostParameters[0].CostTypeStartTime).ToString("yyyy-MM-dd"),
  25172. CostTypeEndTime = Convert.ToDateTime(_GroupCostParameters[0].CostTypeendTime).ToString("yyyy-MM-dd"),
  25173. CostTypeNumber = _GroupCostParameters[0].CostTypenumber
  25174. };
  25175. List<dynamic> _ModuleSubPromptInfo = new List<dynamic>(); // 存储CTbale != 85 的动态数据
  25176. if (_GroupCostParameters.Count == 2)
  25177. {
  25178. _ModulePromptInfo.CostTypeEndTime = Convert.ToDateTime(_GroupCostParameters[1].CostTypeendTime).ToString("yyyy-MM-dd");
  25179. }
  25180. foreach (var item in _GroupCostParameters)
  25181. {
  25182. decimal _rate = 1;
  25183. decimal _rate1 = item.Rate;
  25184. decimal _scale = 1;
  25185. //decimal _scale = 0.95M; 雷怡 2024-06-11 10:06:08 屏蔽
  25186. #region 处理地接价格比例 总经理 国交部经理 主管 不下调 其他人 下调 5%
  25187. //var userInfo = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.Id == dto.UserId).First();
  25188. //if (userInfo != null)
  25189. //{
  25190. // if (userInfo.DepId == 1 || userInfo.DepId == 7)
  25191. // {
  25192. // if (userInfo.JobPostId == 1 || userInfo.JobPostId == 22 || userInfo.JobPostId == 32)
  25193. // {
  25194. // _scale = 1.00M;
  25195. // }
  25196. // }
  25197. //}
  25198. #endregion
  25199. GroupCostModulePromptInfo modulePromptInfo = new GroupCostModulePromptInfo()
  25200. {
  25201. CurrencyCode = currCode,
  25202. Rate = _rate1,
  25203. CostType = item.CostType,
  25204. CostTypeStartTime = Convert.ToDateTime(item.CostTypeStartTime).ToString("yyyy-MM-dd"),
  25205. CostTypeEndTime = Convert.ToDateTime(item.CostTypeendTime).ToString("yyyy-MM-dd"),
  25206. CostTypeNumber = item.CostTypenumber
  25207. };
  25208. if (_GroupCostParameters.Count > 1)
  25209. {
  25210. modulePromptInfo.CostTypeNumber = item.CostTypenumber;
  25211. }
  25212. else
  25213. {
  25214. modulePromptInfo.CostTypeNumber = item.LYJRS;
  25215. }
  25216. if (dto.CTable == 79)//
  25217. {
  25218. modulePromptInfo.IndividualCost = item.DJCB / modulePromptInfo.CostTypeNumber;
  25219. modulePromptInfo.TotalCost = item.DJCB;
  25220. }
  25221. List<string> costTypes = new List<string>() { "A", "B" };
  25222. List<Grp_GroupCost> _GroupCostsTypeData = new List<Grp_GroupCost>();
  25223. var _GroupCostsDuplicates = _GroupCostParameters.GroupBy(x => x.CostType).Select(y => y.FirstOrDefault());
  25224. if (_GroupCostsDuplicates.Count() == 1)
  25225. {
  25226. _GroupCostsTypeData = _GroupCosts;
  25227. }
  25228. else
  25229. {
  25230. _GroupCostsTypeData = _GroupCosts.Where(it => Convert.ToDateTime(it.Date) >= Convert.ToDateTime(item.CostTypeStartTime) &&
  25231. Convert.ToDateTime(it.Date) <= Convert.ToDateTime(item.CostTypeendTime)).ToList();
  25232. }
  25233. /*
  25234. * 76 酒店预订
  25235. * 77 行程
  25236. * 79 车/导游地接
  25237. * 80 签证
  25238. * 81 邀请/公务活动
  25239. * 82 团组客户保险
  25240. * 85 机票预订
  25241. * 98 其他款项
  25242. * 285 收款退还
  25243. * 751 酒店早餐
  25244. * 1015 超支费用
  25245. */
  25246. switch (dto.CTable)
  25247. {
  25248. case 76: // 酒店预订
  25249. _ModuleSubPromptInfo.AddRange(
  25250. _GroupCostsTypeData.Select(it => new
  25251. {
  25252. it.DAY,
  25253. it.Date,
  25254. it.ACCON,
  25255. it.ITIN,
  25256. it.SGR,
  25257. it.TBR,
  25258. it.JS_ES,
  25259. it.Suite
  25260. })
  25261. );
  25262. break;
  25263. case 79: // 车/导游地接
  25264. _ModuleSubPromptInfo.AddRange(
  25265. _GroupCostsTypeData.Select(it => new
  25266. {
  25267. Date = it.Date, //日期
  25268. CarFee = it.CarCost * _rate * _scale, //车费用
  25269. CarType = it.CarType, //车型
  25270. DriverFee = it.CFS * _rate * _scale, //司机工资
  25271. DriverTipsFee = it.DRVTips * _rate * _scale, //司机小费
  25272. DriverMealSubsidy = it.CFM * _rate * _scale, //司机餐补
  25273. DriverOvertimeFee = it.CFOF * _rate * _scale, //司机超时费用
  25274. GuideFee = it.TGS * _rate * _scale, //导游费用
  25275. GuideOvertimeFee = it.TGOF * _rate * _scale, //导游超时费用
  25276. GuideMealSubsidy = it.TGM * _rate * _scale, //导游餐补
  25277. GuideRoomSubsidy = it.TGA * _rate * _scale, //导游房补
  25278. GuideCarFare = it.TGTF * _rate * _scale, //导游交通费
  25279. GuideSpotFee = it.TGEF * _rate * _scale, //导游景点费
  25280. GuideTipsFee = it.TGTips * _rate * _scale, //导游小费
  25281. Breakfast = it.B * _rate * _scale, //早餐费
  25282. Lunch = it.L * _rate * _scale, //午餐费
  25283. Dinner = it.D * _rate * _scale, //晚餐费
  25284. OfficialActivitiesFee = it.TV * _rate * _scale,//会务活动费 --新加
  25285. OfficialTransFee = it.IF * _rate * _scale, //公务翻译费 --新加
  25286. InvitationFee = it.iL * _rate * _scale, //邀请函费用 --新加
  25287. TicketFee = it.EF * _rate * _scale, //门票费
  25288. TicketRemark = it.EFR, //门票费描述
  25289. DrinksSnacksFruitFee = it.B_R_F * _rate * _scale, //饮料零食水果
  25290. TravelSupplies = it.TE * _rate * _scale, //出行物资
  25291. SpentCash = it.PC * _rate * _scale, //零用金
  25292. LeadersFee = it.TLF * _rate * _scale, //领队费
  25293. ActivitiesFee = it.ECT * _rate * _scale, //会务费 --新加
  25294. })
  25295. );
  25296. break;
  25297. case 85: // 机票
  25298. List<dynamic> datas = new List<dynamic>();
  25299. datas.Add(
  25300. new
  25301. {
  25302. AirType = "经济舱",
  25303. AirNum = item.JJCRS,
  25304. AirDRCB = item.JJCCB,
  25305. AirZCB = (item.JJCRS * item.JJCCB)
  25306. }
  25307. );
  25308. datas.Add(
  25309. new
  25310. {
  25311. AirType = "公务舱",
  25312. AirNum = item.GWCRS,
  25313. AirDRCB = item.GWCCB,
  25314. AirZCB = (item.GWCRS * item.GWCCB)
  25315. }
  25316. );
  25317. var groupCosts = _usersRep._sqlSugar.Queryable<Grp_GroupCost>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  25318. var initDatas = groupCosts.Select(it => new { date = it.Date, week = it.Date.GetWeek() == "" ? "-" : it.Date.GetWeek(), itinerary = it.ITIN }).ToList();
  25319. modulePromptInfo.Data = new
  25320. {
  25321. airFeeData = datas,
  25322. airInitData = initDatas
  25323. };
  25324. _ModulePromptInfos.Add(modulePromptInfo);
  25325. break;
  25326. default:
  25327. break;
  25328. }
  25329. }
  25330. if (dto.CTable != 85)
  25331. {
  25332. _ModulePromptInfo.Data = _ModuleSubPromptInfo;
  25333. _ModulePromptInfos.Add(_ModulePromptInfo);
  25334. }
  25335. _view.ModulePromptInfos = _ModulePromptInfos;
  25336. return Ok(JsonView(true, "操作成功!", _view));
  25337. }
  25338. catch (Exception ex)
  25339. {
  25340. return Ok(JsonView(false, ex.Message));
  25341. }
  25342. }
  25343. /// <summary>
  25344. /// 根据黑屏代码重新生成行程
  25345. /// </summary>
  25346. /// <param name="dto"></param>
  25347. /// <returns></returns>
  25348. [HttpPost]
  25349. public IActionResult CraeteGroupCostTravel(GroupCostInItDto dto)
  25350. {
  25351. var jw = JsonView(false, "Error");
  25352. var Create = _sqlSugar.Queryable<Air_TicketBlackCode>()
  25353. .Where(x => x.IsDel == 0 && x.DiId == dto.Diid)
  25354. .Select(x => new
  25355. {
  25356. x.Id,
  25357. x.Title
  25358. })
  25359. .ToList();
  25360. if (Create.Any())
  25361. {
  25362. jw.Msg = "获取成功!";
  25363. jw.Code = 200;
  25364. jw.Data = new
  25365. {
  25366. BlackCodeListSelect = Create,
  25367. blackCodeIsTrue = true
  25368. };
  25369. }
  25370. else
  25371. {
  25372. jw.Code = 400;
  25373. jw.Data = new
  25374. {
  25375. BlackCodeListSelect = Create,
  25376. blackCodeIsTrue = false,
  25377. };
  25378. }
  25379. return Ok(jw);
  25380. }
  25381. /// <summary>
  25382. /// 根据黑屏代码Id重新生成行程
  25383. /// </summary>
  25384. /// <param name="dto"></param>
  25385. /// <returns></returns>
  25386. [HttpPost]
  25387. public IActionResult CraeteGroupCostTravelById(CraeteGroupCostTravelByIdDto dto)
  25388. {
  25389. var jw = JsonView(false, "Error");
  25390. var result = _GroupCostRepository.CreateGroupCostByBlackCode(dto.DiId, dto.BlackCodeId);
  25391. if (result.Code == 0)
  25392. {
  25393. jw.Msg = "获取成功!";
  25394. jw.Code = 200;
  25395. jw.Data = new
  25396. {
  25397. groupCost = result.Data,
  25398. blackCodeIsTrue = true
  25399. };
  25400. }
  25401. else
  25402. {
  25403. jw.Code = 400;
  25404. jw.Data = new
  25405. {
  25406. groupCost = result.Data,
  25407. blackCodeIsTrue = false,
  25408. };
  25409. }
  25410. return Ok(jw);
  25411. }
  25412. /// <summary>
  25413. /// 成本获取OP历史车费用
  25414. /// </summary>
  25415. /// <param name="dto"></param>
  25416. /// <returns></returns>
  25417. [HttpPost]
  25418. public async Task<IActionResult> GetHistoryCarData(HistoryCarDataDto dto)
  25419. {
  25420. var jw = JsonView(false);
  25421. try
  25422. {
  25423. List<HistoryCarDataView> dbResult = new List<HistoryCarDataView>();
  25424. //获取现有所有车的数据
  25425. if (!dto.Param.IsNullOrWhiteSpace())
  25426. {
  25427. string sql = $@"
  25428. SELECT gdi.TeamName , gctggr.Area, gctggr.PriceName , gctggrc.Id ,gctggrc.Price , gctggrc.DatePrice , gctggrc.PriceContent , gctggrc.Currency , gctggr.ServiceStartTime , gctggr.ServiceEndTime
  25429. FROM Grp_CarTouristGuideGroundReservationsContent gctggrc inner join Grp_CarTouristGuideGroundReservations gctggr on
  25430. gctggrc.CTGGRId = gctggr.Id inner JOIN Grp_DelegationInfo gdi on gctggr.DiId = gdi.Id LEFT JOIN Sys_SetData ssd on ssd.Id = gctggr.PriceType
  25431. 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
  25432. AND gctggr.ServiceEndTime is not NULL
  25433. ORDER by gctggrc.id DESC
  25434. ";
  25435. dbResult = await _sqlSugar.SqlQueryable<HistoryCarDataView>(sql).ToListAsync();
  25436. var numeberResult = await Task.Run(() =>
  25437. {
  25438. var numberArr = dbResult.Where(x => int.TryParse(x.Area, out int number)).ToList();
  25439. _ = dbResult.RemoveAll(x => int.TryParse(x.Area, out int number));
  25440. return numberArr;
  25441. });
  25442. var cityArr = await _sqlSugar.Queryable<Grp_NationalTravelFee>().ToListAsync();
  25443. foreach (var item in numeberResult)
  25444. {
  25445. var find = cityArr.Find(x => x.Id == int.Parse(item.Area)) ?? new Grp_NationalTravelFee
  25446. {
  25447. Country = "数据异常!",
  25448. City = string.Empty,
  25449. };
  25450. item.Area = find.Country + " " + find.City;
  25451. }
  25452. dbResult.AddRange(numeberResult);
  25453. if (dto.Param.Contains("、"))
  25454. {
  25455. var sp = dto.Param.Split("、");
  25456. dbResult = dbResult.AsParallel().WithDegreeOfParallelism(Environment.ProcessorCount)
  25457. .Where(x =>
  25458. {
  25459. return System.Array.Exists(sp, e =>
  25460. {
  25461. bool where = false;
  25462. if (x.Area != null)
  25463. {
  25464. where = x.Area.Contains(e);
  25465. if (x.Area.Contains("尾款") || x.PriceName.Contains("尾款"))
  25466. {
  25467. return false;
  25468. }
  25469. }
  25470. if (x.PriceName != null && !where)
  25471. {
  25472. where = x.PriceName.Contains(e);
  25473. if (x.PriceName.Contains("尾款") || x.PriceName.Contains("尾款"))
  25474. {
  25475. return false;
  25476. }
  25477. }
  25478. return where;
  25479. });
  25480. }).ToList();
  25481. }
  25482. else
  25483. {
  25484. dbResult = dbResult.AsParallel().WithDegreeOfParallelism(Environment.ProcessorCount)
  25485. .Where(x =>
  25486. {
  25487. bool where = false;
  25488. if (x.Area != null)
  25489. {
  25490. where = x.Area.Contains(dto.Param);
  25491. if (x.Area.Contains("尾款") || x.PriceName.Contains("尾款"))
  25492. {
  25493. return false;
  25494. }
  25495. }
  25496. if (x.PriceName != null && !where)
  25497. {
  25498. where = x.PriceName.Contains(dto.Param);
  25499. if (x.PriceName.Contains("尾款") || x.PriceName.Contains("尾款"))
  25500. {
  25501. return false;
  25502. }
  25503. }
  25504. return where;
  25505. }
  25506. )
  25507. .ToList();
  25508. }
  25509. }
  25510. var view = dbResult.Select(x =>
  25511. {
  25512. decimal dp = 0.00M;
  25513. var startB = DateTime.TryParse(x.Start.ToString(), out DateTime startD);
  25514. var endB = DateTime.TryParse(x.End.ToString(), out DateTime endD);
  25515. if (string.IsNullOrWhiteSpace(x.DatePrice))
  25516. {
  25517. if (startB && endB)
  25518. {
  25519. var timesp = endD.Subtract(startD);
  25520. if ((timesp.Days + 1) != 0)
  25521. {
  25522. dp = x.Price / (timesp.Days + 1);
  25523. }
  25524. }
  25525. }
  25526. else
  25527. {
  25528. dp = x.Price;
  25529. }
  25530. return new
  25531. {
  25532. start = startB ? startD.ToString("yyyy-MM-dd") : "",
  25533. end = endB ? endD.ToString("yyyy-MM-dd") : "",
  25534. x.Area,
  25535. x.id,
  25536. price = x.Price.ToString("F2"),
  25537. x.PriceName,
  25538. x.PriceContent,
  25539. x.TeamName,
  25540. x.DatePrice,
  25541. dayPrice = dp.ToString("F2"),
  25542. };
  25543. }).OrderByDescending(x => x.id).ToList();
  25544. jw = JsonView(true, "获取成功!", view);
  25545. }
  25546. catch (Exception e)
  25547. {
  25548. jw = JsonView(false, e.Message);
  25549. }
  25550. return Ok(jw);
  25551. }
  25552. [HttpPost]
  25553. public async Task<IActionResult> SearchGroupByKeyword(SearchGroupByKeywordDto dto)
  25554. {
  25555. var jw = JsonView(true);
  25556. List<DelegationInfoAndIsTrueView> matches = new List<DelegationInfoAndIsTrueView>();
  25557. #region SQL语句
  25558. //if (string.IsNullOrWhiteSpace(dto.Keyword))
  25559. //{
  25560. // matches = _sqlSugar.SqlQueryable<DelegationInfoAndIsTrueView>($@"
  25561. // Select a.Id,TeamName GroupName,b.isTrue From Grp_DelegationInfo a left join (select top 100 percent Diid, CASE
  25562. // WHEN COUNT(*) >= 0 THEN 'True'
  25563. // ELSE 'False' END as isTrue from Grp_GroupCost where Isdel = 0 and date != '' group by Diid) b on a.Id = b.Diid
  25564. // Where TeamName != '' And IsDel = 0 Order By a.VisitStartDate Desc
  25565. // ")
  25566. // .ToList();
  25567. //}
  25568. //else
  25569. //{
  25570. // string likeKey = string.Empty;
  25571. // foreach (var item in dto.Keyword)
  25572. // {
  25573. // likeKey += "%" + item;
  25574. // }
  25575. // likeKey += "%";
  25576. // matches = _sqlSugar.SqlQueryable<DelegationInfoAndIsTrueView>($@"
  25577. // Select a.Id,TeamName GroupName,b.isTrue From Grp_DelegationInfo a left join (select top 100 percent Diid, CASE
  25578. // WHEN COUNT(*) >= 0 THEN 'True'
  25579. // ELSE 'False' END as isTrue from Grp_GroupCost where Isdel = 0 and date != '' group by Diid) b on a.Id = b.Diid
  25580. // Where TeamName != '' And IsDel = 0 And TeamName LIKE '{likeKey}' Order By a.VisitStartDate Desc
  25581. // ")
  25582. // .ToList();
  25583. //}
  25584. #endregion
  25585. var table = _sqlSugar.Ado.UseStoredProcedure().GetDataTable("SearchGroupByKeyword", new
  25586. {
  25587. @KeyWord = dto.Keyword
  25588. });
  25589. if (table != null && table.Rows.Count > 0)
  25590. {
  25591. foreach (DataRow row in table.Rows)
  25592. {
  25593. matches.Add(new DelegationInfoAndIsTrueView
  25594. {
  25595. Id = row.Field<int>("Id"),
  25596. GroupName = row.Field<string>("GroupName"),
  25597. isTrue = row.Field<string>("isTrue")
  25598. });
  25599. }
  25600. }
  25601. if (matches.Any())
  25602. {
  25603. jw.Data = matches;
  25604. }
  25605. else
  25606. {
  25607. jw.Code = 201;
  25608. jw.Msg = "empty list";
  25609. jw.Data = new List<string>(1);
  25610. }
  25611. return Ok(jw);
  25612. }
  25613. /// <summary>
  25614. /// 报价Word下载
  25615. /// </summary>
  25616. /// <param name="dto"></param>
  25617. /// <returns></returns>
  25618. [HttpPost]
  25619. public async Task<IActionResult> GroupQuotationsFileDown(GroupQuotationsFileDownDto dto)
  25620. {
  25621. var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  25622. .FirstAsync(x => x.Id == dto.Diid && x.IsDel == 0);
  25623. if (di == null)
  25624. {
  25625. return Ok(JsonView(false, "团组不存在!"));
  25626. }
  25627. var mainPrice = _GroupCostParameterRepository.GetGroupCostParameterMainByDiid(dto.Diid);
  25628. if (mainPrice == null || mainPrice.IsShare == 0)
  25629. {
  25630. return Ok(JsonView(false, "团组成本不存在!"));
  25631. }
  25632. var costTypeHotelNumbers = await _sqlSugar.Queryable<Grp_CostTypeHotelNumber>()
  25633. .FirstAsync(x => x.Type == "Default" && x.Diid == dto.Diid && x.IsDel == 0);
  25634. if (costTypeHotelNumbers == null)
  25635. {
  25636. return Ok(JsonView(false, "团组成本不存在!"));
  25637. }
  25638. //文件名
  25639. string strFileName = di.TeamName + "-收款账单.doc";
  25640. //获取模板
  25641. string tmppath = (AppSettingsHelper.Get("WordBasePath") + "Template/收款账单(四川)模板.doc");
  25642. //载入模板
  25643. Document doc = new Document(tmppath);
  25644. decimal allPrice = 0.00M;
  25645. string itemStr = string.Empty;
  25646. Dictionary<string, string> airSouer = new Dictionary<string, string>();
  25647. airSouer.Add("经济舱TBR", "经济舱及酒店双人间");
  25648. airSouer.Add("经济舱SGR", "经济舱及酒店单人间");
  25649. airSouer.Add("公务舱SGR", "公务舱及酒店单人间");
  25650. airSouer.Add("公务舱JSES", "公务舱及酒店小套房");
  25651. airSouer.Add("公务舱SUITE", "公务舱及酒店套房");
  25652. airSouer.Add("经济舱SUITE", "经济舱及酒店套房");
  25653. airSouer.Add("头等舱JSES", "头等舱及酒店小套房");
  25654. airSouer.Add("头等舱SUITE", "头等舱及酒店套房");
  25655. airSouer.Add("经济舱JSES", "经济舱及酒店小套房");
  25656. var priceDataList = new List<(string rsName, string cbName, string xsName, string prefix)>
  25657. {
  25658. ("VisaRS", "VisaCB", "VisaXS", "qz"),
  25659. ("BXRS", "BXCB", "BXXS", "bx"),
  25660. ("HCPRS", "HCPCB", "HCPXS", "hcp"),
  25661. ("JJCRS", "JJCCB", "JJCXS", "jjc"),
  25662. ("GWCRS", "GWCCB", "GWCXS", "gwc"),
  25663. ("TDCRS", "TDCCB", "TDCXS", "tdc"),
  25664. ("CPRS", "CPCB", "CPXS", "cp"),
  25665. ("HSRS", "HSCB", "HSXS", "hsjc"),
  25666. ("TBRNumber", "TBRCB", "TBRXS", "tbr"),
  25667. ("SGRNumber", "SGRCB", "SGRXS", "sgr"),
  25668. ("JSESNumber", "JSESCB", "JSESXS", "jses"),
  25669. ("SUITENumber", "SUITECB", "SUITEXS", "suite"),
  25670. ("DJRS", "DJCB", "DJXS", "dj"),
  25671. ("GWRS", "GWCB", "GWXS", "gw"),
  25672. ("LYJRS", "LYJCB", "LYJXS", "lyj"),
  25673. };
  25674. var OtherCostPropertyBJ = new string[] { "qz", "hcp", "cp", "bx", "hsjc", "dj", "gw", "lyj" };
  25675. var rightSum = 0.00M;
  25676. foreach (var (rsName, cbName, xsName, prefix) in priceDataList)
  25677. {
  25678. var rsValue = (int)mainPrice.GetType().GetProperty(rsName).GetValue(mainPrice);
  25679. var cbValue = (decimal)mainPrice.GetType().GetProperty(cbName).GetValue(mainPrice);
  25680. var xsValue = (decimal)mainPrice.GetType().GetProperty(xsName).GetValue(mainPrice);
  25681. if (prefix == "tbr")
  25682. {
  25683. rsValue *= 2;
  25684. cbValue /= 2;
  25685. }
  25686. if (OtherCostPropertyBJ.Contains(prefix))
  25687. {
  25688. rightSum += cbValue * xsValue;
  25689. }
  25690. }
  25691. var hotelRooms = new Dictionary<string, int>
  25692. {
  25693. { "SGR", costTypeHotelNumbers.SGR },
  25694. { "TBR", costTypeHotelNumbers.TBR },
  25695. { "JSES", costTypeHotelNumbers.JSES },
  25696. { "SUITE", costTypeHotelNumbers.SUITE }
  25697. };
  25698. var flights = new Dictionary<string, int>
  25699. {
  25700. { "经济舱", mainPrice.JJCRS },
  25701. { "公务舱", mainPrice.GWCRS },
  25702. { "头等舱", mainPrice.TDCRS }
  25703. };
  25704. var flightRoomMatchingRules = new Dictionary<string, string[]>
  25705. {
  25706. { "经济舱", new[] { "TBR", "SGR", "JSES", "SUITE" } },
  25707. { "公务舱", new[] { "SUITE", "JSES", "SGR" } },
  25708. { "头等舱", new[] { "SUITE", "JSES" } }
  25709. };
  25710. var result = new Dictionary<string, int>();
  25711. List<AirHotelPrice> airHotelPriceList = new List<AirHotelPrice>();
  25712. foreach (var flight in flights.Keys)
  25713. {
  25714. // 获取当前舱位的匹配规则
  25715. if (flightRoomMatchingRules.TryGetValue(flight, out string[] roomTypes))
  25716. {
  25717. MatchRooms(ref hotelRooms, ref flights, roomTypes, flight, ref result);
  25718. }
  25719. }
  25720. #region right计算
  25721. if (result.Keys.Contains("经济舱TBR") && result["经济舱TBR"] > 0)
  25722. {
  25723. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  25724. var hotel = (mainPrice.TBRCB * mainPrice.TBRXS) / 2;
  25725. airHotelPriceList.Add(new
  25726. AirHotelPrice
  25727. {
  25728. Name = "经济舱TBR",
  25729. Price = rightSum + air + hotel,
  25730. Count = result["经济舱TBR"] * 2
  25731. });
  25732. allPrice += (rightSum + air + hotel) * result["经济舱TBR"] * 2;
  25733. }
  25734. if (result.Keys.Contains("经济舱SGR") && result["经济舱SGR"] > 0)
  25735. {
  25736. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  25737. var hotel = mainPrice.SGRCB * mainPrice.SGRXS;
  25738. airHotelPriceList.Add(new
  25739. AirHotelPrice
  25740. {
  25741. Name = "经济舱SGR",
  25742. Price = rightSum + air + hotel,
  25743. Count = result["经济舱SGR"]
  25744. });
  25745. allPrice += (rightSum + air + hotel) * result["经济舱SGR"];
  25746. }
  25747. if (result.Keys.Contains("公务舱SGR") && result["公务舱SGR"] > 0)
  25748. {
  25749. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  25750. var hotel = mainPrice.SGRCB * mainPrice.SGRXS;
  25751. airHotelPriceList.Add(new
  25752. AirHotelPrice
  25753. {
  25754. Name = "公务舱SGR",
  25755. Price = rightSum + air + hotel,
  25756. Count = result["公务舱SGR"]
  25757. });
  25758. allPrice += (rightSum + air + hotel) * result["公务舱SGR"];
  25759. }
  25760. if (result.Keys.Contains("公务舱JSES") && result["公务舱JSES"] > 0)
  25761. {
  25762. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  25763. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  25764. airHotelPriceList.Add(new
  25765. AirHotelPrice
  25766. {
  25767. Name = "公务舱JSES",
  25768. Price = rightSum + air + hotel,
  25769. Count = result["公务舱JSES"]
  25770. });
  25771. allPrice += (rightSum + air + hotel) * result["公务舱JSES"];
  25772. }
  25773. if (result.Keys.Contains("公务舱SUITE") && result["公务舱SUITE"] > 0)
  25774. {
  25775. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  25776. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  25777. airHotelPriceList.Add(new
  25778. AirHotelPrice
  25779. {
  25780. Name = "公务舱SUITE",
  25781. Price = rightSum + air + hotel,
  25782. Count = result["公务舱SUITE"]
  25783. });
  25784. allPrice += (rightSum + air + hotel) * result["公务舱SUITE"];
  25785. }
  25786. if (result.Keys.Contains("经济舱SUITE") && result["经济舱SUITE"] > 0)
  25787. {
  25788. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  25789. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  25790. airHotelPriceList.Add(new
  25791. AirHotelPrice
  25792. {
  25793. Name = "经济舱SUITE",
  25794. Price = rightSum + air + hotel,
  25795. Count = result["经济舱SUITE"]
  25796. });
  25797. allPrice += (rightSum + air + hotel) * result["经济舱SUITE"];
  25798. }
  25799. if (result.Keys.Contains("头等舱JSES") && result["头等舱JSES"] > 0)
  25800. {
  25801. var air = mainPrice.TDCCB * mainPrice.TDCXS;
  25802. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  25803. airHotelPriceList.Add(new
  25804. AirHotelPrice
  25805. {
  25806. Name = "头等舱JSES",
  25807. Price = rightSum + air + hotel,
  25808. Count = result["头等舱JSES"]
  25809. });
  25810. allPrice += (rightSum + air + hotel) * result["头等舱JSES"];
  25811. }
  25812. if (result.Keys.Contains("头等舱SUITE") && result["头等舱SUITE"] > 0)
  25813. {
  25814. var air = mainPrice.TDCCB * mainPrice.TDCXS;
  25815. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  25816. airHotelPriceList.Add(new
  25817. AirHotelPrice
  25818. {
  25819. Name = "头等舱SUITE",
  25820. Price = rightSum + air + hotel,
  25821. Count = result["头等舱SUITE"]
  25822. });
  25823. allPrice += (rightSum + air + hotel) * result["头等舱SUITE"];
  25824. }
  25825. if (result.Keys.Contains("经济舱JSES") && result["经济舱JSES"] > 0)
  25826. {
  25827. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  25828. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  25829. airHotelPriceList.Add(new
  25830. AirHotelPrice
  25831. {
  25832. Name = "经济舱JSES",
  25833. Price = rightSum + air + hotel,
  25834. Count = result["经济舱JSES"]
  25835. });
  25836. allPrice += (rightSum + air + hotel) * result["经济舱JSES"];
  25837. }
  25838. #endregion
  25839. foreach (var item in airSouer.Keys)
  25840. {
  25841. var find = airHotelPriceList.FirstOrDefault(x => x.Name == item);
  25842. if (find != null && find.Count > 0)
  25843. {
  25844. if (item.Contains("TBR"))
  25845. {
  25846. itemStr += "团费(" + airSouer[item] + ") RMB " + find.Price.ToString("F2") + "/人*" + find.Count + "(" + (find.Count / 2) + "间) ............合计 RMB " + (find.Count * find.Price).ToString("#0.00") + "\n";
  25847. }
  25848. else
  25849. {
  25850. itemStr += "团费(" + airSouer[item] + ") RMB " + find.Price.ToString("F2") + "/人*" + find.Count + "(" + find.Count + "间) ............合计 RMB " + (find.Count * find.Price).ToString("#0.00") + "\n";
  25851. }
  25852. }
  25853. }
  25854. #region 替换Word模板书签内容
  25855. Dictionary<string, string> marks = new Dictionary<string, string>();
  25856. marks.Add("To", di.ClientUnit);//付款方
  25857. marks.Add("ToTel", di.TellPhone);//付款方电话
  25858. marks.Add("Date", DateTime.Now.ToString("yyyy-MM-dd"));//导出时间
  25859. marks.Add("Team", di.VisitCountry.Replace(" ", "、"));//团队名称
  25860. marks.Add("TontractTime", (di.VisitDate).ToString("yyyy年MM月dd日"));//付款日期
  25861. marks.Add("PayDay", (di.PayDay).ToString());//付款预期
  25862. marks.Add("PaymentMoney", (di.PaymentMoney).ToString("#0.00"));//付款金额
  25863. marks.Add("WeChat", di.WeChatNo ?? "");//微信号
  25864. marks.Add("PayItemContent", itemStr);//详细信息
  25865. marks.Add("Total", allPrice.ToString("F2"));//合计
  25866. #endregion
  25867. foreach (var item in marks.Keys)
  25868. {
  25869. if (doc.Range.Bookmarks[item] != null)
  25870. {
  25871. Bookmark mark = doc.Range.Bookmarks[item];
  25872. mark.Text = marks[item];
  25873. }
  25874. }
  25875. string savePaht = $"{AppSettingsHelper.Get("WordBasePath")}GroupCostQuotations/{di.TeamName}_报批费用.doc";
  25876. doc.Save(savePaht);
  25877. var jw = new JsonView();
  25878. jw.Msg = "生成成功!";
  25879. jw.Code = 200;
  25880. jw.Data = new { Url = AppSettingsHelper.Get("WordBaseUrl") + savePaht.Replace(AppSettingsHelper.Get("WordBasePath"), AppSettingsHelper.Get("WordFtpPath")) };
  25881. return Ok(jw);
  25882. }
  25883. /// <summary>
  25884. /// 详细报价费用Excel下载
  25885. /// </summary>
  25886. /// <param name="dto"></param>
  25887. /// <returns></returns>
  25888. [HttpPost]
  25889. public async Task<IActionResult> GroupQuotationsDetailFileDown(GroupQuotationsFileDownDto dto)
  25890. {
  25891. var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  25892. .FirstAsync(x => x.Id == dto.Diid && x.IsDel == 0);
  25893. if (di == null)
  25894. {
  25895. return Ok(JsonView(false, "团组不存在!"));
  25896. }
  25897. var mainPrice = _GroupCostParameterRepository.GetGroupCostParameterMainByDiid(dto.Diid);
  25898. if (mainPrice == null || mainPrice.IsShare == 0)
  25899. {
  25900. return Ok(JsonView(false, "团组成本不存在!"));
  25901. }
  25902. var costTypeHotelNumbers = await _sqlSugar.Queryable<Grp_CostTypeHotelNumber>()
  25903. .FirstAsync(x => x.Type == "Default" && x.Diid == dto.Diid && x.IsDel == 0);
  25904. if (costTypeHotelNumbers == null)
  25905. {
  25906. return Ok(JsonView(false, "团组成本不存在!"));
  25907. }
  25908. WorkbookDesigner designer = new WorkbookDesigner();
  25909. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + ("Template/报价详细表.xls"));
  25910. List<int> hideRowsList = new List<int>();
  25911. int conterStartIndex = 3;
  25912. int rowIndex = conterStartIndex;
  25913. designer.SetDataSource("GroupName", di.TeamName);
  25914. var priceDataList = new List<(string rsName, string cbName, string xsName, string prefix)>
  25915. {
  25916. ("VisaRS", "VisaCB", "VisaXS", "qz"),
  25917. ("BXRS", "BXCB", "BXXS", "bx"),
  25918. ("HCPRS", "HCPCB", "HCPXS", "hcp"),
  25919. ("JJCRS", "JJCCB", "JJCXS", "jjc"),
  25920. ("GWCRS", "GWCCB", "GWCXS", "gwc") ,
  25921. ("TDCRS", "TDCCB", "TDCXS", "tdc") ,
  25922. ("CPRS", "CPCB", "CPXS", "cp") ,
  25923. ("HSRS", "HSCB", "HSXS", "hsjc") ,
  25924. ("TBRNumber", "TBRCB", "TBRXS", "tbr") ,
  25925. ("SGRNumber", "SGRCB", "SGRXS", "sgr") ,
  25926. ("JSESNumber", "JSESCB", "JSESXS", "jses") ,
  25927. ("SUITENumber", "SUITECB", "SUITEXS", "suite") ,
  25928. ("DJRS", "DJCB", "DJXS", "dj") ,
  25929. ("GWRS", "GWCB", "GWXS", "gw") ,
  25930. ("LYJRS", "LYJCB", "LYJXS", "lyj") ,
  25931. };
  25932. var OtherCostPropertyBJ = new string[] { "qz", "hcp", "cp", "bx", "hsjc", "dj", "gw", "lyj" };
  25933. var rightSum = 0.00M;
  25934. foreach (var (rsName, cbName, xsName, prefix) in priceDataList)
  25935. {
  25936. var rsValue = (int)mainPrice.GetType().GetProperty(rsName).GetValue(mainPrice);
  25937. var cbValue = (decimal)mainPrice.GetType().GetProperty(cbName).GetValue(mainPrice);
  25938. var xsValue = (decimal)mainPrice.GetType().GetProperty(xsName).GetValue(mainPrice);
  25939. if (prefix == "tbr")
  25940. {
  25941. rsValue *= 2;
  25942. cbValue /= 2;
  25943. }
  25944. if (OtherCostPropertyBJ.Contains(prefix))
  25945. {
  25946. rightSum += cbValue * xsValue;
  25947. }
  25948. if (rsValue == 0)
  25949. {
  25950. hideRowsList.Add(rowIndex);
  25951. }
  25952. else
  25953. {
  25954. designer.SetDataSource($"{prefix}rs", rsValue);
  25955. designer.SetDataSource($"{prefix}bj", cbValue * xsValue);
  25956. designer.SetDataSource($"{prefix}zbj", cbValue * xsValue * rsValue);
  25957. }
  25958. rowIndex += 2;
  25959. }
  25960. var hotelRooms = new Dictionary<string, int>
  25961. {
  25962. { "SGR", costTypeHotelNumbers.SGR },
  25963. { "TBR", costTypeHotelNumbers.TBR },
  25964. { "JSES", costTypeHotelNumbers.JSES },
  25965. { "SUITE", costTypeHotelNumbers.SUITE }
  25966. };
  25967. var flights = new Dictionary<string, int>
  25968. {
  25969. { "经济舱", mainPrice.JJCRS },
  25970. { "公务舱", mainPrice.GWCRS },
  25971. { "头等舱", mainPrice.TDCRS }
  25972. };
  25973. var flightRoomMatchingRules = new Dictionary<string, string[]>
  25974. {
  25975. { "经济舱", new[] { "TBR", "SGR", "JSES", "SUITE" } },
  25976. { "公务舱", new[] { "SUITE", "JSES", "SGR" } },
  25977. { "头等舱", new[] { "SUITE", "JSES" } }
  25978. };
  25979. var result = new Dictionary<string, int>();
  25980. foreach (var flight in flights.Keys)
  25981. {
  25982. // 获取当前舱位的匹配规则
  25983. if (flightRoomMatchingRules.TryGetValue(flight, out string[] roomTypes))
  25984. {
  25985. MatchRooms(ref hotelRooms, ref flights, roomTypes, flight, ref result);
  25986. }
  25987. }
  25988. var allPrice = 0.00M;
  25989. #region right计算
  25990. int airRowIndex = 35;
  25991. if (result.Keys.Contains("经济舱TBR") && result["经济舱TBR"] > 0)
  25992. {
  25993. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  25994. var hotel = (mainPrice.TBRCB * mainPrice.TBRXS) / 2;
  25995. designer.SetDataSource("jjctbrrs", result["经济舱TBR"] * 2);
  25996. designer.SetDataSource("jjctbrbj", rightSum + air + hotel);
  25997. designer.SetDataSource("jjctbrzbj", (rightSum + air + hotel) * result["经济舱TBR"] * 2);
  25998. allPrice += (rightSum + air + hotel) * result["经济舱TBR"] * 2;
  25999. }
  26000. else
  26001. {
  26002. hideRowsList.Add(airRowIndex);
  26003. }
  26004. airRowIndex += 2;
  26005. if (result.Keys.Contains("经济舱SGR") && result["经济舱SGR"] > 0)
  26006. {
  26007. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  26008. var hotel = mainPrice.SGRCB * mainPrice.SGRXS;
  26009. designer.SetDataSource("jjcsgrrs", result["经济舱SGR"]);
  26010. designer.SetDataSource("jjcsgrbj", rightSum + air + hotel);
  26011. designer.SetDataSource("jjcsgrzbj", (rightSum + air + hotel) * result["经济舱SGR"]);
  26012. allPrice += (rightSum + air + hotel) * result["经济舱SGR"];
  26013. }
  26014. else
  26015. {
  26016. hideRowsList.Add(airRowIndex);
  26017. }
  26018. airRowIndex += 2;
  26019. if (result.Keys.Contains("公务舱SGR") && result["公务舱SGR"] > 0)
  26020. {
  26021. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  26022. var hotel = mainPrice.SGRCB * mainPrice.SGRXS;
  26023. designer.SetDataSource("gwcsgrrs", result["公务舱SGR"]);
  26024. designer.SetDataSource("gwcsgrbj", rightSum + air + hotel);
  26025. designer.SetDataSource("gwcsgrzbj", (rightSum + air + hotel) * result["公务舱SGR"]);
  26026. allPrice += (rightSum + air + hotel) * result["公务舱SGR"];
  26027. }
  26028. else
  26029. {
  26030. hideRowsList.Add(airRowIndex);
  26031. }
  26032. airRowIndex += 2;
  26033. if (result.Keys.Contains("公务舱JSES") && result["公务舱JSES"] > 0)
  26034. {
  26035. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  26036. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  26037. designer.SetDataSource("gwcjsesrs", result["公务舱JSES"]);
  26038. designer.SetDataSource("gwcjsesbj", rightSum + air + hotel);
  26039. designer.SetDataSource("gwcjseszbj", (rightSum + air + hotel) * result["公务舱JSES"]);
  26040. allPrice += (rightSum + air + hotel) * result["公务舱JSES"];
  26041. }
  26042. else
  26043. {
  26044. hideRowsList.Add(airRowIndex);
  26045. }
  26046. airRowIndex += 2;
  26047. if (result.Keys.Contains("公务舱SUITE") && result["公务舱SUITE"] > 0)
  26048. {
  26049. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  26050. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  26051. designer.SetDataSource("gwcsuiters", result["公务舱SUITE"]);
  26052. designer.SetDataSource("gwcsuitebj", rightSum + air + hotel);
  26053. designer.SetDataSource("gwcsuitezbj", (rightSum + air + hotel) * result["公务舱SUITE"]);
  26054. allPrice += (rightSum + air + hotel) * result["公务舱SUITE"];
  26055. }
  26056. else
  26057. {
  26058. hideRowsList.Add(airRowIndex);
  26059. }
  26060. airRowIndex += 2;
  26061. if (result.Keys.Contains("经济舱SUITE") && result["经济舱SUITE"] > 0)
  26062. {
  26063. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  26064. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  26065. designer.SetDataSource("jjcsuiters", result["经济舱SUITE"]);
  26066. designer.SetDataSource("jjcsuitebj", rightSum + air + hotel);
  26067. designer.SetDataSource("jjcsuitezbj", (rightSum + air + hotel) * result["经济舱SUITE"]);
  26068. allPrice += (rightSum + air + hotel) * result["经济舱SUITE"];
  26069. }
  26070. else
  26071. {
  26072. hideRowsList.Add(airRowIndex);
  26073. }
  26074. airRowIndex += 2;
  26075. if (result.Keys.Contains("头等舱JSES") && result["头等舱JSES"] > 0)
  26076. {
  26077. var air = mainPrice.TDCCB * mainPrice.TDCXS;
  26078. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  26079. designer.SetDataSource("tdcjsesrs", result["头等舱JSES"]);
  26080. designer.SetDataSource("tdcjsesbj", rightSum + air + hotel);
  26081. designer.SetDataSource("tdcjseszbj", (rightSum + air + hotel) * result["头等舱JSES"]);
  26082. allPrice += (rightSum + air + hotel) * result["头等舱JSES"];
  26083. }
  26084. else
  26085. {
  26086. hideRowsList.Add(airRowIndex);
  26087. }
  26088. airRowIndex += 2;
  26089. if (result.Keys.Contains("头等舱SUITE") && result["头等舱SUITE"] > 0)
  26090. {
  26091. var air = mainPrice.TDCCB * mainPrice.TDCXS;
  26092. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  26093. designer.SetDataSource("tdcsuiters", result["头等舱SUITE"]);
  26094. designer.SetDataSource("tdcsuitebj", rightSum + air + hotel);
  26095. designer.SetDataSource("tdcsuitezbj", (rightSum + air + hotel) * result["头等舱SUITE"]);
  26096. allPrice += (rightSum + air + hotel) * result["头等舱SUITE"];
  26097. }
  26098. else
  26099. {
  26100. hideRowsList.Add(airRowIndex);
  26101. }
  26102. airRowIndex += 2;
  26103. if (result.Keys.Contains("经济舱JSES") && result["经济舱JSES"] > 0)
  26104. {
  26105. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  26106. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  26107. designer.SetDataSource("jjcjsesrs", result["经济舱JSES"]);
  26108. designer.SetDataSource("jjcjsesbj", rightSum + air + hotel);
  26109. designer.SetDataSource("jjcjseszbj", (rightSum + air + hotel) * result["经济舱JSES"]);
  26110. allPrice += (rightSum + air + hotel) * result["经济舱JSES"];
  26111. }
  26112. else
  26113. {
  26114. hideRowsList.Add(airRowIndex);
  26115. }
  26116. #endregion
  26117. designer.SetDataSource("AllPrice", "总金额:" + allPrice.ToString("#0.00"));
  26118. string savePaht = AppSettingsHelper.Get("ExcelBasePath") + "GroupCostQuotations/" + di.TeamName + "_详细报批费用.xls";
  26119. var ws = designer.Workbook.Worksheets[0];
  26120. foreach (var Rowindex in hideRowsList)
  26121. {
  26122. ws.Cells.HideRows(Rowindex, 2);
  26123. }
  26124. designer.Process();
  26125. designer.Workbook.Save(savePaht);
  26126. return Ok(JsonView(true, "生成成功!", new
  26127. {
  26128. Url = AppSettingsHelper.Get("ExcelBaseUrl") + savePaht.Replace(AppSettingsHelper.Get("ExcelBasePath"), AppSettingsHelper.Get("ExcelFtpPath"))
  26129. }));
  26130. }
  26131. private void MatchRooms(ref Dictionary<string, int> hotelRooms, ref Dictionary<string, int> flights, string[] roomTypes, string flightType, ref Dictionary<string, int> result)
  26132. {
  26133. foreach (var roomType in roomTypes)
  26134. {
  26135. while (hotelRooms[roomType] > 0 && flights[flightType] > 0)
  26136. {
  26137. hotelRooms[roomType]--;
  26138. flights[flightType]--;
  26139. if (roomType == "TBR")
  26140. {
  26141. flights[flightType]--; // 双人间在减少1
  26142. }
  26143. string key = flightType + roomType;
  26144. if (result.Keys.Contains(key))
  26145. {
  26146. result[key]++;
  26147. }
  26148. else
  26149. {
  26150. result.Add(key, 1);
  26151. }
  26152. }
  26153. }
  26154. }
  26155. private class AirHotelPrice
  26156. {
  26157. public string Name { get; set; }
  26158. public decimal Price { get; set; }
  26159. public int Count { get; set; }
  26160. }
  26161. /// <summary>
  26162. /// 团组系数设置
  26163. /// </summary>
  26164. /// <param name="dto"></param>
  26165. /// <returns></returns>
  26166. [HttpPost]
  26167. public async Task<IActionResult> QueryGroupCostCoefficient(QueryGroupCostCoefficientDto dto)
  26168. {
  26169. var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  26170. .FirstAsync(x => x.Id == dto.Diid && x.IsDel == 0);
  26171. if (di == null)
  26172. {
  26173. return Ok(JsonView(false, "团组不存在!"));
  26174. }
  26175. //var firstExpression = Expressionable.Create<Grp_GroupCostParameter>()
  26176. // .And(x => x.CostType == "A" && x.DiId == di.Id && x.IsDel == 0);
  26177. //var groupCostMainPrice = await _sqlSugar.Queryable<Grp_GroupCostParameter>().
  26178. // FirstAsync(firstExpression.ToExpression());
  26179. #region JSON
  26180. string hcpJson = @"
  26181. [
  26182. {
  26183. ""min"": 1,
  26184. ""max"": 500,
  26185. ""value"": 1.50
  26186. },
  26187. {
  26188. ""min"": 501,
  26189. ""max"": 1000,
  26190. ""value"": 1.40
  26191. },
  26192. {
  26193. ""min"": 1001,
  26194. ""max"": 2000,
  26195. ""value"": 1.35
  26196. }
  26197. ]";
  26198. #endregion
  26199. var hcpPriceRange = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PriceRange>>(hcpJson);
  26200. List<(Predicate<decimal>, decimal)> hcpSwitchDictionary = hcpPriceRange
  26201. .Select(pr => (new Predicate<decimal>(x => x >= pr.Min && x <= pr.Max), pr.Value))
  26202. .ToList();
  26203. List<(Predicate<decimal>, List<(Predicate<decimal>, decimal)>)> jjcSwitchDictionary =
  26204. new List<(Predicate<decimal>, List<(Predicate<decimal>, decimal)>)>();
  26205. //jjcSwitchDictionary.Add((new Predicate<decimal>(x => x >= 1 && x <= 3),
  26206. // new List<(Predicate<decimal>, decimal)>()
  26207. // {
  26208. // (new Predicate<decimal>(y => y >= 1000 && y <= 3000), 2.6M),
  26209. // (new Predicate<decimal>(y => y > 3000), 2.5M)
  26210. // }
  26211. // ));
  26212. #region 签证系数
  26213. var visaXS = 0.00M;
  26214. switch (dto.VisaCB)
  26215. {
  26216. case decimal n when (n > 1 && n < 500):
  26217. switch (dto.VisaRS)
  26218. {
  26219. case 2 or 3:
  26220. visaXS = 1.35M;
  26221. break;
  26222. case 4 or 5:
  26223. visaXS = 1.30M;
  26224. break;
  26225. case 6 or 7:
  26226. visaXS = 1.25M;
  26227. break;
  26228. case 8 or 9 or 10:
  26229. visaXS = 1.20M;
  26230. break;
  26231. case > 10:
  26232. visaXS = 1.15M;
  26233. break;
  26234. default:
  26235. visaXS = 0.00M;
  26236. break;
  26237. }
  26238. break;
  26239. case decimal n when (n >= 500 && n < 1000):
  26240. switch (dto.VisaRS)
  26241. {
  26242. case 2 or 3 or 4:
  26243. visaXS = 1.30M;
  26244. break;
  26245. case 5 or 6 or 7 or 8:
  26246. visaXS = 1.25M;
  26247. break;
  26248. case 9 or 10:
  26249. visaXS = 1.20M;
  26250. break;
  26251. case > 10:
  26252. visaXS = 1.15M;
  26253. break;
  26254. default:
  26255. visaXS = 0.00M;
  26256. break;
  26257. }
  26258. break;
  26259. default:
  26260. switch (dto.VisaRS)
  26261. {
  26262. case 2 or 3 or 4:
  26263. visaXS = 1.30M;
  26264. break;
  26265. case 5 or 6 or 7 or 8:
  26266. visaXS = 1.25M;
  26267. break;
  26268. case 9 or 10:
  26269. visaXS = 1.20M;
  26270. break;
  26271. case > 10:
  26272. visaXS = 1.15M;
  26273. break;
  26274. default:
  26275. visaXS = 0.00M;
  26276. break;
  26277. }
  26278. break;
  26279. }
  26280. #endregion
  26281. #region 火车系数
  26282. var hcpXS = 0.00M;
  26283. foreach (var (condition, result) in hcpSwitchDictionary)
  26284. {
  26285. if (condition(dto.HCPCB))
  26286. {
  26287. hcpXS = result;
  26288. break;
  26289. }
  26290. }
  26291. #endregion
  26292. #region 机票系数
  26293. #region 经济舱系数
  26294. var jjcXS = 0.00M;
  26295. switch (dto.JJCCB)
  26296. {
  26297. case decimal x when (x >= 1000 && x <= 3000):
  26298. jjcXS = 2.6M;
  26299. break;
  26300. case decimal x when (x >= 3001 && x <= 8000):
  26301. jjcXS = 2.3M;
  26302. break;
  26303. case decimal x when (x >= 8001 && x <= 15000):
  26304. jjcXS = 2.1M;
  26305. break;
  26306. case decimal x when (x >= 15001 && x <= 30000):
  26307. jjcXS = 1.95M;
  26308. break;
  26309. case > 30000:
  26310. jjcXS = 1.8M;
  26311. break;
  26312. default:
  26313. break;
  26314. }
  26315. #endregion
  26316. #region 公务舱系数
  26317. var gwcXS = 0.00M;
  26318. switch (dto.GWCCB)
  26319. {
  26320. case decimal x when (x >= 1000 && x <= 3000):
  26321. gwcXS = 2.5M;
  26322. break;
  26323. case decimal x when (x >= 3001 && x <= 8000):
  26324. gwcXS = 2.2M;
  26325. break;
  26326. case decimal x when (x >= 8001 && x <= 15000):
  26327. gwcXS = 2.0M;
  26328. break;
  26329. case decimal x when (x >= 15001 && x <= 30000):
  26330. gwcXS = 1.85M;
  26331. break;
  26332. case > 30000:
  26333. gwcXS = 1.7M;
  26334. break;
  26335. default:
  26336. break;
  26337. }
  26338. #endregion
  26339. #region 头等舱系数
  26340. var tdcXS = 0.00M;
  26341. switch (dto.TDCCB)
  26342. {
  26343. case > 70000:
  26344. tdcXS = 1.5M;
  26345. break;
  26346. default:
  26347. tdcXS = 1.9M;
  26348. break;
  26349. }
  26350. #endregion
  26351. #endregion
  26352. #region 酒店系数
  26353. Dictionary<decimal, List<string>> dic = new Dictionary<decimal, List<string>>()
  26354. {
  26355. {1.6M, new List<string>(){"新西兰","澳大利亚" }},
  26356. {1.5M, new List<string>(){"越南社会主义共和国",
  26357. "老挝",
  26358. "柬埔寨",
  26359. "泰国",
  26360. "缅甸",
  26361. "马来西亚",
  26362. //"新加坡",
  26363. "文莱达鲁萨兰",
  26364. "印度尼西亚",
  26365. "东帝汶"}},
  26366. {1.2M, new List<string>(){ "日本","新加坡","法国","意大利","荷兰"}},
  26367. };
  26368. #region SGR
  26369. var sgrXS = 1.25M;
  26370. #endregion
  26371. #region TBR
  26372. var tbrXS = 1.25M;
  26373. #endregion
  26374. #region JSES
  26375. var jsesXS = 1.25M;
  26376. #endregion
  26377. #region SUITE
  26378. var suiteXS = 1.25M;
  26379. #endregion
  26380. var countryArr = di.VisitCountry.Split("|");
  26381. foreach (var item in dic)
  26382. {
  26383. var extsisCount = item.Value.Where(x => countryArr.Contains(x))
  26384. .Count();
  26385. if (extsisCount > 0)
  26386. {
  26387. jsesXS = item.Key;
  26388. sgrXS = item.Key;
  26389. tbrXS = item.Key;
  26390. suiteXS = item.Key;
  26391. }
  26392. }
  26393. #endregion
  26394. #region 地接系数
  26395. var djXS = 0.00M;
  26396. switch (dto.DJRS)
  26397. {
  26398. case 2 or 3:
  26399. djXS = 2.65M;
  26400. break;
  26401. case 4:
  26402. djXS = 2.6M;
  26403. break;
  26404. case 5 or 6:
  26405. djXS = 2.5M;
  26406. break;
  26407. case 7 or 8:
  26408. djXS = 2.4M;
  26409. break;
  26410. case 9 or 10:
  26411. djXS = 2.3M;
  26412. break;
  26413. case 11:
  26414. djXS = 2.2M;
  26415. break;
  26416. case 12:
  26417. djXS = 2.1M;
  26418. break;
  26419. case 13 or 14:
  26420. djXS = 2M;
  26421. break;
  26422. case 15:
  26423. djXS = 1.9M;
  26424. break;
  26425. case 16 or 17 or 18:
  26426. djXS = 1.8M;
  26427. break;
  26428. case 19 or 20:
  26429. djXS = 1.7M;
  26430. break;
  26431. }
  26432. #endregion
  26433. #region 零用金系数
  26434. var lyjXS = 0.00M;
  26435. switch (dto.LYJRS)
  26436. {
  26437. case 2:
  26438. lyjXS = 1.25M;
  26439. break;
  26440. case 3 or 4 or 5:
  26441. lyjXS = 1.2M;
  26442. break;
  26443. case int number when (number > 5 && number < 10):
  26444. lyjXS = 1.15M;
  26445. break;
  26446. case > 10:
  26447. lyjXS = 1.1M;
  26448. break;
  26449. default:
  26450. break;
  26451. }
  26452. #endregion
  26453. return Ok(JsonView(true, "查询成功", new ArrayList()
  26454. {
  26455. new { label = "火车票系数", value = hcpXS, key = "hcpXS" },
  26456. new { label = "经济舱系数", value = jjcXS, key = "jjcXS" },
  26457. new { label = "公务舱系数", value = gwcXS, key = "gwcXS" },
  26458. new { label = "头等舱系数", value = tdcXS, key = "tdcXS" },
  26459. new { label = "SGR系数", value = sgrXS, key = "sgrXS" },
  26460. new { label = "TBR系数", value = tbrXS, key = "tbrXS" },
  26461. new { label = "JSES系数", value = jsesXS, key = "jsesXS" },
  26462. new { label = "SUITE系数", value = suiteXS, key = "suiteXS" },
  26463. new { label = "地接系数", value = djXS, key = "djXS" },
  26464. new { label = "零用金系数", value = lyjXS, key = "lyjXS" },
  26465. new { label = "公务系数", value = 2M, key = "gwXS" }
  26466. }));
  26467. }
  26468. #endregion
  26469. #region 酒店预订 New 2023-12-28 17:45
  26470. /// <summary>
  26471. /// 酒店预订
  26472. /// 酒店费用列表 根据团组Id查询
  26473. /// </summary>
  26474. /// <param name="_dto"></param>
  26475. /// <returns></returns>
  26476. [HttpPost]
  26477. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26478. public async Task<IActionResult> PostHotelReservationsItemsByDiId(HotelReservationItemDto _dto)
  26479. {
  26480. #region 参数验证
  26481. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  26482. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  26483. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  26484. #region 团组操作权限验证 76 酒店预定模块
  26485. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  26486. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  26487. #endregion
  26488. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  26489. #region 页面操作权限验证
  26490. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  26491. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  26492. #endregion
  26493. #endregion
  26494. return Ok(await _hotelPriceRep.ItemsByDiId(_dto.PortType, _dto.DiId));
  26495. }
  26496. /// <summary>
  26497. /// 酒店预订
  26498. /// 基础数据
  26499. /// </summary>
  26500. /// <param name="_dto"></param>
  26501. /// <returns></returns>
  26502. [HttpPost]
  26503. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26504. public async Task<IActionResult> PostHotelReservationsBasicsDataInit(HotelReservationBasicsDataInitDto _dto)
  26505. {
  26506. #region 参数验证
  26507. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  26508. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  26509. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  26510. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  26511. #region 页面操作权限验证
  26512. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  26513. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  26514. #endregion
  26515. #region 团组操作权限验证 76 酒店预定模块
  26516. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  26517. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  26518. #endregion
  26519. #endregion
  26520. return Ok(await _hotelPriceRep.BasicsDataInit(_dto.PortType, _dto.DiId));
  26521. }
  26522. /// <summary>
  26523. /// 酒店预订
  26524. /// 创建 入住卷号码
  26525. /// </summary>
  26526. /// <param name="_dto"></param>
  26527. /// <returns></returns>
  26528. [HttpPost]
  26529. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26530. public async Task<IActionResult> PostHotelReservationsCreateCheckVolumeNo(HotelReservationBasicsDataInitDto _dto)
  26531. {
  26532. #region 参数验证
  26533. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  26534. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  26535. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  26536. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  26537. #region 页面操作权限验证
  26538. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  26539. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  26540. #endregion
  26541. #region 团组操作权限验证 76 酒店预定模块
  26542. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  26543. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  26544. #endregion
  26545. #endregion
  26546. Result data = await _hotelPriceRep.CreateCheckVolumeNo(_dto.DiId);
  26547. if (data.Code != 0)
  26548. {
  26549. return Ok(JsonView(false, data.Msg));
  26550. }
  26551. return Ok(JsonView(true, data.Msg, data.Data));
  26552. }
  26553. /// <summary>
  26554. /// 酒店预订
  26555. /// 详情
  26556. /// </summary>
  26557. /// <param name="_dto"></param>
  26558. /// <returns></returns>
  26559. [HttpPost]
  26560. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26561. public async Task<IActionResult> PostHotelReservationsDetails(HotelReservationsDetailsDto _dto)
  26562. {
  26563. #region 参数验证
  26564. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入正确的UserId参数"));
  26565. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  26566. if (_dto.DiId < 1) return Ok(JsonView(false, "请传入正确的DiId参数"));
  26567. #region 团组操作权限验证 76 酒店预定模块
  26568. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  26569. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  26570. #endregion
  26571. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  26572. #region 页面操作权限验证
  26573. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  26574. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  26575. #endregion
  26576. #endregion
  26577. return Ok(await _hotelPriceRep.Details(_dto.PortType, _dto.Id));
  26578. }
  26579. /// <summary>
  26580. /// 酒店预订
  26581. /// Add Or Edit
  26582. /// </summary>
  26583. /// <param name="_dto"></param>
  26584. /// <returns></returns>
  26585. [HttpPost]
  26586. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26587. public async Task<IActionResult> PostHotelReservationsAddOrEdit(HotelReservationsAddOrEditDto _dto)
  26588. {
  26589. #region 参数验证
  26590. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  26591. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  26592. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  26593. #region 团组操作权限验证 76 酒店预定模块
  26594. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  26595. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  26596. #endregion
  26597. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  26598. #region 页面操作权限验证
  26599. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  26600. if (_dto.Id == 0) // Add
  26601. {
  26602. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
  26603. }
  26604. else if (_dto.Id > 1) // Edit
  26605. {
  26606. if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
  26607. }
  26608. else return Ok(JsonView(false, "请输入正确的数据Id!"));
  26609. #endregion
  26610. #endregion
  26611. //验证:团回归30天后不能更改
  26612. if (_dto.Id > 0)
  26613. {
  26614. //// 审核、付款 验证
  26615. //(bool valid, string msg) = await GeneralMethod.FeeOpValid(_dto.Id, 76);
  26616. //if (!valid) return Ok(JsonView(false, msg));
  26617. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  26618. .Where(x => x.Id == _dto.DiId && x.IsDel == 0)
  26619. .FirstAsync();
  26620. if (groupInfo == null)
  26621. {
  26622. return Ok(JsonView(false, "团组信息不存在"));
  26623. }
  26624. // 截止日期:团回归日期+30天
  26625. var deadline = groupInfo.VisitEndDate.AddDays(30).Date;
  26626. // 当前日期
  26627. var currDate = DateTime.Today;
  26628. if (currDate > deadline)
  26629. {
  26630. return Ok(JsonView(false, "当前日期已超过截止日期(团回归日期+30天),不可编辑。"));
  26631. }
  26632. }
  26633. JsonView _view = await _hotelPriceRep.AddOrEdit(_dto);
  26634. if (_view.Code != 200)
  26635. {
  26636. return Ok(_view);
  26637. }
  26638. #region 成本无酒店价格数据进入超支
  26639. _sqlSugar.BeginTran();
  26640. var start_Bool = DateTime.TryParse(_dto.CheckInDate, out DateTime start_Time);
  26641. var end_Bool = DateTime.TryParse(_dto.CheckOutDate, out DateTime end_Time);
  26642. var groupCost = _sqlSugar.Queryable<Grp_GroupCost>().Where(x => x.Diid == _dto.DiId && x.IsDel == 0).ToList();
  26643. for (int i = 0; i < groupCost.Count; i++)
  26644. {
  26645. if (groupCost[i].Date.IsNullOrWhiteSpace() && i != 0)
  26646. {
  26647. groupCost[i].Date = groupCost[i - 1].Date;
  26648. }
  26649. }
  26650. var groupCost_Grp = groupCost.GroupBy(x => x.Date).ToList();
  26651. List<Fin_GroupExtraCostDto_OP> extraCostList = new
  26652. List<Fin_GroupExtraCostDto_OP>();
  26653. if (start_Bool && end_Bool)
  26654. {
  26655. while (start_Time < end_Time)
  26656. {
  26657. foreach (var item in groupCost_Grp)
  26658. {
  26659. if (DateTime.TryParse(item.Key, out DateTime cost_Time))
  26660. {
  26661. if (DateTime.Compare(start_Time, cost_Time) == 0 && item.Sum(x => x.SGR + x.Suite + x.TBR + x.JS_ES) == 0)
  26662. {
  26663. extraCostList.Add(new
  26664. Fin_GroupExtraCostDto_OP
  26665. {
  26666. Area = _dto.AreaId,
  26667. coefficient = 1.5M,
  26668. createUser = _dto.UserId,
  26669. currency = _dto.CardPriceCurrency,
  26670. diId = _dto.DiId,
  26671. ManagerConfirm = 0,
  26672. SupervisorConfirm = 0,
  26673. SYsupervisorConfirm = 0,
  26674. editType = 1,
  26675. PortType = 1,
  26676. price = _dto.CardPrice,
  26677. PriceCount = 1,
  26678. priceType = 1027,
  26679. priceDetailType = 1044,
  26680. PriceDt = start_Time.ToString("yyyy-MM-dd"),
  26681. priceName = $"酒店超支费用-酒店导入-({start_Time.ToString("yyyy/MM/dd")})",
  26682. });
  26683. }
  26684. }
  26685. }
  26686. start_Time = start_Time.AddDays(1);
  26687. }
  26688. }
  26689. if (extraCostList.Any())
  26690. {
  26691. await _carTouristGuideGroundRep.GroupExtraCost_OperatorList(extraCostList);
  26692. }
  26693. _sqlSugar.CommitTran();
  26694. #endregion
  26695. #region 应用推送
  26696. try
  26697. {
  26698. //int ccpId = (int)_view.Data.GetType().GetProperty("ccpId").GetValue(_view.Data, null);
  26699. //int sign = (int)_view.Data.GetType().GetProperty("sign").GetValue(_view.Data, null);
  26700. //int hotelId = (int)_view.Data.GetType().GetProperty("hotelId").GetValue(_view.Data, null);
  26701. int ccpId = Convert.ToInt32(_view.Data.GetType().GetProperty("ccpId").GetValue(_view.Data, null) ?? 0);
  26702. int sign = Convert.ToInt32(_view.Data.GetType().GetProperty("sign").GetValue(_view.Data, null) ?? 0);
  26703. int hotelId = Convert.ToInt32(_view.Data.GetType().GetProperty("hotelId").GetValue(_view.Data, null) ?? 0);
  26704. var diId = _dto.DiId;
  26705. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  26706. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  26707. #region 操作记录
  26708. var opInfo = new Crm_TableOperationRecord()
  26709. {
  26710. TableName = "Grp_HotelReservations",
  26711. PortType = _dto.PortType,
  26712. DataId = hotelId,
  26713. CreateUserId = _dto.UserId
  26714. };
  26715. //var opStatus = OperationEnum.NoOperation;
  26716. if (_dto.Id < 1) //添加操作
  26717. {
  26718. opInfo.OperationItem = OperationEnum.Add;
  26719. }
  26720. else if (_dto.Id > 0)
  26721. {
  26722. opInfo.OperationItem = OperationEnum.Edit;
  26723. }
  26724. string opRemark = string.Empty;
  26725. if (ccpInfo != null)
  26726. {
  26727. // USD 1211.86、 CNY 8761.75、汇率:7.2300
  26728. var currency = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.Id == ccpInfo.PaymentCurrency).First()?.Name;
  26729. var cnyPrice = ccpInfo.PayMoney * ccpInfo.DayRate;
  26730. opRemark = $"{currency} {ccpInfo.PayMoney.ToString("#0.00")}、CNY {cnyPrice.ToString("#0.00")}、汇率:{ccpInfo.DayRate.ToString("#0.0000")}";
  26731. }
  26732. opInfo.Remark = opRemark;
  26733. await _tableorRep.AddAsync(opInfo);
  26734. #endregion
  26735. _logger.LogInformation($"【iOS推送通知Exception】Begin");
  26736. //2024-10-21 新增LZ UID
  26737. var userIds = new List<int>() { 21 };
  26738. string title = $"费用审核";
  26739. string content = "";
  26740. if (_dto.Id == 0) content = $"[新增-酒店费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  26741. else if (_dto.Id > 0) content = $"[更新-酒店费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  26742. try
  26743. {
  26744. PageParam_PriceAuditH5 h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "76" };
  26745. await APNsTools.iOS_PushNotifications1("051", title, "", content, true, "ExpenseAuditWebView", h5);
  26746. //Logs($"【iOS推送通知PostHotelReservationsAddOrEdit】Start");
  26747. //var iosRes = await APNsTools.iOS_PushNotifications("051", title, "", content);
  26748. //Logs($"【iOS推送通知PostHotelReservationsAddOrEdit】End Response:[{JsonConvert.SerializeObject(iosRes)}]");
  26749. }
  26750. catch (Exception ex)
  26751. {
  26752. Logs($"【iOS推送通知-PostHotelReservationsAddOrEdit-Exception】[{ex.Message}]");
  26753. }
  26754. }
  26755. catch (Exception ex)
  26756. {
  26757. Logs($"【iOS推送通知Exception】【{ex.Message}】");
  26758. }
  26759. try
  26760. {
  26761. //int ccpId = (int)_view.Data.GetType().GetProperty("ccpId").GetValue(_view.Data, null);
  26762. //int sign = (int)_view.Data.GetType().GetProperty("sign").GetValue(_view.Data, null);
  26763. //int hotelId = (int)_view.Data.GetType().GetProperty("hotelId").GetValue(_view.Data, null);
  26764. int ccpId = Convert.ToInt32(_view.Data.GetType().GetProperty("ccpId").GetValue(_view.Data, null) ?? 0);
  26765. int sign = Convert.ToInt32(_view.Data.GetType().GetProperty("sign").GetValue(_view.Data, null) ?? 0);
  26766. int hotelId = Convert.ToInt32(_view.Data.GetType().GetProperty("hotelId").GetValue(_view.Data, null) ?? 0);
  26767. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  26768. //自动审核
  26769. var autoAdit = await _feeAuditRep.FeeAutomaticAudit(1, _dto.DiId, hotelId);
  26770. //if (autoAdit.Code != 200) _view.Msg += $"\r\n{autoAdit.Msg}";
  26771. _logger.LogInformation($"【酒店自动审核】【{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}】执行调用 调用结果:{JsonConvert.SerializeObject(autoAdit)}");
  26772. //2024-10-21 新增LZ UID
  26773. var userIds = new List<int>() { 21 };
  26774. string title = $"系统通知";
  26775. var diId = _dto.DiId;
  26776. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  26777. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  26778. string content = "";
  26779. if (_dto.Id == 0) content = $"[新增-酒店费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  26780. else if (_dto.Id > 0) content = $"[更新-酒店费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  26781. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  26782. }
  26783. catch (Exception ex)
  26784. {
  26785. }
  26786. #endregion
  26787. return Ok(_view);
  26788. }
  26789. /// <summary>
  26790. /// 酒店自动审核测试
  26791. /// Add Or Edit
  26792. /// </summary>
  26793. /// <param name="diid"></param>
  26794. /// <param name="dataId"></param>
  26795. /// <returns></returns>
  26796. [HttpPost]
  26797. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26798. public async Task<IActionResult> PostHotelAutoAuditTest(int diid, int dataId)
  26799. {
  26800. #region 应用推送
  26801. try
  26802. {
  26803. //自动审核
  26804. await _feeAuditRep.FeeAutomaticAudit(1, diid, dataId);
  26805. }
  26806. catch (Exception ex)
  26807. {
  26808. return Ok(JsonView(false, ex.Message));
  26809. }
  26810. #endregion
  26811. return Ok(JsonView(false, "操作成功"));
  26812. }
  26813. /// <summary>
  26814. /// 酒店预订
  26815. /// Del
  26816. /// </summary>
  26817. /// <param name="_dto"></param>
  26818. /// <returns></returns>
  26819. [HttpPost]
  26820. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26821. public async Task<IActionResult> PostHotelReservationsDel(HotelReservationsDelDto _dto)
  26822. {
  26823. #region 参数验证
  26824. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  26825. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  26826. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  26827. #region 团组操作权限验证 76 酒店预定模块
  26828. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  26829. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  26830. #endregion
  26831. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  26832. #region 页面操作权限验证
  26833. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  26834. if (pageFunAuthView.DeleteAuth == 0) return Ok(JsonView(false, "您没有删除权限!"));
  26835. #endregion
  26836. #endregion
  26837. //验证
  26838. (bool valid, string msg) = await GeneralMethod.FeeOpValid(_dto.Id, 76);
  26839. if (!valid) return Ok(JsonView(false, msg));
  26840. var data = await _hotelPriceRep.Del(_dto.Id, _dto.UserId);
  26841. #region 操作记录
  26842. await _tableorRep.AddAsync(new Crm_TableOperationRecord()
  26843. {
  26844. TableName = "Grp_HotelReservations",
  26845. PortType = _dto.PortType,
  26846. OperationItem = OperationEnum.Del,
  26847. DataId = _dto.Id,
  26848. CreateUserId = _dto.UserId
  26849. });
  26850. #endregion
  26851. return Ok(data);
  26852. }
  26853. /// <summary>
  26854. /// 酒店预订
  26855. /// 生成VOUCHER
  26856. /// 2024.05.06 之前版本
  26857. /// </summary>
  26858. /// <param name="_dto"></param>
  26859. /// <returns></returns>
  26860. [HttpPost]
  26861. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26862. public async Task<IActionResult> PostHotelReservationsCreateVoucherOld(HotelReservationsCreateVoucherDto _dto)
  26863. {
  26864. try
  26865. {
  26866. #region 参数验证
  26867. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  26868. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  26869. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  26870. if (_dto.Id < 1) return Ok(JsonView(false, "Id为空"));
  26871. #region 团组操作权限验证 76 酒店预定模块
  26872. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  26873. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  26874. #endregion
  26875. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  26876. #region 页面操作权限验证
  26877. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  26878. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  26879. #endregion
  26880. #endregion
  26881. Grp_HotelReservations hr = await _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && it.Id == _dto.Id).FirstAsync();
  26882. //判断数据是否完整
  26883. if (hr != null)
  26884. {
  26885. if (!string.IsNullOrEmpty(hr.DetermineNo))
  26886. {
  26887. string strFileName = "HotelStatement/";
  26888. Grp_DelegationInfo dele = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == _dto.DiId).FirstAsync();
  26889. if (dele != null)
  26890. strFileName += dele.TourCode;
  26891. //载入模板
  26892. string sss = AppSettingsHelper.Get("WordBasePath") + "Template/酒店预订模板.doc";
  26893. Document doc = new Document(sss);
  26894. DocumentBuilder builder = new DocumentBuilder(doc);
  26895. #region 替换Word模板书签内容
  26896. //这里可以创建个DataTable循环添加书签的值,这里提示一下就不多做修改了
  26897. //入住卷预定号码
  26898. if (doc.Range.Bookmarks["VNO"] != null)
  26899. {
  26900. Bookmark mark = doc.Range.Bookmarks["VNO"];
  26901. mark.Text = hr.CheckNumber;
  26902. }
  26903. //酒店时间
  26904. if (doc.Range.Bookmarks["Date"] != null)
  26905. {
  26906. Bookmark mark = doc.Range.Bookmarks["Date"];
  26907. mark.Text = Convert.ToDateTime(hr.CreateTime).ToString("yyyy-MM-dd");
  26908. }
  26909. //团号
  26910. if (doc.Range.Bookmarks["TNo"] != null)
  26911. {
  26912. Bookmark mark = doc.Range.Bookmarks["TNo"];
  26913. mark.Text = dele.TourCode;
  26914. }
  26915. //预定号码
  26916. if (doc.Range.Bookmarks["BookingId"] != null)
  26917. {
  26918. Bookmark mark = doc.Range.Bookmarks["BookingId"];
  26919. mark.Text = hr.ReservationsNo;
  26920. }
  26921. if (doc.Range.Bookmarks["HotelConfirmNo"] != null)
  26922. {
  26923. Bookmark mark = doc.Range.Bookmarks["HotelConfirmNo"];
  26924. mark.Text = hr.DetermineNo;
  26925. }
  26926. //酒店城市
  26927. if (doc.Range.Bookmarks["City"] != null)
  26928. {
  26929. Bookmark mark = doc.Range.Bookmarks["City"];
  26930. mark.Text = hr.City;
  26931. }
  26932. //酒店名称
  26933. if (doc.Range.Bookmarks["HName"] != null)
  26934. {
  26935. Bookmark mark = doc.Range.Bookmarks["HName"];
  26936. mark.Text = hr.HotelName;
  26937. }
  26938. //酒店地址
  26939. if (doc.Range.Bookmarks["Address"] != null)
  26940. {
  26941. Bookmark mark = doc.Range.Bookmarks["Address"];
  26942. mark.Text = hr.HotelAddress;
  26943. }
  26944. //酒店电话
  26945. if (doc.Range.Bookmarks["Tel"] != null)
  26946. {
  26947. Bookmark mark = doc.Range.Bookmarks["Tel"];
  26948. mark.Text = hr.HotelTel;
  26949. }
  26950. //酒店传真
  26951. if (doc.Range.Bookmarks["Fax"] != null)
  26952. {
  26953. Bookmark mark = doc.Range.Bookmarks["Fax"];
  26954. if (!string.IsNullOrWhiteSpace(hr.HotelFax))
  26955. {
  26956. mark.Text = hr.HotelFax;
  26957. }
  26958. }
  26959. //入住时间
  26960. if (doc.Range.Bookmarks["CIn"] != null)
  26961. {
  26962. DateTime dtCheckIn = Convert.ToDateTime(hr.CheckInDate);
  26963. Bookmark mark = doc.Range.Bookmarks["CIn"];
  26964. mark.Text = dtCheckIn.Day + " " + dtCheckIn.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckIn.Year;
  26965. }
  26966. //退房时间
  26967. if (doc.Range.Bookmarks["COut"] != null)
  26968. {
  26969. DateTime dtCheckOut = Convert.ToDateTime(hr.CheckOutDate);
  26970. Bookmark mark = doc.Range.Bookmarks["COut"];
  26971. mark.Text = dtCheckOut.Day + " " + dtCheckOut.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckOut.Year;
  26972. }
  26973. //客户名称
  26974. if (doc.Range.Bookmarks["GName"] != null)
  26975. {
  26976. string guestName = "";
  26977. string[] clients = Array.Empty<string>();
  26978. if (hr.GuestName.Contains(","))
  26979. {
  26980. clients = hr.GuestName.Split(",");
  26981. }
  26982. else
  26983. {
  26984. clients = new string[] { hr.GuestName };
  26985. }
  26986. List<int> clientIds_int = new List<int>();
  26987. if (clients.Length > 0)
  26988. {
  26989. foreach (var item in clients)
  26990. {
  26991. if (item.IsNumeric())
  26992. {
  26993. clientIds_int.Add(int.Parse(item));
  26994. }
  26995. }
  26996. }
  26997. if (clientIds_int.Count > 0)
  26998. {
  26999. var _clientDatas = _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0 && clientIds_int.Contains(it.Id)).ToList();
  27000. foreach (var client in _clientDatas)
  27001. {
  27002. //男
  27003. if (client.Sex == 0) guestName += $"Mr.";
  27004. //女
  27005. else if (client.Sex == 1) guestName += $"Ms.";
  27006. if (!String.IsNullOrEmpty(client.FirstName + client.LastName))
  27007. {
  27008. guestName += $"{string.Join("", client.FirstName.GetTotalPingYin()).ToUpper()} {string.Join("", client.LastName.GetTotalPingYin()).ToUpper()},";
  27009. }
  27010. //guestName += $"{client.Pinyin},";
  27011. }
  27012. if (guestName.Length > 0)
  27013. {
  27014. guestName = guestName.Substring(0, guestName.Length - 1);
  27015. }
  27016. }
  27017. else
  27018. {
  27019. guestName = hr.GuestName;
  27020. }
  27021. Bookmark mark = doc.Range.Bookmarks["GName"];
  27022. mark.Text = guestName;
  27023. }
  27024. //房间介绍
  27025. if (doc.Range.Bookmarks["ROOM"] != null)
  27026. {
  27027. Bookmark mark = doc.Range.Bookmarks["ROOM"];
  27028. mark.Text = hr.RoomExplanation;
  27029. }
  27030. //报价描述
  27031. if (doc.Range.Bookmarks["NOTE"] != null)
  27032. {
  27033. Bookmark mark = doc.Range.Bookmarks["NOTE"];
  27034. Sys_SetData ss = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == hr.ReservationsWebsite);
  27035. if (ss != null)
  27036. mark.Text = ss.Name;
  27037. }
  27038. //入住时间
  27039. if (doc.Range.Bookmarks["CheckIn"] != null)
  27040. {
  27041. DateTime dtCheckIn = Convert.ToDateTime(hr.CheckInDate);
  27042. Bookmark mark = doc.Range.Bookmarks["CheckIn"];
  27043. mark.Text = dtCheckIn.Day + " " + dtCheckIn.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckIn.Year + " ";
  27044. }
  27045. //退房时间
  27046. if (doc.Range.Bookmarks["CheckOut"] != null)
  27047. {
  27048. DateTime dtCheckOut = Convert.ToDateTime(hr.CheckOutDate);
  27049. Bookmark mark = doc.Range.Bookmarks["CheckOut"];
  27050. mark.Text = " " + dtCheckOut.Day + " " + dtCheckOut.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckOut.Year;
  27051. }
  27052. //日期
  27053. if (doc.Range.Bookmarks["DT"] != null)
  27054. {
  27055. Bookmark mark = doc.Range.Bookmarks["DT"];
  27056. mark.Text = Convert.ToDateTime(hr.CreateTime).ToString("yyyy-MM-dd");
  27057. }
  27058. //名称
  27059. if (doc.Range.Bookmarks["VName"] != null)
  27060. {
  27061. Bookmark mark = doc.Range.Bookmarks["VName"];
  27062. mark.Text = hr.HotelName;
  27063. }
  27064. //号码
  27065. if (doc.Range.Bookmarks["VOUCHERNO"] != null)
  27066. {
  27067. Bookmark mark = doc.Range.Bookmarks["VOUCHERNO"];
  27068. mark.Text = hr.CheckNumber;
  27069. }
  27070. #endregion
  27071. strFileName += "VOUCHER.doc";
  27072. var fileDir = AppSettingsHelper.Get("WordBasePath") + strFileName;
  27073. doc.Save(fileDir);
  27074. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/" + strFileName;
  27075. return Ok(JsonView(true, "操作成功!", Url));
  27076. }
  27077. else
  27078. {
  27079. return Ok(JsonView(false, "酒店确定号码未填写,无法生成Voucher!"));
  27080. }
  27081. }
  27082. else
  27083. {
  27084. return Ok(JsonView(false, "该条数据已删除或不存在!"));
  27085. }
  27086. }
  27087. catch (Exception ex)
  27088. {
  27089. return Ok(JsonView(false, ex.Message));
  27090. }
  27091. }
  27092. /// <summary>
  27093. /// 酒店预订
  27094. /// 生成VOUCHER
  27095. /// 2024.05.06 之后版本
  27096. /// </summary>
  27097. /// <param name="_dto"></param>
  27098. /// <returns></returns>
  27099. [HttpPost]
  27100. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27101. public async Task<IActionResult> PostHotelReservationsCreateVoucher(HotelReservationsCreateVoucherDto _dto)
  27102. {
  27103. #region 参数验证
  27104. if (_dto.UserId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "员工Id为空", ""));
  27105. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  27106. if (_dto.DiId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组Id为空", ""));
  27107. #region 团组操作权限验证 76 酒店预定模块
  27108. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  27109. if (groupAuthView.Code != 0) return Ok(JsonView(StatusCodes.Status400BadRequest, groupAuthView.Msg, ""));
  27110. #endregion
  27111. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  27112. #region 页面操作权限验证
  27113. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  27114. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  27115. #endregion
  27116. #endregion
  27117. List<Grp_HotelReservations> hrDtas = await _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && it.DiId == _dto.DiId).ToListAsync();
  27118. //判断数据是否完整
  27119. if (hrDtas.Count < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "请先录入酒店预订信息!", ""));
  27120. hrDtas = hrDtas.OrderBy(it => it.CheckInDate).ToList();
  27121. string strFileName = "HotelStatement/";
  27122. string guestNames = ""; //格式Mr.xxx Ms.xxx
  27123. List<HotelVoucherInfoView> vouchers = new List<HotelVoucherInfoView>();
  27124. #region 数据处理
  27125. List<int> guestIds = new List<int>();
  27126. //int index = 0;
  27127. foreach (var item in hrDtas)
  27128. {
  27129. if (item.GuestName.Contains(","))
  27130. {
  27131. string[] guestIdArr = item.GuestName.Split(',');
  27132. foreach (var guestIdStr in guestIdArr)
  27133. {
  27134. bool guestBool = int.TryParse(guestIdStr, out int guestId);
  27135. if (guestBool)
  27136. {
  27137. guestIds.Add(guestId);
  27138. }
  27139. }
  27140. }
  27141. else guestNames += item.GuestName;
  27142. var voucherInfo = new HotelVoucherInfoView()
  27143. {
  27144. HotelName = item.HotelName,
  27145. CheckInDate = item.CheckInDate,
  27146. CheckOutDate = item.CheckOutDate,
  27147. ConfirmationNumber = item.DetermineNo.Trim(),
  27148. RoomType = item.RoomExplanation
  27149. };
  27150. vouchers.Add(voucherInfo);
  27151. }
  27152. if (guestIds.Count > 0)
  27153. {
  27154. guestIds = guestIds.Distinct().ToList();
  27155. var guestDatas = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0 && guestIds.Contains(it.Id)).ToListAsync();
  27156. if (guestDatas.Count > 0)
  27157. {
  27158. guestNames = "";
  27159. foreach (var guest in guestDatas)
  27160. {
  27161. string guestName = "";
  27162. if (guest.Sex == 0) guestName += @"MR.";
  27163. else if (guest.Sex == 1) guestName += @"MS.";
  27164. if (guest.Pinyin == null) guestName += $"{string.Join("", guest.LastName.GetTotalPingYin()).ToUpper()}/{string.Join("", guest.FirstName.GetTotalPingYin()).ToUpper()}";
  27165. else guestName += @$"{guest.Pinyin.Replace(" ", "")}";
  27166. guestNames += @$"{guestName.Trim()}、";
  27167. }
  27168. if (guestNames.Length > 0)
  27169. {
  27170. guestNames = guestNames.Substring(0, guestNames.Length - 1);
  27171. }
  27172. }
  27173. }
  27174. #endregion
  27175. //载入模板
  27176. string sss = AppSettingsHelper.Get("WordBasePath") + "Template/Voucher-2024Versions.docx";
  27177. Document doc = new Document(sss);
  27178. DocumentBuilder builder = new DocumentBuilder(doc);
  27179. if (doc.Range.Bookmarks["GuestName"] != null)
  27180. {
  27181. Bookmark mark = doc.Range.Bookmarks["GuestName"];
  27182. mark.Text = guestNames;
  27183. }
  27184. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  27185. Aspose.Words.Tables.Table table = allTables[0] as Aspose.Words.Tables.Table;
  27186. vouchers = vouchers.OrderBy(it => it.CheckInDate).ToList();
  27187. for (int i = 1; i <= vouchers.Count; i++)
  27188. {
  27189. HotelVoucherInfoView hviv = vouchers[i - 1];
  27190. builder.MoveToCell(0, i, 0, 0);
  27191. builder.Write(hviv.HotelName);
  27192. builder.MoveToCell(0, i, 1, 0);
  27193. builder.Write(hviv.CheckInDate);
  27194. builder.MoveToCell(0, i, 2, 0);
  27195. builder.Write(hviv.CheckOutDate);
  27196. builder.MoveToCell(0, i, 3, 0);
  27197. builder.Write(hviv.RoomType);
  27198. builder.MoveToCell(0, i, 4, 0);
  27199. builder.Write(hviv.ConfirmationNumber);
  27200. }
  27201. //删除多余行
  27202. int currRowIndex = vouchers.Count + 1;
  27203. int delRows = 21 - currRowIndex;
  27204. if (delRows > 0)
  27205. {
  27206. for (int i = 0; i < delRows; i++)
  27207. {
  27208. table.Rows.RemoveAt(currRowIndex);
  27209. //cultivateRowIndex++;
  27210. }
  27211. }
  27212. strFileName += "VOUCHER.docx";
  27213. var fileDir = AppSettingsHelper.Get("WordBasePath") + strFileName;
  27214. doc.Save(fileDir);
  27215. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/" + strFileName;
  27216. return Ok(JsonView(true, "操作成功!", Url));
  27217. }
  27218. /// <summary>
  27219. /// 酒店预订
  27220. /// 生成VOUCHER 批量生成
  27221. /// New
  27222. /// </summary>
  27223. /// <param name="_dto"></param>
  27224. /// <returns></returns>
  27225. [HttpPost]
  27226. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27227. public async Task<IActionResult> PostHotelReservationsCreateVoucherBatchNew(HotelReservationsCreateVoucherDto _dto)
  27228. {
  27229. #region 参数验证
  27230. if (_dto.UserId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "员工Id为空", ""));
  27231. if (_dto.PageId < 1) _dto.PageId = 28;
  27232. if (_dto.DiId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组Id为空", ""));
  27233. #region 团组操作权限验证 76 酒店预定模块
  27234. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  27235. if (groupAuthView.Code != 0) return Ok(JsonView(StatusCodes.Status400BadRequest, groupAuthView.Msg, ""));
  27236. #endregion
  27237. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  27238. #region 页面操作权限验证
  27239. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  27240. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  27241. #endregion
  27242. #endregion
  27243. var hrDtas = await _sqlSugar.Queryable<Grp_HotelReservations>()
  27244. .Where(it => it.IsDel == 0 && it.DiId == _dto.DiId)
  27245. .OrderBy(x => x.CheckInDate)
  27246. .ToListAsync();
  27247. //判断数据是否完整
  27248. if (hrDtas.Count < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "请先录入酒店预订信息!", ""));
  27249. string strFileName = "HotelStatement/";
  27250. var dele = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == _dto.DiId).FirstAsync();
  27251. if (dele != null)
  27252. strFileName += $"{dele?.TeamName ?? ""}_{dele.TourCode}_";
  27253. var guestDatas = await _sqlSugar.Queryable<Crm_DeleClient>()
  27254. .Select(x => new Crm_DeleClient { Id = x.Id, FirstName = x.FirstName, LastName = x.LastName, Pinyin = x.Pinyin })
  27255. .Where(it => it.IsDel == 0)
  27256. .ToListAsync();
  27257. foreach (var item in guestDatas) EncryptionProcessor.DecryptProperties(item);
  27258. for (int i = 0; i < hrDtas.Count; i++)
  27259. {
  27260. string guestNames = string.Empty;
  27261. List<int> guestIds = new List<int>();
  27262. var item = hrDtas[i];
  27263. //处理客户姓名
  27264. if (item.GuestName.Contains(","))
  27265. {
  27266. string[] guestIdArr = item.GuestName.Split(',');
  27267. foreach (var guestIdStr in guestIdArr)
  27268. if (int.TryParse(guestIdStr, out int guestId))
  27269. guestIds.Add(guestId);
  27270. }
  27271. else
  27272. {
  27273. bool guestIdBool = int.TryParse(item.GuestName, out int guestId);
  27274. if (guestIdBool)
  27275. {
  27276. guestIds.Add(guestId);
  27277. }
  27278. //NaN
  27279. if (item.GuestName.Contains("NaN"))
  27280. {
  27281. guestNames += item.GuestName.Replace("NaN", "").Replace(",", "");
  27282. }
  27283. }
  27284. if (guestIds.Count > 0)
  27285. {
  27286. guestIds = guestIds.Distinct().ToList();
  27287. var guestDatas1 = guestDatas.Where(it => guestIds.Contains(it.Id)).ToList();
  27288. if (guestDatas1.Count > 0)
  27289. {
  27290. guestNames = "";
  27291. foreach (var guest in guestDatas1)
  27292. {
  27293. string guestName = "";
  27294. if (guest.Sex == 0) guestName += @"MR.";
  27295. else if (guest.Sex == 1) guestName += @"MS.";
  27296. if (guest.Pinyin == null) guestName += $"{string.Join("", guest.LastName.GetTotalPingYin()).ToUpper()}/{string.Join("", guest.FirstName.GetTotalPingYin()).ToUpper()}";
  27297. else guestName += @$"{guest.Pinyin.Replace(" ", "")}";
  27298. guestNames += @$"{guestName.Trim()}、";
  27299. }
  27300. if (guestNames.Length > 0)
  27301. {
  27302. guestNames = guestNames.Substring(0, guestNames.Length - 1);
  27303. }
  27304. }
  27305. }
  27306. //if (!string.IsNullOrEmpty(guestNames))
  27307. //{
  27308. hrDtas[i].GuestName = guestNames;
  27309. //}
  27310. }
  27311. strFileName += $"VOUCHER_{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
  27312. Document doc = new Document();
  27313. DocumentBuilder builder = new DocumentBuilder(doc);
  27314. try
  27315. {
  27316. builder.MoveToDocumentStart();
  27317. foreach (var item in hrDtas)
  27318. {
  27319. //标题
  27320. builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Title;
  27321. builder.ParagraphFormat.LineSpacing = 1;
  27322. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27323. builder.ParagraphFormat.Style.Font.Size = 9;
  27324. builder.ParagraphFormat.Style.Font.Bold = true;
  27325. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  27326. builder.Writeln(@$"ACCOMMODATION VOUCHER");
  27327. builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Title;
  27328. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  27329. builder.ParagraphFormat.LineSpacing = 1;
  27330. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27331. builder.ParagraphFormat.Style.Font.Size = 9;
  27332. builder.ParagraphFormat.Style.Font.Bold = true;
  27333. builder.Writeln(@$"VOUCHER No:{item.CheckNumber} DATE: {item.CreateTime.ToString("yyyy-MM-dd")}");
  27334. builder.StartTable();
  27335. // 设置边框颜色
  27336. builder.CellFormat.Borders.Top.Color = System.Drawing.Color.Black;
  27337. //设置边框样式
  27338. builder.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.Dot;
  27339. //表格
  27340. #region 第一行
  27341. builder.InsertCell();
  27342. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27343. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27344. //builder.CellFormat.AllowAutoFit = false;
  27345. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27346. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27347. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27348. builder.CellFormat.WrapText = true; //自动换行
  27349. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  27350. builder.RowFormat.AllowBreakAcrossPages = false; //文字自适应大小
  27351. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27352. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27353. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27354. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27355. builder.Write("TOUR NO:");
  27356. builder.InsertCell();
  27357. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27358. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27359. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27360. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27361. builder.ParagraphFormat.Style.Font.Bold = false;
  27362. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27363. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  27364. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27365. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27366. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27367. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27368. builder.Write($"{dele?.TourCode ?? "-"}");
  27369. builder.InsertCell();
  27370. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27371. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27372. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27373. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27374. builder.ParagraphFormat.Style.Font.Bold = false;
  27375. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27376. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  27377. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27378. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27379. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27380. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27381. builder.Write($"CITY:");
  27382. builder.InsertCell();
  27383. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27384. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27385. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27386. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27387. builder.ParagraphFormat.Style.Font.Bold = false;
  27388. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27389. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  27390. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27391. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27392. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27393. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27394. builder.Write($"{item.City}");
  27395. builder.EndRow();
  27396. #endregion
  27397. #region 第二行
  27398. builder.InsertCell();
  27399. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27400. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27401. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27402. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27403. builder.ParagraphFormat.Style.Font.Bold = false;
  27404. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27405. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  27406. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27407. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27408. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27409. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27410. builder.Write("CONFIRMATION NO:");
  27411. builder.InsertCell();
  27412. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27413. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27414. builder.ParagraphFormat.Style.Font.Size = 8;
  27415. builder.ParagraphFormat.Style.Font.Bold = false;
  27416. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27417. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27418. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  27419. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27420. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27421. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27422. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27423. builder.CellFormat.HorizontalMerge = CellMerge.First;
  27424. builder.Write($"{item.DetermineNo}");
  27425. builder.InsertCell();
  27426. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27427. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  27428. builder.InsertCell();
  27429. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27430. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  27431. builder.EndRow();
  27432. #endregion
  27433. #region 第三行
  27434. builder.InsertCell();
  27435. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27436. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27437. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27438. builder.ParagraphFormat.Style.Font.Bold = false;
  27439. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27440. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27441. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  27442. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27443. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27444. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27445. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27446. builder.Write($"HOTEL NAME:");
  27447. builder.InsertCell();
  27448. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27449. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27450. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27451. builder.ParagraphFormat.Style.Font.Bold = false;
  27452. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27453. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27454. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  27455. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27456. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27457. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27458. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27459. builder.CellFormat.HorizontalMerge = CellMerge.First;
  27460. builder.Write($"{item.HotelName}");
  27461. builder.InsertCell();
  27462. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27463. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  27464. builder.InsertCell();
  27465. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27466. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  27467. builder.EndRow();
  27468. #endregion
  27469. #region 第四行
  27470. builder.InsertCell();
  27471. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27472. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27473. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27474. builder.ParagraphFormat.Style.Font.Bold = false;
  27475. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27476. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27477. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  27478. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27479. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27480. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27481. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27482. builder.Write($"HOTEL ADDRESS:");
  27483. builder.InsertCell();
  27484. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27485. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27486. builder.ParagraphFormat.Style.Font.Size = 8;
  27487. builder.ParagraphFormat.Style.Font.Bold = false;
  27488. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27489. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27490. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  27491. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27492. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27493. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27494. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27495. builder.CellFormat.HorizontalMerge = CellMerge.First;
  27496. builder.Write($"{item.HotelAddress}");
  27497. builder.InsertCell();
  27498. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27499. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  27500. builder.InsertCell();
  27501. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27502. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  27503. builder.EndRow();
  27504. #endregion
  27505. #region 第五行
  27506. builder.InsertCell();
  27507. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27508. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27509. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27510. builder.ParagraphFormat.Style.Font.Bold = false;
  27511. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27512. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27513. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  27514. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27515. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27516. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27517. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27518. builder.Write("TEL:");
  27519. builder.InsertCell();
  27520. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27521. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27522. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27523. builder.ParagraphFormat.Style.Font.Bold = false;
  27524. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27525. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27526. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  27527. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27528. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27529. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27530. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27531. builder.Write($"{item.HotelTel}");
  27532. builder.InsertCell();
  27533. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27534. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27535. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27536. builder.ParagraphFormat.Style.Font.Bold = false;
  27537. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27538. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27539. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  27540. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27541. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27542. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27543. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27544. builder.Write($"FAX:");
  27545. builder.InsertCell();
  27546. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27547. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27548. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27549. builder.ParagraphFormat.Style.Font.Bold = false;
  27550. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27551. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27552. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  27553. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27554. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27555. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27556. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27557. builder.Write($"{item.HotelFax}");
  27558. builder.EndRow();
  27559. #endregion
  27560. #region 第六行
  27561. builder.InsertCell();
  27562. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27563. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27564. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27565. builder.ParagraphFormat.Style.Font.Bold = false;
  27566. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27567. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27568. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  27569. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27570. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27571. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27572. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27573. builder.Write("CHECK IN:");
  27574. builder.InsertCell();
  27575. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27576. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27577. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27578. builder.ParagraphFormat.Style.Font.Bold = false;
  27579. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27580. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27581. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  27582. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27583. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27584. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27585. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27586. DateTime dtCheckIn = Convert.ToDateTime(item.CheckInDate);
  27587. string checkInStr = dtCheckIn.Day + " " + dtCheckIn.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckIn.Year + " ";
  27588. builder.Write($"{checkInStr}");
  27589. builder.InsertCell();
  27590. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27591. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27592. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27593. builder.ParagraphFormat.Style.Font.Bold = false;
  27594. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27595. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27596. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  27597. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27598. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27599. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27600. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27601. builder.Write($"CHECK OUT:");
  27602. builder.InsertCell();
  27603. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27604. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27605. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27606. builder.ParagraphFormat.Style.Font.Bold = false;
  27607. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27608. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27609. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  27610. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27611. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27612. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27613. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27614. DateTime dtCheckOut = Convert.ToDateTime(item.CheckOutDate);
  27615. string checkOutStr = dtCheckOut.Day + " " + dtCheckOut.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckOut.Year + " ";
  27616. builder.Write($"{checkOutStr}");
  27617. builder.EndRow();
  27618. #endregion
  27619. #region 第七行
  27620. builder.InsertCell();
  27621. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27622. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27623. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27624. builder.ParagraphFormat.Style.Font.Bold = false;
  27625. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27626. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27627. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  27628. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27629. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27630. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27631. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27632. builder.Write($"GUEST NAME:");
  27633. builder.InsertCell();
  27634. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27635. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27636. builder.ParagraphFormat.Style.Font.Size = 8;
  27637. builder.ParagraphFormat.Style.Font.Bold = false;
  27638. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27639. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27640. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  27641. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27642. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27643. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27644. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27645. builder.CellFormat.HorizontalMerge = CellMerge.First;
  27646. builder.Write($"{item.GuestName.Trim()}");
  27647. builder.InsertCell();
  27648. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27649. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  27650. builder.InsertCell();
  27651. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27652. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  27653. builder.EndRow();
  27654. #endregion
  27655. #region 第八行
  27656. builder.InsertCell();
  27657. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27658. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27659. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27660. builder.ParagraphFormat.Style.Font.Bold = false;
  27661. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27662. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27663. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  27664. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27665. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27666. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27667. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27668. builder.Write($"ROOM TYPE:");
  27669. builder.InsertCell();
  27670. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27671. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27672. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27673. builder.ParagraphFormat.Style.Font.Bold = false;
  27674. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27675. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27676. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  27677. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27678. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27679. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27680. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27681. builder.CellFormat.HorizontalMerge = CellMerge.First;
  27682. builder.Write($"{item.RoomExplanation}");
  27683. builder.InsertCell();
  27684. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27685. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  27686. builder.InsertCell();
  27687. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27688. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  27689. builder.EndRow();
  27690. #endregion
  27691. #region 第九行
  27692. builder.InsertCell();
  27693. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27694. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27695. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27696. builder.ParagraphFormat.Style.Font.Bold = false;
  27697. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27698. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27699. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  27700. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  27701. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  27702. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  27703. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  27704. builder.Write($"NOTE:");
  27705. builder.InsertCell();
  27706. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27707. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  27708. builder.ParagraphFormat.Style.Font.Size = 7.5;
  27709. builder.ParagraphFormat.Style.Font.Bold = false;
  27710. builder.CellFormat.HorizontalMerge = CellMerge.None;
  27711. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  27712. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  27713. builder.CellFormat.HorizontalMerge = CellMerge.First;
  27714. 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.");
  27715. builder.InsertCell();
  27716. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  27717. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  27718. builder.InsertCell();
  27719. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  27720. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  27721. builder.EndRow();
  27722. #endregion
  27723. builder.EndTable();
  27724. //换行
  27725. builder.Writeln("");
  27726. builder.Writeln("");
  27727. }
  27728. #region 获取文档中的所有表格 设置文字自适应
  27729. // 获取文档中的所有表格。
  27730. foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
  27731. {
  27732. // 遍历表格中的所有行。
  27733. foreach (Aspose.Words.Tables.Row row in table.Rows)
  27734. {
  27735. foreach (Cell cell in row.Cells)
  27736. {
  27737. Aspose.Words.Tables.CellFormat cellFormat = cell.CellFormat;
  27738. cellFormat.Width = 0;
  27739. }
  27740. }
  27741. }
  27742. #endregion
  27743. #region 设置页眉
  27744. builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
  27745. string voucherHeaderPath = $"./Images/VoucherHeader.png";
  27746. if (System.IO.File.Exists(voucherHeaderPath))
  27747. {
  27748. byte[] imageBytes = System.IO.File.ReadAllBytes(voucherHeaderPath);
  27749. //Image image = Image.FromStream(imageBytes, ImageType.Png);
  27750. //builder.InsertImage(imageBytes, RelativeHorizontalPosition.Margin, 0, RelativeVerticalPosition.Margin, 0, 81, 36, WrapType.None);
  27751. Aspose.Words.Drawing.Shape shape = builder.InsertImage(imageBytes);
  27752. // 调整图片位置
  27753. shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page; // 将图片的水平位置设置为页面
  27754. shape.RelativeVerticalPosition = RelativeVerticalPosition.TopMargin; // 将图片的垂直位置设置为页眉上边距
  27755. shape.Top = 50; // 将图片距离页眉上边缘的距离
  27756. shape.Left = 0; // 将图片距离页面左边缘的距离
  27757. shape.Width = 81; // 设置图片宽度
  27758. shape.Height = 36; // 设置图片高度
  27759. }
  27760. //靠右
  27761. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  27762. //// 设置页脚上下边距
  27763. //builder.PageSetup.HeaderDistance = 42;
  27764. // 添加页眉线
  27765. Aspose.Words.Border borderHeader = null;
  27766. try
  27767. {
  27768. borderHeader = builder.ParagraphFormat.Borders.Bottom;
  27769. }
  27770. catch (Exception e)
  27771. {
  27772. // TODO Auto-generated catch block
  27773. //e.printStackTrace();
  27774. }
  27775. borderHeader.Shadow = true;
  27776. borderHeader.DistanceFromText = 2;
  27777. borderHeader.LineStyle = Aspose.Words.LineStyle.Single;
  27778. #endregion
  27779. }
  27780. catch (Exception ex)
  27781. {
  27782. }
  27783. var fileDir = AppSettingsHelper.Get("WordBasePath") + strFileName;
  27784. doc.Save(fileDir);
  27785. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/" + strFileName;
  27786. return Ok(JsonView(true, "操作成功!", Url));
  27787. }
  27788. /// <summary>
  27789. /// 酒店预订
  27790. /// 生成 预定成本 Excel
  27791. /// </summary>
  27792. /// <param name="_dto"></param>
  27793. /// <returns></returns>
  27794. [HttpPost]
  27795. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27796. public async Task<IActionResult> PostHotelReservationsPredictedCostFileDownload(HotelReservations_PCFD_DTO _dto)
  27797. {
  27798. #region 参数验证
  27799. var vadalitor = new HotelReservations_PCFD_DTOFoalidator();
  27800. var vadalitorRes = await vadalitor.ValidateAsync(_dto);
  27801. if (!vadalitorRes.IsValid)
  27802. {
  27803. var errors = new StringBuilder();
  27804. foreach (var valid in vadalitorRes.Errors) errors.AppendLine(valid.ErrorMessage);
  27805. return Ok(JsonView(StatusCodes.Status400BadRequest, errors.ToString(), ""));
  27806. }
  27807. #region 团组操作权限验证 76 酒店预定模块
  27808. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  27809. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  27810. #endregion
  27811. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  27812. #region 页面操作权限验证
  27813. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  27814. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  27815. #endregion
  27816. #endregion
  27817. decimal _rate = 1.00M;
  27818. string _currency = string.Empty;
  27819. var currDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.STid == 66).ToList();
  27820. var hrDtas = _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && it.DiId == _dto.DiId).ToList();
  27821. if (hrDtas.Count < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "酒店预订费用未录入,不支持预定成本Excel导出", ""));
  27822. var hotelSubData = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => it.IsDel == 0 && it.DiId == _dto.DiId).ToList();
  27823. var ccpData = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.IsDel == 0 && it.DIId == _dto.DiId && it.CTable == 76).ToList();
  27824. var _GroupCostParameter = _sqlSugar.Queryable<Grp_GroupCostParameter>().Where(it => it.IsDel == 0 && it.DiId == _dto.DiId).First();
  27825. //if (_GroupCostParameter == null) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组成本费用未录入,不支持预定成本Excel导出", ""));
  27826. if (_GroupCostParameter == null)
  27827. {
  27828. //return Ok(JsonView(StatusCodes.Status400BadRequest, "团组成本费用“币种为录入”未录入,不支持预定成本Excel导出", ""));
  27829. bool isIntType = int.TryParse(_currency, out int currId);
  27830. if (isIntType)
  27831. {
  27832. _currency = currDatas.Find(it => it.Id == currId)?.Name ?? "";
  27833. }
  27834. var teamRate = await _teamRateRep.PostGroupTeamRateItemByDiIdAndCTableId(1, _dto.DiId, 76);
  27835. var currInfo = teamRate.Find(it => it.CurrencyCode.Equals(_currency));
  27836. if (currInfo == null)
  27837. {
  27838. //return Ok(JsonView(StatusCodes.Status400BadRequest, $"团组汇率-->酒店模块 {_currency} 币种未设置汇率,不支持预定成本Excel导出", ""));
  27839. }
  27840. else _rate = currInfo.Rate;
  27841. if (!string.IsNullOrEmpty(_currency) && !_currency.ToUpper().Equals("CNY"))
  27842. {
  27843. _rate = _GroupCostParameter.Rate;
  27844. }
  27845. hrDtas = hrDtas.OrderBy(it => it.CheckInDate).ToList();
  27846. //string strFileName = "HotelStatement/";
  27847. //string guestNames = ""; //格式Mr.xxx Ms.xxx
  27848. List<HotelReservations_PCFD_View> pcfds = new List<HotelReservations_PCFD_View>();
  27849. var rateDatas = new List<dynamic>();
  27850. #region 数据处理
  27851. foreach (var item in hrDtas)
  27852. {
  27853. var ccpInfo = ccpData.Where(it => it.DIId == _dto.DiId && it.CId == item.Id).First();
  27854. var roomInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 1).FirstOrDefault(); //房费
  27855. var breakfastInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 2).FirstOrDefault(); //早餐
  27856. var governmentRentInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 3).FirstOrDefault(); //地税
  27857. var cityTaxInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 4).FirstOrDefault(); //城市税
  27858. if (ccpInfo == null || roomInfo == null || breakfastInfo == null || governmentRentInfo == null || cityTaxInfo == null)
  27859. {
  27860. continue;
  27861. }
  27862. string roomCurr = currDatas.Find(it => it.Id == roomInfo?.Currency)?.Name ?? "";
  27863. if (string.IsNullOrEmpty(_currency)) _currency = $"CNY";
  27864. string singleRoomFeeStr = string.Empty,
  27865. doubleRoomFeeStr = string.Empty,
  27866. suiteRoomFeeStr = string.Empty,
  27867. otherRoomFeeStr = string.Empty,
  27868. payMoneyStr = string.Empty,
  27869. cardPriceStr = string.Empty;
  27870. if (roomCurr.Equals("CNY"))
  27871. {
  27872. rateDatas.Add(new { code = "CNY", rate = 1.0000 });
  27873. singleRoomFeeStr = $"{item.SingleRoomPrice.ToString("#0.00")} {roomCurr}";
  27874. doubleRoomFeeStr = $"{item.DoubleRoomPrice.ToString("#0.00")} {roomCurr}";
  27875. suiteRoomFeeStr = $"{item.SuiteRoomPrice.ToString("#0.00")} {roomCurr}";
  27876. otherRoomFeeStr = $"{item.OtherRoomPrice.ToString("#0.00")} {roomCurr}";
  27877. payMoneyStr = $"{ccpInfo.PayMoney.ToString("#0.00")} {currDatas.Find(it => it.Id == ccpInfo?.PaymentCurrency)?.Name ?? ""}";
  27878. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} {currDatas.Find(it => it.Id == item.CardPriceCurrency)?.Name ?? ""}";
  27879. }
  27880. else
  27881. {
  27882. //singleRoomFeeStr = $"{((item.SingleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.SingleRoomPrice.ToString("#0.00")} {roomCurr}";
  27883. //doubleRoomFeeStr = $"{((item.DoubleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.DoubleRoomPrice.ToString("#0.00")} {roomCurr}";
  27884. //suiteRoomFeeStr = $"{((item.SuiteRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.SuiteRoomPrice.ToString("#0.00")} {roomCurr}";
  27885. //otherRoomFeeStr = $"{((item.OtherRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.OtherRoomPrice.ToString("#0.00")} {roomCurr}";
  27886. //payMoneyStr = $"{((ccpInfo.PayMoney * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{ccpInfo.PayMoney.ToString("#0.00")} {roomCurr}";
  27887. //cardPriceStr = $"{((item.CardPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.CardPrice.ToString("#0.00")} {roomCurr}";
  27888. singleRoomFeeStr = $"{item.SingleRoomPrice.ToString("#0.00")} {roomCurr}\r\n{((item.SingleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}";
  27889. doubleRoomFeeStr = $"{item.DoubleRoomPrice.ToString("#0.00")} {roomCurr}\r\n{((item.DoubleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}";
  27890. suiteRoomFeeStr = $"{item.SuiteRoomPrice.ToString("#0.00")} {roomCurr}\r\n{((item.SuiteRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}";
  27891. otherRoomFeeStr = $"{item.OtherRoomPrice.ToString("#0.00")} {roomCurr}\r\n{((item.OtherRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}";
  27892. rateDatas.Add(new { code = roomCurr, rate = roomInfo.Rate });
  27893. var ccpPaymentCurrency = currDatas.Find(it => it.Id == ccpInfo?.PaymentCurrency)?.Name ?? "";
  27894. if (ccpPaymentCurrency.Equals("CNY"))
  27895. {
  27896. payMoneyStr = $"{ccpInfo.PayMoney.ToString("#0.00")} CNY";
  27897. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} CNY";
  27898. }
  27899. else
  27900. {
  27901. rateDatas.Add(new { code = ccpPaymentCurrency, rate = ccpInfo.DayRate });
  27902. payMoneyStr = $"{ccpInfo.PayMoney.ToString("#0.00")} {ccpPaymentCurrency}\r\n{((ccpInfo.PayMoney * ccpInfo.DayRate) / _rate).ToString("#0.00")} CNY";
  27903. }
  27904. var hotelcardPriceCurrency = currDatas.Find(it => it.Id == item?.CardPriceCurrency)?.Name ?? "";
  27905. if (hotelcardPriceCurrency.Equals("CNY"))
  27906. {
  27907. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} CNY";
  27908. }
  27909. else
  27910. {
  27911. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} {hotelcardPriceCurrency}\r\n{((item.CardPrice * roomInfo.Rate) / _rate).ToString("#0.00")} CNY";
  27912. }
  27913. }
  27914. string breakfastPriceStr = string.Empty,
  27915. breakfastCurrency = currDatas.Find(it => it.Id == item.BreakfastCurrency)?.Name ?? "",
  27916. governmentRentStr = string.Empty,
  27917. governmentRentCurrency = currDatas.Find(it => it.Id == item.GovernmentRentCurrency)?.Name ?? "",
  27918. cityTaxStr = string.Empty,
  27919. cityTaxStrCurrency = currDatas.Find(it => it.Id == item.CityTaxCurrency)?.Name ?? "";
  27920. var breakfastCurrency1 = currDatas.Find(it => it.Id == breakfastInfo?.Currency)?.Name;
  27921. if (!string.IsNullOrEmpty(breakfastCurrency1))
  27922. {
  27923. if (breakfastCurrency1.Equals("CNY"))
  27924. {
  27925. breakfastPriceStr = $"{breakfastInfo?.Price.ToString("#0.00")} {breakfastCurrency1}";
  27926. }
  27927. else
  27928. {
  27929. rateDatas.Add(new { code = breakfastCurrency1, rate = breakfastInfo.Rate });
  27930. var breakfastPriceCny = breakfastInfo.Price * breakfastInfo.Rate;
  27931. breakfastPriceStr = $"{breakfastInfo?.Price.ToString("#0.00")} {breakfastCurrency1}\r\n{breakfastPriceCny.ToString("#0.00")} CNY";
  27932. }
  27933. }
  27934. else breakfastPriceStr = $"{breakfastInfo?.Price.ToString("#0.00")} {breakfastCurrency1}";
  27935. var governmentRentCurrency1 = currDatas.Find(it => it.Id == governmentRentInfo?.Currency)?.Name;
  27936. if (!string.IsNullOrEmpty(governmentRentCurrency1))
  27937. {
  27938. if (governmentRentCurrency.Equals("CNY"))
  27939. {
  27940. governmentRentStr = $"{governmentRentInfo?.Price.ToString("#0.00")} {governmentRentCurrency1}";
  27941. }
  27942. else
  27943. {
  27944. rateDatas.Add(new { code = governmentRentCurrency1, rate = governmentRentInfo.Rate });
  27945. var governmentRentCny = governmentRentInfo.Price * governmentRentInfo.Rate;
  27946. governmentRentStr = $"{governmentRentInfo?.Price.ToString("#0.00")} {governmentRentCurrency1}\r\n{governmentRentCny.ToString("#0.00")} CNY";
  27947. }
  27948. }
  27949. else governmentRentStr = $"{governmentRentInfo?.Price.ToString("#0.00")} {governmentRentCurrency1}";
  27950. var cityTaxStrCurrency1 = currDatas.Find(it => it.Id == cityTaxInfo?.Currency)?.Name;
  27951. if (!string.IsNullOrEmpty(cityTaxStrCurrency1))
  27952. {
  27953. if (cityTaxStrCurrency1.Equals("CNY"))
  27954. {
  27955. cityTaxStr = $"{cityTaxInfo?.Price.ToString("#0.00")} {cityTaxStrCurrency1}";
  27956. }
  27957. else
  27958. {
  27959. rateDatas.Add(new { code = cityTaxStrCurrency1, rate = cityTaxInfo.Rate });
  27960. var cityTaxCny = cityTaxInfo.Price * cityTaxInfo.Rate;
  27961. cityTaxStr = $"{cityTaxInfo?.Price.ToString("#0.00")} {cityTaxStrCurrency1}\r\n{cityTaxCny.ToString("#0.00")} CNY";
  27962. }
  27963. }
  27964. else cityTaxStr = $"{cityTaxInfo?.Price.ToString("#0.00")} {cityTaxStrCurrency1}";
  27965. int payDId = roomInfo?.PayDId ?? 0;
  27966. pcfds.Add(new HotelReservations_PCFD_View()
  27967. {
  27968. City = item.City,
  27969. HotelName = item.HotelName,
  27970. Date = $"{item.CheckInDate} - {item.CheckOutDate}",
  27971. // SingleRoomCount = item.SingleRoomCount,
  27972. SingleRoomPrice = singleRoomFeeStr,
  27973. // DoubleRoomCount = item.DoubleRoomCount,
  27974. DoubleRoomPrice = doubleRoomFeeStr,
  27975. //SuiteRoomCount = item.SuiteRoomCount,
  27976. SuiteRoomPrice = suiteRoomFeeStr,
  27977. OtherRoomPrice = otherRoomFeeStr,
  27978. //OtherRoomCount = item.OtherRoomCount,
  27979. BreakfastPrice = breakfastPriceStr,
  27980. GovernmentRent = governmentRentStr,
  27981. CityTax = cityTaxStr,
  27982. RoomExplanation = item.RoomExplanation,
  27983. PayTypeName = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == payDId).First()?.Name ?? "",
  27984. PayTime = roomInfo?.ConsumptionDate,
  27985. BankNo = roomInfo?.BankNo,
  27986. PayMoney = payMoneyStr,
  27987. //PayMoneys = ccpInfo.PayMoney.ToString("#0.00"),
  27988. ConsumptionPatterns = roomInfo?.ConsumptionPatterns,
  27989. CardPrice = cardPriceStr,
  27990. Remark = ccpInfo.Remark
  27991. });
  27992. }
  27993. #endregion
  27994. //载入模板
  27995. WorkbookDesigner designer = new WorkbookDesigner();
  27996. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/酒店预订成本.xls");
  27997. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == _dto.DiId).First();
  27998. var userInfo = _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == hrDtas[0].CreateUserId).First();
  27999. designer.SetDataSource("TourNo", groupInfo.TourCode);
  28000. var rateDatas1 = rateDatas.Distinct();
  28001. var rateStr = string.Empty;
  28002. foreach (var item in rateDatas1)
  28003. {
  28004. rateStr += $"{item.code} {item.rate.ToString("#0.0000")} \t\t";
  28005. }
  28006. designer.SetDataSource("TeamName", $"酒店模块汇率:{rateStr}");
  28007. designer.SetDataSource("Opertor", userInfo.CnName);
  28008. DataTable dt = CommonFun.GetDataTableFromIList<HotelReservations_PCFD_View>(pcfds);
  28009. dt.TableName = "ViewMyHotelReservations";
  28010. designer.SetDataSource(dt);
  28011. designer.Process();
  28012. string fileName = $"HotelReservation/{groupInfo.TeamName.Replace("/", "").Replace(@"\", "").Trim()}_酒店预订成本_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  28013. string serverPath = AppSettingsHelper.Get("ExcelBasePath") + fileName;
  28014. designer.Workbook.Save(serverPath);
  28015. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  28016. #region 删除指定行
  28017. bool singleDel = true, doubleDel = true, suiteDel = true, otherDel = true, zcDel = true, dsDel = true, cssDel = true, cpDel = true, remarkDel = true;
  28018. int singleIndex = dt.Columns["SingleRoomPrice"].Ordinal,
  28019. doubleIndex = dt.Columns["DoubleRoomPrice"].Ordinal,
  28020. suiteIndex = dt.Columns["SuiteRoomPrice"].Ordinal,
  28021. otherIndex = dt.Columns["OtherRoomPrice"].Ordinal,
  28022. zcIndex = dt.Columns["BreakfastPrice"].Ordinal,
  28023. dsIndex = dt.Columns["GovernmentRent"].Ordinal,
  28024. cssIndex = dt.Columns["CityTax"].Ordinal,
  28025. cpIndex = dt.Columns["ConsumptionPatterns"].Ordinal,
  28026. remarkIndex = dt.Columns["Remark"].Ordinal;
  28027. //删除指定列
  28028. foreach (DataRow item in dt.Rows)
  28029. {
  28030. string singleStr = item["SingleRoomPrice"].ToString();
  28031. bool containsDigitButNotZero1 = !singleStr.StartsWith("0") && Regex.IsMatch(singleStr, @"[1-9]");
  28032. if (containsDigitButNotZero1) singleDel = false;
  28033. singleIndex = dt.Columns["SingleRoomPrice"].Ordinal;
  28034. string doubleStr = item["DoubleRoomPrice"].ToString();
  28035. bool containsDigitButNotZero2 = !doubleStr.StartsWith("0") && Regex.IsMatch(doubleStr, @"[1-9]");
  28036. if (containsDigitButNotZero2) doubleDel = false;
  28037. string suiteStr = item["SuiteRoomPrice"].ToString();
  28038. bool containsDigitButNotZero3 = !singleStr.StartsWith("0") && Regex.IsMatch(doubleStr, @"[1-9]");
  28039. if (containsDigitButNotZero3) suiteDel = false;
  28040. string otherStr = item["OtherRoomPrice"].ToString();
  28041. bool containsDigitButNotZero4 = !otherStr.StartsWith("0") && Regex.IsMatch(otherStr, @"[1-9]");
  28042. if (containsDigitButNotZero4) otherDel = false;
  28043. string zcStr = item["BreakfastPrice"].ToString();
  28044. bool containsDigitButNotZero5 = !zcStr.StartsWith("0") && Regex.IsMatch(zcStr, @"[1-9]");
  28045. if (containsDigitButNotZero5) zcDel = false;
  28046. string dsStr = item["GovernmentRent"].ToString();
  28047. bool containsDigitButNotZero6 = !dsStr.StartsWith("0") && Regex.IsMatch(dsStr, @"[1-9]");
  28048. if (containsDigitButNotZero6) dsDel = false;
  28049. string cssStr = item["CityTax"].ToString();
  28050. bool containsDigitButNotZero7 = !cssStr.StartsWith("0") && Regex.IsMatch(cssStr, @"[1-9]");
  28051. if (containsDigitButNotZero7) cssDel = false;
  28052. string cpStr = item["ConsumptionPatterns"].ToString();
  28053. if (!string.IsNullOrEmpty(cpStr)) cpDel = false;
  28054. string remarkStr = item["Remark"].ToString();
  28055. if (!string.IsNullOrEmpty(remarkStr)) remarkDel = false;
  28056. }
  28057. DeleteColumn(serverPath, remarkIndex, remarkDel);
  28058. DeleteColumn(serverPath, cpIndex, cpDel);
  28059. DeleteColumn(serverPath, dsIndex, dsDel);
  28060. DeleteColumn(serverPath, cssIndex, cssDel);
  28061. DeleteColumn(serverPath, zcIndex, zcDel);
  28062. DeleteColumn(serverPath, otherIndex, otherDel);
  28063. DeleteColumn(serverPath, suiteIndex, suiteDel);
  28064. DeleteColumn(serverPath, doubleIndex, doubleDel);
  28065. DeleteColumn(serverPath, singleIndex, singleDel);
  28066. #endregion
  28067. //只保留第一个表格
  28068. DeleteSheet(serverPath);
  28069. return Ok(JsonView(true, "操作成功", url = rst));
  28070. }
  28071. else
  28072. {
  28073. _currency = _GroupCostParameter.Currency;
  28074. bool isIntType = int.TryParse(_currency, out int currId);
  28075. if (isIntType)
  28076. {
  28077. _currency = currDatas.Find(it => it.Id == currId)?.Name ?? "";
  28078. }
  28079. var teamRate = await _teamRateRep.PostGroupTeamRateItemByDiIdAndCTableId(1, _dto.DiId, 76);
  28080. var currInfo = teamRate.Find(it => it.CurrencyCode.Equals(_currency));
  28081. if (currInfo == null)
  28082. {
  28083. return Ok(JsonView(StatusCodes.Status400BadRequest, $"团组汇率-->酒店模块 {_currency} 币种未设置汇率,不支持预定成本Excel导出", ""));
  28084. }
  28085. if (!_currency.ToUpper().Equals("CNY"))
  28086. {
  28087. _rate = _GroupCostParameter.Rate;
  28088. }
  28089. _rate = currInfo.Rate;
  28090. hrDtas = hrDtas.OrderBy(it => it.CheckInDate).ToList();
  28091. //string strFileName = "HotelStatement/";
  28092. //string guestNames = ""; //格式Mr.xxx Ms.xxx
  28093. List<HotelReservations_PCFD_View> pcfds = new List<HotelReservations_PCFD_View>();
  28094. #region 数据处理
  28095. foreach (var item in hrDtas)
  28096. {
  28097. var ccpInfo = ccpData.Where(it => it.DIId == _dto.DiId && it.CId == item.Id).First();
  28098. var roomInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 1).FirstOrDefault(); //房费
  28099. var breakfastInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 2).FirstOrDefault(); //早餐
  28100. var governmentRentInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 3).FirstOrDefault(); //地税
  28101. var cityTaxInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 4).FirstOrDefault(); //城市税
  28102. string roomCurr = currDatas.Find(it => it.Id == roomInfo?.Currency)?.Name ?? "";
  28103. string singleRoomFeeStr = string.Empty,
  28104. doubleRoomFeeStr = string.Empty,
  28105. suiteRoomFeeStr = string.Empty,
  28106. otherRoomFeeStr = string.Empty,
  28107. payMoneyStr = string.Empty,
  28108. cardPriceStr = string.Empty;
  28109. if (roomCurr.Equals(_currency))
  28110. {
  28111. singleRoomFeeStr = $"{item.SingleRoomPrice.ToString("#0.00")} {_currency}";
  28112. doubleRoomFeeStr = $"{item.DoubleRoomPrice.ToString("#0.00")} {_currency}";
  28113. suiteRoomFeeStr = $"{item.SuiteRoomPrice.ToString("#0.00")} {_currency}";
  28114. otherRoomFeeStr = $"{item.OtherRoomPrice.ToString("#0.00")} {_currency}";
  28115. payMoneyStr = $"{ccpInfo.PayMoney.ToString("#0.00")} {_currency}";
  28116. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} {_currency}";
  28117. }
  28118. else
  28119. {
  28120. singleRoomFeeStr = $"{((item.SingleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.SingleRoomPrice.ToString("#0.00")} {roomCurr}";
  28121. doubleRoomFeeStr = $"{((item.DoubleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.DoubleRoomPrice.ToString("#0.00")} {roomCurr}";
  28122. suiteRoomFeeStr = $"{((item.SuiteRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.SuiteRoomPrice.ToString("#0.00")} {roomCurr}";
  28123. otherRoomFeeStr = $"{((item.OtherRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.OtherRoomPrice.ToString("#0.00")} {roomCurr}";
  28124. payMoneyStr = $"{((ccpInfo.PayMoney * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{ccpInfo.PayMoney.ToString("#0.00")} {roomCurr}";
  28125. cardPriceStr = $"{((item.CardPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.CardPrice.ToString("#0.00")} {roomCurr}";
  28126. }
  28127. string breakfastPriceStr = string.Empty,
  28128. breakfastCurrency = currDatas.Find(it => it.Id == item.BreakfastCurrency)?.Name ?? "",
  28129. governmentRentStr = string.Empty,
  28130. governmentRentCurrency = currDatas.Find(it => it.Id == item.GovernmentRentCurrency)?.Name ?? "",
  28131. cityTaxStrStr = string.Empty,
  28132. cityTaxStrCurrency = currDatas.Find(it => it.Id == item.CityTaxCurrency)?.Name ?? "";
  28133. breakfastPriceStr = $"{breakfastInfo?.Price.ToString("#0.00")} {currDatas.Find(it => it.Id == breakfastInfo?.Currency)?.Name}";
  28134. governmentRentStr = $"{governmentRentInfo?.Price.ToString("#0.00")} {currDatas.Find(it => it.Id == governmentRentInfo?.Currency)?.Name}";
  28135. cityTaxStrStr = $"{cityTaxInfo?.Price.ToString("#0.00")} {currDatas.Find(it => it.Id == cityTaxInfo?.Currency)?.Name}";
  28136. int payDId = roomInfo?.PayDId ?? 0;
  28137. pcfds.Add(new HotelReservations_PCFD_View()
  28138. {
  28139. City = item.City,
  28140. HotelName = item.HotelName,
  28141. Date = $"{item.CheckInDate} - {item.CheckOutDate}",
  28142. // SingleRoomCount = item.SingleRoomCount,
  28143. SingleRoomPrice = singleRoomFeeStr,
  28144. // DoubleRoomCount = item.DoubleRoomCount,
  28145. DoubleRoomPrice = doubleRoomFeeStr,
  28146. //SuiteRoomCount = item.SuiteRoomCount,
  28147. SuiteRoomPrice = suiteRoomFeeStr,
  28148. OtherRoomPrice = otherRoomFeeStr,
  28149. //OtherRoomCount = item.OtherRoomCount,
  28150. BreakfastPrice = breakfastPriceStr,
  28151. GovernmentRent = governmentRentStr,
  28152. CityTax = cityTaxStrStr,
  28153. RoomExplanation = item.RoomExplanation,
  28154. PayTypeName = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == payDId).First()?.Name ?? "",
  28155. PayTime = roomInfo?.ConsumptionDate,
  28156. BankNo = roomInfo?.BankNo,
  28157. PayMoney = payMoneyStr,
  28158. //PayMoneys = ccpInfo.PayMoney.ToString("#0.00"),
  28159. ConsumptionPatterns = roomInfo?.ConsumptionPatterns,
  28160. CardPrice = cardPriceStr,
  28161. Remark = ccpInfo.Remark
  28162. });
  28163. }
  28164. #endregion
  28165. //载入模板
  28166. WorkbookDesigner designer = new WorkbookDesigner();
  28167. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/酒店预订成本.xls");
  28168. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == _dto.DiId).First();
  28169. var userInfo = _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == hrDtas[0].CreateUserId).First();
  28170. designer.SetDataSource("TourNo", groupInfo.TourCode);
  28171. designer.SetDataSource("TeamName", $"{groupInfo.TeamName} 团组成本币种:{_currency} 团组汇率-->酒店模块汇率:{_rate.ToString("#0.0000")}");
  28172. designer.SetDataSource("Opertor", userInfo.CnName);
  28173. DataTable dt = CommonFun.GetDataTableFromIList<HotelReservations_PCFD_View>(pcfds);
  28174. dt.TableName = "ViewMyHotelReservations";
  28175. designer.SetDataSource(dt);
  28176. designer.Process();
  28177. string fileName = $"HotelReservation/{groupInfo.TeamName.Replace("/", "").Replace(@"\", "").Trim()}_酒店预订成本_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  28178. string serverPath = AppSettingsHelper.Get("ExcelBasePath") + fileName;
  28179. designer.Workbook.Save(serverPath);
  28180. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  28181. #region 删除指定行
  28182. bool singleDel = true, doubleDel = true, suiteDel = true, otherDel = true, zcDel = true, dsDel = true, cssDel = true, cpDel = true, remarkDel = true;
  28183. int singleIndex = dt.Columns["SingleRoomPrice"].Ordinal,
  28184. doubleIndex = dt.Columns["DoubleRoomPrice"].Ordinal,
  28185. suiteIndex = dt.Columns["SuiteRoomPrice"].Ordinal,
  28186. otherIndex = dt.Columns["OtherRoomPrice"].Ordinal,
  28187. zcIndex = dt.Columns["BreakfastPrice"].Ordinal,
  28188. dsIndex = dt.Columns["GovernmentRent"].Ordinal,
  28189. cssIndex = dt.Columns["CityTax"].Ordinal,
  28190. cpIndex = dt.Columns["ConsumptionPatterns"].Ordinal,
  28191. remarkIndex = dt.Columns["Remark"].Ordinal;
  28192. //删除指定列
  28193. foreach (DataRow item in dt.Rows)
  28194. {
  28195. string singleStr = item["SingleRoomPrice"].ToString();
  28196. bool containsDigitButNotZero1 = !singleStr.StartsWith("0") && Regex.IsMatch(singleStr, @"[1-9]");
  28197. if (containsDigitButNotZero1) singleDel = false;
  28198. singleIndex = dt.Columns["SingleRoomPrice"].Ordinal;
  28199. string doubleStr = item["DoubleRoomPrice"].ToString();
  28200. bool containsDigitButNotZero2 = !doubleStr.StartsWith("0") && Regex.IsMatch(doubleStr, @"[1-9]");
  28201. if (containsDigitButNotZero2) doubleDel = false;
  28202. string suiteStr = item["SuiteRoomPrice"].ToString();
  28203. bool containsDigitButNotZero3 = !singleStr.StartsWith("0") && Regex.IsMatch(doubleStr, @"[1-9]");
  28204. if (containsDigitButNotZero3) suiteDel = false;
  28205. string otherStr = item["OtherRoomPrice"].ToString();
  28206. bool containsDigitButNotZero4 = !otherStr.StartsWith("0") && Regex.IsMatch(otherStr, @"[1-9]");
  28207. if (containsDigitButNotZero4) otherDel = false;
  28208. string zcStr = item["BreakfastPrice"].ToString();
  28209. bool containsDigitButNotZero5 = !zcStr.StartsWith("0") && Regex.IsMatch(zcStr, @"[1-9]");
  28210. if (containsDigitButNotZero5) zcDel = false;
  28211. string dsStr = item["GovernmentRent"].ToString();
  28212. bool containsDigitButNotZero6 = !dsStr.StartsWith("0") && Regex.IsMatch(dsStr, @"[1-9]");
  28213. if (containsDigitButNotZero6) dsDel = false;
  28214. string cssStr = item["CityTax"].ToString();
  28215. bool containsDigitButNotZero7 = !cssStr.StartsWith("0") && Regex.IsMatch(cssStr, @"[1-9]");
  28216. if (containsDigitButNotZero7) cssDel = false;
  28217. string cpStr = item["ConsumptionPatterns"].ToString();
  28218. if (!string.IsNullOrEmpty(cpStr)) cpDel = false;
  28219. string remarkStr = item["Remark"].ToString();
  28220. if (!string.IsNullOrEmpty(remarkStr)) remarkDel = false;
  28221. }
  28222. DeleteColumn(serverPath, remarkIndex, remarkDel);
  28223. DeleteColumn(serverPath, cpIndex, cpDel);
  28224. DeleteColumn(serverPath, dsIndex, dsDel);
  28225. DeleteColumn(serverPath, cssIndex, cssDel);
  28226. DeleteColumn(serverPath, zcIndex, zcDel);
  28227. DeleteColumn(serverPath, otherIndex, otherDel);
  28228. DeleteColumn(serverPath, suiteIndex, suiteDel);
  28229. DeleteColumn(serverPath, doubleIndex, doubleDel);
  28230. DeleteColumn(serverPath, singleIndex, singleDel);
  28231. #endregion
  28232. //只保留第一个表格
  28233. DeleteSheet(serverPath);
  28234. return Ok(JsonView(true, "操作成功", url = rst));
  28235. }
  28236. //return Ok(JsonView(false));
  28237. }
  28238. /// <summary>
  28239. /// 删除指定列
  28240. /// </summary>
  28241. /// <param name="file"></param>
  28242. /// <param name="columnIndex"></param>
  28243. /// <param name="isDel"></param>
  28244. private void DeleteColumn(string file, int columnIndex, bool isDel)
  28245. {
  28246. Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(file);
  28247. //wb.Save(file);
  28248. Aspose.Cells.Worksheet sheet1 = wb.Worksheets[0];
  28249. if (sheet1 != null)
  28250. {
  28251. if (isDel)
  28252. {
  28253. Cells cells = sheet1.Cells;
  28254. cells.DeleteColumn(columnIndex);
  28255. }
  28256. }
  28257. wb.Save(file);
  28258. }
  28259. /// <summary>
  28260. /// 删除sheet
  28261. /// </summary>
  28262. /// <param name="file"></param>
  28263. private void DeleteSheet(string file)
  28264. {
  28265. Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(file);
  28266. //wb.Save(file);
  28267. List<string> sheets = new List<string>();
  28268. foreach (var item in wb.Worksheets)
  28269. {
  28270. sheets.Add(item.Name);
  28271. }
  28272. if (sheets.Count > 0)
  28273. {
  28274. sheets.RemoveAt(0);//不删除第一个sheet
  28275. foreach (var item in sheets)
  28276. {
  28277. wb.Worksheets.RemoveAt(item);
  28278. }
  28279. }
  28280. wb.Save(file);
  28281. }
  28282. /// <summary>
  28283. /// 酒店预订
  28284. /// 确认单
  28285. /// </summary>
  28286. /// <param name="_dto"></param>
  28287. /// <returns></returns>
  28288. [HttpPost]
  28289. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28290. public async Task<IActionResult> PostHotelReservationsConfirmationSlip(HotelReservationsConfirmationSlipDto _dto)
  28291. {
  28292. try
  28293. {
  28294. #region 参数验证
  28295. if (_dto.UserId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "员工Id为空", ""));
  28296. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  28297. if (_dto.DiId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组Id为空", ""));
  28298. #region 团组操作权限验证 76 酒店预定模块
  28299. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  28300. if (groupAuthView.Code != 0) return Ok(JsonView(StatusCodes.Status400BadRequest, groupAuthView.Msg, ""));
  28301. #endregion
  28302. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  28303. #region 页面操作权限验证
  28304. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  28305. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  28306. #endregion
  28307. #endregion
  28308. //团组信息
  28309. Grp_DelegationInfo di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(a => a.Id == _dto.DiId);
  28310. //酒店数据
  28311. List<Grp_HotelReservations> listhoteldata = await _sqlSugar.Queryable<Grp_HotelReservations>().Where(a => a.DiId == _dto.DiId && a.IsDel == 0).ToListAsync();
  28312. if (listhoteldata.Count < 0)
  28313. {
  28314. return Ok(JsonView(StatusCodes.Status400BadRequest, "当前团组暂无酒店预订信息!", ""));
  28315. }
  28316. //利datatable存储
  28317. DataTable dt = new DataTable();
  28318. dt.Columns.Add("CheckInDate", typeof(string));
  28319. dt.Columns.Add("City", typeof(string));
  28320. dt.Columns.Add("Hotel", typeof(string));
  28321. dt.Columns.Add("Room", typeof(string));
  28322. for (int i = 0; i < listhoteldata.Count; i++)
  28323. {
  28324. DateTime dayStart = Convert.ToDateTime(listhoteldata[i].CheckInDate);
  28325. DateTime dayEnd = Convert.ToDateTime(listhoteldata[i].CheckOutDate);
  28326. while (dayStart < dayEnd)
  28327. {
  28328. string temp = "";
  28329. DataRow row = dt.NewRow();
  28330. row["CheckInDate"] = dayStart.ToString("yyyy-MM-dd");
  28331. row["City"] = listhoteldata[i].City;
  28332. row["Hotel"] = listhoteldata[i].HotelName;
  28333. if (listhoteldata[i].SingleRoomCount > 0)
  28334. {
  28335. temp = listhoteldata[i].SingleRoomCount + "个单间" + "\r\n";
  28336. }
  28337. if (listhoteldata[i].DoubleRoomCount > 0)
  28338. {
  28339. temp = temp + listhoteldata[i].DoubleRoomCount + "个标间" + "\r\n";
  28340. }
  28341. if (listhoteldata[i].SuiteRoomCount > 0)
  28342. {
  28343. temp = temp + listhoteldata[i].SuiteRoomCount + "个套房" + "\r\n";
  28344. }
  28345. if (listhoteldata[i].OtherRoomCount > 0)
  28346. {
  28347. temp = temp + listhoteldata[i].OtherRoomCount + "个其他房型" + "\r\n";
  28348. }
  28349. row["Room"] = temp;
  28350. dt.Rows.Add(row);
  28351. dayStart = dayStart.AddDays(1);
  28352. }
  28353. }
  28354. Dictionary<string, string> dic = new Dictionary<string, string>();
  28355. dic.Add("Dele", di.TeamName);
  28356. dic.Add("City", di.VisitCountry);
  28357. //模板路径
  28358. string tempPath = AppSettingsHelper.Get("WordBasePath") + "Template/酒店用房确认单-模板.doc";
  28359. //载入模板
  28360. Aspose.Words.Document doc = new Aspose.Words.Document(tempPath);
  28361. DocumentBuilder builder = new DocumentBuilder(doc);
  28362. foreach (var key in dic.Keys)
  28363. {
  28364. builder.MoveToBookmark(key);
  28365. builder.Write(dic[key]);
  28366. }
  28367. //获取word里所有表格
  28368. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  28369. //获取所填表格的序数
  28370. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  28371. var rowStart = tableOne.Rows[0]; //获取第1行
  28372. //循环赋值
  28373. for (int i = 0; i < dt.Rows.Count; i++)
  28374. {
  28375. builder.MoveToCell(0, i + 1, 0, 0);
  28376. builder.Write(dt.Rows[i]["CheckInDate"].ToString());
  28377. builder.MoveToCell(0, i + 1, 1, 0);
  28378. builder.Write(dt.Rows[i]["City"].ToString());
  28379. builder.MoveToCell(0, i + 1, 2, 0);
  28380. builder.Write(dt.Rows[i]["Hotel"].ToString());
  28381. builder.MoveToCell(0, i + 1, 3, 0);
  28382. builder.Write(dt.Rows[i]["Room"].ToString());
  28383. }
  28384. //删除多余行
  28385. while (tableOne.Rows.Count > dt.Rows.Count + 1)
  28386. {
  28387. tableOne.Rows.RemoveAt(dt.Rows.Count + 1);
  28388. }
  28389. string strFileName = di.TeamName + "酒店确认单.doc";
  28390. doc.Save(AppSettingsHelper.Get("WordBasePath") + "HotelStatement/" + strFileName);
  28391. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/HotelStatement/" + strFileName;
  28392. return Ok(JsonView(true, "成功", url));
  28393. }
  28394. catch (Exception ex)
  28395. {
  28396. return Ok(JsonView(StatusCodes.Status400BadRequest, ex.Message, ""));
  28397. }
  28398. }
  28399. #endregion
  28400. #region 团组状态
  28401. /// <summary>
  28402. /// 团组状态列表 Page
  28403. /// </summary>
  28404. /// <param name="dto">团组列表请求dto</param>
  28405. /// <returns></returns>
  28406. [HttpPost]
  28407. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28408. public async Task<IActionResult> PostGroupStatusPageList(GroupStatusListDto dto)
  28409. {
  28410. if (dto == null) return Ok(JsonView(false, "请输入搜索条件!"));
  28411. if (dto.PortType == 1 || dto.PortType == 2) // web/Android
  28412. {
  28413. string sqlWhere = string.Empty;
  28414. if (dto.IsSure == 0) //未完成
  28415. {
  28416. sqlWhere += string.Format(@" And IsSure = 0");
  28417. }
  28418. else if (dto.IsSure == 1) //已完成
  28419. {
  28420. sqlWhere += string.Format(@" And IsSure = 1");
  28421. }
  28422. if (!string.IsNullOrEmpty(dto.SearchCriteria))
  28423. {
  28424. string tj = dto.SearchCriteria;
  28425. 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}%')",
  28426. tj, tj, tj, tj, tj);
  28427. }
  28428. string sql = string.Format(@"Select Row_Number,Id,SalesQuoteNo,TourCode,TeamTypeId, TeamType,
  28429. TeamLevId,TeamLev,TeamName,ClientName,ClientUnit,
  28430. VisitDate,VisitDays,VisitPNumber,JietuanOperator,IsSure,CreateTime
  28431. From (
  28432. Select row_number() over(order by gdi.VisitStartDate Desc) as Row_Number,
  28433. gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,
  28434. ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,
  28435. VisitDate,VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure,gdi.CreateTime
  28436. From Grp_DelegationInfo gdi
  28437. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  28438. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  28439. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  28440. Where gdi.IsDel = 0 {0}
  28441. ) temp ", sqlWhere);
  28442. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  28443. var _DelegationList = await _sqlSugar.SqlQueryable<GroupStatusView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);//ToPageAsync
  28444. return Ok(JsonView(true, "查询成功!", _DelegationList, total));
  28445. }
  28446. else
  28447. {
  28448. return Ok(JsonView(false, "查询失败"));
  28449. }
  28450. }
  28451. /// <summary>
  28452. /// 团组状态
  28453. /// 设置操作完成
  28454. /// </summary>
  28455. /// <param name="dto">团组列表请求dto</param>
  28456. /// <returns></returns>
  28457. [HttpPost]
  28458. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28459. public async Task<IActionResult> PostGroupStatusSetOperationComplete(GroupStatusSetOperationCompleteDto dto)
  28460. {
  28461. if (dto == null) return Ok(JsonView(false, "请输入搜索条件!"));
  28462. Grp_DelegationInfo _DelegationInfo = new Grp_DelegationInfo()
  28463. {
  28464. Id = dto.Id,
  28465. IsSure = 1
  28466. };
  28467. var result = await _sqlSugar.Updateable(_DelegationInfo)
  28468. .UpdateColumns(it => new { it.IsSure })
  28469. .WhereColumns(it => new { it.Id })
  28470. .ExecuteCommandAsync();
  28471. if (result > 0)
  28472. {
  28473. return Ok(JsonView(true, "操作完成!"));
  28474. }
  28475. return Ok(JsonView(false, "操作失败!"));
  28476. }
  28477. #endregion
  28478. #region 保险费用录入
  28479. /// <summary>
  28480. /// 根据团组Id查询保险费用列表
  28481. /// </summary>
  28482. /// <param name="dto"></param>
  28483. /// <returns></returns>
  28484. [HttpPost]
  28485. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28486. public async Task<IActionResult> CustomersByDiId(CustomersByDiIdDto dto)
  28487. {
  28488. Result groupData = await _customersRep.CustomersByDiId(dto);
  28489. if (groupData.Code != 0)
  28490. {
  28491. return Ok(JsonView(false, groupData.Msg));
  28492. }
  28493. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  28494. }
  28495. /// <summary>
  28496. /// 根据保险费用Id查询保险费用详细
  28497. /// </summary>
  28498. /// <param name="dto"></param>
  28499. /// <returns></returns>
  28500. [HttpPost]
  28501. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28502. public async Task<IActionResult> CustomersById(CustomersByIdDto dto)
  28503. {
  28504. try
  28505. {
  28506. Result groupData = await _customersRep.CustomersById(dto);
  28507. if (groupData.Code != 0)
  28508. {
  28509. return Ok(JsonView(false, groupData.Msg));
  28510. }
  28511. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  28512. }
  28513. catch (Exception ex)
  28514. {
  28515. return Ok(JsonView(false, ex.Message));
  28516. }
  28517. }
  28518. /// <summary>
  28519. /// 保险费用录入页面初始化绑定
  28520. /// </summary>
  28521. /// <param name="dto"></param>
  28522. /// <returns></returns>
  28523. [HttpPost]
  28524. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28525. public async Task<IActionResult> CustomersInitialize(CustomersInitializeDto dto)
  28526. {
  28527. try
  28528. {
  28529. Result groupData = await _customersRep.CustomersInitialize(dto);
  28530. if (groupData.Code != 0)
  28531. {
  28532. return Ok(JsonView(false, groupData.Msg));
  28533. }
  28534. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  28535. }
  28536. catch (Exception ex)
  28537. {
  28538. return Ok(JsonView(false, ex.Message));
  28539. }
  28540. }
  28541. /// <summary>
  28542. /// 保险费用操作(Status:1.新增,2.修改)
  28543. /// </summary>
  28544. /// <param name="dto"></param>
  28545. /// <returns></returns>
  28546. [HttpPost]
  28547. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28548. public async Task<IActionResult> OpCustomers(OpCustomersDto dto)
  28549. {
  28550. //验证
  28551. if (dto.Status == 2)
  28552. {
  28553. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 82);
  28554. if (!valid) return Ok(JsonView(false, msg));
  28555. }
  28556. Result groupData = await _customersRep.OpCustomers(dto);
  28557. if (groupData.Code != 0)
  28558. {
  28559. return Ok(JsonView(false, groupData.Msg));
  28560. }
  28561. #region 应用推送
  28562. try
  28563. {
  28564. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  28565. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  28566. int dataId = groupData.Data.GetType().GetProperty("dataId").GetValue(groupData.Data, null);
  28567. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  28568. //自动审核
  28569. await _feeAuditRep.FeeAutomaticAudit(4, dto.DiId, dataId);
  28570. //2024-10-21 新增LZ UID
  28571. var userIds = new List<int>() { 21 };
  28572. string title = $"系统通知";
  28573. var diId = dto.DiId;
  28574. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  28575. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  28576. string content = "";
  28577. if (dto.Status == 1) content = $"[新增-保险费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  28578. else if (dto.Status == 2) content = $"[更新-保险费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  28579. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  28580. PageParam_PriceAuditH5 h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "82" };
  28581. await APNsTools.iOS_PushNotifications1("051", "保险费用审核", "", content, true, "ExpenseAuditWebView", h5);
  28582. }
  28583. catch (Exception ex)
  28584. {
  28585. }
  28586. #endregion
  28587. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  28588. }
  28589. /// <summary>
  28590. /// 保险文件上传
  28591. /// </summary>
  28592. /// <param name="file"></param>
  28593. /// <returns></returns>
  28594. [HttpPost]
  28595. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28596. public async Task<IActionResult> UploadCus(IFormFile file)
  28597. {
  28598. try
  28599. {
  28600. if (file != null)
  28601. {
  28602. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  28603. //文件名称
  28604. string projectFileName = file.FileName;
  28605. //上传的文件的路径
  28606. string filePath = "";
  28607. if (!Directory.Exists(fileDir))
  28608. {
  28609. Directory.CreateDirectory(fileDir);
  28610. }
  28611. //上传的文件的路径
  28612. filePath = fileDir + $@"\保险费用文件上传\{projectFileName}";
  28613. using (FileStream fs = System.IO.File.Create(filePath))
  28614. {
  28615. file.CopyTo(fs);
  28616. fs.Flush();
  28617. }
  28618. return Ok(JsonView(true, "上传成功!", projectFileName));
  28619. }
  28620. else
  28621. {
  28622. return Ok(JsonView(false, "上传失败!"));
  28623. }
  28624. }
  28625. catch (Exception ex)
  28626. {
  28627. return Ok(JsonView(false, ex.Message));
  28628. }
  28629. }
  28630. /// <summary>
  28631. /// 保险删除指定文件
  28632. /// </summary>
  28633. /// <param name="dto"></param>
  28634. /// <returns></returns>
  28635. [HttpPost]
  28636. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28637. public async Task<IActionResult> DelFileCus(DelFileDto dto)
  28638. {
  28639. try
  28640. {
  28641. string filePath = "";
  28642. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  28643. // 返回与指定虚拟路径相对应的物理路径即绝对路径
  28644. //int id = 0;
  28645. filePath = fileDir + "/保险费用文件上传/" + dto.fileName;
  28646. // 删除该文件
  28647. try
  28648. {
  28649. System.IO.File.Delete(filePath);
  28650. 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()
  28651. {
  28652. Attachment = "",
  28653. }).ExecuteCommandAsync();
  28654. if (result != 0)
  28655. {
  28656. return Ok(JsonView(true, "成功!"));
  28657. }
  28658. else
  28659. {
  28660. return Ok(JsonView(false, "失败!"));
  28661. }
  28662. }
  28663. catch (Exception)
  28664. {
  28665. 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()
  28666. {
  28667. Attachment = "",
  28668. }).ExecuteCommandAsync();
  28669. if (result != 0)
  28670. {
  28671. return Ok(JsonView(true, "成功!"));
  28672. }
  28673. else
  28674. {
  28675. return Ok(JsonView(false, "失败!"));
  28676. }
  28677. }
  28678. }
  28679. catch (Exception ex)
  28680. {
  28681. return Ok(JsonView(false, "程序错误!"));
  28682. throw;
  28683. }
  28684. }
  28685. /// <summary>
  28686. /// 保险费用操作(删除)
  28687. /// </summary>
  28688. /// <param name="dto"></param>
  28689. /// <returns></returns>
  28690. [HttpPost]
  28691. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28692. public async Task<IActionResult> DelCustomers(DelBaseDto dto)
  28693. {
  28694. try
  28695. {
  28696. //验证
  28697. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 82);
  28698. if (!valid) return Ok(JsonView(false, msg));
  28699. var res = await _customersRep.SoftDeleteByIdAsync<Grp_Customers>(dto.Id.ToString(), dto.DeleteUserId);
  28700. if (!res)
  28701. {
  28702. return Ok(JsonView(false, "删除失败"));
  28703. }
  28704. var resultC = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 82).SetColumns(a => new Grp_CreditCardPayment()
  28705. {
  28706. IsDel = 1,
  28707. DeleteUserId = dto.DeleteUserId,
  28708. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  28709. }).ExecuteCommandAsync();
  28710. return Ok(JsonView(true, "删除成功!"));
  28711. }
  28712. catch (Exception ex)
  28713. {
  28714. return Ok(JsonView(false, "程序错误!"));
  28715. }
  28716. }
  28717. #endregion
  28718. #region 接团客户名单 PageId 104
  28719. /// <summary>
  28720. /// 接团客户名单
  28721. /// 迁移数据(慎用!)
  28722. /// </summary>
  28723. /// <returns></returns>
  28724. [HttpPost]
  28725. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28726. public async Task<IActionResult> PostTourClientListChange()
  28727. {
  28728. try
  28729. {
  28730. _sqlSugar.ChangeDatabase(DBEnum.OA2014DB);
  28731. //var groupClinetData1
  28732. string sql = string.Format($"Select * From DeleClient Where Isdel = 0");
  28733. var oldOAClientList = await _sqlSugar.SqlQueryable<OA2021_DeleClient>(sql).Where(it => it.Isdel == 0).ToListAsync();
  28734. int updateCount = 0;
  28735. if (oldOAClientList.Count > 0)
  28736. {
  28737. _sqlSugar.ChangeDatabase(DBEnum.OA2023DB);
  28738. _sqlSugar.BeginTran();
  28739. var clientComInfos = _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToList();
  28740. var clientInfos = _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToList();
  28741. foreach (var item in oldOAClientList)
  28742. {
  28743. int comId = 0;
  28744. string format = "yyyy-MM-dd HH:mm:ss";
  28745. string data11 = "1990-01-01 00:00";
  28746. var data1 = IsValidDate(item.OPdate, format);
  28747. if (data1) data11 = item.OPdate;
  28748. //客户公司验证
  28749. if (!string.IsNullOrEmpty(item.Company))
  28750. {
  28751. var clientComInfo = clientComInfos.Where(it => it.CompanyFullName.Equals(item.Company)).FirstOrDefault();
  28752. if (clientComInfo == null) // add
  28753. {
  28754. var addInfo = new Crm_CustomerCompany()
  28755. {
  28756. CompanyAbbreviation = "",
  28757. CompanyFullName = item.Company,
  28758. Address = "",
  28759. PostCodes = "",
  28760. LastedOpUserId = item.OPer,
  28761. LastedOpDt = Convert.ToDateTime(data11),
  28762. CreateUserId = item.OPer,
  28763. CreateTime = Convert.ToDateTime(data11),
  28764. IsDel = 0
  28765. };
  28766. var comId1 = _sqlSugar.Insertable<Crm_CustomerCompany>(addInfo).ExecuteReturnIdentity();
  28767. if (comId1 > 0) comId = comId1;
  28768. }
  28769. else comId = clientComInfo.Id;
  28770. }
  28771. //客户人员验证
  28772. int clientId = 0;
  28773. string name = item.LastName + item.Name;
  28774. if (!string.IsNullOrEmpty(name))
  28775. {
  28776. var clientInfo = clientInfos.Where(it => (it.LastName + it.FirstName).Equals(name)).FirstOrDefault();
  28777. if (clientInfo == null)
  28778. {
  28779. DateTime? dateTime = null;
  28780. var isDt = DateTime.TryParse(item.Birthday, out DateTime birthDayDt);
  28781. if (isDt) dateTime = birthDayDt;
  28782. var addInfo1 = new Crm_DeleClient()
  28783. {
  28784. CrmCompanyId = comId,
  28785. DiId = -1,
  28786. LastName = item.LastName,
  28787. FirstName = item.Name,
  28788. OldName = "",
  28789. Pinyin = item.Pinyin,
  28790. Sex = item.Sex == "男" ? 0 : item.Sex == "女" ? 1 : -1,
  28791. Marriage = 0,
  28792. Phone = item.Phone,
  28793. Job = item.Job,
  28794. BirthDay = dateTime
  28795. };
  28796. var clientId1 = _sqlSugar.Insertable<Crm_DeleClient>(addInfo1).ExecuteReturnIdentity();
  28797. if (clientId1 > 0) clientId = clientId1;
  28798. }
  28799. else clientId = clientInfo.Id;
  28800. }
  28801. if (clientId < 1)
  28802. {
  28803. continue;
  28804. }
  28805. int airType = 0;
  28806. if (item.AirType == "超经舱") airType = 459;
  28807. else if (item.AirType == "公务舱") airType = 458;
  28808. else if (item.AirType == "经济舱") airType = 460;
  28809. else if (item.AirType == "其他") airType = 565;
  28810. else if (item.AirType == "头等舱") airType = 457;
  28811. var _TourClientListEntity = new Grp_TourClientList()
  28812. {
  28813. DiId = item.Diid,
  28814. ClientId = clientId,
  28815. CreateUserId = item.OPer,
  28816. CreateTime = Convert.ToDateTime(data11),
  28817. Remark = item.Remark,
  28818. IsDel = item.Isdel,
  28819. ShippingSpaceTypeId = airType,
  28820. ShippingSpaceSpecialNeeds = item.AirRemark,
  28821. HotelSpecialNeeds = item.RoomType
  28822. };
  28823. var _TourClientList = _sqlSugar.Insertable<Grp_TourClientList>(_TourClientListEntity).ExecuteCommand();
  28824. if (_TourClientList > 0)
  28825. {
  28826. updateCount++;
  28827. }
  28828. }
  28829. _sqlSugar.CommitTran();
  28830. }
  28831. return Ok(JsonView(true, $"更新条数:{updateCount}条"));
  28832. }
  28833. catch (Exception ex)
  28834. {
  28835. _sqlSugar.RollbackTran();
  28836. return Ok(JsonView(false, ex.Message));
  28837. }
  28838. //return Ok(JsonView(true));
  28839. }
  28840. private bool IsValidDate(string dateString, string format)
  28841. {
  28842. return DateTime.TryParseExact(dateString, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateValue);
  28843. }
  28844. /// <summary>
  28845. /// 接团客户名单
  28846. /// 根据团组Id查询List
  28847. /// </summary>
  28848. /// <param name="_dto"></param>
  28849. /// <returns></returns>
  28850. [HttpPost]
  28851. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28852. public async Task<IActionResult> PostTourClientListByDiId(TourClientListByDiIdDto _dto)
  28853. {
  28854. #region 参数验证
  28855. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId"));
  28856. if (_dto.PageId != 104) _dto.PageId = 104; //接团客户名单PageId
  28857. if (_dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId!"));
  28858. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  28859. #region 页面操作权限验证
  28860. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  28861. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  28862. #endregion
  28863. #endregion
  28864. var viewData = await _tourClientListRep._ItemByDiId(_dto.PortType, _dto.DiId);
  28865. if (viewData.Code != 0)
  28866. {
  28867. return Ok(JsonView(false, viewData.Msg));
  28868. }
  28869. return Ok(JsonView(viewData.Data));
  28870. }
  28871. /// <summary>
  28872. /// 接团客户名单
  28873. /// 基础数据 Init
  28874. /// </summary>
  28875. /// <param name="_dto"></param>
  28876. /// <returns></returns>
  28877. [HttpPost]
  28878. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28879. public async Task<IActionResult> PostTourClientListBasicDataInit(TourClientListBasicDataInitDto _dto)
  28880. {
  28881. #region 参数验证
  28882. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  28883. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  28884. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  28885. #region 页面操作权限验证
  28886. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  28887. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  28888. #endregion
  28889. #endregion
  28890. return Ok(await _tourClientListRep._BasicDataInit(_dto.PortType));
  28891. }
  28892. /// <summary>
  28893. /// 接团客户名单
  28894. /// 根据 Id查询 Details
  28895. /// </summary>
  28896. /// <param name="_dto"></param>
  28897. /// <returns></returns>
  28898. [HttpPost]
  28899. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28900. public async Task<IActionResult> PostTourClientListDetails(TourClientListDetailsDto _dto)
  28901. {
  28902. #region 参数验证
  28903. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  28904. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  28905. if (_dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数!"));
  28906. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  28907. #region 页面操作权限验证
  28908. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  28909. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  28910. #endregion
  28911. #endregion
  28912. var viewData = await _tourClientListRep._Details(_dto.PortType, _dto.Id);
  28913. if (viewData.Code != 0)
  28914. {
  28915. return Ok(JsonView(false, viewData.Msg));
  28916. }
  28917. return Ok(JsonView(viewData.Data));
  28918. }
  28919. /// <summary>
  28920. /// 接团客户名单
  28921. /// Add Or Edit
  28922. /// </summary>
  28923. /// <param name="_dto"></param>
  28924. /// <returns></returns>
  28925. [HttpPost]
  28926. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28927. public async Task<IActionResult> PostTourClientListAddOrEdit(TourClientListAddOrEditDto _dto)
  28928. {
  28929. #region 参数验证
  28930. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  28931. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  28932. if (_dto.Id < 0) return Ok(JsonView(false, "请传入有效的Id参数!"));
  28933. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  28934. #region 页面操作权限验证
  28935. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  28936. if (_dto.Id == 0) //添加
  28937. {
  28938. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
  28939. }
  28940. else if (_dto.Id >= 0) //修改
  28941. {
  28942. if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
  28943. }
  28944. #endregion
  28945. #endregion
  28946. var viewData = await _tourClientListRep._AddOrEdit(_dto);
  28947. if (viewData.Code != 0)
  28948. {
  28949. return Ok(JsonView(false, viewData.Msg));
  28950. }
  28951. return Ok(JsonView(true));
  28952. }
  28953. /// <summary>
  28954. /// 接团客户名单
  28955. /// json字符串 AddMultiple(添加多个)
  28956. /// </summary>
  28957. /// <param name="_dto"></param>
  28958. /// <returns></returns>
  28959. [HttpPost]
  28960. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28961. public async Task<IActionResult> PostTourClientListJsonFormatAddMultiple(PostTourClientListJsonFormatAddMultipleDto _dto)
  28962. {
  28963. #region 参数验证
  28964. string jsonLabel = _dto.JsonLabel;
  28965. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  28966. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  28967. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  28968. #region 页面操作权限验证
  28969. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  28970. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
  28971. #endregion
  28972. #endregion
  28973. var request = new TourClientListAddMultipleDto();
  28974. request.DiId = _dto.DiId;
  28975. request.UserId = _dto.UserId;
  28976. if (!CommonFun.IsValidJson(jsonLabel)) return Ok(JsonView(false, "JsonLabel参数不是合法的json格式!"));
  28977. if (string.IsNullOrEmpty(jsonLabel)) return Ok(JsonView(false, "JsonLabel参数值不能为空"));
  28978. List<TourClientListInfoCN> datas = JsonConvert.DeserializeObject<List<TourClientListInfoCN>>(jsonLabel);
  28979. if (!datas.Any()) return Ok(JsonView(false, "JsonLabel参数值不能为空!"));
  28980. var infos = new List<TourClientListInfo>();
  28981. foreach (var data in datas)
  28982. {
  28983. (string lastName, string firstName) = CommonFun.GetLastNameAndFirstName(data.Name);
  28984. string lastNameEn = CommonFun.ConvertToPinyin(lastName),
  28985. firstNameEn = CommonFun.ConvertToPinyin(lastName);
  28986. if (string.IsNullOrEmpty(lastNameEn) || string.IsNullOrEmpty(firstNameEn))
  28987. {
  28988. continue;
  28989. }
  28990. infos.Add(new TourClientListInfo()
  28991. {
  28992. IsAccompany = 1,
  28993. LastName = lastName,
  28994. FirstName = firstName,
  28995. Pinyin = lastNameEn + @"/" + firstNameEn,
  28996. Sex = data.Sex.Equals("男") ? 0 : data.Sex.Equals("女") ? 1 : 2,
  28997. CompanyFullName = data.CompanyFullName,
  28998. Job = data.Job
  28999. });
  29000. }
  29001. if (infos.Any())
  29002. {
  29003. var viewData = await _tourClientListRep._AddMultiple(request);
  29004. if (viewData.Code != 0)
  29005. {
  29006. return Ok(JsonView(false, viewData.Msg));
  29007. }
  29008. return Ok(JsonView(true));
  29009. }
  29010. return Ok(JsonView(false));
  29011. }
  29012. /// <summary>
  29013. /// 接团客户名单
  29014. /// AddMultiple(添加多个)
  29015. /// </summary>
  29016. /// <param name="_dto"></param>
  29017. /// <returns></returns>
  29018. [HttpPost]
  29019. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29020. public async Task<IActionResult> PostTourClientListAddMultiple(TourClientListAddMultipleDto _dto)
  29021. {
  29022. #region 参数验证
  29023. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  29024. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  29025. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  29026. #region 页面操作权限验证
  29027. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  29028. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
  29029. #endregion
  29030. #endregion
  29031. var viewData = await _tourClientListRep._AddMultiple(_dto);
  29032. if (viewData.Code != 0)
  29033. {
  29034. return Ok(JsonView(false, viewData.Msg));
  29035. }
  29036. return Ok(JsonView(true));
  29037. }
  29038. /// <summary>
  29039. /// 接团客户名单
  29040. /// Del
  29041. /// </summary>
  29042. /// <param name="_dto"></param>
  29043. /// <returns></returns>
  29044. [HttpPost]
  29045. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29046. public async Task<IActionResult> PostTourClientListDel(TourClientListDelDto _dto)
  29047. {
  29048. #region 参数验证
  29049. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  29050. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  29051. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  29052. #region 页面操作权限验证
  29053. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  29054. if (pageFunAuthView.DeleteAuth == 0) return Ok(JsonView(false, "您没有删除权限!"));
  29055. #endregion
  29056. #endregion
  29057. var viewData = await _tourClientListRep._Del(_dto.Id, _dto.UserId);
  29058. if (viewData.Code != 0)
  29059. {
  29060. return Ok(JsonView(false, viewData.Msg));
  29061. }
  29062. return Ok(JsonView(true));
  29063. }
  29064. /// <summary>
  29065. /// 接团客户名单
  29066. /// 文件下载 客户名单
  29067. /// </summary>
  29068. /// <param name="_dto"></param>
  29069. /// <returns></returns>
  29070. [HttpPost]
  29071. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29072. public async Task<IActionResult> PostTourClientListDownloadFile(PostTourClientListDownloadFile _dto)
  29073. {
  29074. #region 参数验证
  29075. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  29076. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  29077. if (_dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId参数"));
  29078. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  29079. #region 页面操作权限验证
  29080. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  29081. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  29082. #endregion
  29083. #endregion
  29084. string clientSql = string.Format(@"Select tcl.Id,tcl.DiId,temp.*,tcl.ShippingSpaceTypeId,tcl.ShippingSpaceSpecialNeeds,
  29085. tcl.HotelSpecialNeeds,tcl.MealSpecialNeeds,tcl.Remark
  29086. From Grp_TourClientList tcl
  29087. Left Join
  29088. (Select dc.Id As DcId,dc.LastName,dc.FirstName,dc.Pinyin,dc.Sex,ccom.CompanyFullName,dc.Job,
  29089. cc1.CertNo As IDCardNo,dc.Phone,dc.BirthDay,cc2.PassportType,cc2.CertNo As PassportNo,cc2.Country,
  29090. cc2.Area,cc2.IssueDt,cc2.ExpiryDt
  29091. From Crm_DeleClient dc
  29092. Left Join Crm_CustomerCompany ccom On dc.CrmCompanyId = ccom.Id And ccom.IsDel = 0
  29093. Left Join Crm_CustomerCert cc1 On dc.Id = cc1.DcId And cc1.SdId = 773 And cc1.IsDel = 0
  29094. Left Join Crm_CustomerCert cc2 On dc.Id = cc2.DcId And cc2.SdId = 774 And cc2.IsDel = 0
  29095. Where dc.IsDel = 0) temp
  29096. On temp.DcId =tcl.ClientId
  29097. Where tcl.IsDel = 0 And tcl.DiId = {0}", _dto.DiId);
  29098. List<TourClientListDetailsView> DcList = await _sqlSugar.SqlQueryable<TourClientListDetailsView>(clientSql).ToListAsync();
  29099. if (DcList.Count < 0) return Ok(JsonView(false, "该团未录入客户名单!"));
  29100. //载入模板
  29101. string tempPath = AppSettingsHelper.Get("WordBasePath") + "Template/dwon_团组人员列表模板.doc";
  29102. if (_dto.Language == 1)
  29103. {
  29104. tempPath = AppSettingsHelper.Get("WordBasePath") + "Template/EN_Down_团组人员列表模板.doc";
  29105. }
  29106. //载入模板
  29107. var doc = new Document(tempPath);
  29108. DocumentBuilder builder = new DocumentBuilder(doc);
  29109. //获取word里所有表格
  29110. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  29111. //获取所填表格的序数
  29112. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  29113. var rowStart = tableOne.Rows[0]; //获取第1行
  29114. if (_dto.Language == 0)
  29115. {
  29116. //循环赋值
  29117. for (int i = 0; i < DcList.Count; i++)
  29118. {
  29119. EncryptionProcessor.DecryptProperties(DcList[i]);
  29120. builder.MoveToCell(0, i + 1, 0, 0);
  29121. builder.Write(DcList[i].LastName + DcList[i].FirstName);
  29122. builder.MoveToCell(0, i + 1, 1, 0);
  29123. int sex = DcList[i].Sex;
  29124. string sexStr = string.Empty;
  29125. if (sex == 0) sexStr = "男";
  29126. else if (sex == 1) sexStr = "女";
  29127. else sexStr = "未设置";
  29128. builder.Write(sexStr);
  29129. builder.MoveToCell(0, i + 1, 2, 0);
  29130. string birthDay = DcList[i].BirthDay;
  29131. string birthDayStr = string.Empty;
  29132. if (!string.IsNullOrEmpty(birthDay))
  29133. {
  29134. birthDayStr = Convert.ToDateTime(birthDay).ToString("yyyy-MM-dd");
  29135. }
  29136. builder.Write(birthDayStr);
  29137. builder.MoveToCell(0, i + 1, 3, 0);
  29138. string company = "";
  29139. if (!string.IsNullOrEmpty(DcList[i].CompanyFullName))
  29140. {
  29141. company = DcList[i].CompanyFullName.ToString();
  29142. }
  29143. builder.Write(company);
  29144. builder.MoveToCell(0, i + 1, 4, 0);
  29145. builder.Write(DcList[i].Job);
  29146. }
  29147. }
  29148. else if (_dto.Language == 1)
  29149. {
  29150. List<Res_PositionEnglishComparison> listPEC = _setDataRep.Query<Res_PositionEnglishComparison>(s => s.IsDel == 0).ToList();
  29151. List<Res_CompanyEnglishComparison> listCEC = _setDataRep.Query<Res_CompanyEnglishComparison>(s => s.IsDel == 0).ToList();
  29152. List<string> transArrayStr = new List<string>();
  29153. string transStrRes1 = "";
  29154. var clientEnglishs = new List<ClientEnglishView>();
  29155. for (int i = 0; i < DcList.Count; i++)
  29156. {
  29157. var dc = DcList[i];
  29158. EncryptionProcessor.DecryptProperties(dc);
  29159. if (dc.CompanyFullName.Equals("暂无")) dc.CompanyFullName = "-";
  29160. if (dc.Job.Equals("暂无")) dc.Job = "-";
  29161. string str1 = $"{i}&{dc.CompanyFullName}&{dc.Job}";
  29162. if (DcList.Count - 1 == i) transStrRes1 += str1;
  29163. else transStrRes1 += $"{str1}|";
  29164. clientEnglishs.Add(new()
  29165. {
  29166. Id = dc.Id,
  29167. LastName = dc.LastName,
  29168. FirstName = dc.FirstName,
  29169. Pinyin = dc.Pinyin,
  29170. Sex = dc.Sex,
  29171. CompanyFullName = dc.CompanyFullName,
  29172. Job = dc.Job,
  29173. IDCardNo = dc.IDCardNo,
  29174. BirthDay = dc.BirthDay,
  29175. });
  29176. }
  29177. #region AI转英文
  29178. string jsonValue = JsonConvert.SerializeObject(clientEnglishs);
  29179. string text = @"将此JSON的中文部分全部翻译为英文,然后只给出修改后的JSON数据,不要其他任何文字";
  29180. List<SeedMessages> messages = new List<SeedMessages>()
  29181. {
  29182. new SeedMessages
  29183. {
  29184. Role = KimiRole.user,
  29185. Content = jsonValue + text
  29186. }
  29187. };
  29188. KiMiApiClient client = new KiMiApiClient();
  29189. var kimiApiResult = await client.SeedMessage(messages);
  29190. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  29191. string clients = kimiApiResult_JObject["content"].ToString();
  29192. string startStr = "```json", endStr = "```";
  29193. // 判断并清除开头部分
  29194. if (clients.StartsWith(startStr))
  29195. {
  29196. clients = clients.Remove(0, startStr.Length);
  29197. }
  29198. // 判断并清除结尾部分
  29199. if (clients.EndsWith(endStr))
  29200. {
  29201. clients = clients.Remove(clients.Length - endStr.Length);
  29202. }
  29203. var en_Json = JsonConvert.DeserializeObject<List<ClientEnglishView>>(clients);
  29204. //循环赋值
  29205. for (int i = 0; i < en_Json.Count; i++)
  29206. {
  29207. var dc = en_Json[i];
  29208. var dc1 = DcList.Find(x => x.Id == dc.Id);
  29209. string PYName = dc.FirstName + " " + dc.LastName;
  29210. builder.MoveToCell(0, i + 1, 0, 0);
  29211. builder.Write(PYName);
  29212. string sex = dc.Sex == 0 ? "Male" : dc.Sex == 1 ? "Female" : "";
  29213. builder.MoveToCell(0, i + 1, 1, 0);
  29214. builder.Write(sex);
  29215. DateTime birthDt;
  29216. bool b_birth = DateTime.TryParse(dc.BirthDay, out birthDt);
  29217. string birthday = b_birth ? birthDt.ToString("yyyy-MM-dd") : " ";
  29218. builder.MoveToCell(0, i + 1, 2, 0);
  29219. builder.Write(birthday);
  29220. string company = string.Empty, job = string.Empty;
  29221. company = dc.CompanyFullName;
  29222. job = dc.Job;
  29223. if (dc1 != null && !string.IsNullOrEmpty(dc1.CompanyFullName))
  29224. {
  29225. //查询对照表
  29226. Res_CompanyEnglishComparison tempCec = listCEC.FirstOrDefault(s => s.zhName.Contains(dc1.CompanyFullName.ToString().Trim()));
  29227. if (tempCec != null)
  29228. {
  29229. company = tempCec.enName;
  29230. }
  29231. }
  29232. builder.MoveToCell(0, i + 1, 3, 0);
  29233. builder.Write(company);
  29234. if (dc1 != null && !string.IsNullOrEmpty(dc1.Job))
  29235. {
  29236. //查询对照表
  29237. Res_PositionEnglishComparison tempPec = listPEC.FirstOrDefault(s => s.zhName == dc1.Job.ToString().Trim());
  29238. if (tempPec != null)
  29239. {
  29240. job = tempPec.enName;
  29241. }
  29242. }
  29243. builder.MoveToCell(0, i + 1, 4, 0);
  29244. builder.Write(job);
  29245. }
  29246. #endregion
  29247. #region 旧翻译英文处理
  29248. ////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";
  29249. //string transStrRes = "";
  29250. //if (transStrRes1.Length > 0)
  29251. //{
  29252. // transStrRes = await _juHeApi.GetTextTranslateAsync(transStrRes1);
  29253. //}
  29254. ////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
  29255. ////await _juHeApi.GetTextTranslateAsync(DcList[i].CompanyFullName.ToString().Trim()) ?? "";
  29256. ////List<string> transArray = new List<string> { };
  29257. //List<TranslateInfo> transArray = new List<TranslateInfo>();
  29258. //if (transStrRes.Contains("|"))
  29259. //{
  29260. // string[] transArray1 = transStrRes.Split('|');
  29261. // if (transArray1.Length > 0)
  29262. // {
  29263. // foreach (var item in transArray1)
  29264. // {
  29265. // if (item.Contains("&"))
  29266. // {
  29267. // string[] transArray2 = item.Split('&');
  29268. // int index = 0;
  29269. // string companyName = "", job = "";
  29270. // if (transArray2.Length > 0)
  29271. // {
  29272. // bool success = int.TryParse(transArray2[0].Trim(), out index);
  29273. // if (1 < transArray2.Length) companyName = transArray2[1];
  29274. // if (2 < transArray2.Length) job = transArray2[2];
  29275. // }
  29276. // transArray.Add(new TranslateInfo { Index = index, CompanyName = companyName, Job = job });
  29277. // }
  29278. // }
  29279. // }
  29280. //}
  29281. ////循环赋值
  29282. //for (int i = 0; i < DcList.Count; i++)
  29283. //{
  29284. // string PYName = "";
  29285. // if (DcList[i].Pinyin.Length > 0 && DcList[i].Pinyin.IndexOf('/') > -1)
  29286. // {
  29287. // string PY_Last = DcList[i].Pinyin.Split('/')[0];
  29288. // string PY_First = DcList[i].Pinyin.Split('/')[1];
  29289. // PYName = PY_First + " " + PY_Last;
  29290. // }
  29291. // else
  29292. // {
  29293. // string PY_Last = DcList[i].LastName.GetTotalPingYin().Count > 0 ? DcList[i].LastName.GetTotalPingYin()[0].ToUpper() : "";
  29294. // string PY_First = DcList[i].FirstName.GetTotalPingYin().Count > 0 ? DcList[i].FirstName.GetTotalPingYin()[0].ToUpper() : "";
  29295. // PYName = PY_First + " " + PY_Last;
  29296. // }
  29297. // builder.MoveToCell(0, i + 1, 0, 0);
  29298. // builder.Write(PYName);
  29299. // string sex = DcList[i].Sex == 0 ? "Male" : DcList[i].Sex == 1 ? "Female" : "";
  29300. // builder.MoveToCell(0, i + 1, 1, 0);
  29301. // builder.Write(sex);
  29302. // DateTime birthDt;
  29303. // bool b_birth = DateTime.TryParse(DcList[i].BirthDay, out birthDt);
  29304. // string birthday = b_birth ? birthDt.ToString("yyyy-MM-dd") : " ";
  29305. // builder.MoveToCell(0, i + 1, 2, 0);
  29306. // builder.Write(birthday);
  29307. // string company = string.Empty, job = string.Empty;
  29308. // var dcTransInfo = transArray.FirstOrDefault(s => s.Index == i);
  29309. // if (dcTransInfo != null)
  29310. // {
  29311. // company = dcTransInfo.CompanyName;
  29312. // job = dcTransInfo.Job;
  29313. // }
  29314. // if (!string.IsNullOrEmpty(DcList[i].CompanyFullName))
  29315. // {
  29316. // //查询对照表
  29317. // Res_CompanyEnglishComparison tempCec = listCEC.FirstOrDefault(s => s.zhName.Contains(DcList[i].CompanyFullName.ToString().Trim()));
  29318. // if (tempCec != null)
  29319. // {
  29320. // company = tempCec.enName;
  29321. // }
  29322. // //翻译
  29323. // else
  29324. // {
  29325. // }
  29326. // }
  29327. // builder.MoveToCell(0, i + 1, 3, 0);
  29328. // builder.Write(company);
  29329. // if (!string.IsNullOrEmpty(DcList[i].Job.ToString()))
  29330. // {
  29331. // //查询对照表
  29332. // Res_PositionEnglishComparison tempPec = listPEC.FirstOrDefault(s => s.zhName == DcList[i].Job.ToString().Trim());
  29333. // if (tempPec != null)
  29334. // {
  29335. // job = tempPec.enName;
  29336. // }
  29337. // //翻译
  29338. // else
  29339. // {
  29340. // }
  29341. // }
  29342. // builder.MoveToCell(0, i + 1, 4, 0);
  29343. // builder.Write(job);
  29344. //}
  29345. #endregion
  29346. }
  29347. //删除多余行
  29348. while (tableOne.Rows.Count > DcList.Count + 1)
  29349. {
  29350. tableOne.Rows.RemoveAt(DcList.Count + 1);
  29351. }
  29352. string fileName = "组团人员名单(" + DateTime.Now.ToString("yyyyhhddHHmmss") + ").doc";
  29353. var fileDir = AppSettingsHelper.Get("WordBasePath") + "TourClientList/" + fileName;
  29354. doc.Save(fileDir);
  29355. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/TourClientList/" + fileName;
  29356. return Ok(JsonView(true, "操作成功!", Url));
  29357. }
  29358. private class TranslateInfo
  29359. {
  29360. public int Index { get; set; }
  29361. public string CompanyName { get; set; }
  29362. public string Job { get; set; }
  29363. }
  29364. [HttpPost]
  29365. public async Task<IActionResult> FileReadClient(List<IFormFile> files)
  29366. {
  29367. if (files.Count == 0)
  29368. {
  29369. return Ok(JsonView(false, "文件为空"));
  29370. }
  29371. KiMiApiClient KiMiApi = new KiMiApiClient();
  29372. var seedConter = await KiMiApi.UploadFilesAsync(files);
  29373. if (seedConter.Count == 0)
  29374. {
  29375. return Ok(JsonView(false, "上传结果为空!"));
  29376. }
  29377. var messages = new List<SeedMessages>
  29378. {
  29379. new SeedMessages { Role = KimiRole.system, Content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一切涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。" },
  29380. new SeedMessages { Role = KimiRole.user, Content = "根据文件内容 ,按照“姓、名、姓名拼音、性别、单位、职务、出生日期”的json格式来排列整理(性别和出生日期通过身份证来识别 , 当识别到性别为男时值给0女给1 未识别到性别的情况下值给-1,出生日期按照yyyy-MM-dd来整理(若出生日期没有值则为‘-’),文件存在拼音的情况读取对应的拼音不存在则设置拼音为中文名字全拼),只输出JSON数组数据 从'['开始 到']'结尾 ,不要除JSON数据外的任何文字以及符号" }
  29381. };
  29382. messages.InsertRange(1, seedConter);
  29383. var kimiApiResult = await KiMiApi.SeedMessage(messages);
  29384. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  29385. string clients = kimiApiResult_JObject["content"].ToString();
  29386. string startStr = "```json", endStr = "```";
  29387. // 判断并清除开头部分
  29388. if (clients.StartsWith(startStr))
  29389. {
  29390. clients = clients.Remove(0, startStr.Length);
  29391. }
  29392. // 判断并清除结尾部分
  29393. if (clients.EndsWith(endStr))
  29394. {
  29395. clients = clients.Remove(clients.Length - endStr.Length);
  29396. }
  29397. var clients_JObject = JsonConvert.DeserializeObject<List<JObject>>(clients);
  29398. Dictionary<string, string> clientFieldMap = new Dictionary<string, string>()
  29399. {
  29400. {"姓", "LastName" },
  29401. {"名", "FirstName" },
  29402. {"姓名拼音", "Pinyin" },
  29403. {"性别", "Sex" },
  29404. {"单位", "CompanyFullName" },
  29405. {"职务", "Job" },
  29406. {"出生日期", "Birthday" },
  29407. };
  29408. List<BaiduClientOCRView> crmClients = new List<BaiduClientOCRView>();
  29409. foreach (var item in clients_JObject)
  29410. {
  29411. BaiduClientOCRView cdc = new BaiduClientOCRView();
  29412. foreach (var field in clientFieldMap.Keys)
  29413. {
  29414. if (item.TryGetValue(field, out JToken value))
  29415. {
  29416. var getValue = value.ToString();
  29417. System.Type type = cdc.GetType();
  29418. PropertyInfo propertyInfo = type.GetProperty(clientFieldMap[field]);
  29419. var propertyValue = Convert.ChangeType(getValue, propertyInfo.PropertyType);
  29420. propertyInfo.SetValue(cdc, propertyValue);
  29421. }
  29422. }
  29423. crmClients.Add(cdc);
  29424. }
  29425. return Ok(JsonView(new
  29426. {
  29427. fileCount = files.Count,
  29428. UploadCount = seedConter.Count,
  29429. ApiResult = clients,
  29430. CrmClients = crmClients
  29431. }));
  29432. }
  29433. #endregion
  29434. #region 团组倒推表
  29435. /// <summary>
  29436. /// 倒推表基础数据
  29437. /// Init
  29438. /// </summary>
  29439. /// <returns></returns>
  29440. [HttpPost]
  29441. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29442. public async Task<IActionResult> PostInvertedListInit()
  29443. {
  29444. var viewData = await _invertedListRep.Init();
  29445. if (viewData.Code != 0)
  29446. {
  29447. return Ok(JsonView(false, viewData.Msg));
  29448. }
  29449. return Ok(JsonView(viewData.Data));
  29450. }
  29451. /// <summary>
  29452. /// 倒推表
  29453. /// Info
  29454. /// </summary>
  29455. /// <param name="dto"></param>
  29456. /// <returns></returns>
  29457. [HttpPost]
  29458. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29459. public async Task<IActionResult> PostInvertedListInfo(InvertedListCreateDto dto)
  29460. {
  29461. var viewData = await _invertedListRep.Info(dto.PortType, dto.DiId);
  29462. if (viewData.Code != 0)
  29463. {
  29464. return Ok(JsonView(false, viewData.Msg));
  29465. }
  29466. return Ok(JsonView(viewData.Data));
  29467. }
  29468. /// <summary>
  29469. /// 倒推表
  29470. /// Create
  29471. /// </summary>
  29472. /// <param name="dto"></param>
  29473. /// <returns></returns>
  29474. [HttpPost]
  29475. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29476. public async Task<IActionResult> PostInvertedListCreate(InvertedListCreateDto dto)
  29477. {
  29478. var viewData = await _invertedListRep.Create(dto.PortType, dto.DiId);
  29479. if (viewData.Code != 0)
  29480. {
  29481. return Ok(JsonView(false, viewData.Msg));
  29482. }
  29483. return Ok(JsonView(viewData.Data));
  29484. }
  29485. /// <summary>
  29486. /// 倒推表
  29487. /// Update
  29488. /// </summary>
  29489. /// <param name="dto"></param>
  29490. /// <returns></returns>
  29491. [HttpPost]
  29492. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29493. public async Task<IActionResult> PostInvertedListUpdate(InvertedListUpdateDto dto)
  29494. {
  29495. var viewData = await _invertedListRep.Update(dto);
  29496. if (viewData.Code != 0)
  29497. {
  29498. return Ok(JsonView(false, viewData.Msg));
  29499. }
  29500. return Ok(JsonView(viewData.Data));
  29501. }
  29502. /// <summary>
  29503. /// 倒推表
  29504. /// File Download
  29505. /// </summary>
  29506. /// <param name="dto"></param>
  29507. /// <returns></returns>
  29508. [HttpPost]
  29509. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29510. public async Task<IActionResult> PostInvertedListFileDownload(InvertedListFileDownloadDto dto)
  29511. {
  29512. var info2 = await _invertedListRep.Info(1, dto.DiId);
  29513. if (info2.Code != 0)
  29514. {
  29515. return Ok(JsonView(false, "倒推表数据未生成,请先生成倒退表数据!"));
  29516. }
  29517. var info1 = info2.Data as InvertedListInfoView;
  29518. var info = await _invertedListRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == dto.DiId).FirstAsync();
  29519. string teamName = "";
  29520. if (info != null) teamName = info.TeamName;
  29521. var tempPath = $"{AppSettingsHelper.Get("WordBasePath")}Template/倒退表模板20250121.doc";
  29522. var doc = new Document();
  29523. var builder = new DocumentBuilder(doc);
  29524. #region old insert
  29525. ////载入模板
  29526. //var tempPath = $"{AppSettingsHelper.Get("WordBasePath")}Template/倒退表模板20200617.doc";
  29527. //Document doc = new Document(tempPath);
  29528. //DocumentBuilder builder = new DocumentBuilder(doc);
  29529. //利用键值对存放数据
  29530. //Dictionary<string, string> dic = new Dictionary<string, string>();
  29531. //dic.Add("TeamName", teamName);
  29532. //dic.Add("StartTime", info1.AirportdDropOffDt.ConvertToDatetime()); //开始时间
  29533. //dic.Add("BPtime", info1.ApprovalDataDt.ConvertToDatetime());
  29534. //dic.Add("BPRemark", info1.ApprovalDataRemark);
  29535. //dic.Add("SQtime", info1.ApprovalDt.ConvertToDatetime());
  29536. //dic.Add("SQRemark", info1.ApprovalRemark);
  29537. //dic.Add("CPJtime", info1.IssueApprovalDt.ConvertToDatetime());
  29538. //dic.Add("CPJRemark", info1.IssueApprovalRemark);
  29539. ////dic.Add("HZtime", info1.ApplyPassportDt.ConvertToDatetime());
  29540. ////dic.Add("HZRemark", info1.ApplyPassportRemark);
  29541. //dic.Add("QZtime", info1.VisaInformationDt.ConvertToDatetime());
  29542. //dic.Add("QZRemark", info1.VisaInformationRemark);
  29543. //dic.Add("SQQZtime", info1.SendVisaDt.ConvertToDatetime());
  29544. //dic.Add("SQQZRemark", info1.SendVisaRemark);
  29545. //dic.Add("CQtime", info1.IssueVisaDt.ConvertToDatetime());
  29546. //dic.Add("CQRemark", info1.IssueVisaRemark);
  29547. //dic.Add("XQHtime", info1.PreTripMeetingDt.ConvertToDatetime());
  29548. //dic.Add("XQHRemark", info1.PreTripMeetingRemark);
  29549. //dic.Add("SJtime", info1.AirportdDropOffDt.ConvertToDatetime());
  29550. //dic.Add("SJRemark", info1.AirportdDropOffRemark);
  29551. //#region 填充word模板书签内容
  29552. //foreach (var key in dic.Keys)
  29553. //{
  29554. // builder.MoveToBookmark(key);
  29555. // builder.Write(dic[key]);
  29556. //}
  29557. //#endregion
  29558. #endregion
  29559. #region New Insert
  29560. string titleFont = $"仿宋",
  29561. contentFont = $"仿宋";
  29562. var fontColor = Color.FromArgb(64, 64, 64);
  29563. //设置标题 团组名称
  29564. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  29565. builder.Font.Name = titleFont;
  29566. builder.Font.Color = fontColor;
  29567. builder.Font.Size = 12;
  29568. builder.Font.Bold = true;
  29569. builder.Writeln(teamName);
  29570. //设置副标题 团组出访时间
  29571. builder.Font.Size = 12;
  29572. builder.Writeln("出发时间:" + info1.AirportdDropOffDt.ConvertToDatetime());
  29573. builder.Writeln();
  29574. var backgroundColor = Color.FromArgb(199, 199, 199);
  29575. var table = builder.StartTable();
  29576. builder.InsertCell();
  29577. builder.CellFormat.Shading.BackgroundPatternColor = backgroundColor;
  29578. builder.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.Single;
  29579. builder.CellFormat.Borders.LineWidth = 1;
  29580. builder.CellFormat.Borders.Color = Color.FromArgb(183, 183, 183);
  29581. table.FirstRow.FirstCell.CellFormat.Width = 20; // 单位为百分比
  29582. builder.RowFormat.Height = 40;
  29583. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  29584. builder.Font.Name = contentFont;
  29585. builder.Font.Size = 12;
  29586. builder.Font.Bold = true;
  29587. builder.Font.Color = fontColor;
  29588. builder.Write("时间");
  29589. builder.InsertCell();
  29590. table.FirstRow.FirstCell.CellFormat.Width = 30; // 单位为百分比
  29591. builder.Write("流程");
  29592. builder.InsertCell();
  29593. table.FirstRow.FirstCell.CellFormat.Width = 50; // 单位为百分比
  29594. builder.Write("说明");
  29595. builder.EndRow();
  29596. //报批资料准备
  29597. if (info1.IsSelectedAirportd)
  29598. {
  29599. InvertedListFileDownloadSetRow(builder, contentFont, info1.ApprovalDataDt.ConvertToDatetime(), "报批资料准备", info1.ApprovalDataRemark);
  29600. }
  29601. //报批/提供送签资料
  29602. if (info1.IsSelectedApprovalData)
  29603. {
  29604. InvertedListFileDownloadSetRow(builder, contentFont, info1.ApprovalDt.ConvertToDatetime(), "报批/提供送签资料", info1.ApprovalRemark);
  29605. }
  29606. //出批件护照办理
  29607. if (info1.IsSelectedIssueApproval)
  29608. {
  29609. InvertedListFileDownloadSetRow(builder, contentFont, info1.IssueApprovalDt.ConvertToDatetime(), "出批件\r\n护照办理", info1.IssueApprovalRemark);
  29610. }
  29611. //签证资料准备
  29612. if (info1.IsSelectedVisaInfo)
  29613. {
  29614. InvertedListFileDownloadSetRow(builder, contentFont, info1.VisaInformationDt.ConvertToDatetime(), "签证资料准备", info1.VisaInformationRemark);
  29615. }
  29616. //送签
  29617. if (info1.IsSelectedSendVisa)
  29618. {
  29619. InvertedListFileDownloadSetRow(builder, contentFont, info1.SendVisaDt.ConvertToDatetime(), "送签", info1.SendVisaRemark);
  29620. }
  29621. //出签
  29622. if (info1.IsSelectedIssueVisa)
  29623. {
  29624. InvertedListFileDownloadSetRow(builder, contentFont, info1.IssueVisaDt.ConvertToDatetime(), "出签", info1.IssueVisaRemark);
  29625. }
  29626. //机票
  29627. if (info1.IsSelectedAirTicket)
  29628. {
  29629. if (string.IsNullOrEmpty(info1.AirTicketDt)) info1.AirTicketDt = info1.IssueVisaDt;
  29630. InvertedListFileDownloadSetRow(builder, contentFont, info1.AirTicketDt.ConvertToDatetime(), "机票", info1.AirTicketRemark);
  29631. }
  29632. //酒店
  29633. if (info1.IsSelectedHotel)
  29634. {
  29635. if (string.IsNullOrEmpty(info1.HotelDt)) info1.HotelDt = info1.IssueVisaDt;
  29636. InvertedListFileDownloadSetRow(builder, contentFont, info1.HotelDt.ConvertToDatetime(), "酒店", info1.HotelRemark);
  29637. }
  29638. //开行前会
  29639. if (info1.IsSelectedPreTripMeeting)
  29640. {
  29641. InvertedListFileDownloadSetRow(builder, contentFont, info1.PreTripMeetingDt.ConvertToDatetime(), "开行前会", info1.PreTripMeetingRemark);
  29642. }
  29643. //送机
  29644. if (info1.IsSelectedAirportdDropOff)
  29645. {
  29646. InvertedListFileDownloadSetRow(builder, contentFont, info1.AirportdDropOffDt.ConvertToDatetime(), "送机", info1.AirportdDropOffRemark);
  29647. }
  29648. builder.EndTable();
  29649. //table.PreferredWidth = PreferredWidth.FromPercent(100.00);
  29650. //table.AutoFit(AutoFitBehavior.FixedColumnWidths);
  29651. for (int i = 0; i < table.Rows.Count; i++)
  29652. {
  29653. var row = table.Rows[i];
  29654. //设置宽度
  29655. row.Cells[0].CellFormat.Width = 20.00;
  29656. row.Cells[1].CellFormat.Width = 30.00;
  29657. row.Cells[2].CellFormat.Width = 50.00;
  29658. if (i != 0)
  29659. {
  29660. //边框设置
  29661. InvertedListFileDownloadSetBorders(row.Cells, 0);
  29662. InvertedListFileDownloadSetBorders(row.Cells, 1);
  29663. InvertedListFileDownloadSetBorders(row.Cells, 2);
  29664. }
  29665. }
  29666. #region 页脚插入图片
  29667. // 创建页脚
  29668. Aspose.Words.HeaderFooter footer = new Aspose.Words.HeaderFooter(doc, HeaderFooterType.FooterPrimary);
  29669. doc.FirstSection.HeadersFooters.Add(footer);
  29670. Paragraph para = new Paragraph(doc);
  29671. para.ParagraphFormat.Alignment = ParagraphAlignment.Right;
  29672. footer.AppendChild(para);
  29673. builder.MoveTo(para);
  29674. string imagePath = "./Images/FMGJ_Log.png";
  29675. builder.InsertImage(imagePath);
  29676. #endregion
  29677. #endregion
  29678. var fileDir = AppSettingsHelper.Get("WordBasePath");
  29679. string fileName = $"{teamName}团出行准备流程表{CommonFun.GUID}.doc";
  29680. string filePath = fileDir + $@"InvertedList/{fileName}";
  29681. doc.Save(filePath);
  29682. string Url = $@"{AppSettingsHelper.Get("WordBaseUrl")}Office/Word/InvertedList/{fileName}";
  29683. return Ok(JsonView(true, "操作成功!", Url));
  29684. }
  29685. /// <summary>
  29686. /// 倒推表
  29687. /// File Download
  29688. /// 客户版
  29689. /// </summary>
  29690. /// <param name="dto"></param>
  29691. /// <returns></returns>
  29692. [HttpPost]
  29693. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29694. public async Task<IActionResult> PostInvertedListClientFileDownload(InvertedListFileDownloadDto dto)
  29695. {
  29696. var info2 = await _invertedListRep.Info(1, dto.DiId);
  29697. if (info2.Code != 0)
  29698. {
  29699. return Ok(JsonView(false, "倒推表数据未生成,请先生成倒退表数据!"));
  29700. }
  29701. var info1 = info2.Data as InvertedListInfoView;
  29702. var info = await _invertedListRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == dto.DiId).FirstAsync();
  29703. string teamName = "";
  29704. if (info != null) teamName = info.TeamName;
  29705. var tempPath = $"{AppSettingsHelper.Get("WordBasePath")}Template/倒退表模板20250121.doc";
  29706. var doc = new Document();
  29707. var builder = new DocumentBuilder(doc);
  29708. #region New Insert
  29709. string titleFont = $"仿宋",
  29710. contentFont = $"仿宋";
  29711. var fontColor = Color.FromArgb(64, 64, 64);
  29712. //设置标题 团组名称
  29713. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  29714. builder.Font.Name = titleFont;
  29715. builder.Font.Color = fontColor;
  29716. builder.Font.Size = 12;
  29717. builder.Font.Bold = true;
  29718. builder.Writeln(teamName);
  29719. //设置副标题 团组出访时间
  29720. builder.Font.Size = 12;
  29721. builder.Writeln("出发时间:" + info1.AirportdDropOffDt.ConvertToDatetime());
  29722. builder.Writeln();
  29723. var backgroundColor = Color.FromArgb(199, 199, 199);
  29724. var table = builder.StartTable();
  29725. builder.InsertCell();
  29726. builder.CellFormat.Shading.BackgroundPatternColor = backgroundColor;
  29727. builder.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.Single;
  29728. builder.CellFormat.Borders.LineWidth = 1;
  29729. builder.CellFormat.Borders.Color = Color.FromArgb(183, 183, 183);
  29730. table.FirstRow.FirstCell.CellFormat.Width = 20; // 单位为百分比
  29731. builder.RowFormat.Height = 40;
  29732. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  29733. builder.Font.Name = contentFont;
  29734. builder.Font.Size = 12;
  29735. builder.Font.Bold = true;
  29736. builder.Font.Color = fontColor;
  29737. builder.Write("时间");
  29738. builder.InsertCell();
  29739. table.FirstRow.FirstCell.CellFormat.Width = 30; // 单位为百分比
  29740. builder.Write("流程");
  29741. builder.InsertCell();
  29742. table.FirstRow.FirstCell.CellFormat.Width = 50; // 单位为百分比
  29743. builder.Write("说明");
  29744. builder.EndRow();
  29745. //报批资料准备
  29746. if (info1.IsSelectedAirportd)
  29747. {
  29748. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_ApprovalDataDt.ConvertToDatetime(), "报批资料准备", info1.ApprovalDataRemark);
  29749. }
  29750. //报批/提供送签资料
  29751. if (info1.IsSelectedApprovalData)
  29752. {
  29753. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_ApprovalDt.ConvertToDatetime(), "报批/提供送签资料", info1.ApprovalRemark);
  29754. }
  29755. //出批件护照办理
  29756. if (info1.IsSelectedIssueApproval)
  29757. {
  29758. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_IssueApprovalDt.ConvertToDatetime(), "出批件\r\n护照办理", info1.IssueApprovalRemark);
  29759. }
  29760. //签证资料准备
  29761. if (info1.IsSelectedVisaInfo)
  29762. {
  29763. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_VisaInformationDt.ConvertToDatetime(), "签证资料准备", info1.VisaInformationRemark);
  29764. }
  29765. //送签
  29766. if (info1.IsSelectedSendVisa)
  29767. {
  29768. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_SendVisaDt.ConvertToDatetime(), "送签", info1.SendVisaRemark);
  29769. }
  29770. //出签
  29771. if (info1.IsSelectedIssueVisa)
  29772. {
  29773. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_IssueVisaDt.ConvertToDatetime(), "出签", info1.IssueVisaRemark);
  29774. }
  29775. //机票
  29776. if (info1.IsSelectedAirTicket)
  29777. {
  29778. if (string.IsNullOrEmpty(info1.Client_AirTicketDt)) info1.Client_AirTicketDt = info1.Client_IssueVisaDt;
  29779. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_AirTicketDt.ConvertToDatetime(), "机票", info1.AirTicketRemark);
  29780. }
  29781. //酒店
  29782. if (info1.IsSelectedHotel)
  29783. {
  29784. if (string.IsNullOrEmpty(info1.Client_HotelDt)) info1.Client_HotelDt = info1.Client_IssueVisaDt;
  29785. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_HotelDt.ConvertToDatetime(), "酒店", info1.HotelRemark);
  29786. }
  29787. //开行前会
  29788. if (info1.IsSelectedPreTripMeeting)
  29789. {
  29790. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_PreTripMeetingDt.ConvertToDatetime(), "开行前会", info1.PreTripMeetingRemark);
  29791. }
  29792. //送机
  29793. if (info1.IsSelectedAirportdDropOff)
  29794. {
  29795. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_AirportdDropOffDt.ConvertToDatetime(), "送机", info1.AirportdDropOffRemark);
  29796. }
  29797. builder.EndTable();
  29798. //table.PreferredWidth = PreferredWidth.FromPercent(100.00);
  29799. //table.AutoFit(AutoFitBehavior.FixedColumnWidths);
  29800. for (int i = 0; i < table.Rows.Count; i++)
  29801. {
  29802. var row = table.Rows[i];
  29803. //设置宽度
  29804. row.Cells[0].CellFormat.Width = 20.00;
  29805. row.Cells[1].CellFormat.Width = 30.00;
  29806. row.Cells[2].CellFormat.Width = 50.00;
  29807. if (i != 0)
  29808. {
  29809. //边框设置
  29810. InvertedListFileDownloadSetBorders(row.Cells, 0);
  29811. InvertedListFileDownloadSetBorders(row.Cells, 1);
  29812. InvertedListFileDownloadSetBorders(row.Cells, 2);
  29813. }
  29814. }
  29815. #region 页脚插入图片
  29816. // 创建页脚
  29817. Aspose.Words.HeaderFooter footer = new Aspose.Words.HeaderFooter(doc, HeaderFooterType.FooterPrimary);
  29818. doc.FirstSection.HeadersFooters.Add(footer);
  29819. Paragraph para = new Paragraph(doc);
  29820. para.ParagraphFormat.Alignment = ParagraphAlignment.Right;
  29821. footer.AppendChild(para);
  29822. builder.MoveTo(para);
  29823. string imagePath = "./Images/FMGJ_Log.png";
  29824. builder.InsertImage(imagePath);
  29825. #endregion
  29826. #endregion
  29827. var fileDir = AppSettingsHelper.Get("WordBasePath");
  29828. string fileName = $"{teamName}团出行准备流程表(客户版){CommonFun.GUID}.doc";
  29829. string filePath = fileDir + $@"InvertedList/{fileName}";
  29830. doc.Save(filePath);
  29831. string Url = $@"{AppSettingsHelper.Get("WordBaseUrl")}Office/Word/InvertedList/{fileName}";
  29832. return Ok(JsonView(true, "操作成功!", Url));
  29833. }
  29834. private void InvertedListFileDownloadSetRow(DocumentBuilder builder, string fontName, string dateTime, string content, string reamrk)
  29835. {
  29836. var fontColor = Color.FromArgb(64, 64, 64);
  29837. builder.InsertCell();
  29838. builder.CellFormat.Shading.BackgroundPatternColor = Color.Empty;
  29839. builder.RowFormat.Height = 40;
  29840. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  29841. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  29842. builder.Font.Name = fontName;
  29843. builder.Font.Size = 8;
  29844. builder.Font.Bold = true;
  29845. builder.Font.Color = fontColor;
  29846. builder.Write(dateTime);
  29847. builder.InsertCell();
  29848. builder.Font.Size = 9;
  29849. builder.Font.Bold = true;
  29850. builder.Font.Color = fontColor;
  29851. builder.Write(content);
  29852. builder.InsertCell();
  29853. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  29854. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  29855. builder.Font.Size = 9;
  29856. builder.Font.Bold = false;
  29857. builder.Font.Color = fontColor;
  29858. builder.Write(reamrk);
  29859. builder.EndRow();
  29860. }
  29861. private void InvertedListFileDownloadSetBorders(CellCollection cell, int index)
  29862. {
  29863. cell[index].CellFormat.Borders.Top.LineStyle = Aspose.Words.LineStyle.None;
  29864. cell[index].CellFormat.Borders.Bottom.LineStyle = Aspose.Words.LineStyle.None;
  29865. cell[index].CellFormat.Borders.Left.LineStyle = Aspose.Words.LineStyle.None;
  29866. cell[index].CellFormat.Borders.Right.LineStyle = Aspose.Words.LineStyle.None;
  29867. //cell[index].CellFormat.Borders.Horizontal.LineStyle = Aspose.Words.LineStyle.None;
  29868. //cell[index].CellFormat.Borders.Vertical.LineStyle = Aspose.Words.LineStyle.None;
  29869. }
  29870. #endregion
  29871. #region 会务倒推表
  29872. /// <summary>
  29873. /// 会务倒推表
  29874. /// Init
  29875. /// </summary>
  29876. /// <returns></returns>
  29877. [HttpPost]
  29878. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29879. public async Task<IActionResult> InforRetrogressTableInit()
  29880. {
  29881. var groupData = await _groupRepository.PostShareGroupInfos(1);
  29882. if (groupData.Code == 0) return Ok(JsonView(groupData.Data));
  29883. return Ok(JsonView(false, groupData.Msg));
  29884. }
  29885. /// <summary>
  29886. /// 会务倒推表
  29887. /// ExcelDownload
  29888. /// </summary>
  29889. /// <param name="dto"></param>
  29890. /// <returns></returns>
  29891. [HttpPost]
  29892. [ApiLog("InforRetrogressTable", OperationEnum.Download)]
  29893. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29894. public async Task<IActionResult> InforRetrogressTableFileDownload(InforRetrogressTableFileDownloadDto dto)
  29895. {
  29896. var validator = new InforRetrogressTableFileDownloadDtoValidator();
  29897. var validatorRes = await validator.ValidateAsync(dto);
  29898. if (!validatorRes.IsValid)
  29899. {
  29900. StringBuilder sb = new StringBuilder();
  29901. foreach (var item in validatorRes.Errors)
  29902. {
  29903. sb.AppendLine(item.ErrorMessage);
  29904. }
  29905. return Ok(JsonView(false, sb.ToString()));
  29906. }
  29907. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.GroupId);
  29908. if (groupInfo == null) return Ok(JsonView(false, $"该团组信息未填写!"));
  29909. //时间根据团组出访日期-接团录入日期的天数来判断用哪个模板
  29910. var days = groupInfo.VisitDate.Subtract(groupInfo.CreateTime).Days;
  29911. #region Excel
  29912. var tempPath = AppSettingsHelper.Get("ExcelTempPath");
  29913. var servicePath = AppSettingsHelper.Get("GrpFileBaseUrl");
  29914. var savePath = AppSettingsHelper.Get("ExcelBasePath") + "InforRetrogressTable/";
  29915. var ftpPath = AppSettingsHelper.Get("ExcelFtpPath") + "InforRetrogressTable/";
  29916. var fileNamePrefix = string.Empty;
  29917. if (days >= 30)
  29918. {
  29919. tempPath += $"会务工作倒推进度表(30天).xlsx";
  29920. fileNamePrefix = $"{groupInfo.TeamName}_会务工作倒推进度表(30天)";
  29921. }
  29922. else if (days < 30 && days > 7)
  29923. {
  29924. tempPath += $"会务工作倒推进度表(15天).xlsx";
  29925. fileNamePrefix = $"{groupInfo.TeamName}_会务工作倒推进度表(15天)";
  29926. }
  29927. else if (days <= 7)
  29928. {
  29929. tempPath += $"会务工作倒推进度表(7天).xlsx";
  29930. fileNamePrefix = $"{groupInfo.TeamName}_会务工作倒推进度表(7天)";
  29931. }
  29932. var fileName = $"{fileNamePrefix}{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx";
  29933. fileName = CommonFun.ValidFileName(fileName);
  29934. //载入模板
  29935. WorkbookDesigner designer = new WorkbookDesigner();
  29936. designer.Workbook = new Workbook(tempPath);
  29937. designer.Process();
  29938. if (!Directory.Exists(savePath))
  29939. {
  29940. Directory.CreateDirectory(savePath);
  29941. }
  29942. string serverPath = $"{savePath}{fileName}";
  29943. designer.Workbook.Save(serverPath);
  29944. string rst = $"{servicePath}{ftpPath}{fileName}";
  29945. #endregion
  29946. return Ok(JsonView(new { url = rst }));
  29947. }
  29948. #endregion
  29949. #region 三公签证费用(签证费、代办费)
  29950. /// <summary>
  29951. /// 三公签证费用(签证费、代办费)
  29952. /// List
  29953. /// </summary>
  29954. /// <returns></returns>
  29955. [HttpPost]
  29956. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29957. public async Task<IActionResult> PostVisaFeeList(VisaFeeListDto _dto)
  29958. {
  29959. return Ok(await _visaFeeInfoRep.List(_dto.PortType, _dto.DiId));
  29960. }
  29961. /// <summary>
  29962. /// 三公签证费用(签证费、代办费)
  29963. /// Add Or Update
  29964. /// </summary>
  29965. /// <returns></returns>
  29966. [HttpPost]
  29967. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29968. public async Task<IActionResult> PostVisaFeeAddAndUpdate(VisaFeeAddAndUpdateDto _dto)
  29969. {
  29970. var _view = await _visaFeeInfoRep.Update(_dto);
  29971. if (_view.Code != 0)
  29972. {
  29973. return Ok(JsonView(false, _view.Msg));
  29974. }
  29975. return Ok(JsonView(true, _view.Msg));
  29976. }
  29977. #endregion
  29978. #region 酒店询价
  29979. /// <summary>
  29980. /// 酒店询价
  29981. /// Init
  29982. /// </summary>
  29983. /// <returns></returns>
  29984. [HttpPost]
  29985. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29986. public async Task<IActionResult> PostHotelInquiryInit()
  29987. {
  29988. var res = await _hotelInquiryRep._Init();
  29989. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  29990. return Ok(JsonView(true, res.Msg, res.Data));
  29991. }
  29992. /// <summary>
  29993. /// 酒店询价
  29994. /// page Item
  29995. /// </summary>
  29996. /// <param name="_dto"></param>
  29997. /// <returns></returns>
  29998. [HttpPost]
  29999. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30000. public async Task<IActionResult> PostHotelInquiryPageItem(HotelInquiryPageItemDto _dto)
  30001. {
  30002. var res = await _hotelInquiryRep._PageItem(_dto.PageIndex, _dto.PageSize, _dto.PortType, _dto.DiId);
  30003. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  30004. var view = res.Data as PageDataViewBase;
  30005. return Ok(JsonView(true, res.Msg, view.Data, view.Total));
  30006. }
  30007. /// <summary>
  30008. /// 酒店询价
  30009. /// info
  30010. /// </summary>
  30011. /// <param name="_dto"></param>
  30012. /// <returns></returns>
  30013. [HttpPost]
  30014. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30015. public async Task<IActionResult> PostHotelInquiryInfo(HotelInquiryInfoDto _dto)
  30016. {
  30017. var res = await _hotelInquiryRep._Info(_dto.PortType, _dto.Id);
  30018. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  30019. return Ok(JsonView(true, res.Msg, res.Data));
  30020. }
  30021. /// <summary>
  30022. /// 酒店询价
  30023. /// Add Or Edit
  30024. /// </summary>
  30025. /// <param name="_dto"></param>
  30026. /// <returns></returns>
  30027. [HttpPost]
  30028. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30029. public async Task<IActionResult> PostHotelInquiryAddOrEdit(HotelInquiryAddOrEditDto _dto)
  30030. {
  30031. var res = await _hotelInquiryRep._AddOrEdit(_dto);
  30032. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  30033. return Ok(JsonView(true, res.Msg, res.Data));
  30034. }
  30035. /// <summary>
  30036. /// 酒店询价
  30037. /// Del
  30038. /// </summary>
  30039. /// <param name="_dto"></param>
  30040. /// <returns></returns>
  30041. [HttpPost]
  30042. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30043. public async Task<IActionResult> PostHotelInquiryDel(HotelInquiryDelDto _dto)
  30044. {
  30045. var res = await _hotelInquiryRep._Del(_dto.Id, _dto.DeleteUserId);
  30046. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  30047. return Ok(JsonView(true, res.Msg, res.Data));
  30048. }
  30049. #endregion
  30050. #region 下载匹配op行程单
  30051. /// <summary>
  30052. /// 匹配op行程单
  30053. /// Init
  30054. /// </summary>
  30055. /// <param name="dto">团组列表请求dto</param>
  30056. /// <returns></returns>
  30057. [HttpPost]
  30058. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30059. public async Task<IActionResult> PostMateOpGroupInit(MateOpGroupInitDto dto)
  30060. {
  30061. Stopwatch stopwatch = Stopwatch.StartNew(); // 创建并启动Stopwatch
  30062. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  30063. bool isDepStatus = await GeneralMethod.IsMarketingStaff(dto.CurrUserId);
  30064. List<Grp_DelegationInfo> groupInfos = new List<Grp_DelegationInfo>();
  30065. groupInfos = _sqlSugar.Queryable<Grp_DelegationInfo>()
  30066. .Where(it => it.IsDel == 0)
  30067. .WhereIF(isDepStatus, it => it.JietuanOperator == dto.CurrUserId)
  30068. .OrderByDescending(it => it.VisitStartDate)
  30069. .ToList();
  30070. if (groupInfos.Count < 1) return Ok(JsonView(false, "暂无和你相关的团组信息!"));
  30071. var country = groupInfos.Select(it => it.VisitCountry).ToList();
  30072. var diids = groupInfos.Select(it => it.Id).ToList();
  30073. List<string> countrys = new List<string>();
  30074. foreach (var item in country)
  30075. {
  30076. var data = _groupRepository.FormartTeamName(item);
  30077. var dataArray = _groupRepository.GroupSplitCountry(data);
  30078. if (dataArray.Count > 0) countrys.AddRange(dataArray);
  30079. }
  30080. countrys = countrys.Where(it => !string.IsNullOrEmpty(it)).Distinct().ToList();
  30081. List<string> areaArray = new List<string>(); //GetGroupCityLine
  30082. var areaItem = GeneralMethod.GetGroupCityLineItem(diids, "-");
  30083. foreach (var item in areaItem)
  30084. {
  30085. string areaStr = item.Value;
  30086. if (!string.IsNullOrEmpty(areaStr))
  30087. {
  30088. string[] str1 = areaStr.Split("-");
  30089. if (str1.Length > 0)
  30090. {
  30091. areaArray.AddRange(str1);
  30092. }
  30093. }
  30094. }
  30095. if (areaArray.Count > 0) areaArray = areaArray.Distinct().ToList();
  30096. var cityDatas = _sqlSugar.Queryable<Sys_Cities>()
  30097. .Where(it => it.IsDel == 0 && areaArray.Contains(it.Name_CN))
  30098. .Select(it => new { id = it.Id, parentId = it.CountriesId, name = it.Name_CN })
  30099. .ToList();
  30100. List<int> countriesIds = cityDatas.Select(it => it.parentId).ToList();
  30101. var countriesDatas = _sqlSugar.Queryable<Sys_Countries>()
  30102. .Where(it => countriesIds.Contains(it.Id))
  30103. .Select(it => new { it.Id, Name = it.Name_CN })
  30104. .ToList();
  30105. var teamNames = groupInfos.Where(it => !string.IsNullOrEmpty(it.TeamName))
  30106. .Select(it => it.TeamName).ToList();
  30107. stopwatch.Stop();
  30108. return Ok(JsonView(true, $"操作成功,耗时{stopwatch.ElapsedMilliseconds} ms", new { teamNames, countriesDatas, citiesDatas = cityDatas }));
  30109. }
  30110. ///// <summary>
  30111. ///// 匹配op行程单
  30112. ///// Init 查询区域数据
  30113. ///// </summary>
  30114. ///// <param name="dto">团组列表请求dto</param>
  30115. ///// <returns></returns>
  30116. //[HttpPost]
  30117. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30118. //public async Task<IActionResult> PostMateOpGroupCountryChangeData(MateOpGroupCountryChangeDataDto dto)
  30119. //{
  30120. // Stopwatch stopwatch = Stopwatch.StartNew(); // 创建并启动Stopwatch
  30121. // List<Sys_Cities> cityDatas = new List<Sys_Cities>();
  30122. // string countriesDataStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("CityDatas");//string 取
  30123. // if (string.IsNullOrEmpty(countriesDataStr))
  30124. // {
  30125. // cityDatas = await _sqlSugar.Queryable<Sys_Cities>().Where(it => it.IsDel == 0).ToListAsync();
  30126. // TimeSpan ts = DateTime.Now.AddHours(2).TimeOfDay; //设置redis 过期时间 2
  30127. // await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>("CountriesDatas", JsonConvert.SerializeObject(cityDatas), ts);//string 存
  30128. // }
  30129. // else
  30130. // {
  30131. // cityDatas = JsonConvert.DeserializeObject<List<Sys_Cities>>(countriesDataStr);
  30132. // }
  30133. // var provinceData = cityDatas.Where(it => it.CountriesId == dto.CountriesId && it.Level == 1).ToList();
  30134. // var citiesData = cityDatas.Where(it => it.CountriesId == dto.CountriesId && it.Level == 2).ToList();
  30135. // var countiesData = cityDatas.Where(it => it.CountriesId == dto.CountriesId && it.Level == 3).ToList();
  30136. // List<dynamic> childList = new List<dynamic>();
  30137. // int parentId = dto.CountriesId;
  30138. // if (provinceData.Count > 1)
  30139. // {
  30140. // foreach (var item1 in provinceData)
  30141. // {
  30142. // List<dynamic> childList1 = new List<dynamic>();
  30143. // var citiesData1 = citiesData.Where(it => it.ParentId == item1.Id).ToList();
  30144. // foreach (var item2 in citiesData1)
  30145. // {
  30146. // List<dynamic> childList2 = new List<dynamic>();
  30147. // var countiesData1 = countiesData.Where(it => it.ParentId == item2.Id).ToList();
  30148. // foreach (var item3 in countiesData1)
  30149. // {
  30150. // childList2.Add(new
  30151. // {
  30152. // id = item3.Id,
  30153. // parentId = item2.Id,
  30154. // level = "district",
  30155. // name = item3.Name_CN,
  30156. // });
  30157. // }
  30158. // childList1.Add(new
  30159. // {
  30160. // id = item2.Id,
  30161. // parentId = item1.Id,
  30162. // level = "city",
  30163. // name = item2.Name_CN,
  30164. // childList = childList2
  30165. // });
  30166. // }
  30167. // childList.Add(new
  30168. // {
  30169. // id = item1.Id,
  30170. // parentId = parentId,
  30171. // level = "province",
  30172. // name = item1.Name_CN,
  30173. // childList = childList1
  30174. // });
  30175. // }
  30176. // //城市
  30177. // var citiesData2 = citiesData.Where(it => it.ParentId == 0).ToList();
  30178. // foreach (var item2 in citiesData2)
  30179. // {
  30180. // List<dynamic> childList22 = new List<dynamic>();
  30181. // var countiesData1 = countiesData.Where(it => it.ParentId == item2.Id).ToList();
  30182. // foreach (var item3 in countiesData1)
  30183. // {
  30184. // childList22.Add(new
  30185. // {
  30186. // id = item3.Id,
  30187. // parentId = item2.Id,
  30188. // level = "district",
  30189. // name = item3.Name_CN,
  30190. // });
  30191. // }
  30192. // childList.Add(new
  30193. // {
  30194. // id = item2.Id,
  30195. // parentId = parentId,
  30196. // level = "city",
  30197. // name = item2.Name_CN,
  30198. // childList = childList22
  30199. // });
  30200. // }
  30201. // }
  30202. // else
  30203. // {
  30204. // foreach (var item2 in citiesData)
  30205. // {
  30206. // string cname = item2.Name_CN;
  30207. // List<dynamic> childList1 = new List<dynamic>();
  30208. // var countiesData1 = countiesData.Where(it => it.ParentId == item2.Id).ToList();
  30209. // foreach (var item3 in countiesData1)
  30210. // {
  30211. // childList1.Add(new
  30212. // {
  30213. // Id = item3.Id,
  30214. // parentId = item2.Id,
  30215. // level = "district",
  30216. // name = item3.Name_CN
  30217. // });
  30218. // }
  30219. // childList.Add(new
  30220. // {
  30221. // id = item2.Id,
  30222. // parentId = parentId,
  30223. // level = "city",
  30224. // name = item2.Name_CN,
  30225. // childList = childList1
  30226. // });
  30227. // }
  30228. // }
  30229. // stopwatch.Stop();
  30230. // return Ok(JsonView(true, $"操作成功,耗时{stopwatch.ElapsedMilliseconds} ms", childList));
  30231. //}
  30232. /// <summary>
  30233. /// 匹配op行程单
  30234. /// 接团信息列表 Page
  30235. /// </summary>
  30236. /// <param name="dto">团组列表请求dto</param>
  30237. /// <returns></returns>
  30238. [HttpPost]
  30239. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30240. public async Task<IActionResult> PostMateOpGroupPageList(MateOpGroupPageListDto dto)
  30241. {
  30242. var swatch = new Stopwatch();
  30243. swatch.Start();
  30244. #region 参数验证
  30245. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  30246. if (dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  30247. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  30248. #region 页面操作权限验证
  30249. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  30250. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  30251. #endregion
  30252. #endregion
  30253. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) // web/Android
  30254. {
  30255. var _view = await GeneralMethod.MateOpGroupPageListRedis();
  30256. //string sqlWhere = "";
  30257. if (!string.IsNullOrEmpty(dto.Country))
  30258. {
  30259. _view = _view.Where(x => !string.IsNullOrEmpty(x.VisitCountry) && x.VisitCountry.Contains(dto.Country)).ToList();
  30260. }
  30261. if (!string.IsNullOrEmpty(dto.Area))
  30262. {
  30263. _view = _view.Where(x => !string.IsNullOrEmpty(x.RouteCity) && x.RouteCity.Contains(dto.Area)).ToList();
  30264. }
  30265. if (!string.IsNullOrEmpty(dto.TeamName))
  30266. {
  30267. _view = _view.Where(x => !string.IsNullOrEmpty(x.TeamName) && x.TeamName.Contains(dto.TeamName)).ToList();
  30268. }
  30269. int startIndex = (dto.PageIndex - 1) * dto.PageSize; // 计算开始的索引
  30270. int endIndex = startIndex + dto.PageSize - 1; // 计算结束的索引
  30271. var _view1 = _view.Skip(startIndex).Take(endIndex).ToList();
  30272. swatch.Stop();
  30273. return Ok(JsonView(true, $"查询成功!耗时 {swatch.ElapsedMilliseconds} ms", _view1, _view.Count));
  30274. }
  30275. else
  30276. {
  30277. return Ok(JsonView(false, "查询失败"));
  30278. }
  30279. }
  30280. /// <summary>
  30281. /// 匹配op行程单
  30282. /// 行程单下载
  30283. /// </summary>
  30284. /// <param name="dto">团组列表请求dto</param>
  30285. /// <returns></returns>
  30286. [HttpPost]
  30287. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30288. public async Task<IActionResult> PostMateOpGroupDownload(MateOpGroupDownloadDto dto)
  30289. {
  30290. #region 参数验证
  30291. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  30292. if (dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  30293. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  30294. #region 页面操作权限验证
  30295. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  30296. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限"));
  30297. #endregion
  30298. #endregion
  30299. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) // web/Android
  30300. {
  30301. var res = ExportTravel(new ExportTravelDto() { Diid = dto.diId });
  30302. return Ok(res.GetType().GetProperty("Value").GetValue(res, null));
  30303. }
  30304. else
  30305. {
  30306. return Ok(JsonView(false, "下载失败!"));
  30307. }
  30308. }
  30309. #endregion
  30310. #region 国家信息 数据 注释
  30311. //[HttpPost]
  30312. //public async Task<IActionResult> LoadCitiesInitData(List<int> dto)
  30313. //{
  30314. // List<Grp_GroupsTaskAssignment> infos = new List<Grp_GroupsTaskAssignment>();
  30315. // foreach (var item in dto)
  30316. // {
  30317. // infos.Add(new Grp_GroupsTaskAssignment()
  30318. // {
  30319. // DIId = item,
  30320. // CTId = 82,
  30321. // UId = 248,
  30322. // IsEnable = 1,
  30323. // CreateUserId = 233,
  30324. // CreateTime = DateTime.Now,
  30325. // IsDel = 0
  30326. // });
  30327. // infos.Add(new Grp_GroupsTaskAssignment()
  30328. // {
  30329. // DIId = item,
  30330. // CTId = 82,
  30331. // UId = 286,
  30332. // IsEnable = 1,
  30333. // CreateUserId = 233,
  30334. // CreateTime = DateTime.Now,
  30335. // IsDel = 0
  30336. // });
  30337. // }
  30338. // int add = _sqlSugar.Insertable<Grp_GroupsTaskAssignment>(infos).ExecuteCommand();
  30339. // return Ok("操作成功");
  30340. //}
  30341. //public class paramJsonDto
  30342. //{
  30343. // public List<CountriesInfo> str { get; set; }
  30344. //}
  30345. //[HttpPost]
  30346. //public async Task<IActionResult> LoadCitiesInitData(paramJsonDto dto)
  30347. //{
  30348. // //List<CountriesInfo> infos = new List<CountriesInfo>();
  30349. // //infos = JsonConvert.DeserializeObject<List<CountriesInfo>>(dto.str);
  30350. // List<Sys_Cities> cities = new List<Sys_Cities>();
  30351. // List<Sys_Cities> districts = new List<Sys_Cities>();
  30352. // var counties = _sqlSugar.Queryable<Sys_Countries>().Where(it => it.IsDel == 0).ToList();
  30353. // _sqlSugar.BeginTran();
  30354. // int countitiesIndex = 0;
  30355. // foreach (var item in dto.str)
  30356. // {
  30357. // dynamic data = item.c;
  30358. // int countriesId = counties.Find(it => it.Name_CN.Equals(item.cn))?.Id ?? 0;
  30359. // if (data != null)
  30360. // {
  30361. // countitiesIndex++;
  30362. // foreach (var item1 in data)
  30363. // {
  30364. // string cnname = item1.cn;
  30365. // string enname = item1.en;
  30366. // Sys_Cities provinceInfo = new Sys_Cities()
  30367. // {
  30368. // CountriesId = countriesId,
  30369. // Name_CN = cnname,
  30370. // Name_EN = enname,
  30371. // ParentId = 0,
  30372. // IsCapital = 1,
  30373. // CreateUserId = 208,
  30374. // CreateTime = DateTime.Now,
  30375. // IsDel = 0
  30376. // };
  30377. // if (item1.lv == "province") //省份
  30378. // {
  30379. // provinceInfo.Level = 1;
  30380. // int provinceId = 0;
  30381. // var provinceInfo1 = _sqlSugar.Queryable<Sys_Cities>().Where(it => it.CountriesId == countriesId && it.Level == 1 && it.Name_CN.Equals(cnname)).First();
  30382. // if (provinceInfo1 != null) provinceId = provinceInfo1.Id;
  30383. // else provinceId = _sqlSugar.Insertable<Sys_Cities>(provinceInfo).ExecuteReturnIdentity();
  30384. // var data1 = item1.c;
  30385. // foreach (var item2 in data1)
  30386. // {
  30387. // if (item2.lv == "city")
  30388. // {
  30389. // string citycnname = item2.cn;
  30390. // string cityenname = item2.en;
  30391. // Sys_Cities cityInfo = new Sys_Cities()
  30392. // {
  30393. // CountriesId = countriesId,
  30394. // ParentId = provinceId,
  30395. // Level = 2,
  30396. // Name_CN = citycnname,
  30397. // Name_EN = cityenname,
  30398. // IsCapital = 1,
  30399. // CreateUserId = 208,
  30400. // CreateTime = DateTime.Now,
  30401. // IsDel = 0
  30402. // };
  30403. // if (item2.c != null)
  30404. // {
  30405. // int cityId = 0;
  30406. // var citiesInfo = _sqlSugar.Queryable<Sys_Cities>().Where(it => it.CountriesId == countriesId && it.Level == 2 && it.Name_CN.Equals(citycnname)).First();
  30407. // if (citiesInfo != null) cityId = citiesInfo.Id;
  30408. // else cityId = _sqlSugar.Insertable<Sys_Cities>(cityInfo).ExecuteReturnIdentity();
  30409. // foreach (var item3 in item2.c)
  30410. // {
  30411. // if (item3.lv == "district")
  30412. // {
  30413. // var districtInfo = new Sys_Cities()
  30414. // {
  30415. // CountriesId = countriesId,
  30416. // Name_CN = item3.cn,
  30417. // Name_EN = item3.en,
  30418. // Level = 3,
  30419. // ParentId = cityId,
  30420. // IsCapital = 1,
  30421. // CreateUserId = 208,
  30422. // CreateTime = DateTime.Now,
  30423. // IsDel = 0
  30424. // };
  30425. // //if (districts.Find(it => it.CountriesId == countriesId && it.ParentId == cityId && it.Name_CN.Equals(districtInfo.Name_CN)) == null)
  30426. // //{
  30427. // districts.Add(districtInfo);
  30428. // //}
  30429. // }
  30430. // }
  30431. // }
  30432. // else
  30433. // {
  30434. // //if (cities.Find(it => it.CountriesId == countriesId && it.ParentId == provinceId && it.Name_CN.Equals(citycnname)) == null)
  30435. // //{
  30436. // cities.Add(cityInfo);
  30437. // //}
  30438. // }
  30439. // }
  30440. // }
  30441. // }
  30442. // else if (item1.lv == "city")//城市
  30443. // {
  30444. // provinceInfo.Level = 2;
  30445. // if (item1.c != null)
  30446. // {
  30447. // int cityId = 0;
  30448. // var citiesInfo = _sqlSugar.Queryable<Sys_Cities>().Where(it => it.CountriesId == countriesId && it.Level == 1 && it.Name_CN.Equals(provinceInfo.Name_CN)).First();
  30449. // if (citiesInfo != null) cityId = citiesInfo.Id;
  30450. // else cityId = _sqlSugar.Insertable<Sys_Cities>(provinceInfo).ExecuteReturnIdentity();
  30451. // foreach (var item3 in item1.c)
  30452. // {
  30453. // if (item3.lv == "district")
  30454. // {
  30455. // var districtInfo = new Sys_Cities()
  30456. // {
  30457. // CountriesId = countriesId,
  30458. // Name_CN = item3.cn,
  30459. // Name_EN = item3.en,
  30460. // Level = 3,
  30461. // ParentId = cityId,
  30462. // IsCapital = 1,
  30463. // CreateUserId = 208,
  30464. // CreateTime = DateTime.Now,
  30465. // IsDel = 0
  30466. // };
  30467. // //if (districts.Find(it => it.CountriesId == countriesId && it.ParentId == cityId && it.Name_CN.Equals(districtInfo.Name_CN)) == null)
  30468. // //{
  30469. // districts.Add(districtInfo);
  30470. // //}
  30471. // }
  30472. // }
  30473. // }
  30474. // else
  30475. // {
  30476. // //if (cities.Find(it => it.CountriesId == countriesId && it.Name_CN.Equals(provinceInfo.Name_CN)) == null)
  30477. // //{
  30478. // cities.Add(provinceInfo);
  30479. // //}
  30480. // }
  30481. // }
  30482. // }
  30483. // }
  30484. // }
  30485. // var procinceDatas = _sqlSugar.Queryable<Sys_Cities>().ToList();
  30486. // cities = cities.Distinct().ToList();
  30487. // districts = districts.Distinct().ToList();
  30488. // var citiesDatas = cities.Where(it => it.Level == 2).ToList();
  30489. // //var districtDatas = cities.Where(it => it.Level == 3).ToList();
  30490. // cities.AddRange(districts);
  30491. // var citiesAdd = _sqlSugar.Insertable<Sys_Cities>(cities).ExecuteReturnIdentity();
  30492. // //_sqlSugar.RollbackTran();
  30493. // _sqlSugar.CommitTran();
  30494. // return Ok(JsonView(false, "操作成功!"));
  30495. //}
  30496. //[HttpPost]
  30497. //public async Task<IActionResult> LoadCitiesInitInfo(CounrtiesDto dto)
  30498. //{
  30499. // List<CountitiesInfo> infos = dto.MyProperty;
  30500. // List<Sys_Cities> cityInfos = new List<Sys_Cities>();
  30501. // _sqlSugar.BeginTran();
  30502. // var countities = _sqlSugar.Queryable<Sys_Countries>().Where(it => it.IsDel == 0).ToList();
  30503. // var citities = _sqlSugar.Queryable<Sys_Cities>().Where(it => it.IsDel == 0 && it.Level == 2).ToList();
  30504. // foreach (var item in infos)
  30505. // {
  30506. // var countryInfo = countities.Where(it => it.ThreeCode.Equals(item.country_code3)).FirstOrDefault();
  30507. // if (countryInfo != null)
  30508. // {
  30509. // var cityInfo = citities.Where(it => it.CountriesId == countryInfo.Id).ToList();
  30510. // var cityInfo1 = cityInfo.Where(it => item.capital_name_chinese.Contains(it.Name_CN)).FirstOrDefault();
  30511. // if (cityInfo1 != null)
  30512. // {
  30513. // cityInfo1.IsCapital = 0;
  30514. // cityInfos.Add(cityInfo1);
  30515. // }
  30516. // }
  30517. // }
  30518. // var update = _sqlSugar.Updateable<Sys_Cities>(cityInfos)
  30519. // .UpdateColumns(it => it.IsCapital)
  30520. // .WhereColumns(it => it.Id)
  30521. // .ExecuteCommand();
  30522. // //_sqlSugar.RollbackTran();
  30523. // _sqlSugar.CommitTran();
  30524. // return Ok(JsonView(false, "操作成功!"));
  30525. //}
  30526. //public class CounrtiesDto
  30527. //{
  30528. // public List<CountitiesInfo> MyProperty { get; set; }
  30529. //}
  30530. //public class CountitiesInfo
  30531. //{
  30532. // /// <summary>
  30533. // /// 圣约翰
  30534. // /// </summary>
  30535. // public string capital_name_chinese { get; set; }
  30536. // /// <summary>
  30537. // ///
  30538. // /// </summary>
  30539. // public string capital_name { get; set; }
  30540. // /// <summary>
  30541. // ///
  30542. // /// </summary>
  30543. // public string country_type { get; set; }
  30544. // /// <summary>
  30545. // /// 安提瓜和巴布达
  30546. // /// </summary>
  30547. // public string country_name_chinese { get; set; }
  30548. // /// <summary>
  30549. // /// 安提瓜和巴布达
  30550. // /// </summary>
  30551. // public string country_name_chinese_short { get; set; }
  30552. // /// <summary>
  30553. // /// 安提瓜和巴布达
  30554. // /// </summary>
  30555. // public string country_name_chinese_UN { get; set; }
  30556. // /// <summary>
  30557. // ///
  30558. // /// </summary>
  30559. // public string country_name_english_abbreviation { get; set; }
  30560. // /// <summary>
  30561. // ///
  30562. // /// </summary>
  30563. // public string country_name_english_formal { get; set; }
  30564. // /// <summary>
  30565. // ///
  30566. // /// </summary>
  30567. // public string country_name_english_UN { get; set; }
  30568. // /// <summary>
  30569. // ///
  30570. // /// </summary>
  30571. // public string continent_name { get; set; }
  30572. // /// <summary>
  30573. // ///
  30574. // /// </summary>
  30575. // public string subregion_name { get; set; }
  30576. // /// <summary>
  30577. // ///
  30578. // /// </summary>
  30579. // public string country_code2 { get; set; }
  30580. // /// <summary>
  30581. // ///
  30582. // /// </summary>
  30583. // public string country_code3 { get; set; }
  30584. // /// <summary>
  30585. // ///
  30586. // /// </summary>
  30587. // public string phone_code { get; set; }
  30588. //}
  30589. //public class CountriesInfo : BasicInfo
  30590. //{
  30591. // public List<CitiesInfo> c { get; set; }
  30592. //}
  30593. //public class CitiesInfo : BasicInfo
  30594. //{
  30595. // public List<AreaInfo> c { get; set; }
  30596. //}
  30597. //public class AreaInfo : BasicInfo
  30598. //{
  30599. // public List<AreaInfo> c { get; set; }
  30600. //}
  30601. //public class BasicInfo
  30602. //{
  30603. // public string code { get; set; }
  30604. // public string cn { get; set; }
  30605. // public string lv { get; set; }
  30606. // public string en { get; set; }
  30607. //}
  30608. #endregion
  30609. #region 查看邀请方
  30610. /// <summary>
  30611. /// 查看邀请方
  30612. /// 邀请方信息 Init
  30613. /// </summary>
  30614. /// <param name="dto"></param>
  30615. /// <returns></returns>
  30616. [HttpPost]
  30617. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30618. public async Task<IActionResult> PostGroupLinkInvitingUnitNameInit(GroupLinkInvitingUnitNameInitDto dto)
  30619. {
  30620. string sqlWhere = string.Empty;
  30621. if (!string.IsNullOrEmpty(dto.Search))
  30622. {
  30623. sqlWhere = string.Format($@" And UnitName Like '%{dto.Search}%'");
  30624. }
  30625. string sql = string.Format($@"Select
  30626. ROW_NUMBER() Over(Order By Id desc) As Row_Number,
  30627. Id,
  30628. UnitName
  30629. From Res_InvitationOfficialActivityData
  30630. Where IsDel = 0
  30631. And (UnitName != '' Or UnitName != null) {sqlWhere}");
  30632. RefAsync<int> total = 0;
  30633. var _views = await _sqlSugar.SqlQueryable<GroupLinkInvitingUnitNameInitView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  30634. return Ok(JsonView(true, MsgTips.Succeed, _views, total));
  30635. }
  30636. /// <summary>
  30637. /// 查看邀请方
  30638. /// 国家信息 Init
  30639. /// </summary>
  30640. /// <param name="dto"></param>
  30641. /// <returns></returns>
  30642. [HttpPost]
  30643. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30644. public async Task<IActionResult> PostGroupLinkInvitingCountryInit(GroupLinkInvitingUnitNameInitDto dto)
  30645. {
  30646. var groupInfos = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).OrderByDescending(it => it.CreateUserId).ToListAsync();
  30647. var country = groupInfos.Select(it => it.VisitCountry).ToList();
  30648. var diids = groupInfos.Select(it => it.Id).ToList();
  30649. List<string> countrys = new List<string>();
  30650. foreach (var item in country)
  30651. {
  30652. var data = _groupRepository.FormartTeamName(item);
  30653. var dataArray = _groupRepository.GroupSplitCountry(data);
  30654. if (dataArray.Count > 0) countrys.AddRange(dataArray);
  30655. }
  30656. countrys = countrys.Distinct().ToList();
  30657. for (int i = 0; i < countrys.Count; i++)
  30658. {
  30659. string item = countrys[i];
  30660. if (string.IsNullOrEmpty(item) || item.Contains("-"))
  30661. {
  30662. countrys.Remove(item);
  30663. i--;
  30664. }
  30665. }
  30666. RefAsync<int> total = 0;
  30667. var countyDatas = await _sqlSugar.Queryable<Sys_Countries>()
  30668. .Where(it => countrys.Contains(it.Name_CN))
  30669. .WhereIF(!string.IsNullOrEmpty(dto.Search), it => it.Name_CN.Contains(dto.Search))
  30670. .Select(it => new { id = it.Id, name = it.Name_CN })
  30671. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  30672. return Ok(JsonView(true, MsgTips.Succeed, countyDatas, total));
  30673. }
  30674. /// <summary>
  30675. /// 查看邀请方
  30676. /// 城市信息 Init
  30677. /// </summary>
  30678. /// <param name="dto"></param>
  30679. /// <returns></returns>
  30680. [HttpPost]
  30681. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30682. public async Task<IActionResult> PostGroupLinkInvitingCityInit(GroupLinkInvitingCityInitDto dto)
  30683. {
  30684. if (dto.CountiesId < 1) return Ok(JsonView(false, "请传入有效的国家Id"));
  30685. RefAsync<int> total = 0;
  30686. var countyDatas = await _sqlSugar.Queryable<Sys_Cities>()
  30687. .Where(it => it.CountriesId == dto.CountiesId)
  30688. .WhereIF(!string.IsNullOrEmpty(dto.Search), it => it.Name_CN.Contains(dto.Search))
  30689. .OrderBy(it => new { IsCapital = SqlFunc.Asc(it.IsCapital), Id = SqlFunc.Asc(it.Id) })
  30690. .Select(it => new { id = it.Id, name = it.Name_CN })
  30691. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  30692. return Ok(JsonView(true, MsgTips.Succeed, countyDatas, total));
  30693. }
  30694. /// <summary>
  30695. /// 查看邀请方
  30696. /// 团组名称 Init
  30697. /// </summary>
  30698. /// <param name="dto"></param>
  30699. /// <returns></returns>
  30700. [HttpPost]
  30701. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30702. public async Task<IActionResult> PostGroupLinkInvitingGroupInit(GroupLinkInvitingDto dto)
  30703. {
  30704. var watch = new Stopwatch();
  30705. watch.Start();
  30706. RefAsync<int> total = 0;
  30707. var countyDatas = await _sqlSugar.Queryable<Res_OfficialActivities>()
  30708. .InnerJoin<Grp_DelegationInfo>((oa, di) => oa.DiId == di.Id)
  30709. .Where((oa, di) => oa.IsDel == 0)
  30710. .WhereIF(!string.IsNullOrEmpty(dto.Search), (oa, di) => di.TeamName.Contains(dto.Search))
  30711. .OrderBy((oa, di) => new { id = SqlFunc.Desc(di.Id) })
  30712. .Select((oa, di) => new { id = di.Id, name = di.TeamName })
  30713. .Distinct()
  30714. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  30715. watch.Stop();
  30716. return Ok(JsonView(true, $"{MsgTips.Succeed},耗时 {watch.ElapsedMilliseconds} ms", countyDatas, total));
  30717. }
  30718. /// <summary>
  30719. /// 查看邀请方
  30720. /// 团组 & 邀请方信息
  30721. /// </summary>
  30722. /// <param name="dto"></param>
  30723. /// <returns></returns>
  30724. [HttpPost]
  30725. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30726. public async Task<IActionResult> PostGroupLinkInvitingPageList(GroupLinkInvitingPageListDto dto)
  30727. {
  30728. var watch = new Stopwatch();
  30729. watch.Start();
  30730. RefAsync<int> total = 0;
  30731. var infos = await _sqlSugar.Queryable<GroupLinkInvitingPageListView>()
  30732. .AS("Grp_DelegationInfo")
  30733. .Includes(x => x.InvitingInfos)
  30734. .Where(x => x.IsDel == 0 && x.InvitingInfos.Any(z => z.IsDel == 0))
  30735. .WhereIF(!string.IsNullOrEmpty(dto.Counrty), x => x.VisitCountry.Contains(dto.Counrty))
  30736. .WhereIF(!string.IsNullOrEmpty(dto.Area), x => x.InvitingInfos.Any(z => z.Area.Contains(dto.Area))) //
  30737. .WhereIF(!string.IsNullOrEmpty(dto.TeamName), x => x.TeamName.Contains(dto.TeamName)) //
  30738. .WhereIF(!string.IsNullOrEmpty(dto.UnitName), x => x.InvitingInfos.Any(z => z.Client.Contains(dto.UnitName)))
  30739. .OrderBy(x => new { JietuanTime = SqlFunc.Desc(x.VisitStartDate) })
  30740. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  30741. var userDatas = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToList();
  30742. var setDatas = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0).ToList();
  30743. infos.ForEach(x =>
  30744. {
  30745. x.TeamDid = setDatas.Find(y => int.Parse(x.TeamDid) == y.Id)?.Name ?? "-";
  30746. x.JietuanOperator = userDatas.Find(y => int.Parse(x.JietuanOperator) == y.Id)?.CnName ?? "-";
  30747. x.TeamLevSId = setDatas.Find(y => int.Parse(x.TeamLevSId) == y.Id)?.Name ?? "-";
  30748. x.InvitingInfos = x.InvitingInfos.Where(it => it.IsDel == 0).ToList();
  30749. });
  30750. watch.Stop();
  30751. return Ok(JsonView(true, $"{MsgTips.Succeed},耗时 {watch.ElapsedMilliseconds} ms", infos, total));
  30752. }
  30753. #endregion
  30754. #region 报批行程
  30755. /// <summary>
  30756. /// 报批行程初始化
  30757. /// </summary>
  30758. /// <param name="dto"></param>
  30759. /// <returns></returns>
  30760. [HttpPost]
  30761. public IActionResult ApprovalJourneyInit(ApprovalJourneyDto dto)
  30762. {
  30763. const int chiNumber = 5;
  30764. var jw = JsonView(false);
  30765. var groupList = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0).OrderByDescending(x => x.VisitStartDate).ToList();
  30766. var group = groupList.First();
  30767. var diid = dto.Diid == -1 ? group?.Id : dto.Diid;
  30768. group = groupList.First(x => x.Id == diid);
  30769. var blackCodeList = _sqlSugar.Queryable<Air_TicketBlackCode>()
  30770. .Where(x => x.DiId == diid && x.IsDel == 0)
  30771. .ToArray();
  30772. var count = 1;
  30773. foreach (var item in blackCodeList)
  30774. {
  30775. if (string.IsNullOrWhiteSpace(item.Title))
  30776. {
  30777. item.Title = "未设置名称数据" + count;
  30778. }
  30779. count++;
  30780. }
  30781. ;
  30782. if (group == null)
  30783. {
  30784. jw.Msg = "暂无团组!";
  30785. return Ok(jw);
  30786. }
  30787. var data = new
  30788. {
  30789. groupList = groupList.Select(x => new
  30790. {
  30791. x.TeamName,
  30792. x.Id
  30793. }),
  30794. content = new ArrayList(),
  30795. groupInfo = new
  30796. {
  30797. group.VisitDays,
  30798. group.TourCode,
  30799. group.VisitPNumber,
  30800. group.TeamName,
  30801. group.Id,
  30802. visitStartDate = group.VisitStartDate.ToString("yyyy-MM-dd"),
  30803. visitEndDate = group.VisitEndDate.ToString("yyyy-MM-dd"),
  30804. group.ClientUnit
  30805. },
  30806. blackCodeList = blackCodeList.Select(x => new
  30807. {
  30808. x.Title,
  30809. x.Id
  30810. }),
  30811. FileTempList = new ArrayList()
  30812. {
  30813. new { Index = 1,FileName = "旧模板" },
  30814. new { Index = 2,FileName = "省外办" },
  30815. new { Index = 3,FileName = "市外办" },
  30816. }
  30817. };
  30818. var resultArr = new ArrayList();
  30819. var content = _sqlSugar.Queryable<Grp_ApprovalTravel>().Where(x => x.Diid == diid && x.IsDel == 0).ToList();
  30820. #region 默认不生成行程
  30821. //if (content.Count == 0)
  30822. //{
  30823. // var stay = "-";
  30824. // var cityPath = "-";
  30825. // var blackCodeList = _sqlSugar.Queryable<Air_TicketBlackCode>()
  30826. // .Where(x => x.DiId == diid && x.IsDel == 0)
  30827. // .ToList();
  30828. // //添加城市路径以及住宿地
  30829. // //黑屏代码数据
  30830. // DataTable dtBlack = GeneralMethod.GetTableByBlackCodeById(blackCodeList.FirstOrDefault());
  30831. // if (dtBlack.Rows.Count == 0 || string.IsNullOrWhiteSpace(dtBlack.Rows[0][1].ToString()))
  30832. // {
  30833. // jw = JsonView(true, "黑屏代码有误!", data);
  30834. // return Ok(jw);
  30835. // }
  30836. // data = data with
  30837. // {
  30838. // blackCodeList = new ArrayList(blackCodeList.Select(x => new
  30839. // {
  30840. // x.Title,
  30841. // x.Id,
  30842. // }).ToArray())
  30843. // };
  30844. // foreach (DataRow row in dtBlack.Rows)
  30845. // {
  30846. // if (!string.IsNullOrWhiteSpace(row["Error"].ToString()))
  30847. // {
  30848. // jw = JsonView(true, "黑屏代码有误!" + row["Error"].ToString(), data);
  30849. // return Ok(jw);
  30850. // }
  30851. // }
  30852. // //黑屏代码获取时间区间
  30853. // var timeArr = GeneralMethod.GetTimeListByDataTable(dtBlack);
  30854. // string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  30855. // _sqlSugar.BeginTran();
  30856. // for (int i = 0; i < timeArr.Count; i++)
  30857. // {
  30858. // stay = "-";
  30859. // cityPath = "-";
  30860. // DateTime NewData = DateTime.Parse(timeArr[i]);
  30861. // string week = Day[Convert.ToInt32(NewData.DayOfWeek.ToString("d"))].ToString();
  30862. // Grp_ApprovalTravel appro = new Grp_ApprovalTravel();
  30863. // var tbSelect = dtBlack.Select(string.Format("Day = '{0}'", NewData.ToString("yyyy-MM-dd")));
  30864. // if (tbSelect.Length > 0)
  30865. // {
  30866. // List<string> threeCodeStr = new List<string>();
  30867. // foreach (var item in tbSelect)
  30868. // {
  30869. // var threeCode = item["Three"].ToString() ?? "";
  30870. // if (threeCode.Length == 6)
  30871. // {
  30872. // var start = threeCode.Substring(0, 3);
  30873. // var end = threeCode.Substring(3, 3);
  30874. // if (threeCodeStr.Count == 0)
  30875. // {
  30876. // threeCodeStr.Add(start);
  30877. // threeCodeStr.Add(end);
  30878. // }
  30879. // else
  30880. // {
  30881. // if (threeCodeStr[threeCodeStr.Count - 1] == start)
  30882. // {
  30883. // threeCodeStr.Add(end);
  30884. // }
  30885. // else
  30886. // {
  30887. // threeCodeStr.Add(start);
  30888. // threeCodeStr.Add(end);
  30889. // }
  30890. // }
  30891. // }
  30892. // }
  30893. // var threeCodeList = _threeCodeRepository.QueryThreeCodeArray(threeCodeStr);
  30894. // var last = threeCodeStr.Last();
  30895. // foreach (var item in threeCodeStr)
  30896. // {
  30897. // cityPath += (threeCodeList.Keys.Contains(item) ? threeCodeList[item].City : "【未知三字码】") + "-";
  30898. // if (item.Equals(last))
  30899. // {
  30900. // stay = threeCodeList.Keys.Contains(item) ? threeCodeList[item].City : "【未知三字码】";
  30901. // }
  30902. // }
  30903. // cityPath = cityPath.Trim('-');
  30904. // }
  30905. // appro.Date = "第" + intToString(i + 1) + "天 " + NewData.Month + "月" + NewData.Day + "日(" + week + ") " + cityPath + " 宿:" + stay;
  30906. // appro.Diid = diid ?? -1;
  30907. // var thisId = _sqlSugar.Insertable<Grp_ApprovalTravel>(appro).ExecuteReturnIdentity();
  30908. // appro.Id = thisId;
  30909. // appro.CreateUserId = dto.UserId;
  30910. // appro.CreateTime = DateTime.Now;
  30911. // content.Add(appro);
  30912. // }
  30913. // _sqlSugar.CommitTran();
  30914. //}
  30915. #endregion
  30916. foreach (var x in content)
  30917. {
  30918. var chiList = _sqlSugar.Queryable<Grp_ApprovalTravelDetails>().Where(x1 => x1.ParentId == x.Id && x1.IsDel == 0).ToList();
  30919. if (chiList.Count < chiNumber)
  30920. {
  30921. for (int i = chiList.Count; i < chiNumber; i++)
  30922. {
  30923. chiList.Add(new Grp_ApprovalTravelDetails());
  30924. }
  30925. }
  30926. resultArr.Add(new
  30927. {
  30928. x.Id,
  30929. x.Date,
  30930. x.Diid,
  30931. chiList = chiList.Select(x1 => new
  30932. {
  30933. timeInterval = string.IsNullOrWhiteSpace(x1.Time) ? new string[1] : x1.Time.Split('-'),
  30934. x1.Details,
  30935. x1.ParentId,
  30936. x1.Id
  30937. })
  30938. });
  30939. }
  30940. data = data with
  30941. {
  30942. content = resultArr,
  30943. };
  30944. jw = JsonView(true, "获取成功!", data);
  30945. return Ok(jw);
  30946. }
  30947. /// <summary>
  30948. /// 报批行程删除
  30949. /// </summary>
  30950. /// <param name="dto"></param>
  30951. /// <returns></returns>
  30952. [HttpPost]
  30953. public IActionResult DeleteApprovalJourney(DeleteApprovalJourney dto)
  30954. {
  30955. var jw = JsonView(false);
  30956. var group = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  30957. if (group == null)
  30958. {
  30959. jw.Msg = "团组参数有误!";
  30960. return Ok(jw);
  30961. }
  30962. try
  30963. {
  30964. _sqlSugar.BeginTran();
  30965. var arr = _sqlSugar.Queryable<Grp_ApprovalTravel>().Where(x => x.Diid == dto.Diid && x.IsDel == 0).Select(x => x.Id).ToList();
  30966. _ = _sqlSugar.Updateable<Grp_ApprovalTravelDetails>().SetColumns(x => new Grp_ApprovalTravelDetails
  30967. {
  30968. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  30969. DeleteUserId = dto.uesrId,
  30970. IsDel = 1
  30971. }).Where(x => arr.Contains(x.ParentId) && x.IsDel == 0).ExecuteCommand();
  30972. _ = _sqlSugar.Updateable<Grp_ApprovalTravel>().SetColumns(x => new Grp_ApprovalTravel
  30973. {
  30974. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  30975. DeleteUserId = dto.uesrId,
  30976. IsDel = 1
  30977. }).Where(x => arr.Contains(x.Id)).ExecuteCommand();
  30978. _sqlSugar.CommitTran();
  30979. jw = JsonView(true, "删除成功");
  30980. }
  30981. catch (Exception ex)
  30982. {
  30983. jw = JsonView(false, ex.Message);
  30984. }
  30985. return Ok(jw);
  30986. }
  30987. /// <summary>
  30988. /// 报批行程保存
  30989. /// </summary>
  30990. /// <param name="dto"></param>
  30991. /// <returns></returns>
  30992. [HttpPost]
  30993. public IActionResult SaveApprovalJourney(SaveApprovalJourney dto)
  30994. {
  30995. var jw = JsonView(false);
  30996. var Find = dto.Arr.Find(x => x.id == 0);
  30997. if (Find != null)
  30998. {
  30999. jw.Msg = "生成的ID为0!";
  31000. return Ok(jw);
  31001. }
  31002. foreach (var item in dto.Arr)
  31003. {
  31004. foreach (var chi in item.chiList)
  31005. {
  31006. if (chi.parentId == 0)
  31007. {
  31008. chi.parentId = item.id;
  31009. }
  31010. }
  31011. }
  31012. var chiArr = dto.Arr.SelectMany(x => x.chiList).ToList();
  31013. _sqlSugar.BeginTran();
  31014. if (chiArr.Where(x => x.id == 0).Count() == chiArr.Count)
  31015. {
  31016. var parentIds = dto.Arr.Select(x => x.id).ToList();
  31017. _sqlSugar.Updateable<Grp_ApprovalTravelDetails>().Where(x => parentIds.Contains(x.ParentId) && x.IsDel == 0).SetColumns(x => new Grp_ApprovalTravelDetails
  31018. {
  31019. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  31020. DeleteUserId = dto.UserId,
  31021. IsDel = 1
  31022. }).ExecuteCommand();
  31023. }
  31024. try
  31025. {
  31026. _ = _sqlSugar.Insertable<Grp_ApprovalTravelDetails>(chiArr.Where(x => x.id == 0).Select(x => new Grp_ApprovalTravelDetails
  31027. {
  31028. CreateTime = DateTime.Now,
  31029. CreateUserId = dto.UserId,
  31030. Details = x.details,
  31031. ParentId = x.parentId,
  31032. Time = x.timeInterval.Where(x => !string.IsNullOrWhiteSpace(x)).Count() > 1 ? x.timeInterval[0] + "-" + x.timeInterval[1] : "",
  31033. Remark = "",
  31034. IsDel = 0
  31035. }).ToList()).ExecuteCommand();
  31036. _ = _sqlSugar.Updateable<Grp_ApprovalTravelDetails>(chiArr.Where(x => x.id != 0).Select(x => new Grp_ApprovalTravelDetails
  31037. {
  31038. Id = x.id,
  31039. Details = x.details,
  31040. ParentId = x.parentId,
  31041. Time = x.timeInterval.Where(x => !string.IsNullOrWhiteSpace(x)).Count() > 1 ? x.timeInterval[0] + "-" + x.timeInterval[1] : "",
  31042. }).ToList()).UpdateColumns(x => new Grp_ApprovalTravelDetails
  31043. {
  31044. Details = x.Details,
  31045. ParentId = x.ParentId,
  31046. Time = x.Time
  31047. }).ExecuteCommand();
  31048. _ = _sqlSugar.Updateable<Grp_ApprovalTravel>(dto.Arr.Where(x => x.id != 0).Select(x => new Grp_ApprovalTravel
  31049. {
  31050. Id = x.id,
  31051. Date = x.date,
  31052. }).ToList()).UpdateColumns(x => new Grp_ApprovalTravel
  31053. {
  31054. Date = x.Date
  31055. }).ExecuteCommand();
  31056. _sqlSugar.CommitTran();
  31057. jw = JsonView(true, "保存成功!");
  31058. }
  31059. catch (Exception ex)
  31060. {
  31061. _sqlSugar.RollbackTran();
  31062. jw = JsonView(false, "保存失败!" + ex.Message);
  31063. }
  31064. return Ok(jw);
  31065. }
  31066. /// <summary>
  31067. /// 报批行程生成
  31068. /// </summary>
  31069. /// <param name="dto"></param>
  31070. /// <returns></returns>
  31071. [HttpPost]
  31072. public IActionResult CreateApprovalJourney(CreateApprovalJourneyDto dto)
  31073. {
  31074. var jw = JsonView(false);
  31075. var group = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  31076. if (group == null)
  31077. {
  31078. jw.Msg = "暂无该团组!";
  31079. return Ok(jw);
  31080. }
  31081. var blackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().First(x => x.Id == dto.BlackCodeId && x.IsDel == 0);
  31082. //黑屏代码数据
  31083. DataTable dtBlack = GeneralMethod.GetTableByBlackCodeBySingle(blackCode);
  31084. if (dtBlack.Rows.Count == 0 || string.IsNullOrWhiteSpace(dtBlack.Rows[0][1].ToString()))
  31085. {
  31086. jw.Msg = "黑屏代码有误!";
  31087. return Ok(jw);
  31088. }
  31089. foreach (DataRow row in dtBlack.Rows)
  31090. {
  31091. if (!string.IsNullOrWhiteSpace(row["Error"].ToString()))
  31092. {
  31093. jw.Msg = "黑屏代码有误!" + row["Error"].ToString();
  31094. return Ok(jw);
  31095. }
  31096. }
  31097. //var officialActivitiesArr = _sqlSugar.Queryable<Res_OfficialActivities>().Where(x => x.DiId == dto.Diid && x.IsDel == 0).ToList();
  31098. var resultArr = new ArrayList();
  31099. //if (officialActivitiesArr.Count == 0)
  31100. //{
  31101. // jw.Msg = "暂无公务出访信息!";
  31102. // return Ok(jw);
  31103. //}
  31104. try
  31105. {
  31106. _sqlSugar.BeginTran();
  31107. DeleteApprovalJourney(new
  31108. Domain.Dtos.Groups.DeleteApprovalJourney
  31109. {
  31110. Diid = dto.Diid,
  31111. uesrId = dto.Userid
  31112. });
  31113. var stay = "-";
  31114. var cityPath = "-";
  31115. var arriveCountry = string.Empty;
  31116. //添加城市路径以及住宿地
  31117. //黑屏代码获取时间区间
  31118. var timeArr = GeneralMethod.GetTimeListByDataTable(dtBlack);
  31119. var empty = "【未收入该三字码!请机票同事录入】";
  31120. string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  31121. #region 配置公务活动时间
  31122. List<Tuple<int, string, string>> Times = new List<Tuple<int, string, string>>();
  31123. Times.Add(new Tuple<int, string, string>(9, "9:00", "10:30"));
  31124. Times.Add(new Tuple<int, string, string>(11, "11:00", "12:00"));
  31125. Times.Add(new Tuple<int, string, string>(14, "14:00", "15:30"));
  31126. Times.Add(new Tuple<int, string, string>(16, "16:00", "17:00"));
  31127. List<Tuple<DateTime, List<string>>> fallTimesCheckCountry = new List<Tuple<DateTime, List<string>>>()
  31128. {
  31129. 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" }),
  31130. 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"}),
  31131. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,11,30,0), new List<string>{"14:00-15:30","16:00-17:00"}),
  31132. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,13,30,0), new List<string>{"16:30-17:30"}),
  31133. };
  31134. List<Tuple<DateTime, List<string>>> fallTimesNotCheckCountry = new List<Tuple<DateTime, List<string>>>()
  31135. {
  31136. 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" }),
  31137. 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"}),
  31138. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,11,30,0), new List<string>{"14:00-15:30","16:00-17:00"}),
  31139. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,14,30,0), new List<string>{"16:30-17:30"}),
  31140. };
  31141. List<Tuple<DateTime, List<string>>> takeoffTimes = new List<Tuple<DateTime, List<string>>>()
  31142. {
  31143. 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" }),
  31144. 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"}),
  31145. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,14,00,0), new List<string>{"9:00-10:30", "11:00-12:00",}),
  31146. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,12,00,0), new List<string>{"09:00-10:00"}),
  31147. };
  31148. #endregion
  31149. var nextDayNum = 0;
  31150. for (int i = 0; i < timeArr.Count; i++)
  31151. {
  31152. stay = "-";
  31153. cityPath = "-";
  31154. var chiarr = new List<Grp_ApprovalTravelDetails>();
  31155. DateTime NewData = DateTime.Parse(timeArr[i]);
  31156. //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();
  31157. var tbSelect = dtBlack.Select(string.Format("Day = '{0}'", NewData.ToString("yyyy-MM-dd")));
  31158. if (nextDayNum > 0)
  31159. {
  31160. nextDayNum--;
  31161. }
  31162. if (tbSelect.Length > 0)
  31163. {
  31164. List<string> threeCodeStr = new List<string>();
  31165. bool isTrade = false;
  31166. string trip = string.Empty;
  31167. foreach (var item in tbSelect)
  31168. {
  31169. if (nextDayNum == 0)
  31170. {
  31171. nextDayNum = Convert.ToInt32(item["Sign"]);
  31172. }
  31173. var airStartTime = item["StartTime"].ToString() ?? "0000";
  31174. var airEndTime = item["EndTime"].ToString() ?? "0000";
  31175. var takeOffTime = DateTime.Parse(timeArr[i]);
  31176. var fallToTime = DateTime.Parse(timeArr[i]);
  31177. takeOffTime = takeOffTime.AddHours(int.Parse(airStartTime.Substring(0, 2)));
  31178. takeOffTime = takeOffTime.AddMinutes(int.Parse(airStartTime.Substring(2, 2)));
  31179. fallToTime = fallToTime.AddHours(int.Parse(airEndTime.Substring(0, 2)));
  31180. fallToTime = fallToTime.AddMinutes(int.Parse(airEndTime.Substring(2, 2)));
  31181. if (nextDayNum > 0)
  31182. {
  31183. fallToTime = fallToTime.AddDays(nextDayNum);
  31184. }
  31185. trip = string.Empty;
  31186. var start = string.Empty;
  31187. var end = string.Empty;
  31188. var threeCode = item["Three"].ToString() ?? "";
  31189. if (threeCode.Length == 6)
  31190. {
  31191. start = threeCode.Substring(0, 3);
  31192. end = threeCode.Substring(3, 3);
  31193. if (threeCodeStr.Count == 0)
  31194. {
  31195. threeCodeStr.Add(start);
  31196. threeCodeStr.Add(end);
  31197. }
  31198. else
  31199. {
  31200. if (threeCodeStr[threeCodeStr.Count - 1] == start)
  31201. {
  31202. threeCodeStr.Add(end);
  31203. }
  31204. else
  31205. {
  31206. threeCodeStr.Add(start);
  31207. threeCodeStr.Add(end);
  31208. }
  31209. }
  31210. }
  31211. //处理机票信息
  31212. var start_Object = _sqlSugar.Queryable<Res_ThreeCode>().First(x => x.Three.ToUpper() == start.ToUpper());
  31213. var end_Object = _sqlSugar.Queryable<Res_ThreeCode>().First(x => x.Three.ToUpper() == end.ToUpper());
  31214. if (start_Object == null)
  31215. {
  31216. start_Object = new Res_ThreeCode()
  31217. {
  31218. AirPort = empty,
  31219. AirPort_En = empty,
  31220. City = empty,
  31221. Country = empty,
  31222. Four = empty,
  31223. Three = empty,
  31224. };
  31225. }
  31226. if (end_Object == null)
  31227. {
  31228. end_Object = new Res_ThreeCode()
  31229. {
  31230. AirPort = empty,
  31231. AirPort_En = empty,
  31232. City = empty,
  31233. Country = empty,
  31234. Four = empty,
  31235. Three = empty,
  31236. };
  31237. }
  31238. //机型判断
  31239. string airModel = item["AirModel"].ToString();
  31240. airModel = GeneralMethod.GetLonger(airModel!.Substring(0, 1)) + airModel;
  31241. string flightTime = item["FlightTime"].ToString();
  31242. flightTime = ParseBlackTime(flightTime);
  31243. //航班号
  31244. string flightcode = item["Fliagtcode"].ToString();
  31245. var aircompany = _sqlSugar.Queryable<Res_AirCompany>().First(x => x.ShortCode.ToUpper() == flightcode!.Substring(0, 2).ToUpper() && x.IsDel == 0);
  31246. var hsEmpty = "【此航司" + flightcode!.Substring(0, 2).ToUpper() + "未收录,请机票同事录入】";
  31247. if (aircompany == null)
  31248. {
  31249. aircompany = new Res_AirCompany
  31250. {
  31251. CnName = hsEmpty,
  31252. EnName = hsEmpty,
  31253. ShortCode = hsEmpty,
  31254. };
  31255. }
  31256. //航班前公务安排
  31257. if (tbSelect.First().Equals(item) && i != 0)
  31258. {
  31259. foreach (var takeoff in takeoffTimes)
  31260. {
  31261. var takeoffItem1 = NewData.AddHours(takeoff.Item1.Hour).AddMinutes(takeoff.Item1.Minute);
  31262. if (DateTime.Compare(takeOffTime, takeoffItem1) > 0)
  31263. {
  31264. foreach (var addTime in takeoff.Item2)
  31265. {
  31266. chiarr.Add(new Grp_ApprovalTravelDetails
  31267. {
  31268. Time = addTime,
  31269. CreateTime = DateTime.Now,
  31270. CreateUserId = dto.Userid,
  31271. ParentId = 0,
  31272. Details = "公务活动"
  31273. });
  31274. }
  31275. break;
  31276. }
  31277. }
  31278. }
  31279. //从成都天府国际机场搭乘四川航空公司3U3961飞往东京
  31280. //trip += $"从{start_Object.AirPort}搭乘{aircompany.CnName}{flightcode}飞往{end_Object.City}。\r\n({start_Object.AirPort}/{end_Object.AirPort} 机型:{airModel} 飞行时间{flightTime});\r\n";
  31281. //乘坐四川航空3U3901次航班由成都飞往加德满都,3小时25分钟
  31282. trip += $"乘坐{aircompany.CnName}{flightcode}次航班由{start_Object.City}飞往{end_Object.City},{flightTime}";
  31283. isTrade = Convert.ToBoolean(item["isTransitShipment"]);
  31284. if (isTrade)
  31285. {
  31286. //trip += $"抵达{end_Object.AirPort}{item["EndBuilding"].ToString().Trim()}航站楼(中转 行李直达)\r\n";
  31287. trip += "(转机不出机场)。";
  31288. }
  31289. //else
  31290. //{
  31291. // trip += "\r\n"; //$"抵达{end_Object.AirPort}{item["EndBuilding"].ToString().Trim()}航站楼,办理入境手续,之后前往提取行李\r\n";
  31292. //}
  31293. chiarr.Add(new Grp_ApprovalTravelDetails
  31294. {
  31295. Time = takeOffTime.ToString("HH:mm") + "-" + fallToTime.ToString("HH:mm"),
  31296. CreateTime = DateTime.Now,
  31297. CreateUserId = dto.Userid,
  31298. ParentId = 0,
  31299. Details = trip
  31300. });
  31301. //最后一条到达的时间安排公务
  31302. if (tbSelect.Last().Equals(item) && i != timeArr.Count - 1)
  31303. {
  31304. bool isCheckCountry = false;
  31305. if (end_Object.Country != arriveCountry)
  31306. {
  31307. arriveCountry = end_Object.Country;
  31308. isCheckCountry = true;
  31309. }
  31310. if (nextDayNum == 0)
  31311. {
  31312. //需要入境的情况
  31313. if (isCheckCountry)
  31314. {
  31315. foreach (var fallTime in fallTimesCheckCountry)
  31316. {
  31317. var fallTimeItem1 = NewData.AddHours(fallTime.Item1.Hour).AddMinutes(fallTime.Item1.Minute);
  31318. if (DateTime.Compare(fallToTime, fallTimeItem1) < 0)
  31319. {
  31320. foreach (var addTime in fallTime.Item2)
  31321. {
  31322. chiarr.Add(new Grp_ApprovalTravelDetails
  31323. {
  31324. Time = addTime,
  31325. CreateTime = DateTime.Now,
  31326. CreateUserId = dto.Userid,
  31327. ParentId = 0,
  31328. Details = "公务活动"
  31329. });
  31330. }
  31331. break;
  31332. }
  31333. }
  31334. }
  31335. else
  31336. {
  31337. foreach (var fallTime in fallTimesNotCheckCountry)
  31338. {
  31339. var fallTimeItem1 = NewData.AddHours(fallTime.Item1.Hour).AddMinutes(fallTime.Item1.Minute);
  31340. if (DateTime.Compare(fallToTime, fallTimeItem1) < 0)
  31341. {
  31342. foreach (var addTime in fallTime.Item2)
  31343. {
  31344. chiarr.Add(new Grp_ApprovalTravelDetails
  31345. {
  31346. Time = addTime,
  31347. CreateTime = DateTime.Now,
  31348. CreateUserId = dto.Userid,
  31349. ParentId = 0,
  31350. Details = "公务活动"
  31351. });
  31352. }
  31353. break;
  31354. }
  31355. }
  31356. }
  31357. }
  31358. }
  31359. }
  31360. //添加乘车语句
  31361. //chiarr.Add(new Grp_ApprovalTravelDetails
  31362. //{
  31363. // Time = (fallToTime.AddHours(2.5).ToString("HH:mm") + "-" + fallToTime.AddHours(3).ToString("HH:mm")),
  31364. // CreateTime = DateTime.Now,
  31365. // CreateUserId = dto.Userid,
  31366. // ParentId = 0,
  31367. // Details = "乘车前往市区(约xx公里,大约需要xx分钟)"
  31368. //});
  31369. //if (i != timeArr.Count - 1)
  31370. //{
  31371. // fallToTime = fallToTime.AddHours(2.5);
  31372. // foreach (var item in Times)
  31373. // {
  31374. // //排列公务时间
  31375. // if (fallToTime.Hour < item.Item1)
  31376. // {
  31377. // chiarr.Add(new Grp_ApprovalTravelDetails
  31378. // {
  31379. // Time = $"{item.Item2} - {item.Item3}",
  31380. // CreateTime = DateTime.Now,
  31381. // CreateUserId = dto.Userid,
  31382. // ParentId = 0,
  31383. // Details = "公务活动"
  31384. // });
  31385. // }
  31386. // }
  31387. //}
  31388. var threeCodeList = _threeCodeRepository.QueryThreeCodeArray(threeCodeStr);
  31389. var last = threeCodeStr.Last();
  31390. foreach (var item in threeCodeStr)
  31391. {
  31392. cityPath += (threeCodeList.Keys.Contains(item) ? threeCodeList[item].City : "【未知三字码】") + "-";
  31393. if (item.Equals(last))
  31394. {
  31395. stay = threeCodeList.Keys.Contains(item) ? threeCodeList[item].City : "【未知三字码】";
  31396. }
  31397. }
  31398. cityPath = cityPath.Trim('-');
  31399. }
  31400. else
  31401. {
  31402. foreach (var item in Times)
  31403. {
  31404. chiarr.Add(new Grp_ApprovalTravelDetails
  31405. {
  31406. Time = $"{item.Item2} - {item.Item3}",
  31407. CreateTime = DateTime.Now,
  31408. CreateUserId = dto.Userid,
  31409. ParentId = 0,
  31410. Details = "公务活动"
  31411. });
  31412. }
  31413. }
  31414. string week = Day[Convert.ToInt32(NewData.DayOfWeek.ToString("d"))].ToString();
  31415. Grp_ApprovalTravel appro = new Grp_ApprovalTravel();
  31416. appro.Date = NewData.Month + "月" + NewData.Day + "日(" + week + ")" + "第" + intToString(i + 1) + "天 ";
  31417. appro.Diid = dto.Diid;
  31418. appro.CreateUserId = dto.Userid;
  31419. appro.CreateTime = DateTime.Now;
  31420. var thisId = _sqlSugar.Insertable<Grp_ApprovalTravel>(appro).ExecuteReturnIdentity();
  31421. appro.Id = thisId;
  31422. //foreach (var item in gwinfo)
  31423. //{
  31424. // Grp_ApprovalTravelDetails chi = new Grp_ApprovalTravelDetails();
  31425. // chi.Details = "拜访" + item.Client;
  31426. // if (!string.IsNullOrWhiteSpace(item.ReqSample))
  31427. // {
  31428. // chi.Details += "," + item.ReqSample;
  31429. // }
  31430. // chi.ParentId = thisId;
  31431. // chi.Time = item.Time;
  31432. // chiarr.Add(chi);
  31433. //}
  31434. if (chiarr.Count < 6)
  31435. {
  31436. for (int j = chiarr.Count; j < 6; j++)
  31437. {
  31438. chiarr.Add(new
  31439. Grp_ApprovalTravelDetails());
  31440. }
  31441. }
  31442. resultArr.Add(new
  31443. {
  31444. appro.Id,
  31445. appro.Date,
  31446. appro.Diid,
  31447. chiList = chiarr.Select(x1 => new
  31448. {
  31449. timeInterval = string.IsNullOrWhiteSpace(x1.Time) ? new string[1] : x1.Time.Split('-'),
  31450. x1.Details,
  31451. x1.ParentId,
  31452. x1.Id
  31453. })
  31454. });
  31455. }
  31456. _sqlSugar.CommitTran();
  31457. jw = JsonView(true, "生成成功!", resultArr);
  31458. }
  31459. catch (Exception ex)
  31460. {
  31461. jw.Code = 400;
  31462. jw.Msg = "生成失败!" + ex.Message;
  31463. }
  31464. return Ok(jw);
  31465. }
  31466. /// <summary>
  31467. /// 报批行程word导出
  31468. /// </summary>
  31469. /// <param name="dto"></param>
  31470. /// <returns></returns>
  31471. [HttpPost]
  31472. public IActionResult ExportApprovalJourneyWord(ExportApprovalJourneyWord dto)
  31473. {
  31474. var jw = JsonView(false);
  31475. var group = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  31476. if (group == null)
  31477. {
  31478. jw.Msg = "暂无该团组!";
  31479. return Ok(jw);
  31480. }
  31481. //模板路径
  31482. string tempPath = AppSettingsHelper.Get("WordBasePath") + "Template/";
  31483. var fileName = string.Empty;
  31484. string titleFont = string.Empty, timeFont = string.Empty, contentFont = string.Empty;
  31485. bool bold = false;
  31486. if (dto.FileIndex == 1)
  31487. {
  31488. fileName = "公务行程导出模板.docx"; //"C:\\Server\\File\\OA2023\\Office\\Word\\Template/公务行程导出模板.docx"
  31489. }
  31490. else if (dto.FileIndex == 2)
  31491. {
  31492. fileName = "省外办-报批.docx";
  31493. bold = false;
  31494. titleFont = "方正黑体简体";
  31495. timeFont = "Times New Roman";
  31496. contentFont = "方正仿宋_GBK";
  31497. }
  31498. else if (dto.FileIndex == 3)
  31499. {
  31500. fileName = "市外办-报批.docx";
  31501. titleFont = "方正黑体简体";
  31502. timeFont = "Times New Roman";
  31503. contentFont = "方正仿宋简体";
  31504. }
  31505. tempPath = tempPath + fileName;
  31506. //载入模板
  31507. Document doc = new Document(tempPath);
  31508. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  31509. //获取所填表格的序数
  31510. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  31511. Aspose.Words.Tables.Row titleRowClone = null;
  31512. Aspose.Words.Tables.Row CenterRowClone = null;
  31513. int index = 0;
  31514. int indexChi = 0;
  31515. int SetIndex = 0;
  31516. var ApprovalTravelArr = _sqlSugar.Queryable<Grp_ApprovalTravel>().Where(x => x.IsDel == 0 && x.Diid == dto.Diid).ToList();
  31517. //获取数据,放到datatable
  31518. foreach (var item in ApprovalTravelArr)
  31519. {
  31520. if (index > 0)
  31521. {
  31522. titleRowClone = (Aspose.Words.Tables.Row)tableOne.Rows[0].Clone(true);
  31523. tableOne.AppendChild(titleRowClone);
  31524. }
  31525. var textTime = item.Date;
  31526. var ChiRep = _sqlSugar.Queryable<Grp_ApprovalTravelDetails>().Where(x => x.IsDel == 0 && x.ParentId == item.Id).ToList();
  31527. SetCells(tableOne, doc, SetIndex, 0, textTime, titleFont, bold);
  31528. SetIndex++;
  31529. if (ChiRep.Count > 0)
  31530. {
  31531. foreach (var itemChi in ChiRep)
  31532. {
  31533. var txtTime = itemChi.Time;
  31534. var txtDetail = itemChi.Details;
  31535. if (string.IsNullOrEmpty(txtTime) && string.IsNullOrEmpty(txtDetail))
  31536. {
  31537. //SetCells(tableOne, doc, SetIndex, 0, "", timeFont, bold);
  31538. //SetCells(tableOne, doc, SetIndex, 1, "", contentFont, bold);
  31539. //indexChi++;
  31540. //SetIndex++;
  31541. break;
  31542. }
  31543. if (indexChi > 0)
  31544. {
  31545. CenterRowClone = (Aspose.Words.Tables.Row)tableOne.Rows[1].Clone(true);
  31546. tableOne.AppendChild(CenterRowClone);
  31547. }
  31548. SetCells(tableOne, doc, SetIndex, 0, txtTime, timeFont, bold);
  31549. SetCells(tableOne, doc, SetIndex, 1, txtDetail, contentFont, bold);
  31550. indexChi++;
  31551. SetIndex++;
  31552. }
  31553. }
  31554. //else
  31555. //{
  31556. // if (indexChi > 0)
  31557. // {
  31558. // CenterRowClone = (Aspose.Words.Tables.Row)tableOne.Rows[1].Clone(true);
  31559. // tableOne.AppendChild(CenterRowClone);
  31560. // }
  31561. // SetCells(tableOne, doc, SetIndex, 0, "",timeFont, bold);
  31562. // SetCells(tableOne, doc, SetIndex, 1, "", contentFont, bold);
  31563. // indexChi++;
  31564. // SetIndex++;
  31565. //}
  31566. index++;
  31567. }
  31568. string strFileName = "/Travel/ExportApprovalJourneyWord/" + group.TeamName + fileName;
  31569. doc.Save(AppSettingsHelper.Get("WordBasePath") + strFileName, Aspose.Words.SaveFormat.Docx); //"C:\\Server\\File\\OA2023\\Office\\Word" + strFileName
  31570. jw.Data = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + strFileName; //"C:\\Server\\File\\OA2023\\Office\\Word" + strFileName
  31571. jw.Code = 200;
  31572. jw.Msg = "";
  31573. return Ok(jw);
  31574. }
  31575. private string ParseBlackTime(string time)
  31576. {
  31577. // 匹配可能只有分钟的情况
  31578. string pattern = @"(?:(\d+)H)?(?:(\d+)M)?";
  31579. System.Text.RegularExpressions.Match match = Regex.Match(time, pattern);
  31580. if (match.Success)
  31581. {
  31582. string hours = match.Groups[1].Value;
  31583. string minutes = match.Groups[2].Value;
  31584. // 如果小时部分为空,则只显示分钟
  31585. if (string.IsNullOrEmpty(hours))
  31586. {
  31587. return $"{minutes}分钟";
  31588. }
  31589. // 如果分钟部分为空,则只显示小时
  31590. else if (string.IsNullOrEmpty(minutes))
  31591. {
  31592. return $"{hours}小时";
  31593. }
  31594. // 否则显示完整格式
  31595. else
  31596. {
  31597. return $"{hours}小时{minutes}分钟";
  31598. }
  31599. }
  31600. else
  31601. {
  31602. return "未知时长";
  31603. }
  31604. }
  31605. private string intToString(int numberVal)
  31606. {
  31607. string numberval = numberVal.ToString();
  31608. Dictionary<char, string> Number = new Dictionary<char, string>();
  31609. Number.Add('1', "一");
  31610. Number.Add('2', "二");
  31611. Number.Add('3', "三");
  31612. Number.Add('4', "四");
  31613. Number.Add('5', "五");
  31614. Number.Add('6', "六");
  31615. Number.Add('7', "七");
  31616. Number.Add('8', "八");
  31617. Number.Add('9', "九");
  31618. string stringNumberVal = string.Empty;
  31619. for (int i = 0; i < numberval.Length; i++)
  31620. {
  31621. if (i == 0)
  31622. {
  31623. stringNumberVal += Number[numberval[i]];
  31624. }
  31625. else if (i >= 1)
  31626. {
  31627. if (numberval[i] == '0')
  31628. {
  31629. stringNumberVal = "十";
  31630. }
  31631. else
  31632. {
  31633. stringNumberVal += "十" + Number[numberval[i]];
  31634. }
  31635. }
  31636. }
  31637. return stringNumberVal;
  31638. }
  31639. private void SetCells(Aspose.Words.Tables.Table table, Document doc, int rows, int cells, string val, string font, bool bold)
  31640. {
  31641. //获取table中的某个单元格,从0开始
  31642. Cell lshCell = table.Rows[rows].Cells[cells];
  31643. //将单元格中段落移除
  31644. foreach (Paragraph item in lshCell.Paragraphs)
  31645. {
  31646. lshCell.Paragraphs.Remove(item);
  31647. }
  31648. if (val.Contains("\r\n"))
  31649. {
  31650. var spArr = val.Split("\r\n").Where(x => !string.IsNullOrWhiteSpace(x));
  31651. foreach (var item in spArr)
  31652. {
  31653. //新建一个段落
  31654. Paragraph p = new Paragraph(doc);
  31655. var r = new Run(doc, item);
  31656. //设置字体
  31657. if (!string.IsNullOrEmpty(font))
  31658. {
  31659. r.Font.Name = font;
  31660. }
  31661. r.Font.Bold = bold;
  31662. //把设置的值赋给之前新建的段落
  31663. p.AppendChild(r);
  31664. //将此段落加到单元格内
  31665. lshCell.AppendChild(p);
  31666. }
  31667. }
  31668. else
  31669. {
  31670. //新建一个段落
  31671. Paragraph p = new Paragraph(doc);
  31672. var r = new Run(doc, val);
  31673. //设置字体
  31674. if (!string.IsNullOrEmpty(font))
  31675. {
  31676. r.Font.Name = font;
  31677. }
  31678. r.Font.Bold = bold;
  31679. //把设置的值赋给之前新建的段落
  31680. p.AppendChild(r);
  31681. //将此段落加到单元格内
  31682. lshCell.AppendChild(p);
  31683. }
  31684. }
  31685. /// <summary>
  31686. /// 报批行程AI续写
  31687. /// </summary>
  31688. /// <returns></returns>
  31689. [HttpPost]
  31690. public async Task<IActionResult> ApprovalJourneyAiWrite(ApprovalJourneyAiWriteDto dto)
  31691. {
  31692. var jw = JsonView(false);
  31693. if (dto.ClientPurpose.IsNullOrWhiteSpace() || dto.ClientName.IsNullOrWhiteSpace())
  31694. {
  31695. jw.Msg = "参数有误!";
  31696. return Ok(jw);
  31697. }
  31698. KiMiApiClient kiMi = new KiMiApiClient();
  31699. List<SeedMessages> messages = new List<SeedMessages>() {
  31700. new SeedMessages
  31701. {
  31702. Role = KimiRole.system,
  31703. Content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。"
  31704. },
  31705. new SeedMessages
  31706. {
  31707. Role = KimiRole.user,
  31708. Content = $@"参考这个模板格式来编写一份{dto.ClientName}拜访{dto.ClientPurpose},结合{dto.ClientName}的业务,描述拜访目的,字数在200字内(直接给出拜访目的,不输出其他内容)"
  31709. }
  31710. };
  31711. var kimi_result = await kiMi.SeedMessageByFullConterObject(messages);
  31712. string data = kimi_result.Choices[0]?.Message.Content;
  31713. if (string.IsNullOrWhiteSpace(data))
  31714. {
  31715. jw.Data = "Ai续写失败!";
  31716. }
  31717. else
  31718. {
  31719. jw = JsonView(true, "success!", data);
  31720. }
  31721. return Ok(jw);
  31722. }
  31723. #endregion
  31724. #region 团组接待意见调查
  31725. /// <summary>
  31726. /// 团组接待意见调查 - 信息管理
  31727. /// 基础数据(团组)
  31728. /// </summary>
  31729. /// <returns></returns>
  31730. [HttpGet]
  31731. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31732. public async Task<IActionResult> OpinionaireInit()
  31733. {
  31734. var groupData = await _groupRepository.Query(x => x.IsDel == 0)
  31735. .Select(x => new
  31736. {
  31737. x.Id,
  31738. GroupName = $"[{x.VisitDate.ToString("yyyy-MM-dd")}]{x.TeamName}"
  31739. })
  31740. .OrderByDescending(x => x.Id)
  31741. .ToListAsync();
  31742. return Ok(JsonView(groupData, groupData.Count));
  31743. }
  31744. /// <summary>
  31745. /// 团组接待意见调查 - 信息管理
  31746. /// 列表
  31747. /// </summary>
  31748. /// <param name="groupId"></param>
  31749. /// <returns></returns>
  31750. [HttpGet("{groupId}")]
  31751. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31752. public async Task<IActionResult> OpinionaireManageList(int groupId)
  31753. {
  31754. if (groupId < 1) Ok(JsonView(false, "请传入有效的diId"));
  31755. var data = await _opinionaireRep.Query(x => x.DiId == groupId)
  31756. .Select(x => new
  31757. {
  31758. x.Id,
  31759. x.TourGuideName,
  31760. x.CityName,
  31761. CreateUserName = SqlFunc.Subqueryable<Sys_Users>().Where(x1 => x.CreateUserId == x1.Id).Select(x1 => x1.CnName),
  31762. x.CreateTime
  31763. })
  31764. .OrderBy(x => x.Id)
  31765. .ToListAsync();
  31766. return Ok(JsonView(data));
  31767. }
  31768. /// <summary>
  31769. /// 团组接待意见调查 - 信息管理
  31770. /// 保存
  31771. /// </summary>
  31772. /// <param name="dto"></param>
  31773. /// <returns></returns>
  31774. [HttpPost]
  31775. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31776. public async Task<IActionResult> OpinionaireManageSave(OpinionaireManageSaveDto dto)
  31777. {
  31778. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  31779. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  31780. if (dto.DiId < 1) Ok(JsonView(false, "请传入有效的diId"));
  31781. if (dto.Items.Length < 1) Ok(JsonView(false, "请传入需要保存的信息"));
  31782. var addData = _mapper.Map<List<Grp_Opinionaire>>(dto.Items.Where(x => x.Id == 0).ToList());
  31783. var updData = _mapper.Map<List<Grp_Opinionaire>>(dto.Items.Where(x => x.Id > 0).ToList());
  31784. _opinionaireRep.BeginTran();
  31785. if (addData != null && addData.Count > 0)
  31786. {
  31787. foreach (var item in addData)
  31788. {
  31789. item.CreateUserId = currUserInfo.UserId;
  31790. item.DiId = dto.DiId;
  31791. }
  31792. var add = await _opinionaireRep._sqlSugar.Insertable(addData).ExecuteCommandAsync();
  31793. }
  31794. if (updData != null && updData.Count > 0)
  31795. {
  31796. var upd = await _opinionaireRep._sqlSugar
  31797. .Updateable(updData)
  31798. .UpdateColumns(x => new { x.CityName, x.TourGuideName })
  31799. .WhereColumns(x => new { x.Id })
  31800. .ExecuteCommandAsync();
  31801. }
  31802. _opinionaireRep.CommitTran();
  31803. return Ok(JsonView("操作成功!"));
  31804. }
  31805. /// <summary>
  31806. /// 团组接待意见调查 - 信息管理
  31807. /// 删除
  31808. /// </summary>
  31809. /// <param name="id"></param>
  31810. /// <returns></returns>
  31811. [HttpDelete("{id}")]
  31812. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31813. public async Task<IActionResult> OpinionaireManageDel(int id)
  31814. {
  31815. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  31816. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  31817. if (id < 1) Ok(JsonView(false, "请传入有效的id"));
  31818. var del = await _opinionaireRep.SoftDeleteAsync(x => x.Id == id, currUserInfo.UserId);
  31819. if (!del) return Ok(JsonView("操作失败!"));
  31820. return Ok(JsonView("操作成功!"));
  31821. }
  31822. /// <summary>
  31823. /// 团组接待意见调查 - 用户
  31824. /// 列表
  31825. /// </summary>
  31826. /// <param name="diId"></param>
  31827. /// <returns></returns>
  31828. [HttpGet("{diId}")]
  31829. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31830. public async Task<IActionResult> OpinionaireUserList(int diId)
  31831. {
  31832. if (diId < 1) Ok(JsonView(false, "请传入有效的diId"));
  31833. var sql = string.Format(@"
  31834. SELECT
  31835. o.Id,
  31836. o.DiId,
  31837. di.TeamName AS 'GroupName',
  31838. di.VisitPNumber AS 'PeopleNumber',
  31839. di.ClientName AS 'LeadGroup',
  31840. di.VisitCountry AS 'Travel',
  31841. di.VisitDays AS 'Days',
  31842. o.CityName,
  31843. o.TourGuideName,
  31844. o.Catering,
  31845. o.CateringReason,
  31846. o.Stay,
  31847. o.StayReason,
  31848. o.[Route],
  31849. o.RouteReason,
  31850. o.OfficialActivity,
  31851. o.OfficialActivityReason,
  31852. o.TourGuide,
  31853. o.TourGuideReason,
  31854. o.[Translate],
  31855. o.TranslateReason,
  31856. o.Trip,
  31857. o.TripReason,
  31858. o.ESFileName,
  31859. o.SignatureDate,
  31860. o.Remark
  31861. FROM
  31862. Grp_Opinionaire o
  31863. LEFT JOIN Grp_DelegationInfo di ON o.DiId = di.Id
  31864. WHERE
  31865. o.IsDel = 0
  31866. AND o.DiId = {0}
  31867. ORDER BY
  31868. o.Id ASC", diId);
  31869. var data = await _sqlSugar.SqlQueryable<OpinionaireUserListView>(sql).ToListAsync();
  31870. if (data.Count < 1) return Ok(JsonView(false, "暂无数据"));
  31871. return Ok(JsonView(data));
  31872. }
  31873. /// <summary>
  31874. /// 团组接待意见调查 - 用户
  31875. /// 保存
  31876. /// </summary>
  31877. /// <param name="dto"></param>
  31878. /// <returns></returns>
  31879. [HttpPost]
  31880. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31881. public async Task<IActionResult> OpinionaireUserSave([FromForm] OpinionaireUserSaveInfo[] dto)
  31882. {
  31883. if (dto.Length < 1) Ok(JsonView(false, "请传入有效的参数"));
  31884. foreach (var item in dto)
  31885. {
  31886. if (string.IsNullOrEmpty(item.Catering)) Ok(JsonView(false, "请选择餐饮评分!"));
  31887. if (string.IsNullOrEmpty(item.Stay)) Ok(JsonView(false, "请选择住宿评分!"));
  31888. if (string.IsNullOrEmpty(item.Route)) Ok(JsonView(false, "请选择行程评分!"));
  31889. if (string.IsNullOrEmpty(item.OfficialActivity)) Ok(JsonView(false, "请选择公务活动评分!"));
  31890. if (string.IsNullOrEmpty(item.Translate)) Ok(JsonView(false, "请选择翻译评分!"));
  31891. if (string.IsNullOrEmpty(item.Trip)) Ok(JsonView(false, "请选择行程评分!"));
  31892. if (string.IsNullOrEmpty(item.SignatureDate)) Ok(JsonView(false, "请填写签名日期!"));
  31893. if (item.File.Length < 1) Ok(JsonView(false, "请上传签名图片!"));
  31894. }
  31895. var filePathBase = $"{AppSettingsHelper.Get("GrpFileBasePath")}OpinionaireElectronicSignature";
  31896. if (!Directory.Exists(filePathBase))
  31897. {
  31898. Directory.CreateDirectory(filePathBase);
  31899. }
  31900. #region 上传文件
  31901. var filePaths = new List<string>();
  31902. foreach (var item in dto)
  31903. {
  31904. var file = item.File;
  31905. // 将文件保存到指定位置
  31906. var filePath = Path.Combine(filePathBase, file.FileName);
  31907. using (var stream = new FileStream(filePath, FileMode.Create))
  31908. {
  31909. await file.CopyToAsync(stream);
  31910. }
  31911. //验证文件是否上传成功
  31912. if (!System.IO.File.Exists(filePath))
  31913. {
  31914. foreach (var filePathStr in filePaths)
  31915. {
  31916. System.IO.File.Delete(filePathStr);
  31917. }
  31918. return Ok(JsonView(false, "文件上传失败!"));
  31919. }
  31920. item.ESFileName = file.FileName;
  31921. }
  31922. #endregion
  31923. var infos = _mapper.Map<List<Grp_Opinionaire>>(dto);
  31924. var upd = await _sqlSugar.Updateable<Grp_Opinionaire>(infos)
  31925. .UpdateColumns(x => new
  31926. {
  31927. x.Catering,
  31928. x.CateringReason,
  31929. x.Stay,
  31930. x.StayReason,
  31931. x.Route,
  31932. x.RouteReason,
  31933. x.OfficialActivity,
  31934. x.OfficialActivityReason,
  31935. x.TourGuide,
  31936. x.TourGuideReason,
  31937. x.Translate,
  31938. x.TranslateReason,
  31939. x.Trip,
  31940. x.TripReason,
  31941. x.ESFileName,
  31942. x.SignatureDate,
  31943. x.Remark
  31944. })
  31945. .WhereColumns(x => new { x.Id })
  31946. .ExecuteCommandAsync();
  31947. if (upd < 1)
  31948. {
  31949. foreach (var filePathStr in filePaths)
  31950. {
  31951. System.IO.File.Delete(filePathStr);
  31952. }
  31953. return Ok(JsonView(false));
  31954. }
  31955. return Ok(JsonView(true));
  31956. }
  31957. #endregion
  31958. #region 团组餐厅相关信息
  31959. /// <summary>
  31960. /// 团组相关餐厅信息
  31961. /// 基础数据(团组)
  31962. /// </summary>
  31963. /// <returns></returns>
  31964. [HttpGet]
  31965. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31966. public async Task<IActionResult> RestaurantInit()
  31967. {
  31968. return Ok(await _restaurantRep.InitAsync());
  31969. }
  31970. /// <summary>
  31971. /// 团组相关餐厅信息
  31972. /// Item
  31973. /// </summary>
  31974. /// <param name="dto"></param>
  31975. /// <returns></returns>
  31976. [HttpPost]
  31977. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31978. public async Task<IActionResult> RestaurantItem(RestaurantItemDto dto)
  31979. {
  31980. int portType = dto.PortType,
  31981. groupId = dto.GroupId;
  31982. if (!SharingStaticData.PortTypes.Contains(portType)) return Ok(JsonView(false, MsgTips.Port));
  31983. if (groupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  31984. return Ok(await _restaurantRep.ItemAsync(portType, groupId));
  31985. }
  31986. /// <summary>
  31987. /// 团组相关餐厅信息
  31988. /// List
  31989. /// </summary>
  31990. /// <param name="dto"></param>
  31991. /// <returns></returns>
  31992. [HttpPost]
  31993. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  31994. public async Task<IActionResult> RestaurantList(RestaurantItemDto dto)
  31995. {
  31996. int portType = dto.PortType,
  31997. groupId = dto.GroupId;
  31998. if (!SharingStaticData.PortTypes.Contains(portType)) return Ok(JsonView(false, MsgTips.Port));
  31999. if (groupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  32000. var sql = string.Format(@" SELECT
  32001. ri.Id,
  32002. ri.GroupId,
  32003. ri.Date,
  32004. ri.StartTime,
  32005. ri.EndTime,
  32006. CASE WHEN ri.Type = 1 THEN '早餐'
  32007. WHEN ri.Type = 2 THEN '午餐'
  32008. WHEN ri.Type = 3 THEN '晚餐'
  32009. ELSE '其他'
  32010. END AS 'Type',
  32011. ri.Name,
  32012. ri.Address,
  32013. ri.Tel,
  32014. ri.Remark,
  32015. ri.CreateTime,
  32016. u.CnName AS CreateUserName
  32017. FROM
  32018. Grp_RestaurantInfo ri
  32019. LEFT JOIN Sys_Users u ON ri.CreateUserId = u.Id
  32020. WHERE
  32021. ri.IsDel = 0
  32022. AND ri.GroupId = {0}
  32023. ORDER BY
  32024. ri.Date ASC
  32025. ", groupId);
  32026. var infos = await _sqlSugar.SqlQueryable<RestaurantItemView>(sql).ToListAsync();
  32027. if (!infos.Any()) Ok(JsonView(false, "数据未填写!"));
  32028. return Ok(JsonView(infos));
  32029. }
  32030. /// <summary>
  32031. /// 团组相关餐厅信息
  32032. /// Info
  32033. /// </summary>
  32034. /// <param name="dto"></param>
  32035. /// <returns></returns>
  32036. [HttpPost]
  32037. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  32038. public async Task<IActionResult> RestaurantInfo(RestaurantInfoDto dto)
  32039. {
  32040. int portType = dto.PortType,
  32041. id = dto.Id;
  32042. if (!SharingStaticData.PortTypes.Contains(portType)) return Ok(JsonView(false, MsgTips.Port));
  32043. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  32044. return Ok(await _restaurantRep.InfoAsync(portType, id));
  32045. }
  32046. /// <summary>
  32047. /// 团组相关餐厅信息
  32048. /// Op
  32049. /// </summary>
  32050. /// <param name="dto"></param>
  32051. /// <returns></returns>
  32052. [HttpPost]
  32053. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  32054. public async Task<IActionResult> RestaurantOp(RestaurantOpDto dto)
  32055. {
  32056. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  32057. if (dto.GroupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  32058. if (string.IsNullOrEmpty(dto.Name)) return Ok(JsonView(false, "餐厅名称为空!"));
  32059. return Ok(await _restaurantRep.OpAsync(dto));
  32060. }
  32061. /// <summary>
  32062. /// 团组相关餐厅信息
  32063. /// Del
  32064. /// </summary>
  32065. /// <param name="dto"></param>
  32066. /// <returns></returns>
  32067. [HttpPost]
  32068. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  32069. public async Task<IActionResult> RestaurantDel(RestaurantDelDto dto)
  32070. {
  32071. int userId = dto.DeleteUserId;
  32072. var id = dto.Id;
  32073. if (userId < 1) return Ok(JsonView(false, MsgTips.UserId));
  32074. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  32075. return Ok(await _restaurantRep.DelAsync(dto));
  32076. }
  32077. #endregion
  32078. #region 团组会务成本
  32079. ///读取excel数据
  32080. /// </summary>
  32081. /// <returns></returns>
  32082. [HttpPost]
  32083. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  32084. public async Task<IActionResult> MaterialCostsReadExcel(MaterialCostsReadExcelDto dto)
  32085. {
  32086. var file = dto.File;
  32087. var rowIndex = dto.RowIndex;
  32088. var userId = dto.UserId;
  32089. var groupId = dto.GroupId;
  32090. var conferenceAffairsCostId = dto.ConferenceAffairsCostId;
  32091. if (file == null || file.Length == 0)
  32092. {
  32093. return Ok(JsonView(false, "请选择文件"));
  32094. }
  32095. var conferenceAffairsCost = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
  32096. .First(x => x.Id == conferenceAffairsCostId && x.IsDel == 0);
  32097. if (conferenceAffairsCost == null)
  32098. {
  32099. return Ok(JsonView(false, "ConferenceAffairsCostId 参数有误!"));
  32100. }
  32101. var workbook = new Workbook(file.OpenReadStream());
  32102. var worksheet = workbook.Worksheets[0];
  32103. var rowCount = worksheet.Cells.MaxDataRow + 1;
  32104. var colCount = worksheet.Cells.MaxDataColumn + 1;
  32105. var setDatas = await _sqlSugar.Queryable<Sys_SetData>()
  32106. .Where(x => x.IsDel == 0 && (x.STid == 21 || x.STid == 119))
  32107. .Select(x => new { x.Id, x.Name, x.STid })
  32108. .ToListAsync();
  32109. var typeItems = setDatas.Where(x => x.STid == 21).ToList();
  32110. var unitItems = setDatas.Where(x => x.STid == 119).ToList();
  32111. // 预处理为字典,提高查找效率
  32112. var typeDict = typeItems.GroupBy(x => x.Name).ToDictionary(g => g.Key, g => g.First().Id);
  32113. var unitDict = unitItems.GroupBy(x => x.Name).ToDictionary(g => g.Key, g => g.First().Id);
  32114. List<Grp_ConferenceAffairsCostChild> data = new List<Grp_ConferenceAffairsCostChild>();
  32115. for (int i = rowIndex; i < rowCount; i++)
  32116. {
  32117. var sotr = int.TryParse(worksheet.Cells[i, 0].Value.toString(), out int index) ? index : 0;
  32118. var typeName = worksheet.Cells[i, 1].Value.toString();
  32119. var itemName = worksheet.Cells[i, 2].Value.toString();
  32120. var count = int.TryParse(worksheet.Cells[i, 3].Value.toString(), out int countInt) ? countInt : 0;
  32121. var unitName = worksheet.Cells[i, 4].Value.toString();
  32122. var baoJiaPrice = decimal.TryParse(worksheet.Cells[i, 5].Value.toString(), out decimal priceDecimal) ? priceDecimal : 0;
  32123. var baoJiaAllPrice = decimal.TryParse(worksheet.Cells[i, 6].Value.toString(), out decimal allPriceDecimal) ? allPriceDecimal : 0;
  32124. var costPriceAll = decimal.TryParse(worksheet.Cells[i, 7].Value.toString(), out decimal costPriceAllDecimal) ? costPriceAllDecimal : 0; //成本总价
  32125. var rowNo = i + 1;
  32126. if (count == 0) return Ok(JsonView(false, $"第{rowNo}行第4列单元格数据有误"));
  32127. if (baoJiaPrice == 0) return Ok(JsonView(false, $"第{rowNo}行第6列单元格数据有误"));
  32128. if (baoJiaAllPrice == 0) return Ok(JsonView(false, $"第{rowNo}行第7列单元格数据有误"));
  32129. if (costPriceAll == 0) return Ok(JsonView(false, $"第{rowNo}行第8列单元格数据有误"));
  32130. //计算系数
  32131. var costSinglePrice = costPriceAll / count; //单项成本
  32132. var costSinglePriceRate = baoJiaPrice / costSinglePrice; //系数
  32133. data.Add(new Grp_ConferenceAffairsCostChild
  32134. {
  32135. Index = index,
  32136. PriceType = typeDict.GetValueOrDefault(typeName, 0),
  32137. PriceName = itemName,
  32138. Count = count,
  32139. Unit = unitDict.GetValueOrDefault(unitName, 0),
  32140. CostPrice = costSinglePrice,
  32141. Currency = 836, // 建议定义为常量或从配置读取
  32142. Rate = costSinglePriceRate,
  32143. AddedValue = 0,
  32144. Details = "",
  32145. ReviewStatus = 0,
  32146. Imgs = "",
  32147. Diid = groupId,
  32148. ConferenceAffairsCostId = conferenceAffairsCostId,
  32149. CreateTime = DateTime.Now,
  32150. CreateUserId = userId,
  32151. IsDel = 0,
  32152. BaoJiaPrice = baoJiaPrice,
  32153. Coefficient = costSinglePriceRate,
  32154. Remark = string.Empty
  32155. });
  32156. }
  32157. var result = await _sqlSugar.Insertable(data).ExecuteCommandAsync();
  32158. if (result < 1) return Ok(JsonView(false, "数据插入失败!"));
  32159. return Ok(JsonView(true, "数据插入成功!", new { count = result }));
  32160. }
  32161. /// <summary>
  32162. /// 团组会务成本数据初始化
  32163. /// </summary>
  32164. /// <returns></returns>
  32165. [HttpPost]
  32166. public async Task<IActionResult> ConferenceAffairsInIt(ConferenceAffairsInItDto Dto)
  32167. {
  32168. var hwids = _sqlSugar.Queryable<Sys_SetData>()
  32169. .Where(x => x.IsDel == 0 && x.STid == 10 && x.Name.Contains("会务活动"))
  32170. .Select(x => x.Id)
  32171. .ToList();
  32172. var expr = _sqlSugar.Queryable<Grp_DelegationInfo>()
  32173. .OrderByDescending(x => x.VisitDate)
  32174. .Where(x => x.IsDel == 0 && hwids.Contains(x.TeamDid))
  32175. .Select<DelegationEasyView>();
  32176. DelegationEasyView di = Dto.GroupId == 0 ?
  32177. expr.First() :
  32178. expr.First(x => x.Id == Dto.GroupId);
  32179. if (di == null)
  32180. {
  32181. return Ok(JsonView(false, "团组信息不存在!"));
  32182. }
  32183. var typeData = await _sqlSugar.Queryable<Sys_SetData>()
  32184. .Where(x => x.IsDel == 0 && x.STid == 21)
  32185. .Select(x => new { x.Id, Text = x.Name })
  32186. .ToListAsync();
  32187. //仅检索会务团组
  32188. var groupList = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  32189. .Where(x => x.IsDel == 0 && hwids.Contains(x.TeamDid))
  32190. .OrderByDescending(x => x.VisitDate)
  32191. .Select(x => new { x.Id, x.TeamName })
  32192. .ToListAsync();
  32193. var currenyList = await GeneralMethod.PostGroupTeamRateByDiIdAndCTableId(1, di.Id, 98);
  32194. var userList = await _sqlSugar.Queryable<Sys_Users>()
  32195. .Where(x => x.IsDel == 0)
  32196. .Select(x => new { x.Id, x.CnName })
  32197. .ToListAsync();
  32198. var units = await _sqlSugar.Queryable<Sys_SetData>()
  32199. .Where(x => x.IsDel == 0 && x.STid == 119)
  32200. .Select(x => new { x.Id, Text = x.Name })
  32201. .ToListAsync();
  32202. var FileType = new[]
  32203. {
  32204. new { Id = 0 , Name = "成本下载" },
  32205. new { Id = 1 , Name = "报价下载" },
  32206. new { Id = 2 , Name = "总表下载" },
  32207. };
  32208. var GM = new List<int>();
  32209. var permissionControlDB = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == 1448)?.Remark;
  32210. try
  32211. {
  32212. GM = JsonConvert.DeserializeObject<List<int>>(permissionControlDB);
  32213. }
  32214. catch (Exception ex)
  32215. {
  32216. GM = new List<int>() { 21 };
  32217. }
  32218. var isReview = Dto.UserId == 21;
  32219. var isGM = GM.Contains(Dto.UserId);
  32220. var ConferenceAffairsCost = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
  32221. .Where(x => x.IsDel == 0)
  32222. .First(x => x.Diid == di.Id);
  32223. if (ConferenceAffairsCost == null)
  32224. {
  32225. //插入主表数据
  32226. ConferenceAffairsCost = new Grp_ConferenceAffairsCost()
  32227. {
  32228. Diid = di.Id,
  32229. CreateTime = DateTime.Now,
  32230. CreateUserId = Dto.UserId,
  32231. IsDel = 0,
  32232. AllocationAmount = 0,
  32233. AllocationCurrency = 836,
  32234. AllocationRate = 0,
  32235. AllocationGroupId = di.Id,
  32236. CostAll = 0,
  32237. BaoJiaAll = 0,
  32238. MostCurr = 836,
  32239. Remark = "",
  32240. City = "",
  32241. };
  32242. ConferenceAffairsCost.Id = _sqlSugar.Insertable(ConferenceAffairsCost).ExecuteReturnIdentity();
  32243. }
  32244. #region 权限校验
  32245. var ids = _sqlSugar.Queryable<Grp_ConferenceAffairsCostControl>()
  32246. .Where(x => x.Diid == di.Id && x.IsDel == 0)
  32247. .Select(x => x.UserId)
  32248. .Distinct()
  32249. .ToList();
  32250. if (!ids.Contains(Dto.UserId) && !isGM)
  32251. {
  32252. return Ok(JsonView(201, "暂无权限!", new
  32253. {
  32254. typeData,
  32255. groupList,
  32256. currenyList,
  32257. isGM,
  32258. userList,
  32259. units,
  32260. isReview,
  32261. operatorUser = ids,
  32262. di,
  32263. FileType
  32264. }));
  32265. }
  32266. #endregion
  32267. var ConferenceAffairsCostChi = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  32268. .Where(x => x.IsDel == 0 && x.Diid == di.Id)
  32269. .Select<ConferenceAffairsCostChildView>()
  32270. .OrderBy(x => x.Index)
  32271. .ToList();
  32272. for (int i = 1; i <= ConferenceAffairsCostChi.Count; i++)
  32273. {
  32274. ConferenceAffairsCostChi[i - 1].Index = i;
  32275. }
  32276. var ConferenceAffairsCostMap = _mapper.Map<ConferenceAffairsCostView>(ConferenceAffairsCost);
  32277. var backData = new
  32278. {
  32279. ConferenceAffairsCost = ConferenceAffairsCostMap,
  32280. ConferenceAffairsCostChi,
  32281. typeData,
  32282. groupList,
  32283. currenyList,
  32284. isGM,
  32285. userList,
  32286. units,
  32287. isReview,
  32288. operatorUser = ids,
  32289. di,
  32290. FileType
  32291. };
  32292. return Ok(JsonView(true, "SUCCESS", backData));
  32293. }
  32294. [HttpPost]
  32295. public async Task<IActionResult> ConferenceAffairsChildAddRowReturnId(ConferenceAffairsChildAddRowReturnIdDto dto)
  32296. {
  32297. var data = _mapper.Map<Grp_ConferenceAffairsCostChild>(dto.data);
  32298. if (data.Rate == 0)
  32299. {
  32300. data.Rate = 1;
  32301. }
  32302. if (data.Coefficient == 0)
  32303. {
  32304. data.Coefficient = 1;
  32305. }
  32306. if (data.Count == 0)
  32307. {
  32308. data.Count = 1;
  32309. }
  32310. var id = await _sqlSugar.Insertable(data).ExecuteReturnIdentityAsync();
  32311. return Ok(JsonView(true, "SUCCESS", new { id }));
  32312. }
  32313. /// <summary>
  32314. /// 会务成本从表新增行
  32315. /// </summary>
  32316. /// <param name="Dto"></param>
  32317. /// <returns></returns>
  32318. [HttpPost]
  32319. public async Task<IActionResult> ConferenceAffairsChildAddRow(ConferenceAffairsChildAddRowDto Dto)
  32320. {
  32321. if (Dto.diid < 1) return Ok(JsonView(false, "团组id有误!"));
  32322. if (Dto.userId < 1) return Ok(JsonView(false, "用户id有误!"));
  32323. var queryList = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  32324. .Where(x => x.IsDel == 0 && x.Diid == Dto.diid)
  32325. .OrderByDescending(x => x.Index)
  32326. .ToList();
  32327. var queryData = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
  32328. .Where(x => x.IsDel == 0 && x.Diid == Dto.diid)
  32329. .First();
  32330. if (queryData == null)
  32331. {
  32332. return Ok(JsonView(false, "会务成本主表不存在!"));
  32333. }
  32334. var child = new Grp_ConferenceAffairsCostChild();
  32335. child.Diid = Dto.diid;
  32336. child.CreateTime = DateTime.Now;
  32337. child.CreateUserId = Dto.userId;
  32338. child.IsDel = 0;
  32339. child.Index = queryList.Count + 1;
  32340. child.ConferenceAffairsCostId = queryData.Id;
  32341. child.PriceType = 0;
  32342. child.PriceName = "";
  32343. child.CostPrice = 0;
  32344. child.Currency = 836;
  32345. child.Rate = 1;
  32346. child.Count = 1;
  32347. child.Unit = 0;
  32348. child.Coefficient = 1;
  32349. child.BaoJiaPrice = 0;
  32350. child.AddedValue = 0;
  32351. child.Details = "";
  32352. child.ReviewStatus = 0;
  32353. child.Imgs = "";
  32354. child.Id = _sqlSugar.Insertable(child).ExecuteReturnIdentity();
  32355. var result = new
  32356. {
  32357. index = queryList.Count + 1,
  32358. priceType = "",
  32359. priceName = "",
  32360. costPrice = 0m,
  32361. currency = 836,
  32362. rate = 1m,
  32363. count = 1,
  32364. unit = "",
  32365. coefficient = 1m,
  32366. baoJiaPrice = 0m,
  32367. addedValue = 0m,
  32368. details = "",
  32369. reviewStatus = 0,
  32370. diid = Dto.diid,
  32371. imgs = "",
  32372. imgsList = new List<string>(),
  32373. id = child.Id,
  32374. remark = ""
  32375. };
  32376. return Ok(JsonView(true, "新增成功!", result));
  32377. }
  32378. /// <summary>
  32379. /// 会务成本从表图片文件上传
  32380. /// </summary>
  32381. /// <param name="Dto"></param>
  32382. /// <returns></returns>
  32383. [HttpPost]
  32384. public async Task<IActionResult> ConferenceAffairsChildImageUpload([FromForm] ConferenceAffairsChildImageUploadDto Dto)
  32385. {
  32386. try
  32387. {
  32388. if (Dto == null || Dto.Files == null || Dto.Files.Count == 0)
  32389. {
  32390. return Ok(JsonView(false, "请选择要上传的图片文件!"));
  32391. }
  32392. var child = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  32393. .Where(x => x.IsDel == 0 && x.Id == Dto.childId)
  32394. .First();
  32395. if (child == null)
  32396. {
  32397. return Ok(JsonView(false, "会务成本从表不存在!"));
  32398. }
  32399. // 允许的图片类型
  32400. var allowedImageTypes = new[] { ".jpg", ".jpeg", ".png", ".gif", ".bmp" };
  32401. var allowedContentTypes = new[] { "image/jpeg", "image/jpg", "image/png", "image/gif", "image/bmp" };
  32402. // 获取配置路径
  32403. string baseUrl = AppSettingsHelper.Get("ConferenceCostImageBaseUrl");
  32404. string basePath = AppSettingsHelper.Get("ConferenceCostImageBasePath");
  32405. string ftpPath = AppSettingsHelper.Get("ConferenceCostImageFtpPath");
  32406. // 确保路径以/结尾
  32407. if (!baseUrl.EndsWith("/"))
  32408. {
  32409. baseUrl = baseUrl.TrimEnd('/') + "/";
  32410. }
  32411. if (!basePath.EndsWith("\\") && !basePath.EndsWith("/"))
  32412. {
  32413. basePath = basePath.TrimEnd('\\', '/') + "\\";
  32414. }
  32415. // 创建保存目录(按childId分目录)
  32416. string saveDir = Path.Combine(basePath, "child", child.Id.ToString());
  32417. if (!Directory.Exists(saveDir))
  32418. {
  32419. Directory.CreateDirectory(saveDir);
  32420. }
  32421. var uploadedImageUrls = new List<string>();
  32422. var existingImgs = string.IsNullOrWhiteSpace(child.Imgs)
  32423. ? new List<string>()
  32424. : child.Imgs.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  32425. foreach (var file in Dto.Files)
  32426. {
  32427. if (file == null || file.Length == 0)
  32428. {
  32429. continue;
  32430. }
  32431. // 验证文件扩展名
  32432. var fileExtension = Path.GetExtension(file.FileName).ToLowerInvariant();
  32433. if (string.IsNullOrEmpty(fileExtension) || !allowedImageTypes.Contains(fileExtension))
  32434. {
  32435. return Ok(JsonView(false, $"文件 {file.FileName} 不是支持的图片格式,仅支持:{string.Join("、", allowedImageTypes)}"));
  32436. }
  32437. // 验证ContentType
  32438. if (!string.IsNullOrEmpty(file.ContentType) && !allowedContentTypes.Contains(file.ContentType.ToLowerInvariant()))
  32439. {
  32440. return Ok(JsonView(false, $"文件 {file.FileName} 的ContentType不正确,不是图片类型"));
  32441. }
  32442. // 获取原始文件名(不含扩展名)和扩展名
  32443. string originalFileName = Path.GetFileNameWithoutExtension(file.FileName);
  32444. string fileName = file.FileName;
  32445. string filePath = Path.Combine(saveDir, fileName);
  32446. // 如果文件已存在,添加计数后缀
  32447. int count = 0;
  32448. while (System.IO.File.Exists(filePath))
  32449. {
  32450. count++;
  32451. fileName = $"{originalFileName}({count}){fileExtension}";
  32452. filePath = Path.Combine(saveDir, fileName);
  32453. }
  32454. // 保存文件
  32455. using (var stream = new FileStream(filePath, FileMode.Create))
  32456. {
  32457. await file.CopyToAsync(stream);
  32458. }
  32459. // 生成完整URL路径
  32460. string imageUrl = $"{baseUrl}{ftpPath}child/{child.Id}/{fileName}";
  32461. uploadedImageUrls.Add(imageUrl);
  32462. }
  32463. if (uploadedImageUrls.Count == 0)
  32464. {
  32465. return Ok(JsonView(false, "没有成功上传任何图片!"));
  32466. }
  32467. // 合并现有图片路径和新上传的图片路径
  32468. existingImgs.AddRange(uploadedImageUrls);
  32469. string updatedImgs = string.Join(",", existingImgs);
  32470. // 更新数据库
  32471. _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>()
  32472. .SetColumns(x => new Grp_ConferenceAffairsCostChild { Imgs = updatedImgs })
  32473. .Where(x => x.Id == child.Id)
  32474. .ExecuteCommand();
  32475. return Ok(JsonView(true, $"成功上传 {uploadedImageUrls.Count} 张图片", uploadedImageUrls));
  32476. }
  32477. catch (Exception ex)
  32478. {
  32479. return Ok(JsonView(false, $"上传失败:{ex.Message}"));
  32480. }
  32481. }
  32482. /// <summary>
  32483. /// 根据文件名和从表id删除对应的图片
  32484. /// </summary>
  32485. /// <param name="Dto"></param>
  32486. /// <returns></returns>
  32487. [HttpPost]
  32488. public async Task<IActionResult> ConferenceAffairsChildImageDelete(ConferenceAffairsChildImageDeleteDto Dto)
  32489. {
  32490. if (Dto == null || Dto.fileNames == null || Dto.fileNames.Count == 0)
  32491. {
  32492. return Ok(JsonView(false, "请提供要删除的文件名列表!"));
  32493. }
  32494. var child = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  32495. .Where(x => x.IsDel == 0 && x.Id == Dto.childId)
  32496. .First();
  32497. if (child == null)
  32498. {
  32499. return Ok(JsonView(false, "会务成本id有误!"));
  32500. }
  32501. var existingImgs = string.IsNullOrWhiteSpace(child.Imgs)
  32502. ? new List<string>()
  32503. : child.Imgs.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  32504. // 获取配置路径
  32505. string baseUrl = AppSettingsHelper.Get("ConferenceCostImageBaseUrl");
  32506. string basePath = AppSettingsHelper.Get("ConferenceCostImageBasePath");
  32507. string ftpPath = AppSettingsHelper.Get("ConferenceCostImageFtpPath");
  32508. // 确保路径格式正确
  32509. if (!baseUrl.EndsWith("/"))
  32510. {
  32511. baseUrl = baseUrl.TrimEnd('/') + "/";
  32512. }
  32513. if (!basePath.EndsWith("\\") && !basePath.EndsWith("/"))
  32514. {
  32515. basePath = basePath.TrimEnd('\\', '/') + "\\";
  32516. }
  32517. if (!ftpPath.EndsWith("/"))
  32518. {
  32519. ftpPath = ftpPath.TrimEnd('/') + "/";
  32520. }
  32521. int deletedCount = 0;
  32522. var expectedUrlPrefix = $"{baseUrl}{ftpPath}child/{child.Id}/";
  32523. var fileDir = Path.Combine(basePath, "child", child.Id.ToString());
  32524. // 遍历要删除的文件名列表
  32525. foreach (var fileNameOrUrl in Dto.fileNames)
  32526. {
  32527. if (string.IsNullOrWhiteSpace(fileNameOrUrl))
  32528. {
  32529. continue;
  32530. }
  32531. string fileName = fileNameOrUrl;
  32532. string fullUrl = fileNameOrUrl;
  32533. // 判断是完整URL还是文件名
  32534. if (fileNameOrUrl.StartsWith("http://") || fileNameOrUrl.StartsWith("https://"))
  32535. {
  32536. // 是完整URL,提取文件名
  32537. try
  32538. {
  32539. var uri = new Uri(fileNameOrUrl);
  32540. fileName = Path.GetFileName(uri.AbsolutePath);
  32541. // 如果URL包含child/{childId}/路径,使用完整URL匹配
  32542. if (fileNameOrUrl.Contains($"/child/{child.Id}/"))
  32543. {
  32544. fullUrl = fileNameOrUrl;
  32545. }
  32546. else
  32547. {
  32548. // URL格式不匹配,尝试构造完整URL
  32549. fullUrl = $"{expectedUrlPrefix}{fileName}";
  32550. }
  32551. }
  32552. catch
  32553. {
  32554. // URL解析失败,当作文件名处理
  32555. fileName = Path.GetFileName(fileNameOrUrl);
  32556. fullUrl = $"{expectedUrlPrefix}{fileName}";
  32557. }
  32558. }
  32559. else
  32560. {
  32561. // 是文件名,构造完整URL用于匹配
  32562. fullUrl = $"{expectedUrlPrefix}{fileName}";
  32563. }
  32564. // 从现有图片列表中移除(支持完整URL匹配或文件名匹配)
  32565. var removed = existingImgs.RemoveAll(img =>
  32566. img.Equals(fullUrl, StringComparison.OrdinalIgnoreCase) ||
  32567. img.Equals(fileNameOrUrl, StringComparison.OrdinalIgnoreCase) ||
  32568. img.EndsWith($"/{fileName}", StringComparison.OrdinalIgnoreCase));
  32569. if (removed > 0)
  32570. {
  32571. deletedCount++;
  32572. }
  32573. // 删除磁盘上的文件
  32574. var filePath = Path.Combine(fileDir, fileName);
  32575. if (System.IO.File.Exists(filePath))
  32576. {
  32577. try
  32578. {
  32579. System.IO.File.Delete(filePath);
  32580. }
  32581. catch (Exception ex)
  32582. {
  32583. _logger.LogError(ex, "删除图片失败:{fileName}", fileName);
  32584. }
  32585. }
  32586. }
  32587. if (deletedCount == 0)
  32588. {
  32589. return Ok(JsonView(false, "没有找到要删除的图片!"));
  32590. }
  32591. // 更新数据库
  32592. var updatedImgs = string.Join(",", existingImgs);
  32593. _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>()
  32594. .SetColumns(x => new Grp_ConferenceAffairsCostChild { Imgs = updatedImgs })
  32595. .Where(x => x.Id == child.Id)
  32596. .ExecuteCommand();
  32597. return Ok(JsonView(true, $"成功删除 {deletedCount} 张图片", updatedImgs));
  32598. }
  32599. /// <summary>
  32600. /// 会务流程word下载
  32601. /// </summary>
  32602. /// <param name="Dto"></param>
  32603. /// <returns></returns>
  32604. [HttpPost]
  32605. public async Task<IActionResult> InspectionReportFileDown(InspectionReportFileDownDto Dto)
  32606. {
  32607. var di = _sqlSugar.Queryable<Grp_DelegationInfo>()
  32608. .Where(x => x.IsDel == 0 && x.Id == Dto.Diid)
  32609. .First();
  32610. if (di == null)
  32611. {
  32612. return Ok(JsonView(false, "团组信息不存在!"));
  32613. }
  32614. //书签dic
  32615. var bookmarks = new Dictionary<string, string>();
  32616. bookmarks.Add("TeamName", di.TeamName);
  32617. bookmarks.Add("TeamName1", di.TeamName);
  32618. bookmarks.Add("ClientUnit", di.ClientUnit);
  32619. bookmarks.Add("ClientUnit1", di.ClientUnit);
  32620. bookmarks.Add("thisTime", DateTime.Now.ToString("yyyy年MM月dd日"));
  32621. //读取word模板
  32622. var templatePath = $"{AppSettingsHelper.Get("WordBasePath")}/template/活动验收报告.docx";
  32623. var doc = new Document(templatePath);
  32624. var chiList = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  32625. .Where(x => x.IsDel == 0 && x.Diid == Dto.Diid && x.PriceType > 0 && x.Unit > 0)
  32626. .Select(x => new
  32627. {
  32628. x.Index,
  32629. x.PriceName,
  32630. PriceType = SqlFunc.Subqueryable<Sys_SetData>().Where(y => y.IsDel == 0 && y.Id == x.PriceType).Select(y => y.Name),
  32631. x.Count,
  32632. x.Remark,
  32633. x.Imgs
  32634. })
  32635. .OrderBy(x => x.Index)
  32636. .ToList();
  32637. //获取word所有表格
  32638. var allTables = doc.GetChildNodes(NodeType.Table, true);
  32639. //获取word第一个表格
  32640. var table = allTables[0] as Aspose.Words.Tables.Table;
  32641. //内容行索引
  32642. var startIndex = 2;
  32643. var copyRow = table.Rows[startIndex].Clone(true);
  32644. for (int i = 0; i < chiList.Count; i++)
  32645. {
  32646. var chi = chiList[i];
  32647. //插入复制的行(从第2次开始插入新行,第1次使用模板行)
  32648. if (i > 0)
  32649. {
  32650. var newRow = copyRow.Clone(true) as Aspose.Words.Tables.Row;
  32651. table.Rows.Insert(startIndex, newRow);
  32652. }
  32653. //word 表格 赋值
  32654. var row = table.Rows[startIndex];
  32655. row.Cells[0].FirstParagraph.Runs.Clear();
  32656. row.Cells[0].FirstParagraph.AppendChild(new Run(doc, (i + 1).ToString()));
  32657. row.Cells[1].FirstParagraph.Runs.Clear();
  32658. row.Cells[1].FirstParagraph.AppendChild(new Run(doc, chi.PriceName));
  32659. row.Cells[2].FirstParagraph.Runs.Clear();
  32660. row.Cells[2].FirstParagraph.AppendChild(new Run(doc, chi.PriceType));
  32661. row.Cells[3].FirstParagraph.Runs.Clear();
  32662. row.Cells[3].FirstParagraph.AppendChild(new Run(doc, chi.Count.ToString()));
  32663. row.Cells[4].FirstParagraph.Runs.Clear();
  32664. row.Cells[4].FirstParagraph.AppendChild(new Run(doc, chi.Remark));
  32665. if (!string.IsNullOrWhiteSpace(chi.Imgs))
  32666. {
  32667. var imgs = chi.Imgs.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  32668. if (imgs.Length > 0)
  32669. {
  32670. // 获取图片基础路径配置
  32671. string baseUrl = AppSettingsHelper.Get("ConferenceCostImageBaseUrl");
  32672. string basePath = AppSettingsHelper.Get("ConferenceCostImageBasePath");
  32673. // 按图片方向分类,同时缓存图片字节数据
  32674. var imageInfos = new List<(string url, bool isWide, int width, int height, byte[] imageData)>();
  32675. _logger.LogInformation($"开始处理图片,配置 - BaseUrl: {baseUrl}, BasePath: {basePath}, 索引: {chi.Index}");
  32676. using (var httpClient = new HttpClient())
  32677. {
  32678. httpClient.Timeout = TimeSpan.FromSeconds(30);
  32679. foreach (var imgUrl in imgs)
  32680. {
  32681. try
  32682. {
  32683. string fullUrl = imgUrl;
  32684. string localPath = "";
  32685. // 判断是否为完整URL
  32686. if (imgUrl.StartsWith("http://") || imgUrl.StartsWith("https://"))
  32687. {
  32688. fullUrl = imgUrl;
  32689. // 尝试从URL转换为本地路径
  32690. if (imgUrl.Contains("/child/"))
  32691. {
  32692. var pathPart = imgUrl.Substring(imgUrl.IndexOf("/child/"));
  32693. localPath = Path.Combine(basePath, pathPart.TrimStart('/').Replace("/", "\\"));
  32694. }
  32695. }
  32696. else
  32697. {
  32698. // 文件名,构造本地路径和完整URL
  32699. localPath = Path.Combine(basePath, "child", chi.Index.ToString(), imgUrl);
  32700. fullUrl = $"{baseUrl.TrimEnd('/')}/child/{chi.Index}/{imgUrl}";
  32701. }
  32702. _logger.LogInformation($"处理图片 [{imgUrl}] - 本地路径: {localPath}, URL: {fullUrl}");
  32703. // 优先使用本地文件,如果不存在则尝试下载
  32704. byte[] imageBytes = null;
  32705. if (!string.IsNullOrEmpty(localPath) && System.IO.File.Exists(localPath))
  32706. {
  32707. imageBytes = System.IO.File.ReadAllBytes(localPath);
  32708. _logger.LogInformation($"从本地加载成功,大小: {imageBytes.Length} 字节");
  32709. }
  32710. else
  32711. {
  32712. // 从URL下载图片
  32713. try
  32714. {
  32715. _logger.LogInformation($"本地文件不存在,尝试从URL下载: {fullUrl}");
  32716. imageBytes = await httpClient.GetByteArrayAsync(fullUrl);
  32717. _logger.LogInformation($"从URL下载成功,大小: {imageBytes.Length} 字节");
  32718. }
  32719. catch (Exception ex)
  32720. {
  32721. _logger.LogWarning($"下载图片失败: {fullUrl}, 错误: {ex.Message}");
  32722. continue;
  32723. }
  32724. }
  32725. if (imageBytes != null && imageBytes.Length > 0)
  32726. {
  32727. // 获取图片尺寸
  32728. using (var ms = new MemoryStream(imageBytes))
  32729. {
  32730. using (var image = System.Drawing.Image.FromStream(ms))
  32731. {
  32732. bool isWide = image.Width >= image.Height;
  32733. // 缓存图片数据,避免后续重复加载
  32734. imageInfos.Add((imgUrl, isWide, image.Width, image.Height, imageBytes));
  32735. _logger.LogInformation($"图片分析完成 - 宽度: {image.Width}px, 高度: {image.Height}px, 类型: {(isWide ? "横图" : "竖图")}");
  32736. }
  32737. }
  32738. }
  32739. }
  32740. catch (Exception ex)
  32741. {
  32742. _logger.LogError(ex, $"处理图片失败: {imgUrl}");
  32743. continue;
  32744. }
  32745. }
  32746. }
  32747. _logger.LogInformation($"图片处理完成,成功加载 {imageInfos.Count} 张图片");
  32748. // 插入图片行
  32749. if (imageInfos.Count > 0)
  32750. {
  32751. var builder = new DocumentBuilder(doc);
  32752. // 从数据模板行获取正确的列数,而不是标题行(标题行可能是合并单元格)
  32753. int totalColumns = table.Rows[startIndex].Cells.Count;
  32754. _logger.LogInformation($"表格总列数: {totalColumns}(从第{startIndex}行获取)");
  32755. for (int imgIndex = 0; imgIndex < imageInfos.Count;)
  32756. {
  32757. var currentImg = imageInfos[imgIndex];
  32758. // 在当前行后插入新行(使用复制的模板行)
  32759. var newRow = copyRow.Clone(true) as Aspose.Words.Tables.Row;
  32760. table.Rows.Insert(startIndex + 1, newRow);
  32761. startIndex++; // 更新startIndex,因为插入了新行
  32762. // 重置所有单元格的合并状态(关键:清除克隆行的原有格式)
  32763. for (int col = 0; col < totalColumns; col++)
  32764. {
  32765. if (col < newRow.Cells.Count)
  32766. {
  32767. newRow.Cells[col].CellFormat.HorizontalMerge = CellMerge.None;
  32768. newRow.Cells[col].CellFormat.VerticalMerge = CellMerge.None;
  32769. }
  32770. }
  32771. if (currentImg.isWide)
  32772. {
  32773. _logger.LogInformation($"开始插入宽图 [{currentImg.url}],宽度: {currentImg.width}px");
  32774. // 宽图:先设置所有单元格的合并状态
  32775. for (int col = 0; col < totalColumns; col++)
  32776. {
  32777. if (col < newRow.Cells.Count)
  32778. {
  32779. var cell = newRow.Cells[col];
  32780. cell.RemoveAllChildren();
  32781. if (col == 0)
  32782. {
  32783. cell.CellFormat.HorizontalMerge = CellMerge.First;
  32784. }
  32785. else
  32786. {
  32787. cell.CellFormat.HorizontalMerge = CellMerge.Previous;
  32788. }
  32789. cell.CellFormat.PreferredWidth = PreferredWidth.Auto;
  32790. }
  32791. }
  32792. // 然后在第一个单元格插入图片
  32793. var firstCell = newRow.Cells[0];
  32794. var para = new Paragraph(doc);
  32795. para.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  32796. firstCell.AppendChild(para);
  32797. builder.MoveTo(para);
  32798. try
  32799. {
  32800. // 使用缓存的图片数据
  32801. byte[] imageBytes = currentImg.imageData;
  32802. if (imageBytes != null && imageBytes.Length > 0)
  32803. {
  32804. using (var imgStream = new MemoryStream(imageBytes))
  32805. {
  32806. // 插入图片,设置合理的宽度和最大高度
  32807. var shape = builder.InsertImage(imgStream);
  32808. // 使用预先获取的原始尺寸
  32809. double originalWidth = currentImg.width;
  32810. double originalHeight = currentImg.height;
  32811. // 设置最大宽度(约表格宽度的85%,避免超出)
  32812. double maxWidth = 380;
  32813. double maxHeight = 300; // 限制最大高度,避免图片过高
  32814. // 计算缩放比例
  32815. double widthScale = originalWidth > maxWidth ? maxWidth / originalWidth : 1;
  32816. double heightScale = originalHeight > maxHeight ? maxHeight / originalHeight : 1;
  32817. double scale = Math.Min(widthScale, heightScale);
  32818. shape.Width = originalWidth * scale;
  32819. shape.Height = originalHeight * scale;
  32820. _logger.LogInformation($"宽图插入成功,原始尺寸: {originalWidth}x{originalHeight}, 缩放后: {shape.Width:F0}x{shape.Height:F0},已合并 {totalColumns} 个单元格");
  32821. }
  32822. }
  32823. else
  32824. {
  32825. _logger.LogWarning($"图片数据为空");
  32826. para.AppendChild(new Run(doc, "[图片数据为空]"));
  32827. }
  32828. }
  32829. catch (Exception ex)
  32830. {
  32831. _logger.LogError(ex, $"插入宽图失败: {currentImg.url}");
  32832. para.AppendChild(new Run(doc, "[图片加载失败]"));
  32833. }
  32834. imgIndex++; // 处理下一张图片
  32835. }
  32836. else
  32837. {
  32838. _logger.LogInformation($"开始插入高图 [{currentImg.url}],高度: {currentImg.height}px");
  32839. // 高图:合并一半单元格
  32840. int halfColumns = totalColumns / 2;
  32841. _logger.LogInformation($"高图模式 - 前半部分列数: {halfColumns}, 后半部分列数: {totalColumns - halfColumns}");
  32842. // 先设置前一半单元格的合并状态
  32843. for (int col = 0; col < halfColumns; col++)
  32844. {
  32845. if (col < newRow.Cells.Count)
  32846. {
  32847. var cell = newRow.Cells[col];
  32848. cell.RemoveAllChildren();
  32849. if (col == 0)
  32850. {
  32851. cell.CellFormat.HorizontalMerge = CellMerge.First;
  32852. }
  32853. else
  32854. {
  32855. cell.CellFormat.HorizontalMerge = CellMerge.Previous;
  32856. }
  32857. cell.CellFormat.PreferredWidth = PreferredWidth.Auto;
  32858. }
  32859. }
  32860. // 设置后一半单元格的合并状态
  32861. for (int col = halfColumns; col < totalColumns; col++)
  32862. {
  32863. if (col < newRow.Cells.Count)
  32864. {
  32865. var cell = newRow.Cells[col];
  32866. cell.RemoveAllChildren();
  32867. if (col == halfColumns)
  32868. {
  32869. cell.CellFormat.HorizontalMerge = CellMerge.First;
  32870. }
  32871. else
  32872. {
  32873. cell.CellFormat.HorizontalMerge = CellMerge.Previous;
  32874. }
  32875. cell.CellFormat.PreferredWidth = PreferredWidth.Auto;
  32876. }
  32877. }
  32878. // 在第一个单元格插入第一张高图
  32879. var firstCell = newRow.Cells[0];
  32880. var para1 = new Paragraph(doc);
  32881. para1.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  32882. firstCell.AppendChild(para1);
  32883. builder.MoveTo(para1);
  32884. try
  32885. {
  32886. // 使用缓存的图片数据
  32887. byte[] imageBytes = currentImg.imageData;
  32888. if (imageBytes != null && imageBytes.Length > 0)
  32889. {
  32890. using (var imgStream = new MemoryStream(imageBytes))
  32891. {
  32892. var shape = builder.InsertImage(imgStream);
  32893. // 使用预先获取的原始尺寸
  32894. double originalWidth = currentImg.width;
  32895. double originalHeight = currentImg.height;
  32896. // 设置最大宽度和高度(约表格一半宽度)
  32897. double maxWidth = 180;
  32898. double maxHeight = 300; // 限制最大高度
  32899. // 计算缩放比例
  32900. double widthScale = originalWidth > maxWidth ? maxWidth / originalWidth : 1;
  32901. double heightScale = originalHeight > maxHeight ? maxHeight / originalHeight : 1;
  32902. double scale = Math.Min(widthScale, heightScale);
  32903. shape.Width = originalWidth * scale;
  32904. shape.Height = originalHeight * scale;
  32905. _logger.LogInformation($"第一张高图插入成功,原始尺寸: {originalWidth}x{originalHeight}, 缩放后: {shape.Width:F0}x{shape.Height:F0},已合并前 {halfColumns} 个单元格");
  32906. }
  32907. }
  32908. else
  32909. {
  32910. _logger.LogWarning($"图片数据为空");
  32911. para1.AppendChild(new Run(doc, "[图片数据为空]"));
  32912. }
  32913. }
  32914. catch (Exception ex)
  32915. {
  32916. _logger.LogError(ex, $"插入高图失败: {currentImg.url}");
  32917. para1.AppendChild(new Run(doc, "[图片加载失败]"));
  32918. }
  32919. imgIndex++; // 第一张高图已处理
  32920. // 检查是否还有下一张高图,如果有则插入到后一半单元格
  32921. if (imgIndex < imageInfos.Count && !imageInfos[imgIndex].isWide)
  32922. {
  32923. var secondCell = newRow.Cells[halfColumns];
  32924. var para2 = new Paragraph(doc);
  32925. para2.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  32926. secondCell.AppendChild(para2);
  32927. builder.MoveTo(para2);
  32928. try
  32929. {
  32930. var nextImg = imageInfos[imgIndex];
  32931. _logger.LogInformation($"开始插入第二张高图 [{nextImg.url}]");
  32932. // 使用缓存的图片数据
  32933. byte[] imageBytes = nextImg.imageData;
  32934. if (imageBytes != null && imageBytes.Length > 0)
  32935. {
  32936. using (var imgStream = new MemoryStream(imageBytes))
  32937. {
  32938. var shape = builder.InsertImage(imgStream);
  32939. // 使用预先获取的原始尺寸
  32940. double originalWidth = nextImg.width;
  32941. double originalHeight = nextImg.height;
  32942. // 设置最大宽度和高度
  32943. double maxWidth = 180;
  32944. double maxHeight = 300;
  32945. // 计算缩放比例
  32946. double widthScale = originalWidth > maxWidth ? maxWidth / originalWidth : 1;
  32947. double heightScale = originalHeight > maxHeight ? maxHeight / originalHeight : 1;
  32948. double scale = Math.Min(widthScale, heightScale);
  32949. shape.Width = originalWidth * scale;
  32950. shape.Height = originalHeight * scale;
  32951. _logger.LogInformation($"第二张高图插入成功,原始尺寸: {originalWidth}x{originalHeight}, 缩放后: {shape.Width:F0}x{shape.Height:F0},已合并后 {totalColumns - halfColumns} 个单元格");
  32952. }
  32953. }
  32954. else
  32955. {
  32956. _logger.LogWarning($"第二张高图数据为空");
  32957. para2.AppendChild(new Run(doc, "[图片数据为空]"));
  32958. }
  32959. imgIndex++; // 第二张高图已处理
  32960. }
  32961. catch (Exception ex)
  32962. {
  32963. _logger.LogError(ex, $"插入第二张高图失败");
  32964. para2.AppendChild(new Run(doc, "[图片加载失败]"));
  32965. }
  32966. }
  32967. }
  32968. }
  32969. }
  32970. }
  32971. }
  32972. startIndex++;
  32973. }
  32974. //替换书签
  32975. foreach (var key in bookmarks.Keys)
  32976. {
  32977. if (doc.Range.Bookmarks[key] != null)
  32978. {
  32979. Bookmark mark = doc.Range.Bookmarks[key];
  32980. mark.Text = bookmarks[key];
  32981. }
  32982. }
  32983. //去水印
  32984. new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String(AsposeHelper.asposeKey)));
  32985. //保存word
  32986. string fileName = $"活动验收报告_{di.TeamName}_{DateTime.Now:yyyyMMddHHmmss}.docx";
  32987. string filePath = $"InspectionReport/{fileName}";
  32988. string fullPath = AppSettingsHelper.Get("WordBasePath") + filePath;
  32989. //确保目录存在
  32990. string directory = Path.GetDirectoryName(fullPath);
  32991. if (!Directory.Exists(directory))
  32992. {
  32993. Directory.CreateDirectory(directory);
  32994. }
  32995. //保存文档
  32996. doc.Save(fullPath, Aspose.Words.SaveFormat.Docx);
  32997. //返回文件路径http
  32998. string url = AppSettingsHelper.Get("WordBaseUrl") + $"Office/Word/{filePath}";
  32999. return Ok(JsonView(true, "SUCCESS!", new { Url = url, FileName = fileName }));
  33000. }
  33001. /// <summary>
  33002. /// 会务成本保存
  33003. /// </summary>
  33004. /// <returns></returns>
  33005. [HttpPost]
  33006. public async Task<IActionResult> ConferenceAffairsSave(ConferenceAffairsSaveDto Dto)
  33007. {
  33008. _sqlSugar.BeginTran();
  33009. var data = _mapper.Map<Grp_ConferenceAffairsCost>(Dto.ConferenceAffairsCost);
  33010. var childResult = new
  33011. {
  33012. success = 0,
  33013. error = 0
  33014. };
  33015. try
  33016. {
  33017. if (data.Id == 0)
  33018. {
  33019. _sqlSugar.Updateable<Grp_ConferenceAffairsCost>()
  33020. .Where(x => x.Diid == Dto.GroupId)
  33021. .SetColumns(x => new Grp_ConferenceAffairsCost
  33022. {
  33023. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  33024. DeleteUserId = Dto.UserId
  33025. })
  33026. .ExecuteCommand();
  33027. data.Diid = Dto.GroupId;
  33028. data.CreateTime = DateTime.Now;
  33029. data.CreateUserId = Dto.UserId;
  33030. data.Id = _sqlSugar.Insertable<Grp_ConferenceAffairsCost>(data)
  33031. .ExecuteReturnIdentity();
  33032. }
  33033. else
  33034. {
  33035. _sqlSugar.Updateable<Grp_ConferenceAffairsCost>(data)
  33036. .ExecuteCommand();
  33037. data.Id = data.Id;
  33038. }
  33039. if (Dto.ConferenceAffairsCostChild.Any())
  33040. {
  33041. var datas = _mapper.Map<List<Grp_ConferenceAffairsCostChild>>(Dto.ConferenceAffairsCostChild);
  33042. var insertArr = datas.Where(x => x.Id == 0).ToList();
  33043. var updateArr = datas.Where(x => x.Id != 0 && x.ReviewStatus != 1).ToList();
  33044. var notUpdateArr = datas.Where(x => x.Id != 0 && x.ReviewStatus == 1).ToList();
  33045. insertArr.ForEach(x => { x.Diid = Dto.GroupId; x.ConferenceAffairsCostId = data.Id; });
  33046. var inrsetCount = insertArr.Any() ? _sqlSugar.Insertable<Grp_ConferenceAffairsCostChild>(insertArr).ExecuteCommand() : 0;
  33047. var updateCount = updateArr.Any() ? _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>(updateArr)
  33048. .IgnoreColumns(x => new { x.ConferenceAffairsCostId })
  33049. .ExecuteCommand() : 0;
  33050. childResult = childResult with
  33051. {
  33052. error = notUpdateArr.Count(),
  33053. success = inrsetCount + updateCount
  33054. };
  33055. }
  33056. _sqlSugar.CommitTran();
  33057. }
  33058. catch (Exception ex)
  33059. {
  33060. _sqlSugar.RollbackTran();
  33061. return Ok(JsonView(false, "失败!" + ex.Message));
  33062. }
  33063. return Ok(JsonView(true, "操作成功!", childResult));
  33064. }
  33065. [HttpPost]
  33066. public async Task<IActionResult> ConferenceAffairsAudit(ConferenceAffairsAuditDto Dto)
  33067. {
  33068. var count = 0;
  33069. if (Dto.ConferenceAffairsCostChildids.Any())
  33070. {
  33071. count = _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>().
  33072. Where(x => Dto.ConferenceAffairsCostChildids.Contains(x.Id)).
  33073. SetColumns(x => new Grp_ConferenceAffairsCostChild
  33074. {
  33075. ReviewStatus = Dto.ReviewStatus
  33076. }).
  33077. ExecuteCommand();
  33078. }
  33079. return Ok(JsonView(true, "操作成功!", count));
  33080. }
  33081. /// <summary>
  33082. /// 会务成本所有数据清除
  33083. /// </summary>
  33084. /// <param name="Dto"></param>
  33085. /// <returns></returns>
  33086. [HttpPost]
  33087. public async Task<IActionResult> ConferenceAffairsDelete(ConferenceAffairsDeleteDto Dto)
  33088. {
  33089. if (Dto.GroupId < 1) return Ok(JsonView(false, "请传入有效的Id"));
  33090. if (Dto.UserId < 1) return Ok(JsonView(false, "请传入有效的用户Id"));
  33091. _sqlSugar.BeginTran();
  33092. try
  33093. {
  33094. var delCount = _sqlSugar.Updateable<Grp_ConferenceAffairsCost>()
  33095. .Where(x => x.Diid == Dto.GroupId)
  33096. .SetColumns(x => new Grp_ConferenceAffairsCost
  33097. {
  33098. IsDel = 1,
  33099. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  33100. DeleteUserId = Dto.UserId
  33101. })
  33102. .ExecuteCommand();
  33103. if (delCount > 0)
  33104. {
  33105. _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>()
  33106. .Where(x => x.Diid == Dto.GroupId)
  33107. .SetColumns(x => new Grp_ConferenceAffairsCostChild
  33108. {
  33109. IsDel = 1,
  33110. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  33111. DeleteUserId = Dto.UserId
  33112. })
  33113. .ExecuteCommand();
  33114. _sqlSugar.Updateable<Grp_ConferenceAffairsCostControl>()
  33115. .Where(x => x.Diid == Dto.GroupId && x.IsDel == 0)
  33116. .SetColumns(x => new Grp_ConferenceAffairsCostControl
  33117. {
  33118. IsDel = 1,
  33119. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  33120. DeleteUserId = Dto.UserId
  33121. })
  33122. .ExecuteCommand();
  33123. }
  33124. _sqlSugar.CommitTran();
  33125. }
  33126. catch (Exception ex)
  33127. {
  33128. _sqlSugar.RollbackTran();
  33129. return Ok(JsonView(false, "操作失败!" + ex.Message));
  33130. }
  33131. return Ok(JsonView(true, "操作成功!"));
  33132. }
  33133. /// <summary>
  33134. /// 子项数据删除
  33135. /// </summary>
  33136. /// <param name="Dto"></param>
  33137. /// <returns></returns>
  33138. [HttpPost]
  33139. public async Task<IActionResult> ConferenceAffairSinglesDelete(ConferenceAffairsDeleteSingleDto Dto)
  33140. {
  33141. var isAudit = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>().Where(x => x.IsDel == 0 && Dto.ids.Contains(x.Id))
  33142. .Any(x => x.ReviewStatus == 1);
  33143. if (isAudit) return Ok(JsonView(false, "包含已审核数据无法删除!"));
  33144. var queryData = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  33145. .Where(x => x.IsDel == 0 && Dto.ids.Contains(x.Id))
  33146. .ToList();
  33147. //删除图片
  33148. foreach (var item in queryData)
  33149. {
  33150. if (!string.IsNullOrEmpty(item.Imgs))
  33151. {
  33152. var imgList = item.Imgs.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  33153. string baseUrl = AppSettingsHelper.Get("ConferenceCostImageBaseUrl");
  33154. string basePath = AppSettingsHelper.Get("ConferenceCostImageBasePath");
  33155. foreach (var imgUrl in imgList)
  33156. {
  33157. try
  33158. {
  33159. string localPath = "";
  33160. // 判断是否为完整URL
  33161. if (imgUrl.StartsWith("http://") || imgUrl.StartsWith("https://"))
  33162. {
  33163. // 尝试从URL转换为本地路径
  33164. if (imgUrl.Contains("/child/"))
  33165. {
  33166. var pathPart = imgUrl.Substring(imgUrl.IndexOf("/child/"));
  33167. localPath = Path.Combine(basePath, pathPart.TrimStart('/').Replace("/", "\\"));
  33168. }
  33169. }
  33170. else
  33171. {
  33172. // 文件名,构造本地路径
  33173. localPath = Path.Combine(basePath, "child", item.Index.ToString(), imgUrl);
  33174. }
  33175. if (!string.IsNullOrEmpty(localPath) && System.IO.File.Exists(localPath))
  33176. {
  33177. _logger.LogInformation($"-----------------------");
  33178. _logger.LogInformation($"删除图片: {localPath}");
  33179. System.IO.File.Delete(localPath);
  33180. _logger.LogInformation($"删除成功");
  33181. _logger.LogInformation($"-----------------------");
  33182. }
  33183. else
  33184. {
  33185. _logger.LogWarning($"图片文件不存在或路径为空: {imgUrl} -> {localPath}");
  33186. }
  33187. }
  33188. catch (Exception ex)
  33189. {
  33190. _logger.LogError(ex, $"删除图片失败: {imgUrl}");
  33191. }
  33192. }
  33193. }
  33194. }
  33195. var count = _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>()
  33196. .Where(x => Dto.ids.Contains(x.Id) && x.IsDel == 0)
  33197. .SetColumns(x => new Grp_ConferenceAffairsCostChild
  33198. {
  33199. IsDel = 1,
  33200. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  33201. DeleteUserId = Dto.UserId
  33202. })
  33203. .ExecuteCommand();
  33204. return Ok(JsonView(true, "SUCCESS!", count));
  33205. }
  33206. /// <summary>
  33207. /// 会务成本权限分配
  33208. /// </summary>
  33209. /// <param name="Dto"></param>
  33210. /// <returns></returns>
  33211. [HttpPost]
  33212. public async Task<IActionResult> PermissionSetting(PermissionSettingDto Dto)
  33213. {
  33214. _sqlSugar.BeginTran();
  33215. var count = 0;
  33216. try
  33217. {
  33218. _sqlSugar.Updateable<Grp_ConferenceAffairsCostControl>()
  33219. .Where(x => x.Diid == Dto.GroupId && x.IsDel == 0)
  33220. .SetColumns(x => new Grp_ConferenceAffairsCostControl
  33221. {
  33222. IsDel = 1,
  33223. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  33224. DeleteUserId = Dto.CreateUserId
  33225. })
  33226. .ExecuteCommand();
  33227. count = _sqlSugar.Insertable<Grp_ConferenceAffairsCostControl>(Dto.UserIds.Select(x => new Grp_ConferenceAffairsCostControl
  33228. {
  33229. CreateTime = DateTime.Now,
  33230. CreateUserId = Dto.CreateUserId,
  33231. UserId = x,
  33232. Diid = Dto.GroupId,
  33233. }).ToList()).ExecuteCommand();
  33234. _sqlSugar.CommitTran();
  33235. }
  33236. catch (Exception ex)
  33237. {
  33238. _sqlSugar.RollbackTran();
  33239. return Ok(JsonView(false, "操作失败!" + ex.Message));
  33240. }
  33241. return Ok(JsonView(true, "操作成功!", count));
  33242. }
  33243. /// <summary>
  33244. /// 团组会务成本文件下载
  33245. /// </summary>
  33246. /// <returns></returns>
  33247. [HttpPost]
  33248. public async Task<IActionResult> ConferenceAffairsFileDown(ConferenceAffairsFileDownDto Dto)
  33249. {
  33250. var FileType = new[]
  33251. {
  33252. new { Id = 0 , Name = "成本下载" },
  33253. new { Id = 1 , Name = "报价下载" },
  33254. new { Id = 2 , Name = "总表下载" },
  33255. };
  33256. if (Dto.GroupId < 1) return Ok(JsonView(false, "请传入有效的Id"));
  33257. if (Dto.FileTypeId < 0 || Dto.FileTypeId > 2) return Ok(JsonView(false, "请传入有效的文件类型"));
  33258. var di = _sqlSugar.Queryable<Grp_DelegationInfo>()
  33259. .Where(x => x.IsDel == 0 && x.Id == Dto.GroupId)
  33260. .Select<DelegationEasyView>()
  33261. .First();
  33262. var main = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
  33263. .First(x => x.Diid == Dto.GroupId && x.IsDel == 0);
  33264. if (main == null)
  33265. {
  33266. return Ok(JsonView(false, "团组会务成本信息不存在!"));
  33267. }
  33268. JsonView jw = JsonView(false);
  33269. //总表下载
  33270. var loadPath = $"{AppSettingsHelper.Get("ExcelBasePath")}ConferenceAffairs/template/";
  33271. var outputPath = $"{AppSettingsHelper.Get("ExcelBasePath")}ConferenceAffairs/output/total/";
  33272. var networkPath = outputPath.Replace(AppSettingsHelper.Get("ExcelBasePath"), AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath"));
  33273. var field = string.Empty;
  33274. var fileTypeName = string.Empty;
  33275. field = @$"
  33276. a.[Index],a.PriceName,a.CostPrice,a.Count,a.Coefficient,a.BaoJiaPrice,a.AddedValue,a.Details,a.Remark,a.Rate,
  33277. b.Name as PriceTypeStr ,
  33278. c.Name as CurrencyStr ,
  33279. d.Name as UnitStr ,
  33280. case a.ReviewStatus
  33281. WHEN 1 THEN '已通过'
  33282. WHEN 0 THEN '未审核'
  33283. WHEN -1 THEN '未通过'
  33284. ELSE '未审核'
  33285. END AS ReviewStatusStr
  33286. ";
  33287. if (Dto.FileTypeId == 0)
  33288. {
  33289. fileTypeName = "会务成本成本表";
  33290. loadPath += $"{fileTypeName}.xlsx";
  33291. outputPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  33292. networkPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  33293. }
  33294. else if (Dto.FileTypeId == 1)
  33295. {
  33296. fileTypeName = "会务成本报价表";
  33297. loadPath += $"{fileTypeName}.xlsx";
  33298. outputPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  33299. networkPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  33300. }
  33301. else if (Dto.FileTypeId == 2)
  33302. {
  33303. fileTypeName = "会务成本总表";
  33304. loadPath += $"{fileTypeName}.xlsx";
  33305. outputPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  33306. networkPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  33307. }
  33308. var chiExcelContent = _sqlSugar.SqlQueryable<ConferenceAffairsExcelContent>(@$"
  33309. SELECT
  33310. {field}
  33311. FROM Grp_ConferenceAffairsCostChild a
  33312. LEFT JOIN Sys_SetData b on b.IsDel = 0 AND b.Id = a.PriceType
  33313. LEFT JOIN Sys_SetData c on c.IsDel = 0 AND c.Id = a.Currency
  33314. LEFT JOIN Sys_SetData d on d.IsDel = 0 AND d.Id = a.Unit
  33315. WHERE a.isdel = 0
  33316. AND a.Diid = {main.Diid}
  33317. AND a.ConferenceAffairsCostId = {main.Id}
  33318. ").ToList();
  33319. var currLists = chiExcelContent.Select(x => new CurrList
  33320. {
  33321. CurrName = x.CurrencyStr,
  33322. CurrRate = x.Rate
  33323. })
  33324. .Distinct()
  33325. .ToList();
  33326. var designer = new WorkbookDesigner
  33327. {
  33328. Workbook = new Workbook(loadPath)
  33329. };
  33330. var MostCurr = _sqlSugar.Queryable<Sys_SetData>().First(x => x.IsDel == 0 && x.Id == main.MostCurr);
  33331. MostCurr ??= new Sys_SetData { Name = "暂无!" };
  33332. designer.SetDataSource("TeamName", di.TeamName);
  33333. designer.SetDataSource("City", main.City);
  33334. designer.SetDataSource("AllCost", main.CostAll);
  33335. designer.SetDataSource("AllBaoJia", main.BaoJiaAll);
  33336. designer.SetDataSource("Curr", MostCurr.Name);
  33337. designer.SetDataSource("Curr1", MostCurr.Name);
  33338. DataTable dt = CommonFun.GetDataTableFromIList<ConferenceAffairsExcelContent>(chiExcelContent);
  33339. dt.TableName = "TB";
  33340. designer.SetDataSource(dt);
  33341. DataTable dt1 = CommonFun.GetDataTableFromIList<CurrList>(currLists);
  33342. dt1.TableName = "currTb";
  33343. designer.SetDataSource(dt1);
  33344. designer.Process();
  33345. designer.Workbook.Save(outputPath);
  33346. jw = JsonView(true, "操作成功!", new
  33347. {
  33348. FileName = $"{di.TeamName}_{fileTypeName}.xlsx",
  33349. FilePath = networkPath
  33350. });
  33351. return Ok(jw);
  33352. }
  33353. [HttpPost]
  33354. public async Task<IActionResult> QueryConferenceAffairsChild(QueryConferenceAffairsChildDto Dto)
  33355. {
  33356. return Ok(JsonView(true, "SUCCESS", _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>().Where(x => x.IsDel == 0 && x.Diid == Dto.GroupId)
  33357. .Select(x => x.PriceName).ToList()));
  33358. }
  33359. #endregion
  33360. #region 会务流程
  33361. /// <summary>
  33362. /// 会务流程 - 团组列表
  33363. /// </summary>
  33364. /// <returns>团组基本信息、团组列表和会务基本信息列表</returns>
  33365. [HttpGet]
  33366. public async Task<IActionResult> ConferenceProceduresGroupNames()
  33367. {
  33368. var conferenceTypeIds = new List<int>() {
  33369. 302, // 成都-会务活动
  33370. 691 // 四川-会务活动
  33371. };
  33372. var groupList = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  33373. .Where(x => x.IsDel == 0)
  33374. .Where(x => conferenceTypeIds.Contains(x.TeamDid))
  33375. .OrderByDescending(x => x.VisitDate)
  33376. .Select(x => new
  33377. {
  33378. x.Id,
  33379. x.TeamName,
  33380. HasChildData = SqlFunc.Subqueryable<Grp_ConferenceProcedures>()
  33381. .Where(child => child.DiId == x.Id) // 替换关联条件
  33382. .Any() // 判断子表是否存在数据
  33383. })
  33384. .ToListAsync();
  33385. return Ok(JsonView(true, "SUCCESS", groupList));
  33386. }
  33387. /// <summary>
  33388. /// 会务流程 - 数据初始化
  33389. /// </summary>
  33390. /// <param name="dto"></param>
  33391. /// <returns>团组基本信息、团组列表和会务基本信息列表</returns>
  33392. [HttpPost]
  33393. public async Task<IActionResult> ConferenceProceduresInit(ConferenceProceduresInitDto dto)
  33394. {
  33395. try
  33396. {
  33397. var conferenceTypeIds = new List<int>() {
  33398. 302, // 成都-会务活动
  33399. 691 // 四川-会务活动
  33400. };
  33401. Grp_DelegationInfo targetGroup = null;
  33402. targetGroup = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  33403. .Where(x => x.Id == dto.GroupId && x.IsDel == 0)
  33404. .FirstAsync();
  33405. if (targetGroup == null)
  33406. {
  33407. targetGroup = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  33408. .Where(x => x.IsDel == 0)
  33409. .Where(x => conferenceTypeIds.Contains(x.TeamDid))
  33410. .OrderByDescending(x => x.VisitDate)
  33411. .FirstAsync();
  33412. }
  33413. if (targetGroup == null)
  33414. {
  33415. return Ok(JsonView(false, "未找到任何团组信息"));
  33416. }
  33417. var groupList = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  33418. .Where(x => x.IsDel == 0)
  33419. .Where(x => conferenceTypeIds.Contains(x.TeamDid))
  33420. .OrderByDescending(x => x.VisitDate)
  33421. .Select(x => new
  33422. {
  33423. x.Id,
  33424. x.TeamName,
  33425. HasChildData = SqlFunc.Subqueryable<Grp_ConferenceProcedures>()
  33426. .Where(child => child.DiId == x.Id)
  33427. .Any() // 判断子表是否存在数据
  33428. })
  33429. .ToListAsync();
  33430. var conferenceProceduresList = await _sqlSugar.Queryable<Grp_ConferenceProcedures>()
  33431. .Where(x => x.DiId == targetGroup.Id && x.IsDel == 0)
  33432. .Select(x => new { x.Id, x.Title, x.DataDetails, x.Details, x.Remark })
  33433. .ToListAsync();
  33434. if (!conferenceProceduresList.Any())
  33435. {
  33436. conferenceProceduresList = await _sqlSugar.Queryable<Grp_ConferenceProcedures>()
  33437. .Where(x => x.DiId == -1 && x.IsDel == 0)
  33438. .Select(x => new { x.Id, x.Title, x.DataDetails, x.Details, x.Remark })
  33439. .ToListAsync();
  33440. }
  33441. var conferenceProceduresGroupByTitle = conferenceProceduresList
  33442. .GroupBy(x => x.Title)
  33443. .Select(x => new
  33444. {
  33445. title = x.Key,
  33446. itmes = x.Select(y => new
  33447. {
  33448. y.Id,
  33449. y.DataDetails,
  33450. y.Details,
  33451. y.Remark
  33452. }).ToList()
  33453. })
  33454. .ToList();
  33455. var response = new
  33456. {
  33457. GroupInfo = new
  33458. {
  33459. targetGroup.Id,
  33460. targetGroup.TeamName,
  33461. targetGroup.VisitDate,
  33462. targetGroup.VisitDays,
  33463. targetGroup.VisitPNumber,
  33464. targetGroup.VisitCountry,
  33465. targetGroup.VisitStartDate,
  33466. targetGroup.VisitEndDate,
  33467. targetGroup.ClientName,
  33468. targetGroup.ClientUnit
  33469. },
  33470. GroupList = groupList,
  33471. ConferenceProceduresList = conferenceProceduresList,
  33472. conferenceProceduresGroupByTitle = conferenceProceduresGroupByTitle
  33473. };
  33474. return Ok(JsonView(true, "SUCCESS", response));
  33475. }
  33476. catch (Exception ex)
  33477. {
  33478. _logger.LogError(ex, "数据初始化失败");
  33479. return Ok(JsonView(false, $"ERROR:{ex.Message}"));
  33480. }
  33481. }
  33482. /// <summary>
  33483. /// 会务流程 - 保存
  33484. /// </summary>
  33485. /// <param name="dto"></param>
  33486. /// <returns></returns>
  33487. [HttpPost]
  33488. public async Task<IActionResult> ConferenceProceduresSave(ConferenceProceduresSaveDto dto)
  33489. {
  33490. _sqlSugar.BeginTran();
  33491. try
  33492. {
  33493. //删除旧数据
  33494. _sqlSugar.Updateable<Grp_ConferenceProcedures>()
  33495. .Where(x => x.DiId == dto.GroupId && x.IsDel == 0)
  33496. .SetColumns(x => new Grp_ConferenceProcedures
  33497. {
  33498. IsDel = 1,
  33499. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  33500. DeleteUserId = dto.UserId
  33501. })
  33502. .ExecuteCommand();
  33503. //添加新数据
  33504. var newData = new List<Grp_ConferenceProcedures>();
  33505. foreach (var item in dto.ConferenceProceduresSaveItem)
  33506. {
  33507. foreach (var item2 in item.itmes)
  33508. {
  33509. newData.Add(new Grp_ConferenceProcedures
  33510. {
  33511. DiId = dto.GroupId,
  33512. Title = item.title,
  33513. DataDetails = item2.DataDetails,
  33514. Details = item2.details,
  33515. Remark = item2.Remark,
  33516. CreateTime = DateTime.Now,
  33517. CreateUserId = dto.UserId
  33518. });
  33519. }
  33520. }
  33521. _sqlSugar.Insertable(newData).ExecuteCommand();
  33522. _sqlSugar.CommitTran();
  33523. }
  33524. catch (Exception ex)
  33525. {
  33526. _sqlSugar.RollbackTran();
  33527. return Ok(JsonView(false, $"ERROR:{ex.Message}"));
  33528. }
  33529. return Ok(JsonView(true, "SUCCESS"));
  33530. }
  33531. [HttpPost]
  33532. public async Task<IActionResult> ConferenceProceduresFileDown(ConferenceProceduresFileDownDto dto)
  33533. {
  33534. var jw = JsonView(false, "团组信息不存在");
  33535. jw.Data = string.Empty;
  33536. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  33537. .Where(x => x.Id == dto.GroupId && x.IsDel == 0)
  33538. .FirstAsync();
  33539. if (groupInfo == null)
  33540. {
  33541. return Ok(jw);
  33542. }
  33543. var conferenceProceduresList = await _sqlSugar.Queryable<Grp_ConferenceProcedures>()
  33544. .Where(x => x.DiId == dto.GroupId && x.IsDel == 0)
  33545. .ToListAsync();
  33546. if (!conferenceProceduresList.Any())
  33547. {
  33548. jw.Msg = "会务流程信息不存在";
  33549. return Ok(jw);
  33550. }
  33551. var filePath = $"{AppSettingsHelper.Get("ExcelBasePath")}Template/会务流程.xlsx";
  33552. if (!System.IO.File.Exists(filePath))
  33553. {
  33554. jw.Msg = "模板文件不存在";
  33555. return Ok(jw);
  33556. }
  33557. var designer = new WorkbookDesigner();
  33558. designer.Workbook = new Workbook(filePath);
  33559. designer.SetDataSource("TB", conferenceProceduresList);
  33560. designer.Process();
  33561. var sheet = designer.Workbook.Worksheets[0];
  33562. var cells = sheet.Cells;
  33563. int col = 0; // 第一列
  33564. int startRow = 2; // 若第0行为表头,则从第1行开始;无表头请改为0
  33565. int endRow = cells.MaxDataRow;
  33566. if (endRow >= startRow)
  33567. {
  33568. int mergeStart = startRow;
  33569. string prev = cells[mergeStart, col].StringValue?.Trim() ?? string.Empty;
  33570. for (int r = startRow + 1; r <= endRow; r++)
  33571. {
  33572. string cur = cells[r, col].StringValue?.Trim() ?? string.Empty;
  33573. if (!string.Equals(cur, prev, StringComparison.Ordinal))
  33574. {
  33575. int count = r - mergeStart;
  33576. if (count > 1)
  33577. cells.Merge(mergeStart, col, count, 1);
  33578. mergeStart = r;
  33579. prev = cur;
  33580. }
  33581. }
  33582. int tailCount = endRow - mergeStart + 1;
  33583. if (tailCount > 1)
  33584. cells.Merge(mergeStart, col, tailCount, 1);
  33585. }
  33586. // byte[] bytes = null;
  33587. // using (MemoryStream stream = new MemoryStream())
  33588. // {
  33589. // designer.Workbook.Save(stream, Aspose.Cells.SaveFormat.Xlsx);
  33590. // bytes = stream.ToArray();
  33591. // }
  33592. // return File(bytes, "application/excel", $"{groupInfo.TeamName}_会务流程.xlsx");
  33593. string savePath = $"{AppSettingsHelper.Get("ExcelBasePath")}ConferenceProcedures";
  33594. if (!System.IO.Directory.Exists(savePath))
  33595. {
  33596. System.IO.Directory.CreateDirectory(savePath);
  33597. }
  33598. designer.Workbook.Save($"{savePath}/{groupInfo.TeamName}_会务流程.xlsx");
  33599. string rst = savePath.replace(AppSettingsHelper.Get("ExcelBasePath"),
  33600. AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath"));
  33601. return Ok(JsonView(true, "SUCCESS", $"{rst}/{groupInfo.TeamName}_会务流程.xlsx"));
  33602. }
  33603. #endregion
  33604. #region 团组签证流程
  33605. /// <summary>
  33606. /// 团组签证流程 - 团组列表(分页)
  33607. /// </summary>
  33608. /// <returns></returns>
  33609. [HttpPost]
  33610. public async Task<IActionResult> VisaProcessGroupNames(VisaProcessGroupNamesDto dto)
  33611. {
  33612. int currUserId = dto.CurrUserId <= 0 ? 1 : dto.CurrUserId;
  33613. string groupName = dto.GroupName.Trim();
  33614. int pageIndex = dto.PageIndex <= 0 ? 1 : dto.PageIndex;
  33615. int pageSize = dto.PageSize <= 0 ? 10 : dto.PageSize;
  33616. int portType = dto.PortType;
  33617. RefAsync<int> total = 0;
  33618. var query = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>()
  33619. .InnerJoin<Grp_DelegationInfo>((x, y) => x.DIId == y.Id)
  33620. .InnerJoin<Grp_VisaProcessSteps>((x, y, z) => x.DIId == z.GroupId)
  33621. .Where((x, y, z) => x.IsDel == 0 && x.CTId == 80 && x.UId == currUserId && z.IsDel == 0);
  33622. //构建单字模糊查询
  33623. if (!string.IsNullOrEmpty(groupName))
  33624. {
  33625. var characters = groupName.ToCharArray();
  33626. foreach (var character in characters)
  33627. {
  33628. var charString = character.ToString();
  33629. query = query.Where((x, y) =>
  33630. SqlFunc.Contains(y.TeamName, charString));
  33631. }
  33632. }
  33633. var groups = await query
  33634. .OrderByDescending((x, y) => y.VisitDate)
  33635. .Select((x, y) => new
  33636. {
  33637. y.Id,
  33638. GroupName = y.TeamName,
  33639. y.VisitDate,
  33640. // 加入子查询统计子表条数
  33641. CompletedCount = SqlFunc.Subqueryable<Grp_VisaProcessSteps>()
  33642. .Where(sub => sub.GroupId == y.Id && sub.IsCompleted && sub.IsDel == 0)
  33643. .Count()
  33644. })
  33645. .Distinct()
  33646. .ToPageListAsync(pageIndex, pageSize, total);
  33647. var msg = "SUCCESS";
  33648. if (total <= 0) msg = "暂无可操作的团组,请联系经理分配团组!";
  33649. var groups1 = groups.Select(x => new
  33650. {
  33651. x.Id,
  33652. x.GroupName,
  33653. x.CompletedCount
  33654. }).ToList();
  33655. return Ok(JsonView(true, msg, groups1, total));
  33656. }
  33657. /// <summary>
  33658. /// 团组签证流程 - 详情
  33659. /// </summary>
  33660. /// <returns></returns>
  33661. [HttpPost]
  33662. public async Task<IActionResult> VisaProcessInfoByGroupId(VisaProcessInfoByGroupIdDto dto)
  33663. {
  33664. var res = await _visaProcessRep.Info(dto);
  33665. if (res.Code != 200) return Ok(JsonView(false, res.Msg));
  33666. return Ok(JsonView(true, res.Msg, res.Data));
  33667. }
  33668. /// <summary>
  33669. /// 团组签证流程 - 流程创建测试
  33670. /// </summary>
  33671. /// <returns></returns>
  33672. [HttpPost]
  33673. public async Task<IActionResult> VisaProcessAdd(int groupId, int currUserId)
  33674. {
  33675. return Ok(await _visaProcessRep.Create(currUserId, groupId));
  33676. }
  33677. /// <summary>
  33678. /// 团组签证流程 - 流程Top4Init 测试
  33679. /// </summary>
  33680. /// <returns></returns>
  33681. [HttpPost]
  33682. public async Task<IActionResult> VisaProcessTop4StepInit(int groupId, int currUserId)
  33683. {
  33684. return Ok(await _visaProcessRep.UpdateBatchTop4Step(groupId, currUserId));
  33685. }
  33686. /// <summary>
  33687. /// 团组签证流程 - 设置状态 完成/未完成
  33688. /// </summary>
  33689. /// <returns></returns>
  33690. [HttpPost]
  33691. public async Task<IActionResult> VisaProcessSetCompleted(VisaProcessSetCompletedDto dto)
  33692. {
  33693. //参数验证
  33694. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.Id == dto.StepId && x.IsDel == 0).AnyAsync();
  33695. if (!stepValid) return Ok(JsonView(false, "签证流程ID无效。"));
  33696. var userValid = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == dto.CurrUserId && x.IsDel == 0).AnyAsync();
  33697. if (!userValid) return Ok(JsonView(false, "用户ID无效。"));
  33698. var res = await _visaProcessRep.SetCompleted(dto.StepId, dto.CurrUserId, dto.IsCompleted);
  33699. if (res.Code != 200) return Ok(JsonView(false, res.Msg));
  33700. return Ok(JsonView(true, res.Msg));
  33701. }
  33702. /// <summary>
  33703. /// 团组签证流程 - 修改各步骤内容
  33704. /// </summary>
  33705. /// <returns></returns>
  33706. [HttpPost]
  33707. public async Task<IActionResult> VisaProcessSetContent(VisaProcessSetContent dto)
  33708. {
  33709. //参数验证
  33710. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.Id == dto.StepId && x.IsDel == 0).FirstAsync();
  33711. if (stepValid == null) return Ok(JsonView(false, "签证流程ID无效。"));
  33712. var userValid = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == dto.CurrUserId && x.IsDel == 0).AnyAsync();
  33713. if (!userValid) return Ok(JsonView(false, "用户ID无效。"));
  33714. if (dto.StepContents == null && dto.StepContents.Count < 1)
  33715. {
  33716. return Ok(JsonView(false, "步骤内容无效。"));
  33717. }
  33718. //各步骤值处理
  33719. object stepVal;
  33720. if (stepValid.Step == 7) stepVal = dto.StepContents;
  33721. else stepVal = dto.StepContents[0].ToString();
  33722. var stepInfo = new Grp_VisaProcessSteps
  33723. {
  33724. Id = dto.StepId,
  33725. DataType = stepValid.DataType,
  33726. TypedValue = stepVal,
  33727. LastUpdateUserId = dto.CurrUserId
  33728. };
  33729. var res = await _visaProcessRep.Update(stepInfo);
  33730. if (res.Code != 200) return Ok(JsonView(false, res.Msg));
  33731. return Ok(JsonView(true, res.Msg));
  33732. }
  33733. /// <summary>
  33734. /// 团组签证流程 - 上传文件
  33735. /// </summary>
  33736. /// <returns></returns>
  33737. [HttpPost]
  33738. public async Task<IActionResult> VisaProcessUploadFiles([FromForm] VisaProcessUploadFilesDto dto)
  33739. {
  33740. //参数验证
  33741. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.Id == dto.StepId && x.IsDel == 0).FirstAsync();
  33742. if (stepValid == null) return Ok(JsonView(false, "签证流程ID无效。"));
  33743. var before = stepValid;
  33744. var userValid = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == dto.CurrUserId && x.IsDel == 0).AnyAsync();
  33745. if (!userValid) return Ok(JsonView(false, "用户ID无效。"));
  33746. //验证文件是否存在
  33747. if (dto.Files == null || dto.Files.Count < 1) return Ok(JsonView(false, "请选择文件。"));
  33748. //验证该步骤是否可以上传文件
  33749. var uploadSteps = new List<int>() {
  33750. 5, //实际出签时间
  33751. 6, //是否需要开出境证明
  33752. 7, //是否需要办理电子入境卡手续
  33753. };
  33754. if (!uploadSteps.Contains(stepValid.Step))
  33755. {
  33756. return Ok(JsonView(false, $"该步骤不可上传附件。可上传附件步骤({string.Join("、", uploadSteps)})"));
  33757. }
  33758. //验证根目录
  33759. string rootRrl = AppSettingsHelper.Get("OfficeBaseUrl");
  33760. string rootPath = AppSettingsHelper.Get("OfficeTempBasePath");
  33761. if (!System.IO.Directory.Exists(rootPath))
  33762. {
  33763. System.IO.Directory.CreateDirectory(rootPath);
  33764. }
  33765. //验证签证流程上传文件夹 //按照团组名称存储文件夹 GrpFile/VisaProcessFiles/
  33766. var groupName = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  33767. .Where(x => x.IsDel == 0 && x.Id == stepValid.GroupId)
  33768. .Select(x => $"{x.TeamName}({x.Id})")
  33769. .FirstAsync();
  33770. //创建团组文件夹
  33771. var groupPath = rootPath + "GrpFile/VisaProcessFiles/" + groupName;
  33772. if (!System.IO.Directory.Exists(groupPath))
  33773. {
  33774. System.IO.Directory.CreateDirectory(groupPath);
  33775. }
  33776. List<string> filePaths = new List<string>();
  33777. //保存文件
  33778. foreach (var file in dto.Files)
  33779. {
  33780. // 生成存储文件名
  33781. var fileName = CommonFun.GenerateStoredFileName($"Step{stepValid.Step}.{file.FileName.Split(".")[1]}");
  33782. var filePath = Path.Combine(groupPath, fileName);
  33783. // 保存文件到磁盘
  33784. using (var stream = new FileStream(filePath, FileMode.Create))
  33785. {
  33786. await file.CopyToAsync(stream);
  33787. }
  33788. filePaths.Add($"GrpFile/VisaProcessFiles/{groupName}/{fileName}");
  33789. }
  33790. //数据库存储
  33791. stepValid.TypedFileNameValue = filePaths;
  33792. stepValid.LastUpdateUserId = dto.CurrUserId;
  33793. stepValid.LastUpdateTime = DateTime.Now;
  33794. var res = await _sqlSugar.Updateable(stepValid)
  33795. .UpdateColumns(it => new { it.TypedFileNameValue, it.LastUpdateUserId, it.LastUpdateTime })
  33796. .Where(s => s.Id == dto.StepId && s.IsDel == 0)
  33797. .ExecuteCommandAsync();
  33798. if (res < 1) Ok(JsonView(false, "文件上传失败。"));
  33799. //记录上传文件
  33800. await _visaProcessRep.LogOperationAsync(before, stepValid, "Upload", dto.CurrUserId);
  33801. return Ok(JsonView(true));
  33802. }
  33803. /// <summary>
  33804. /// 团组签证流程 - step 7 资料下载
  33805. /// </summary>
  33806. /// <returns></returns>
  33807. [HttpGet]
  33808. public async Task<IActionResult> VisaProcessDownload(int groupId, int currUserId)
  33809. {
  33810. var userValid = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == currUserId && x.IsDel == 0).AnyAsync();
  33811. if (!userValid) return Ok(JsonView(false, "用户ID无效。"));
  33812. //验证根目录
  33813. string rootRrl = AppSettingsHelper.Get("OfficeBaseUrl");
  33814. string rootPath = AppSettingsHelper.Get("OfficeTempBasePath");
  33815. if (!System.IO.Directory.Exists(rootPath))
  33816. {
  33817. System.IO.Directory.CreateDirectory(rootPath);
  33818. }
  33819. //验证签证流程上传文件夹 //按照团组名称存储文件夹 GrpFile/VisaProcessFiles/
  33820. var groupName = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  33821. .Where(x => x.IsDel == 0 && x.Id == groupId)
  33822. .Select(x => $"{x.TeamName}({x.Id})")
  33823. .FirstAsync();
  33824. //创建团组文件夹
  33825. var timestamp = DateTime.Now.ToString("yyyyMMddHHmmss");
  33826. var randomStr = Guid.NewGuid().ToString("N").Substring(0, 8);
  33827. var dirName = $"{groupName}_相关资料_{timestamp}";
  33828. var sourceDirectoryPath = $"{rootPath}/GrpFile/VisaProcessFiles/{groupName}";
  33829. var path = $"{rootPath}/GrpFile/VisaProcessFiles/{groupName}/{dirName}";
  33830. if (!System.IO.Directory.Exists(path))
  33831. {
  33832. System.IO.Directory.CreateDirectory(path);
  33833. }
  33834. //验证接团客户名单
  33835. string sql = string.Format(@"
  33836. SELECT
  33837. tcl.Id,
  33838. tcl.DiId,
  33839. tcl.IsAccompany,
  33840. temp.*,
  33841. u.CnName AS Operator,
  33842. tcl.CreateTime AS OperatingTime,
  33843. ssd.name AS ShippingSpaceType
  33844. FROM
  33845. Grp_TourClientList tcl
  33846. LEFT JOIN (
  33847. SELECT
  33848. dc.Id AS DcId,
  33849. dc.LastName,
  33850. dc.FirstName,
  33851. ccom.CompanyFullName,
  33852. dc.Job,
  33853. cc.CertNo AS IDCardNo,
  33854. dc.Sex,
  33855. dc.BirthDay
  33856. FROM
  33857. Crm_DeleClient dc
  33858. LEFT JOIN Crm_CustomerCompany ccom ON dc.CrmCompanyId = ccom.Id
  33859. AND ccom.IsDel = 0
  33860. LEFT JOIN Crm_CustomerCert cc ON dc.Id = cc.DcId
  33861. AND cc.SdId = 773
  33862. AND cc.IsDel = 0
  33863. WHERE
  33864. dc.IsDel = 0
  33865. ) temp ON temp.DcId = tcl.ClientId
  33866. LEFT JOIN Sys_Users u ON tcl.CreateUserId = u.Id
  33867. LEFT JOIN sys_setdata ssd ON ssd.isdel = 0 AND ssd.id = tcl.ShippingSpaceTypeid
  33868. WHERE
  33869. tcl.IsDel = 0
  33870. AND tcl.DiId = {0}", groupId);
  33871. var groupClientList = await _sqlSugar.SqlQueryable<TourClientInfosView>(sql).ToListAsync();
  33872. //解密
  33873. foreach (var item in groupClientList)
  33874. {
  33875. EncryptionProcessor.DecryptProperties(item);
  33876. }
  33877. if (groupClientList == null || groupClientList.Count < 1)
  33878. {
  33879. return Ok(JsonView(false, $"团组客户名单未录入客户信息,不可生成相关资料。"));
  33880. }
  33881. #region 生成文件
  33882. //酒店信息
  33883. var hotelInfos = await _sqlSugar.Queryable<Grp_HotelReservations>()
  33884. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  33885. .OrderBy(x => x.CheckInDate)
  33886. .ToListAsync();
  33887. //航班信息
  33888. var airInfos = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  33889. .Where(x => x.IsDel == 0 && x.DIId == groupId)
  33890. .OrderBy(x => x.FlightsDate)
  33891. .ToListAsync();
  33892. foreach (var clientInfo in groupClientList)
  33893. {
  33894. var clientId = clientInfo.DcId;
  33895. var guestName = $"{clientInfo.LastName}{clientInfo.FirstName}";
  33896. #region 个人信息资料
  33897. #endregion
  33898. #region 机票航班信息
  33899. var clientAirInfos = airInfos.Where(x => x.ClientName.Contains(clientId.ToString())).ToList();
  33900. if (clientAirInfos != null && clientAirInfos.Count > 0)
  33901. {
  33902. //创建表格
  33903. Document airDoc = new Document();
  33904. DocumentBuilder airBuilder = new DocumentBuilder(airDoc);
  33905. GeneralMethod.SetupDocumentStyles(airBuilder);
  33906. GeneralMethod.AddTitle(airBuilder, $"{guestName} - 机票信息");
  33907. GeneralMethod.AddAirInfoSections(airBuilder, clientAirInfos, "机票航班信息");
  33908. var airRandomStr = Guid.NewGuid().ToString("N").Substring(0, 8);
  33909. var airFileName = $"{guestName}_机票信息_{airRandomStr}.docx";
  33910. airDoc.Save($"{path}/{airFileName}");
  33911. }
  33912. #endregion
  33913. #region 酒店信息
  33914. var clientHotelInfos = hotelInfos.Where(x => x.GuestName.Contains(clientId.ToString())).ToList();
  33915. if (clientHotelInfos != null && clientHotelInfos.Count > 0)
  33916. {
  33917. //创建表格
  33918. Document hotelDoc = new Document();
  33919. DocumentBuilder HotelBuilder = new DocumentBuilder(hotelDoc);
  33920. GeneralMethod.SetupDocumentStyles(HotelBuilder);
  33921. GeneralMethod.AddTitle(HotelBuilder, $"{guestName} - 酒店信息");
  33922. GeneralMethod.AddHotelInfoSections(HotelBuilder, clientHotelInfos, "酒店信息");
  33923. var hotelRandomStr = Guid.NewGuid().ToString("N").Substring(0, 8);
  33924. var hotelFileName = $"{guestName}_酒店信息_{hotelRandomStr}.docx";
  33925. hotelDoc.Save($"{path}/{hotelFileName}");
  33926. }
  33927. #endregion
  33928. }
  33929. #endregion
  33930. //打包文件夹
  33931. var sourceDirectory = $"{sourceDirectoryPath}/{dirName}";
  33932. var zipFilePath = $"{sourceDirectoryPath}/{dirName}.zip";
  33933. if (System.IO.File.Exists(zipFilePath))
  33934. {
  33935. System.IO.File.Delete(zipFilePath);
  33936. }
  33937. ZipFile.CreateFromDirectory(sourceDirectory, zipFilePath, CompressionLevel.Fastest, false);
  33938. // 等待并验证
  33939. await Task.Delay(100); // 给系统时间完成文件操作
  33940. if (System.IO.File.Exists(zipFilePath))
  33941. {
  33942. var fileInfo = new FileInfo(zipFilePath);
  33943. var url = $"{rootRrl}Office/GrpFile/VisaProcessFiles/{groupName}/{dirName}.zip";
  33944. //记录下载日志
  33945. await _visaProcessRep.LogOperationAsync(null, null, "Download", currUserId);
  33946. return Ok(JsonView(StatusCodes.Status200OK, "操作成功!", url));
  33947. }
  33948. return Ok(JsonView(false));
  33949. }
  33950. /// <summary>
  33951. /// 团组签证流程 - 根据步骤记录ID获取该步骤的所有操作日志
  33952. /// </summary>
  33953. /// <returns></returns>
  33954. [HttpGet]
  33955. public async Task<IActionResult> VisaProcessLogByStepId(int stepId)
  33956. {
  33957. //参数验证
  33958. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.Id == stepId && x.IsDel == 0).FirstAsync();
  33959. if (stepValid == null) return Ok(JsonView(false, "签证流程ID无效。"));
  33960. var logs = await _visaProcessRep.GetStepLogsAsync(stepId);
  33961. return Ok(JsonView(logs));
  33962. }
  33963. /// <summary>
  33964. /// 团组签证流程 - 根据团组ID获取该团组下所有步骤的操作日志
  33965. /// </summary>
  33966. /// <returns></returns>
  33967. [HttpGet]
  33968. public async Task<IActionResult> VisaProcessLogByGroupId(int groupId)
  33969. {
  33970. //参数验证
  33971. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.GroupId == groupId && x.IsDel == 0).FirstAsync();
  33972. if (stepValid == null) return Ok(JsonView(false, "团组ID无效。"));
  33973. var logs = await _visaProcessRep.GetGroupStepLogsAsync(groupId);
  33974. return Ok(JsonView(logs));
  33975. }
  33976. #endregion
  33977. #region 团组总览进程
  33978. /// <summary>
  33979. /// 团组总览进程 - 流程创建测试
  33980. /// </summary>
  33981. /// <returns></returns>
  33982. [HttpGet]
  33983. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  33984. public async Task<IActionResult> GroupProcessInitTest(int groupId, int currUserId)
  33985. {
  33986. return Ok(await _processOverviewRep.ProcessInitAsync(groupId, currUserId));
  33987. }
  33988. /// <summary>
  33989. /// 团组总览进程 - 团组名称集合
  33990. /// </summary>
  33991. /// <returns></returns>
  33992. [HttpGet()]
  33993. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  33994. public async Task<IActionResult> GroupProcessGroupNames()
  33995. {
  33996. var groupNames = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  33997. .Where(x => x.IsDel == 0)
  33998. .OrderByDescending(x => x.VisitDate)
  33999. .Select(x => new
  34000. {
  34001. x.Id,
  34002. GroupName = x.TeamName,
  34003. HasProcess = SqlFunc.Subqueryable<Grp_ProcessOverview>()
  34004. .Where(po => po.GroupId == x.Id && po.IsDel == 0)
  34005. .Any()
  34006. })
  34007. .ToListAsync();
  34008. return Ok(JsonView(groupNames));
  34009. }
  34010. /// <summary>
  34011. /// 团组总览进程 - 流程详情
  34012. /// </summary>
  34013. /// <returns></returns>
  34014. [HttpGet]
  34015. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  34016. public async Task<IActionResult> GroupProcessDetails(int groupId)
  34017. {
  34018. var res = await _processOverviewRep.ProcessesDetailsAsync(groupId);
  34019. if (res.Code == StatusCodes.Status200OK)
  34020. {
  34021. return Ok(JsonView(res.Data));
  34022. }
  34023. return Ok(JsonView(false, res.Msg));
  34024. }
  34025. /// <summary>
  34026. /// 团组总览进程 - 更新节点状态
  34027. /// </summary>
  34028. /// <returns></returns>
  34029. [HttpPost]
  34030. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  34031. public async Task<IActionResult> GroupProcessUpdateNodeStatus(GroupProcessUpdateNodeStatusDto dto)
  34032. {
  34033. var res = await _processOverviewRep.UpdateNodeStatusSimpleAsync(dto.NodeId, dto.CurrUserId);
  34034. if (res.Code == StatusCodes.Status200OK)
  34035. {
  34036. return Ok(JsonView(res.Data));
  34037. }
  34038. return Ok(JsonView(false, res.Msg));
  34039. }
  34040. /// <summary>
  34041. /// 团组总览进程 - 更新签证节点信息
  34042. /// </summary>
  34043. /// <returns></returns>
  34044. [HttpPost]
  34045. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  34046. public async Task<IActionResult> GroupProcessUpdateVisaNodeDetails(GroupProcessUpdateVisaNodeDetailsDto dto)
  34047. {
  34048. //验证签证信息
  34049. if (dto.VisaSubNodes.Count < 1) return Ok(JsonView(false, "请传入有效的签证节点信息。"));
  34050. var res = await _processOverviewRep.UpdateVisaNodeDetailsAsync(dto);
  34051. if (res.Code == StatusCodes.Status200OK)
  34052. {
  34053. return Ok(JsonView(res.Data));
  34054. }
  34055. return Ok(JsonView(false, res.Msg));
  34056. }
  34057. /// <summary>
  34058. /// 团组总览进程 - 设置实际完成时间
  34059. /// </summary>
  34060. /// <returns></returns>
  34061. [HttpPost]
  34062. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  34063. public async Task<IActionResult> GroupProcessSetActualDone(GroupProcessSetActualDoneDto dto)
  34064. {
  34065. //验证签证信息
  34066. var res = await _processOverviewRep.SetActualDoneAsync(dto);
  34067. if (res.Code == StatusCodes.Status200OK)
  34068. {
  34069. return Ok(JsonView(res.Data));
  34070. }
  34071. return Ok(JsonView(false, res.Msg));
  34072. }
  34073. #endregion
  34074. #region 团组会务总览进程
  34075. /// <summary>
  34076. /// 团组会务总览进程 - 流程创建测试
  34077. /// </summary>
  34078. /// <returns></returns>
  34079. [HttpGet]
  34080. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  34081. public async Task<IActionResult> ConfProcessInitTest(int groupId, int currUserId)
  34082. {
  34083. return Ok(await _processOverviewRep.ProcessInitAsync(groupId, currUserId));
  34084. }
  34085. /// <summary>
  34086. /// 团组会务总览进程 - 基础信息集合(团组名称、参与人信息)
  34087. /// </summary>
  34088. /// <returns></returns>
  34089. [HttpGet]
  34090. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  34091. public async Task<IActionResult> ConfProcessGroupNames()
  34092. {
  34093. var groupTypes = new List<int>() {
  34094. 302, // 成都-会务活动
  34095. 691, // 四川-会务活动
  34096. 762, // 四川-赛事项目收入
  34097. 1047 // 成都-赛事项目收入
  34098. };
  34099. var groupNames = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  34100. .Where(x => x.IsDel == 0 && groupTypes.Contains(x.TeamDid))
  34101. .OrderByDescending(x => x.VisitDate)
  34102. .Select(x => new
  34103. {
  34104. x.Id,
  34105. GroupName = x.TeamName,
  34106. HasProcess = SqlFunc.Subqueryable<Grp_ConfProcessOverview>()
  34107. .Where(po => po.GroupId == x.Id && po.IsDel == 0)
  34108. .Any()
  34109. })
  34110. .ToListAsync();
  34111. var participators = await _sqlSugar.Queryable<Sys_Users>()
  34112. .Where(x => x.IsDel == 0 && x.DepId == 5)
  34113. .Select(x => new ParticipatorInfo()
  34114. {
  34115. UserId = x.Id,
  34116. UserName = x.CnName
  34117. })
  34118. .ToListAsync();
  34119. var view = new { groupNames, participators };
  34120. return Ok(JsonView(view));
  34121. }
  34122. /// <summary>
  34123. /// 团组会务总览进程 - 获取节点模板信息
  34124. /// </summary>
  34125. /// <returns></returns>
  34126. [HttpGet]
  34127. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  34128. public async Task<IActionResult> ConfProcessNodeTempInfos(int groupId, int currUserId)
  34129. {
  34130. var nodeTemps1 = await _processOverviewRep.DefaultConfProcessTemps(groupId, currUserId);
  34131. var nodeTemps = nodeTemps1.Select(x => new
  34132. {
  34133. TempId = x.ProcessOrder,
  34134. TempName = $"情况{x.ProcessOrder}",
  34135. //TempNodes = x.Nodes
  34136. }).ToList();
  34137. return Ok(JsonView(nodeTemps));
  34138. }
  34139. /// <summary>
  34140. /// 团组会务总览进程 - 更新节点模板
  34141. /// </summary>
  34142. /// <param name="groupId">团组Id</param>
  34143. /// <param name="nodeTempId">节点模板Id</param>
  34144. /// <param name="currUserId">当前用户Id</param>
  34145. /// <returns></returns>
  34146. [HttpGet]
  34147. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  34148. public async Task<IActionResult> ConfProcessChangeNodeTempSave(int groupId, int nodeTempId, int currUserId)
  34149. {
  34150. var res = await _processOverviewRep.ConfProcessChangeNodeTempSaveAsync(groupId, nodeTempId, currUserId);
  34151. if (res.Code == StatusCodes.Status200OK)
  34152. {
  34153. return Ok(JsonView(res.Data));
  34154. }
  34155. return Ok(JsonView(false, res.Msg));
  34156. }
  34157. /// <summary>
  34158. /// 团组会务总览进程 - 流程详情
  34159. /// </summary>
  34160. /// <param name="groupId">团组Id</param>
  34161. /// <param name="currUserId">当前userId</param>
  34162. /// <returns></returns>
  34163. [HttpGet]
  34164. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  34165. public async Task<IActionResult> ConfProcessDetails(int groupId, int currUserId)
  34166. {
  34167. var res = await _processOverviewRep.ConfProcessesDetailsAsync(groupId, currUserId);
  34168. if (res.Code == StatusCodes.Status200OK)
  34169. {
  34170. return Ok(JsonView(res.Data));
  34171. }
  34172. return Ok(JsonView(false, res.Msg));
  34173. }
  34174. /// <summary>
  34175. /// 团组会务总览进程 - 更新节点状态
  34176. /// </summary>
  34177. /// <returns></returns>
  34178. [HttpPost]
  34179. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  34180. public async Task<IActionResult> ConfProcessUpdateNodeStatus(GroupProcessUpdateNodeStatusDto dto)
  34181. {
  34182. var res = await _processOverviewRep.UpdateConfNodeStatusAsync(dto.NodeId, dto.CurrUserId);
  34183. if (res.Code == StatusCodes.Status200OK)
  34184. {
  34185. return Ok(JsonView(res.Data));
  34186. }
  34187. return Ok(JsonView(false, res.Msg));
  34188. }
  34189. /// <summary>
  34190. /// 团组会务总览进程 - 设置实际完成时间及其他信息
  34191. /// </summary>
  34192. /// <returns></returns>
  34193. [HttpPost]
  34194. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  34195. public async Task<IActionResult> ConfProcessSetActualDone(ConfProcessSetActualDoneDto dto)
  34196. {
  34197. var res = await _processOverviewRep.SetNodeInfoAsync(dto);
  34198. if (res.Code == StatusCodes.Status200OK)
  34199. {
  34200. return Ok(JsonView(res.Data));
  34201. }
  34202. return Ok(JsonView(false, res.Msg));
  34203. }
  34204. #endregion
  34205. }
  34206. }