GroupsController.cs 1.5 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434
  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 iTextSharp.text.pdf;
  8. using Microsoft.AspNetCore.SignalR;
  9. using NPOI.SS.UserModel;
  10. using NPOI.SS.Util;
  11. using NPOI.XSSF.UserModel;
  12. using OASystem.API.Middlewares;
  13. using OASystem.API.OAMethodLib;
  14. using OASystem.API.OAMethodLib.APNs;
  15. using OASystem.API.OAMethodLib.DeepSeekAPI;
  16. using OASystem.API.OAMethodLib.File;
  17. using OASystem.API.OAMethodLib.GenericSearch;
  18. using OASystem.API.OAMethodLib.Hub.HubClients;
  19. using OASystem.API.OAMethodLib.Hub.Hubs;
  20. using OASystem.API.OAMethodLib.JuHeAPI;
  21. using OASystem.API.OAMethodLib.KiMiApi;
  22. using OASystem.API.OAMethodLib.QiYeWeChatAPI.AppNotice;
  23. using OASystem.Domain.AesEncryption;
  24. using OASystem.Domain.Attributes;
  25. using OASystem.Domain.Dtos.CRM;
  26. using OASystem.Domain.Dtos.FileDto;
  27. using OASystem.Domain.Dtos.Financial;
  28. using OASystem.Domain.Dtos.Groups;
  29. using OASystem.Domain.Entities.Customer;
  30. using OASystem.Domain.Entities.Financial;
  31. using OASystem.Domain.Entities.Groups;
  32. using OASystem.Domain.ViewModels.Financial;
  33. using OASystem.Domain.ViewModels.Groups;
  34. using OASystem.Domain.ViewModels.OCR;
  35. using OASystem.Infrastructure.Logging;
  36. using OASystem.Infrastructure.Repositories.CRM;
  37. using OASystem.Infrastructure.Repositories.Financial;
  38. using OASystem.Infrastructure.Repositories.Groups;
  39. using Quartz.Util;
  40. using SqlSugar.Extensions;
  41. using System.Collections;
  42. using System.ComponentModel.DataAnnotations;
  43. using System.Data;
  44. using System.Diagnostics;
  45. using System.Globalization;
  46. using System.IO.Compression;
  47. using System.Linq.Expressions;
  48. using System.Text.Json;
  49. using System.Web;
  50. using static OASystem.API.OAMethodLib.JWTHelper;
  51. using static OASystem.Infrastructure.Repositories.Groups.AirTicketResRepository;
  52. using Bookmark = Aspose.Words.Bookmark;
  53. using Cell = Aspose.Words.Tables.Cell;
  54. using Table = Aspose.Words.Tables.Table;
  55. namespace OASystem.API.Controllers
  56. {
  57. /// <summary>
  58. /// 团组相关
  59. /// </summary>
  60. //[Authorize]
  61. [Route("api/[controller]/[action]")]
  62. public class GroupsController : ControllerBase
  63. {
  64. private readonly ILogger<GroupsController> _logger;
  65. private readonly ITextFileLogger _eec_textLogger;
  66. private readonly IGroupTextFileLogger _groupTextLogger;
  67. private readonly GrpScheduleRepository _grpScheduleRep;
  68. private readonly IMapper _mapper;
  69. private readonly DelegationInfoRepository _groupRepository;
  70. private readonly TaskAssignmentRepository _taskAssignmentRep;
  71. private readonly AirTicketResRepository _airTicketResRep;
  72. private readonly DecreasePaymentsRepository _decreasePaymentsRep;
  73. private readonly InvitationOfficialActivitiesRepository _InvitationOfficialActivitiesRep;
  74. private readonly DelegationEnDataRepository _delegationEnDataRep;
  75. private readonly DelegationVisaRepository _delegationVisaRep;
  76. private readonly VisaPriceRepository _visaPriceRep;
  77. private readonly CarTouristGuideGroundRepository _carTouristGuideGroundRep;
  78. private readonly HotelPriceRepository _hotelPriceRep;
  79. private readonly CustomersRepository _customersRep;
  80. private readonly MessageRepository _message;
  81. private readonly SqlSugarClient _sqlSugar;
  82. private readonly TourClientListRepository _tourClientListRep;
  83. private readonly TeamRateRepository _teamRateRep;
  84. #region 成本相关
  85. private readonly CheckBoxsRepository _checkBoxs;
  86. private readonly GroupCostRepository _GroupCostRepository;
  87. private readonly CostTypeHotelNumberRepository _CostTypeHotelNumberRepository;
  88. private readonly GroupCostParameterRepository _GroupCostParameterRepository;
  89. #endregion
  90. private readonly SetDataRepository _setDataRep;
  91. private string url;
  92. private string path;
  93. private readonly EnterExitCostRepository _enterExitCostRep;
  94. private readonly IHubContext<ChatHub, IChatClient> _hubContext;
  95. private readonly UsersRepository _usersRep;
  96. private readonly IJuHeApiService _juHeApi;
  97. private readonly InvertedListRepository _invertedListRep;
  98. private readonly VisaFeeInfoRepository _visaFeeInfoRep;
  99. private readonly TicketBlackCodeRepository _ticketBlackCodeRep;
  100. private readonly ThreeCodeRepository _threeCodeRepository;
  101. private readonly HotelInquiryRepository _hotelInquiryRep;
  102. private readonly FeeAuditRepository _feeAuditRep;
  103. private readonly VisaCommissionRepository _visaCommissionRep;
  104. private readonly ForeignReceivablesRepository _ffrRep; //对外收款账单仓库
  105. private readonly OpinionaireRepository _opinionaireRep; //对外收款账单仓库
  106. private readonly List<CurrencyInfo> _currencyInit;
  107. private readonly List<int> _portTypeData;
  108. private readonly TableOperationRecordRepository _tableorRep;
  109. private readonly EnterExitCostDraftRepository _enterExitCostDraftRep;
  110. private readonly RestaurantRepository _restaurantRep;
  111. private readonly EnterExitCostQuoteRepository _enterExitCostQuoteRep;
  112. private readonly GroupOrderPreInfoRepository _grpOrderPreInfoRep;
  113. private readonly VisaProcessRepository _visaProcessRep;
  114. private readonly ProcessOverviewRepository _processOverviewRep;
  115. private readonly IDeepSeekService _deepSeekService;
  116. private readonly DynamicSearchService<Grp_DelegationInfo> _groupSearchService;
  117. /// <summary>
  118. /// 接送机默认报价系数
  119. /// </summary>
  120. public const decimal Def_AirportTransferCoeff = 2.50M;
  121. /// <summary>
  122. /// 接送机默认服务次数
  123. /// </summary>
  124. public const int Def_ServiceCount = 1;
  125. /// <summary>
  126. /// 火车默认报价系数
  127. /// </summary>
  128. public const decimal Def_TrainCoeff = 2.50M;
  129. /// <summary>
  130. /// 拉扯默认报价系数
  131. /// </summary>
  132. public const decimal Def_PullCartCoeff = 2.50M;
  133. /// <summary>
  134. /// 城市机票默认报价系数
  135. /// </summary>
  136. public const decimal Def_CityFlightCoeff = 2.50M;
  137. /// <summary>
  138. /// 初始化岗位对应负责的数据类型
  139. ///
  140. /// 岗位ID
  141. /// 24 机票、25 酒店、26 签证、27 商邀、28 OP
  142. ///
  143. /// 费用类型ID
  144. /// 76 酒店预订、79 车/导游地接、80 签证、81 邀请/公务活动、82 团组客户保险、85 机票预订、98 其他款项
  145. /// </summary>
  146. private readonly Dictionary<int, List<int>> _dataInit = new() {
  147. { 24, new List<int> { 85 } }, // 机票 -> 机票预订
  148. { 25, new List<int> { 76 } }, // 酒店 -> 酒店预订
  149. { 26, new List<int> { 80, 82 } }, // 签证 -> 签证, 团组客户保险
  150. { 27, new List<int> { 81 } }, // 地接 -> 邀请/公务活动
  151. { 28, new List<int> { 79 } } // 商邀 -> 车/导游地接
  152. };
  153. /// <summary>
  154. /// 构造函数
  155. /// </summary>
  156. /// <param name="logger"></param>
  157. /// <param name="eec_textLogger"></param>
  158. /// <param name="groupTextLogger"></param>
  159. /// <param name="mapper"></param>
  160. /// <param name="hubContext"></param>
  161. /// <param name="sqlSugar"></param>
  162. /// <param name="grpScheduleRep"></param>
  163. /// <param name="groupRepository"></param>
  164. /// <param name="taskAssignmentRep"></param>
  165. /// <param name="airTicketResRep"></param>
  166. /// <param name="decreasePaymentsRep"></param>
  167. /// <param name="InvitationOfficialActivitiesRep"></param>
  168. /// <param name="delegationEnDataRep"></param>
  169. /// <param name="enterExitCostRep"></param>
  170. /// <param name="delegationVisaRep"></param>
  171. /// <param name="message"></param>
  172. /// <param name="visaPriceRep"></param>
  173. /// <param name="carTouristGuideGroundRep"></param>
  174. /// <param name="checkBoxs"></param>
  175. /// <param name="GroupCostRepository"></param>
  176. /// <param name="CostTypeHotelNumberRepository"></param>
  177. /// <param name="GroupCostParameterRepository"></param>
  178. /// <param name="hotelPriceRep"></param>
  179. /// <param name="customersRep"></param>
  180. /// <param name="setDataRep"></param>
  181. /// <param name="tourClientListRep"></param>
  182. /// <param name="teamRateRep"></param>
  183. /// <param name="usersRep"></param>
  184. /// <param name="juHeApi"></param>
  185. /// <param name="invertedListRep"></param>
  186. /// <param name="visaFeeInfoRep"></param>
  187. /// <param name="ticketBlackCodeRep"></param>
  188. /// <param name="hotelInquiryRep"></param>
  189. /// <param name="threeCodeRepository"></param>
  190. /// <param name="feeAuditRep"></param>
  191. /// <param name="visaCommissionRep"></param>
  192. /// <param name="ffrRep"></param>
  193. /// <param name="opinionaireRep"></param>
  194. /// <param name="tableorRep"></param>
  195. /// <param name="enterExitCostDraftRep"></param>
  196. /// <param name="restaurantRep"></param>
  197. /// <param name="enterExitCostQuoteRep"></param>
  198. /// <param name="grpOrderPreInfoRep"></param>
  199. /// <param name="visaProcessRep"></param>
  200. /// <param name="processOverviewRep"></param>
  201. /// <param name="groupSearchService"></param>
  202. public GroupsController(
  203. ILogger<GroupsController> logger,
  204. ITextFileLogger eec_textLogger,
  205. IGroupTextFileLogger groupTextLogger,
  206. IMapper mapper,
  207. IHubContext<ChatHub, IChatClient> hubContext,
  208. SqlSugarClient sqlSugar,
  209. GrpScheduleRepository grpScheduleRep,
  210. DelegationInfoRepository groupRepository,
  211. TaskAssignmentRepository taskAssignmentRep,
  212. AirTicketResRepository airTicketResRep,
  213. DecreasePaymentsRepository decreasePaymentsRep,
  214. InvitationOfficialActivitiesRepository InvitationOfficialActivitiesRep,
  215. DelegationEnDataRepository delegationEnDataRep,
  216. EnterExitCostRepository enterExitCostRep,
  217. DelegationVisaRepository delegationVisaRep,
  218. MessageRepository message,
  219. VisaPriceRepository visaPriceRep,
  220. CarTouristGuideGroundRepository carTouristGuideGroundRep,
  221. CheckBoxsRepository checkBoxs,
  222. GroupCostRepository GroupCostRepository,
  223. CostTypeHotelNumberRepository CostTypeHotelNumberRepository,
  224. GroupCostParameterRepository GroupCostParameterRepository,
  225. HotelPriceRepository hotelPriceRep,
  226. CustomersRepository customersRep,
  227. SetDataRepository setDataRep,
  228. TourClientListRepository tourClientListRep,
  229. TeamRateRepository teamRateRep,
  230. UsersRepository usersRep,
  231. IJuHeApiService juHeApi,
  232. InvertedListRepository invertedListRep,
  233. VisaFeeInfoRepository visaFeeInfoRep,
  234. TicketBlackCodeRepository ticketBlackCodeRep,
  235. HotelInquiryRepository hotelInquiryRep,
  236. ThreeCodeRepository threeCodeRepository,
  237. FeeAuditRepository feeAuditRep,
  238. VisaCommissionRepository visaCommissionRep,
  239. ForeignReceivablesRepository ffrRep,
  240. OpinionaireRepository opinionaireRep,
  241. TableOperationRecordRepository tableorRep,
  242. EnterExitCostDraftRepository enterExitCostDraftRep,
  243. RestaurantRepository restaurantRep,
  244. EnterExitCostQuoteRepository enterExitCostQuoteRep,
  245. GroupOrderPreInfoRepository grpOrderPreInfoRep,
  246. VisaProcessRepository visaProcessRep,
  247. ProcessOverviewRepository processOverviewRep,
  248. DynamicSearchService<Grp_DelegationInfo> groupSearchService
  249. )
  250. {
  251. _logger = logger;
  252. _eec_textLogger = eec_textLogger;
  253. _groupTextLogger = groupTextLogger;
  254. _mapper = mapper;
  255. _grpScheduleRep = grpScheduleRep;
  256. _groupRepository = groupRepository;
  257. _taskAssignmentRep = taskAssignmentRep;
  258. _airTicketResRep = airTicketResRep;
  259. _sqlSugar = sqlSugar;
  260. url = AppSettingsHelper.Get("ExcelBaseUrl");
  261. path = AppSettingsHelper.Get("ExcelBasePath");
  262. if (!System.IO.Directory.Exists(path))
  263. {
  264. System.IO.Directory.CreateDirectory(path);//不存在就创建文件夹
  265. }
  266. _decreasePaymentsRep = decreasePaymentsRep;
  267. _InvitationOfficialActivitiesRep = InvitationOfficialActivitiesRep;
  268. _delegationEnDataRep = delegationEnDataRep;
  269. _enterExitCostRep = enterExitCostRep;
  270. _delegationVisaRep = delegationVisaRep;
  271. _message = message;
  272. _visaPriceRep = visaPriceRep;
  273. _carTouristGuideGroundRep = carTouristGuideGroundRep;
  274. _checkBoxs = checkBoxs;
  275. _GroupCostRepository = GroupCostRepository;
  276. _CostTypeHotelNumberRepository = CostTypeHotelNumberRepository;
  277. _GroupCostParameterRepository = GroupCostParameterRepository;
  278. _hotelPriceRep = hotelPriceRep;
  279. _customersRep = customersRep;
  280. _setDataRep = setDataRep;
  281. _tourClientListRep = tourClientListRep;
  282. _teamRateRep = teamRateRep;
  283. _hubContext = hubContext;
  284. _usersRep = usersRep;
  285. _juHeApi = juHeApi;
  286. _invertedListRep = invertedListRep;
  287. _visaFeeInfoRep = visaFeeInfoRep;
  288. _ticketBlackCodeRep = ticketBlackCodeRep;
  289. _hotelInquiryRep = hotelInquiryRep;
  290. _threeCodeRepository = threeCodeRepository;
  291. _feeAuditRep = feeAuditRep;
  292. _visaCommissionRep = visaCommissionRep;
  293. _ffrRep = ffrRep;
  294. _opinionaireRep = opinionaireRep;
  295. _currencyInit = new List<CurrencyInfo>()
  296. {
  297. new(){ CurrencyCode="USD",CurrencyName = "美元",Rate = 7.5000M },
  298. new(){ CurrencyCode="EUR",CurrencyName = "欧元",Rate = 8.0000M },
  299. new(){ CurrencyCode="GBP",CurrencyName = "英镑",Rate = 9.5000M },
  300. new(){ CurrencyCode="JPY",CurrencyName = "日元",Rate = 0.0500M },
  301. new(){ CurrencyCode="HKD",CurrencyName = "港币",Rate = 0.9500M },
  302. };
  303. _portTypeData = new List<int>() { 2, 3 };
  304. _tableorRep = tableorRep;
  305. _enterExitCostDraftRep = enterExitCostDraftRep;
  306. _restaurantRep = restaurantRep;
  307. _enterExitCostQuoteRep = enterExitCostQuoteRep;
  308. _grpOrderPreInfoRep = grpOrderPreInfoRep;
  309. _visaProcessRep = visaProcessRep;
  310. _processOverviewRep = processOverviewRep;
  311. _groupSearchService = groupSearchService;
  312. }
  313. #region 页面加载弹窗信息
  314. /// <summary>
  315. /// 提示用户录入团组费用信息
  316. /// 根据用户ID获取分配权限内团组名称
  317. /// </summary>
  318. /// <param name="currUserId">用户Id</param>
  319. /// <param name="daysAgo">往前推的天数</param>
  320. /// <returns></returns>
  321. [HttpGet]
  322. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  323. public async Task<IActionResult> GetGroupNamesByUserId(int currUserId, int daysAgo = 5)
  324. {
  325. var stopwatch = Stopwatch.StartNew();
  326. var userInfo = await _sqlSugar.Queryable<Sys_Users>()
  327. .Where(x => x.Id == currUserId && x.IsDel == 0)
  328. .Select(x => new { x.Id, x.JobPostId, x.CnName })
  329. .FirstAsync();
  330. if (userInfo == null)
  331. {
  332. return Ok(JsonView(false, "用户不存在或已被禁用!"));
  333. }
  334. var jobId = userInfo.JobPostId;
  335. var feeTypeIds = new List<int>() { };
  336. if (_dataInit.TryGetValue(jobId, out var values))
  337. {
  338. feeTypeIds = values;
  339. }
  340. /*
  341. * 获取今天时间往前推5天查询团组c表里有没有费用
  342. */
  343. var today_startDate = DateTime.Now.Date.AddDays(-daysAgo);
  344. //var today_endDate = DateTime.Now.Date.AddDays(-daysAgo).AddDays(1).AddSeconds(-1);
  345. var today_endDate = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
  346. var groupNames = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  347. .Where(di => di.IsDel == 0)
  348. .Where(di => di.VisitDate >= today_startDate && di.VisitDate <= today_endDate)
  349. // 存在任务分配记录
  350. .Where(di => SqlFunc.Subqueryable<Grp_GroupsTaskAssignment>()
  351. .Where(gta => gta.DIId == di.Id && gta.IsDel == 0 && feeTypeIds.Contains(gta.CTId))
  352. .Any())
  353. // 不存在费用记录
  354. .Where(di => !SqlFunc.Subqueryable<Grp_CreditCardPayment>()
  355. .Where(ccp => ccp.DIId == di.Id && ccp.IsDel == 0 && feeTypeIds.Contains(ccp.CTable))
  356. .Any())
  357. // 新增条件:不在确认记录表中(排除已确认的团组)
  358. .Where(di => !SqlFunc.Subqueryable<Grp_FeeEntryAcknowledge>()
  359. .Where(ack => ack.GroupId == di.Id && ack.IsDel == 0 && ack.UserId == currUserId)
  360. .Where(ack => feeTypeIds.Contains(ack.FeeTypeId))
  361. .Where(ack => ack.IsAcknowledged == AcknowledgeStatusEnum.Acknowledged) // 只排除已确认的记录
  362. .Any())
  363. .Select(di => new
  364. {
  365. di.Id,
  366. di.TeamName,
  367. di.VisitDate
  368. })
  369. .OrderBy(di => di.VisitDate)
  370. .ToListAsync();
  371. stopwatch.Stop();
  372. return Ok(JsonView(true, $"操作成功!【耗时:{stopwatch.ElapsedMilliseconds}ms】", new
  373. {
  374. isTips = groupNames.Any(),
  375. groupNames = groupNames.Select(x => new { x.Id, GroupName = x.TeamName, x.VisitDate }).ToList()
  376. }));
  377. }
  378. /// <summary>
  379. /// 提示用户录入团组费用信息
  380. /// 已知晓确认操作记录(添加) 批量
  381. /// </summary>
  382. /// <param name="dto">请求体</param>
  383. /// <returns></returns>
  384. [HttpPost]
  385. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  386. public async Task<IActionResult> FeeEntryAcknowledgeCrate(FeeEntryAcknowledgeCrateDto dto)
  387. {
  388. // 1. 参数验证
  389. if (dto?.GroupIds == null || !dto.GroupIds.Any())
  390. return Ok(JsonView(false, "请选择需要确认的团组!"));
  391. if (dto.GroupIds.Count > 100)
  392. return Ok(JsonView(false, "一次性确认团组数量不能超过100个!"));
  393. if (dto.CurrUserId <= 0)
  394. return Ok(JsonView(false, "用户ID无效!"));
  395. // 2. 验证用户存在性
  396. var userInfo = await _sqlSugar.Queryable<Sys_Users>()
  397. .Where(x => x.Id == dto.CurrUserId && x.IsDel == 0)
  398. .Select(x => new { x.Id, x.JobPostId, x.CnName })
  399. .FirstAsync();
  400. if (userInfo == null)
  401. return Ok(JsonView(false, "用户不存在或已被禁用!"));
  402. // 3. 获取费用类型
  403. if (!_dataInit.TryGetValue(userInfo.JobPostId, out var feeTypeIds) || feeTypeIds?.Count == 0)
  404. return Ok(JsonView(false, "当前用户岗位无对应的费用类型配置!"));
  405. // 4. 验证团组存在性
  406. var validGroupIds = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  407. .Where(x => dto.GroupIds.Contains(x.Id) && x.IsDel == 0)
  408. .Select(x => x.Id)
  409. .ToListAsync();
  410. if (!validGroupIds.Any())
  411. return Ok(JsonView(false, "未找到有效的团组信息!"));
  412. // 5. 检查团组费用表中是否存在对应费用类型的数据
  413. var existingFeeRecords = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  414. .Where(x => validGroupIds.Contains(x.DIId) && x.IsDel == 0)
  415. .Where(x => feeTypeIds.Contains(x.CTable))
  416. .Select(x => new { GroupId = x.DIId, FeeTypeId = x.CTable })
  417. .ToListAsync();
  418. if (existingFeeRecords.Count > 0)
  419. {
  420. // 找出有问题的团组和费用类型
  421. var problematicGroups = existingFeeRecords
  422. .GroupBy(x => x.GroupId)
  423. .Select(g => new
  424. {
  425. GroupId = g.Key,
  426. FeeTypeIds = string.Join(",", g.Select(x => x.FeeTypeId).Distinct())
  427. })
  428. .ToList();
  429. var errorMessage = $"以下团组的费用表中已存在费用数据,不可添加确认记录:";
  430. foreach (var group in problematicGroups)
  431. {
  432. errorMessage += $"\n团组 {group.GroupId} - 费用类型ID: [{group.FeeTypeIds}]";
  433. }
  434. return Ok(JsonView(false, errorMessage));
  435. }
  436. // 6. 检查是否已存在确认记录(避免重复确认)
  437. var existingAcknowledgeRecords = await _sqlSugar.Queryable<Grp_FeeEntryAcknowledge>()
  438. .Where(x => x.UserId == dto.CurrUserId && x.IsDel == 0)
  439. .Where(x => validGroupIds.Contains(x.GroupId))
  440. .Where(x => feeTypeIds.Contains(x.FeeTypeId))
  441. .Select(x => new { x.GroupId, x.FeeTypeId })
  442. .ToListAsync();
  443. // 7. 准备插入数据(过滤已存在的记录)
  444. var recordsToInsert = new List<Grp_FeeEntryAcknowledge>();
  445. foreach (var groupId in validGroupIds)
  446. {
  447. foreach (var feeTypeId in feeTypeIds)
  448. {
  449. // 检查是否已存在相同记录
  450. var exists = existingAcknowledgeRecords.Any(x => x.GroupId == groupId && x.FeeTypeId == feeTypeId);
  451. if (!exists)
  452. {
  453. recordsToInsert.Add(new Grp_FeeEntryAcknowledge()
  454. {
  455. GroupId = groupId,
  456. UserId = dto.CurrUserId,
  457. JobPostId = userInfo.JobPostId,
  458. FeeTypeId = feeTypeId,
  459. IsAcknowledged = Domain.Enums.AcknowledgeStatusEnum.Acknowledged,
  460. AcknowledgeTime = DateTime.Now,
  461. AcknowledgeType = Domain.Enums.AcknowledgeTypeEnum.WebConfirm,
  462. CreateUserId = 4, // 系统创建
  463. CreateTime = DateTime.Now
  464. });
  465. }
  466. }
  467. }
  468. if (!recordsToInsert.Any())
  469. return Ok(JsonView(true, "所选团组已确认,无需重复操作!"));
  470. // 8. 批量插入数据
  471. var successCount = await _sqlSugar.Insertable(recordsToInsert).ExecuteCommandAsync();
  472. if (successCount <= 0)
  473. return Ok(JsonView(false, "操作失败,未能保存确认记录!"));
  474. // 9. 记录操作日志
  475. _logger.LogInformation("用户 {UserName}(ID:{UserId}) 批量确认了 {GroupCount} 个团组的费用类型,共添加 {RecordCount} 条确认记录",
  476. userInfo.CnName, dto.CurrUserId, validGroupIds.Count, successCount);
  477. // 10. 操作成功 返回成功视图
  478. var result = await GetGroupNamesByUserId(dto.CurrUserId, dto.DaysAgo);
  479. if (result is OkObjectResult okObjectResult)
  480. {
  481. return Ok(okObjectResult.Value);
  482. }
  483. //return Ok(result);
  484. return Ok(JsonView(true, $"操作成功!共为 {validGroupIds.Count} 个团组添加了 {successCount} 条确认记录"));
  485. }
  486. /// <summary>
  487. /// 提示用户录入团组费用信息
  488. /// 已知晓确认操作记录(添加) 单个
  489. /// </summary>
  490. /// <param name="dto">请求体</param>
  491. /// <returns></returns>
  492. [HttpPost]
  493. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  494. public async Task<IActionResult> FeeEntryAcknowledgeSingleCreate(FeeEntryAcknowledgeSingleDto dto)
  495. {
  496. // 1. 参数验证
  497. if (dto.GroupId <= 0)
  498. return Ok(JsonView(false, "请选择有效的团组ID!"));
  499. if (dto.CurrUserId <= 0)
  500. return Ok(JsonView(false, "用户ID无效!"));
  501. // 2. 验证用户存在性
  502. var userInfo = await _sqlSugar.Queryable<Sys_Users>()
  503. .Where(x => x.Id == dto.CurrUserId && x.IsDel == 0)
  504. .Select(x => new { x.Id, x.JobPostId, x.CnName })
  505. .FirstAsync();
  506. if (userInfo == null)
  507. return Ok(JsonView(false, "用户不存在或已被禁用!"));
  508. // 3. 获取费用类型
  509. if (!_dataInit.TryGetValue(userInfo.JobPostId, out var feeTypeIds) || feeTypeIds?.Count == 0)
  510. return Ok(JsonView(false, "当前用户岗位无对应的费用类型配置!"));
  511. // 4. 验证团组存在性
  512. var groupExists = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  513. .AnyAsync(x => x.Id == dto.GroupId && x.IsDel == 0);
  514. if (!groupExists)
  515. return Ok(JsonView(false, "未找到有效的团组信息!"));
  516. // 5. 检查团组费用表中是否存在对应费用类型的数据
  517. var existingFeeRecords = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  518. .Where(x => x.DIId == dto.GroupId && x.IsDel == 0)
  519. .Where(x => feeTypeIds.Contains(x.CTable))
  520. .Select(x => new { x.CTable })
  521. .ToListAsync();
  522. if (existingFeeRecords.Count > 0)
  523. {
  524. var existingFeeTypeNames = existingFeeRecords.Select(x => x.CTable).Distinct().ToList();
  525. return Ok(JsonView(false, $"团组费用表中已存在费用类型ID [{string.Join(",", existingFeeTypeNames)}] 的数据,不可添加确认无费用记录!"));
  526. }
  527. // 6. 检查已存在的确认记录
  528. var existingAcknowledgeRecords = await _sqlSugar.Queryable<Grp_FeeEntryAcknowledge>()
  529. .Where(x => x.UserId == dto.CurrUserId && x.IsDel == 0)
  530. .Where(x => x.GroupId == dto.GroupId)
  531. .Where(x => feeTypeIds.Contains(x.FeeTypeId))
  532. .Select(x => new { x.FeeTypeId })
  533. .ToListAsync();
  534. var existingAcknowledgeFeeTypeIds = existingAcknowledgeRecords.Select(x => x.FeeTypeId).ToHashSet();
  535. // 7. 准备插入数据(过滤已存在的记录)
  536. var recordsToInsert = feeTypeIds
  537. .Where(feeTypeId => !existingAcknowledgeFeeTypeIds.Contains(feeTypeId))
  538. .Select(feeTypeId => new Grp_FeeEntryAcknowledge
  539. {
  540. GroupId = dto.GroupId,
  541. UserId = dto.CurrUserId,
  542. JobPostId = userInfo.JobPostId,
  543. FeeTypeId = feeTypeId,
  544. IsAcknowledged = Domain.Enums.AcknowledgeStatusEnum.Acknowledged,
  545. AcknowledgeTime = DateTime.Now,
  546. AcknowledgeType = Domain.Enums.AcknowledgeTypeEnum.WebConfirm,
  547. CreateUserId = 4, // 系统创建
  548. CreateTime = DateTime.Now
  549. })
  550. .ToList();
  551. if (recordsToInsert.Count == 0)
  552. return Ok(JsonView(true, "所选团组已确认,无需重复操作!"));
  553. // 8. 批量插入数据
  554. var successCount = await _sqlSugar.Insertable(recordsToInsert).ExecuteCommandAsync();
  555. if (successCount <= 0)
  556. return Ok(JsonView(false, "操作失败,未能保存确认记录!"));
  557. // 9. 记录操作日志(可选)
  558. _logger.LogInformation("用户 {UserName}(ID:{UserId}) 确认了团组 {GroupId} 的费用类型",
  559. userInfo.CnName, dto.CurrUserId, dto.GroupId);
  560. return Ok(JsonView(true, $"操作成功!"));
  561. }
  562. #endregion
  563. #region 流程管控
  564. /// <summary>
  565. /// 获取团组流程管控信息
  566. /// </summary>
  567. /// <param name="_jsonDto">查询参数</param>
  568. /// <returns></returns>
  569. [HttpPost]
  570. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  571. public async Task<IActionResult> PostSearchGrpSchedule(JsonDtoBase _jsonDto)
  572. {
  573. if (string.IsNullOrEmpty(_jsonDto.Paras))
  574. {
  575. return Ok(JsonView(false, "参数为空"));
  576. }
  577. Grp_ScheduleDto _ScheduleDto = JsonConvert.DeserializeObject<Grp_ScheduleDto>(_jsonDto.Paras);
  578. if (_ScheduleDto != null)
  579. {
  580. if (_ScheduleDto.SearchType == 2)//获取列表
  581. {
  582. List<Grp_ScheduleView> _grpScheduleViewList = await _grpScheduleRep.GetViewList_GrpSchedule(_ScheduleDto);
  583. return Ok(JsonView(_grpScheduleViewList));
  584. }
  585. else//获取对象
  586. {
  587. Grp_ScheduleCombinView _grpScheduleView = await _grpScheduleRep.GetView_GrpSchedule(_ScheduleDto);
  588. if (_grpScheduleView != null)
  589. {
  590. return Ok(JsonView(_grpScheduleView));
  591. }
  592. }
  593. }
  594. else
  595. {
  596. return Ok(JsonView(false, "参数反序列化失败"));
  597. }
  598. return Ok(JsonView(false, "暂无数据!"));
  599. }
  600. /// <summary>
  601. /// 修改团组流程管控详细表数据
  602. /// </summary>
  603. /// <param name="dto"></param>
  604. /// <returns></returns>
  605. [HttpPost]
  606. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  607. public async Task<IActionResult> PostUpdateGrpScheduleDetail(Grp_ScheduleDetailUpdDto dto)
  608. {
  609. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  610. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_ScheduleDetailInfo>()
  611. .SetColumns(it => it.Duty == _detail.Duty)
  612. .SetColumns(it => it.ExpectBeginDt == _detail.ExpectBeginDt)
  613. .SetColumns(it => it.ExpectEndDt == _detail.ExpectEndDt)
  614. .SetColumns(it => it.JobContent == _detail.JobContent)
  615. .SetColumns(it => it.Remark == _detail.Remark)
  616. .SetColumns(it => it.StepStatus == _detail.StepStatus)
  617. .Where(s => s.Id == dto.Id)
  618. //.UpdateColumns(s => new { s.Duty, s.ExpectBeginDt, s.ExpectEndDt, s.JobContent, s.Remark, s.StepStatus })
  619. .ExecuteCommandAsync();
  620. if (result > 0)
  621. {
  622. return Ok(JsonView(true, "保存成功!"));
  623. }
  624. return Ok(JsonView(false, "保存失败!"));
  625. }
  626. /// <summary>
  627. /// 删除团组流程管控详细表数据,删除人Id请放在Duty
  628. /// </summary>
  629. /// <param name="dto"></param>
  630. /// <returns></returns>
  631. [HttpPost]
  632. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  633. public async Task<ActionResult> PostDeleteGrpScheduleDetail(Grp_ScheduleDetailUpdDto dto)
  634. {
  635. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  636. _detail.IsDel = 1;
  637. _detail.DeleteUserId = dto.Duty;
  638. _detail.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  639. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_ScheduleDetailInfo>()
  640. .SetColumns(it => it.IsDel == _detail.IsDel)
  641. .SetColumns(it => it.DeleteUserId == _detail.DeleteUserId)
  642. .SetColumns(it => it.DeleteTime == _detail.DeleteTime)
  643. .Where(it => it.Id == dto.Id)
  644. //.UpdateColumns(s => new { s.IsDel, s.DeleteUserId, s.DeleteTime })
  645. //.WhereColumns(s => s.Id == dto.Id)
  646. .ExecuteCommandAsync();
  647. if (result > 0)
  648. {
  649. return Ok(JsonView(true, "删除成功!"));
  650. }
  651. return Ok(JsonView(false, "删除失败!"));
  652. }
  653. /// <summary>
  654. /// 增加团组流程管控详细表数据
  655. /// </summary>
  656. /// <param name="dto"></param>
  657. /// <returns></returns>
  658. [HttpPost]
  659. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  660. public async Task<ActionResult> PostInsertGrpScheduleDetail(Grp_ScheduleDetailInsertDto dto)
  661. {
  662. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  663. if (DateTime.Now < _detail.ExpectBeginDt)
  664. {
  665. _detail.StepStatus = 0;
  666. }
  667. else
  668. {//若大于设置时间,不考虑设置的预计结束日期,统一视为进行中
  669. _detail.StepStatus = 1;
  670. }
  671. var result = await _grpScheduleRep._sqlSugar.Insertable(_detail).ExecuteReturnIdentityAsync();
  672. if (result > 0)
  673. {
  674. Grp_ScheduleDetailView _result = await _grpScheduleRep.GetInsertBackData(result);
  675. return Ok(JsonView(true, "添加成功!", _result));
  676. }
  677. return Ok(JsonView(false, "添加失败!"));
  678. }
  679. #endregion
  680. #region 团组前期信息
  681. /// <summary>
  682. /// 团组前期信息H5-URL(员工对应地址)
  683. /// </summary>
  684. /// <param name="name">用户名称</param>
  685. /// <returns></returns>
  686. [HttpGet]
  687. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  688. public async Task<IActionResult> GroupOrderPreInfoH5URLList([FromQuery] string name)
  689. {
  690. var userURLs = await _sqlSugar.Queryable<Sys_Users>()
  691. .Where(x => x.IsDel == 0)
  692. .WhereIF(!string.IsNullOrEmpty(name), x => x.CnName.Contains(name))
  693. .OrderBy(x => x.Id)
  694. .Select(x => new
  695. {
  696. name = x.CnName,
  697. url = $"http://oa.pan-american-intl.com:4399/#/MarketplacePick?userid={x.Id}",
  698. })
  699. .ToListAsync();
  700. return Ok(JsonView(true, "操作成功!", userURLs, userURLs.Count));
  701. }
  702. /// <summary>
  703. /// 团组前期信息 List
  704. /// </summary>
  705. /// <returns></returns>
  706. [HttpPost]
  707. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  708. public async Task<IActionResult> GroupOrderPreInfoList(GroupOrderPreInfoListDto dto)
  709. {
  710. var search = dto.Search;
  711. int[] nameTempIds = new int[] { 1, 12, 28 },
  712. countryTempIds = new int[] { 2, 13, 29 },
  713. daysTempIds = new int[] { 4, 15, 31 },
  714. ppNumTempIds = new int[] { 6 };
  715. var list = await _sqlSugar.Queryable<Grp_OrderPreInfo>()
  716. .LeftJoin<Sys_Users>((opi, u) => opi.CreateUserId == u.Id)
  717. .Where((opi, u) => opi.IsDel == 0)
  718. .OrderByDescending((opi, u) => opi.CreateTime)
  719. .Select((opi, u) => new GroupOrderPreInfoListView()
  720. {
  721. Id = opi.Id,
  722. Name = opi.Name,
  723. UnitName = SqlFunc.Subqueryable<Grp_OrderPreItem>().Where(x => x.ParentId == opi.Id && nameTempIds.Contains(x.FormTempId)).Select(x => x.Value),
  724. VisitCountryVal = SqlFunc.Subqueryable<Grp_OrderPreItem>().Where(x => x.ParentId == opi.Id && countryTempIds.Contains(x.FormTempId)).Select(x => x.Value),
  725. VisitDays = SqlFunc.Subqueryable<Grp_OrderPreItem>().Where(x => x.ParentId == opi.Id && daysTempIds.Contains(x.FormTempId)).Select(x => x.Value),
  726. VisiPpNum = SqlFunc.Subqueryable<Grp_OrderPreItem>().Where(x => x.ParentId == opi.Id && ppNumTempIds.Contains(x.FormTempId)).Select(x => x.Value),
  727. Operator = u.CnName,
  728. OperationTime = opi.CreateTime
  729. })
  730. //.WhereIF(!string.IsNullOrEmpty(search), x => x.Name.Contains(search) || x.UnitName.Contains(search) || x.VisitCountrys.Contains(search))
  731. //.ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  732. .ToListAsync();
  733. var listPageData = list.WhereIF(!string.IsNullOrEmpty(search), x => x.Name.Contains(search) || x.UnitName.Contains(search) || x.VisitCountrys.Contains(search)).ToList();
  734. int total = list.Count;
  735. int totalPageCount = (int)Math.Ceiling(list.Count / (double)dto.PageSize);
  736. var listPageData1 = listPageData
  737. .Skip((dto.PageIndex - 1) * dto.PageSize)
  738. .Take(dto.PageSize)
  739. .ToList();
  740. var infoIds = listPageData1.Select(x => x.Id).ToList();
  741. var typeDatas = await _sqlSugar.Queryable<Sys_SetData>()
  742. .Where(x => x.IsDel == 0 && x.STid == 109)
  743. .ToArrayAsync();
  744. var items = await _sqlSugar.Queryable<Grp_OrderPreItem>()
  745. .LeftJoin<Sys_FormTemp>((opi, ft) => opi.FormTempId == ft.Id)
  746. .Where((opi, ft) => opi.IsDel == 0 && infoIds.Contains(opi.ParentId))
  747. .Select((opi, ft) => new { opi.ParentId, opi.FormTempId, ft.TempId })
  748. .ToListAsync();
  749. foreach (var item in listPageData1)
  750. {
  751. var typeDatas1 = typeDatas.Select(x => new
  752. {
  753. x.Id,
  754. x.Name,
  755. IsNull = !items.Any(x1 => item.Id == x1.ParentId && x.Id == x1.TempId)
  756. }).ToArray();
  757. item.VersionDetails = typeDatas1;
  758. }
  759. return Ok(JsonView(listPageData1, listPageData1.Count));
  760. }
  761. /// <summary>
  762. /// 团组前期信息 Init
  763. /// </summary>
  764. /// <returns></returns>
  765. [HttpGet("{userId}")]
  766. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  767. public async Task<IActionResult> GroupOrderPreInfo(int userId)
  768. {
  769. return Ok(await _grpOrderPreInfoRep.DataInit(userId));
  770. }
  771. /// <summary>
  772. /// 国家数据源
  773. /// </summary>
  774. /// <param name="pageIndex">当前页码</param>
  775. /// <param name="pageSize">每页条数</param>
  776. /// <param name="search">查询条件</param>
  777. /// <returns></returns>
  778. [HttpGet]
  779. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  780. public async Task<IActionResult> CountryInit([FromQuery] int pageIndex, [FromQuery] int pageSize, [FromQuery] string search)
  781. {
  782. var countrys = await _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x => x.IsDel == 0).Select(x => x.Country).Distinct().ToListAsync();
  783. if (pageIndex == 0 && pageSize == 0)
  784. {
  785. //所有数据
  786. return Ok(JsonView(countrys, countrys.Count));
  787. }
  788. //分页
  789. int skip = (pageIndex - 1) * pageSize;
  790. int take = pageSize;
  791. if (!string.IsNullOrEmpty(search))
  792. {
  793. IEnumerable<char> charSequence = search.Select(c => c);
  794. var pageResult1 = countrys.Where(x => charSequence.All(x1 => x.Contains(x1))).ToList();
  795. var pageData = pageResult1.Skip(skip).Take(take).ToList();
  796. return Ok(JsonView(pageData, pageResult1.Count));
  797. }
  798. var pageResult2 = countrys.Skip(skip).Take(take).ToList();
  799. return Ok(JsonView(pageResult2, countrys.Count));
  800. }
  801. /// <summary>
  802. /// 城市数据源
  803. /// </summary>
  804. /// <param name="countryLabel">国家名称 多个使用英文逗号隔开</param>
  805. /// <param name="pageIndex">当前页码</param>
  806. /// <param name="pageSize">每页条数</param>
  807. /// <param name="search">查询条件</param>
  808. /// <returns></returns>
  809. [HttpGet("{countryLabel}")]
  810. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  811. public async Task<IActionResult> CityByCountry(
  812. string countryLabel,
  813. [FromQuery] int pageIndex,
  814. [FromQuery] int pageSize,
  815. [FromQuery] string search)
  816. {
  817. countryLabel = HttpUtility.UrlDecode(countryLabel);
  818. var countryList = countryLabel.Split(',', StringSplitOptions.RemoveEmptyEntries).ToArray();
  819. var citys = Array.Empty<string?>();
  820. if (countryList.Any())
  821. {
  822. var cityDatas = await _sqlSugar
  823. .Queryable<Grp_NationalTravelFee>()
  824. .Where(x => x.IsDel == 0 && countryList.Contains(x.Country) && !string.IsNullOrEmpty(x.City))
  825. .ToArrayAsync();
  826. foreach (var item in cityDatas)
  827. {
  828. if (item.City.Contains("城市"))
  829. {
  830. item.City = item.Country + "-所有城市";
  831. }
  832. }
  833. var cityDatas1 = cityDatas.OrderBy(x => x.Country);
  834. citys = cityDatas1.Select(x => x.City).Distinct().ToArray();
  835. }
  836. if (pageIndex == 0 && pageSize == 0)
  837. {
  838. //所有数据
  839. return Ok(JsonView(citys, citys?.Length ?? 0));
  840. }
  841. //分页
  842. int skip = (pageIndex - 1) * pageSize;
  843. int take = pageSize;
  844. if (!string.IsNullOrEmpty(search))
  845. {
  846. IEnumerable<char> charSequence = search.Select(c => c);
  847. var pageResult1 = citys.Where(x => charSequence.All(x1 => x.Contains(x1))).ToList();
  848. var pageData = pageResult1.Skip(skip).Take(take).ToList();
  849. return Ok(JsonView(pageData, pageResult1.Count));
  850. }
  851. var pageResult2 = citys.Skip(skip).Take(take).ToList();
  852. return Ok(JsonView(pageResult2, citys?.Length ?? 0));
  853. }
  854. /// <summary>
  855. /// 团组前期信息 Info
  856. /// </summary>
  857. /// <param name="dto">Id</param>
  858. /// <returns></returns>
  859. [HttpGet("{Id}/{TempId}")]
  860. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  861. public async Task<IActionResult> GroupOrderPreInfo([FromRoute] GroupOrderPreInfoDto dto)
  862. {
  863. return Ok(await _grpOrderPreInfoRep.InfoAsync(dto.Id, dto.TempId));
  864. }
  865. /// <summary>
  866. /// 团组前期信息 移动端 Info
  867. /// </summary>
  868. /// <param name="dto">Id</param>
  869. /// <returns></returns>
  870. [HttpGet("{Id}/{TempId}")]
  871. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  872. public async Task<IActionResult> GroupOrderPreMobileInfo([FromRoute] GroupOrderPreInfoDto dto)
  873. {
  874. return Ok(await _grpOrderPreInfoRep.MobileInfoAsync(dto.Id, dto.TempId));
  875. }
  876. /// <summary>
  877. /// 团组前期信息 Save
  878. /// </summary>
  879. /// <param name="dto">Id</param>
  880. /// <returns></returns>
  881. [HttpPost]
  882. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  883. public async Task<IActionResult> GroupOrderPreInfoSave(GroupOrderPreInfoOpDto dto)
  884. {
  885. return Ok(await _grpOrderPreInfoRep.OpAsync(dto));
  886. }
  887. /// <summary>
  888. /// 团组前期信息 Del
  889. /// </summary>
  890. /// <param name="dto">Id</param>
  891. /// <returns></returns>
  892. [HttpPost]
  893. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  894. public async Task<IActionResult> GroupOrderPreInfoDel(GroupOrderPreInfoDelDto dto)
  895. {
  896. return Ok(await _grpOrderPreInfoRep.DelAsync(dto));
  897. }
  898. /// <summary>
  899. /// 团组前期信息 文件下载
  900. /// </summary>
  901. /// <param name="dto">Id</param>
  902. /// <returns></returns>
  903. [HttpGet("{Id}/{TempId}")]
  904. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  905. public async Task<IActionResult> GroupOrderPreInfoFileDownload([FromRoute] GroupOrderPreInfoDto dto)
  906. {
  907. int id = dto.Id, tempId = dto.TempId;
  908. var view = await _grpOrderPreInfoRep.InfoAsync(id, tempId);
  909. var data = view.Data as GrpOrderPreInfoView;
  910. #region Excel
  911. var tempPath = AppSettingsHelper.Get("ExcelTempPath");
  912. var servicePath = AppSettingsHelper.Get("GrpFileBaseUrl");
  913. var savePath = AppSettingsHelper.Get("ExcelBasePath") + "GroupOrderPreInfo/";
  914. var ftpPath = AppSettingsHelper.Get("ExcelFtpPath") + "GroupOrderPreInfo/";
  915. var fileNamePrefix = string.Empty;
  916. if (tempId == 1405)
  917. {
  918. tempPath += $"前期需客户提供信息_无商邀版Temp.xlsx";
  919. fileNamePrefix = $"{data.Name}_无商邀版";
  920. }
  921. else if (tempId == 1406)
  922. {
  923. tempPath += $"前期需客户提供信息_有商邀版Temp.xlsx";
  924. fileNamePrefix = $"{data.Name}_有商邀版";
  925. }
  926. else
  927. {
  928. //tempId == 1404 默认下载
  929. tempPath += $"前期需客户提供信息_单接送机Temp.xlsx";
  930. fileNamePrefix = $"{data.Name}_单接送机";
  931. }
  932. foreach (var item in data.Items)
  933. {
  934. var obj = item.NewValue;
  935. if (obj == null) item.OriginVal = "";
  936. else if (obj.Equals("有") || obj.Equals("无"))
  937. {
  938. item.OriginVal = obj.ToString();
  939. }
  940. else if (obj is object[] objArray)
  941. {
  942. string[] stringArray = Array.ConvertAll(objArray, item => item?.ToString() ?? string.Empty);
  943. item.OriginVal = string.Join("、", stringArray);
  944. }
  945. else if (obj is string[] stringArray)
  946. {
  947. item.OriginVal = string.Join("、", stringArray);
  948. }
  949. else if (obj.Equals("-"))
  950. {
  951. item.OriginVal = "";
  952. }
  953. }
  954. var fileName = $"{fileNamePrefix}{CommonFun.GUID}.xlsx";
  955. fileName = CommonFun.ValidFileName(fileName);
  956. //载入模板
  957. var designer = new WorkbookDesigner
  958. {
  959. Workbook = new Workbook(tempPath)
  960. };
  961. if (tempId == 1406)
  962. {
  963. var view1 = data.Items.Where(x => x.Index < 11).ToArray();
  964. var view2 = data.Items.Where(x => x.Index > 10).ToArray();
  965. for (int i = 1; i <= view2.Length; i++)
  966. {
  967. view2[i - 1].Index = i;
  968. }
  969. designer.SetDataSource("View1", view1);
  970. designer.SetDataSource("View2", view2);
  971. }
  972. else
  973. {
  974. designer.SetDataSource("View", data.Items);
  975. }
  976. designer.Process();
  977. if (!Directory.Exists(savePath))
  978. {
  979. Directory.CreateDirectory(savePath);
  980. }
  981. string serverPath = $"{savePath}{fileName}";
  982. designer.Workbook.Save(serverPath);
  983. string rst = $"{servicePath}{ftpPath}{fileName}";
  984. #endregion
  985. return Ok(JsonView(new { url = rst }));
  986. }
  987. #endregion
  988. #region 团组基本信息
  989. /// <summary>
  990. /// 接团信息列表
  991. /// </summary>
  992. /// <param name="dto">团组列表请求dto</param>
  993. /// <returns></returns>
  994. [HttpPost]
  995. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  996. public async Task<IActionResult> GetGroupList(GroupListDto dto)
  997. {
  998. var groupData = await _groupRepository.GetGroupList(dto);
  999. if (groupData.Code != 0)
  1000. {
  1001. return Ok(JsonView(false, groupData.Msg));
  1002. }
  1003. return Ok(JsonView(groupData.Data));
  1004. }
  1005. /// <summary>
  1006. /// 分页查询团组列表
  1007. /// </summary>
  1008. /// <param name="dto"></param>
  1009. /// <returns></returns>
  1010. [HttpPost]
  1011. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1012. public async Task<IActionResult> QueryGroupListOffset(QueryGroupListOffsetDto dto)
  1013. {
  1014. var watch = new Stopwatch();
  1015. watch.Start();
  1016. RefAsync<int> total = 0;
  1017. var countyDatas = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  1018. .Where((di) => di.IsDel == 0 && !string.IsNullOrWhiteSpace(di.TeamName))
  1019. .WhereIF(!string.IsNullOrEmpty(dto.Search), (di) => di.TeamName.Contains(dto.Search))
  1020. .OrderBy((di) => new { id = SqlFunc.Desc(di.Id) })
  1021. .Select((di) => new { id = di.Id, name = di.TeamName, di.ClientName, di.VisitPNumber, di.VisitCountry, di.VisitDays, di.VisitStartDate, di.VisitEndDate, di.TourCode })
  1022. .Distinct()
  1023. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  1024. watch.Stop();
  1025. return Ok(JsonView(true, $"{MsgTips.Succeed},耗时 {watch.ElapsedMilliseconds} ms", countyDatas, total));
  1026. }
  1027. /// <summary>
  1028. /// 接团信息列表 Page Init
  1029. /// </summary>
  1030. /// <returns></returns>
  1031. [HttpPost]
  1032. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1033. public async Task<IActionResult> PostGroupPageListInit()
  1034. {
  1035. var depDatas = await GeneralMethod.GroupOpAffiliationBranchInit();
  1036. var rankDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 56).Select(x => new { x.Id, x.Name }).ToListAsync();
  1037. rankDatas.Insert(0, new { Id = 0, Name = "全部" });
  1038. var _view = new
  1039. {
  1040. depData = depDatas,
  1041. rankData = rankDatas
  1042. };
  1043. return Ok(JsonView(true, "查询成功!", _view));
  1044. }
  1045. /// <summary>
  1046. /// 接团信息列表 关键字输入提示
  1047. /// </summary>
  1048. /// <param name="keyword">关键字</param>
  1049. /// <returns></returns>
  1050. [HttpGet]
  1051. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1052. public async Task<IActionResult> GroupItemNativeKeywordSearch(string keyword)
  1053. {
  1054. var jw = JsonView(true, "暂无数据");
  1055. if (string.IsNullOrEmpty(keyword)) return Ok(jw);
  1056. var expression = Expressionable
  1057. .Create<Grp_DelegationInfo>()
  1058. .And(x => x.IsDel == 0);
  1059. string field = "TeamName,ClientUnit,ClientName";
  1060. var groupData = _sqlSugar.Queryable<Grp_DelegationInfo>()
  1061. .Where(expression.ToExpression())
  1062. .Select(field)
  1063. .ToList();
  1064. var keywordArray = keyword.ToCharArray();
  1065. var matches = groupData
  1066. .Where(fullString => !string.IsNullOrWhiteSpace(fullString.TeamName) &&
  1067. keywordArray.All(keyword => fullString.TeamName.Contains(keyword)))
  1068. .Select(x => new
  1069. {
  1070. x.TeamName,
  1071. x.ClientUnit,
  1072. x.ClientName
  1073. })
  1074. .DistinctBy(x => x.TeamName)
  1075. .ToList();
  1076. if (matches.Any())
  1077. {
  1078. jw.Code = StatusCodes.Status200OK;
  1079. jw.Msg = "搜索成功";
  1080. jw.Data = matches;
  1081. jw.Count = matches.Count;
  1082. }
  1083. return Ok(jw);
  1084. }
  1085. /// <summary>
  1086. /// 接团信息列表 关键字输入提示(智能版)
  1087. /// </summary>
  1088. /// <param name="keyword">关键字</param>
  1089. /// <returns></returns>
  1090. [HttpGet]
  1091. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1092. public async Task<IActionResult> GroupItemKeywordSearch(string keyword)
  1093. {
  1094. try
  1095. {
  1096. // 验证请求参数
  1097. if (string.IsNullOrEmpty(keyword))
  1098. {
  1099. return Ok(JsonView(true, $"暂无数据!"));
  1100. }
  1101. var searchRequest = new DynamicSearchRequest
  1102. {
  1103. Keyword = keyword,
  1104. RequireAllSingleChars = true,
  1105. PageIndex = 1,
  1106. PageSize = 999999,
  1107. FieldWeights = new Dictionary<string, int>
  1108. {
  1109. { "TeamName", 10 }
  1110. },
  1111. Filters = new List<SearchFilter>()
  1112. {
  1113. new(){Field = "IsDel",Operator="eq",Value="0" }
  1114. },
  1115. OrderBy = "VisitDate",
  1116. ReturnFields = new List<string>() { "TeamName", "ClientUnit", "ClientName" }
  1117. };
  1118. // 验证字段配置
  1119. var validation = _groupSearchService.ValidateFieldConfig(
  1120. searchRequest.FieldWeights,
  1121. searchRequest.ReturnFields);
  1122. if (!validation.IsValid)
  1123. {
  1124. return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
  1125. }
  1126. var result = await _groupSearchService.SearchAsync(searchRequest);
  1127. if (result.Success)
  1128. {
  1129. var data = new List<dynamic>();
  1130. foreach (var item in result.Items)
  1131. {
  1132. data.Add(new
  1133. {
  1134. item.Data.TeamName,
  1135. item.Data.ClientUnit,
  1136. item.Data.ClientName,
  1137. //item.Data.VisitDate
  1138. });
  1139. }
  1140. return Ok(JsonView(true, result.Message, data, data.Count));
  1141. }
  1142. return Ok(JsonView(true, result.Message));
  1143. }
  1144. catch (Exception ex)
  1145. {
  1146. return Ok(JsonView(true, $"搜索服务暂时不可用!"));
  1147. }
  1148. }
  1149. /// <summary>
  1150. /// 接团信息列表 Page
  1151. /// </summary>
  1152. /// <param name="dto">团组列表请求dto</param>
  1153. /// <returns></returns>
  1154. [HttpPost]
  1155. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1156. public async Task<IActionResult> PostGroupPageList(GroupPageListDto dto)
  1157. {
  1158. // 创建Stopwatch实例
  1159. var stopwatch = new Stopwatch();
  1160. stopwatch.Start();
  1161. #region 参数验证
  1162. if (dto.UserId < 1)
  1163. return Ok(JsonView(false, "员工Id为空"));
  1164. if (dto.PageId < 1)
  1165. return Ok(JsonView(false, "页面Id为空"));
  1166. #region 页面操作权限验证
  1167. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1168. if (pageFunAuthView.CheckAuth == 0)
  1169. return Ok(JsonView(false, "您没有查看权限"));
  1170. #endregion
  1171. #endregion
  1172. //if (dto.PortType != 1 && dto.PortType != 2) // web/Android
  1173. // return Ok(JsonView(false, "不支持的端口类型"));
  1174. // 构建查询条件
  1175. var sqlWhereBuilder = new StringBuilder(" WHERE gdi.IsDel = 0");
  1176. var parameters = new List<SugarParameter>();
  1177. // 完成状态筛选
  1178. if (dto.IsSure == 0 || dto.IsSure == 1)
  1179. {
  1180. sqlWhereBuilder.Append(" AND gdi.IsSure = @IsSure");
  1181. parameters.Add(new SugarParameter("@IsSure", dto.IsSure));
  1182. }
  1183. // 搜索条件
  1184. if (!string.IsNullOrWhiteSpace(dto.SearchCriteria))
  1185. {
  1186. var searchParam = $"%{dto.SearchCriteria.Trim()}%";
  1187. sqlWhereBuilder.Append(@"
  1188. AND (ssd.Name LIKE @SearchCriteria
  1189. OR gdi.TeamName LIKE @SearchCriteria
  1190. OR gdi.ClientName LIKE @SearchCriteria
  1191. OR su.CnName LIKE @SearchCriteria)");
  1192. parameters.Add(new SugarParameter("@SearchCriteria", searchParam));
  1193. }
  1194. // 等级筛选
  1195. if (int.TryParse(dto.Rank, out int rankId) && rankId > 0)
  1196. {
  1197. sqlWhereBuilder.Append(" AND gdi.TeamLevSId = @RankId");
  1198. parameters.Add(new SugarParameter("@RankId", rankId));
  1199. }
  1200. // 部门筛选
  1201. var departmentWhere = string.Empty;
  1202. if (!string.IsNullOrWhiteSpace(dto.Department) && !dto.Department.Equals("全部"))
  1203. {
  1204. departmentWhere = " WHERE Department = @Department";
  1205. parameters.Add(new SugarParameter("@Department", dto.Department));
  1206. }
  1207. // 构建SQL查询
  1208. string sql = $@"
  1209. SELECT Row_Number, Id, SalesQuoteNo, TourCode, TeamTypeId, TeamType, Department,
  1210. TeamLevId, TeamLev, TeamName, ClientName, ClientUnit,
  1211. VisitDate, VisitDays, VisitPNumber, JietuanOperatorId,
  1212. JietuanOperator, IsSure, CreateTime, IsBid, Step,
  1213. CONVERT(VARCHAR(19), StepOperationTime, 20) AS StepOperationTime
  1214. FROM (
  1215. SELECT ROW_NUMBER() OVER(ORDER BY gdi.VisitStartDate DESC) AS Row_Number,
  1216. CASE
  1217. WHEN gdi.JietuanOperator IN (4, 21) THEN '国交部'
  1218. ELSE (SELECT DepName FROM OA2023DB.dbo.Sys_Department WHERE Id = su.DepId)
  1219. END AS 'Department',
  1220. gdi.Id, SalesQuoteNo, TourCode, ssd.Id AS TeamTypeId, ssd.Name AS TeamType, gdi.Step,
  1221. ssd1.Id AS TeamLevId, ssd1.Name AS TeamLev, TeamName, ClientName, ClientUnit,
  1222. VisitDate, VisitDays, VisitPNumber, JietuanOperator AS JietuanOperatorId,
  1223. su.CnName AS JietuanOperator, IsSure, gdi.CreateTime, gdi.IsBid,StepOperationTime
  1224. FROM Grp_DelegationInfo gdi
  1225. LEFT JOIN Sys_SetData ssd ON gdi.TeamDid = ssd.Id
  1226. LEFT JOIN Sys_SetData ssd1 ON gdi.TeamLevSId = ssd1.Id
  1227. LEFT JOIN Sys_Users su ON gdi.JietuanOperator = su.Id
  1228. {sqlWhereBuilder}
  1229. ) temp {departmentWhere}";
  1230. // 执行分页查询
  1231. RefAsync<int> total = 0;
  1232. var delegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql)
  1233. .AddParameters(parameters)
  1234. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  1235. if (!delegationList.Any())
  1236. {
  1237. var emptyView = new
  1238. {
  1239. PageFuncAuth = pageFunAuthView,
  1240. Data = delegationList
  1241. };
  1242. return Ok(JsonView(true, "查询成功,暂无数据", emptyView, total));
  1243. }
  1244. // 批量处理团组模块实际操作人和背景颜色设置
  1245. await ProcessDelegationListData(delegationList);
  1246. var resultView = new
  1247. {
  1248. PageFuncAuth = pageFunAuthView,
  1249. Data = delegationList
  1250. };
  1251. stopwatch.Stop();
  1252. return Ok(JsonView(true, $"查询成功!耗时:{stopwatch.Elapsed.TotalSeconds:F3}s", resultView, total));
  1253. }
  1254. /// <summary>
  1255. /// 批量处理团组数据
  1256. /// </summary>
  1257. private async Task ProcessDelegationListData(List<DelegationListView> delegationList)
  1258. {
  1259. var groupIds = delegationList.Select(x => x.Id).ToList();
  1260. // 批量查询信用卡支付记录
  1261. var creditCardPayments = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  1262. .Where(y => groupIds.Contains(y.DIId) && y.IsDel == 0)
  1263. .Select(y => y.DIId)
  1264. .Distinct()
  1265. .ToListAsync();
  1266. // 批量查询费用确认记录
  1267. var feeAcknowledgements = await _sqlSugar.Queryable<Grp_FeeEntryAcknowledge>()
  1268. .Where(y => groupIds.Contains(y.GroupId) && y.IsDel == 0)
  1269. .Where(y => y.IsAcknowledged == AcknowledgeStatusEnum.Acknowledged)
  1270. .Select(y => y.GroupId)
  1271. .Distinct()
  1272. .ToListAsync();
  1273. var creditCardPaymentSet = creditCardPayments.ToHashSet();
  1274. var feeAcknowledgementSet = feeAcknowledgements.ToHashSet();
  1275. // 并行处理每个团组
  1276. var tasks = delegationList.Select(async x =>
  1277. {
  1278. // 处理团组模块实际操作人
  1279. var operators = GeneralMethod.GetGroupModuleOperators(x.Id);
  1280. var operatorNames = new StringBuilder();
  1281. if (operators.Any())
  1282. {
  1283. foreach (var operatorInfo in operators)
  1284. {
  1285. string label = operatorInfo.OperationUsers.Any()
  1286. ? string.Join('、', operatorInfo.OperationUsers.Select(u => u.UserName))
  1287. : "暂未指定";
  1288. operatorNames.AppendLine($"{operatorInfo.CTableName}:{label}");
  1289. operatorNames.AppendLine();
  1290. }
  1291. }
  1292. x.OperatorLabel = operatorNames.ToString().TrimEnd('\n', '\r');
  1293. // 设置背景颜色为红色
  1294. // C表没数据并且没点提醒确认按钮(无成本费用按钮)的团组该行显示红色
  1295. bool hasCreditCardPayment = creditCardPaymentSet.Contains(x.Id);
  1296. bool hasFeeAcknowledgement = feeAcknowledgementSet.Contains(x.Id);
  1297. x.UseRedBackground = !hasCreditCardPayment && !hasFeeAcknowledgement;
  1298. });
  1299. await Task.WhenAll(tasks);
  1300. }
  1301. /// <summary>
  1302. /// 团组列表
  1303. /// </summary>
  1304. /// <returns></returns>
  1305. [HttpPost]
  1306. public async Task<IActionResult> GetGroupListByWhere(GroupListByWhere dto)
  1307. {
  1308. #region 参数验证
  1309. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  1310. if (dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  1311. #region 页面操作权限验证
  1312. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1313. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  1314. #endregion
  1315. #endregion
  1316. if (dto.PortType != 1 && dto.PortType != 2)
  1317. {
  1318. return Ok(JsonView(false, "查询失败!"));
  1319. }
  1320. string orderbyStr = "order by gdi.CreateTime Desc";
  1321. string sqlWhere = string.Empty;
  1322. if (dto.IsSure == 0) //未完成
  1323. {
  1324. sqlWhere += string.Format(@" And IsSure = 0");
  1325. }
  1326. else if (dto.IsSure == 1) //已完成
  1327. {
  1328. sqlWhere += string.Format(@" And IsSure = 1");
  1329. }
  1330. //团组类型
  1331. if (dto.TeamDid > 0)
  1332. {
  1333. sqlWhere += string.Format(@"And TeamDid = {0} ", dto.TeamDid);
  1334. }
  1335. //团组名称
  1336. if (!string.IsNullOrEmpty(dto.TeamName))
  1337. {
  1338. sqlWhere += string.Format(@"And TeamName Like '%{0}%'", dto.TeamName);
  1339. }
  1340. //客户名称
  1341. if (!string.IsNullOrEmpty(dto.ClientName))
  1342. {
  1343. sqlWhere += string.Format(@"And ClientName Like '%{0}%'", dto.ClientName);
  1344. }
  1345. //客户单位
  1346. if (!string.IsNullOrEmpty(dto.ClientUnit))
  1347. {
  1348. sqlWhere += string.Format(@"And ClientUnit Like '%{0}%'", dto.ClientUnit);
  1349. }
  1350. //出访时间
  1351. if (!string.IsNullOrEmpty(dto.visitDataTime))
  1352. {
  1353. sqlWhere += string.Format(@"And VisitDate >= '{0}'", dto.visitDataTime);
  1354. orderbyStr = "order by gdi.VisitDate";
  1355. }
  1356. string sql = string.Format(@"Select Row_Number,Id,SalesQuoteNo,TourCode,TeamTypeId, TeamType,
  1357. TeamLevId,TeamLev,TeamName,ClientName,ClientUnit,
  1358. VisitDate,VisitDays,VisitPNumber,JietuanOperatorId,
  1359. JietuanOperator,IsSure,CreateTime
  1360. From (
  1361. Select row_number() over({0}) as Row_Number,
  1362. gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,
  1363. ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,
  1364. VisitDate,VisitDays,VisitPNumber,JietuanOperator JietuanOperatorId,
  1365. su.CnName JietuanOperator,IsSure,gdi.CreateTime
  1366. From Grp_DelegationInfo gdi
  1367. Left Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  1368. Left Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  1369. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  1370. Where gdi.IsDel = 0 {1}
  1371. ) temp ", orderbyStr, sqlWhere);
  1372. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  1373. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);//ToPageAsync
  1374. #region 处理所属部门
  1375. /*
  1376. * 1.sq 和 gyy 等显示 市场部
  1377. * 2.王鸽和主管及张总还有管理员号统一国交部
  1378. * 2-1. 4 管理员 ,21 张海麟
  1379. */
  1380. var userIds = _DelegationList.Select(it => it.JietuanOperatorId).ToList();
  1381. var userIds1 = new List<int>() { 4, 21 };
  1382. var UserDepDatas = _sqlSugar.Queryable<Sys_Users>()
  1383. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  1384. .Where(u => u.IsDel == 0 && userIds.Contains(u.Id))
  1385. .Select((u, d) => new { UserId = u.Id, DepName = userIds1.Contains(u.Id) ? "国交部" : d.DepName })
  1386. .ToList();
  1387. foreach (var item in _DelegationList)
  1388. {
  1389. item.Department = UserDepDatas.Find(it => item.JietuanOperatorId == it.UserId)?.DepName ?? "Unknown";
  1390. }
  1391. #endregion
  1392. var _view = new
  1393. {
  1394. PageFuncAuth = pageFunAuthView,
  1395. Data = _DelegationList
  1396. };
  1397. return Ok(JsonView(true, $"查询成功!", _view, total));
  1398. }
  1399. /// <summary>
  1400. /// 接团信息详情
  1401. /// </summary>
  1402. /// <param name="dto">团组info请求dto</param>
  1403. /// <returns></returns>
  1404. [HttpPost]
  1405. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1406. public async Task<IActionResult> GetGroupInfo(GroupInfoDto dto)
  1407. {
  1408. var groupData = await _groupRepository.GetGroupInfo(dto);
  1409. if (groupData.Code != 0)
  1410. {
  1411. return Ok(JsonView(false, groupData.Msg));
  1412. }
  1413. return Ok(JsonView(groupData.Data));
  1414. }
  1415. /// <summary>
  1416. /// 接团信息 编辑添加
  1417. /// 基础信息数据源
  1418. /// </summary>
  1419. /// <param name="dto"></param>
  1420. /// <returns></returns>
  1421. [HttpPost]
  1422. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1423. public async Task<IActionResult> GroupEditBasicSource(GroupListDto dto)
  1424. {
  1425. var groupData = await _groupRepository.GroupEditBasicSource(dto);
  1426. if (groupData.Code != 0)
  1427. {
  1428. return Ok(JsonView(false, groupData.Msg));
  1429. }
  1430. return Ok(JsonView(groupData.Data));
  1431. }
  1432. /// <summary>
  1433. /// 成本修改团组信息
  1434. /// </summary>
  1435. /// <param name="dto"></param>
  1436. /// <returns></returns>
  1437. [HttpPost]
  1438. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1439. public async Task<IActionResult> GroupCostEditGroupInfo(GroupCostEditGroupInfoDto dto)
  1440. {
  1441. var jw = JsonView(false, "操作失败");
  1442. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  1443. if (di == null)
  1444. {
  1445. jw.Msg = "参数有误!";
  1446. return Ok(jw);
  1447. }
  1448. #region 添加出访起止时间
  1449. var startTime = new DateTime();
  1450. var endTime = new DateTime();
  1451. if (DateTime.TryParse(dto.VisitDate, out startTime))
  1452. {
  1453. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  1454. }
  1455. else
  1456. {
  1457. jw.Msg = "参数有误!";
  1458. return Ok(jw);
  1459. }
  1460. #endregion
  1461. #region 验证出访时间是否有变化 有变化则重新生成倒推表
  1462. if (!startTime.ToString("yyyy-MM-dd").Equals(di.VisitDate.ToString("yyyy-MM-dd")))
  1463. {
  1464. var msg = "团组成本模块修改出访时间,删除倒推表重新生成";
  1465. var softDel = await _sqlSugar.Updateable<Grp_InvertedList>()
  1466. .SetColumns(x => x.IsDel == 1)
  1467. .SetColumns(x => x.DeleteUserId == 4)
  1468. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  1469. .SetColumns(x => x.Remark == msg)
  1470. .Where(x => x.DiId == dto.Diid)
  1471. .ExecuteCommandAsync();
  1472. //默认创建倒推表
  1473. await _invertedListRep.Create(4, dto.Diid, msg);
  1474. }
  1475. #endregion
  1476. di.VisitDate = startTime;
  1477. di.VisitPNumber = dto.VisitPNumber;
  1478. di.VisitDays = dto.VisitDays;
  1479. di.VisitStartDate = startTime;
  1480. di.VisitEndDate = endTime;
  1481. var count = _sqlSugar.Updateable(di)
  1482. .UpdateColumns(x => new { x.VisitDate, x.VisitPNumber, x.VisitDays, x.VisitStartDate, x.VisitEndDate })
  1483. .ExecuteCommand();
  1484. return Ok(count > 0 ? JsonView(true, "操作成功") : jw);
  1485. }
  1486. /// <summary>
  1487. /// 接团信息 编辑添加
  1488. /// 省份-城市 基础信息数据源
  1489. /// </summary>
  1490. /// <param name="dto"></param>
  1491. /// <returns></returns>
  1492. [HttpPost]
  1493. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1494. public async Task<IActionResult> GroupProvCityBasicSource(GroupProvCityBasicSourceDto dto)
  1495. {
  1496. int pageIndex = dto.PageIndex, pageSize = dto.PageSize;
  1497. string search = dto.Search;
  1498. var data = await _groupRepository.CityBasicSource();
  1499. int total = data.Length;
  1500. data = data.WhereIF(!string.IsNullOrEmpty(search), x => x.Name.Contains(search))
  1501. .Skip((pageIndex - 1) * pageSize)
  1502. .Take(pageSize)
  1503. .ToArray();
  1504. return Ok(JsonView(data, total));
  1505. }
  1506. /// <summary>
  1507. /// 接团信息 操作(增改)
  1508. /// </summary>
  1509. /// <param name="dto"></param>
  1510. /// <returns></returns>
  1511. [HttpPost]
  1512. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1513. public async Task<IActionResult> GroupOperation(GroupOperationDto dto)
  1514. {
  1515. // 创建 Stopwatch 实例
  1516. Stopwatch stopwatch = Stopwatch.StartNew();
  1517. decimal ffrPrice = 0.00M;
  1518. DateTime? visitDt = null;
  1519. if (dto.Status == 2)
  1520. {
  1521. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.Id && x.IsDel == 0);
  1522. if (groupInfo != null)
  1523. {
  1524. ffrPrice = groupInfo.PaymentMoney;
  1525. visitDt = groupInfo.VisitDate.AddDays(-groupInfo.PayDay);
  1526. #region 验证出访时间是否有变化 有变化则重新生成倒推表
  1527. if (DateTime.TryParse(dto.VisitDate, out DateTime startTime))
  1528. {
  1529. if (!startTime.ToString("yyyy-MM-dd").Equals(groupInfo.VisitDate.ToString("yyyy-MM-dd")))
  1530. {
  1531. var msg = "团组信息模块修改出访时间,删除倒推表重新生成";
  1532. var softDel = await _sqlSugar.Updateable<Grp_InvertedList>()
  1533. .SetColumns(x => x.IsDel == 1)
  1534. .SetColumns(x => x.DeleteUserId == 4)
  1535. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  1536. .SetColumns(x => x.Remark == msg)
  1537. .Where(x => x.DiId == dto.Id)
  1538. .ExecuteCommandAsync();
  1539. //默认创建倒推表
  1540. await _invertedListRep.Create(dto.UserId, dto.Id, msg);
  1541. }
  1542. }
  1543. #endregion
  1544. }
  1545. }
  1546. var groupData = await _groupRepository.GroupOperation(dto);
  1547. if (groupData.Code != 0)
  1548. {
  1549. return Ok(JsonView(false, groupData.Msg));
  1550. }
  1551. int diId = 0;
  1552. try
  1553. {
  1554. //添加时 默认加入团组汇率
  1555. if (dto.Status == 1) //添加
  1556. {
  1557. diId = groupData.Data;
  1558. //添加默认币种
  1559. await GeneralMethod.PostGroupRateAddInit(dto.UserId, diId);
  1560. //默认分配权限
  1561. await GeneralMethod.PostGroupAuthAddInit(dto.UserId, diId);
  1562. //消息提示 王鸽 主管号 2024-10-21 新增LZ UID
  1563. var _managerIds = new List<int>() { 22, 32, 21 };
  1564. var userIds = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && _managerIds.Contains(it.JobPostId)).Select(it => it.Id).ToList();
  1565. if (userIds.Count > 0)
  1566. {
  1567. userIds.Add(208);
  1568. //创建团组管控
  1569. GroupStepForDelegation.CreateWorkStep(diId);
  1570. //发送消息
  1571. string groupName = dto.TeamName;
  1572. string createGroupUser = string.Empty;
  1573. var userInfo = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.Id == dto.UserId).First();
  1574. if (userInfo != null) createGroupUser = userInfo.CnName;
  1575. string title = $"系统通知";
  1576. string content = $"团组[{groupName}(创建人:{createGroupUser})]创建成功,请前往页面进行下一步操作!";
  1577. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  1578. }
  1579. //默认创建倒推表
  1580. await _invertedListRep.Create(dto.UserId, diId);
  1581. //默认创建签证流程
  1582. await _visaProcessRep.Create(dto.UserId, diId);
  1583. //默认创建团组流程总览信息
  1584. await _processOverviewRep.ProcessInitAsync(diId, dto.UserId);
  1585. }
  1586. else if (dto.Status == 2)
  1587. {
  1588. diId = dto.Id;
  1589. }
  1590. #region 签证人员团组时间通知
  1591. #region 计算出访起止时间
  1592. var startTime = new DateTime();
  1593. var endTime = new DateTime();
  1594. if (DateTime.TryParse(dto.VisitDate, out startTime))
  1595. {
  1596. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  1597. }
  1598. #endregion
  1599. #endregion
  1600. #region 团组操作默认添加/修改收款账单
  1601. if (dto.PayDay > 0 && dto.PaymentMoney > 0)
  1602. {
  1603. var ffrInfo = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  1604. .Where(x => x.IsDel == 0 &&
  1605. x.Diid == diId &&
  1606. x.Remark.Equals("预付款")
  1607. )
  1608. .WhereIF(ffrPrice > 0, x => x.ItemSumPrice == ffrPrice)
  1609. .WhereIF(visitDt != null, x => x.CreateTime == visitDt)
  1610. .FirstAsync();
  1611. ffrInfo = new Fin_ForeignReceivables()
  1612. {
  1613. Diid = diId,
  1614. PriceName = dto.ClientUnit,
  1615. Price = dto.PaymentMoney,
  1616. Count = 1,
  1617. Unit = $"元",
  1618. ItemSumPrice = dto.PaymentMoney,
  1619. Rate = 1.0000M,
  1620. Currency = 836,
  1621. AddingWay = 0,
  1622. CreateUserId = dto.UserId,
  1623. CreateTime = Convert.ToDateTime(dto.VisitDate).AddDays(-dto.PayDay),
  1624. Remark = $"预付款"
  1625. };
  1626. if (ffrInfo == null) //Add
  1627. {
  1628. await _sqlSugar.Insertable(ffrInfo).ExecuteCommandAsync();
  1629. }
  1630. else //修改
  1631. {
  1632. await _sqlSugar.Updateable(ffrInfo)
  1633. .UpdateColumns(x => new
  1634. {
  1635. x.PriceName,
  1636. x.Price,
  1637. x.ItemSumPrice,
  1638. x.CreateTime,
  1639. x.CreateUserId
  1640. })
  1641. .WhereColumns(x => x.Id)
  1642. .ExecuteCommandAsync();
  1643. }
  1644. }
  1645. #endregion
  1646. if (diId > 0)
  1647. {
  1648. await AppNoticeLibrary.SendUserMsg_GroupTimeInfo_ToVisaUser(diId, startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"));
  1649. }
  1650. // 停止计时
  1651. stopwatch.Stop();
  1652. return Ok(JsonView(true, $"操作成功!{stopwatch.ElapsedMilliseconds}ms", diId));
  1653. }
  1654. catch (Exception ex)
  1655. {
  1656. // 停止计时
  1657. stopwatch.Stop();
  1658. Logs("[response]" + JsonConvert.SerializeObject(dto));
  1659. Logs(ex.Message);
  1660. //return Ok(JsonView(false, $"{ex.Message}[{stopwatch.ElapsedMilliseconds}ms]"));
  1661. }
  1662. // 停止计时
  1663. stopwatch.Stop();
  1664. return Ok(JsonView(true, $"操作成功!{stopwatch.ElapsedMilliseconds}ms", diId));
  1665. }
  1666. /// <summary>
  1667. /// 接团流程操作(增改)
  1668. /// 安卓端使用 建团时添加客户名单
  1669. /// </summary>
  1670. /// <param name="dto"></param>
  1671. /// <returns></returns>
  1672. [HttpPost]
  1673. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1674. public async Task<IActionResult> GroupProcessOperation(GroupProcessOperationDto dto)
  1675. {
  1676. #region 参数验证
  1677. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  1678. #region 页面操作权限验证
  1679. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, 104);
  1680. //if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "客户名单您没有添加权限!"));
  1681. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, 27);
  1682. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "团组操作您没有添加权限!"));
  1683. #endregion
  1684. #endregion
  1685. try
  1686. {
  1687. //_sqlSugar.BeginTran();
  1688. decimal ffrPrice = 0.00M;
  1689. DateTime? visitDt = null;
  1690. if (dto.Status == 2)
  1691. {
  1692. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.Id && x.IsDel == 0);
  1693. if (groupInfo != null)
  1694. {
  1695. ffrPrice = groupInfo.PaymentMoney;
  1696. visitDt = groupInfo.VisitDate.AddDays(-groupInfo.PayDay);
  1697. }
  1698. }
  1699. var _dto = new GroupOperationDto();
  1700. _dto = _mapper.Map<GroupProcessOperationDto, GroupOperationDto>(dto);
  1701. var groupData = await _groupRepository.GroupOperation(_dto);
  1702. if (groupData.Code != 0)
  1703. {
  1704. return Ok(JsonView(false, "团组操作添加失败!" + groupData.Msg));
  1705. }
  1706. int diId = 0;
  1707. //添加时 默认加入团组汇率
  1708. if (dto.Status == 1) //添加
  1709. {
  1710. diId = groupData.Data;
  1711. //添加默认币种
  1712. await GeneralMethod.PostGroupRateAddInit(dto.UserId, diId);
  1713. //默认分配权限
  1714. await GeneralMethod.PostGroupAuthAddInit(dto.UserId, diId);
  1715. //消息提示 王鸽 主管号 2024-10-21 新增LZ UID
  1716. var _managerIds = new List<int>() { 21, 22, 32 };
  1717. var userIds = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && _managerIds.Contains(it.JobPostId)).Select(it => it.Id).ToList();
  1718. if (userIds.Count > 0)
  1719. {
  1720. userIds.Add(208);
  1721. //创建团组管控
  1722. GroupStepForDelegation.CreateWorkStep(diId);
  1723. //发送消息
  1724. string groupName = dto.TeamName;
  1725. string createGroupUser = string.Empty;
  1726. var userInfo = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.Id == dto.UserId).First();
  1727. if (userInfo != null) createGroupUser = userInfo.CnName;
  1728. string title = $"系统通知";
  1729. string content = $"团组[{groupName}(创建人:{createGroupUser})]创建成功,请前往页面进行下一步操作!";
  1730. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  1731. }
  1732. #region 应用推送
  1733. try
  1734. {
  1735. await AppNoticeLibrary.SendChatMsg_GroupStatus_Create(diId, QiyeWeChatEnum.CompanyCRMChat);
  1736. Sys_Users users = _airTicketResRep.Query<Sys_Users>(s => s.Id == dto.UserId).First();
  1737. Sys_Department department = _airTicketResRep.Query<Sys_Department>(s => s.Id == users.DepId).First();
  1738. if (department.Id == 6 && !string.IsNullOrEmpty(users.QiyeChatUserId))
  1739. {
  1740. var userList = new List<string>() { users.QiyeChatUserId };
  1741. await AppNoticeLibrary.SendUserMsg_GroupStatus_Create(diId, userList);
  1742. }
  1743. }
  1744. catch (Exception ex)
  1745. {
  1746. }
  1747. #endregion
  1748. //默认创建倒推表
  1749. await _invertedListRep.Create(dto.UserId, diId);
  1750. //默认创建签证流程
  1751. await _visaProcessRep.Create(dto.UserId, diId);
  1752. //默认创建团组流程总览信息
  1753. await _processOverviewRep.ProcessInitAsync(diId, dto.UserId);
  1754. }
  1755. if (dto.Status == 2)
  1756. {
  1757. diId = dto.Id;
  1758. if (diId == 0)
  1759. {
  1760. //_sqlSugar.RollbackTran();
  1761. return Ok(JsonView(false, "修改失败! 未添加团组id" + groupData.Msg));
  1762. }
  1763. }
  1764. var viewData = await _tourClientListRep.OperMultiple(dto.TourClientListInfos, diId, dto.UserId);
  1765. if (viewData.Code != 0)
  1766. {
  1767. //_sqlSugar.RollbackTran();
  1768. return Ok(JsonView(false, "客户名单添加失败!" + viewData.Msg));
  1769. }
  1770. #region 团组操作默认添加/修改收款账单
  1771. if (dto.PayDay > 0 && dto.PaymentMoney > 0)
  1772. {
  1773. var ffrInfo = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  1774. .Where(x => x.IsDel == 0 &&
  1775. x.Diid == diId &&
  1776. x.Remark.Equals("预付款")
  1777. )
  1778. .WhereIF(ffrPrice > 0, x => x.ItemSumPrice == ffrPrice)
  1779. .WhereIF(visitDt != null, x => x.CreateTime == visitDt)
  1780. .FirstAsync();
  1781. ffrInfo = new Fin_ForeignReceivables()
  1782. {
  1783. Diid = diId,
  1784. PriceName = dto.ClientUnit,
  1785. Price = dto.PaymentMoney,
  1786. Count = 1,
  1787. Unit = $"元",
  1788. ItemSumPrice = dto.PaymentMoney,
  1789. Rate = 1.0000M,
  1790. Currency = 836,
  1791. AddingWay = 0,
  1792. CreateUserId = dto.UserId,
  1793. CreateTime = Convert.ToDateTime(dto.VisitDate).AddDays(-dto.PayDay),
  1794. Remark = $"预付款"
  1795. };
  1796. if (ffrInfo == null) //Add
  1797. {
  1798. await _sqlSugar.Insertable(ffrInfo).ExecuteCommandAsync();
  1799. }
  1800. else //修改
  1801. {
  1802. await _sqlSugar.Updateable<Fin_ForeignReceivables>(ffrInfo)
  1803. .UpdateColumns(x => new
  1804. {
  1805. x.PriceName,
  1806. x.Price,
  1807. x.ItemSumPrice,
  1808. x.CreateTime,
  1809. x.CreateUserId
  1810. })
  1811. .WhereColumns(x => x.Id)
  1812. .ExecuteCommandAsync();
  1813. }
  1814. }
  1815. #endregion
  1816. #region 签证人员团组时间通知
  1817. #region 计算出访起止时间
  1818. var startTime = new DateTime();
  1819. var endTime = new DateTime();
  1820. if (DateTime.TryParse(dto.VisitDate, out startTime))
  1821. {
  1822. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  1823. }
  1824. #endregion
  1825. if (diId > 0)
  1826. {
  1827. await AppNoticeLibrary.SendUserMsg_GroupTimeInfo_ToVisaUser(diId, startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"));
  1828. }
  1829. #endregion
  1830. //_sqlSugar.CommitTran();
  1831. return Ok(JsonView(true, "添加成功"));
  1832. }
  1833. catch (Exception ex)
  1834. {
  1835. _sqlSugar.RollbackTran();
  1836. return Ok(JsonView(false, ex.Message));
  1837. }
  1838. }
  1839. /// <summary>
  1840. /// 接团流程操作(增改)
  1841. /// 安卓端使用 建团时添加客户名单
  1842. /// </summary>
  1843. /// <param name="dto"></param>
  1844. /// <returns></returns>
  1845. [HttpPost]
  1846. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1847. public async Task<IActionResult> GroupProcessOperation1(GroupProcessOperationDto dto)
  1848. {
  1849. #region 参数验证
  1850. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  1851. #region 页面操作权限验证
  1852. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, 104);
  1853. //if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "客户名单您没有添加权限!"));
  1854. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, 27);
  1855. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "团组操作您没有添加权限!"));
  1856. #endregion
  1857. #endregion
  1858. _sqlSugar.BeginTran();
  1859. decimal ffrPrice = 0.00M;
  1860. DateTime? visitDt = null;
  1861. if (dto.Status == 2)
  1862. {
  1863. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.Id && x.IsDel == 0);
  1864. if (groupInfo != null)
  1865. {
  1866. ffrPrice = groupInfo.PaymentMoney;
  1867. visitDt = groupInfo.VisitDate.AddDays(-groupInfo.PayDay);
  1868. }
  1869. }
  1870. var _dto = new GroupOperationDto();
  1871. _dto = _mapper.Map<GroupProcessOperationDto, GroupOperationDto>(dto);
  1872. var groupData = await _groupRepository.GroupOperation(_dto);
  1873. if (groupData.Code != 0)
  1874. {
  1875. _sqlSugar.RollbackTran();
  1876. return Ok(JsonView(false, "团组操作添加失败!" + groupData.Msg));
  1877. }
  1878. try
  1879. {
  1880. int diId = 0;
  1881. //添加时 默认加入团组汇率
  1882. if (dto.Status == 1) //添加
  1883. {
  1884. diId = groupData.Data;
  1885. //添加默认币种
  1886. await GeneralMethod.PostGroupRateAddInit(dto.UserId, diId);
  1887. //默认分配权限
  1888. await GeneralMethod.PostGroupAuthAddInit(dto.UserId, diId);
  1889. //消息提示 王鸽 主管号 2024-10-21 新增LZ UID
  1890. var _managerIds = new List<int>() { 21, 22, 32 };
  1891. var userIds = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && _managerIds.Contains(it.JobPostId)).Select(it => it.Id).ToList();
  1892. if (userIds.Count > 0)
  1893. {
  1894. userIds.Add(208);
  1895. //创建团组管控
  1896. GroupStepForDelegation.CreateWorkStep(diId);
  1897. //发送消息
  1898. string groupName = dto.TeamName;
  1899. string createGroupUser = string.Empty;
  1900. var userInfo = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.Id == dto.UserId).First();
  1901. if (userInfo != null) createGroupUser = userInfo.CnName;
  1902. string title = $"系统通知";
  1903. string content = $"团组[{groupName}(创建人:{createGroupUser})]创建成功,请前往页面进行下一步操作!";
  1904. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  1905. }
  1906. #region 应用推送
  1907. try
  1908. {
  1909. await AppNoticeLibrary.SendChatMsg_GroupStatus_Create(diId, QiyeWeChatEnum.CompanyCRMChat);
  1910. Sys_Users users = _airTicketResRep.Query<Sys_Users>(s => s.Id == dto.UserId).First();
  1911. Sys_Department department = _airTicketResRep.Query<Sys_Department>(s => s.Id == users.DepId).First();
  1912. if (department.Id == 6 && !string.IsNullOrEmpty(users.QiyeChatUserId))
  1913. {
  1914. var userList = new List<string>() { users.QiyeChatUserId };
  1915. await AppNoticeLibrary.SendUserMsg_GroupStatus_Create(diId, userList);
  1916. }
  1917. }
  1918. catch (Exception ex)
  1919. {
  1920. _sqlSugar.CommitTran();
  1921. return Ok(JsonView(true, "操作成功! 应用推送异常:" + groupData.Msg));
  1922. }
  1923. #endregion
  1924. //默认创建倒推表
  1925. await _invertedListRep.Create(dto.UserId, diId);
  1926. }
  1927. else if (dto.Status == 2)
  1928. {
  1929. diId = dto.Id;
  1930. if (diId == 0)
  1931. {
  1932. _sqlSugar.RollbackTran();
  1933. return Ok(JsonView(false, "操作失败! 未添加团组id" + groupData.Msg));
  1934. }
  1935. }
  1936. var viewData = await _tourClientListRep.OperMultiple(dto.TourClientListInfos, diId, dto.UserId);
  1937. if (viewData.Code != 0)
  1938. {
  1939. _sqlSugar.RollbackTran();
  1940. return Ok(JsonView(false, "客户名单添加失败!" + viewData.Msg));
  1941. }
  1942. #region 团组操作默认添加/修改收款账单
  1943. if (dto.PayDay > 0 && dto.PaymentMoney > 0)
  1944. {
  1945. var ffrInfo = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  1946. .Where(x => x.IsDel == 0 &&
  1947. x.Diid == diId &&
  1948. x.Remark.Equals("预付款")
  1949. )
  1950. .WhereIF(ffrPrice > 0, x => x.ItemSumPrice == ffrPrice)
  1951. .WhereIF(visitDt != null, x => x.CreateTime == visitDt)
  1952. .FirstAsync();
  1953. ffrInfo = new Fin_ForeignReceivables()
  1954. {
  1955. Diid = diId,
  1956. PriceName = dto.ClientUnit,
  1957. Price = dto.PaymentMoney,
  1958. Count = 1,
  1959. Unit = $"元",
  1960. ItemSumPrice = dto.PaymentMoney,
  1961. Rate = 1.0000M,
  1962. Currency = 836,
  1963. AddingWay = 0,
  1964. CreateUserId = dto.UserId,
  1965. CreateTime = Convert.ToDateTime(dto.VisitDate).AddDays(-dto.PayDay),
  1966. Remark = $"预付款"
  1967. };
  1968. if (ffrInfo == null) //Add
  1969. {
  1970. await _sqlSugar.Insertable(ffrInfo).ExecuteCommandAsync();
  1971. }
  1972. else //修改
  1973. {
  1974. await _sqlSugar.Updateable<Fin_ForeignReceivables>(ffrInfo)
  1975. .UpdateColumns(x => new
  1976. {
  1977. x.PriceName,
  1978. x.Price,
  1979. x.ItemSumPrice,
  1980. x.CreateTime,
  1981. x.CreateUserId
  1982. })
  1983. .WhereColumns(x => x.Id)
  1984. .ExecuteCommandAsync();
  1985. }
  1986. }
  1987. #endregion
  1988. #region 签证人员团组时间通知
  1989. #region 计算出访起止时间
  1990. var startTime = new DateTime();
  1991. var endTime = new DateTime();
  1992. if (DateTime.TryParse(dto.VisitDate, out startTime))
  1993. {
  1994. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  1995. }
  1996. #endregion
  1997. if (diId > 0)
  1998. {
  1999. await AppNoticeLibrary.SendUserMsg_GroupTimeInfo_ToVisaUser(diId, startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"));
  2000. }
  2001. #endregion
  2002. _sqlSugar.CommitTran();
  2003. return Ok(JsonView(true));
  2004. }
  2005. catch (Exception ex)
  2006. {
  2007. _sqlSugar.RollbackTran();
  2008. return Ok(JsonView(false, ex.Message));
  2009. }
  2010. }
  2011. /// <summary>
  2012. /// 接团信息 操作(删除)
  2013. /// </summary>
  2014. /// <param name="dto"></param>
  2015. /// <returns></returns>
  2016. [HttpPost]
  2017. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2018. public async Task<IActionResult> GroupDel(GroupDelDto dto)
  2019. {
  2020. var diId = dto.Id;
  2021. if (diId < 1) return Ok(JsonView(false, MsgTips.Id));
  2022. #region 删除 验证
  2023. /*
  2024. * 1、收款账单数据:0 条
  2025. * 2、收款退还数据:0 条
  2026. * 3、机票费用数据:0 条
  2027. * 4、签证费用数据:0 条
  2028. * 5、保险费用数据:0 条
  2029. * 6、酒店费用数据:0 条
  2030. * 7、公务出访数据:1 条
  2031. * 8、邀请公务活动费用数据:1 条
  2032. * 9、OP费用数据:5 条
  2033. * 10、其他费用数据:0 条
  2034. * 11、团组日付报销费用数据:0 条
  2035. *
  2036. * 温馨提示:该团组已产生费用,不允许删除;如需删除,请先删除对应版块费用,谢谢!
  2037. */
  2038. //收款账单
  2039. int frCount = _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(x => x.IsDel == 0 && x.Diid == diId).Count();
  2040. //收款退还
  2041. int fraomCount = _sqlSugar.Queryable<Fin_PaymentRefundAndOtherMoney>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2042. //机票费用
  2043. int arCount = _sqlSugar.Queryable<Grp_AirTicketReservations>().Where(x => x.IsDel == 0 && x.DIId == diId).Count();
  2044. //签证费用
  2045. int viCount = _sqlSugar.Queryable<Grp_VisaInfo>().Where(x => x.IsDel == 0 && x.DIId == diId).Count();
  2046. //保险费用
  2047. int cCount = _sqlSugar.Queryable<Grp_Customers>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2048. //酒店费用
  2049. int hrCount = _sqlSugar.Queryable<Grp_HotelReservations>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2050. //公务出访
  2051. int oaCount = _sqlSugar.Queryable<Res_OfficialActivities>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2052. //邀请公务活动费用
  2053. int ioaCount = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2054. //OP费用
  2055. int ctggrCount = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2056. //其他费用
  2057. int dpCount = _sqlSugar.Queryable<Grp_DecreasePayments>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2058. //团组日付报销费用
  2059. int dfpCount = _sqlSugar.Queryable<Fin_DailyFeePayment>().Where(x => x.IsDel == 0 && x.GroupId == diId).Count();
  2060. var feeCount = frCount + fraomCount + arCount + viCount + cCount + hrCount + oaCount + ioaCount + ctggrCount + dpCount + dfpCount;
  2061. if (feeCount > 0)
  2062. {
  2063. var delMsgTips = new StringBuilder();
  2064. delMsgTips.AppendLine($"1、收款账单数据:{frCount} 条");
  2065. delMsgTips.AppendLine($"2、收款退换数据:{fraomCount} 条");
  2066. delMsgTips.AppendLine($"3、机票费用数据:{arCount} 条");
  2067. delMsgTips.AppendLine($"4、签证费用数据:{viCount} 条");
  2068. delMsgTips.AppendLine($"5、保险费用数据:{cCount} 条");
  2069. delMsgTips.AppendLine($"6、酒店费用数据:{hrCount} 条");
  2070. delMsgTips.AppendLine($"7、公务出访数据:{oaCount} 条");
  2071. delMsgTips.AppendLine($"8、邀请公务活动费用数据:{ioaCount} 条");
  2072. delMsgTips.AppendLine($"9、OP费用数据:{ctggrCount} 条");
  2073. delMsgTips.AppendLine($"10、其他费用数据:{dpCount} 条");
  2074. delMsgTips.AppendLine($"11、团组日付报销费用数据:{dfpCount} 条");
  2075. delMsgTips.AppendLine($"");
  2076. delMsgTips.AppendLine($"温馨提示:该团组已产生费用,不允许删除;如需删除,请先删除对应版块费用,谢谢!");
  2077. return Ok(JsonView(false, delMsgTips.ToString()));
  2078. }
  2079. #endregion
  2080. var groupData = await _groupRepository.GroupDel(dto);
  2081. if (groupData.Code != 0)
  2082. {
  2083. return Ok(JsonView(false, groupData.Msg));
  2084. }
  2085. return Ok(JsonView(true));
  2086. }
  2087. /// <summary>
  2088. /// 获取团组销售报价号
  2089. /// 团组添加时 使用
  2090. /// </summary>
  2091. /// <returns></returns>
  2092. [HttpPost]
  2093. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2094. public async Task<IActionResult> GetGroupSalesQuoteNo()
  2095. {
  2096. var groupData = await _groupRepository.GetGroupSalesQuoteNo();
  2097. if (groupData.Code != 0)
  2098. {
  2099. return Ok(JsonView(false, groupData.Msg));
  2100. }
  2101. object salesQuoteNo = new
  2102. {
  2103. SalesQuoteNo = groupData.Data
  2104. };
  2105. return Ok(JsonView(salesQuoteNo));
  2106. }
  2107. /// <summary>
  2108. /// 设置确认出团
  2109. /// </summary>
  2110. /// <param name="dto"></param>
  2111. /// <returns></returns>
  2112. [HttpPost]
  2113. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2114. public async Task<IActionResult> SetConfirmationGroup(ConfirmationGroupDto dto)
  2115. {
  2116. var groupData = await _groupRepository.ConfirmationGroup(dto);
  2117. if (groupData.Code != 0)
  2118. {
  2119. return Ok(JsonView(false, groupData.Msg));
  2120. }
  2121. var groupInfo = _groupRepository.Query(s => s.Id == dto.GroupId).First();
  2122. #region OA消息推送
  2123. try
  2124. {
  2125. string groupName = groupInfo.TeamName;
  2126. var userIds = _airTicketResRep.Query<Sys_Users>(s => s.DepId == 7 && s.IsDel == 0).Select(x => x.Id).ToList();
  2127. string title = $"系统通知";
  2128. string content = $"团组[{groupName}]已确认出团!";
  2129. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, dto.GroupId);
  2130. }
  2131. catch (Exception ex)
  2132. {
  2133. }
  2134. #endregion
  2135. #region 应用推送
  2136. try
  2137. {
  2138. await AppNoticeLibrary.SendChatMsg_GroupStatus_Create(dto.GroupId, QiyeWeChatEnum.CompanyCRMChat);
  2139. Sys_Users users = _airTicketResRep.Query<Sys_Users>(s => s.Id == groupInfo.JietuanOperator).First();
  2140. Sys_Department department = _airTicketResRep.Query<Sys_Department>(s => s.Id == users.DepId).First();
  2141. if (department.Id == 6 && !string.IsNullOrEmpty(users.QiyeChatUserId))
  2142. {
  2143. var userList = new List<string>() { users.QiyeChatUserId };
  2144. await AppNoticeLibrary.SendUserMsg_GroupStatus_Create(dto.GroupId, userList);
  2145. }
  2146. }
  2147. catch (Exception ex)
  2148. {
  2149. }
  2150. #endregion
  2151. GroupStepForDelegation.CreateWorkStep(dto.GroupId); //创建管控流程
  2152. return Ok(JsonView(true, "操作成功!", groupData.Data));
  2153. }
  2154. /// <summary>
  2155. /// 获取团组名称data And 签证国别Data
  2156. /// </summary>
  2157. /// <param name="dto"></param>
  2158. /// <returns></returns>
  2159. [HttpPost]
  2160. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2161. public async Task<IActionResult> GetGroupNameAndVisaNationality(GroupNameDto dto)
  2162. {
  2163. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  2164. Where TeamName != '' And IsDel = 0
  2165. Order By VisitDate Desc");
  2166. var groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  2167. var data = new
  2168. {
  2169. groupNameData = groupNameList,
  2170. visaNationalityData = _visaTypeInit.ToList()
  2171. };
  2172. return Ok(JsonView(data));
  2173. }
  2174. /// <summary>
  2175. /// 根据CTable类型返回对应的团组名称及简单数据(APP端)
  2176. /// </summary>
  2177. /// <returns></returns>
  2178. [HttpPost]
  2179. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2180. public async Task<IActionResult> PostGroupNameAndEasy(DecreasePaymentsDto dto)
  2181. {
  2182. try
  2183. {
  2184. Result groupData = await _decreasePaymentsRep.PostGroupNameAndEasy(dto);
  2185. if (groupData.Code != 0)
  2186. {
  2187. return Ok(JsonView(false, groupData.Msg));
  2188. }
  2189. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  2190. }
  2191. catch (Exception ex)
  2192. {
  2193. return Ok(JsonView(false, ex.Message));
  2194. throw;
  2195. }
  2196. }
  2197. /// <summary>
  2198. /// 团组清单 Excel
  2199. /// </summary>
  2200. /// <param name="beginDt">开始时间 EG:“2024-01-01”</param>
  2201. /// <param name="endDt">结束时间 EG;“2024-12-31”</param>
  2202. /// <returns></returns>
  2203. [HttpGet]
  2204. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2205. public async Task<IActionResult> GroupListFile([FromQuery] string beginDt, [FromQuery] string endDt)
  2206. {
  2207. bool beginBool = DateTime.TryParse($"{beginDt} 00:00:00", out DateTime _beginDt),
  2208. endBool = DateTime.TryParse($"{endDt} 23:59:59", out DateTime _endDt);
  2209. if (!beginBool && !endBool)
  2210. {
  2211. return Ok(JsonView(false, "开始或结束时间不正确!"));
  2212. }
  2213. string sql = string.Format(@"
  2214. SELECT
  2215. ROW_NUMBER,
  2216. Id,
  2217. SalesQuoteNo,
  2218. TourCode,
  2219. TeamTypeId,
  2220. TeamType,
  2221. TeamLevId,
  2222. TeamLev,
  2223. TeamName,
  2224. ClientName,
  2225. ClientUnit,
  2226. VisitDate,
  2227. VisitDays,
  2228. VisitPNumber,
  2229. JietuanOperatorId,
  2230. JietuanOperator,
  2231. IsSure,
  2232. CreateUserName,
  2233. IsBid
  2234. FROM
  2235. (
  2236. SELECT
  2237. ROW_NUMBER() OVER(
  2238. ORDER BY
  2239. gdi.VisitDate Desc
  2240. ) AS ROW_NUMBER,
  2241. gdi.Id,
  2242. SalesQuoteNo,
  2243. TourCode,
  2244. ssd.Id TeamTypeId,
  2245. ssd.Name TeamType,
  2246. ssd1.Id TeamLevId,
  2247. ssd1.Name TeamLev,
  2248. TeamName,
  2249. ClientName,
  2250. ClientUnit,
  2251. VisitDate,
  2252. VisitDays,
  2253. VisitPNumber,
  2254. JietuanOperator JietuanOperatorId,
  2255. su.CnName JietuanOperator,
  2256. IsSure,
  2257. gdi.CreateTime,
  2258. su1.CnName As CreateUserName,
  2259. gdi.IsBid
  2260. FROM
  2261. Grp_DelegationInfo gdi
  2262. LEFT JOIN Sys_SetData ssd ON gdi.TeamDid = ssd.Id
  2263. LEFT JOIN Sys_SetData ssd1 ON gdi.TeamLevSId = ssd1.Id
  2264. LEFT JOIN Sys_Users su ON gdi.JietuanOperator = su.Id
  2265. LEFT JOIN Sys_Users su1 ON gdi.CreateUserId = su1.Id
  2266. WHERE
  2267. gdi.IsDel = 0
  2268. AND gdi.IsBid = 0
  2269. AND gdi.VisitDate BETWEEN '{0}' AND '{1}'
  2270. ) temp", _beginDt.ToString("yyyy-MM-dd HH:mm:ss"), _endDt.ToString("yyyy-MM-dd HH:mm:ss"));
  2271. var groupList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
  2272. #region 处理所属部门
  2273. /*
  2274. * 1.sq 和 gyy 等显示 市场部
  2275. * 2.王鸽和主管及张总还有管理员号统一国交部
  2276. * 2-1. 4 管理员 ,21 张海麟
  2277. */
  2278. var userIds = groupList.Select(it => it.JietuanOperatorId).ToList();
  2279. var userIds1 = new List<int>() { 4, 21 };
  2280. var userDepDatas = await _sqlSugar.Queryable<Sys_Users>()
  2281. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  2282. .Where(u => u.IsDel == 0 && userIds.Contains(u.Id))
  2283. .Select((u, d) => new { UserId = u.Id, DepName = userIds1.Contains(u.Id) ? "国交部" : d.DepName })
  2284. .ToListAsync();
  2285. var droupIds = groupList.Select(it => it.Id).ToList();
  2286. var deleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  2287. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  2288. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  2289. .Where((tcl, dc, cc) => tcl.IsDel == 0 && droupIds.Contains(tcl.DiId))
  2290. .Select((tcl, dc, cc) => new ClientInfoInfo_Group
  2291. {
  2292. DiId = tcl.DiId,
  2293. LastName = dc.LastName,
  2294. FirstName = dc.FirstName,
  2295. Sex = dc.Sex,
  2296. Birthday = dc.BirthDay,
  2297. Company = cc.CompanyFullName,
  2298. Job = dc.Job,
  2299. CreateTime = tcl.CreateTime,
  2300. })
  2301. .ToList();
  2302. foreach (var item in groupList)
  2303. {
  2304. item.Department = userDepDatas.Find(it => item.JietuanOperatorId == it.UserId)?.DepName ?? "Unknown";
  2305. string groupFirstName = "";
  2306. var currDatas = deleClientList.Where(x => x.DiId == item.Id).ToList();
  2307. if (currDatas.Any())
  2308. {
  2309. groupFirstName = AesEncryptionHelper.Decrypt(currDatas[0].LastName) + AesEncryptionHelper.Decrypt(currDatas[0].FirstName);
  2310. }
  2311. item.GroupFirst = groupFirstName;
  2312. }
  2313. #endregion
  2314. #region Excel
  2315. var tempPath = AppSettingsHelper.Get("ExcelTempPath");
  2316. var servicePath = AppSettingsHelper.Get("GrpFileBaseUrl");
  2317. var savePath = AppSettingsHelper.Get("GrpListFileBasePath");
  2318. var ftpPath = AppSettingsHelper.Get("GrpListFileFtpPath");
  2319. var fileName = $"团组清单({beginDt}~{endDt}){DateTime.Now:yyyyMMddHHmmss}.xlsx";
  2320. //载入模板
  2321. var designer = new WorkbookDesigner
  2322. {
  2323. Workbook = new Workbook($"{tempPath}团组清单模板.xlsx")
  2324. };
  2325. designer.SetDataSource("Titel", $"团组清单({beginDt}~{endDt})");
  2326. DataTable dt = CommonFun.GetDataTableFromIList<DelegationListView>(groupList); ;
  2327. dt.TableName = "GroupList";
  2328. designer.SetDataSource(dt);
  2329. designer.Process();
  2330. if (!Directory.Exists(savePath))
  2331. {
  2332. Directory.CreateDirectory(savePath);
  2333. }
  2334. string serverPath = $"{savePath}{fileName}";
  2335. designer.Workbook.Save(serverPath);
  2336. string rst = $"{servicePath}{ftpPath}{fileName}";
  2337. #endregion
  2338. return Ok(JsonView(true, "操作成功!", rst));
  2339. }
  2340. /// <summary>
  2341. /// 团组合同下载(1.付款80% 2.付全款)
  2342. /// </summary>
  2343. /// <param name="dto"></param>
  2344. /// <returns></returns>
  2345. /// <exception cref="Exception"></exception>
  2346. [HttpPost]
  2347. public async Task<IActionResult> DownGroupContractFile(DownGroupContractFileDto dto)
  2348. {
  2349. var jw = JsonView(false);
  2350. var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  2351. .FirstAsync(x => x.Id == dto.GroupId && x.IsDel == 0);
  2352. if (di == null)
  2353. {
  2354. jw.Msg = "团组Id有误!";
  2355. return Ok(jw);
  2356. }
  2357. #region 权限校验
  2358. var allDownFile = new List<int>() { 21 };
  2359. try
  2360. {
  2361. var setting = _sqlSugar.Queryable<Sys_SetData>()
  2362. .First(x => x.Id == 1418 && x.IsDel == 0);
  2363. allDownFile.AddRange(JsonConvert.DeserializeObject<List<int>>(setting.Remark));
  2364. }
  2365. catch (Exception)
  2366. { }
  2367. var guojiaoDownFile = new List<int>() { 330, 383 };
  2368. var shichangDownFile = new List<int>() { 95 };
  2369. if (allDownFile.Contains(dto.UserId))
  2370. {
  2371. }
  2372. else if (guojiaoDownFile.Contains(dto.UserId))
  2373. {
  2374. var guojiaobuDi = new List<int>() { 4, 21 };
  2375. var departmentStr = _sqlSugar.Queryable<Sys_Department>()
  2376. .LeftJoin<Sys_Users>((d, u) => d.Id == u.DepId && u.IsDel == 0)
  2377. .Where((d, u) => u.Id == di.JietuanOperator)
  2378. .Select((d, u) => d.DepName)
  2379. .First();
  2380. if (!guojiaobuDi.Contains(di.JietuanOperator) && departmentStr != "策划部" && departmentStr != "国交部")
  2381. {
  2382. jw.Msg = "暂无下载权限!";
  2383. return Ok(jw);
  2384. }
  2385. }
  2386. else if (shichangDownFile.Contains(dto.UserId))
  2387. {
  2388. var dic = new Dictionary<int, int[]>()
  2389. {
  2390. { 95, new int []{ 95 , 337 , 302, 350, 355, 357, 353 , 359 , 361, 368, 364, 366, 369} }
  2391. };
  2392. try
  2393. {
  2394. var sqSetting = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == 1417);
  2395. if (sqSetting != null)
  2396. {
  2397. Dictionary<int, int[]> result = JsonConvert.DeserializeObject<Dictionary<int, int[]>>(sqSetting.Remark);
  2398. foreach (var item in result.Keys)
  2399. {
  2400. if (dic.ContainsKey(item))
  2401. {
  2402. int[] dilatation = new int[dic[item].Length + result[item].Length];
  2403. Array.Copy(dic[item], dilatation, dic[item].Length);
  2404. Array.Copy(result[item], 0, dilatation, dic[item].Length, result[item].Length);
  2405. dic[item] = dilatation;
  2406. }
  2407. else
  2408. {
  2409. dic.Add(item, result[item]);
  2410. }
  2411. }
  2412. }
  2413. if (!dic[95].Contains(di.CreateUserId))
  2414. {
  2415. jw.Msg = "暂无下载权限!";
  2416. return Ok(jw);
  2417. }
  2418. }
  2419. catch (Exception)
  2420. { }
  2421. }
  2422. else if (dto.UserId == di.CreateUserId)
  2423. {
  2424. }
  2425. else
  2426. {
  2427. jw.Msg = "暂无下载权限!";
  2428. return Ok(jw);
  2429. }
  2430. #endregion
  2431. var blackCodeList = await _sqlSugar.Queryable<Air_TicketBlackCode>()
  2432. .Where(x => x.DiId == dto.GroupId && x.IsDel == 0)
  2433. .ToListAsync();
  2434. if (!blackCodeList.Any())
  2435. {
  2436. jw.Msg = "该团无机票行程代码!";
  2437. return Ok(jw);
  2438. }
  2439. var groupEnterExitCost = await _sqlSugar.Queryable<Grp_EnterExitCost>()
  2440. .FirstAsync(x => x.DiId == dto.GroupId && x.IsDel == 0);
  2441. if (groupEnterExitCost == null)
  2442. {
  2443. jw.Msg = "暂无三公费用信息!";
  2444. return Ok(jw);
  2445. }
  2446. var rateList = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(groupEnterExitCost.CurrencyRemark);
  2447. rateList ??= new List<CurrencyInfo>();
  2448. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == di.Id).ToList();
  2449. var dac5 = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  2450. .LeftJoin<Sys_SetData>((x, a) => a.IsDel == 0 && a.Id == x.SetDataId)
  2451. .LeftJoin<Sys_SetData>((x, a, b) => b.IsDel == 0 && b.Id == x.Currency)
  2452. .Where((x, a, b) => x.IsDel == 0 && x.Diid == di.Id)
  2453. .Select((x, a, b) => new
  2454. {
  2455. x.Index,
  2456. itemName = a.Name,
  2457. CurrencyStr = b.Name,
  2458. x.Cost,
  2459. x.SubTotal,
  2460. x.Remark
  2461. })
  2462. .OrderBy((x) => x.Index)
  2463. .ToList();
  2464. decimal stayFeeTotal = groupEnterExitCost.ChoiceThree == 1 ? _DayAndCosts.Where(it => it.Type == 1).Sum(it => it.SubTotal) : 0.00M; // 住宿费
  2465. decimal mealsFeeTotal = groupEnterExitCost.ChoiceFour == 1 ? _DayAndCosts.Where(it => it.Type == 2).Sum(it => it.SubTotal) : 0.00M; // 伙食费费
  2466. decimal miscellaneousFeeTotal = groupEnterExitCost.ChoiceFive == 1 ? _DayAndCosts.Where(it => it.Type == 3).Sum(it => it.SubTotal) : 0.00M; // 公杂费
  2467. decimal tainFeeTotal = groupEnterExitCost.ChoiceSix == 1 ? _DayAndCosts.Where(it => it.Type == 4).Sum(it => it.SubTotal) : 0.00M; // 培训费
  2468. decimal otherPriceTotal = groupEnterExitCost.OtherExpenses_Checked == 1 ? dac5.Sum(x => x.SubTotal) : 0.00M; //其他费用
  2469. decimal insidePayTotal = groupEnterExitCost.ChoiceOne == 1 ? groupEnterExitCost.InsidePay : 0.00M;
  2470. decimal otherFeeTotal = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + otherPriceTotal;
  2471. decimal subJJC = 0.00M,
  2472. subGWC = 0.00M,
  2473. subTDC = 0.00M;
  2474. //经济舱
  2475. if (groupEnterExitCost.SumJJC == 1)
  2476. {
  2477. subJJC = otherFeeTotal + groupEnterExitCost.OutsideJJPay;
  2478. }
  2479. //公务舱
  2480. if (groupEnterExitCost.SumGWC == 1)
  2481. {
  2482. subGWC = otherFeeTotal + groupEnterExitCost.OutsideGWPay;
  2483. }
  2484. //头等舱
  2485. if (groupEnterExitCost.SumTDC == 1)
  2486. {
  2487. subTDC = otherFeeTotal + groupEnterExitCost.OutsideTDPay;
  2488. }
  2489. var groupClints = await _sqlSugar.Queryable<Grp_TourClientList>()
  2490. .LeftJoin<Sys_SetData>((x, s) => s.Id == x.ShippingSpaceTypeId && s.IsDel == 0)
  2491. .LeftJoin<Crm_DeleClient>((x, s, dc) => x.ClientId == dc.Id && dc.IsDel == 0)
  2492. .LeftJoin<Crm_CustomerCompany>((x, s, dc, cc) => dc.CrmCompanyId == cc.Id && cc.IsDel == 0)
  2493. .Where((x, s, dc, cc) => x.DiId == dto.GroupId && x.IsDel == 0)
  2494. .Select((x, s, dc, cc) => new GroupClints
  2495. {
  2496. Id = x.Id,
  2497. Name = s.Name,
  2498. IsAccompany = x.IsAccompany,
  2499. CompanyFullName = cc.CompanyFullName
  2500. })
  2501. .ToListAsync();
  2502. groupClints.ForEach(x => x.CompanyFullName = AesEncryptionHelper.Decrypt(x.CompanyFullName));
  2503. //获取舱位人数
  2504. var cabinCount = groupClints.Where(x => x.IsAccompany != 2 && !x.CompanyFullName.Contains("泛美国际"))
  2505. .GroupBy(x => x.Name)
  2506. .Select(x => new { Cabin = x.Key, Count = x.Count() })
  2507. .ToList();
  2508. string cityPath = string.Empty;
  2509. string startCity = string.Empty;
  2510. string endCity = string.Empty;
  2511. foreach (var item in blackCodeList)
  2512. {
  2513. string city = GeneralMethod.GetGroupCityLine(item, "-");
  2514. cityPath += city + "\r\n";
  2515. if (item.Equals(blackCodeList.First()))
  2516. {
  2517. var sp = city.Split('-');
  2518. startCity = sp[0];
  2519. endCity = sp[^1];
  2520. }
  2521. }
  2522. di.VisitCountry = Regex.Replace(di.VisitCountry, @"[|-]", "、");
  2523. var bookMarkDic = new Dictionary<string, string>
  2524. {
  2525. { "ClientUnit", di.ClientUnit },
  2526. { "VisitCountry", di.VisitCountry },
  2527. { "VisitDate", di.VisitDate.ToString("yyyy年MM月dd日") },
  2528. { "VisitPNumber", di.VisitPNumber.ToString() },
  2529. { "CityPath", cityPath },
  2530. { "StartCity", startCity },
  2531. { "EndCity", endCity },
  2532. { "StayDays", $"{di.VisitDays}天{di.VisitDays - 1}晚" }
  2533. };
  2534. Document doc = null;
  2535. var percentage = 0.8M;
  2536. var fileNameadd = "预付";
  2537. if (dto.FileType == 1)
  2538. {
  2539. doc = new Document($"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Template/团组合同bookmarkFormat.doc");
  2540. }
  2541. else if (dto.FileType == 2)
  2542. {
  2543. doc = new Document($"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Template/团组合同全款无表格.doc");
  2544. percentage = 1;
  2545. fileNameadd = "全款";
  2546. }
  2547. else
  2548. {
  2549. throw new Exception("FileType有误!");
  2550. }
  2551. var builder = new DocumentBuilder(doc);
  2552. decimal totalPrice = 0.00M;
  2553. Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true);
  2554. if (firstTable != null)
  2555. {
  2556. // 遍历表格的行和单元格
  2557. foreach (Aspose.Words.Tables.Row row in firstTable.Rows)
  2558. {
  2559. for (int i = 0; i < row.Cells.Count; i++)
  2560. {
  2561. var cell = row.Cells[i];
  2562. // 读取单元格内容
  2563. string cellTextFirst = row.Cells[0].FirstParagraph.ToString(Aspose.Words.SaveFormat.Text).Trim();
  2564. if (cellTextFirst.Contains("舱位"))
  2565. {
  2566. break;
  2567. }
  2568. if (cellTextFirst == "经济舱" || cellTextFirst == "公务舱")
  2569. {
  2570. if (i == 2)
  2571. {
  2572. if (cellTextFirst == "经济舱")
  2573. {
  2574. // 设置单元格内容
  2575. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2576. cell.FirstParagraph.AppendChild(new Run(doc, subJJC.ToString())); // 添加
  2577. }
  2578. else
  2579. {
  2580. // 设置单元格内容
  2581. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2582. cell.FirstParagraph.AppendChild(new Run(doc, subGWC.ToString())); // 添加
  2583. }
  2584. }
  2585. if (i == 3)
  2586. {
  2587. var count = cabinCount.Find(x => x.Cabin == cellTextFirst)?.Count;
  2588. if (count != null)
  2589. {
  2590. // 设置单元格内容
  2591. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2592. cell.FirstParagraph.AppendChild(new Run(doc, count.ToString())); // 添加
  2593. }
  2594. }
  2595. if (i == 4)
  2596. {
  2597. var rowPrice = 0.00M;
  2598. var count = cabinCount.Find(x => x.Cabin == cellTextFirst)?.Count;
  2599. count ??= 0;
  2600. if (cellTextFirst == "经济舱")
  2601. {
  2602. rowPrice = subJJC * (int)count;
  2603. }
  2604. else
  2605. {
  2606. rowPrice = subGWC * (int)count;
  2607. }
  2608. totalPrice += rowPrice;
  2609. // 设置单元格内容
  2610. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2611. cell.FirstParagraph.AppendChild(new Run(doc, rowPrice.ToString())); // 添加
  2612. }
  2613. }
  2614. }
  2615. }
  2616. }
  2617. bookMarkDic.Add("TotalPrice", (totalPrice).ToString("#0.00"));
  2618. bookMarkDic.Add("TotalPrice1", (totalPrice * percentage).ToString("#0.00"));
  2619. bookMarkDic.Add("TotalPriceChinese", decimal.Parse((totalPrice * percentage).ToString("#0.00")).ConvertCNYUpper());
  2620. //--合同表格部分
  2621. bookMarkDic.Add("TimeNowDate", DateTime.Now.ToString("yyyy年MM月dd日"));
  2622. bookMarkDic.Add("ClientUnit1", di.ClientUnit);
  2623. bookMarkDic.Add("VisitCountry1", di.VisitCountry);
  2624. bookMarkDic.Add("DayCount", di.VisitDays.ToString());
  2625. bookMarkDic.Add("VisitingArea", di.VisitDate.ToString("yyyy年MM月dd日") + "-" + di.VisitEndDate.ToString("yyyy年MM月dd日"));
  2626. bookMarkDic.Add("CityPath1", cityPath);
  2627. bookMarkDic.Add("CityPath2", cityPath);
  2628. Table contractTable = (Table)doc.GetChild(NodeType.Table, 1, true);
  2629. if (contractTable != null)
  2630. {
  2631. //数据源
  2632. var _DayAndCostsAndCity = _sqlSugar.Queryable<Grp_DayAndCost>()
  2633. .LeftJoin<Grp_NationalTravelFee>((it, y) => it.NationalTravelFeeId == y.Id && y.IsDel == 0)
  2634. .LeftJoin<Sys_SetData>((it, y, s) => s.IsDel == 0 && s.Id == it.Currency)
  2635. .Where((it, y, s) => it.IsDel == 0 && it.DiId == di.Id)
  2636. .Select((it, y, s) => new
  2637. {
  2638. it.Cost,
  2639. it.SubTotal,
  2640. it.Type,
  2641. y.Id,
  2642. y.City,
  2643. s.Name,
  2644. CurrencyCodeCn = s.Remark
  2645. })
  2646. .ToList()
  2647. .Select(x => new
  2648. {
  2649. CurrencyCode = x.Name,
  2650. CityId = x.Id,
  2651. x.City,
  2652. di.VisitPNumber,
  2653. x.Type,
  2654. x.Cost,
  2655. x.SubTotal,
  2656. rateList.Find(y => y.CurrencyCode == x.Name)?.Rate,
  2657. x.CurrencyCodeCn,
  2658. });
  2659. var dac1 = _DayAndCostsAndCity.Where(it => it.Type == 1).GroupBy(x => x.CityId).ToList(); //住宿费
  2660. var dac2 = _DayAndCostsAndCity.Where(it => it.Type == 2).GroupBy(x => x.CityId).ToList(); //伙食费
  2661. var dac3 = _DayAndCostsAndCity.Where(it => it.Type == 3).GroupBy(x => x.CityId).ToList(); //公杂费
  2662. var dac4 = _DayAndCostsAndCity.Where(it => it.Type == 4).GroupBy(x => x.CityId).ToList(); //培训费
  2663. var tableSettings = new List<tableSetting>()
  2664. {
  2665. new(){ Index = 1 , Property = "City"},
  2666. new(){ Index = 2 , Property = "CurrencyCodeCn"},
  2667. new(){ Index = 3 , Property = "Cost"},
  2668. new(){ Index = 4 , Property = "VisitPNumber"},
  2669. //new tableSetting{ Index = 5 , Property = ""},
  2670. //new tableSetting{ Index = 6 , Property = ""},
  2671. new(){ Index = 7 , Property = "Rate"},
  2672. //new tableSetting{ Index = 8 , Property = ""},
  2673. };
  2674. //1.住宿费
  2675. int cloneRow = 8;
  2676. int startDayPrice = 8; //写入index
  2677. decimal ZSPriceSum = 0.00M, HSPriceSum = 0.00M, GZPriceSum = 0.00M;
  2678. foreach (var dac in dac1)
  2679. {
  2680. var first = dac.First();
  2681. var dayCount = dac.Count();
  2682. Aspose.Words.Tables.Row row = contractTable.Rows[startDayPrice];
  2683. for (int i = 1; i < row.Cells.Count; i++)
  2684. {
  2685. var cell = row.Cells[i];
  2686. var findProperty = tableSettings.Find(x => x.Index == i);
  2687. if (findProperty != null)
  2688. {
  2689. string value = first.GetType().GetProperty(findProperty.Property).GetValue(first).ToString();
  2690. // 设置单元格内容
  2691. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2692. cell.FirstParagraph.AppendChild(new Run(doc, value)); // 添加
  2693. }
  2694. else
  2695. {
  2696. switch (i)
  2697. {
  2698. case 5:
  2699. cell.FirstParagraph.Runs.Clear();
  2700. cell.FirstParagraph.AppendChild(new Run(doc, dayCount.ToString()));
  2701. break;
  2702. case 6:
  2703. var xiaoji = dayCount * first.VisitPNumber * first.Cost;
  2704. cell.FirstParagraph.Runs.Clear();
  2705. cell.FirstParagraph.AppendChild(new Run(doc, xiaoji.ToString("F2")));
  2706. break;
  2707. case 8:
  2708. var xiaojiRMB = dayCount * first.VisitPNumber * first.SubTotal;
  2709. cell.FirstParagraph.Runs.Clear();
  2710. cell.FirstParagraph.AppendChild(new Run(doc, xiaojiRMB.ToString("F2")));
  2711. ZSPriceSum += xiaojiRMB;
  2712. break;
  2713. default:
  2714. break;
  2715. }
  2716. }
  2717. }
  2718. startDayPrice++;
  2719. if (!dac1.Last().Equals(dac))
  2720. {
  2721. Aspose.Words.Tables.Row newRow = (Aspose.Words.Tables.Row)contractTable.Rows[cloneRow].Clone(true);
  2722. // 将克隆的行追加到原行后面
  2723. contractTable.Rows.Insert(startDayPrice, newRow);
  2724. }
  2725. else
  2726. {
  2727. cloneRow += dac1.Count + 1;
  2728. startDayPrice = cloneRow;
  2729. }
  2730. }
  2731. //2.伙食费
  2732. foreach (var dac in dac2)
  2733. {
  2734. var first = dac.First();
  2735. var dayCount = dac.Count();
  2736. Aspose.Words.Tables.Row row = contractTable.Rows[startDayPrice];
  2737. for (int i = 1; i < row.Cells.Count; i++)
  2738. {
  2739. var cell = row.Cells[i];
  2740. var findProperty = tableSettings.Find(x => x.Index == i);
  2741. if (findProperty != null)
  2742. {
  2743. string value = first.GetType().GetProperty(findProperty.Property).GetValue(first).ToString();
  2744. // 设置单元格内容
  2745. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2746. cell.FirstParagraph.AppendChild(new Run(doc, value)); // 添加
  2747. }
  2748. else
  2749. {
  2750. switch (i)
  2751. {
  2752. case 5:
  2753. cell.FirstParagraph.Runs.Clear();
  2754. cell.FirstParagraph.AppendChild(new Run(doc, dayCount.ToString()));
  2755. break;
  2756. case 6:
  2757. var xiaoji = dayCount * first.VisitPNumber * first.Cost;
  2758. cell.FirstParagraph.Runs.Clear();
  2759. cell.FirstParagraph.AppendChild(new Run(doc, xiaoji.ToString("F2")));
  2760. break;
  2761. case 8:
  2762. var xiaojiRMB = dayCount * first.VisitPNumber * first.SubTotal;
  2763. cell.FirstParagraph.Runs.Clear();
  2764. cell.FirstParagraph.AppendChild(new Run(doc, xiaojiRMB.ToString("F2")));
  2765. HSPriceSum += xiaojiRMB;
  2766. break;
  2767. default:
  2768. break;
  2769. }
  2770. }
  2771. }
  2772. startDayPrice++;
  2773. if (!dac2.Last().Equals(dac))
  2774. {
  2775. Aspose.Words.Tables.Row newRow = (Aspose.Words.Tables.Row)contractTable.Rows[cloneRow].Clone(true);
  2776. // 将克隆的行追加到原行后面
  2777. contractTable.Rows.Insert(startDayPrice, newRow);
  2778. }
  2779. else
  2780. {
  2781. cloneRow += dac2.Count + 1;
  2782. startDayPrice = cloneRow;
  2783. }
  2784. }
  2785. //3.公杂费
  2786. foreach (var dac in dac3)
  2787. {
  2788. var first = dac.First();
  2789. var dayCount = dac.Count();
  2790. Aspose.Words.Tables.Row row = contractTable.Rows[startDayPrice];
  2791. for (int i = 1; i < row.Cells.Count; i++)
  2792. {
  2793. var cell = row.Cells[i];
  2794. var findProperty = tableSettings.Find(x => x.Index == i);
  2795. if (findProperty != null)
  2796. {
  2797. string value = first.GetType().GetProperty(findProperty.Property).GetValue(first).ToString();
  2798. // 设置单元格内容
  2799. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2800. cell.FirstParagraph.AppendChild(new Run(doc, value)); // 添加
  2801. }
  2802. else
  2803. {
  2804. switch (i)
  2805. {
  2806. case 5:
  2807. cell.FirstParagraph.Runs.Clear();
  2808. cell.FirstParagraph.AppendChild(new Run(doc, dayCount.ToString()));
  2809. break;
  2810. case 6:
  2811. var xiaoji = dayCount * first.VisitPNumber * first.Cost;
  2812. cell.FirstParagraph.Runs.Clear();
  2813. cell.FirstParagraph.AppendChild(new Run(doc, xiaoji.ToString("F2")));
  2814. break;
  2815. case 8:
  2816. var xiaojiRMB = dayCount * first.VisitPNumber * first.SubTotal;
  2817. cell.FirstParagraph.Runs.Clear();
  2818. cell.FirstParagraph.AppendChild(new Run(doc, xiaojiRMB.ToString("F2")));
  2819. GZPriceSum += xiaojiRMB;
  2820. break;
  2821. default:
  2822. break;
  2823. }
  2824. }
  2825. }
  2826. startDayPrice++;
  2827. if (!dac3.Last().Equals(dac))
  2828. {
  2829. Aspose.Words.Tables.Row newRow = (Aspose.Words.Tables.Row)contractTable.Rows[cloneRow].Clone(true);
  2830. // 将克隆的行追加到原行后面
  2831. contractTable.Rows.Insert(startDayPrice, newRow);
  2832. }
  2833. else
  2834. {
  2835. cloneRow += dac3.Count + 1;
  2836. startDayPrice = cloneRow;
  2837. }
  2838. }
  2839. //合并单元格
  2840. for (int i = 8; i < contractTable.Rows.Count - 1; i++)
  2841. {
  2842. var currentRow = contractTable.Rows[i];
  2843. var nextRow = contractTable.Rows[i + 1];
  2844. // 获取当前行和下一行的第一个单元格
  2845. Cell currentCell = currentRow.Cells[0];
  2846. Cell nextCell = nextRow.Cells[0];
  2847. // 检查单元格内容是否一致(去除尾部的换行符)
  2848. string currentText = currentCell.GetText().Trim();
  2849. string nextText = nextCell.GetText().Trim();
  2850. if (currentText == nextText)
  2851. {
  2852. // 如果当前单元格已经被合并,找到合并的起始单元格
  2853. if (currentCell.CellFormat.VerticalMerge == CellMerge.Previous)
  2854. {
  2855. // 找到合并的起始单元格
  2856. int mergeStartIndex = FindMergeStartRowIndex(contractTable, i);
  2857. // 将下一行的单元格设置为合并的后续单元格
  2858. nextCell.CellFormat.VerticalMerge = CellMerge.Previous;
  2859. }
  2860. else
  2861. {
  2862. // 如果当前单元格是合并的起始单元格
  2863. currentCell.CellFormat.VerticalMerge = CellMerge.First;
  2864. // 将下一行的单元格设置为合并的后续单元格
  2865. nextCell.CellFormat.VerticalMerge = CellMerge.Previous;
  2866. }
  2867. }
  2868. else
  2869. {
  2870. // 如果内容不一致,重置当前单元格的合并属性
  2871. if (currentCell.CellFormat.VerticalMerge == CellMerge.Previous)
  2872. {
  2873. // 如果当前单元格是合并的后续单元格,找到合并的起始单元格并重置
  2874. int mergeStartIndex = FindMergeStartRowIndex(contractTable, i);
  2875. contractTable.Rows[mergeStartIndex].Cells[0].CellFormat.VerticalMerge = CellMerge.First;
  2876. }
  2877. else
  2878. {
  2879. currentCell.CellFormat.VerticalMerge = CellMerge.None;
  2880. }
  2881. }
  2882. }
  2883. bookMarkDic.Add("ZSPriceSum", ZSPriceSum.ToString("F2"));
  2884. bookMarkDic.Add("HSPriceSum", HSPriceSum.ToString("F2"));
  2885. bookMarkDic.Add("GZPriceSum", GZPriceSum.ToString("F2"));
  2886. }
  2887. foreach (var bookmarkName in bookMarkDic.Keys)
  2888. {
  2889. Bookmark bookmark = doc.Range.Bookmarks[bookmarkName];
  2890. if (bookmark != null)
  2891. {
  2892. if (bookmarkName == "ClientUnit")
  2893. {
  2894. // 移动到书签位置
  2895. builder.MoveTo(bookmark.BookmarkStart);
  2896. // 设置字体样式为下划线
  2897. builder.Font.Underline = Aspose.Words.Underline.Single;
  2898. // 插入书签值
  2899. builder.Write(bookMarkDic[bookmarkName]);
  2900. // 清除字体格式,避免影响后续文本
  2901. builder.Font.ClearFormatting();
  2902. }
  2903. else
  2904. {
  2905. builder.MoveToBookmark(bookmarkName);
  2906. builder.Write(bookMarkDic[bookmarkName]);
  2907. }
  2908. }
  2909. }
  2910. string savePaht = $"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Export/{di.TeamName}_{fileNameadd}版本合同文件.doc";
  2911. doc.Save(savePaht);
  2912. jw.Msg = "生成成功!";
  2913. jw.Code = 200;
  2914. jw.Data = new { Url = AppSettingsHelper.Get("WordBaseUrl") + savePaht.Replace(AppSettingsHelper.Get("WordBasePath"), AppSettingsHelper.Get("WordFtpPath")) };
  2915. return Ok(jw);
  2916. }
  2917. static int FindMergeStartRowIndex(Table table, int rowIndex)
  2918. {
  2919. int index = rowIndex;
  2920. while (index > 0 && table.Rows[index].Cells[0].CellFormat.VerticalMerge == CellMerge.Previous)
  2921. {
  2922. index--;
  2923. }
  2924. return index;
  2925. }
  2926. /// <summary>
  2927. /// 报批完成企微通知
  2928. /// </summary>
  2929. /// <param name="dto"></param>
  2930. /// <returns></returns>
  2931. [HttpPost]
  2932. public async Task<IActionResult> EnterpriseWeChatNotificationAsyncBaoPi(EnterpriseWeChatNotificationAsyncBaoPiDto dto)
  2933. {
  2934. int currUserId = dto.currUserId;
  2935. int diid = dto.diid;
  2936. var jw = JsonView(true);
  2937. var users = new List<string>();
  2938. var ssd = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == 1460);
  2939. //时间格式验证
  2940. if (!DateTime.TryParse(dto.stepOperationTime, out DateTime dt))
  2941. {
  2942. return Ok(JsonView(false, "请传入有效的时间格式!(例如:2026-01-06 15:45:02)"));
  2943. }
  2944. try
  2945. {
  2946. users = JsonConvert.DeserializeObject<List<string>>(ssd.Remark);
  2947. var groupModuleOperators = GeneralMethod.GetGroupModuleOperators(dto.diid);
  2948. //添加分配人员
  2949. // 79 车/导游地接
  2950. // 80 签证
  2951. // 81 邀请/公务活动
  2952. var setdataids = new List<int>() { 79, 81 };
  2953. foreach (var groupModule in groupModuleOperators)
  2954. {
  2955. if (setdataids.Contains(groupModule.CTableId))
  2956. {
  2957. users.AddRange(groupModule.OperationUsers.Select(x => x.UserId.ToString()));
  2958. }
  2959. }
  2960. var res = await AppNoticeLibrary.SendUserMsg_BaoPi_ToUser(users, diid);
  2961. //消息通知成功 更改团组step、记录日志
  2962. if (res)
  2963. {
  2964. var groupStep = 0; //0-新建 1-企微消息通知
  2965. //更改团组step
  2966. var updStatus = await _sqlSugar.Updateable<Grp_DelegationInfo>()
  2967. .SetColumns(x => new Grp_DelegationInfo()
  2968. {
  2969. Step = 2,
  2970. StepOperationTime = dt
  2971. })
  2972. .Where(x => x.Id == diid && x.IsDel == 0)
  2973. .ExecuteCommandAsync();
  2974. if (updStatus > 0) groupStep = 2;
  2975. string groupStepLabel = groupStep switch
  2976. {
  2977. 1 => "新建",
  2978. 2 => "企微消息通知(报批)",
  2979. _ => "未设置"
  2980. };
  2981. //记录日志
  2982. var teamName = _sqlSugar.Queryable<Grp_DelegationInfo>()
  2983. .Where(x => x.Id == diid && x.IsDel == 0)
  2984. .Select(x => x.TeamName)
  2985. .First() ?? "-";
  2986. var operationName = _sqlSugar.Queryable<Sys_Users>()
  2987. .Where(x => x.Id == currUserId && x.IsDel == 0)
  2988. .Select(x => x.CnName)
  2989. .First() ?? "-";
  2990. _groupTextLogger.LogInformation("团组:【{teamName}({groupId})】 操作人:【{operationName}】 操作时间:【{operationTime}】{logContent}", teamName, diid, operationName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), groupStepLabel);
  2991. //设置 签证流程初始值
  2992. await _visaProcessRep.UpdateBatchTop4Step(dto.diid, dto.currUserId);
  2993. }
  2994. }
  2995. catch (Exception ex)
  2996. {
  2997. return Ok(JsonView(false, ex.Message));
  2998. }
  2999. return Ok(jw);
  3000. }
  3001. #endregion
  3002. #region 团组&签证
  3003. #region 团组&签证 New
  3004. /// <summary>
  3005. /// 团组&签证 New
  3006. /// DeepSeek API:测试API连通性
  3007. /// </summary>
  3008. /// <param name="file">请求dto</param>
  3009. /// <returns></returns>
  3010. [HttpPost]
  3011. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3012. public async Task<IActionResult> TestDeepSeekApiConnectivityAsync()
  3013. {
  3014. return Ok(JsonView(await _deepSeekService.TestApiConnectivityAsync()));
  3015. }
  3016. /// <summary>
  3017. /// 团组&签证 New
  3018. /// DeepSeek API:检查可用端点
  3019. /// </summary>
  3020. /// <param name="file">请求dto</param>
  3021. /// <returns></returns>
  3022. [HttpPost]
  3023. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3024. public async Task<IActionResult> DiscoverAvailableEndpointsAsync()
  3025. {
  3026. return Ok(JsonView(await _deepSeekService.DiscoverAvailableEndpointsAsync()));
  3027. }
  3028. /// <summary>
  3029. /// 团组&签证 New
  3030. /// 上传签证文件(客户填写签证文件),新增或更新 签证信息
  3031. /// </summary>
  3032. /// <param name="visaFile">文件</param>
  3033. /// </param>
  3034. /// <returns></returns>
  3035. [HttpPost]
  3036. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3037. public async Task<IActionResult> VisaFileUploadAndUpdate(IFormFile visaFile)
  3038. {
  3039. //文件验证
  3040. if (visaFile.Length < 1) return Ok(JsonView(false, "请选择文件!"));
  3041. //var visaFiles = new VisaUploadFileTypeView();
  3042. //var filetypes = VisaUploadFileTypeView.GetVisaUploadFileTypeViewItemInit();
  3043. //if (!filetypes.Any(x => x.FileId == fileTypeId)) return Ok(JsonView(false, "请选择文件类型!"));
  3044. //服务器存储文件
  3045. var fileServerPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Uploads";
  3046. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(fileServerPath);
  3047. var filePath = Path.Combine(fileServerPath, visaFile.FileName);
  3048. using (var stream = new FileStream(filePath, FileMode.Create))
  3049. {
  3050. await visaFile.CopyToAsync(stream);
  3051. }
  3052. //日志记录-上传文件
  3053. _logger.LogInformation("【签证上传文件操作信息】签证文件存储成功!路径:{fileServerPath} 文件名称:{fileName}", fileServerPath, visaFile.FileName);
  3054. #region kimi API
  3055. //kimi AI 识别文档返回json结果
  3056. var KiMiApi = new KiMiApiClient();
  3057. var files = new List<IFormFile>() { visaFile };
  3058. var seedConter = await KiMiApi.UploadFilesAsync(files);
  3059. if (seedConter.Count == 0) return Ok(JsonView(false, "Kimi AI 文件上传结果为空!"));
  3060. var seedMessage = string.Format(@"你是领事馆电子材料审核员,只关注 Word 里的表格,正文、页眉页脚、水印、批注全部忽略。
  3061. 个人信息:
  3062. - 姓名:请提取文档中的“姓名”。
  3063. - 拼音名:请提取文档中的“拼音名”或“英文名”。
  3064. - 曾用名:请提取文档中的“曾用名”或“别名”。
  3065. - 性别:请提取文档中的“性别”。
  3066. - 出生日期:请提取文档中的“出生日期”。
  3067. - 出生地省:请提取文档中的“出生地省”或“出生地省份”。
  3068. - 出生地市:请提取文档中的“出生地市”或“出生地城市”。
  3069. - 国籍:请提取文档中的“国籍”或“现国籍”。
  3070. - 身份证号码:请提取文档中的“身份证号码”。
  3071. - 婚姻状况:请提取文档中的“婚姻状况”。
  3072. - 离婚原因:请提取文档中的“离婚原因”。
  3073. 家庭信息:
  3074. - 家庭成员:请提取文档中所有家庭成员信息,以列表形式返回,每个条目包含以下信息:
  3075. - 关系
  3076. - 姓名
  3077. - 出生日期
  3078. - 婚姻状况
  3079. - 现国籍
  3080. - 出生国
  3081. - 现居住国
  3082. - 现职务
  3083. - 家庭地址:请提取文档中的“家庭地址”或“现住址”。
  3084. - 家庭电话:请提取文档中的“家庭电话”。
  3085. - 移动电话:请提取文档中的“移动电话”或“手机”。
  3086. - 电子邮箱:请提取文档中的“电子邮箱”或“电子邮件”。
  3087. 工作信息:
  3088. - 工作经历:请提取文档中所有工作经历,以列表形式返回,每个条目包含以下信息:
  3089. - 单位名称
  3090. - 单位地址
  3091. - 职务
  3092. - 入职时间
  3093. - 离职时间
  3094. - 上级领导姓名(如适用)
  3095. - 工作单位名称:请提取文档中的“工作单位名称”或“现单位名称”。
  3096. - 工作单位地址:请提取文档中的“工作单位地址”或“单位地址”。
  3097. - 工作单位电话:请提取文档中的“工作单位电话”或“单位电话”。
  3098. - 职位:请提取文档中的“职位”或“目前职位”。
  3099. - 月薪:请提取文档中的“月薪”或“月收入”。
  3100. 教育经历:
  3101. - 教育经历:请提取文档中所有教育经历,以列表形式返回,每个条目包含以下信息:
  3102. - 学校名称
  3103. - 学校地址
  3104. - 学位
  3105. - 专业
  3106. - 入学时间
  3107. - 毕业时间
  3108. 签证与旅行记录:
  3109. - 拒签记录:请提取文档中所有拒签记录,以列表形式返回,每个条目包含以下信息:
  3110. - 国家
  3111. - 拒签日期:请提取文档中的“拒签日期”或“申请日期”。
  3112. - 地点:请提取文档中的“地点”或“拒签地点”。
  3113. - 签证申请类别
  3114. - 拒签原因
  3115. - 旅行历史:请提取文档中所有旅行历史,以列表形式返回,每个条目包含以下信息:
  3116. - 国家
  3117. - 到达日期
  3118. - 离开日期
  3119. - 签证类型(如适用)
  3120. - 服役历史:请提取文档中所有服役历史,以列表形式返回,每个条目包含以下信息:
  3121. - 军种
  3122. - 军衔
  3123. - 服役时间范围(开始日期至结束日期)
  3124. - 去过的国家:请提取文档中所有去过的国家及访问日期范围,以列表形式返回,每个条目包含以下信息:
  3125. - 国家名称
  3126. - 访问日期范围
  3127. - 申根签证记录:请提取文档中所有申根签证记录,以列表形式返回,每个条目包含以下信息:
  3128. - 签证类型
  3129. - 签发日期
  3130. - 有效期
  3131. 其他信息:
  3132. - 社交账号:请提取文档中提到的所有社交账号信息,以列表形式返回,每个条目包含以下信息:
  3133. - 平台名称
  3134. - 账号名称
  3135. - 邀请人信息:请提取文档中的“邀请人信息”,以列表形式返回,每个条目包含以下信息:
  3136. - 邀请人姓名
  3137. - 邀请人地址
  3138. - 邀请人联系方式
  3139. - 旅行目的:请提取文档中的“旅行目的”或“赴美目的”。
  3140. - 旅费支付方:请提取文档中的“旅费支付方”或“费用谁付”。
  3141. - 是否持有因公护照:请提取文档中的“是否持有因公护照”。
  3142. - 因公护照类型:请提取文档中的“因公护照类型”。
  3143. - 因公护照号码:请提取文档中的“因公护照号码”。
  3144. - 因公护照有效期:请提取文档中的“因公护照有效期”。
  3145. - 是否申请过该国签证:请提取文档中的“是否申请过该国签证”。
  3146. - 是否有亲属在目标国家:请提取文档中的“是否有亲属在目标国家”。
  3147. - 亲属、朋友及联系人信息:
  3148. - 请提取文档中所有在目标国家的亲属、朋友及联系人信息,以列表形式返回。
  3149. - 每个条目包含以下信息:
  3150. - 类型(亲属/朋友/联系人)
  3151. - 姓名
  3152. - 关系(如适用,如亲属关系)
  3153. - 出生日期
  3154. - 地址
  3155. - 联系方式
  3156. - 是否居住在现国籍以外的国家:请提取文档中的“是否居住在现国籍以外的国家”。
  3157. - 居留证编号:请提取文档中的“居留证编号”。
  3158. - 居留证有效期:请提取文档中的“居留证有效期”。
  3159. - 是否有指纹记录:请提取文档中的“是否有指纹记录”。
  3160. - 指纹记录日期:请提取文档中的“指纹记录日期”。
  3161. - 是否有美国驾照:请提取文档中的“是否有美国驾照”。
  3162. - 美国驾照号码:请提取文档中的“美国驾照号码”。
  3163. - 美国驾照签发地:请提取文档中的“美国驾照签发地”。
  3164. - 是否有美国社会安全号:请提取文档中的“是否有美国社会安全号”。
  3165. - 美国社会安全号:请提取文档中的“美国社会安全号”。
  3166. - 是否是其他国家的永久居民:请提取文档中的“是否是其他国家的永久居民”。
  3167. - 是否曾抵达过美国:请提取文档中的“是否曾抵达过美国”。
  3168. - 抵达美国时间:请提取文档中的“抵达美国时间”。
  3169. - 在美停留时间:请提取文档中的“在美停留时间”。
  3170. - 是否曾被美国拒签:请提取文档中的“是否曾被美国拒签”。
  3171. - 美国拒签日期:请提取文档中的“美国拒签日期”。
  3172. - 美国拒签原因:请提取文档中的“美国拒签原因”。
  3173. - 代办人姓名:请提取文档中的“代办人姓名”。
  3174. - 代办人手机号码:请提取文档中的“代办人手机号码”。
  3175. - 代办人现居住地址:请提取文档中的“代办人现居住地址”。
  3176. 把表格里的每个可填字段转换成“标题:值”的键值对,值用原文,不翻译。
  3177. 注:日期格式:YYYY-MM-DD、值为空时空字符串
  3178. 只返回json结果,不需要其他内容,json内容去掉换行。");
  3179. var messages = new List<SeedMessages>
  3180. {
  3181. new() { Role = KimiRole.system, Content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长识别文件为Json格式的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一切涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。" },
  3182. new() { Role = KimiRole.user, Content = seedMessage }
  3183. };
  3184. messages.InsertRange(1, seedConter);
  3185. string jsonString = "";
  3186. dynamic jsonData = null;
  3187. bool isJson = false;
  3188. while (!isJson)
  3189. {
  3190. var kimiApiResult = await KiMiApi.SeedMessage(messages);
  3191. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  3192. var newJsonString = kimiApiResult_JObject["content"].ToString();
  3193. string startStr = "```json", endStr = "```";
  3194. // 判断并清除开头部分
  3195. if (newJsonString.StartsWith(startStr))
  3196. {
  3197. newJsonString = newJsonString.Replace(startStr, "");
  3198. }
  3199. // 判断并清除结尾部分
  3200. if (newJsonString.EndsWith(endStr))
  3201. {
  3202. newJsonString = newJsonString.Replace(endStr, "");
  3203. }
  3204. jsonString += newJsonString;
  3205. //验证json格式是否正确
  3206. try
  3207. {
  3208. jsonData = JsonDocument.Parse(jsonString);
  3209. isJson = true; // 如果解析成功,则是json格式
  3210. }
  3211. catch (Exception)
  3212. {
  3213. messages.Add(new() { Role = KimiRole.user, Content = "请接着续写未完成的json格式内容。" });
  3214. }
  3215. }
  3216. if (jsonData == null)
  3217. {
  3218. return Ok(JsonView(false, "kimi识别json转换失败。"));
  3219. }
  3220. var info = new Crm_DeleClient();
  3221. var company = new Crm_CustomerCompany();
  3222. var certs = new List<Crm_CustomerCert>();
  3223. var familys = new List<Crm_VisaCustomerFamily>();
  3224. var schools = new List<Crm_VisaCustomerSchool>();
  3225. var works = new List<Crm_VisaCustomerCompany>();
  3226. var refusalRecords = new List<VisaRefusalRecord>(); //拒签记录
  3227. var travelHistories = new List<TravelHistory>(); //出行历史
  3228. var militaries = new List<MilitaryInfo>(); //军事信息
  3229. var countryVisiteds = new List<CountryVisited>(); //已出访的国家
  3230. var schengenVisaRecords = new List<SchengenVisaRecord>(); //申根签证记录
  3231. var socialAccounts = new List<SocialAccount>(); //社交账号
  3232. var personInfos = new List<PersonInfo>(); //亲属朋友信息
  3233. try
  3234. {
  3235. using (JsonDocument document = JsonDocument.Parse(jsonString))
  3236. {
  3237. JsonElement root = document.RootElement;
  3238. if (root.ValueKind == JsonValueKind.Object)
  3239. {
  3240. if (root.TryGetProperty("个人信息", out JsonElement userInfo))
  3241. {
  3242. if (TryGetNonEmptyStringProperty(userInfo, "姓名", out string name))
  3243. {
  3244. info.LastName = name.Substring(0, 1);
  3245. info.FirstName = name.Substring(1, name.Length - 1);
  3246. }
  3247. if (TryGetNonEmptyStringProperty(userInfo, "曾用名", out string oldName))
  3248. info.OldName = oldName;
  3249. if (TryGetNonEmptyStringProperty(userInfo, "拼音名", out string pinyin))
  3250. info.Pinyin = pinyin;
  3251. if (TryGetNonEmptyStringProperty(userInfo, "性别", out string gender))
  3252. info.Sex = gender switch
  3253. {
  3254. "男" => 0,
  3255. "女" => 1,
  3256. _ => -1
  3257. };
  3258. if (TryGetNonEmptyDateTimeProperty(userInfo, "出生日期", out DateTime? birthDay))
  3259. info.BirthDay = birthDay;
  3260. if (TryGetNonEmptyStringProperty(userInfo, "出生地省", out string birthProvince))
  3261. info.BirthProvince = birthProvince;
  3262. if (TryGetNonEmptyStringProperty(userInfo, "出生地市", out string birthCity))
  3263. info.BirthCity = birthCity;
  3264. if (TryGetNonEmptyStringProperty(userInfo, "国籍", out string nationality))
  3265. { }
  3266. if (TryGetNonEmptyStringProperty(userInfo, "身份证号码", out string idNo))
  3267. certs.Add(new() { PassportType = 74, CertNo = idNo, Country = nationality });
  3268. if (TryGetNonEmptyStringProperty(userInfo, "婚姻状况", out string marital_status))
  3269. info.Marriage = marital_status switch
  3270. {
  3271. "未婚" => 1,
  3272. "已婚" => 2,
  3273. "离异" => 3,
  3274. "丧偶" => 4,
  3275. _ => 0
  3276. };
  3277. if (TryGetNonEmptyStringProperty(userInfo, "离婚原因", out string DivorceRsn))
  3278. info.DivorceRsn = DivorceRsn;
  3279. }
  3280. if (root.TryGetProperty("家庭信息", out JsonElement familyInfo))
  3281. {
  3282. if (TryGetNonEmptyStringProperty(familyInfo, "家庭地址", out string address))
  3283. info.Address = address;
  3284. if (TryGetNonEmptyStringProperty(familyInfo, "家庭电话", out string tel))
  3285. info.Tel = tel;
  3286. if (TryGetNonEmptyStringProperty(familyInfo, "移动电话", out string phone))
  3287. info.Phone = phone;
  3288. if (TryGetNonEmptyStringProperty(familyInfo, "电子邮箱", out string email))
  3289. info.Email = email;
  3290. if (familyInfo.TryGetProperty("家庭成员", out JsonElement family_members))
  3291. {
  3292. foreach (JsonElement family_member in family_members.EnumerateArray())
  3293. {
  3294. var familyInfo1 = new Crm_VisaCustomerFamily();
  3295. if (TryGetNonEmptyStringProperty(family_member, "关系", out string gx))
  3296. familyInfo1.Appellation = gx;
  3297. if (TryGetNonEmptyStringProperty(family_member, "姓名", out string family_name))
  3298. familyInfo1.Name = family_name;
  3299. if (TryGetNonEmptyDateTimeProperty(family_member, "出生日期", out DateTime? family_date_of_birth))
  3300. familyInfo1.BirthDay = family_date_of_birth;
  3301. if (TryGetNonEmptyStringProperty(family_member, "婚姻状况", out string marital_status))
  3302. familyInfo1.MaritalStatus = marital_status;
  3303. if (TryGetNonEmptyStringProperty(family_member, "现国籍", out string currentNationality))
  3304. familyInfo1.CurrentNationality = currentNationality;
  3305. if (TryGetNonEmptyStringProperty(family_member, "出生国", out string countryOfBirth))
  3306. familyInfo1.CountryOfBirth = countryOfBirth;
  3307. if (TryGetNonEmptyStringProperty(family_member, "现居住国", out string currentResidenceCountry))
  3308. familyInfo1.CurrentResidenceCountry = currentResidenceCountry;
  3309. if (TryGetNonEmptyStringProperty(family_member, "现职务", out string currentOccupation))
  3310. familyInfo1.CurrentOccupation = currentOccupation;
  3311. familys.Add(familyInfo1);
  3312. }
  3313. }
  3314. }
  3315. if (root.TryGetProperty("工作信息", out JsonElement workInfo))
  3316. {
  3317. if (TryGetNonEmptyStringProperty(workInfo, "工作单位名称", out string workName))
  3318. company.CompanyFullName = workName;
  3319. if (TryGetNonEmptyStringProperty(workInfo, "工作单位电话", out string workPhone))
  3320. info.ClientPhone = workPhone;
  3321. if (TryGetNonEmptyStringProperty(workInfo, "工作单位地址", out string address))
  3322. company.Address = address;
  3323. if (TryGetNonEmptyStringProperty(workInfo, "职位", out string job))
  3324. info.Job = job;
  3325. if (TryGetNonEmptyStringProperty(workInfo, "月薪", out string wage))
  3326. info.Wage = wage;
  3327. if (workInfo.TryGetProperty("工作经历", out JsonElement workExp))
  3328. {
  3329. foreach (JsonElement work in workExp.EnumerateArray())
  3330. {
  3331. var workInfo1 = new Crm_VisaCustomerCompany();
  3332. if (TryGetNonEmptyStringProperty(work, "单位名称", out string unit_name))
  3333. workInfo1.Company = unit_name;
  3334. if (TryGetNonEmptyStringProperty(work, "单位地址", out string unit_address))
  3335. workInfo1.CompanyAddress = unit_address;
  3336. if (TryGetNonEmptyStringProperty(work, "职务", out string work_position))
  3337. workInfo1.Job = work_position;
  3338. if (TryGetNonEmptyStringProperty(work, "上级领导姓名", out string superior_leader_name))
  3339. workInfo1.LeaderName = superior_leader_name;
  3340. if (TryGetNonEmptyDateTimeProperty(work, "入职时间", out DateTime? start_date))
  3341. workInfo1.WorkStart = start_date;
  3342. if (TryGetNonEmptyDateTimeProperty(work, "离职时间", out DateTime? end_date))
  3343. workInfo1.WorkEnd = end_date;
  3344. workInfo1.WorkState = "";
  3345. works.Add(workInfo1);
  3346. }
  3347. }
  3348. }
  3349. if (root.TryGetProperty("教育经历", out JsonElement eduInfo))
  3350. {
  3351. if (eduInfo.TryGetProperty("教育经历", out JsonElement educations))
  3352. {
  3353. foreach (JsonElement edu in educations.EnumerateArray())
  3354. {
  3355. var schoolInfo = new Crm_VisaCustomerSchool();
  3356. if (TryGetNonEmptyStringProperty(edu, "学校名称", out string school_name))
  3357. schoolInfo.School = school_name;
  3358. if (TryGetNonEmptyStringProperty(edu, "学校地址", out string school_address))
  3359. schoolInfo.Address = school_address;
  3360. if (TryGetNonEmptyStringProperty(edu, "专业", out string degree))
  3361. schoolInfo.Subject = degree;
  3362. if (TryGetNonEmptyStringProperty(edu, "学位", out string major))
  3363. schoolInfo.Education = major;
  3364. if (TryGetNonEmptyDateTimeProperty(edu, "入学时间", out DateTime? enrollment_date))
  3365. schoolInfo.StudyStart = enrollment_date;
  3366. if (TryGetNonEmptyDateTimeProperty(edu, "毕业时间", out DateTime? graduation_date))
  3367. schoolInfo.StudyEnd = graduation_date;
  3368. schools.Add(schoolInfo);
  3369. }
  3370. }
  3371. }
  3372. if (root.TryGetProperty("签证与旅行记录", out JsonElement visaTravelRecs))
  3373. {
  3374. if (visaTravelRecs.TryGetProperty("拒签记录", out JsonElement rejectRecs))
  3375. {
  3376. foreach (JsonElement rejectRec in rejectRecs.EnumerateArray())
  3377. {
  3378. var visaRefusalRecordInfo = new VisaRefusalRecord();
  3379. if (TryGetNonEmptyStringProperty(rejectRec, "国家", out string country))
  3380. visaRefusalRecordInfo.Country = country;
  3381. if (TryGetNonEmptyDateTimeProperty(rejectRec, "拒签日期", out DateTime? refusal_date))
  3382. visaRefusalRecordInfo.Date = refusal_date;
  3383. if (TryGetNonEmptyStringProperty(rejectRec, "申请签证类别", out string visaType))
  3384. visaRefusalRecordInfo.VisaType = visaType;
  3385. if (TryGetNonEmptyStringProperty(rejectRec, "地点", out string address))
  3386. visaRefusalRecordInfo.Address = address;
  3387. if (TryGetNonEmptyStringProperty(rejectRec, "拒签原因", out string refusal_reason))
  3388. visaRefusalRecordInfo.Reason = refusal_reason;
  3389. refusalRecords.Add(visaRefusalRecordInfo);
  3390. }
  3391. info.RefusalRecords = refusalRecords;
  3392. }
  3393. if (visaTravelRecs.TryGetProperty("旅行历史", out JsonElement travelHist))
  3394. {
  3395. foreach (JsonElement travel in travelHist.EnumerateArray())
  3396. {
  3397. var travelHistoryInfo = new TravelHistory();
  3398. if (TryGetNonEmptyStringProperty(travel, "国家", out string country))
  3399. travelHistoryInfo.Country = country;
  3400. if (TryGetNonEmptyDateTimeProperty(travel, "到达日期", out DateTime? arrival_date))
  3401. travelHistoryInfo.ArrivalDate = arrival_date;
  3402. if (TryGetNonEmptyDateTimeProperty(travel, "离开日期", out DateTime? departure_date))
  3403. travelHistoryInfo.DepartureDate = departure_date;
  3404. if (TryGetNonEmptyStringProperty(travel, "visa_type", out string visa_type))
  3405. travelHistoryInfo.VisaType = visa_type;
  3406. travelHistories.Add(travelHistoryInfo);
  3407. }
  3408. info.TravelHistories = travelHistories;
  3409. }
  3410. if (visaTravelRecs.TryGetProperty("服役历史", out JsonElement militaryHist))
  3411. {
  3412. foreach (JsonElement military in militaryHist.EnumerateArray())
  3413. {
  3414. var militaryInfo = new MilitaryInfo();
  3415. if (TryGetNonEmptyStringProperty(military, "军种", out string military_branch))
  3416. militaryInfo.MilBranch = military_branch;
  3417. if (TryGetNonEmptyStringProperty(military, "军衔", out string military_rank))
  3418. militaryInfo.MilRank = military_rank;
  3419. if (TryGetNonEmptyStringProperty(military, "服役时间范围", out string service_duration))
  3420. militaryInfo.ServeDuration = service_duration;
  3421. militaries.Add(militaryInfo);
  3422. }
  3423. info.Militaries = militaries;
  3424. }
  3425. if (visaTravelRecs.TryGetProperty("去过的国家", out JsonElement visitedCountries))
  3426. {
  3427. foreach (JsonElement country in visitedCountries.EnumerateArray())
  3428. {
  3429. var countryVisitedInfo = new CountryVisited();
  3430. if (TryGetNonEmptyStringProperty(country, "国家名称", out string visit_country))
  3431. countryVisitedInfo.Country = visit_country;
  3432. if (TryGetNonEmptyStringProperty(country, "访问日期范围", out string visit_date_range))
  3433. countryVisitedInfo.VisitDate = visit_date_range;
  3434. countryVisiteds.Add(countryVisitedInfo);
  3435. }
  3436. info.CountryVisiteds = countryVisiteds;
  3437. }
  3438. if (visaTravelRecs.TryGetProperty("申根签证记录", out JsonElement schengenVisaRecs))
  3439. {
  3440. foreach (JsonElement schengenVisaRec in schengenVisaRecs.EnumerateArray())
  3441. {
  3442. var schengenVisaRecInfo = new SchengenVisaRecord();
  3443. if (TryGetNonEmptyStringProperty(schengenVisaRec, "签证类型", out string visaType))
  3444. schengenVisaRecInfo.VisaType = visaType;
  3445. if (TryGetNonEmptyDateTimeProperty(schengenVisaRec, "签发日期", out DateTime? issueDate))
  3446. schengenVisaRecInfo.IssueDate = issueDate;
  3447. if (TryGetNonEmptyDateTimeProperty(schengenVisaRec, "有效期", out DateTime? expiryDate))
  3448. schengenVisaRecInfo.ExpiryDate = expiryDate;
  3449. schengenVisaRecords.Add(schengenVisaRecInfo);
  3450. }
  3451. info.SchengenVisaRecords = schengenVisaRecords;
  3452. }
  3453. }
  3454. if (root.TryGetProperty("其他信息", out JsonElement otherInfo))
  3455. {
  3456. if (otherInfo.TryGetProperty("社交账号", out JsonElement socialAccountss))
  3457. {
  3458. foreach (JsonElement socialAccount in socialAccountss.EnumerateArray())
  3459. {
  3460. var socialAccount1 = new SocialAccount();
  3461. if (TryGetNonEmptyStringProperty(socialAccount, "平台名称", out string platform))
  3462. socialAccount1.Platform = platform;
  3463. if (TryGetNonEmptyStringProperty(socialAccount, "账号名称", out string account))
  3464. socialAccount1.Account = account;
  3465. socialAccounts.Add(socialAccount1);
  3466. }
  3467. info.SocialAccounts = socialAccounts;
  3468. }
  3469. if (TryGetNonEmptyStringProperty(otherInfo, "旅行目的", out string usaPurpose))
  3470. info.USAPurpose = usaPurpose;
  3471. if (TryGetNonEmptyStringProperty(otherInfo, "旅费支付方", out string payer))
  3472. info.CostBearers = payer;
  3473. if (TryGetNonEmptyStringProperty(otherInfo, "是否持有因公护照", out string isUSAVia))
  3474. info.IsUSAVia = isUSAVia switch
  3475. {
  3476. "是" => 1,
  3477. _ => 0
  3478. };
  3479. if (TryGetNonEmptyDateTimeProperty(otherInfo, "因公护照有效期", out DateTime? GetUSAVisaDate))
  3480. info.GetUSAVisaDate = GetUSAVisaDate;
  3481. if (TryGetNonEmptyStringProperty(otherInfo, "因公护照类型", out string USAVisaCate))
  3482. info.USAVisaCate = USAVisaCate;
  3483. if (TryGetNonEmptyStringProperty(otherInfo, "因公护照号码", out string USAVisaCode))
  3484. info.USAVisaCode = USAVisaCode;
  3485. if (otherInfo.TryGetProperty("亲属、朋友及联系人信息", out JsonElement personInfos1))
  3486. {
  3487. foreach (JsonElement personInfo in personInfos1.EnumerateArray())
  3488. {
  3489. var personInfo1 = new PersonInfo();
  3490. if (TryGetNonEmptyStringProperty(personInfo, "类型", out string type))
  3491. personInfo1.Type = type;
  3492. if (TryGetNonEmptyStringProperty(personInfo, "姓名", out string name))
  3493. personInfo1.Name = name;
  3494. if (TryGetNonEmptyDateTimeProperty(personInfo, "出生日期", out DateTime? birthDay))
  3495. personInfo1.BirthDay = birthDay;
  3496. if (TryGetNonEmptyStringProperty(personInfo, "地址", out string address))
  3497. personInfo1.Address = address;
  3498. if (TryGetNonEmptyStringProperty(personInfo, "联系方式", out string contactInfo))
  3499. personInfo1.ContactInfo = contactInfo;
  3500. personInfos.Add(personInfo1);
  3501. }
  3502. info.PersonInfos = personInfos;
  3503. }
  3504. if (TryGetNonEmptyStringProperty(otherInfo, "是否有指纹记录", out string IsFinger))
  3505. info.IsFinger = IsFinger switch
  3506. {
  3507. "是" => 1,
  3508. _ => 0
  3509. };
  3510. if (TryGetNonEmptyDateTimeProperty(otherInfo, "指纹记录日期", out DateTime? FingerDate))
  3511. info.FingerDate = FingerDate;
  3512. if (TryGetNonEmptyStringProperty(otherInfo, "美国驾照号码", out string USA_DLNo))
  3513. info.USA_DLNo = USA_DLNo;
  3514. if (TryGetNonEmptyStringProperty(otherInfo, "指纹记录日期", out string USA_DLPlace))
  3515. info.USA_DLPlace = USA_DLPlace;
  3516. if (TryGetNonEmptyStringProperty(otherInfo, "美国社会安全号", out string USA_SSNOrITIN))
  3517. info.USA_SSNOrITIN = USA_SSNOrITIN;
  3518. if (TryGetNonEmptyStringProperty(otherInfo, "是否是其他国家的永久居民", out string Resident))
  3519. info.Resident = Resident;
  3520. if (TryGetNonEmptyStringProperty(otherInfo, "抵达美国时间", out string USAHadArrival‌))
  3521. info.USAHadArrival‌ = USAHadArrival‌;
  3522. if (TryGetNonEmptyStringProperty(otherInfo, "在美停留时间", out string USAHadDays‌))
  3523. info.USAHadDays‌ = USAHadDays‌;
  3524. if (TryGetNonEmptyStringProperty(otherInfo, "代办人姓名", out string TableOpName))
  3525. info.TableOpName = TableOpName;
  3526. if (TryGetNonEmptyStringProperty(otherInfo, "代办人手机号码", out string TableOpTel))
  3527. info.TableOpTel = TableOpTel;
  3528. if (TryGetNonEmptyStringProperty(otherInfo, "代办人现居住地址", out string TableOpAddress))
  3529. { }
  3530. }
  3531. }
  3532. }
  3533. }
  3534. catch (Exception ex)
  3535. {
  3536. return Ok(JsonView(false, "信息提取失败:"+ex.Message));
  3537. }
  3538. #region 数据提交
  3539. _sqlSugar.BeginTran();
  3540. try
  3541. {
  3542. var infos = await _sqlSugar.Queryable<Crm_DeleClient>().Where(x => x.IsDel == 0).Select(x => new { x.Id, x.FirstName, x.LastName, x.Phone }).ToListAsync();
  3543. var infoDecrypts = new List<dynamic>();
  3544. foreach (var item in infos)
  3545. {
  3546. infoDecrypts.Add(new
  3547. {
  3548. Id = item.Id,
  3549. FirstName = AesEncryptionHelper.Decrypt(item.FirstName),
  3550. LastName = AesEncryptionHelper.Decrypt(item.LastName),
  3551. Phone = AesEncryptionHelper.Decrypt(item.Phone),
  3552. });
  3553. }
  3554. var infoVaild = infoDecrypts.Where(x =>
  3555. info.FirstName.Equals(x.FirstName) &&
  3556. info.LastName.Equals(x.LastName) &&
  3557. info.Phone.Equals(x.Phone))
  3558. .FirstOrDefault();
  3559. var compnayInfos = await _sqlSugar.Queryable<Crm_CustomerCompany>()
  3560. .Where(x => x.IsDel == 0)
  3561. .ToListAsync();
  3562. foreach (var company1 in compnayInfos)
  3563. {
  3564. company1.CompanyFullName = AesEncryptionHelper.Decrypt(company1.CompanyFullName);
  3565. }
  3566. var compnayInfo = compnayInfos.FirstOrDefault(x => x.CompanyFullName == company.CompanyFullName);
  3567. if (compnayInfo == null)
  3568. {
  3569. company.CompanyFullName = AesEncryptionHelper.Encrypt(company.CompanyFullName);
  3570. compnayInfo = await _sqlSugar.Insertable(company).ExecuteReturnEntityAsync();
  3571. if (compnayInfo == null)
  3572. {
  3573. _sqlSugar.RollbackTran();
  3574. return Ok(JsonView(false, "公司信息添加失败!"));
  3575. }
  3576. }
  3577. if (infoVaild == null) //添加
  3578. {
  3579. info.CrmCompanyId = compnayInfo.Id;
  3580. EncryptionProcessor.EncryptProperties(info);
  3581. var insertId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  3582. if (insertId < 1)
  3583. {
  3584. _sqlSugar.RollbackTran();
  3585. return Ok(JsonView(false, "信息添加失败!"));
  3586. }
  3587. if (familys.Any())
  3588. {
  3589. foreach (var family in familys)
  3590. {
  3591. family.DcId = insertId;
  3592. }
  3593. var familyInsert = await _sqlSugar.Insertable(familys).ExecuteCommandAsync();
  3594. if (familyInsert < 1)
  3595. {
  3596. _sqlSugar.RollbackTran();
  3597. return Ok(JsonView(false, "家庭信息添加失败!"));
  3598. }
  3599. }
  3600. if (schools.Any())
  3601. {
  3602. foreach (var school in schools)
  3603. {
  3604. school.DcId = insertId;
  3605. }
  3606. var schoolInsert = await _sqlSugar.Insertable(schools).ExecuteCommandAsync();
  3607. if (schoolInsert < 1)
  3608. {
  3609. _sqlSugar.RollbackTran();
  3610. return Ok(JsonView(false, "学校信息添加失败!"));
  3611. }
  3612. }
  3613. if (works.Any())
  3614. {
  3615. foreach (var work in works)
  3616. {
  3617. work.DcId = insertId;
  3618. }
  3619. var workInsert = await _sqlSugar.Insertable(works).ExecuteCommandAsync();
  3620. if (workInsert < 1)
  3621. {
  3622. _sqlSugar.RollbackTran();
  3623. return Ok(JsonView(false, "工作信息添加失败!"));
  3624. }
  3625. }
  3626. }
  3627. //修改
  3628. else
  3629. {
  3630. int id = infoVaild?.Id ?? 0;
  3631. var updInfo = await _sqlSugar.Queryable<Crm_DeleClient>().FirstAsync(x => x.Id == id);
  3632. EncryptionProcessor.DecryptProperties(updInfo);
  3633. foreach (var prop in info.GetType().GetProperties())
  3634. {
  3635. var currentVal = prop.GetValue(updInfo);
  3636. var newValue = prop.GetValue(info);
  3637. // 检查当前值是否为 null 或空字符串
  3638. if (currentVal == null || (currentVal is string && string.IsNullOrEmpty((string)currentVal)))
  3639. {
  3640. // 如果新值不为 null 或空字符串,则更新
  3641. if (newValue != null && !(newValue is string && string.IsNullOrEmpty((string)newValue)))
  3642. {
  3643. prop.SetValue(updInfo, newValue);
  3644. }
  3645. }
  3646. }
  3647. EncryptionProcessor.EncryptProperties(updInfo);
  3648. var upd = await _sqlSugar.Updateable(updInfo).ExecuteCommandAsync();
  3649. if (upd < 1)
  3650. {
  3651. _sqlSugar.RollbackTran();
  3652. return Ok(JsonView(false, "个人信息更新失败!"));
  3653. }
  3654. int parentId = updInfo.Id;
  3655. if (familys.Any())
  3656. {
  3657. await _sqlSugar.Updateable<Crm_VisaCustomerFamily>()
  3658. .SetColumns(x => x.IsDel == 0)
  3659. .SetColumns(x => x.DeleteUserId == 4)
  3660. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  3661. .Where(x => x.DcId == parentId)
  3662. .ExecuteCommandAsync();
  3663. foreach (var family in familys)
  3664. {
  3665. family.DcId = parentId;
  3666. }
  3667. var familyInsert = await _sqlSugar.Insertable(familys).ExecuteCommandAsync();
  3668. if (familyInsert < 1)
  3669. {
  3670. _sqlSugar.RollbackTran();
  3671. return Ok(JsonView(false, "家庭信息添加失败!"));
  3672. }
  3673. }
  3674. if (schools.Any())
  3675. {
  3676. await _sqlSugar.Updateable<Crm_VisaCustomerSchool>()
  3677. .SetColumns(x => x.IsDel == 0)
  3678. .SetColumns(x => x.DeleteUserId == 4)
  3679. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  3680. .Where(x => x.DcId == parentId)
  3681. .ExecuteCommandAsync();
  3682. foreach (var school in schools)
  3683. {
  3684. school.DcId = parentId;
  3685. }
  3686. var schoolInsert = await _sqlSugar.Insertable(schools).ExecuteCommandAsync();
  3687. if (schoolInsert < 1)
  3688. {
  3689. _sqlSugar.RollbackTran();
  3690. return Ok(JsonView(false, "学校信息添加失败!"));
  3691. }
  3692. }
  3693. if (works.Any())
  3694. {
  3695. await _sqlSugar.Updateable<Crm_VisaCustomerCompany>()
  3696. .SetColumns(x => x.IsDel == 0)
  3697. .SetColumns(x => x.DeleteUserId == 4)
  3698. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  3699. .Where(x => x.DcId == parentId)
  3700. .ExecuteCommandAsync();
  3701. foreach (var work in works)
  3702. {
  3703. work.DcId = parentId;
  3704. }
  3705. var workInsert = await _sqlSugar.Insertable(works).ExecuteCommandAsync();
  3706. if (workInsert < 1)
  3707. {
  3708. _sqlSugar.RollbackTran();
  3709. return Ok(JsonView(false, "工作信息添加失败!"));
  3710. }
  3711. }
  3712. }
  3713. }
  3714. catch (Exception ex)
  3715. {
  3716. _sqlSugar.RollbackTran();
  3717. return Ok(JsonView(false, ex.Message));
  3718. }
  3719. _sqlSugar.CommitTran();
  3720. #endregion
  3721. #endregion
  3722. return Ok(JsonView(true));
  3723. }
  3724. private static bool TryGetNonEmptyStringProperty(JsonElement root, string propertyName, out string value)
  3725. {
  3726. value = null;
  3727. if (root.TryGetProperty(propertyName, out JsonElement propertyElement))
  3728. {
  3729. string stringValue = propertyElement.GetString();
  3730. if (stringValue != null && stringValue != "null" && stringValue != "")
  3731. {
  3732. value = stringValue;
  3733. return true;
  3734. }
  3735. }
  3736. return false;
  3737. }
  3738. private static bool TryGetNonEmptyDateTimeProperty(JsonElement root, string propertyName, out DateTime? value)
  3739. {
  3740. value = null; // 初始化为null
  3741. if (root.TryGetProperty(propertyName, out JsonElement propertyElement))
  3742. {
  3743. string stringValue = propertyElement.GetString();
  3744. if (stringValue != null && stringValue != "null" && stringValue != "")
  3745. {
  3746. if (DateTime.TryParse(stringValue, out DateTime parsedValue))
  3747. {
  3748. value = parsedValue; // 将解析结果赋值给value
  3749. return true;
  3750. }
  3751. }
  3752. }
  3753. return false;
  3754. }
  3755. #region 扩展处理
  3756. // 从 Expression<Func<T,object>> 里取出属性名
  3757. static string GetPropName<T>(Expression<Func<T, object>> expr)
  3758. {
  3759. if (expr.Body is UnaryExpression ue) expr = Expression.Lambda<Func<T, object>>(ue.Operand, expr.Parameters);
  3760. return ((MemberExpression)expr.Body).Member.Name;
  3761. }
  3762. /// <summary>
  3763. /// 5.1.4.193 可用:存在更新(非NULL非空串),不存在插入,返回主键ID
  3764. /// </summary>
  3765. public int UpsertReturnId<T>(T entity, Expression<Func<T, object>> whereExpr) where T : class, new()
  3766. {
  3767. // 1. 空字符串→NULL,让后续忽略
  3768. foreach (var pi in typeof(T).GetProperties())
  3769. if (pi.PropertyType == typeof(string) &&
  3770. pi.GetValue(entity) is string s &&
  3771. string.IsNullOrWhiteSpace(s))
  3772. pi.SetValue(entity, null);
  3773. // 2. 从表达式里拿属性名
  3774. string propName = GetPropName(whereExpr);
  3775. var propValue = typeof(T).GetProperty(propName)?.GetValue(entity);
  3776. // 3. 判断存在
  3777. bool exists = _sqlSugar.Queryable<T>().Where(propName, propValue).Any();
  3778. // 4. 执行 Upsert
  3779. if (exists)
  3780. {
  3781. _sqlSugar.Updateable(entity)
  3782. .WhereColumns(propName) // 指定条件列
  3783. .IgnoreColumns(ignoreAllNullColumns: true) // 忽略 NULL
  3784. .ExecuteCommand();
  3785. }
  3786. else
  3787. {
  3788. _sqlSugar.Insertable(entity).ExecuteReturnIdentity();
  3789. }
  3790. // 5. 返回主键值(自增/雪花已回填)
  3791. var idProp = typeof(T).GetProperties()
  3792. .First(p => p.GetCustomAttributes<SugarColumn>()
  3793. .Any(a => a.IsPrimaryKey));
  3794. return (int)idProp.GetValue(entity)!;
  3795. }
  3796. /// <summary>
  3797. /// 地址喊邮编 相关处理
  3798. /// </summary>
  3799. public static (string address, string zipCode) SplitAddressZip(string? s)
  3800. {
  3801. if (string.IsNullOrWhiteSpace(s))
  3802. return ("", "");
  3803. ReadOnlySpan<char> src = s.AsSpan();
  3804. int i = src.IndexOf("邮编".AsSpan());
  3805. if (i < 0) // 没有“邮编”字样
  3806. return (src.Trim().ToString(), "");
  3807. ReadOnlySpan<char> addr = src[..i].TrimEnd();
  3808. ReadOnlySpan<char> zip = src[(i + 3)..].Trim(); // 跳过“邮编:”
  3809. // 可能只有“邮编:”而没有数字
  3810. return (addr.IsEmpty ? "" : addr.ToString(),
  3811. zip.IsEmpty ? "" : zip.ToString());
  3812. }
  3813. /// <summary>
  3814. /// 驾照相 关处理
  3815. /// </summary>
  3816. /// <param name="raw"></param>
  3817. /// <returns></returns>
  3818. public static (bool hasLicense, string number, string place) LicenseParser(string? raw)
  3819. {
  3820. if (string.IsNullOrWhiteSpace(raw))
  3821. return (false, "", "");
  3822. // 1. 是否持有
  3823. bool has = raw.StartsWith("是", System.StringComparison.OrdinalIgnoreCase) ||
  3824. raw.StartsWith("Y", System.StringComparison.OrdinalIgnoreCase);
  3825. // 2. 去掉前缀,按空格切
  3826. ReadOnlySpan<char> s = raw.AsSpan();
  3827. int colon = s.IndexOf(':');
  3828. ReadOnlySpan<char> after = colon < 0 ? s : s[(colon + 1)..];
  3829. after = after.Trim();
  3830. int space = after.IndexOf(' ');
  3831. ReadOnlySpan<char> num = space < 0 ? after : after[..space];
  3832. ReadOnlySpan<char> st = space < 0 ? ReadOnlySpan<char>.Empty : after[(space + 1)..];
  3833. return (has, num.ToString().Trim(), st.ToString().Trim());
  3834. }
  3835. /// <summary>
  3836. /// 美国社会安全号或者纳税ID号 相关处理
  3837. /// </summary>
  3838. /// <param name="raw"></param>
  3839. /// <returns></returns>
  3840. public static (bool hasSsnItin, string number) SsnItinParser(string? raw)
  3841. {
  3842. if (string.IsNullOrWhiteSpace(raw))
  3843. return (false, "");
  3844. ReadOnlySpan<char> s = raw.AsSpan();
  3845. // 1. 是否持有
  3846. bool has = s.StartsWith("是", System.StringComparison.Ordinal) ||
  3847. s.StartsWith("Y", System.StringComparison.OrdinalIgnoreCase);
  3848. // 2. 取号码(去掉前缀和空格)
  3849. int colon = s.IndexOf(':');
  3850. ReadOnlySpan<char> num = colon < 0
  3851. ? ReadOnlySpan<char>.Empty
  3852. : s[(colon + 1)..].Trim();
  3853. return (has, num.ToString());
  3854. }
  3855. /// <summary>
  3856. /// 取消开始的“是:”或者“是”或者“ :”
  3857. /// </summary>
  3858. /// <param name="raw"></param>
  3859. /// <returns></returns>
  3860. public static string CleanPrefix(string? raw)
  3861. {
  3862. if (string.IsNullOrWhiteSpace(raw)) return "";
  3863. // 跳过第一个“是”或“Y”
  3864. ReadOnlySpan<char> s = raw.AsSpan();
  3865. int start = 0;
  3866. if (s.StartsWith("是") || s.StartsWith("Y", StringComparison.OrdinalIgnoreCase))
  3867. start = 1;
  3868. // 跳过连续 : 或空格
  3869. while (start < s.Length && (s[start] == ':' || s[start] == ' '))
  3870. start++;
  3871. return s[start..].Trim().ToString();
  3872. }
  3873. /// <summary>
  3874. /// 婚姻起止时间处理
  3875. /// </summary>
  3876. /// <param name="raw"></param>
  3877. /// <returns></returns>
  3878. public static (DateTime? fromDate, DateTime? toDate) WeddingParser(string? raw)
  3879. {
  3880. if (string.IsNullOrWhiteSpace(raw)) return (null, null);
  3881. Regex _clean = new(@"[\s~至]+", RegexOptions.Compiled);
  3882. // 1. 把所有“空格~至”统一成 '-'
  3883. string normalized = _clean.Replace(raw, "-");
  3884. // 2. 切两段
  3885. string[] parts = normalized.Split('-', StringSplitOptions.RemoveEmptyEntries);
  3886. if (parts.Length != 2) return (null, null);
  3887. // 3. 解析
  3888. bool ff = DateTime.TryParse(parts[0].Trim(), out var from);
  3889. bool tf = DateTime.TryParse(parts[1].Trim(), out var to);
  3890. return (tf ? from : null, tf ? to : null);
  3891. }
  3892. /// <summary>
  3893. /// 出行日期和天数处理
  3894. /// </summary>
  3895. /// <param name="raw"></param>
  3896. /// <returns></returns>
  3897. public static (DateTime? travelDate, int? days) TravelParser(string? raw)
  3898. {
  3899. if (string.IsNullOrWhiteSpace(raw)) return (null, null);
  3900. // 切成两段:第一段日期,第二段天数
  3901. Regex sep = new(@"[^0-9./-]+", RegexOptions.Compiled);
  3902. string[] parts = sep.Split(raw.Trim());
  3903. if (parts.Length < 2) return (null, null);
  3904. bool okDate = DateTime.TryParse(parts[0], out DateTime date);
  3905. bool okDays = int.TryParse(parts[1], out int days) && days > 0;
  3906. return (okDate ? date : null, okDays ? days : null);
  3907. }
  3908. /// <summary>
  3909. /// 是否曾抵达过美国
  3910. /// </summary>
  3911. /// <param name="raw"></param>
  3912. /// <returns></returns>
  3913. public static (bool hasTravel, string date, string days) TravelHadFlagParser(string? raw)
  3914. {
  3915. if (string.IsNullOrWhiteSpace(raw)) return (false, string.Empty, string.Empty);
  3916. Regex sep = new(@"[^0-9./-]+", RegexOptions.Compiled);
  3917. // 1. 是否持有
  3918. bool has = raw.AsSpan().TrimStart().StartsWith("是") ||
  3919. raw.AsSpan().TrimStart().StartsWith("Y", StringComparison.OrdinalIgnoreCase);
  3920. // 2. 用非数字分隔符切成三段:第一段空,第二段日期,第三段天数
  3921. string[] parts = sep.Split(raw.Trim());
  3922. if (parts.Length < 3) return (has, string.Empty, string.Empty);
  3923. return (has, parts[1], parts[2]);
  3924. }
  3925. /// <summary>
  3926. /// 是否有被美国拒发签证的经历
  3927. /// </summary>
  3928. /// <param name="raw"></param>
  3929. /// <returns></returns>
  3930. public static (bool wasDenied, DateTime? date, string place, string visaType) VisaDenialParser(string? raw)
  3931. {
  3932. if (string.IsNullOrWhiteSpace(raw)) return (false, null, "", "");
  3933. bool denied = raw.AsSpan().TrimStart().StartsWith("有") ||
  3934. raw.AsSpan().TrimStart().StartsWith("Y", StringComparison.OrdinalIgnoreCase);
  3935. var parts = Regex.Split(raw.Trim(), @"[^0-9A-Za-z-]+");
  3936. if (parts.Length < 4) return (denied, null, "", "");
  3937. DateTime.TryParse(parts[1], out var dt); // ← 这里改为 DateTime
  3938. return (denied, dt, parts[2], parts[3]);
  3939. }
  3940. /// <summary>
  3941. /// 在美直系、旁系 处理
  3942. /// </summary>
  3943. /// <param name="raw"></param>
  3944. /// <returns></returns>
  3945. public static (bool flag, string name, string rel, string stat) FourFieldParser(string? raw)
  3946. {
  3947. if (string.IsNullOrWhiteSpace(raw)) return (false, "", "", "");
  3948. var parts = raw.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
  3949. if (parts.Length < 4) return (false, "", "", "");
  3950. bool flag = parts[0] is "有" or "是" or "Y" or "Yes";
  3951. string name = parts[1];
  3952. string rel = parts[2];
  3953. string stat = parts[3];
  3954. return (flag, name, rel, stat);
  3955. }
  3956. /// <summary>
  3957. /// 服役时间处理
  3958. /// </summary>
  3959. /// <param name="raw"></param>
  3960. /// <returns></returns>
  3961. public static (bool hasService, string branch, string rank, string specialty, (DateTime? start, DateTime? end) period) MilitaryParser(string? raw)
  3962. {
  3963. const string fmt = "yyyy年MM月dd日";
  3964. if (string.IsNullOrWhiteSpace(raw))
  3965. return (false, "", "", "", (null, null));
  3966. var parts = raw.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
  3967. if (parts.Length < 5) return (false, "", "", "", (null, null));
  3968. bool has = parts[0] is "是" or "Y" or "Yes";
  3969. string branch = parts[1];
  3970. string rank = parts[2];
  3971. string specialty = parts[3];
  3972. // 拼回时间字符串
  3973. string periodRaw = string.Join(" ", parts[4..]);
  3974. var span = periodRaw.AsSpan();
  3975. int zhi = span.IndexOf("至");
  3976. if (zhi < 0) return (has, branch, rank, specialty, (null, null));
  3977. var startStr = span.Slice(0, zhi).Trim();
  3978. var endStr = span.Slice(zhi + 1).Trim();
  3979. bool okStart = DateTime.TryParseExact(startStr.ToString(), fmt, null, DateTimeStyles.None, out var start);
  3980. bool okEnd = DateTime.TryParseExact(endStr.ToString(), fmt, null, DateTimeStyles.None, out var end);
  3981. return (has, branch, rank, specialty, (okStart ? start : null, okEnd ? end : null));
  3982. }
  3983. /// <summary>
  3984. /// 申请人父母信息
  3985. /// </summary>
  3986. /// <param name="raw"></param>
  3987. /// <returns></returns>
  3988. public static (string fatherName, DateTime? fatherDob, string motherName, DateTime? motherDob) ParentParser(string? raw)
  3989. {
  3990. const string fmt = "yyyy年MM月dd日";
  3991. if (string.IsNullOrWhiteSpace(raw)) return ("", null, "", null);
  3992. // 按空格切,去掉空元素
  3993. var parts = raw.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
  3994. if (parts.Length < 4) return ("", null, "", null);
  3995. // 父亲
  3996. string fName = parts[0];
  3997. DateTime.TryParseExact(parts[1], fmt, null, DateTimeStyles.None, out var fDob);
  3998. // 母亲
  3999. string mName = parts[2];
  4000. DateTime.TryParseExact(parts[3], fmt, null, DateTimeStyles.None, out var mDob);
  4001. return (fName, fDob, mName, mDob);
  4002. }
  4003. public class VisaDetailsView
  4004. {
  4005. /// <summary>
  4006. /// 客户资料表
  4007. /// </summary>
  4008. public Crm_DeleClient ClientInfo { get; set; }
  4009. /// <summary>
  4010. /// 客户家庭表
  4011. /// </summary>
  4012. public List<Crm_VisaCustomerFamily> ClientFamilys { get; set; }
  4013. /// <summary>
  4014. /// 客户公司表
  4015. /// </summary>
  4016. public Crm_CustomerCompany ClientCompany { get; set; }
  4017. /// <summary>
  4018. /// 客户证件表
  4019. /// </summary>
  4020. public List<Crm_CustomerCert> ClientCerts { get; set; }
  4021. /// <summary>
  4022. /// 客户学历表
  4023. /// </summary>
  4024. public List<Crm_VisaCustomerSchool> ClientSchools { get; set; }
  4025. }
  4026. private int GetSuccessCount(List<FileUploadResult> results)
  4027. {
  4028. var count = 0;
  4029. foreach (var result in results)
  4030. {
  4031. if (result.Success) count++;
  4032. }
  4033. return count;
  4034. }
  4035. #endregion
  4036. #region 文件下载
  4037. /// <summary>
  4038. /// 签证下载类型初始化
  4039. /// </summary>
  4040. private readonly static Dictionary<int, string> _visaTypeInit = new()
  4041. {
  4042. { 1, "美国" },
  4043. { 2, "日本" },
  4044. { 3, "韩国" },
  4045. { 4, "瑞典" },
  4046. { 5, "波兰" },
  4047. };
  4048. //申根国
  4049. private readonly static string[] _shenGenGuos = new string[] { "奥地利", "比利时", "丹麦", "芬兰", "法国", "德国", "冰岛", "意大利", "希腊", "卢森堡", "荷兰", "挪威", "葡萄牙", "西班牙",
  4050. "瑞典", "匈牙利", "捷克", "斯洛伐克", "斯洛文尼亚","波兰","爱沙尼亚","拉脱维亚","立陶宛","马耳他","瑞士","列支敦士登" };
  4051. //欧盟国家
  4052. private readonly static string[] _eucountries = new string[] { "奥地利", "比利时", "丹麦", "芬兰", "法国", "德国", "意大利", "希腊", "卢森堡", "荷兰", "葡萄牙", "西班牙","爱尔兰","罗马尼亚",
  4053. "保加利亚","匈牙利", "捷克", "斯洛伐克", "斯洛文尼亚","波兰","爱沙尼亚","拉脱维亚","立陶宛","马耳他","瑞士","列支敦士登" };
  4054. //欧洲国家
  4055. private readonly static string[] _aBC = new string[] { "英国", "爱尔兰" };
  4056. /// <summary>
  4057. /// 团组&签证 New
  4058. /// 签证文申请表下载
  4059. /// </summary>
  4060. /// <param name="groupId">
  4061. /// <param name="fileTypeId">
  4062. /// </param>
  4063. /// <returns></returns>
  4064. [HttpGet]
  4065. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  4066. public async Task<IActionResult> VisaFileDownload(int groupId, int fileTypeId)
  4067. {
  4068. if (!_visaTypeInit.TryGetValue(fileTypeId, out _))
  4069. {
  4070. return Ok(JsonView(false, "请选择正确的文件类型!"));
  4071. }
  4072. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0 && x.Id == groupId).First();
  4073. if (groupInfo == null)
  4074. {
  4075. return Ok(JsonView(false, "团组信息不存在!"));
  4076. }
  4077. //访问路径
  4078. var serverPath = $"http://132.232.92.186:24/Office/Word/VisaClientData/Downloads/{groupInfo.TeamName}/";
  4079. //模板存储位置
  4080. var tempPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Template/";
  4081. //服务器存储文件位置
  4082. var fileServerPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Downloads/{groupInfo.TeamName}/";
  4083. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(fileServerPath);
  4084. //文件生成路径
  4085. string url = string.Empty;
  4086. //基础数据
  4087. //团组客户名单
  4088. var groupClients = await _sqlSugar.Queryable<Grp_TourClientList>()
  4089. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  4090. .Select(x => x.ClientId)
  4091. .ToListAsync();
  4092. if (groupClients.Count < 1)
  4093. {
  4094. return Ok(JsonView(false, "该团组下暂无团组名单!"));
  4095. }
  4096. //团组客户详细信息
  4097. var groupCustInfos = _sqlSugar.Queryable<Crm_DeleClient>().Where(x => x.IsDel == 0 && groupClients.Contains(x.Id)).ToList();
  4098. //家庭成员资料
  4099. var familyInfos = _sqlSugar.Queryable<Crm_VisaCustomerFamily>().Where(x => x.IsDel == 0 && groupClients.Contains(x.DcId)).ToList();
  4100. //公司资料
  4101. var companyInfo‌‌s = _sqlSugar.Queryable<Crm_VisaCustomerCompany>().Where(x => x.IsDel == 0 && groupClients.Contains(x.DcId)).ToList();
  4102. //学校资料
  4103. var schoolInfos = _sqlSugar.Queryable<Crm_VisaCustomerSchool>().Where(x => x.IsDel == 0 && groupClients.Contains(x.DcId)).ToList();
  4104. /* 证件类型
  4105. *
  4106. * 773 身份证
  4107. * 774 护照
  4108. * 775 学生证
  4109. * 776 军人证
  4110. * 777 回乡证
  4111. * 778 台胞证
  4112. * 779 港澳通行证
  4113. * 780 国际海员证
  4114. * 781 外国人永久居留证
  4115. * 782 旅行证
  4116. * 783 台湾通行证
  4117. * 784 港澳台居住证
  4118. * 785 其他
  4119. */
  4120. //证件资料
  4121. var certInfos = _sqlSugar.Queryable<Crm_CustomerCert>().Where(x => x.IsDel == 0 && groupClients.Contains(x.DcId)).ToList();
  4122. //利用字典创建书签与书签的值的键值对,第一个string为键,第二个string为值
  4123. var applyDate = DateTime.Now.ToString("yyyy-MM-dd");
  4124. var filePaths = new List<string>();
  4125. var visaTypeName = string.Empty;
  4126. var currTempPath = string.Empty;
  4127. switch (fileTypeId)
  4128. {
  4129. case 1: // 美国
  4130. visaTypeName = $"美国签证申请表";
  4131. currTempPath = $"{tempPath}{visaTypeName}.doc";
  4132. var usaSavePath = $"{fileServerPath}{visaTypeName}/";
  4133. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(usaSavePath);
  4134. foreach (var custInfo in groupCustInfos)
  4135. {
  4136. //解密
  4137. EncryptionProcessor.DecryptProperties(custInfo);
  4138. Dictionary<string, string> dics = new();
  4139. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  4140. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  4141. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  4142. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4143. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4144. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4145. #region 美国签证模板书签值处理
  4146. dics.Add("LastNameEn", custInfo?.LastName ?? "");//名拼音
  4147. dics.Add("FirstNameEn", custInfo?.FirstName ?? "");//姓拼音
  4148. dics.Add("LastName", custInfo?.LastName ?? "");//名
  4149. dics.Add("FirstName", custInfo?.FirstName ?? "");//姓
  4150. dics.Add("OldNameEn", custInfo?.OldName ?? "");//曾用姓名拼音
  4151. dics.Add("OldName", custInfo?.FirstName ?? "");//曾用姓名
  4152. //未设置、未婚、已婚、离异、丧偶
  4153. var marriage = custInfo.Marriage switch
  4154. {
  4155. 0 => "未设置",
  4156. 1 => "未婚",
  4157. 2 => "已婚",
  4158. 3 => "离异",
  4159. 4 => "丧偶",
  4160. _ => "未知"
  4161. };
  4162. dics.Add("Marriage", marriage);//婚姻状况
  4163. dics.Add("Phone", custInfo?.Phone ?? "");//家庭电话
  4164. dics.Add("BirthCity", custInfo?.BirthCity ?? "");//出生城市
  4165. dics.Add("BirthProvince", custInfo?.BirthProvince ?? "");//出生省份
  4166. string m_idCard = idInfo?.CertNo ?? "";
  4167. string m_birthday = string.Empty;
  4168. if (!string.IsNullOrEmpty(m_idCard))
  4169. {
  4170. string m_year = m_idCard.Substring(6, 4);
  4171. string m_month = m_idCard.Substring(10, 2);
  4172. string m_day = m_idCard.Substring(12, 2);
  4173. m_birthday = m_year + "." + m_month + "." + m_day;
  4174. }
  4175. dics.Add("BirthDay", m_birthday);//出生日期
  4176. dics.Add("Tel", custInfo?.Tel ?? "");//移动电话
  4177. dics.Add("Email", custInfo?.Email ?? "");//电子信箱
  4178. dics.Add("IdCard", m_idCard);//身份证号码
  4179. dics.Add("Address", custInfo?.Address ?? "");//现居家庭地址
  4180. dics.Add("PostCodes", custInfo?.PostCodes ?? "");//邮编
  4181. dics.Add("Client", clinetInfo?.Company ?? "");//单位名称
  4182. dics.Add("ClientAddress", clinetInfo?.CompanyAddress ?? "");//单位地址
  4183. dics.Add("ClientPostCodes", custInfo?.PostCodes ?? "");//单位邮编
  4184. dics.Add("Job", custInfo?.Job ?? "");//职务
  4185. dics.Add("WorkDate", custInfo?.WorkDate ?? "");//入职时间
  4186. dics.Add("Wage", custInfo?.Wage ?? "");//月薪
  4187. dics.Add("ClientPhone", custInfo?.ClientPhone ?? "");//单位电话
  4188. dics.Add("ClientFax", custInfo?.ClientFax ?? "");//单位传真
  4189. dics.Add("ClientEmail", custInfo?.ClientEmail ?? "");//单位邮箱
  4190. dics.Add("ClientLeader", custInfo?.ClientLeader ?? "");//单位主管姓名
  4191. dics.Add("ClientLeaderJob", custInfo?.ClientLeaderJob ?? "");//单位主管职务
  4192. dics.Add("WorkState", custInfo?.WorkState ?? "");//工作内容简单介绍
  4193. dics.Add("IsGetSchengen", custInfo?.IsGetSchengen == 0 ? "否" : "是");//是否有获批的申根签证
  4194. dics.Add("StartTime", custInfo?.StartTime.ToString("yyyy-MM-dd") ?? "");//申根签证有效期开始
  4195. dics.Add("EndTime", custInfo?.EndTime.ToString("yyyy-MM-dd") ?? "");//申根签证有效期结束
  4196. dics.Add("IsFinger", custInfo.IsFinger == 0 ? "否" : "是");//申根签证是否有指纹记录
  4197. dics.Add("FingerDate", custInfo?.FingerDate?.ToString("yyyy-MM-dd") ?? "");//申根签指纹采集时间
  4198. dics.Add("TableOpName", custInfo?.TableOpName ?? "");//填表经办人
  4199. dics.Add("TableOpTel", custInfo?.TableOpTel ?? "");//填表经办人联系电话
  4200. dics.Add("TableDate", custInfo?.TableDate.ToString("yyyy-MM-dd") ?? "");//填表日期
  4201. dics.Add("Party", custInfo?.Party ?? "");//所属党派或宗教
  4202. dics.Add("Nationality", custInfo?.Nationality ?? "");//国籍
  4203. var sex = custInfo.Sex switch
  4204. {
  4205. 0 => "男",
  4206. 1 => "女",
  4207. _ => "未知"
  4208. };
  4209. dics.Add("Sex", sex);//性别
  4210. dics.Add("WeddingDate", custInfo?.WeddingDate?.ToString("yyyy-MM-dd") ?? "");//结婚日期
  4211. dics.Add("DivorceDate", custInfo?.DivorceDate?.ToString("yyyy-MM-dd") ?? "");//离婚日期
  4212. dics.Add("MateName", custInfo?.MateName ?? "");//配偶姓名
  4213. dics.Add("MateBirthDay", custInfo?.MateBirthDay.ToString("yyyy-MM-dd") ?? "");//配偶出生日期
  4214. dics.Add("MateBirthCity", custInfo?.MateBirthCity ?? "");//配偶出生城市
  4215. dics.Add("MateBirthCountry", custInfo?.MateBirthCountry ?? "");//配偶出生省份
  4216. dics.Add("MateAddress", custInfo?.MateAddress ?? "");//配偶住址
  4217. dics.Add("MateClient", custInfo?.MateClient ?? "");//配偶工作单位名称
  4218. dics.Add("MateClientAddress", custInfo?.MateClientAddress ?? "");//配偶工作单位地址
  4219. dics.Add("MateJob", custInfo?.MateJob ?? "");//配偶职务
  4220. dics.Add("VisitCountry", custInfo?.VisitCountry ?? "");//因公出访的国家
  4221. dics.Add("Paper", custInfo?.Paper ?? "");//发表的期刊、论文
  4222. dics.Add("Papent", custInfo?.Papent ?? "");//专利
  4223. dics.Add("PhD", custInfo?.PhD ?? "");//博士论文
  4224. dics.Add("IsVisitUC", custInfo?.IsVisitUC == 0 ? "否" : "是" ?? "");//是否因公去过美国/加拿大
  4225. dics.Add("USADate", custInfo?.USADate?.ToString("yyyy-MM-dd") ?? "");//美国抵达日期
  4226. dics.Add("USADays", custInfo?.USADays.ToString() ?? "");//美国停留天数
  4227. dics.Add("CanDate", custInfo?.CanDate.ToString("yyyy-MM-dd") ?? "");//加拿大抵达日期
  4228. dics.Add("CanDays", custInfo?.CanDays.ToString() ?? "");//加拿大停留天数
  4229. dics.Add("IsUSAVia", custInfo?.IsUSAVia == 0 ? "否" : "是" ?? "");//是否获得过因公美国签证
  4230. dics.Add("GetUSAVisaDate", custInfo?.GetUSAVisaDate?.ToString("yyyy-MM-dd") ?? "");//因公美国签证时间
  4231. dics.Add("GetUPPlace", custInfo?.GetUPPlace ?? "");//因公美国签证地点
  4232. dics.Add("USAVisaCate", custInfo?.USAVisaCate ?? "");//因公美国签证种类
  4233. dics.Add("USAVisaCode", custInfo?.USAVisaCode ?? "");//因公美国签证编码
  4234. dics.Add("USAFinger", custInfo?.USAFinger == 0 ? "否" : "是" ?? "");//是否在使馆留过十指的指纹
  4235. dics.Add("IsRejected", custInfo?.IsRejected == 0 ? "否" : "是" ?? "");//是否被拒
  4236. dics.Add("RejectedDate", custInfo?.RejectedDate?.ToString("yyyy-MM-dd") ?? "");//被拒时间
  4237. dics.Add("RejectedPlace", custInfo?.RejectedPlace ?? "");//被拒地点
  4238. dics.Add("RejectedVisa", custInfo?.RejectedVisa ?? "");//被拒签证种类
  4239. dics.Add("IsRevoke", custInfo?.IsRevoke == 0 ? "否" : "是" ?? "");//美国签证是否被吊销
  4240. dics.Add("IsLose", custInfo?.IsLose == 0 ? "否" : "是" ?? "");//护照是否丢失
  4241. dics.Add("LoseDate", custInfo?.LoseDate.ToString("yyyy-MM-dd") ?? "");//丢失的护照时间
  4242. dics.Add("LoseCode", custInfo?.LoseCode ?? "");//丢失的护照号码
  4243. dics.Add("IsUSAVisa", custInfo?.IsUSAVisa == 0 ? "否" : "是" ?? "");//丢失的护照是否有美国签证
  4244. dics.Add("MateUSA", custInfo?.MateUSA == 0 ? "否" : "是" ?? "");//夫/妻是否已在美国
  4245. dics.Add("MateIden", custInfo?.MateIden ?? "");//夫/妻身份
  4246. dics.Add("WHUSA", custInfo?.WHUSA == 0 ? "否" : "是" ?? "");//未婚夫/妻是否已在美国
  4247. dics.Add("WHIden", custInfo?.WHIden ?? "");//未婚夫/妻身份
  4248. dics.Add("ParentUSA", custInfo?.ParentUSA == 0 ? "否" : "是" ?? "");//父/母是否已在美国
  4249. dics.Add("ParentIden", custInfo?.ParentIden ?? "");//父/母身份
  4250. dics.Add("ChildUSA", custInfo?.ChildUSA == 0 ? "否" : "是" ?? "");//儿子/女儿是否已在美国
  4251. dics.Add("ChildIden", custInfo?.ChildIden ?? "");//儿子/女儿身份
  4252. dics.Add("BroUSA", custInfo?.BroUSA == 0 ? "否" : "是" ?? "");//兄弟/姐妹是否已在美国
  4253. dics.Add("BroIden", custInfo?.BroIden ?? "");//兄弟/姐妹身份
  4254. dics.Add("Social", custInfo?.Social ?? "");//所属/捐助/工作过的职业协会、社会团体和慈善机构
  4255. dics.Add("IsArmy", custInfo?.IsArmy == 0 ? "否" : "是" ?? "");//是否参军
  4256. dics.Add("ArmyState", custInfo?.ArmyState ?? "");//参军详情
  4257. dics.Add("ApplyDate", applyDate);//申请日期
  4258. //公司信息书签
  4259. if (currCompanyInfos.Count > 0)
  4260. {
  4261. for (int i = 0; i < currCompanyInfos.Count; i++)
  4262. {
  4263. var compnayInfo = currCompanyInfos[i];
  4264. if (!string.IsNullOrEmpty(compnayInfo.Company))
  4265. {
  4266. dics.Add("Company", compnayInfo?.Company ?? "");//公司名称
  4267. dics.Add("CompanyAddress", compnayInfo?.CompanyAddress ?? "");//公司地址
  4268. dics.Add("CompanyPhone", compnayInfo?.Phone ?? "");//公司电话
  4269. dics.Add("CompanyJob", compnayInfo?.Job ?? "");//职务
  4270. dics.Add("CompanyLeaderName", compnayInfo?.LeaderName ?? "");//主管名字
  4271. dics.Add("CompanyWorkStart", compnayInfo?.WorkStart?.ToString("yyyy-MM-dd") ?? "");//雇佣起始年月日
  4272. dics.Add("CompanyWorkEnd", compnayInfo?.WorkEnd?.ToString("yyyy-MM-dd") ?? "");//雇佣结束年月日
  4273. dics.Add("CompanyWorkState", compnayInfo?.WorkState ?? "");//工作职责及内容简述
  4274. }
  4275. else break;
  4276. }
  4277. }
  4278. //学校信息书签
  4279. if (currSchoolInfos.Count > 0)
  4280. {
  4281. for (int i = 0; i < currSchoolInfos.Count; i++)
  4282. {
  4283. var schoolInfo = currSchoolInfos[i];
  4284. if (!string.IsNullOrEmpty(schoolInfo.School))
  4285. {
  4286. dics.Add("School", schoolInfo?.School ?? "");//学校名称和学历
  4287. dics.Add("SchoolAddress", schoolInfo?.Address ?? "");//学校地址
  4288. dics.Add("SchoolTeacher", schoolInfo?.Teacher ?? "");//指导老师
  4289. dics.Add("SchoolSubject", schoolInfo?.Subject ?? "");//所学课程或专业名称
  4290. dics.Add("SchoolStudyStart", schoolInfo?.StudyStart?.ToString("yyyy-MM-dd") ?? "");//就读起始日
  4291. dics.Add("SchoolStudyEnd", schoolInfo?.StudyEnd?.ToString("yyyy-MM-dd") ?? "");//就读结束日
  4292. }
  4293. else break;
  4294. }
  4295. }
  4296. //家人信息书签
  4297. if (currFamilyInfos.Count > 0)
  4298. {
  4299. for (int i = 0; i < currFamilyInfos.Count; i++)
  4300. {
  4301. var familyInfo = currFamilyInfos[i];
  4302. if (!string.IsNullOrEmpty(familyInfo.Appellation))
  4303. {
  4304. dics.Add("FamilyAppellation", familyInfo?.Appellation ?? "");//家庭成员称谓
  4305. dics.Add("FamilyName", familyInfo?.Name ?? "");//家庭成员姓名
  4306. dics.Add("FamilyBirthDay", familyInfo?.BirthDay?.ToString("yyyy-MM-dd") ?? "");//家庭成员出生日期
  4307. dics.Add("FamilyBirthPlace", familyInfo?.BirthPlace ?? "");// 家庭成员出生地
  4308. dics.Add("FamilyPolitics", familyInfo?.Politics ?? "");//家庭成员政治面貌
  4309. dics.Add("FamilyClient", familyInfo?.Client ?? "");//家庭成员工作单位
  4310. dics.Add("FamilyAddress", familyInfo?.Address ?? "");// 家庭地址
  4311. dics.Add("IsEu", familyInfo?.IsEu == 0 ? "No" : "Yes" ?? "");// 欧盟公民
  4312. dics.Add("FamilyNameSnd", familyInfo?.NameSnd ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员姓名
  4313. dics.Add("FamilyBirthDaySnd", familyInfo?.BirthDaySnd.ToString("yyyy-MM-dd") ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员生日
  4314. dics.Add("FamilyNationality", familyInfo?.Nationality ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员国籍
  4315. dics.Add("FamilyIDCard", familyInfo?.IDCard ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员旅行证件编号或身份证号码
  4316. dics.Add("FamilyReletionship", familyInfo?.Reletionship ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员与申请人的关系
  4317. dics.Add("IsUSA", familyInfo?.IsUSA == 1 ? "是" : "否" ?? "");// 家庭成员是否在美国
  4318. }
  4319. else break;
  4320. }
  4321. }
  4322. #endregion
  4323. #region 生成文件
  4324. try
  4325. {
  4326. _logger.LogInformation("模板位置:{currTempPath}", currTempPath);
  4327. Document doc = new(currTempPath);
  4328. Aspose.Words.DocumentBuilder builder = new(doc);
  4329. string strTemp = "";
  4330. //循环键值对
  4331. foreach (var key in dics.Keys)
  4332. {
  4333. //将光标移入书签的位置
  4334. builder.MoveToBookmark(key);
  4335. //判断书签值是否为空
  4336. if (!string.IsNullOrEmpty(dics[key]))
  4337. {
  4338. strTemp = dics[key];
  4339. }
  4340. else strTemp = "";
  4341. //填充书签
  4342. builder.Write(strTemp.Replace("\\N", "\n"));
  4343. }
  4344. var custName = custInfo.LastName + custInfo.FirstName;
  4345. string fileName = $"{custName}_{visaTypeName}.doc";
  4346. var currFilePath = $"{usaSavePath}{fileName}";
  4347. doc.Save(currFilePath);
  4348. filePaths.Add(currFilePath);
  4349. }
  4350. catch (Exception ex)
  4351. {
  4352. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  4353. }
  4354. #endregion
  4355. }
  4356. break;
  4357. case 2: // 日本
  4358. visaTypeName = $"日本签证申请表";
  4359. currTempPath = $"{tempPath}/{visaTypeName}.doc";
  4360. var jpnSavePath = $"{fileServerPath}/{visaTypeName}/";
  4361. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(jpnSavePath);
  4362. foreach (var custInfo in groupCustInfos)
  4363. {
  4364. EncryptionProcessor.DecryptProperties(custInfo);
  4365. Dictionary<string, string> dics = new();
  4366. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  4367. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  4368. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  4369. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4370. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4371. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4372. #region 日本签证模板书签
  4373. dics.Add("LastNameEn", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? "");//姓
  4374. dics.Add("FirstNameEn", CommonFun.ConvertToPinyin(custInfo?.FirstName?.Trim() ?? "")?.ToLower() ?? "");//名
  4375. if (!string.IsNullOrEmpty(custInfo.OldName)) dics.Add("OldNameEn", custInfo?.OldName ?? "");//名
  4376. else dics.Add("OldNameEn", "无");//名
  4377. dics.Add("LastName", custInfo?.LastName ?? "");//姓
  4378. dics.Add("FirstName", custInfo?.FirstName ?? "");//名
  4379. if (!string.IsNullOrEmpty(custInfo.OldName)) dics.Add("OldName", custInfo?.OldName ?? "");//名
  4380. else dics.Add("OldName", "无");//名
  4381. string idCard = idInfo?.CertNo?.Trim() ?? "";
  4382. string birthday = string.Empty;
  4383. if (!string.IsNullOrEmpty(idCard))
  4384. {
  4385. string year = idCard.Substring(6, 4);
  4386. string month = idCard.Substring(10, 2);
  4387. string day = idCard.Substring(12, 2);
  4388. birthday = year + "/" + month + "/" + day;
  4389. }
  4390. dics.Add("BirthDay", birthday); //出生日期
  4391. dics.Add("BirthProvince", custInfo?.BirthProvince ?? "");//出生省
  4392. dics.Add("BirthCity", custInfo?.BirthCity ?? "");//出生城市
  4393. dics.Add("Nationality", "中国");//国籍
  4394. dics.Add("Address", custInfo?.Address ?? "");//现居家庭地址
  4395. dics.Add("IdCard", idCard);//身份证号码
  4396. dics.Add("OldNationality", "无");//默认没有
  4397. dics.Add("Tel11", custInfo?.Phone ?? "");//座机
  4398. //护照
  4399. if (passportInfo != null)
  4400. {
  4401. dics.Add("PassprotNo", passportInfo?.CertNo ?? "");// 护照編號
  4402. dics.Add("PassprotIssuePlase", passportInfo?.Area ?? "");// 护照签发地
  4403. dics.Add("PassprotStartTime", passportInfo?.IssueDt?.ToString("yyyy/MM/dd") ?? "");//护照开始时间
  4404. dics.Add("PassprotEndTime", passportInfo?.ExpiryDt?.ToString("yyyy/MM/dd") ?? "");// 护照过期时间
  4405. }
  4406. //得到签证国家下的城市
  4407. string city = "";
  4408. string county = "";
  4409. //ResidenceTime1 机票三字码信息
  4410. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  4411. if (atbc != null)
  4412. {
  4413. string startTime = ""; //开始停留时间
  4414. string endTime = ""; //离开时间
  4415. string three = ""; //航司
  4416. string threeCode = ""; //入境口岸
  4417. for (int i = 0; i < atbc.Rows.Count; i++)
  4418. {
  4419. if (i == 0) //得到抵达日期
  4420. {
  4421. three = atbc.Rows[i]["Fliagtcode"].ToString();
  4422. startTime = atbc.Rows[i]["Day"].ToString();
  4423. threeCode = atbc.Rows[i]["Three"].ToString();
  4424. continue;
  4425. }
  4426. if (i == 1)
  4427. endTime = atbc.Rows[i]["Day"].ToString();
  4428. }
  4429. dics.Add("ResidenceTime1", startTime);
  4430. dics.Add("ResidenceTime2", endTime);
  4431. dics.Add("EntryTime", startTime);
  4432. if (!string.IsNullOrEmpty(three))
  4433. {
  4434. //查询航司名称
  4435. var threeCodeTwo = three.Substring(0, 2);
  4436. var ac = _sqlSugar.Queryable<Res_AirCompany>().Where(x => x.ShortCode == threeCodeTwo).First();
  4437. if (ac != null)
  4438. {
  4439. dics.Add("AirName", $"{ac?.EnName ?? ""} {three}"); //入境口岸
  4440. }
  4441. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  4442. if (tc != null)
  4443. {
  4444. county = tc.Country;
  4445. city = tc.City;
  4446. dics.Add("PortOfEntry", tc?.City ?? ""); //入境口岸
  4447. }
  4448. }
  4449. }
  4450. //团组信息
  4451. if (groupInfo != null)
  4452. {
  4453. dics.Add("Destination", groupInfo?.VisitPurpose ?? ""); //出访目的 Destination2
  4454. //DickeyValue.Add("Destination2", dgi.VisitCountry); //出访目的地
  4455. }
  4456. if (!string.IsNullOrEmpty(city))
  4457. {
  4458. //得到当前国家下的城市酒店信息
  4459. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  4460. .Where(x => x.DiId == groupId)
  4461. .Where(x => x.City.contains(city))
  4462. .First();
  4463. //酒店住址
  4464. if (hotelInfo != null)
  4465. {
  4466. dics.Add("HotalName", hotelInfo?.HotelName ?? ""); //酒店名称
  4467. dics.Add("HotalAddress", hotelInfo?.HotelAddress ?? ""); //酒店地址
  4468. dics.Add("HotalTel", hotelInfo?.HotelTel ?? ""); //酒店电话
  4469. }
  4470. }
  4471. dics.Add("Tel", custInfo?.Tel ?? "");//移动电话
  4472. dics.Add("Client", companyInfos?.FirstOrDefault()?.Company ?? "");//单位名称
  4473. dics.Add("ClientPhone", companyInfos?.FirstOrDefault()?.Phone ?? "");//单位电话
  4474. dics.Add("ClientAddress", companyInfos?.FirstOrDefault()?.CompanyAddress ?? "");//单位地址
  4475. dics.Add("Job", custInfo?.Job ?? "");//职务
  4476. dics.Add("MateJob", custInfo?.MateJob ?? "");//配偶职务
  4477. //InvitingPartyInfo RB_IP = new InvitingPartyInfoService().GetAddSelect(int.Parse(ddlTeamNames.SelectedValue), RB_County, RB_City);
  4478. if (!string.IsNullOrEmpty(county) && !string.IsNullOrEmpty(city))
  4479. {
  4480. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  4481. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  4482. .Where(x => x.Country.Contains(county))
  4483. .Where(x => x.Area.Contains(city))
  4484. .First();
  4485. //邀请 接待单位
  4486. if (oa != null)
  4487. {
  4488. dics.Add("OA12", oa?.Contact ?? ""); //接待单位联系人
  4489. dics.Add("OAJob", oa?.Job ?? ""); //接待联系人职务
  4490. dics.Add("OATel", oa?.Tel ?? ""); //接待单位电话
  4491. dics.Add("OAAddress", oa?.Address ?? "");//接待单位地址
  4492. dics.Add("ApplicantGuanxi", "邀请方"); //和申请人关系
  4493. dics.Add("OACountry", "日本"); //邀请方国家
  4494. dics.Add("OADan", "同上"); // 同上
  4495. dics.Add("OAJob1", "同上"); //接待联系人职务
  4496. dics.Add("OATel1", "同上"); // 同上
  4497. dics.Add("OAAddress1", "同上"); // 同上
  4498. dics.Add("ApplicantGuanxi1", "同上"); // 同上
  4499. dics.Add("OACountry1", "同上"); //邀请方国家
  4500. }
  4501. }
  4502. dics.Add("NowTime", DateTime.Now.ToString("yyyy/MM/dd")); //获取当前系统时间
  4503. #endregion
  4504. #region 生成文件
  4505. try
  4506. {
  4507. Document doc = new(currTempPath);
  4508. Aspose.Words.DocumentBuilder builder = new(doc);
  4509. string strTemp = "";
  4510. //循环键值对
  4511. foreach (var key in dics.Keys)
  4512. {
  4513. //将光标移入书签的位置
  4514. builder.MoveToBookmark(key);
  4515. //判断书签值是否为空
  4516. if (!string.IsNullOrEmpty(dics[key]))
  4517. {
  4518. strTemp = dics[key];
  4519. }
  4520. else strTemp = "";
  4521. //填充书签
  4522. builder.Write(strTemp.Replace("\\N", "\n"));
  4523. }
  4524. var custName = custInfo?.LastName + custInfo?.FirstName;
  4525. string fileName = $"{custName}_{visaTypeName}.doc";
  4526. var currFilePath = $"{jpnSavePath}{fileName}";
  4527. doc.Save(currFilePath);
  4528. filePaths.Add(currFilePath);
  4529. }
  4530. catch (Exception ex)
  4531. {
  4532. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  4533. }
  4534. #endregion
  4535. }
  4536. break;
  4537. case 3: // 韩国
  4538. visaTypeName = $"韩国签证申请表";
  4539. currTempPath = $"{tempPath}{visaTypeName}.doc";
  4540. var korSavePath = $"{fileServerPath}{visaTypeName}/";
  4541. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(korSavePath);
  4542. foreach (var custInfo in groupCustInfos)
  4543. {
  4544. EncryptionProcessor.DecryptProperties(custInfo);
  4545. Dictionary<string, string> dics = new();
  4546. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  4547. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  4548. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  4549. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4550. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4551. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4552. #region 韩国签证模板书签
  4553. dics.Add("LastNameEn", custInfo?.LastName ?? "");//姓
  4554. dics.Add("FirstNameEn", custInfo?.FirstName ?? "");//名
  4555. var userName = $"{custInfo?.LastName ?? ""}{custInfo?.FirstName ?? ""}";
  4556. dics.Add("User", userName);//姓名
  4557. //判断性别
  4558. if (custInfo.Sex == 0)
  4559. dics.Add("SexMale", "√");
  4560. else if (custInfo.Sex == 1)
  4561. dics.Add("SexFemale", "√");
  4562. string idCard = idInfo.CertNo;
  4563. string birthday = string.Empty;
  4564. if (!string.IsNullOrEmpty(idCard))
  4565. {
  4566. string year = idCard.Substring(6, 4);
  4567. string month = idCard.Substring(10, 2);
  4568. string day = idCard.Substring(12, 2);
  4569. birthday = year + "/" + month + "/" + day;
  4570. }
  4571. dics.Add("BirthDay", birthday);//出生日期
  4572. dics.Add("Nationality", "中国");//国籍
  4573. dics.Add("NationalityCountry", "中国");//出生国
  4574. dics.Add("IdCard", idCard);//身份证号码
  4575. dics.Add("OtherPassProt", "√"); //默认没有其他护照
  4576. //判断是否否曾用名 是否申请过该国家
  4577. string isGetSchengenStr = custInfo.IsGetSchengen == 0 ? "否" : "是";
  4578. if (!string.IsNullOrEmpty(custInfo.OldName) && isGetSchengenStr.equals("是"))
  4579. {
  4580. dics.Add("IsGetSchengenYes", "√");
  4581. string oldName = custInfo?.OldName ?? "";
  4582. if (!string.IsNullOrEmpty(oldName))
  4583. {
  4584. dics.Add("OldLastName", oldName.Substring(0, 1));
  4585. dics.Add("OldFirstName", oldName.Remove(0, 1));
  4586. }
  4587. }
  4588. else
  4589. dics.Add("IsGetSchengenNo", "√");
  4590. dics.Add("IsDoubleNationality", "√"); //默认没有双重国籍
  4591. //护照
  4592. if (passportInfo != null)
  4593. {
  4594. dics.Add("PassprotNo", passportInfo?.CertNo ?? ""); // 护照編號
  4595. dics.Add("PassprotCountry", passportInfo?.Country ?? ""); // 护照签发国
  4596. dics.Add("PassprotIssuePlase", passportInfo?.Area ?? ""); // 护照签发地
  4597. dics.Add("PassprotStartTime", passportInfo?.IssueDt?.ToString("yyyy-MM-dd") ?? ""); //护照开始时间
  4598. dics.Add("PassprotEndTime", passportInfo?.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); // 护照过期时间
  4599. }
  4600. dics.Add("Address", custInfo?.Address ?? "");//现居家庭地址
  4601. dics.Add("Tel1", custInfo?.Tel ?? "");//移动电话 /家庭电话 /电子信箱
  4602. //dics.Add("Tel2", );//电子信箱
  4603. dics.Add("Email", custInfo?.Email ?? "");//电子信箱
  4604. //判断婚姻状况
  4605. var marriage = custInfo.Marriage switch
  4606. {
  4607. 1 => "未婚",
  4608. 2 => "已婚",
  4609. 3 => "离异",
  4610. 4 => "丧偶",
  4611. _ => "未设置"
  4612. };
  4613. if (marriage.Contains("未婚") || marriage == null || marriage == "")
  4614. dics.Add("Single", "√");
  4615. else if (marriage == "已婚")
  4616. dics.Add("Married", "√");
  4617. else if (marriage == "离婚" || marriage == "离异")
  4618. dics.Add("Divorced", "√");
  4619. //判断是否已婚 已婚则输出配偶信息
  4620. if (marriage == "已婚")
  4621. {
  4622. string mateName = custInfo?.MateName ?? "";
  4623. if (!string.IsNullOrEmpty(mateName))
  4624. {
  4625. try
  4626. {
  4627. string mateFirstName = mateName.Remove(0, 1);
  4628. dics.Add("MateLastName", mateName.Substring(0, 1)); //配偶姓
  4629. dics.Add("MateFirstName", mateFirstName); //配偶名
  4630. //dics.Add("MateLastName", MateName.Substring(0, 1)); //配偶姓
  4631. //dics.Add("MateFirstName", MateName.Substring(1, MateName.Length - 1)); //配偶名
  4632. }
  4633. catch { }
  4634. dics.Add("MateBirthDay", custInfo?.MateBirthDay.ToString("yyyy-MM-dd")); //配偶生日
  4635. //dics.Add("MateNationality", custInfo.ma.ToString()); //配偶国籍
  4636. //dics.Add("MateTel", custInfo..ToString()); //配偶联系电话
  4637. dics.Add("MateAddress", custInfo.MateAddress.ToString()); //配偶居住地址
  4638. //家人信息书签
  4639. if (currFamilyInfos.Count > 0)
  4640. {
  4641. //定义接受子女人数
  4642. int children = currFamilyInfos.Where(x => x.Appellation.contains("儿子") || x.Appellation.contains("女儿")).ToList().Count;
  4643. //判断子女人数
  4644. if (children == 0) //无子女
  4645. dics.Add("NoChildren", "√"); //未查询出 则无子女
  4646. else
  4647. {
  4648. dics.Add("HaveChildren", "√");
  4649. dics.Add("ChildrenNum", children.ToString());//有子女则输出人数
  4650. }
  4651. }
  4652. else
  4653. dics.Add("NoChildren", "√"); //未查询出 则无子女
  4654. }
  4655. }
  4656. else
  4657. dics.Add("NoChildren", "√"); //未婚则无子女
  4658. //学历
  4659. if (custInfo.HighestEducation.Contains("硕士") || custInfo.HighestEducation.Contains("博士"))
  4660. dics.Add("Master", "√");
  4661. else if (custInfo.HighestEducation.Contains("学士"))
  4662. dics.Add("Bachelor", "√");
  4663. else if (custInfo.HighestEducation.Contains("高中"))
  4664. dics.Add("HighSchool", "√");
  4665. else
  4666. {
  4667. dics.Add("Other", "√");
  4668. dics.Add("OtherDetails", custInfo.HighestEducation.Trim());
  4669. }
  4670. //dics.Add("Job", custInfo.Job.ToString()); ;//职业
  4671. dics.Add("Company", companyInfos.FirstOrDefault()?.Company ?? "");//单位名称
  4672. dics.Add("jobs", companyInfos.FirstOrDefault()?.Job ?? ""); //职务
  4673. dics.Add("CompanyAddress", companyInfos.FirstOrDefault()?.CompanyAddress ?? "");//单位地址
  4674. dics.Add("CompanyTel", companyInfos.FirstOrDefault()?.Phone ?? "");//单位电话
  4675. string day1 = ""; //得到抵达日期
  4676. string day2 = ""; //得到离开日期
  4677. string country = groupInfo.VisitCountry; //国家名
  4678. string HG_City = ""; //城市
  4679. string HG_Country = "";//国家
  4680. string[] HG_countryName = new string[] { };
  4681. if (!string.IsNullOrEmpty(country))
  4682. {
  4683. //处理国家名
  4684. if (country.Contains(" "))
  4685. HG_countryName = country.Split(' ');
  4686. else if (country.Contains(","))
  4687. HG_countryName = country.Split(',');
  4688. else if (country.Contains(","))
  4689. HG_countryName = country.Split(',');
  4690. else if (country.Contains("、"))
  4691. HG_countryName = country.Split('、');
  4692. }
  4693. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  4694. int k = 0;
  4695. for (int i = 0; i < HG_countryName.Length; i++)
  4696. {
  4697. for (int j = 0; j < atbc.Rows.Count; j++)
  4698. {
  4699. string HL_Three = atbc.Rows[j]["Three"].ToString();
  4700. if (!string.IsNullOrEmpty(HL_Three))
  4701. {
  4702. var hl_three = HL_Three.Substring(3);
  4703. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == hl_three).First();
  4704. if (tc != null)
  4705. {
  4706. HG_Country = HG_countryName[i];
  4707. HG_City = tc.City; //得到当前国家 城市名
  4708. day1 = atbc.Rows[j]["Day"].ToString(); //得到抵达日期
  4709. k = j + 1;
  4710. }
  4711. }
  4712. if (k == j)
  4713. day2 = atbc.Rows[j]["Day"].ToString(); //离开航班起飞时间
  4714. }
  4715. }
  4716. if (atbc != null)
  4717. {
  4718. if (day2 != null && day1 != null)
  4719. {
  4720. try
  4721. {
  4722. int Han_day = (Convert.ToDateTime(day2) - Convert.ToDateTime(day1)).Days; //得到天数
  4723. dics.Add("Days", Han_day.ToString() + "天");//滞留天数
  4724. dics.Add("EntryTime", day1.ToString());//入境日期 TemporaryAddress
  4725. }
  4726. catch (Exception) { }
  4727. }
  4728. }
  4729. //得到当前国家下的城市酒店信息
  4730. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  4731. .Where(x => x.DiId == groupId)
  4732. .Where(x => x.City.contains(HG_City))
  4733. .First();
  4734. //访问信息
  4735. if (hotelInfo != null)
  4736. {
  4737. dics.Add("TemporaryAddress", hotelInfo?.HotelAddress ?? "");//停留酒店地址 TATel
  4738. dics.Add("TATel", hotelInfo?.HotelTel ?? ""); //停留酒店联系电话
  4739. }
  4740. if (!string.IsNullOrEmpty(HG_Country) && !string.IsNullOrEmpty(HG_City))
  4741. {
  4742. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  4743. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  4744. .Where(x => x.Country.Contains(HG_Country))
  4745. .Where(x => x.Area.Contains(HG_City))
  4746. .First();
  4747. //在韩邀请方信息
  4748. if (oa != null)
  4749. {
  4750. dics.Add("IsYes", "√");
  4751. dics.Add("TT", oa?.Contact ?? ""); //联系人
  4752. dics.Add("TTAddress", oa?.Address ?? ""); //联系地址
  4753. dics.Add("TTtel", oa?.Tel ?? ""); //联系电话
  4754. dics.Add("TTGuanxi", "BY INVITED"); //和在邀联系人关系
  4755. }
  4756. else
  4757. dics.Add("IsNo", "√");
  4758. }
  4759. //费用信息
  4760. if (groupInfo != null)
  4761. {
  4762. //dics.Add("Payer", "Unit"); //在外期间费用承担
  4763. dics.Add("Team1", groupInfo.ClientUnit); //客户单位名称
  4764. dics.Add("Team12", "雇佣"); //与申请人关系 BY INVITED
  4765. dics.Add("PriceType", "Payment By Unit"); //资金类型
  4766. dics.Add("TeamNameTel", custInfo.ClientPhone); //联系方式
  4767. }
  4768. //是否有协助填表人
  4769. if (!string.IsNullOrEmpty(custInfo.TableOpName))
  4770. dics.Add("WirteTableNo", "√");
  4771. else
  4772. {
  4773. dics.Add("WirteTableYes", "√");
  4774. dics.Add("OpTableName", custInfo.TableOpName.ToString()); //协助填表人姓名
  4775. //dics.Add("OpTableDateTime",custInfo.OpDate.ToString()); //填表时间
  4776. dics.Add("OpTableTel", custInfo.TableOpTel.ToString()); //协助人联系电话
  4777. dics.Add("OpTableGuanXi", "雇佣"); //和协助人关系
  4778. }
  4779. dics.Add("NowDateTime", DateTime.Now.ToString("yyyy/MM/dd")); //获取当前系统时间
  4780. dics.Add("ApplicantName", custInfo.LastName + " " + custInfo.FirstName); //申请人
  4781. #endregion
  4782. #region 生成文件
  4783. try
  4784. {
  4785. Document doc = new(currTempPath);
  4786. Aspose.Words.DocumentBuilder builder = new(doc);
  4787. string strTemp = "";
  4788. //循环键值对
  4789. foreach (var key in dics.Keys)
  4790. {
  4791. //将光标移入书签的位置
  4792. builder.MoveToBookmark(key);
  4793. //判断书签值是否为空
  4794. if (!string.IsNullOrEmpty(dics[key]))
  4795. {
  4796. strTemp = dics[key];
  4797. }
  4798. else strTemp = "";
  4799. //填充书签
  4800. builder.Write(strTemp.Replace("\\N", "\n"));
  4801. }
  4802. var custName = custInfo.LastName + custInfo.FirstName;
  4803. string fileName = $"{custName}_{visaTypeName}.doc";
  4804. var currFilePath = $"{korSavePath}{fileName}";
  4805. doc.Save(currFilePath);
  4806. filePaths.Add(currFilePath);
  4807. }
  4808. catch (Exception ex)
  4809. {
  4810. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  4811. }
  4812. #endregion
  4813. }
  4814. break;
  4815. case 4: // 瑞典
  4816. visaTypeName = $"瑞典签证申请表";
  4817. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  4818. var swedenSavePath = $"{fileServerPath}{visaTypeName}/";
  4819. if (!Directory.Exists(swedenSavePath)) Directory.CreateDirectory(swedenSavePath);
  4820. if (!System.IO.File.Exists(currTempPath))
  4821. {
  4822. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  4823. }
  4824. foreach (var custInfo in groupCustInfos)
  4825. {
  4826. EncryptionProcessor.DecryptProperties(custInfo);
  4827. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  4828. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  4829. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  4830. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4831. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4832. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4833. #region 生成文件
  4834. PdfReader reader = null;
  4835. FileStream templateStream = null;
  4836. FileStream outputStream = null;
  4837. PdfStamper stamper = null;
  4838. try
  4839. {
  4840. string outputPath = $"{swedenSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  4841. //读取模板文件
  4842. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  4843. reader = new PdfReader(templateStream);
  4844. //创建输出文件
  4845. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  4846. stamper = new PdfStamper(reader, outputStream);
  4847. AcroFields formFields = stamper.AcroFields;
  4848. #region 设置文本值
  4849. SetFieldValue(formFields, "LastName", custInfo.LastName); //姓
  4850. SetFieldValue(formFields, "BirthLastName", custInfo.LastName); // 出生时姓氏
  4851. SetFieldValue(formFields, "FirstName", custInfo.FirstName); // 名
  4852. // 出生日期(日-月-年)
  4853. string idCard = idInfo.CertNo;
  4854. string birthday = string.Empty;
  4855. if (!string.IsNullOrEmpty(idCard))
  4856. {
  4857. string year = idCard.Substring(6, 4);
  4858. string month = idCard.Substring(10, 2);
  4859. string day = idCard.Substring(12, 2);
  4860. birthday = day + "-" + month + "-" + year;
  4861. }
  4862. SetFieldValue(formFields, "Birthday", birthday);
  4863. string currentNationality = custInfo.BirthProvince + custInfo.BirthCity;
  4864. SetFieldValue(formFields, "CurrentNationality", currentNationality); // 出生地
  4865. SetFieldValue(formFields, "CountryBirth", "中国"); // 出生国
  4866. SetFieldValue(formFields, "CurrentNationalityCountry", "中国"); // 现国籍
  4867. SetFieldValue(formFields, "NationalityBirth", ""); // 出生时国籍,如与现国籍不同
  4868. SetFieldValue(formFields, "OtherNationalities", ""); // 其他国籍
  4869. #region 性别处理
  4870. //清除性别
  4871. SetFieldValue(formFields, "Male", "Off"); // 性别 - 男
  4872. SetFieldValue(formFields, "Female", "Off"); // 性别 - 女
  4873. //设置性别
  4874. if (custInfo.Sex == 0) //男
  4875. {
  4876. SetFieldValue(formFields, "Male", "Yes"); // 性别 - 男
  4877. }
  4878. else if (custInfo.Sex == 1) //女
  4879. {
  4880. SetFieldValue(formFields, "Female", "Yes"); // 性别 - 女
  4881. }
  4882. #endregion
  4883. #region 婚姻状况处理
  4884. //清除婚姻状况
  4885. SetFieldValue(formFields, "Single", "Off"); // 婚姻状况 - 未婚
  4886. SetFieldValue(formFields, "Married", "Off"); // 婚姻状况 - 已婚
  4887. SetFieldValue(formFields, "RegisteredPartnership", "Off"); // 婚姻状况 - 注册伴侣关系
  4888. SetFieldValue(formFields, "Separated", "Off"); // 婚姻状况 - 分居
  4889. SetFieldValue(formFields, "Divorced", "Off"); // 婚姻状况 - 离婚
  4890. SetFieldValue(formFields, "Widow(er)", "Off"); // 婚姻状况 - 丧偶
  4891. SetFieldValue(formFields, "OtherCivilStatus", "Off"); // 婚姻状况 - 其它
  4892. SetFieldValue(formFields, "CivilStatusOther", ""); // 婚姻状况 - 其它(请注明)
  4893. //设置婚姻状况
  4894. switch (custInfo.Marriage)
  4895. {
  4896. case 1: // 未婚
  4897. SetFieldValue(formFields, "Single", "Yes");
  4898. break;
  4899. case 2: // 已婚
  4900. SetFieldValue(formFields, "Married", "Yes");
  4901. break;
  4902. case 3: // 离异
  4903. SetFieldValue(formFields, "Divorced", "Yes");
  4904. break;
  4905. case 4: // 离异
  4906. SetFieldValue(formFields, "Widow(er)", "Yes");
  4907. break;
  4908. }
  4909. #endregion
  4910. //亲权人(如是未成年申请人 )/合法监护人(姓名、住址,如与申请人不同) 电话号码、电子邮件及国籍
  4911. SetFieldValue(formFields, "ParentalAuthority", "");
  4912. SetFieldValue(formFields, "NationalIdentityNumber", idCard); //公民身份证号码
  4913. #region 护照(旅行证件类型)处理
  4914. //清除值
  4915. SetFieldValue(formFields, "OrdinaryPassport", "Off"); //旅行证件类型 - 普通护照
  4916. SetFieldValue(formFields, "DiplomaticPassport", "Off"); //旅行证件类型 - 外交护照
  4917. SetFieldValue(formFields, "ServicePassport", "Off"); //旅行证件类型 - 公务护照
  4918. SetFieldValue(formFields, "OfficialPassport", "Off"); //旅行证件类型 - 因公护照
  4919. SetFieldValue(formFields, "SpecialPassport", "Off"); //旅行证件类型 - 特殊护照
  4920. SetFieldValue(formFields, "OtherTravel", "Off"); //旅行证件类型 - 其它旅行证件
  4921. SetFieldValue(formFields, "OtherTravelDesc", ""); //旅行证件类型 - 其它旅行证件(请注明)
  4922. //设置值
  4923. SetFieldValue(formFields, "OrdinaryPassport", "Yes"); //旅行证件类型 - 普通护照
  4924. if (passportInfo != null)
  4925. {
  4926. SetFieldValue(formFields, "TravelNumber", passportInfo.CertNo); //旅行证件编号
  4927. SetFieldValue(formFields, "IssueDate", passportInfo.IssueDt?.ToString("yyyy-MM-dd") ?? ""); //签发日期
  4928. SetFieldValue(formFields, "ValidUntil", passportInfo.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); //有效期至
  4929. SetFieldValue(formFields, "IssuedCountry", passportInfo.Country); //签发(国)
  4930. }
  4931. #endregion
  4932. //如有家庭成员为欧盟、欧洲经济区、瑞士或受益于退欧协议的英国公民的,请填写该家庭成员的个人信息
  4933. SetFieldValue(formFields, "LastName_om", ""); //姓
  4934. SetFieldValue(formFields, "FirstName_om", ""); //名
  4935. SetFieldValue(formFields, "BirthDate_om", ""); //出生日期(日-月-年)
  4936. SetFieldValue(formFields, "Nationality_om", ""); //国籍
  4937. SetFieldValue(formFields, "TravelNuber_om", ""); //旅行证件或身分证编号
  4938. //申请人与欧盟、欧洲经济区、瑞士或受益于退欧协议的英国公民的关系
  4939. SetFieldValue(formFields, "Spouse_om", ""); //配偶
  4940. SetFieldValue(formFields, "RegisteredPartnership_om", ""); //注册伴侣
  4941. SetFieldValue(formFields, "Child_om", ""); //子女
  4942. SetFieldValue(formFields, "DependentAscendant_om", ""); //受养人
  4943. SetFieldValue(formFields, "Grandchild_om", ""); //孙子女
  4944. SetFieldValue(formFields, "FamilyOther_om", ""); //其他
  4945. SetFieldValue(formFields, "FamilyOtherDesc_om", ""); //其他(说明)
  4946. //申请人住址及电子邮件
  4947. string applicantHomeAddress = $"{custInfo.Address} {custInfo.Email}";
  4948. SetFieldValue(formFields, "ApplicantHomeAddress", applicantHomeAddress); //申请人住址及电子邮件
  4949. SetFieldValue(formFields, "TelephoneNo", custInfo.Tel); //电话号码
  4950. //是否居住在现时国籍以外的国家
  4951. SetFieldValue(formFields, "AnotherCountryNo", "Yes"); //否
  4952. SetFieldValue(formFields, "AnotherCountryYes", ""); //是。
  4953. SetFieldValue(formFields, "ResidencePermit", ""); //居住许可或同等证
  4954. SetFieldValue(formFields, "Number", ""); //编号
  4955. SetFieldValue(formFields, "ValidUntils", ""); //有效期至
  4956. SetFieldValue(formFields, "CurrentOccupation", custInfo.Job); //当前职业
  4957. //工作单位名称,地址和电话,学生填写学校名称及地址
  4958. var currCompanyInfo = currCompanyInfos.FirstOrDefault();
  4959. string employerInfoStr = $"{currCompanyInfo?.Company ?? ""} {currCompanyInfo?.CompanyAddress ?? ""} {currCompanyInfo?.Phone ?? ""}";
  4960. SetFieldValue(formFields, "EmployerInfo", employerInfoStr);
  4961. #region 旅行的目的
  4962. //清空值
  4963. SetFieldValue(formFields, "Tourism", "Off"); //旅游
  4964. SetFieldValue(formFields, "Business", "Off"); //商务
  4965. SetFieldValue(formFields, "VisitingFamily", "Off"); //探亲访友
  4966. SetFieldValue(formFields, "Cultural", "Off"); //文化
  4967. SetFieldValue(formFields, "Sports", "Off"); //体育
  4968. SetFieldValue(formFields, "OfficialVisit", "Off"); //官方访问
  4969. SetFieldValue(formFields, "MedicalReasons", "Off"); //医疗
  4970. SetFieldValue(formFields, "Study", "Off"); //学习
  4971. SetFieldValue(formFields, "AirportTransit", "Off"); //机场过境
  4972. SetFieldValue(formFields, "Other", "Off"); //其它
  4973. SetFieldValue(formFields, "OtherDesc", ""); //其它 (请注明)
  4974. //设置值
  4975. if (groupInfo.VisitPurpose.contains("旅游")) SetFieldValue(formFields, "Tourism", "Yes"); //旅游
  4976. if (groupInfo.VisitPurpose.contains("商务")) SetFieldValue(formFields, "Business", "Yes"); //商务
  4977. if (groupInfo.VisitPurpose.contains("探亲访友")) SetFieldValue(formFields, "VisitingFamily", "Yes"); //探亲访友
  4978. if (groupInfo.VisitPurpose.contains("文化")) SetFieldValue(formFields, "Cultural", "Yes"); //文化
  4979. if (groupInfo.VisitPurpose.contains("体育")) SetFieldValue(formFields, "Sports", "Yes"); //体育
  4980. if (groupInfo.VisitPurpose.contains("官方访问")) SetFieldValue(formFields, "OfficialVisit", "Yes"); //官方访问
  4981. if (groupInfo.VisitPurpose.contains("医疗")) SetFieldValue(formFields, "MedicalReasons", "Yes"); //医疗
  4982. if (groupInfo.VisitPurpose.contains("学习")) SetFieldValue(formFields, "Study", "Yes"); //学习
  4983. if (groupInfo.VisitPurpose.contains("机场过境")) SetFieldValue(formFields, "AirportTransit", "Yes"); //机场过境
  4984. #endregion
  4985. SetFieldValue(formFields, "AdditionalInfo", ""); //有关停留原因的补充信息
  4986. string[] RD_country = new string[] { }; //接收处理的国家
  4987. string firstEntryLabel = string.Empty; //首入申根国标签
  4988. string membeDescLabel = string.Empty; //申根国目的地
  4989. string stopDays = string.Empty; //停留天数
  4990. if (!string.IsNullOrEmpty(groupInfo.VisitCountry))
  4991. {
  4992. List<string> SGGNames = new List<string>();//接收处理后的国家 是申根国
  4993. if (groupInfo.VisitCountry.Contains(","))
  4994. RD_country = groupInfo.VisitCountry.Split(',');
  4995. else if (groupInfo.VisitCountry.Contains(' '))
  4996. RD_country = groupInfo.VisitCountry.Split(' ');
  4997. else if (groupInfo.VisitCountry.Contains(","))
  4998. RD_country = groupInfo.VisitCountry.Split(',');
  4999. else if (groupInfo.VisitCountry.Contains("、"))
  5000. RD_country = groupInfo.VisitCountry.Split('、');
  5001. else if (groupInfo.VisitCountry.Contains("|"))
  5002. RD_country = groupInfo.VisitCountry.Split('|');
  5003. //判断是否是申根国家
  5004. for (int i = 0; i < RD_country.Length; i++)
  5005. {
  5006. if (RD_country[i].ToString() != null)
  5007. {
  5008. //在申根国家中筛选 该国家是否是申根国家
  5009. for (int j = 0; j < _shenGenGuos.Length; j++)
  5010. {
  5011. if (RD_country[i] == _shenGenGuos[j])
  5012. SGGNames.Add(_shenGenGuos[j]); //添加申根国
  5013. }
  5014. }
  5015. }
  5016. //目的地国是否有申根国
  5017. if (SGGNames.Count > 0)
  5018. {
  5019. firstEntryLabel = SGGNames.First();
  5020. membeDescLabel = string.Join(",", SGGNames.ToArray());
  5021. //接收生根国详细信息 存储顺序 起飞日期:Day 起飞时刻:StartTime 抵达日期:ArrivedDate 到达时刻:EndTime
  5022. List<SSGDetails> ListSSGDetails = new List<SSGDetails>();
  5023. //处理申根国家 预定到达时间 预定离开时间 预定停留天数
  5024. for (int i = 0; i < SGGNames.Count; i++)
  5025. {
  5026. //在相同的国家下 得到该航班的信息 //抵达时间 起飞日期:Day 起飞时刻:StartTime 到达时刻:EndTime 抵达日期:ArrivedDate 飞行时间:FlightTime 航司 Fliagtcode 入境口岸
  5027. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  5028. //ResidenceTime1 机票三字码信息
  5029. if (atbc != null)
  5030. {
  5031. string HL_Three = ""; //三字码 Three
  5032. for (int j = 0; j < atbc.Rows.Count; j++)
  5033. {
  5034. HL_Three = atbc.Rows[j]["Three"].ToString();
  5035. if (!string.IsNullOrEmpty(HL_Three))
  5036. {
  5037. string threeCodeTwo = HL_Three.Substring(3);
  5038. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  5039. if (tc != null)
  5040. {
  5041. //首入申根国时间
  5042. if (SGGNames[i] == tc.Country)
  5043. {
  5044. SSGDetails SSGDetails = new SSGDetails()
  5045. {
  5046. Three = atbc.Rows[j]["Three"].ToString(), //三字码
  5047. Fliagtcode = atbc.Rows[j]["Fliagtcode"].ToString(), //航司
  5048. startDate = atbc.Rows[j]["Day"].ToString(), //整理起飞日期
  5049. startTime = atbc.Rows[j]["StartTime"].ToString(), //整理起飞时刻
  5050. endDate = atbc.Rows[j]["ArrivedDate"].ToString(), //整理抵达日期
  5051. endTime = atbc.Rows[j]["EndTime"].ToString() //整理抵达时刻
  5052. };
  5053. ListSSGDetails.Add(SSGDetails);
  5054. }
  5055. }
  5056. }
  5057. }
  5058. }
  5059. }
  5060. ListSSGDetails.Sort((a, b) => a.startDate.CompareTo(b.startDate));
  5061. //得到并计算出入境时间
  5062. if (ListSSGDetails != null)
  5063. {
  5064. string RuJingTime = ListSSGDetails.First().endDate + " " + ListSSGDetails.First().endTime.Substring(0, 2) + ":" + ListSSGDetails.First().endTime.Substring(2); //入境时间
  5065. string LiJingTime = ListSSGDetails[ListSSGDetails.Count - 1].startDate + " " + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(0, 2) + ":" + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(2); //离境时间
  5066. stopDays = Convert.ToDateTime(LiJingTime).Subtract(Convert.ToDateTime(RuJingTime)).Days.ToString();
  5067. }
  5068. }
  5069. }
  5070. SetFieldValue(formFields, "MembeDesc", membeDescLabel); //主要申根目的地 (以及其他申根目的地,如适用)
  5071. SetFieldValue(formFields, "FirstEntry", firstEntryLabel); //首入申根国
  5072. //申请入境次数
  5073. SetFieldValue(formFields, "27.SingleEntry", ""); //单次
  5074. SetFieldValue(formFields, "27.TwoEntries", ""); //两次
  5075. SetFieldValue(formFields, "27.MultipleEntries", ""); //多次
  5076. SetFieldValue(formFields, "27.IntendedDateIn", ""); //在申根地区预计首次停留的预计抵达日期
  5077. SetFieldValue(formFields, "27.IntendedDateOut", ""); //在申根地区预计首次停留之后的预计离开日期
  5078. //以往申根国签证是否有指纹记录
  5079. SetFieldValue(formFields, "28.No", ""); //否
  5080. SetFieldValue(formFields, "28.Yes", ""); //是
  5081. SetFieldValue(formFields, "28.KnownDate", ""); //如有,请写明日期
  5082. SetFieldValue(formFields, "28.KnownVisanumber", ""); //如有,请写明签证贴纸号码
  5083. //最后目的地之入境许可
  5084. SetFieldValue(formFields, "29.Issued", ""); //签发机关
  5085. SetFieldValue(formFields, "29.ValidFrom", ""); //有效期由
  5086. SetFieldValue(formFields, "29.Until", ""); //至
  5087. //申根国的邀请人姓名。如无邀请人,请填写申根国的酒店或暂住居所名称
  5088. //得到当前国家下的城市酒店信息
  5089. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  5090. .Where(x => x.DiId == groupId)
  5091. //.Where(x => x.City.contains(city))
  5092. .First();
  5093. //酒店住址
  5094. if (hotelInfo != null)
  5095. {
  5096. SetFieldValue(formFields, "30.SurnameFirstName", hotelInfo?.HotelName ?? ""); //申根国的酒店
  5097. var otherInfo = $"{hotelInfo.HotelAddress}";
  5098. SetFieldValue(formFields, "30.HotelInfo", otherInfo); //邀请人/酒店/暂住居所的地址及电子邮件
  5099. SetFieldValue(formFields, "30.TelephoneNo", hotelInfo?.HotelTel ?? ""); //电话号码
  5100. }
  5101. //邀请公司或机构的名称及地址
  5102. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  5103. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  5104. //.Where(x => x.Country.Contains(county))
  5105. //.Where(x => x.Area.Contains(city))
  5106. .First();
  5107. if (oa != null)
  5108. {
  5109. //申根国的邀请人姓名。如无邀请人,请填写申根国的酒店或暂住居所名称
  5110. SetFieldValue(formFields, "30.SurnameFirstName", oa?.Contact ?? ""); //申根国的酒店
  5111. SetFieldValue(formFields, "30.HotelInfo", oa?.Address ?? ""); //邀请人/酒店/暂住居所的地址及电子邮件
  5112. SetFieldValue(formFields, "30.TelephoneNo", oa?.Tel ?? ""); //电话号码
  5113. string nameAddressLabel = $"{oa.Client} {oa.Address}";
  5114. SetFieldValue(formFields, "31.NameAddress", nameAddressLabel); //邀请公司或机构的名称及地址
  5115. string surnameLabel = $"{oa.Contact} {oa.Tel}";
  5116. SetFieldValue(formFields, "31.Surname", surnameLabel); //邀请公司或机构的联系人姓名、地址、电话号码及电子邮件
  5117. SetFieldValue(formFields, "31.TelephoneNo", oa?.Tel ?? ""); //邀请公司或机构的电话
  5118. }
  5119. //申请人的旅费以及在国外停留期间的生活费用
  5120. SetFieldValue(formFields, "32.Applicant", ""); //由申请人支付
  5121. SetFieldValue(formFields, "32.Cash", ""); //支付方式 - 现金
  5122. SetFieldValue(formFields, "32.Traveller", ""); //支付方式 - 旅行支票
  5123. SetFieldValue(formFields, "32.CreditCard", ""); //支付方式 - 信用卡
  5124. SetFieldValue(formFields, "32.Prepaid", ""); //支付方式 - 预缴住宿
  5125. SetFieldValue(formFields, "32.Prepaid1", ""); //支付方式 - 预缴交通
  5126. SetFieldValue(formFields, "32.OtherMeans", ""); //支付方式 - 其它
  5127. SetFieldValue(formFields, "32.OtherMeansDesc", ""); //支付方式 - 其它(请注明)
  5128. SetFieldValue(formFields, "32.Sponsor", ""); //由赞助方(邀请人、公司或机构)支付,请注明
  5129. SetFieldValue(formFields, "32.Referred", ""); //参见第 30 及 31 项
  5130. SetFieldValue(formFields, "32.ReferredDesc", ""); //参见第 30 及 31 项(请注明)
  5131. SetFieldValue(formFields, "32.OtherSponsor", ""); //其它
  5132. SetFieldValue(formFields, "32.OtherSponsorDesc", ""); //其它(请注明)
  5133. SetFieldValue(formFields, "32.SponsorCash", ""); //赞助方式 - 现金
  5134. SetFieldValue(formFields, "32.SponsorAccommodation", ""); //赞助方式 - 提供住宿
  5135. SetFieldValue(formFields, "32.SponsorExpenses", ""); //赞助方式 - 支付旅程期间所有开支
  5136. SetFieldValue(formFields, "32.SponsorPrepaid", ""); //赞助方式 - 预缴交通
  5137. SetFieldValue(formFields, "32.ponsorOther", ""); //赞助方式 - 其它
  5138. SetFieldValue(formFields, "32.ponsorOtherDesc", ""); //赞助方式 - 其它(请注明)
  5139. SetFieldValue(formFields, "33.PlaceAndDate", DateTime.Now.ToString("yyyy-MM-dd")); //地点及日期
  5140. #endregion
  5141. filePaths.Add(outputPath);
  5142. //return outputPath;
  5143. }
  5144. catch (Exception ex)
  5145. {
  5146. return Ok(JsonView(false, $"生成PDF文件时出错:{ex.Message}"));
  5147. }
  5148. finally
  5149. {
  5150. // 按正确顺序关闭资源
  5151. stamper?.Close();
  5152. reader?.Close();
  5153. templateStream?.Close();
  5154. outputStream?.Close();
  5155. }
  5156. #endregion
  5157. }
  5158. break;
  5159. case 5: // 波兰
  5160. visaTypeName = $"波兰签证申请表";
  5161. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  5162. var polandSavePath = $"{fileServerPath}{visaTypeName}/";
  5163. if (!Directory.Exists(polandSavePath)) Directory.CreateDirectory(polandSavePath);
  5164. if (!System.IO.File.Exists(currTempPath))
  5165. {
  5166. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  5167. }
  5168. foreach (var custInfo in groupCustInfos)
  5169. {
  5170. EncryptionProcessor.DecryptProperties(custInfo);
  5171. var visaData = new VisaDateView()
  5172. {
  5173. groupInfo = groupInfo,
  5174. idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773),
  5175. passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774),
  5176. custInfo = custInfo,
  5177. schoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList(),
  5178. familyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList(),
  5179. companyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList()
  5180. };
  5181. //生成文件
  5182. string outFilePath = CreatePolandVisaPdf(visaData, polandSavePath, currTempPath);
  5183. filePaths.Add(outFilePath);
  5184. }
  5185. break;
  5186. default:
  5187. return Ok(JsonView(false, "正在开发中,请等待。。。"));
  5188. }
  5189. //压缩文件
  5190. // 压缩文件
  5191. var zipFilePathName = $"{groupInfo.TeamName}({visaTypeName}).zip";
  5192. var zipFilePath = $"{fileServerPath}{zipFilePathName}";
  5193. // 关键修复:先获取压缩文件的上级目录,检查并创建(如果不存在)
  5194. string zipDirectory = Path.GetDirectoryName(zipFilePath);
  5195. if (!Directory.Exists(zipDirectory))
  5196. {
  5197. // CreateDirectory会自动创建所有不存在的上级目录,无需手动逐层创建
  5198. Directory.CreateDirectory(zipDirectory);
  5199. }
  5200. using (var zipFileStream = new FileStream(zipFilePath, FileMode.Create))
  5201. {
  5202. using (var zipArchive = new ZipArchive(zipFileStream, ZipArchiveMode.Create))
  5203. {
  5204. foreach (string filePath in filePaths)
  5205. {
  5206. // 增加空值/空字符串校验,提升代码健壮性
  5207. if (!string.IsNullOrEmpty(filePath) && System.IO.File.Exists(filePath))
  5208. {
  5209. // 获取文件名
  5210. string fileName = Path.GetFileName(filePath);
  5211. // 将文件添加到ZIP归档中
  5212. zipArchive.CreateEntryFromFile(filePath, fileName);
  5213. }
  5214. }
  5215. }
  5216. }
  5217. url = $"{serverPath}{zipFilePathName}";
  5218. if (!string.IsNullOrEmpty(url))
  5219. {
  5220. return Ok(JsonView(true,"操作成功", url));
  5221. }
  5222. return Ok(JsonView(false, "操作失败!"));
  5223. }
  5224. #region iTextSharp pdf 设置值辅助方法
  5225. /// <summary>
  5226. /// 设置文本值
  5227. /// 辅助方法
  5228. /// </summary>
  5229. /// <param name="formFields"></param>
  5230. /// <param name="fieldName"></param>
  5231. /// <param name="value"></param>
  5232. private static void SetFieldValue(AcroFields formFields, string fieldName, string value)
  5233. {
  5234. if (formFields.Fields.ContainsKey(fieldName) && !string.IsNullOrEmpty(value))
  5235. {
  5236. formFields.SetField(fieldName, value);
  5237. }
  5238. }
  5239. /// <summary>
  5240. /// 创建PDF
  5241. /// </summary>
  5242. /// <param name="data"></param>
  5243. /// <param name="currSavePath"></param>
  5244. /// <param name="currTempPath"></param>
  5245. /// <returns></returns>
  5246. /// <exception cref="Exception"></exception>
  5247. private string CreatePolandVisaPdf(VisaDateView data, string currSavePath, string currTempPath)
  5248. {
  5249. var groupInfo = data.groupInfo;
  5250. var groupId = groupInfo.Id;
  5251. var idInfo = data.idInfo;
  5252. var passportInfo = data.passportInfo;
  5253. var custInfo = data.custInfo;
  5254. var currSchoolInfos = data.schoolInfos;
  5255. var currFamilyInfos = data.familyInfos;
  5256. var currCompanyInfos = data.companyInfos;
  5257. string outputPath = $"{currSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  5258. PdfReader reader = null;
  5259. FileStream templateStream = null;
  5260. FileStream outputStream = null;
  5261. PdfStamper stamper = null;
  5262. try
  5263. {
  5264. //读取模板文件
  5265. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  5266. reader = new PdfReader(templateStream);
  5267. //创建输出文件
  5268. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  5269. stamper = new PdfStamper(reader, outputStream);
  5270. AcroFields formFields = stamper.AcroFields;
  5271. #region 设置文本值
  5272. SetFieldValue(formFields, "1.LastName", custInfo.LastName); //姓
  5273. SetFieldValue(formFields, "2.BirthLastName", custInfo.LastName); // 出生时姓氏
  5274. SetFieldValue(formFields, "3.FirstName", custInfo.FirstName); // 名
  5275. // 出生日期(日-月-年)
  5276. string idCard = idInfo.CertNo;
  5277. string birthday = string.Empty;
  5278. if (!string.IsNullOrEmpty(idCard))
  5279. {
  5280. string year = idCard.Substring(6, 4);
  5281. string month = idCard.Substring(10, 2);
  5282. string day = idCard.Substring(12, 2);
  5283. birthday = day + "-" + month + "-" + year;
  5284. }
  5285. SetFieldValue(formFields, "4.Birthday", birthday);
  5286. string currentNationality = custInfo.BirthProvince + custInfo.BirthCity;
  5287. SetFieldValue(formFields, "5.CurrentNationality", currentNationality); // 出生地
  5288. SetFieldValue(formFields, "6.CountryBirth", "中国"); // 出生国
  5289. SetFieldValue(formFields, "7.CurrentNationalityCountry", "中国"); // 现国籍
  5290. SetFieldValue(formFields, "7.NationalityBirth", ""); // 出生时国籍,如与现国籍不同
  5291. SetFieldValue(formFields, "7.OtherNationalities", ""); // 其他国籍
  5292. #region 性别处理
  5293. //清除性别
  5294. SetFieldValue(formFields, "8.Male", "Off"); // 性别 - 男
  5295. SetFieldValue(formFields, "8.Female", "Off"); // 性别 - 女
  5296. SetFieldValue(formFields, "8.Other", "Off"); // 性别 - 其他
  5297. //设置性别
  5298. if (custInfo.Sex == 0) //男
  5299. {
  5300. SetFieldValue(formFields, "8.Male", "Yes"); // 性别 - 男
  5301. }
  5302. else if (custInfo.Sex == 1) //女
  5303. {
  5304. SetFieldValue(formFields, "8.Female", "Yes"); // 性别 - 女
  5305. }
  5306. else //其他
  5307. {
  5308. SetFieldValue(formFields, "8.Other", "Yes"); // 性别 - 其他
  5309. }
  5310. #endregion
  5311. #region 婚姻状况处理
  5312. //清除婚姻状况
  5313. SetFieldValue(formFields, "9.Single", "Off"); // 婚姻状况 - 未婚
  5314. SetFieldValue(formFields, "9.Married", "Off"); // 婚姻状况 - 已婚
  5315. SetFieldValue(formFields, "9.RegisteredPartnership", "Off"); // 婚姻状况 - 注册伴侣关系
  5316. SetFieldValue(formFields, "9.Separated", "Off"); // 婚姻状况 - 分居
  5317. SetFieldValue(formFields, "9.Divorced", "Off"); // 婚姻状况 - 离婚
  5318. SetFieldValue(formFields, "9.Widow(er)", "Off"); // 婚姻状况 - 丧偶
  5319. SetFieldValue(formFields, "9.OtherCivilStatus", "Off"); // 婚姻状况 - 其它
  5320. SetFieldValue(formFields, "9.CivilStatusOther", ""); // 婚姻状况 - 其它(请注明)
  5321. //设置婚姻状况
  5322. switch (custInfo.Marriage)
  5323. {
  5324. case 1: // 未婚
  5325. SetFieldValue(formFields, "9.Single", "Yes");
  5326. break;
  5327. case 2: // 已婚
  5328. SetFieldValue(formFields, "9.Married", "Yes");
  5329. break;
  5330. case 3: // 离异
  5331. SetFieldValue(formFields, "9.Divorced", "Yes");
  5332. break;
  5333. case 4: // 离异
  5334. SetFieldValue(formFields, "9.Widow(er)", "Yes");
  5335. break;
  5336. }
  5337. #endregion
  5338. //亲权人(如是未成年申请人 )/合法监护人(姓名、住址,如与申请人不同) 电话号码、电子邮件及国籍
  5339. SetFieldValue(formFields, "10.ParentalAuthority", "");
  5340. SetFieldValue(formFields, "11.NationalIdentityNumber", idCard); //公民身份证号码
  5341. #region 护照(旅行证件类型)处理
  5342. //清除值
  5343. SetFieldValue(formFields, "12.OrdinaryPassport", "Off"); //旅行证件类型 - 普通护照
  5344. SetFieldValue(formFields, "12.DiplomaticPassport", "Off"); //旅行证件类型 - 外交护照
  5345. SetFieldValue(formFields, "12.ServicePassport", "Off"); //旅行证件类型 - 公务护照
  5346. SetFieldValue(formFields, "12.OfficialPassport", "Off"); //旅行证件类型 - 因公护照
  5347. SetFieldValue(formFields, "12.SpecialPassport", "Off"); //旅行证件类型 - 特殊护照
  5348. SetFieldValue(formFields, "12.OtherTravel", "Off"); //旅行证件类型 - 其它旅行证件
  5349. SetFieldValue(formFields, "12.OtherTravelDesc", ""); //旅行证件类型 - 其它旅行证件(请注明)
  5350. //设置值
  5351. SetFieldValue(formFields, "12.OrdinaryPassport", "Yes"); //旅行证件类型 - 普通护照
  5352. if (passportInfo != null)
  5353. {
  5354. SetFieldValue(formFields, "13.TravelNumber", passportInfo.CertNo); //旅行证件编号
  5355. SetFieldValue(formFields, "14.IssueDate", passportInfo.IssueDt?.ToString("yyyy-MM-dd") ?? ""); //签发日期
  5356. SetFieldValue(formFields, "15.ValidUntil", passportInfo.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); //有效期至
  5357. SetFieldValue(formFields, "16.IssuedCountry", passportInfo.Country); //签发(国)
  5358. }
  5359. #endregion
  5360. //如有家庭成员为欧盟、欧洲经济区、瑞士或受益于退欧协议的英国公民的,请填写该家庭成员的个人信息
  5361. SetFieldValue(formFields, "17.LastName_om", ""); //姓
  5362. SetFieldValue(formFields, "17.FirstName_om", ""); //名
  5363. SetFieldValue(formFields, "17.BirthDate_om", ""); //出生日期(日-月-年)
  5364. SetFieldValue(formFields, "17.Nationality_om", ""); //国籍
  5365. SetFieldValue(formFields, "17.TravelNuber_om", ""); //旅行证件或身分证编号
  5366. //申请人与欧盟、欧洲经济区、瑞士或受益于退欧协议的英国公民的关系
  5367. SetFieldValue(formFields, "18.Spouse_om", ""); //配偶
  5368. SetFieldValue(formFields, "18.RegisteredPartnership_om", ""); //注册伴侣
  5369. SetFieldValue(formFields, "18.Child_om", ""); //子女
  5370. SetFieldValue(formFields, "18.DependentAscendant_om", ""); //受养人
  5371. SetFieldValue(formFields, "18.Grandchild_om", ""); //孙子女
  5372. SetFieldValue(formFields, "18.FamilyOther_om", ""); //其他
  5373. SetFieldValue(formFields, "18.FamilyOtherDesc_om", ""); //其他(说明)
  5374. //申请人住址及电子邮件
  5375. string applicantHomeAddress = $"{custInfo.Address} {custInfo.Email}";
  5376. SetFieldValue(formFields, "19.ApplicantHomeAddress", applicantHomeAddress); //申请人住址及电子邮件
  5377. SetFieldValue(formFields, "19.TelephoneNo", custInfo.Tel); //电话号码
  5378. //是否居住在现时国籍以外的国家
  5379. SetFieldValue(formFields, "20.AnotherCountryNo", "Yes"); //否
  5380. SetFieldValue(formFields, "20.AnotherCountryYes", ""); //是
  5381. SetFieldValue(formFields, "20.ResidencePermit", ""); //居住许可或同等证
  5382. SetFieldValue(formFields, "20.Number", ""); //编号
  5383. SetFieldValue(formFields, "20.ValidUntils", ""); //有效期至
  5384. SetFieldValue(formFields, "21.CurrentOccupation", custInfo.Job); //当前职业
  5385. //工作单位名称,地址和电话,学生填写学校名称及地址
  5386. var currCompanyInfo = currCompanyInfos.FirstOrDefault();
  5387. string employerInfoStr = $"{currCompanyInfo?.Company ?? ""} {currCompanyInfo?.CompanyAddress ?? ""} {currCompanyInfo?.Phone ?? ""}";
  5388. SetFieldValue(formFields, "22.EmployerInfo", employerInfoStr);
  5389. #region 旅行的目的
  5390. //清空值
  5391. SetFieldValue(formFields, "23.Tourism", "Off"); // 旅游
  5392. SetFieldValue(formFields, "23.Business", "Off"); // 商务
  5393. SetFieldValue(formFields, "23.VisitingFamily", "Off"); // 探亲访友
  5394. SetFieldValue(formFields, "23.Cultural", "Off"); // 文化
  5395. SetFieldValue(formFields, "23.Sports", "Off"); // 体育
  5396. SetFieldValue(formFields, "23.OfficialVisit", "Off"); // 官方访问
  5397. SetFieldValue(formFields, "23.MedicalReasons", "Off"); // 医疗
  5398. SetFieldValue(formFields, "23.Study", "Off"); // 学习
  5399. SetFieldValue(formFields, "23.AirportTransit", "Off"); // 机场过境
  5400. SetFieldValue(formFields, "23.Other", "Off"); // 其它
  5401. SetFieldValue(formFields, "23.OtherDesc", ""); // 其它 (请注明)
  5402. //设置值
  5403. if (groupInfo.VisitPurpose.contains("旅游")) SetFieldValue(formFields, "23.Tourism", "Yes"); //旅游
  5404. if (groupInfo.VisitPurpose.contains("商务")) SetFieldValue(formFields, "23.Business", "Yes"); //商务
  5405. if (groupInfo.VisitPurpose.contains("探亲访友")) SetFieldValue(formFields, "23.VisitingFamily", "Yes"); //探亲访友
  5406. if (groupInfo.VisitPurpose.contains("文化")) SetFieldValue(formFields, "23.Cultural", "Yes"); //文化
  5407. if (groupInfo.VisitPurpose.contains("体育")) SetFieldValue(formFields, "23.Sports", "Yes"); //体育
  5408. if (groupInfo.VisitPurpose.contains("官方访问")) SetFieldValue(formFields, "23.OfficialVisit", "Yes"); //官方访问
  5409. if (groupInfo.VisitPurpose.contains("医疗")) SetFieldValue(formFields, "23.MedicalReasons", "Yes"); //医疗
  5410. if (groupInfo.VisitPurpose.contains("学习")) SetFieldValue(formFields, "23.Study", "Yes"); //学习
  5411. if (groupInfo.VisitPurpose.contains("机场过境")) SetFieldValue(formFields, "23.AirportTransit", "Yes"); //机场过境
  5412. #endregion
  5413. SetFieldValue(formFields, "24.AdditionalInfo", ""); //有关停留原因的补充信息
  5414. string[] RD_country = new string[] { }; //接收处理的国家
  5415. string firstEntryLabel = string.Empty; //首入申根国标签
  5416. string membeDescLabel = string.Empty; //申根国目的地
  5417. string stopDays = string.Empty; //停留天数
  5418. if (!string.IsNullOrEmpty(groupInfo.VisitCountry))
  5419. {
  5420. List<string> SGGNames = new List<string>();//接收处理后的国家 是申根国
  5421. if (groupInfo.VisitCountry.Contains(","))
  5422. RD_country = groupInfo.VisitCountry.Split(',');
  5423. else if (groupInfo.VisitCountry.Contains(' '))
  5424. RD_country = groupInfo.VisitCountry.Split(' ');
  5425. else if (groupInfo.VisitCountry.Contains(","))
  5426. RD_country = groupInfo.VisitCountry.Split(',');
  5427. else if (groupInfo.VisitCountry.Contains("、"))
  5428. RD_country = groupInfo.VisitCountry.Split('、');
  5429. else if (groupInfo.VisitCountry.Contains("|"))
  5430. RD_country = groupInfo.VisitCountry.Split('|');
  5431. //判断是否是申根国家
  5432. for (int i = 0; i < RD_country.Length; i++)
  5433. {
  5434. if (RD_country[i].ToString() != null)
  5435. {
  5436. //在申根国家中筛选 该国家是否是申根国家
  5437. for (int j = 0; j < _shenGenGuos.Length; j++)
  5438. {
  5439. if (RD_country[i] == _shenGenGuos[j])
  5440. SGGNames.Add(_shenGenGuos[j]); //添加申根国
  5441. }
  5442. }
  5443. }
  5444. //目的地国是否有申根国
  5445. if (SGGNames.Count > 0)
  5446. {
  5447. firstEntryLabel = SGGNames.First();
  5448. membeDescLabel = string.Join(",", SGGNames.ToArray());
  5449. //接收生根国详细信息 存储顺序 起飞日期:Day 起飞时刻:StartTime 抵达日期:ArrivedDate 到达时刻:EndTime
  5450. List<SSGDetails> ListSSGDetails = new List<SSGDetails>();
  5451. //处理申根国家 预定到达时间 预定离开时间 预定停留天数
  5452. for (int i = 0; i < SGGNames.Count; i++)
  5453. {
  5454. //在相同的国家下 得到该航班的信息 //抵达时间 起飞日期:Day 起飞时刻:StartTime 到达时刻:EndTime 抵达日期:ArrivedDate 飞行时间:FlightTime 航司 Fliagtcode 入境口岸
  5455. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  5456. //ResidenceTime1 机票三字码信息
  5457. if (atbc != null)
  5458. {
  5459. string HL_Three = ""; //三字码 Three
  5460. for (int j = 0; j < atbc.Rows.Count; j++)
  5461. {
  5462. HL_Three = atbc.Rows[j]["Three"].ToString();
  5463. if (!string.IsNullOrEmpty(HL_Three))
  5464. {
  5465. string threeCodeTwo = HL_Three.Substring(3);
  5466. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  5467. if (tc != null)
  5468. {
  5469. //首入申根国时间
  5470. if (SGGNames[i] == tc.Country)
  5471. {
  5472. SSGDetails SSGDetails = new SSGDetails()
  5473. {
  5474. Three = atbc.Rows[j]["Three"].ToString(), //三字码
  5475. Fliagtcode = atbc.Rows[j]["Fliagtcode"].ToString(), //航司
  5476. startDate = atbc.Rows[j]["Day"].ToString(), //整理起飞日期
  5477. startTime = atbc.Rows[j]["StartTime"].ToString(), //整理起飞时刻
  5478. endDate = atbc.Rows[j]["ArrivedDate"].ToString(), //整理抵达日期
  5479. endTime = atbc.Rows[j]["EndTime"].ToString() //整理抵达时刻
  5480. };
  5481. ListSSGDetails.Add(SSGDetails);
  5482. }
  5483. }
  5484. }
  5485. }
  5486. }
  5487. }
  5488. ListSSGDetails.Sort((a, b) => a.startDate.CompareTo(b.startDate));
  5489. //得到并计算出入境时间
  5490. if (ListSSGDetails != null)
  5491. {
  5492. string RuJingTime = ListSSGDetails.First().endDate + " " + ListSSGDetails.First().endTime.Substring(0, 2) + ":" + ListSSGDetails.First().endTime.Substring(2); //入境时间
  5493. string LiJingTime = ListSSGDetails[ListSSGDetails.Count - 1].startDate + " " + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(0, 2) + ":" + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(2); //离境时间
  5494. stopDays = Convert.ToDateTime(LiJingTime).Subtract(Convert.ToDateTime(RuJingTime)).Days.ToString();
  5495. }
  5496. }
  5497. }
  5498. SetFieldValue(formFields, "25.MembeDesc", membeDescLabel); //主要申根目的地 (以及其他申根目的地,如适用)
  5499. SetFieldValue(formFields, "26.FirstEntry", firstEntryLabel); //首入申根国
  5500. //申请入境次数
  5501. SetFieldValue(formFields, "27.SingleEntry", ""); //单次
  5502. SetFieldValue(formFields, "27.TwoEntries", ""); //两次
  5503. SetFieldValue(formFields, "27.MultipleEntries", ""); //多次
  5504. SetFieldValue(formFields, "27.IntendedDateIn", ""); //在申根地区预计首次停留的预计抵达日期
  5505. SetFieldValue(formFields, "27.IntendedDateOut", ""); //在申根地区预计首次停留之后的预计离开日期
  5506. //以往申根国签证是否有指纹记录
  5507. SetFieldValue(formFields, "28.No", ""); //否
  5508. SetFieldValue(formFields, "28.Yes", ""); //是
  5509. SetFieldValue(formFields, "28.KnownDate", ""); //如有,请写明日期
  5510. SetFieldValue(formFields, "28.KnownVisanumber", ""); //如有,请写明签证贴纸号码
  5511. //最后目的地之入境许可
  5512. SetFieldValue(formFields, "29.Issued", ""); //签发机关 Entry permit for the final country of destination, where applicable
  5513. SetFieldValue(formFields, "29.ValidFrom", ""); //有效期由
  5514. SetFieldValue(formFields, "29.Until", ""); //至
  5515. //申根国的邀请人姓名。如无邀请人,请填写申根国的酒店或暂住居所名称
  5516. //得到当前国家下的城市酒店信息
  5517. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  5518. .Where(x => x.DiId == groupId)
  5519. //.Where(x => x.City.contains(city))
  5520. .First();
  5521. //酒店住址
  5522. if (hotelInfo != null)
  5523. {
  5524. SetFieldValue(formFields, "30.SurnameFirstName", hotelInfo?.HotelName ?? ""); //申根国的酒店
  5525. var otherInfo = $"{hotelInfo.HotelAddress}";
  5526. SetFieldValue(formFields, "30.HotelInfo", otherInfo); //邀请人/酒店/暂住居所的地址及电子邮件
  5527. SetFieldValue(formFields, "30.TelephoneNo", hotelInfo?.HotelTel ?? ""); //电话号码
  5528. }
  5529. //邀请公司或机构的名称及地址
  5530. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  5531. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  5532. //.Where(x => x.Country.Contains(county))
  5533. //.Where(x => x.Area.Contains(city))
  5534. .First();
  5535. if (oa != null)
  5536. {
  5537. //申根国的邀请人姓名。如无邀请人,请填写申根国的酒店或暂住居所名称
  5538. SetFieldValue(formFields, "30.SurnameFirstName", oa?.Contact ?? ""); //申根国的酒店
  5539. SetFieldValue(formFields, "30.HotelInfo", oa?.Address ?? ""); //邀请人/酒店/暂住居所的地址及电子邮件
  5540. SetFieldValue(formFields, "30.TelephoneNo", oa?.Tel ?? ""); //电话号码
  5541. string nameAddressLabel = $"{oa.Client} {oa.Address}";
  5542. SetFieldValue(formFields, "31.NameAddress", nameAddressLabel); //邀请公司或机构的名称及地址
  5543. string surnameLabel = $"{oa.Contact} {oa.Tel}";
  5544. SetFieldValue(formFields, "31.Surname", surnameLabel); //邀请公司或机构的联系人姓名、地址、电话号码及电子邮件
  5545. SetFieldValue(formFields, "31.TelephoneNo", oa?.Tel ?? ""); //邀请公司或机构的电话
  5546. }
  5547. //申请人的旅费以及在国外停留期间的生活费用
  5548. SetFieldValue(formFields, "32.Applicant", ""); //由申请人支付
  5549. SetFieldValue(formFields, "32.Cash", ""); //支付方式 - 现金
  5550. SetFieldValue(formFields, "32.Traveller", ""); //支付方式 - 旅行支票
  5551. SetFieldValue(formFields, "32.CreditCard", ""); //支付方式 - 信用卡
  5552. SetFieldValue(formFields, "32.Prepaid", ""); //支付方式 - 预缴住宿
  5553. SetFieldValue(formFields, "32.Prepaid1", ""); //支付方式 - 预缴交通
  5554. SetFieldValue(formFields, "32.OtherMeans", ""); //支付方式 - 其它
  5555. SetFieldValue(formFields, "32.OtherMeansDesc", ""); //支付方式 - 其它(请注明)
  5556. SetFieldValue(formFields, "32.Sponsor", ""); //由赞助方(邀请人、公司或机构)支付,请注明
  5557. SetFieldValue(formFields, "32.Referred", ""); //参见第 30 及 31 项
  5558. SetFieldValue(formFields, "32.ReferredDesc", ""); //参见第 30 及 31 项(请注明)
  5559. SetFieldValue(formFields, "32.OtherSponsor", ""); //其它
  5560. SetFieldValue(formFields, "32.OtherSponsorDesc", ""); //其它(请注明)
  5561. SetFieldValue(formFields, "32.SponsorCash", ""); //赞助方式 - 现金
  5562. SetFieldValue(formFields, "32.SponsorAccommodation", ""); //赞助方式 - 提供住宿
  5563. SetFieldValue(formFields, "32.SponsorExpenses", ""); //赞助方式 - 支付旅程期间所有开支
  5564. SetFieldValue(formFields, "32.SponsorPrepaid", ""); //赞助方式 - 预缴交通
  5565. SetFieldValue(formFields, "32.ponsorOther", ""); //赞助方式 - 其它
  5566. SetFieldValue(formFields, "32.ponsorOtherDesc", ""); //赞助方式 - 其它(请注明)
  5567. //填表人与申请人不同
  5568. SetFieldValue(formFields, "33.WriteTableName", ""); //姓名
  5569. SetFieldValue(formFields, "33.WriteTableAddress", ""); //住址
  5570. SetFieldValue(formFields, "33.WriteTableTel", ""); //电话
  5571. SetFieldValue(formFields, "EndPlaceAndDate", DateTime.Now.ToString("yyyy-MM-dd")); //地点及日期
  5572. #endregion
  5573. }
  5574. catch (Exception ex)
  5575. {
  5576. throw new Exception($"生成PDF文件时出错: {ex.Message}", ex);
  5577. }
  5578. finally
  5579. {
  5580. // 按正确顺序关闭资源
  5581. stamper?.Close();
  5582. reader?.Close();
  5583. templateStream?.Close();
  5584. outputStream?.Close();
  5585. }
  5586. return outputPath;
  5587. }
  5588. #endregion
  5589. #region 文档下载辅助实体类
  5590. private class VisaDateView
  5591. {
  5592. /// <summary>
  5593. /// 团组信息
  5594. /// </summary>
  5595. public Grp_DelegationInfo groupInfo { get; set; }
  5596. /// <summary>
  5597. /// 身份证信息
  5598. /// </summary>
  5599. public Crm_CustomerCert idInfo { get; set; }
  5600. /// <summary>
  5601. /// 护照信息
  5602. /// </summary>
  5603. public Crm_CustomerCert passportInfo { get; set; }
  5604. /// <summary>
  5605. /// 客户信息
  5606. /// </summary>
  5607. public Crm_DeleClient custInfo { get; set; }
  5608. /// <summary>
  5609. /// 学校资料
  5610. /// </summary>
  5611. public List<Crm_VisaCustomerSchool> schoolInfos { get; set; }
  5612. /// <summary>
  5613. /// 家庭成员资料
  5614. /// </summary>
  5615. public List<Crm_VisaCustomerFamily> familyInfos { get; set; }
  5616. /// <summary>
  5617. /// 公司资料
  5618. /// </summary>
  5619. public List<Crm_VisaCustomerCompany> companyInfos { get; set; }
  5620. }
  5621. private class SSGDetails
  5622. {
  5623. public string Three { get; set; } //三字码
  5624. public string Fliagtcode { get; set; } //航司
  5625. public string startDate { get; set; } //首入申根国日期
  5626. public string startTime { get; set; } //首入申根国时间
  5627. public string endDate { get; set; } //离开申根国日期
  5628. public string endTime { get; set; } //离开申根国时间
  5629. }
  5630. #endregion
  5631. #endregion
  5632. /// <summary>
  5633. /// 根据团组Id获取签证客户信息List
  5634. /// </summary>
  5635. /// <param name="dto">请求dto</param>
  5636. /// <returns></returns>
  5637. [HttpPost]
  5638. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5639. public async Task<IActionResult> GetCrmByGroupId(ClientByGroupIdDto dto)
  5640. {
  5641. var data = await _groupRepository.GetCrmByGroupId(dto);
  5642. return Ok(JsonView(data.Code == 0, data.Code != 0 ? "暂无信息" : "操作成功", data.Data));
  5643. }
  5644. /// <summary>
  5645. /// IOS获取团组签证拍照上传进度01(团组列表)
  5646. /// </summary>
  5647. /// <param name="dto">请求dto</param>
  5648. /// <returns></returns>
  5649. [HttpPost]
  5650. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5651. public async Task<IActionResult> PostIOSVisaProgress(IOS_VisaDto dto)
  5652. {
  5653. if (dto == null)
  5654. {
  5655. return Ok(JsonView(false, "参数为空"));
  5656. }
  5657. DelegationVisaViewList visaList = _delegationVisaRep.GetDelegationList(dto);
  5658. return Ok(JsonView(visaList));
  5659. }
  5660. /// <summary>
  5661. /// IOS获取团组签证拍照上传进度02(团组签证详情\人员列表\国家)
  5662. /// </summary>
  5663. /// <returns></returns>
  5664. [HttpPost]
  5665. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5666. public async Task<ActionResult> PostIOSVisaProgressContent(IOS_VisaCustomerListDto dto)
  5667. {
  5668. if (dto == null)
  5669. {
  5670. return Ok(JsonView(false, "请求错误:"));
  5671. }
  5672. List<DelegationVisaProgressView> list = _delegationVisaRep.GetDelegationProgressList(dto.diId);
  5673. return Ok(JsonView(list));
  5674. }
  5675. /// <summary>
  5676. /// IOS获取团组签证拍照上传进度03(相册)
  5677. /// </summary>
  5678. /// <returns></returns>
  5679. [HttpPost]
  5680. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5681. public async Task<ActionResult> PostIOSVisaProgressImageList(IOS_VisaImageListDto dto)
  5682. {
  5683. if (dto == null)
  5684. {
  5685. return Ok(JsonView(false, "请求错误:"));
  5686. }
  5687. List<VisaProgressImageView> list = _delegationVisaRep.GetVisaProgressImageList(dto.visaProgressCustomerId, dto.picType);
  5688. string url = AppSettingsHelper.Get("VisaProgressImageBaseUrl") + AppSettingsHelper.Get("VisaProgressImageFtpPath");
  5689. list.ForEach(s => s.url = url);
  5690. return Ok(JsonView(list));
  5691. }
  5692. /// <summary>
  5693. /// IOS获取团组签证拍照上传进度04(图片上传)
  5694. /// </summary>
  5695. /// <param name="dto"></param>
  5696. /// <returns></returns>
  5697. [HttpPost]
  5698. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5699. public async Task<ActionResult> PostIOSVisaProgressUploadImage(IOS_VisaUploadImageDto dto)
  5700. {
  5701. //string result = decodeBase64ToImage(dto.base64DataURL, dto.imageName);
  5702. //if (!string.IsNullOrEmpty(result))
  5703. //{
  5704. //}
  5705. //else {
  5706. // return Ok(JsonView(false, "上传失败"));
  5707. //}
  5708. var dt1970 = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  5709. int sucNum = 0;
  5710. try
  5711. {
  5712. foreach (var item in dto.base64DataList)
  5713. {
  5714. string imageName = dto.imageName + ((DateTime.Now.Ticks - dt1970.Ticks) / 10000).ToString();
  5715. string result = DecodeBase64ToImage(item, imageName);
  5716. if (!string.IsNullOrEmpty(result))
  5717. {
  5718. var pic = new Grp_VisaProgressCustomerPicture
  5719. {
  5720. CreateUserId = dto.CreateUserId,
  5721. PicName = imageName,
  5722. PicPath = result,
  5723. VisaProgressCustomerId = dto.visaProgressCustomerId
  5724. };
  5725. int insertResult = await _delegationVisaRep.AddAsync<Grp_VisaProgressCustomerPicture>(pic);
  5726. if (insertResult > 0)
  5727. {
  5728. sucNum++;
  5729. }
  5730. }
  5731. }
  5732. }
  5733. catch (Exception ex)
  5734. {
  5735. return Ok(JsonView(false, ex.Message));
  5736. }
  5737. string msg = string.Format(@"成功上传{0}张", sucNum);
  5738. return Ok(JsonView(true, msg));
  5739. }
  5740. private string DecodeBase64ToImage(string base64DataURL, string imgName)
  5741. {
  5742. string filename = "";//声明一个string类型的相对路径
  5743. String base64 = base64DataURL.Substring(base64DataURL.IndexOf(",") + 1); //将‘,’以前的多余字符串删除
  5744. System.Drawing.Bitmap bitmap = null;//定义一个Bitmap对象,接收转换完成的图片
  5745. try//会有异常抛出,try,catch一下
  5746. {
  5747. byte[] arr = Convert.FromBase64String(base64);//将纯净资源Base64转换成等效的8位无符号整形数组
  5748. var ms = new System.IO.MemoryStream(arr);//转换成无法调整大小的MemoryStream对象
  5749. bitmap = new System.Drawing.Bitmap(ms);//将MemoryStream对象转换成Bitmap对象
  5750. var fileDir = AppSettingsHelper.Get("VisaProgressImageBasePath");
  5751. //文件名称
  5752. filename = "VisaProgress_" + DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + imgName + ".jpeg";//所要保存的相对路径及名字
  5753. //上传的文件的路径
  5754. string filePath = "";
  5755. if (!Directory.Exists(fileDir))
  5756. {
  5757. Directory.CreateDirectory(fileDir);
  5758. }
  5759. //上传的文件的路径
  5760. filePath = fileDir + filename;
  5761. //string url = HttpRuntime.AppDomainAppPath.ToString();
  5762. //string tmpRootDir = System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString()); //获取程序根目录
  5763. //string imagesurl2 = tmpRootDir + filename; //转换成绝对路径
  5764. bitmap.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);//保存到服务器路径
  5765. //bitmap.Save(filePath + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
  5766. //bitmap.Save(filePath + ".gif", System.Drawing.Imaging.ImageFormat.Gif);
  5767. //bitmap.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
  5768. ms.Close();//关闭当前流,并释放所有与之关联的资源
  5769. bitmap.Dispose();
  5770. }
  5771. catch (Exception e)
  5772. {
  5773. string massage = e.Message;
  5774. Logs("IOS图片上传Error:" + massage);
  5775. //filename = e.Message;
  5776. }
  5777. return filename;//返回相对路径
  5778. }
  5779. /// <summary>
  5780. /// IOS获取团组签证拍照上传进度05(修改签证状态/通知)
  5781. /// </summary>
  5782. /// <param name="dto"></param>
  5783. /// <returns></returns>
  5784. [HttpPost]
  5785. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5786. public async Task<ActionResult> PostIOSVisaProgressChangeStatus(IOS_VisaChangeStatusDto dto)
  5787. {
  5788. if (dto == null)
  5789. {
  5790. return Ok(JsonView(false, "请求错误:"));
  5791. }
  5792. string msg = "参数错误";
  5793. if (dto.diId > 0 && dto.visaStatus > 0 && dto.visaStatus < 4)
  5794. {
  5795. try
  5796. {
  5797. //_delegationVisaRep.BeginTran();
  5798. var updCount = await _delegationVisaRep._sqlSugar.Updateable<Grp_VisaProgressCustomer>()
  5799. .SetColumns(it => it.WorkStatus == dto.visaStatus)
  5800. .Where(s => s.Id == dto.visaProgressCustomerId)
  5801. .ExecuteCommandAsync();
  5802. if (updCount > 0 && dto.publishCode == 1)
  5803. {
  5804. _delegationVisaRep.ChangeDataBase(DBEnum.OA2014DB); //切换到新OA后删除
  5805. string sqlDelegation = string.Format(@" Select * From DelegationInfo With(Nolock) Where Id = {0} ", dto.diId);
  5806. OA2021_DelegationInfo groupData = _sqlSugar.SqlQueryable<OA2021_DelegationInfo>(sqlDelegation).First();
  5807. //GroupInfoDto grpDto = new GroupInfoDto() { Id = dto.diId };
  5808. //var groupData = await _groupRepository.GetGroupInfo(grpDto);
  5809. _delegationVisaRep.ChangeDataBase(DBEnum.OA2023DB); //切换到新OA后删除
  5810. if (groupData == null)
  5811. {
  5812. _delegationVisaRep.RollbackTran();
  5813. }
  5814. string title = string.Format(@"[签证进度更新]");
  5815. string content = string.Format(@"测试文本");
  5816. bool rst = await _message.AddMsg(new MessageDto()
  5817. {
  5818. Type = MessageTypeEnum.GroupVisaProgressUpdate,
  5819. IssuerId = dto.publisher,
  5820. Title = title,
  5821. Content = content,
  5822. ReleaseTime = DateTime.Now,
  5823. UIdList = new List<int> {
  5824. 234
  5825. }
  5826. });
  5827. if (rst)
  5828. {
  5829. return Ok(JsonView(true, "发送通知成功"));
  5830. }
  5831. }
  5832. //_delegationVisaRep.CommitTran();
  5833. }
  5834. catch (Exception)
  5835. {
  5836. //_delegationVisaRep.RollbackTran();
  5837. }
  5838. }
  5839. return Ok(JsonView(true, msg));
  5840. }
  5841. #endregion
  5842. #endregion
  5843. #region 团组任务分配
  5844. /// <summary>
  5845. /// 团组任务分配初始化
  5846. /// </summary>
  5847. /// <returns></returns>
  5848. [HttpPost]
  5849. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5850. public async Task<IActionResult> GetTaskAssignmen()
  5851. {
  5852. var groupData = await _taskAssignmentRep.GetTaskAssignmen();
  5853. if (groupData.Code != 0)
  5854. {
  5855. return Ok(JsonView(false, groupData.Msg));
  5856. }
  5857. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  5858. }
  5859. /// <summary>
  5860. /// 团组任务分配查询
  5861. /// </summary>
  5862. /// <param name="dto"></param>
  5863. /// <returns></returns>
  5864. [HttpPost]
  5865. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5866. public async Task<IActionResult> TaskAssignmenQuery(TaskAssignmenQueryDto dto)
  5867. {
  5868. var groupData = await _taskAssignmentRep.TaskAssignmenQuery(dto);
  5869. if (groupData.Code != 0)
  5870. {
  5871. return Ok(JsonView(false, groupData.Msg));
  5872. }
  5873. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  5874. }
  5875. /// <summary>
  5876. /// 团组任务分配操作
  5877. /// </summary>
  5878. /// <param name="dto"></param>
  5879. /// <returns></returns>
  5880. [HttpPost]
  5881. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5882. public async Task<IActionResult> GetTaskAssignmenOp(TaskAssignmenDto dto)
  5883. {
  5884. Result groupData = await _taskAssignmentRep.GetTaskAssignmenOp(dto);
  5885. if (groupData.Code != 0)
  5886. {
  5887. return Ok(JsonView(false, groupData.Msg));
  5888. }
  5889. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  5890. }
  5891. /// <summary>
  5892. /// 团组任务分配
  5893. /// 批量分配
  5894. /// 查询团组
  5895. /// </summary>
  5896. /// <param name="dto"></param>
  5897. /// <returns></returns>
  5898. [HttpPost]
  5899. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5900. public async Task<IActionResult> TaskAllocationGroupSelect(TaskAllocationGroupSelectDto dto)
  5901. {
  5902. //参数验证
  5903. if (dto.PortType < 1 || dto.PortType > 3) return Ok(JsonView(false, MsgTips.Port));
  5904. if (!DateTime.TryParse(dto.VisitBeginDt, out _) || !DateTime.TryParse(dto.VisitEndDt, out _))
  5905. return Ok(JsonView(false, "团组出访开始/结束日期格式不正确!"));
  5906. return Ok(await _taskAssignmentRep.TaskAllocationGroupSelect(dto));
  5907. }
  5908. /// <summary>
  5909. /// 团组任务分配
  5910. /// 批量分配
  5911. /// </summary>
  5912. /// <param name="dto"></param>
  5913. /// <returns></returns>
  5914. [HttpPost]
  5915. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5916. public async Task<IActionResult> TaskAllocationBulkAdd(TaskAllocationBulkAddDto dto)
  5917. {
  5918. //参数验证
  5919. if (dto.UserIds.Length < 1) return Ok(JsonView(false, $"请选择分配人员!"));
  5920. if (dto.PermissionTypeIds.Length < 1) return Ok(JsonView(false, $"请选择分配类型!"));
  5921. if (dto.GroupIds.Length < 1) return Ok(JsonView(false, "请选择分配团组Id"));
  5922. if (dto.CurrUserId < 1) return Ok(JsonView(false, "请传入有效的CurrUserId数组参数"));
  5923. return Ok(await _taskAssignmentRep.TaskAllocationBulkAdd(dto));
  5924. }
  5925. #endregion
  5926. #region 团组费用审核
  5927. /// <summary>
  5928. /// 费用审核
  5929. /// 团组列表 Page
  5930. /// </summary>
  5931. /// <param name="dto">团组列表请求dto</param>
  5932. /// <returns></returns>
  5933. [HttpPost]
  5934. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5935. public async Task<IActionResult> PostExpenseAuditGroupPageItems(ExpenseAuditGroupPageItemsDto dto)
  5936. {
  5937. #region 参数验证
  5938. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  5939. if (dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  5940. #region 页面操作权限验证
  5941. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  5942. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  5943. #endregion
  5944. #endregion
  5945. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) // web/Android/IOS
  5946. {
  5947. string sqlWhere = "WHERE gdi.IsDel = 0";
  5948. var parameters = new List<SugarParameter>();
  5949. // 状态条件(保持不变)
  5950. if (dto.IsSure >= 0)
  5951. {
  5952. sqlWhere += $" AND IsSure = {dto.IsSure}";
  5953. }
  5954. // 搜索条件
  5955. if (!string.IsNullOrEmpty(dto.SearchCriteria))
  5956. {
  5957. // 将搜索词按空格分割为多个关键字(支持多关键字检索)
  5958. var keywords = dto.SearchCriteria.Split(new[] { ' ', ',', ',' }, StringSplitOptions.RemoveEmptyEntries);
  5959. if (keywords.Length > 0)
  5960. {
  5961. var searchConditions = new List<string>();
  5962. foreach (var keyword in keywords)
  5963. {
  5964. if (!string.IsNullOrWhiteSpace(keyword))
  5965. {
  5966. // 对每个关键字构建多字段检索条件
  5967. var keywordConditions = new List<string>
  5968. {
  5969. $"ssd.Name LIKE '%{keyword}%'",
  5970. $"gdi.TeamName LIKE '%{keyword}%'",
  5971. $"gdi.ClientName LIKE '%{keyword}%'",
  5972. $"su.CnName LIKE '%{keyword}%'",
  5973. $"gdi.SalesQuoteNo LIKE '%{keyword}%'",
  5974. $"gdi.TourCode LIKE '%{keyword}%'",
  5975. $"gdi.ClientUnit LIKE '%{keyword}%'",
  5976. $"ssd1.Name LIKE '%{keyword}%'"
  5977. };
  5978. // 将多个字段条件用 OR 连接
  5979. searchConditions.Add($"({string.Join(" OR ", keywordConditions)})");
  5980. }
  5981. }
  5982. // 将多个关键字条件用 AND 连接(实现多关键字AND搜索)
  5983. if (searchConditions.Count > 0)
  5984. {
  5985. sqlWhere += $" AND ({string.Join(" AND ", searchConditions)})";
  5986. }
  5987. }
  5988. }
  5989. // 基础查询sql
  5990. string sql = $@"
  5991. SELECT Row_Number, Id, SalesQuoteNo, TourCode, TeamTypeId, TeamType,
  5992. TeamName, ClientName, ClientUnit, TeamLevId, TeamLev, VisitDate,
  5993. VisitDays, VisitPNumber, JietuanOperator, IsSure, CreateTime
  5994. FROM (
  5995. SELECT ROW_NUMBER() OVER (ORDER BY gdi.VisitDate DESC) AS Row_Number,
  5996. gdi.Id, gdi.SalesQuoteNo, gdi.TourCode,
  5997. ssd1.Id AS TeamLevId, ssd1.Name AS TeamLev,
  5998. gdi.TeamName, gdi.ClientName, gdi.ClientUnit,
  5999. ssd.Id AS TeamTypeId, ssd.Name AS TeamType,
  6000. gdi.VisitDate, gdi.VisitDays, gdi.VisitPNumber,
  6001. su.CnName AS JietuanOperator, gdi.IsSure, gdi.CreateTime
  6002. FROM Grp_DelegationInfo gdi
  6003. LEFT JOIN Sys_SetData ssd ON gdi.TeamDid = ssd.Id
  6004. LEFT JOIN Sys_SetData ssd1 ON gdi.TeamLevSId = ssd1.Id
  6005. LEFT JOIN Sys_Users su ON gdi.JietuanOperator = su.Id
  6006. {sqlWhere}
  6007. ) AS temp";
  6008. RefAsync<int> total = 0;
  6009. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql)
  6010. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  6011. var _view = new
  6012. {
  6013. PageFuncAuth = pageFunAuthView,
  6014. Data = _DelegationList
  6015. };
  6016. return Ok(JsonView(true, "查询成功!", _view, total));
  6017. }
  6018. else
  6019. {
  6020. return Ok(JsonView(false, "查询失败"));
  6021. }
  6022. }
  6023. /// <summary>
  6024. /// 获取团组费用审核
  6025. /// </summary>
  6026. /// <param name="_dto"></param>
  6027. /// <returns></returns>
  6028. [HttpPost]
  6029. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  6030. public async Task<IActionResult> PostSearchGrpCreditCardPayment(Search_GrpCreditCardPaymentDto _dto)
  6031. {
  6032. try
  6033. {
  6034. #region 参数验证
  6035. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  6036. if (_dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  6037. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  6038. #region 页面操作权限验证
  6039. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  6040. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  6041. #endregion
  6042. #endregion
  6043. var _view = new Grp_CreditCardPaymentView();
  6044. var clientNameList = GetSimplClientList(_dto.DiId);
  6045. #region 费用清单
  6046. var exp = Expressionable.Create<Grp_CreditCardPayment>();
  6047. exp.AndIF(_dto.AuditStatus != -1, it => it.IsAuditGM == _dto.AuditStatus);
  6048. exp.AndIF(_dto.Label != -1, it => it.CTable == _dto.Label);
  6049. var entityList = _groupRepository.Query<Grp_CreditCardPayment>(s => s.DIId == _dto.DiId && s.IsDel == 0 && s.CreateUserId > 0).Where(exp.ToExpression()).ToList();
  6050. var detailList = new List<Grp_CreditCardPaymentDetailView>();
  6051. var ccpCurrencyPrices = new List<CreditCardPaymentCurrencyPriceItem>();
  6052. /*
  6053. * 76://酒店预订
  6054. */
  6055. var _HotelReservations = await _groupRepository.Query<Grp_HotelReservations>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6056. var _HotelReservationsContents = await _groupRepository.Query<Grp_HotelReservationsContent>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6057. /*
  6058. * 79://车/导游地接
  6059. */
  6060. var _CarTouristGuideGroundReservations = await _groupRepository.Query<Grp_CarTouristGuideGroundReservations>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6061. var _CarTouristGuideGroundReservationsContent = await _groupRepository.Query<Grp_CarTouristGuideGroundReservationsContent>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6062. /*
  6063. * 80: //签证
  6064. */
  6065. var _VisaInfos = await _groupRepository.Query<Grp_VisaInfo>(s => s.DIId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6066. /*
  6067. *81: //邀请/公务活动
  6068. */
  6069. var _InvitationOfficialActivities = await _groupRepository.Query<Grp_InvitationOfficialActivities>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6070. /*
  6071. * 82: //团组客户保险
  6072. */
  6073. var _Customers = await _groupRepository.Query<Grp_Customers>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6074. /*
  6075. * Lable = 85 机票预订
  6076. */
  6077. var p_AirTicketReservations = await _groupRepository.Query<Grp_AirTicketReservations>(s => s.DIId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6078. /*
  6079. * 85 机票预定
  6080. */
  6081. var _AirTicketReservations = await _groupRepository.Query<Grp_AirTicketReservations>(s => s.DIId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6082. /*
  6083. * 98 其他款项
  6084. */
  6085. var _DecreasePayments = await _groupRepository.Query<Grp_DecreasePayments>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6086. /*
  6087. * 285:收款退还
  6088. */
  6089. var _PaymentRefundAndOtherMoneys = await _groupRepository.Query<Fin_PaymentRefundAndOtherMoney>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6090. /*
  6091. * 1015: //超支费用
  6092. */
  6093. var _GroupExtraCosts = await _groupRepository.Query<Fin_GroupExtraCost>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6094. var initDatas = await _groupRepository.Query<Sys_SetData>(s => s.IsDel == 0).ToListAsync();
  6095. /*
  6096. * 币种信息
  6097. */
  6098. var currencyItems = initDatas.Where(s => s.STid == 66).ToList();
  6099. /*
  6100. * 车/导游地接 费用类型
  6101. */
  6102. var carFeeTypeItems = initDatas.Where(s => s.STid == 17).ToList();
  6103. /*
  6104. * 车/导游地接 费用类型
  6105. */
  6106. var carFeeItems = initDatas.Where(s => s.STid == 83).ToList();
  6107. var cityData = await _groupRepository.Query<Grp_NationalTravelFee>(s => s.IsDel == 0).ToListAsync();
  6108. /*
  6109. * 用户信息
  6110. */
  6111. var userItems = await _groupRepository._sqlSugar.Queryable<Sys_Users>().ToListAsync();
  6112. /*
  6113. * 费用模块
  6114. */
  6115. var sdPriceName = initDatas.Where(s => s.Id == _dto.Label).First();
  6116. string priceModule = string.Empty;
  6117. if (sdPriceName != null)
  6118. {
  6119. priceModule = sdPriceName.Name;
  6120. }
  6121. /*
  6122. * 成本信息
  6123. */
  6124. var groupCost = _groupRepository.Query<Grp_GroupCostParameter>(s => s.DiId == _dto.DiId && s.IsDel == 0).First();
  6125. decimal _groupRate = 0.0000M;
  6126. string _groupCurrencyCode = "-";
  6127. if (groupCost != null)
  6128. {
  6129. _groupRate = groupCost.Rate;
  6130. if (int.TryParse(groupCost.Currency, out int _currency))
  6131. {
  6132. _groupCurrencyCode = currencyItems.Find(it => it.Id == _currency)?.Name ?? "-";
  6133. }
  6134. else _groupCurrencyCode = groupCost.Currency;
  6135. }
  6136. string costContentSql = $"Select * From Grp_GroupCost";
  6137. var groupCostDetails = _sqlSugar.SqlQueryable<GroupCostAuditView>(costContentSql).Where(x => x.IsDel == 0 && x.Diid == _dto.DiId).ToList();
  6138. //处理日期为空的天数
  6139. for (int i = 0; i < groupCostDetails.Count; i++)
  6140. if (i != 0)
  6141. if (string.IsNullOrEmpty(groupCostDetails[i].Date))
  6142. groupCostDetails[i].Date = groupCostDetails[i - 1].Date;
  6143. /*
  6144. * 处理详情数据
  6145. */
  6146. foreach (var entity in entityList)
  6147. {
  6148. var _detail = new Grp_CreditCardPaymentDetailView
  6149. {
  6150. Id = entity.Id,
  6151. PriceName = priceModule,
  6152. PayType = initDatas.Find(it => it.Id == entity.PayDId)?.Name ?? "-"
  6153. };
  6154. if (_detail.PayType.Equals("现金")) _detail.CardType = "-";
  6155. else _detail.CardType = initDatas.Find(it => it.Id == entity.CTDId)?.Name ?? "-";
  6156. //处理金额
  6157. if (entity.CTable == 1015)
  6158. {
  6159. var czInfo = _GroupExtraCosts.Find(x => entity.CId == x.Id);
  6160. if (czInfo != null)
  6161. {
  6162. entity.PayMoney = czInfo.Price * czInfo.PriceCount;
  6163. entity.RMBPrice = czInfo.Price * czInfo.PriceCount * entity.DayRate;
  6164. }
  6165. }
  6166. /*
  6167. * 应付款金额
  6168. */
  6169. var sdPaymentCurrency_WaitPay = currencyItems.Where(s => s.Id == entity.PaymentCurrency).FirstOrDefault();
  6170. string PaymentCurrency_WaitPay = "Unknown";
  6171. string hotelCurrncyCode = "Unknown";
  6172. string hotelCurrncyName = "Unknown";
  6173. if (sdPaymentCurrency_WaitPay != null)
  6174. {
  6175. PaymentCurrency_WaitPay = sdPaymentCurrency_WaitPay.Name;
  6176. hotelCurrncyCode = sdPaymentCurrency_WaitPay.Name;
  6177. hotelCurrncyName = sdPaymentCurrency_WaitPay.Remark;
  6178. if (hotelCurrncyCode.Equals("CNY"))
  6179. {
  6180. entity.DayRate = 1.0000M;
  6181. }
  6182. }
  6183. _detail.WaitPay = entity.PayMoney.ConvertToDecimal1().ToString("#0.00") + " " + PaymentCurrency_WaitPay;
  6184. /*
  6185. * 此次付款金额
  6186. */
  6187. decimal CurrPayStr = 0.00M,
  6188. OriginalCurrPay = 0.00M;
  6189. if (entity.PayPercentage == 0)
  6190. {
  6191. if (entity.PayThenMoney != 0)
  6192. CurrPayStr = (entity.PayThenMoney * entity.DayRate).ConvertToDecimal1();
  6193. }
  6194. else
  6195. {
  6196. if (entity.PayMoney != 0)
  6197. {
  6198. CurrPayStr = (entity.PayMoney * entity.PayPercentage / 100 * entity.DayRate).ConvertToDecimal1();
  6199. }
  6200. }
  6201. //if (_dto.Label == 79)
  6202. //{
  6203. // string original = string.Empty;
  6204. // if (hotelCurrncyCode.Equals("CNY"))
  6205. // {
  6206. // OriginalCurrPay = CurrPayStr;
  6207. // _detail.CurrPay = CurrPayStr.ToString("#0.00") + " CNY";
  6208. // }
  6209. // else
  6210. // {
  6211. // OriginalCurrPay = ((entity.PayMoney / 100) * entity.PayPercentage).ConvertToDecimal1();
  6212. // //760 EUR(7600.00 CNY)
  6213. // _detail.CurrPay = $"{OriginalCurrPay.ToString("#0.00")} {hotelCurrncyCode}({CurrPayStr.ToString("#0.00")} CNY)";
  6214. // }
  6215. //}
  6216. //else _detail.CurrPay = CurrPayStr.ToString("#0.00") + " CNY";
  6217. string original = string.Empty;
  6218. if (hotelCurrncyCode.Equals("CNY"))
  6219. {
  6220. OriginalCurrPay = CurrPayStr;
  6221. _detail.CurrPay = CurrPayStr.ToString("#0.00") + " CNY";
  6222. }
  6223. else
  6224. {
  6225. OriginalCurrPay = ((entity.PayMoney / 100) * entity.PayPercentage).ConvertToDecimal1();
  6226. //760 EUR(7600.00 CNY)
  6227. _detail.CurrPay = $"{OriginalCurrPay:#0.00} {hotelCurrncyCode}({CurrPayStr:#0.00} CNY)";
  6228. }
  6229. /*
  6230. * 剩余尾款
  6231. */
  6232. decimal BalanceStr = 0;
  6233. if (CurrPayStr != 0)
  6234. {
  6235. if (entity.PayMoney - (CurrPayStr / entity.DayRate) < 0.01M)
  6236. BalanceStr = 0;
  6237. else
  6238. BalanceStr = (entity.PayMoney - CurrPayStr / entity.DayRate).ConvertToDecimal1();
  6239. }
  6240. _detail.Balance = BalanceStr.ToString("#0.00") + " " + PaymentCurrency_WaitPay;
  6241. /*
  6242. * Bus名称
  6243. */
  6244. _detail.BusName = "待增加";
  6245. /*
  6246. *费用所属
  6247. */
  6248. switch (entity.CTable)
  6249. {
  6250. case 76://酒店预订
  6251. Grp_HotelReservations hotelReservations = _HotelReservations.Where(s => s.Id == entity.CId).FirstOrDefault();
  6252. if (hotelReservations != null)
  6253. {
  6254. DateTime checkIn = Convert.ToDateTime(hotelReservations.CheckInDate),
  6255. checkOut = Convert.ToDateTime(hotelReservations.CheckOutDate);
  6256. int hotel_days = (int)(checkOut - checkIn).TotalDays;
  6257. string roomFeeStr = "", roomFeestr1 = "";
  6258. //是否比较房型价格
  6259. //bool __isSingle = false, __isDouble = false, __isSuite = false, __isOther = false;
  6260. //roomFeeStr += $"<br/><span style='width:70px;display: inline-block;'></span>";
  6261. roomFeeStr += $"<br/>";
  6262. var roomTotal = 0.00M;
  6263. if (hotelReservations.SingleRoomPrice > 0)
  6264. {
  6265. var fee = hotelReservations.SingleRoomPrice * hotelReservations.SingleRoomCount * hotel_days;
  6266. roomFeestr1 += $"<span style='width:70px;display: inline-block;'></span>单间:{hotelReservations.SingleRoomPrice:#0.00} * {hotelReservations.SingleRoomCount}间 * {hotel_days}晚 = {fee:#0.00}<br/>";
  6267. //__isSingle = true;
  6268. roomTotal += fee;
  6269. }
  6270. if (hotelReservations.DoubleRoomPrice > 0)
  6271. {
  6272. var fee = hotelReservations.DoubleRoomPrice * hotelReservations.DoubleRoomCount * hotel_days;
  6273. roomFeestr1 += $"<span style='width:70px;display: inline-block;'></span>双人间:{hotelReservations.DoubleRoomPrice:#0.00} * {hotelReservations.DoubleRoomCount}间 * {hotel_days}晚 = {fee:#0.00}<br/>";
  6274. // __isDouble = true;
  6275. roomTotal += fee;
  6276. }
  6277. if (hotelReservations.SuiteRoomPrice > 0)
  6278. {
  6279. var fee = hotelReservations.SuiteRoomPrice * hotelReservations.SuiteRoomCount * hotel_days;
  6280. roomFeestr1 += $"<span style='width:70px;display: inline-block;'></span>套房:{hotelReservations.SuiteRoomPrice:#0.00} * {hotelReservations.SuiteRoomCount}间 * {hotel_days}晚 = {fee:#0.00}<br/>";
  6281. //__isSuite = true;
  6282. roomTotal += fee;
  6283. }
  6284. if (hotelReservations.OtherRoomPrice > 0)
  6285. {
  6286. var fee = hotelReservations.OtherRoomPrice * hotelReservations.OtherRoomCount * hotel_days;
  6287. roomFeestr1 += $"<span style='width:70px;display: inline-block;'></span>其他:{hotelReservations.OtherRoomPrice:#0.00} * {hotelReservations.OtherRoomCount}间 * {hotel_days}晚 = {fee:#0.00}<br/>";
  6288. //__isOther = true;
  6289. roomTotal += fee;
  6290. }
  6291. if (roomFeestr1.Length > 0) roomFeeStr += roomFeestr1 + $"<span style='width:70px;display: inline-block;'></span>房费总金额:{roomTotal:#0.00}";
  6292. else roomFeeStr += " 0.00 * 0";
  6293. decimal governmentRentFee = 0.00M, cityTaxFee = 0.00M, breakfastFee = 0.00M, roomFee = 0.00M;
  6294. string governmentRentBool = "否", cityTaxBool = "否", breakfastBool = "否", roomBool = "否";
  6295. string governmentRentCode = "", governmentRentName = "", cityTaxCode = "", cityTaxName = "", breakfastCode = "", breakfastName = "", roomCode = "", roomName = "";
  6296. var _HotelReservationsContents1 = _HotelReservationsContents.Where(it => it.HrId == hotelReservations.Id).ToList();
  6297. /*
  6298. * 费用类型
  6299. * 1:房费
  6300. * 2:早餐
  6301. * 3:地税
  6302. * 4:城市税
  6303. * </summary>
  6304. */
  6305. //地税
  6306. var governmentRentData = _HotelReservationsContents1.Find(it => it.PriceType == 3);
  6307. if (governmentRentData != null)
  6308. {
  6309. governmentRentBool = governmentRentData.IsOppay == 1 ? "是" : "否";
  6310. governmentRentFee = governmentRentData.Price;
  6311. var governmentRentCurrData = currencyItems.Find(s => s.Id == governmentRentData.Currency);
  6312. if (governmentRentCurrData != null)
  6313. {
  6314. governmentRentCode = governmentRentCurrData.Name;
  6315. governmentRentName = $"({governmentRentCurrData.Remark})";
  6316. }
  6317. }
  6318. //城市税
  6319. var cityTaxData = _HotelReservationsContents1.Find(it => it.PriceType == 4);
  6320. if (cityTaxData != null)
  6321. {
  6322. cityTaxBool = cityTaxData.IsOppay == 1 ? "是" : "否";
  6323. cityTaxFee = cityTaxData.Price;
  6324. var cityTaxCurrData = currencyItems.Find(s => s.Id == cityTaxData.Currency);
  6325. if (cityTaxCurrData != null)
  6326. {
  6327. cityTaxCode = cityTaxCurrData.Name;
  6328. cityTaxName = $"({cityTaxCurrData.Remark})";
  6329. }
  6330. }
  6331. //酒店早餐
  6332. var breakfastData = _HotelReservationsContents1.Find(it => it.PriceType == 2);
  6333. if (breakfastData != null)
  6334. {
  6335. breakfastBool = breakfastData.IsOppay == 1 ? "是" : "否";
  6336. breakfastFee = breakfastData.Price;
  6337. var breakfastCurrData = currencyItems.Find(s => s.Id == breakfastData.Currency);
  6338. if (breakfastCurrData != null)
  6339. {
  6340. breakfastCode = breakfastCurrData.Name;
  6341. breakfastName = $"({breakfastCurrData.Remark})";
  6342. }
  6343. }
  6344. //房间费用
  6345. var roomData = _HotelReservationsContents1.Find(it => it.PriceType == 1);
  6346. if (roomData != null)
  6347. {
  6348. _detail.PayType = initDatas.Find(it => it.Id == roomData.PayDId)?.Name ?? "-";
  6349. if (_detail.PayType.Equals("现金")) _detail.CardType = "-";
  6350. else _detail.CardType = initDatas.Find(it => it.Id == roomData.CTDId)?.Name ?? "-";
  6351. roomBool = roomData.IsOppay == 1 ? "是" : "否";
  6352. roomFee = roomData.Price;
  6353. var roomCurrData = currencyItems.Find(s => s.Id == roomData.Currency);
  6354. if (roomCurrData != null)
  6355. {
  6356. roomCode = roomCurrData.Name;
  6357. roomName = $"({roomCurrData.Remark})";
  6358. }
  6359. }
  6360. string hotelCostTitalStr = "<span style='font-weight:800;'>成本信息</span><br/>";
  6361. string hotelCostStr = "";
  6362. decimal hotelCsotTotal = 0.00M;
  6363. if (groupCost != null)
  6364. {
  6365. if (int.TryParse(groupCost.Currency, out int currencyId)) groupCost.Currency = currencyItems.Find(s => s.Id == currencyId)?.Name ?? "-";
  6366. hotelCostStr += $"{groupCost.Currency}(汇率:{groupCost.Rate:#0.0000})<br/>";
  6367. }
  6368. if (checkOut > checkIn) checkOut = checkOut.AddDays(-1);
  6369. var hotelCostDetails = groupCostDetails.Where(x => Convert.ToDateTime(x.Date) >= checkIn && Convert.ToDateTime(x.Date) <= checkOut).ToList();
  6370. string hotelCost_day = "";
  6371. var hotelCostDetails1 = hotelCostDetails.GroupBy(x => x.Date);
  6372. foreach (var item in hotelCostDetails1)
  6373. {
  6374. hotelCsotTotal += item.Sum(x => x.HotelSingleRoomFee) + item.Sum(x => x.HotelDoubleRoomFee) + item.Sum(x => x.HotelSuiteRoomFee) + item.Sum(x => x.HotelSuiteFee);
  6375. hotelCost_day += @$"{item.First()?.Date ?? "-"}";
  6376. if (item.Sum(x => x.HotelSingleRoomFee) != 0) hotelCost_day += @$" 单间:{item.Sum(x => x.HotelSingleRoomFee):#0.00}";
  6377. //else { if (__isSingle) hotelCost_day += @$" 单间:0.00"; }
  6378. if (item.Sum(x => x.HotelDoubleRoomFee) != 0) hotelCost_day += @$" 双人间:{item.Sum(x => x.HotelDoubleRoomFee):#0.00}";
  6379. //else { if (__isDouble) hotelCost_day += @$" 双人间:0.00"; }
  6380. if (item.Sum(x => x.HotelSuiteRoomFee) != 0) hotelCost_day += @$" 小套房/豪华套房:{item.Sum(x => x.HotelSuiteRoomFee):#0.00}";
  6381. //else { if (__isSuite) hotelCost_day += @$" 小套房/豪华套房:0.00"; }
  6382. if (item.Sum(x => x.HotelSuiteFee) != 0) hotelCost_day += @$" 套房:{item.Sum(x => x.HotelSuiteFee):#0.00}";
  6383. //else { if (__isOther) hotelCost_day += @$" 套房:0.00"; }
  6384. hotelCost_day += @$"<br/>";
  6385. }
  6386. string hotelBreakfastStr = "", hotelGovernmentRentStr = "", hotelCityTaxStr = "";
  6387. if (breakfastFee > 0) hotelBreakfastStr = $"酒店早餐: {breakfastFee:#0.00} {breakfastCode} {breakfastName} 当时汇率 {breakfastData?.Rate:#0.0000} <br/>是否由地接或其他人代付:{breakfastBool}<br/><br/>";
  6388. if (governmentRentFee > 0) hotelGovernmentRentStr = $"地税: {governmentRentFee:#0.00} {governmentRentCode} {governmentRentName} 当时汇率 {governmentRentData?.Rate:#0.0000} <br/>是否由地接或其他人代付:{governmentRentBool}<br/><br/>";
  6389. if (cityTaxFee > 0) hotelCityTaxStr = $"城市税: {cityTaxFee:#0.00} {cityTaxCode} {cityTaxName} 当时汇率 {cityTaxData?.Rate:#0.0000)} <br/>是否由地接或其他人代付:{cityTaxBool}<br/>";
  6390. string hotelCostTotalStr = "";// $"&nbsp;&nbsp;成本合计:{hotelCsotTotal.ToString("#0.00")}<br/>";
  6391. _detail.PriceMsgContent = $"{hotelCostTitalStr}{hotelCostStr}{hotelCostTotalStr}{hotelCost_day}<br/>" +
  6392. $"<span style='font-weight:800;'>{hotelReservations.HotelName} [{hotelReservations.CheckInDate} - {hotelReservations.CheckOutDate}]</span><br/>" +
  6393. $"酒店费用总额:{_detail.WaitPay} ({hotelCurrncyName})<br/>" +
  6394. $"房间说明: {hotelReservations.Remark} <br/>" +
  6395. $"房间费用: {roomCode} {roomName} 当时汇率:{roomData?.Rate.ToString("#0.0000")}{roomFeeStr} <br/>是否由地接或其他人代付:{roomBool}<br/><br/>" +
  6396. $"{hotelBreakfastStr}" +
  6397. $"{hotelGovernmentRentStr}" +
  6398. $"{hotelCityTaxStr}";
  6399. _detail.PriceNameContent = hotelReservations.HotelName;
  6400. }
  6401. break;
  6402. case 79://车/导游地接
  6403. Grp_CarTouristGuideGroundReservations touristGuideGroundReservations = _CarTouristGuideGroundReservations.Where(s => s.Id == entity.CId).FirstOrDefault();
  6404. if (touristGuideGroundReservations != null)
  6405. {
  6406. if (!string.IsNullOrEmpty(touristGuideGroundReservations.BusName))
  6407. {
  6408. _detail.BusName = touristGuideGroundReservations.BusName;
  6409. }
  6410. _detail.PriceNameContent = touristGuideGroundReservations.PriceName;
  6411. //bool isInt = int.TryParse(touristGuideGroundReservations.Area, out int cityId);
  6412. //if (isInt)
  6413. //{
  6414. // var cityInfo = cityData.Find(it => it.Id == cityId);
  6415. // if (cityInfo != null)
  6416. // {
  6417. // string nameContent = $@"{cityInfo.Country}-{cityInfo.City}";
  6418. // var carFeeItem = carFeeItems.Find(it => it.Id == touristGuideGroundReservations.PriceType);
  6419. // if (carFeeItem != null)
  6420. // {
  6421. // nameContent += $@"({carFeeItem.Name})";
  6422. // }
  6423. // _detail.PriceNameContent = nameContent;
  6424. // }
  6425. //}
  6426. //else
  6427. //{
  6428. // _detail.PriceNameContent = touristGuideGroundReservations.Area;
  6429. //}
  6430. var touristGuideGroundReservationsContents =
  6431. _CarTouristGuideGroundReservationsContent.Where(s => s.CTGGRId == touristGuideGroundReservations.Id && s.IsDel == 0 && s.Price != 0).ToList();
  6432. var opContent_sb = new StringBuilder();
  6433. string contetTitle = $"<span style='font-weight:800;'>{touristGuideGroundReservations.PriceName}({touristGuideGroundReservations.ServiceStartTime} - {touristGuideGroundReservations.ServiceEndTime})</span><br/>";
  6434. opContent_sb.AppendLine(contetTitle);
  6435. foreach (var item in touristGuideGroundReservationsContents)
  6436. {
  6437. string typeName = "Unknown";
  6438. string carCurrencyCode = "Unknown";
  6439. string carCurrencyName = "Unknown";
  6440. var carTypeData = carFeeTypeItems.Where(s => s.Id == item.SId && s.IsDel == 0).FirstOrDefault();
  6441. if (carTypeData != null) typeName = carTypeData.Name;
  6442. var currencyData = currencyItems.Where(s => s.Id == item.Currency && s.IsDel == 0).FirstOrDefault();
  6443. if (currencyData != null)
  6444. {
  6445. carCurrencyCode = currencyData.Name;
  6446. carCurrencyName = currencyData.Remark;
  6447. }
  6448. //op、成本 币种是否一致 (币种一致只比较金额:2025-04-18)
  6449. bool IsCurrencyAgreement = false;
  6450. if (carCurrencyCode.Equals(_groupCurrencyCode)) IsCurrencyAgreement = true;
  6451. string opCostStr = string.Empty;
  6452. decimal opCostTypePrice = 0.00M;
  6453. #region 处理成本各项费用
  6454. var opDate = item.DatePrice?.ToString("yyyy-MM-dd");
  6455. var opCost = groupCostDetails.Where(x => x.Date.Equals(opDate)).ToList();
  6456. decimal aduitOPFeeCNY = 0.00M, //费用审核 op费用
  6457. costOPFeeCNY = 0.00M, //团组成本 op费用
  6458. opPayPercentage = entity.PayPercentage == 0.00M ? 1.00M : entity.PayPercentage / 100M; //费用审核 op付款百分比
  6459. if (opCost.Count > 0)
  6460. {
  6461. switch (item.SId)
  6462. {
  6463. case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //91车费
  6464. //case 982: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //982 车超时费 -- 暂无
  6465. case 92: opCostTypePrice = opCost.Sum(x => x.GuideFee); break; //92 导游费
  6466. case 94: opCostTypePrice = opCost.Sum(x => x.GuideScenicFee); break; //94 导游景点费
  6467. case 95: opCostTypePrice = opCost.Sum(x => x.GuideTipFee); break; //95 导游小费
  6468. case 983: opCostTypePrice = opCost.Sum(x => x.GuideMealFee); break; //983 导游餐补
  6469. case 984: opCostTypePrice = opCost.Sum(x => x.GuideMealFee); break; //984 导游房补
  6470. case 985: opCostTypePrice = opCost.Sum(x => x.GuideRoomFee); break; //985 导游交通
  6471. //case 96: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //96 接送机费 -- 暂无
  6472. //case 97: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //97 其他费用 -- 暂无
  6473. case 979: opCostTypePrice = opCost.Sum(x => x.DriverFee); break; //979 司机工资
  6474. case 980: opCostTypePrice = opCost.Sum(x => x.DriverTipFee); break; //980 司机小费
  6475. case 981: opCostTypePrice = opCost.Sum(x => x.DriverMealFee); break; //981 司机餐补
  6476. case 988: opCostTypePrice = opCost.Sum(x => x.ClientBreakfastFee); break; //988 客户早餐费用
  6477. case 93: opCostTypePrice = opCost.Sum(x => x.ClientDinnerFee); break; //93 客户午餐费用
  6478. case 989: opCostTypePrice = opCost.Sum(x => x.ClientLunchFee); break; //989 客户晚餐费用
  6479. case 990: opCostTypePrice = opCost.Sum(x => x.ScenicTicketFee); break; //990 景点门票费
  6480. case 991: opCostTypePrice = opCost.Sum(x => x.DrinkSnackFruitFee); break; //991 饮料/零食/水果
  6481. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //992 住补费用 -- 暂无
  6482. case 994: opCostTypePrice = opCost.Sum(x => x.TranslatorFee); break; //994 翻译费
  6483. case 1059: opCostTypePrice = opCost.Sum(x => x.GuideOverTimeFee); break; //1059 导游超时费用
  6484. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1070 尾款金额
  6485. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1071 其他额外费用
  6486. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1073 翻译超时费
  6487. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1074 早餐超支费用
  6488. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1075 午餐超支费用
  6489. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1076 晚餐超支费用
  6490. }
  6491. opCostStr = $"&nbsp;&nbsp;/&nbsp;&nbsp;成本:{opCostTypePrice:#0.00} {_groupCurrencyCode}(汇率:{_groupRate:#0.0000})";
  6492. costOPFeeCNY = opCostTypePrice * _groupRate;
  6493. if (!IsCurrencyAgreement) opCostStr += $" ≈ {costOPFeeCNY:#0.00} CNY";
  6494. }
  6495. #endregion
  6496. string opTypeStr = $"{typeName}:{item.Price:#0.00} {carCurrencyCode}(汇率:{entity.DayRate:#0.0000})";
  6497. aduitOPFeeCNY = item.Price * entity.DayRate;
  6498. if (!IsCurrencyAgreement) opTypeStr += $" ≈ {aduitOPFeeCNY:#0.0000} CNY";
  6499. var opContent = $"日期:{item.DatePrice?.ToString("yyyy-MM-dd") ?? "-"}<br/>" +
  6500. $"{opTypeStr} {opCostStr}<br/>" +
  6501. $"明细:{item.PriceContent ?? "-"}<br/>" +
  6502. $"备注:{item.Remark ?? "-"}<br/><br/>";
  6503. if (entity.IsAuditGM != 3) //状态 != 自动审核
  6504. {
  6505. if (IsCurrencyAgreement)
  6506. {
  6507. if (item.Price > opCostTypePrice)
  6508. {
  6509. opContent_sb.Append("<span style='color:red;'>");
  6510. opContent_sb.Append(opContent);
  6511. opContent_sb.Append("</span>");
  6512. opContent_sb.AppendLine();
  6513. }
  6514. else
  6515. {
  6516. opContent_sb.Append(opContent);
  6517. opContent_sb.AppendLine();
  6518. }
  6519. }
  6520. else
  6521. {
  6522. //验证是否超成本 按付款比例计算
  6523. if (aduitOPFeeCNY * opPayPercentage > costOPFeeCNY * opPayPercentage)
  6524. {
  6525. opContent_sb.Append("<span style='color:red;'>");
  6526. opContent_sb.Append(opContent);
  6527. opContent_sb.Append("</span>");
  6528. opContent_sb.AppendLine();
  6529. }
  6530. else
  6531. {
  6532. opContent_sb.Append(opContent);
  6533. opContent_sb.AppendLine();
  6534. }
  6535. }
  6536. }
  6537. else
  6538. {
  6539. opContent_sb.Append(opContent);
  6540. opContent_sb.AppendLine();
  6541. }
  6542. }
  6543. _detail.PriceMsgContent = opContent_sb.ToString();
  6544. }
  6545. break;
  6546. case 80: //签证
  6547. Grp_VisaInfo visaInfo = _VisaInfos.Where(s => s.Id == entity.CId).FirstOrDefault();
  6548. if (visaInfo != null)
  6549. {
  6550. string visaName = GetClientNameStr1(clientNameList, visaInfo.VisaClient);
  6551. _detail.PriceNameContent = visaInfo.VisaDescription;
  6552. _detail.PriceMsgContent = $"签证描述:{visaName}<br/> 备注:{visaInfo.Remark}";
  6553. }
  6554. break;
  6555. case 81: //邀请/公务活动
  6556. Grp_InvitationOfficialActivities _ioa = _InvitationOfficialActivities.Where(s => s.Id == entity.CId).FirstOrDefault();
  6557. if (_ioa != null)
  6558. {
  6559. string inviteCurrName = "Unknown", //邀请费用币种 Name
  6560. inviteCurrCode = "Unknown", //邀请费用币种 Code
  6561. sendCurrName = "Unknown", //快递费用币种 Name
  6562. sendCurrCode = "Unknown", //快递费用币种 Code
  6563. eventsCurrName = "Unknown", //公务活动费币种 Name
  6564. eventsCurrCode = "Unknown", //公务活动费币种 Code
  6565. translateCurrName = "Unknown", //公务翻译费 Name
  6566. translateCurrCode = "Unknown"; //公务翻译费 Code
  6567. #region 处理费用币种
  6568. var inviteCurrData = currencyItems.Where(s => s.Id == _ioa.InviteCurrency && s.IsDel == 0).FirstOrDefault();
  6569. if (inviteCurrData != null)
  6570. {
  6571. inviteCurrName = inviteCurrData.Remark;
  6572. inviteCurrCode = inviteCurrData.Name;
  6573. }
  6574. var sendCurrData = currencyItems.Where(s => s.Id == _ioa.SendCurrency && s.IsDel == 0).FirstOrDefault();
  6575. if (sendCurrData != null)
  6576. {
  6577. sendCurrName = sendCurrData.Remark;
  6578. sendCurrCode = sendCurrData.Name;
  6579. }
  6580. var eventsCurrData = currencyItems.Where(s => s.Id == _ioa.EventsCurrency && s.IsDel == 0).FirstOrDefault();
  6581. if (eventsCurrData != null)
  6582. {
  6583. eventsCurrName = eventsCurrData.Remark;
  6584. eventsCurrCode = eventsCurrData.Name;
  6585. }
  6586. var translateCurrData = currencyItems.Where(s => s.Id == _ioa.TranslateCurrency && s.IsDel == 0).FirstOrDefault();
  6587. if (translateCurrData != null)
  6588. {
  6589. translateCurrName = translateCurrData.Remark;
  6590. translateCurrCode = translateCurrData.Name;
  6591. }
  6592. #endregion
  6593. _detail.PriceNameContent = _ioa.InviterArea;
  6594. //2025-09-08 商邀费用名称更改:单项费用不等于0,则在名称后面最加费用类型名称。
  6595. List<string> priceExpNames = new List<string>();
  6596. if (_ioa.InviteCost != 0.00M) priceExpNames.Add("邀请费");
  6597. if (_ioa.SendCost != 0.00M) priceExpNames.Add("快递费");
  6598. if (_ioa.EventsCost != 0.00M) priceExpNames.Add("公务活动费");
  6599. if (_ioa.TranslateCost != 0.00M) priceExpNames.Add("公务翻译费");
  6600. if (priceExpNames != null && priceExpNames.Count > 0)
  6601. {
  6602. _detail.PriceNameContent += $"({string.Join("+", priceExpNames)})";
  6603. }
  6604. _detail.PriceMsgContent = $@"邀请费用:{_ioa.InviteCost:#0.00} {inviteCurrCode}({inviteCurrName})<br/>" +
  6605. $@"快递费用:{_ioa.SendCost:#0.00} {sendCurrCode}({sendCurrName})<br/>" +
  6606. $@"公务活动费:{_ioa.EventsCost:#0.00} {eventsCurrCode}({eventsCurrName})<br/>" +
  6607. $@"公务翻译费:{_ioa.TranslateCost:#0.00} {translateCurrCode}({translateCurrName})<br/>" +
  6608. $@"备注:" + _ioa.Remark + "<br/>";
  6609. }
  6610. break;
  6611. case 82: //团组客户保险
  6612. Grp_Customers customers = _Customers.Where(s => s.Id == entity.CId && s.IsDel == 0).FirstOrDefault();
  6613. if (customers != null)
  6614. {
  6615. _detail.PriceNameContent = GetClientNameStr(clientNameList, customers.ClientName);
  6616. _detail.PriceMsgContent = "备注:" + customers.Remark + "<br/>";
  6617. }
  6618. break;
  6619. case 85: //机票预订
  6620. Grp_AirTicketReservations jpRes = _AirTicketReservations.Where(s => s.Id == entity.CId).FirstOrDefault();
  6621. if (jpRes != null)
  6622. {
  6623. string FlightsDescription = jpRes.FlightsDescription;
  6624. string PriceDescription = jpRes.PriceDescription;
  6625. _detail.PriceMsgContent = "航班号:" + jpRes.FlightsCode + "<br/>城市A-B:" + jpRes.FlightsCity + "<br/>航班描述:" + FlightsDescription.Replace("\r\n", "<br />") + "<br/>" + "价格描述:" + PriceDescription;
  6626. _detail.PriceNameContent = "(" + jpRes.FlightsCode + ")";
  6627. }
  6628. break;
  6629. case 98://其他款项
  6630. Grp_DecreasePayments gdpRes = _DecreasePayments.Where(s => s.Id == entity.CId).FirstOrDefault();
  6631. if (gdpRes != null)
  6632. {
  6633. //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/";
  6634. //if (!string.IsNullOrEmpty(gdpRes.FilePath))
  6635. //{
  6636. // _detail.FileUrl = $"{urlBase}{gdpRes.FilePath}";
  6637. //}
  6638. _detail.PriceMsgContent = "备注:" + gdpRes.Remark;
  6639. _detail.PriceNameContent = gdpRes.PriceName;
  6640. }
  6641. break;
  6642. case 285://收款退还
  6643. Fin_PaymentRefundAndOtherMoney refundAndOtherMoney = _PaymentRefundAndOtherMoneys.Where(s => s.Id == entity.CId).FirstOrDefault();
  6644. if (refundAndOtherMoney != null)
  6645. {
  6646. _detail.PriceMsgContent = "备注:" + refundAndOtherMoney.Remark;
  6647. _detail.PriceNameContent = refundAndOtherMoney.PriceName;
  6648. }
  6649. break;
  6650. case 751://酒店早餐
  6651. break;
  6652. case 1015://超支费用
  6653. Fin_GroupExtraCost groupExtraCost = _GroupExtraCosts.Where(s => s.Id == entity.CId).FirstOrDefault();
  6654. if (groupExtraCost != null)
  6655. {
  6656. _detail.PriceNameContent = groupExtraCost.PriceName;
  6657. _detail.PriceMsgContent = "备注:" + groupExtraCost.Remark;
  6658. }
  6659. break;
  6660. default:
  6661. break;
  6662. }
  6663. /*
  6664. * 申请人
  6665. */
  6666. string operatorName = " - ";
  6667. var _opUser = userItems.Where(s => s.Id == entity.CreateUserId).FirstOrDefault();
  6668. if (_opUser != null)
  6669. {
  6670. operatorName = _opUser.CnName;
  6671. }
  6672. _detail.OperatorName = operatorName;
  6673. /*
  6674. * 审核人
  6675. */
  6676. string auditOperatorName = " - ";
  6677. if (entity.IsAuditGM != 0)
  6678. {
  6679. if (entity.AuditGMOperate == 0) auditOperatorName = " - ";
  6680. else if (entity.AuditGMOperate == 4) auditOperatorName = "自动审核";
  6681. else
  6682. {
  6683. var _adUser = userItems.Where(s => s.Id == entity.AuditGMOperate).FirstOrDefault();
  6684. if (_adUser != null)
  6685. {
  6686. auditOperatorName = _adUser.CnName;
  6687. }
  6688. }
  6689. }
  6690. _detail.AuditOperatorName = auditOperatorName;
  6691. /*
  6692. * 超预算比例
  6693. */
  6694. string overBudgetStr = "";
  6695. if (entity.ExceedBudget == -1) overBudgetStr = sdPriceName.Name + "尚无预算";
  6696. else if (entity.ExceedBudget == 0)
  6697. {
  6698. if (entity.CTable == 76 || entity.CTable == 79)
  6699. {
  6700. if (entity.IsAuditGM == 3) overBudgetStr = "未超预算";
  6701. else overBudgetStr = _feeAuditRep.IsOverBudget(entity.CTable, entity.DIId, entity.CId);
  6702. }
  6703. else
  6704. {
  6705. overBudgetStr = "未超预算";
  6706. }
  6707. }
  6708. else overBudgetStr = entity.ExceedBudget.ToString("P");
  6709. _detail.OverBudget = overBudgetStr;
  6710. decimal auditFee = 0.00M; //已审核金额 人名币
  6711. decimal auditedFeeOriginal = 0.00M; ////已审核金额 原始
  6712. decimal unAuditFeeCNY = 0.00M; //未审核款项 原始
  6713. decimal unAuditFeeOriginal = 0.00M; //未审核款项 人名币
  6714. if (entity.IsAuditGM == 1 || entity.IsAuditGM == 3)
  6715. {
  6716. auditedFeeOriginal = entity.PayMoney;
  6717. auditFee = CurrPayStr;
  6718. }
  6719. else if (entity.IsAuditGM == 0)
  6720. {
  6721. unAuditFeeCNY = CurrPayStr;
  6722. unAuditFeeOriginal = OriginalCurrPay;
  6723. OriginalCurrPay = 0.00M;
  6724. }
  6725. /*
  6726. * 费用总计
  6727. */
  6728. ccpCurrencyPrices.Add(new CreditCardPaymentCurrencyPriceItem()
  6729. {
  6730. CurrencyId = entity.PaymentCurrency,
  6731. CurrencyName = PaymentCurrency_WaitPay,
  6732. AmountPayable = entity.PayMoney,
  6733. ThisPayment = OriginalCurrPay,
  6734. BalancePayment = BalanceStr,
  6735. AuditedFunds = auditFee,
  6736. AuditedFundsOriginal = auditedFeeOriginal,
  6737. UnAuditFundsCNY = unAuditFeeCNY,
  6738. UnAuditFundsOriginal = unAuditFeeOriginal
  6739. });
  6740. _detail.IsAuditGM = entity.IsAuditGM;
  6741. detailList.Add(_detail);
  6742. }
  6743. #endregion
  6744. _view.DetailList = new List<Grp_CreditCardPaymentDetailView>(detailList);
  6745. /*
  6746. * 下方描述处理
  6747. */
  6748. var nonDuplicat = ccpCurrencyPrices.Where((x, i) => ccpCurrencyPrices.FindIndex(z => z.CurrencyId == x.CurrencyId) == i).ToList();//Lambda表达式去重
  6749. var ccpCurrencyPrice = nonDuplicat.Where(it => it.CurrencyId == 836).FirstOrDefault();
  6750. if (ccpCurrencyPrice != null)
  6751. {
  6752. int CNYIndex = nonDuplicat.IndexOf(ccpCurrencyPrice);
  6753. nonDuplicat.MoveItemAtIndexToFront(CNYIndex);
  6754. }
  6755. else
  6756. {
  6757. nonDuplicat = nonDuplicat.OrderBy(it => it.CurrencyId).ToList();
  6758. }
  6759. string amountPayableStr = string.Format(@"应付款总金额: ");
  6760. string thisPaymentStr = string.Format(@"此次付款总金额: ");
  6761. string balancePaymentStr = string.Format(@"目前剩余尾款总金额: ");
  6762. string auditedFundsStr = string.Format(@"已审费用总额: ");
  6763. string unAuditedFundsStr = string.Format(@"未审费用总额: ");
  6764. foreach (var item in nonDuplicat)
  6765. {
  6766. var currencyName = item.CurrencyName;
  6767. var strs = ccpCurrencyPrices.Where(it => it.CurrencyId == item.CurrencyId).ToList();
  6768. if (strs.Count > 0)
  6769. {
  6770. decimal amountPayable = strs.Sum(it => it.AmountPayable);
  6771. decimal thisPayment = ccpCurrencyPrices.Sum(it => it.ThisPayment);
  6772. decimal balancePayment = strs.Sum(it => it.BalancePayment);
  6773. amountPayableStr += string.Format(@"{0}{1}&nbsp;|", amountPayable.ToString("#0.00"), currencyName);
  6774. //单独处理此次付款金额
  6775. thisPaymentStr += string.Format(@"{0}{1}&nbsp;|", strs.Sum(x => x.ThisPayment).ToString("#0.00"), currencyName);
  6776. balancePaymentStr += string.Format(@"{0}{1}&nbsp;|", balancePayment.ToString("#0.00"), currencyName);
  6777. //单独处理已审核费用
  6778. //if (item.CurrencyId == 836) //人民币
  6779. //{
  6780. // decimal auditedFunds = ccpCurrencyPrices.Sum(it => it.AuditedFunds);
  6781. // auditedFundsStr += string.Format(@"{0}{1}&nbsp;|", auditedFunds.ToString("#0.00"), currencyName);
  6782. //}
  6783. //else
  6784. //{
  6785. // auditedFundsStr += string.Format(@"{0}{1}&nbsp;|", strs.Sum(x => x.AmountPayable), currencyName);
  6786. //}
  6787. if (currencyName.Equals("CNY"))
  6788. {
  6789. //已审核费用
  6790. auditedFundsStr += string.Format(@"{0}{1}&nbsp;|", strs.Sum(x => x.ThisPayment).ToString("#0.00"), currencyName);
  6791. //未审核费用
  6792. unAuditedFundsStr += string.Format(@"{0}{1}&nbsp;|", strs.Sum(x => x.UnAuditFundsOriginal).ToString("#0.00"), currencyName);
  6793. }
  6794. else
  6795. {
  6796. //已审核费用
  6797. 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"));
  6798. //未审核费用
  6799. 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"));
  6800. }
  6801. }
  6802. }
  6803. _view.TotalStr1 = amountPayableStr[..^1];
  6804. _view.TotalStr2 = thisPaymentStr[..^1];
  6805. _view.TotalStr3 = balancePaymentStr[..^1];
  6806. _view.TotalStr4 = $"{auditedFundsStr[..^1]}<br/>{unAuditedFundsStr[..^1]}";
  6807. //_view.TotalStr5 = unAuditedFundsStr.Substring(0, unAuditedFundsStr.Length - 1);
  6808. var _view1 = new
  6809. {
  6810. PageFuncAuth = pageFunAuthView,
  6811. Data = _view
  6812. };
  6813. return Ok(JsonView(_view1));
  6814. }
  6815. catch (Exception ex)
  6816. {
  6817. return Ok(JsonView(false, ex.Message));
  6818. }
  6819. }
  6820. /// <summary>
  6821. /// 费用审核
  6822. /// 修改团组费用审核状态
  6823. /// </summary>
  6824. /// <param name="_dto">参数Json字符串</param>
  6825. /// <returns></returns>
  6826. [HttpPost]
  6827. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  6828. public async Task<IActionResult> PostAuditGrpCreditCardPayment(Edit_GrpCreditCardPaymentDto _dto)
  6829. {
  6830. #region 参数验证
  6831. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  6832. if (_dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  6833. #endregion
  6834. #region 页面操作权限验证
  6835. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  6836. if (pageFunAuthView.AuditAuth == 0) return Ok(JsonView(false, "您没有审核权限"));
  6837. #endregion
  6838. List<string> idList = _dto.CreditIdStr.Split(',').ToList();
  6839. Grp_CreditCardPayment _detail = _mapper.Map<Grp_CreditCardPayment>(_dto);
  6840. DateTime dtNow = DateTime.Now;
  6841. _groupRepository.BeginTran();
  6842. int rst = 0;
  6843. var creditDatas = _grpScheduleRep._sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.IsDel == 0 && idList.Contains(it.Id.ToString())).ToList();
  6844. var creditTypeDatas = _grpScheduleRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 16).ToList();
  6845. var creditCurrencyDatas = _grpScheduleRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  6846. var groupDatas = _grpScheduleRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).ToList();
  6847. var msgDatas = new List<dynamic>();
  6848. var dic_ccp_user = new Dictionary<int, int>() { };
  6849. foreach (var item in idList)
  6850. {
  6851. int CreditId = int.Parse(item);
  6852. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_CreditCardPayment>()
  6853. .SetColumns(it => it.IsAuditGM == _dto.AuditCode)
  6854. .SetColumns(it => it.AuditGMOperate == _dto.UserId)
  6855. .SetColumns(it => it.AuditGMDate == dtNow.ToString("yyyy-MM-dd HH:mm:ss"))
  6856. .Where(s => s.Id == CreditId)
  6857. .ExecuteCommandAsync();
  6858. if (result < 1)
  6859. {
  6860. rst = -1;
  6861. _groupRepository.RollbackTran();
  6862. return Ok(JsonView(false, "操作失败并回滚!"));
  6863. }
  6864. var creditData = creditDatas.Where(it => it.Id == CreditId).FirstOrDefault();
  6865. if (creditData != null)
  6866. {
  6867. #region 应用通知配置
  6868. try
  6869. {
  6870. dic_ccp_user.Add(creditData.Id, creditData.CreateUserId);
  6871. }
  6872. catch (Exception ex)
  6873. {
  6874. }
  6875. #endregion
  6876. string auditStr = _dto.AuditCode == 1 ? "已通过" : _dto.AuditCode == 2 ? "未通过" : "未审核";
  6877. string groupNameStr = string.Empty;
  6878. var groupData = groupDatas.Where(it => it.Id == creditData.DIId).FirstOrDefault();
  6879. if (groupData != null) groupNameStr = groupData.TeamName;
  6880. string creditTypeStr = string.Empty;
  6881. var creditTypeData = creditTypeDatas.Where(it => it.Id == creditData.CTable).FirstOrDefault();
  6882. if (creditTypeData != null) creditTypeStr = creditTypeData.Name;
  6883. string creditCurrency = string.Empty;
  6884. var creditCurrencyData = creditCurrencyDatas.Where(it => it.Id == creditData.PaymentCurrency).FirstOrDefault();
  6885. if (creditCurrencyData != null) creditCurrency = creditCurrencyData.Name;
  6886. if (creditCurrency.Equals("CNY"))
  6887. {
  6888. creditData.DayRate = 1.0000M;
  6889. }
  6890. if (creditData.PayPercentage == 0.00M)
  6891. {
  6892. creditData.PayPercentage = 100M;
  6893. }
  6894. decimal CNYPrice = (creditData.PayMoney * (creditData.PayPercentage / 100)) * creditData.DayRate;
  6895. string msgTitle = $"[{groupNameStr}({creditTypeStr})]的费用申请";
  6896. string msgContent = "";
  6897. if (creditCurrency.Equals("CNY"))
  6898. {
  6899. msgContent = $"[{groupNameStr}({creditTypeStr})]费用申请(金额:{CNYPrice:0.00} CNY) {auditStr}!";
  6900. }
  6901. else
  6902. {
  6903. msgContent = $"[{groupNameStr}({creditTypeStr})]费用申请(金额:{CNYPrice:0.00} CNY({creditData.PayMoney:0.00} {creditCurrency})) {auditStr}!";
  6904. }
  6905. msgDatas.Add(new { DiId = creditData.DIId, UserId = creditData.CreateUserId, MsgTitle = msgTitle, MsgContent = msgContent });
  6906. }
  6907. }
  6908. if (rst == 0)
  6909. {
  6910. _groupRepository.CommitTran();
  6911. foreach (var item in msgDatas)
  6912. {
  6913. //发送消息
  6914. GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupExpenseAudit, item.MsgTitle, item.MsgContent, new List<int>() { item.UserId }, item.DiId);
  6915. }
  6916. #region 应用推送
  6917. try
  6918. {
  6919. foreach (var ccpId in dic_ccp_user.Keys)
  6920. {
  6921. var templist = new List<string>() { dic_ccp_user[ccpId].ToString() };
  6922. await AppNoticeLibrary.SendUserMsg_GroupStatus_AuditFee(ccpId, templist, QiyeWeChatEnum.CaiWuChat);
  6923. }
  6924. }
  6925. catch (Exception)
  6926. {
  6927. }
  6928. #endregion
  6929. return Ok(JsonView(true, "操作成功!"));
  6930. }
  6931. return Ok(JsonView(false, "操作失败!"));
  6932. }
  6933. /// <summary>
  6934. /// 费用审核
  6935. /// 其他款项 文件下载
  6936. /// </summary>
  6937. /// <param name="id">其他款项 主键编号</param>
  6938. /// <returns></returns>
  6939. [HttpGet("{id}")]
  6940. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  6941. public async Task<IActionResult> FeeAuditOtherFileDownlaod([Range(1, int.MaxValue, ErrorMessage = "请传入有效的ID")] int id)
  6942. {
  6943. //网站域名
  6944. 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/";
  6945. var otherInfo = await _decreasePaymentsRep._sqlSugar
  6946. .Queryable<Grp_DecreasePayments>()
  6947. .InnerJoin<Grp_CreditCardPayment>((x, y) => x.Id == y.CId && y.Id == id)
  6948. .Where(((x, y) => x.IsDel == 0 && y.IsDel == 0))
  6949. .Select((x, y) => new
  6950. {
  6951. x.Id,
  6952. x.FilePath
  6953. })
  6954. .FirstAsync();
  6955. if (otherInfo != null && !string.IsNullOrEmpty(otherInfo.FilePath.Trim()))
  6956. {
  6957. var url = $"{baseUrl}{otherInfo.FilePath}";
  6958. return Ok(JsonView(true, "操作成功!", url));
  6959. }
  6960. return Ok(JsonView(false, "暂无附件"));
  6961. }
  6962. #endregion
  6963. #region 机票费用录入
  6964. /// <summary>
  6965. /// 机票录入当前登录人可操作团组
  6966. /// </summary>
  6967. /// <param name="dto"></param>
  6968. /// <returns></returns>
  6969. [HttpPost]
  6970. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  6971. public async Task<IActionResult> AirTicketResSelect(AirTicketResDto dto)
  6972. {
  6973. try
  6974. {
  6975. Result groupData = await _airTicketResRep.AirTicketResSelect(dto);
  6976. if (groupData.Code != 0)
  6977. {
  6978. return Ok(JsonView(false, groupData.Msg));
  6979. }
  6980. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  6981. }
  6982. catch (Exception ex)
  6983. {
  6984. return Ok(JsonView(false, ex.Message));
  6985. }
  6986. }
  6987. /// <summary>
  6988. /// 机票费用录入列表
  6989. /// </summary>
  6990. /// <param name="dto"></param>
  6991. /// <returns></returns>
  6992. [HttpPost]
  6993. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  6994. public async Task<IActionResult> AirTicketResList(AirTicketResDto dto)
  6995. {
  6996. try
  6997. {
  6998. Result groupData = await _airTicketResRep.AirTicketResList(dto);
  6999. if (groupData.Code != 0)
  7000. {
  7001. return Ok(JsonView(false, groupData.Msg));
  7002. }
  7003. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  7004. }
  7005. catch (Exception ex)
  7006. {
  7007. return Ok(JsonView(false, ex.Message));
  7008. throw;
  7009. }
  7010. }
  7011. /// <summary>
  7012. /// 根据id查询费用录入信息
  7013. /// </summary>
  7014. /// <param name="dto"></param>
  7015. /// <returns></returns>
  7016. [HttpPost]
  7017. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7018. public async Task<IActionResult> AirTicketResById(AirTicketResByIdDto dto)
  7019. {
  7020. Result groupData = await _airTicketResRep.AirTicketResById(dto);
  7021. if (groupData.Code != 0)
  7022. {
  7023. return Ok(JsonView(false, groupData.Msg));
  7024. }
  7025. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  7026. }
  7027. /// <summary>
  7028. /// 机票费用录入操作(Status:1.新增,2.修改)
  7029. /// </summary>
  7030. /// <param name="dto"></param>
  7031. /// <returns></returns>
  7032. [HttpPost]
  7033. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7034. public async Task<IActionResult> OpAirTicketRes(AirTicketResOpDto dto)
  7035. {
  7036. Result groupData = await _airTicketResRep.OpAirTicketRes(dto, _setDataRep.PostCurrencyByDiid);
  7037. if (groupData.Code != 0)
  7038. {
  7039. return Ok(JsonView(false, groupData.Msg));
  7040. }
  7041. #region 应用推送
  7042. try
  7043. {
  7044. var diId = dto.AirTicketResOpData.DiId;
  7045. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  7046. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  7047. int dataId = groupData.Data.GetType().GetProperty("dataId").GetValue(groupData.Data, null);
  7048. //自动审核
  7049. //var autoAdit1 = await _feeAuditRep.FeeAutomaticAudit(5, diId, dataId); //机票费用合计方式
  7050. (bool status, string auditMsg) = await AirTicketResAutoAudit(diId, dataId); //KIMI-AI识别INIT方式
  7051. _logger.LogInformation("【机票费用自动审核(KIMI-AI识别INIT)】请求参数:{RequstData} 返回结果:是否执行:{IsExecute}; 结果消息:{ResponseMsg};",
  7052. $"GroupId:{diId};airId:{dataId};",
  7053. status,
  7054. auditMsg);
  7055. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  7056. //2024-10-21 新增LZ UID
  7057. var userIds = new List<int>() { 21 };
  7058. string title = $"系统通知";
  7059. string content = "";
  7060. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  7061. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  7062. if (dto.Status == 1) content = $"[新增-机票费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  7063. else if (dto.Status == 2) content = $"[更新-机票费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  7064. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  7065. var h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "85" };
  7066. await APNsTools.iOS_PushNotifications1("051", $"机票费用审核", "", content, true, "ExpenseAuditWebView", h5);
  7067. }
  7068. catch (Exception ex)
  7069. {
  7070. }
  7071. #endregion
  7072. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  7073. }
  7074. /// <summary>
  7075. /// 机票费用自动审核 AI识别方式
  7076. /// </summary>
  7077. /// <returns></returns>
  7078. private async Task<(bool, string)> AirTicketResAutoAudit(int diId, int dataId)
  7079. {
  7080. var ecoTypeIds = new List<int>() {
  7081. 459, //超经舱
  7082. 460, //经济舱
  7083. 1430, //公务舱(实际经济舱)
  7084. 1432, //头等舱(实际经济舱)
  7085. };
  7086. var bizTypeIds = new List<int>() {
  7087. 457, //头等舱
  7088. 458, //公务舱
  7089. 1431, //头等舱(实际公务舱)
  7090. };
  7091. var auditFeeTypeIds = new List<int>() { };
  7092. auditFeeTypeIds.AddRange(ecoTypeIds);
  7093. auditFeeTypeIds.AddRange(bizTypeIds);
  7094. int currModule = 85;
  7095. var airInfo = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  7096. .InnerJoin<Grp_CreditCardPayment>((x, y) => x.Id == y.CId && y.CTable == currModule && y.IsDel == 0)
  7097. .Where((x, y) => x.Id == dataId && x.IsDel == 0 && auditFeeTypeIds.Contains(x.CType))
  7098. .Select((x, y) => new
  7099. {
  7100. x.Id,
  7101. CcpId = y.Id,
  7102. x.FlightsDate,
  7103. x.PrePrice,
  7104. x.CType,
  7105. x.ClientNum,
  7106. x.DIId
  7107. })
  7108. .FirstAsync();
  7109. if (airInfo == null) return (false, "机票信息为空或费用类型不在自动审核范围内,不可自动审核!");
  7110. var groupDetails = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.IsDel == 0 && x.Id == diId);
  7111. if (groupDetails == null) return (false, "团组信息为空,不可自动审核!");
  7112. var groupCostInfo = await _sqlSugar.Queryable<Grp_GroupCostParameter>().FirstAsync(x => x.IsDel == 0 && x.DiId == diId);
  7113. if (groupCostInfo == null) return (false, "团组成本信息未填写!");
  7114. var groupCostContents = await _sqlSugar
  7115. .SqlQueryable<GroupCostAuditView>($"Select * From Grp_GroupCost")
  7116. .Where(x => x.IsDel == 0 && x.Diid == diId)
  7117. .ToListAsync();
  7118. if (groupCostContents.Count < 1) return (false, "团组成本信息未填写!");
  7119. //处理 成本详细信息日期为空 填装费用信息
  7120. var airFeeLabel = new StringBuilder();
  7121. airFeeLabel.AppendLine("费用成本:");
  7122. for (int i = 0; i < groupCostContents.Count; i++)
  7123. {
  7124. if (string.IsNullOrEmpty(groupCostContents[i].Date))
  7125. {
  7126. int index = i - 1;
  7127. if (index >= 0)
  7128. {
  7129. groupCostContents[i].Date = groupCostContents[index].Date;
  7130. var dtBool = DateTime.TryParse(groupCostContents[i].Date, out DateTime _dateTime);
  7131. if (dtBool) groupCostContents[i].CurrTime = _dateTime;
  7132. }
  7133. }
  7134. else
  7135. {
  7136. var dtBool = DateTime.TryParse(groupCostContents[i].Date, out DateTime _dateTime);
  7137. if (dtBool) groupCostContents[i].CurrTime = _dateTime;
  7138. }
  7139. var item = groupCostContents[i];
  7140. airFeeLabel.AppendLine($"{item.Date}");
  7141. airFeeLabel.AppendLine($"{item.ITIN.Replace("\n", " ")}");
  7142. }
  7143. airFeeLabel.AppendLine($"注:费用:位置:航班号或者航班时间后面; 组成:经济舱/公务舱;");
  7144. airFeeLabel.AppendLine($"取出“{airInfo.FlightsDate}”费用金额,按照经济舱/公务舱格式返回,如果不存在的话则返回0.00/0.00,只返回金额格式文本;不需要其他文字描述;");
  7145. //访问Kimi AI 返回价格结果
  7146. var msgs = new List<SeedMessages>()
  7147. {
  7148. new ()
  7149. {
  7150. Role = KimiRole.user,
  7151. Content = airFeeLabel.ToString()
  7152. }
  7153. };
  7154. var client = new KiMiApiClient();
  7155. var kimiApiResult = await client.SeedMessage(msgs);
  7156. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  7157. string clients = kimiApiResult_JObject["content"].ToString();
  7158. decimal ecoPri_kimiAI = 0.00M,
  7159. bizPri_kimiAI = 0.00M;
  7160. //单个价格: 经济舱价格
  7161. if (decimal.TryParse(clients, out ecoPri_kimiAI)) { }
  7162. //价格文本包含/:/前经济舱价格 /后公务舱价格
  7163. if (clients.Contains('/'))
  7164. {
  7165. var priArray = clients.Split('/');
  7166. decimal.TryParse(priArray[0], out ecoPri_kimiAI); //
  7167. decimal.TryParse(priArray[1], out bizPri_kimiAI); //经济舱价格
  7168. }
  7169. else return (false, "价格文本不存在价格或KIMI-AI未识别出价格,不可自动审核!");
  7170. var isAutoAudit = false;
  7171. //价格验证处理
  7172. //经济舱
  7173. if (ecoTypeIds.Contains(airInfo.CType))
  7174. {
  7175. if (airInfo.PrePrice <= ecoPri_kimiAI) isAutoAudit = true;
  7176. }
  7177. //公务舱
  7178. else if (bizTypeIds.Contains(airInfo.CType))
  7179. {
  7180. if (airInfo.PrePrice <= bizPri_kimiAI) isAutoAudit = true;
  7181. }
  7182. else return (false, "该舱位类型不在自动审核范围内,不可自动审核!");
  7183. //是否执行自动审核
  7184. if (isAutoAudit)
  7185. {
  7186. var auditStatus = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  7187. .SetColumns(x => x.IsAuditGM == 3)
  7188. .SetColumns(x => x.AuditGMOperate == 4)
  7189. .SetColumns(x => x.AuditGMDate == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  7190. .Where(x => x.Id == airInfo.CcpId)
  7191. .ExecuteCommandAsync();
  7192. if (auditStatus > 0) return (true, "机票自动审核(KIMI-AI识别方式)执行成功!");
  7193. }
  7194. return (false, "当前费用超过成本费用,不可自动审核!");
  7195. }
  7196. /// <summary>
  7197. /// 机票费用录入
  7198. /// 自动审核测试 - AI 识别
  7199. /// </summary>
  7200. /// <param name="groupId"></param>
  7201. /// <param name="Id"></param>
  7202. /// <returns></returns>
  7203. [HttpPost]
  7204. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7205. public async Task<IActionResult> AirTicketResAutoAuditTest(int groupId, int Id)
  7206. {
  7207. (bool status, string msg) = await AirTicketResAutoAudit(groupId, Id);
  7208. return Ok(JsonView(status, msg));
  7209. }
  7210. /// <summary>
  7211. /// 根据舱位类型查询接团客户名单信息
  7212. /// </summary>
  7213. /// <param name="dto"></param>
  7214. /// <returns></returns>
  7215. [HttpPost]
  7216. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7217. public async Task<IActionResult> TankType(AirTicketResByIdDto dto)
  7218. {
  7219. try
  7220. {
  7221. List<Crm_GroupCustomer> crm_Groups = _sqlSugar.Queryable<Crm_GroupCustomer>().Where(a => a.IsDel == 0 && a.AirType == dto.Id).ToList();
  7222. if (crm_Groups.Count != 0)
  7223. {
  7224. var Customer = new List<dynamic>();
  7225. foreach (var item in crm_Groups)
  7226. {
  7227. var data = new
  7228. {
  7229. item.Id,
  7230. item.Pinyin,
  7231. Name = item.LastName + item.FirstName
  7232. };
  7233. Customer.Add(data);
  7234. }
  7235. return Ok(JsonView(true, "查询成功!", Customer));
  7236. }
  7237. return Ok(JsonView(true, "暂无数据", crm_Groups));
  7238. }
  7239. catch (Exception ex)
  7240. {
  7241. return Ok(JsonView(false, "程序错误!"));
  7242. throw;
  7243. }
  7244. }
  7245. /// <summary>
  7246. /// 根据团号获取客户信息
  7247. /// </summary>
  7248. /// <param name="dto"></param>
  7249. /// <returns></returns>
  7250. [HttpPost]
  7251. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7252. public IActionResult QueryClientInfoByDIID(QueryClientInfoByDIIDDto dto)
  7253. {
  7254. var jw = JsonView(false);
  7255. if (dto.DIID < 1)
  7256. {
  7257. jw.Msg += "请输入正确的diid";
  7258. return Ok(jw);
  7259. }
  7260. var arr = GetSimplClientList(dto.DIID);
  7261. jw = JsonView(true, "获取成功!", arr);
  7262. return Ok(jw);
  7263. }
  7264. private List<SimplClientInfo> GetSimplClientList(int diId)
  7265. {
  7266. 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);
  7267. List<SimplClientInfo> arr = _sqlSugar.SqlQueryable<SimplClientInfo>(sql).ToList();
  7268. foreach (var item in arr)
  7269. {
  7270. EncryptionProcessor.DecryptProperties(item);
  7271. }
  7272. return arr;
  7273. }
  7274. private static string GetClientNameStr(List<SimplClientInfo> list, string origin)
  7275. {
  7276. string result = origin;
  7277. if (Regex.Match(origin, @"\d+,?").Value.Length > 0)
  7278. {
  7279. string[] temparr = origin.Split(',');
  7280. string fistrStr = temparr[0];
  7281. int count = temparr.Length;
  7282. bool success = int.TryParse(fistrStr, out int tempId);
  7283. if (success)
  7284. {
  7285. SimplClientInfo tempInfo = list.FirstOrDefault(s => s.Id == tempId);
  7286. if (tempInfo != null)
  7287. {
  7288. if (count > 1)
  7289. {
  7290. result = string.Format(@"{0}{1}等{2}人", tempInfo.LastName, tempInfo.FirstName, count);
  7291. }
  7292. else
  7293. {
  7294. result = string.Format(@"{0}{1}", tempInfo.LastName, tempInfo.FirstName);
  7295. }
  7296. }
  7297. }
  7298. }
  7299. return result;
  7300. }
  7301. private static string GetClientNameStr1(List<SimplClientInfo> list, string origin)
  7302. {
  7303. string result = origin;
  7304. if (Regex.Match(origin, @"\d+,?").Value.Length > 0)
  7305. {
  7306. string[] temparr = origin.Split(',');
  7307. result = "";
  7308. foreach (var item in temparr)
  7309. {
  7310. bool success = int.TryParse(item, out int tempId);
  7311. if (success)
  7312. {
  7313. SimplClientInfo tempInfo = list.FirstOrDefault(s => s.Id == tempId);
  7314. if (tempInfo != null)
  7315. {
  7316. result += string.Format(@"{0}{1}、", tempInfo.LastName, tempInfo.FirstName);
  7317. }
  7318. }
  7319. }
  7320. }
  7321. if (result.Length > 0) result = result.Substring(0, result.Length - 1);
  7322. return result;
  7323. }
  7324. /// <summary>
  7325. /// 机票费用录入,删除
  7326. /// </summary>
  7327. /// <param name="dto"></param>
  7328. /// <returns></returns>
  7329. [HttpPost]
  7330. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7331. public async Task<IActionResult> DelAirTicketRes(DelBaseDto dto)
  7332. {
  7333. try
  7334. {
  7335. var res = await _airTicketResRep.SoftDeleteByIdAsync<Grp_AirTicketReservations>(dto.Id.ToString(), dto.DeleteUserId);
  7336. if (res)
  7337. {
  7338. var result = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == dto.Id && a.CTable == 85).SetColumns(a => new Grp_CreditCardPayment()
  7339. {
  7340. IsDel = 1,
  7341. DeleteUserId = dto.DeleteUserId,
  7342. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  7343. }).ExecuteCommandAsync();
  7344. return Ok(JsonView(true, "删除成功!"));
  7345. }
  7346. return Ok(JsonView(false, "删除失败!"));
  7347. }
  7348. catch (Exception ex)
  7349. {
  7350. return Ok(JsonView(false, "程序错误!"));
  7351. throw;
  7352. }
  7353. }
  7354. /// <summary>
  7355. /// 导出机票录入报表
  7356. /// </summary>
  7357. /// <param name="dto"></param>
  7358. /// <returns></returns>
  7359. [HttpPost]
  7360. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7361. public async Task<IActionResult> DeriveAirTicketRes(AirTicketResDto dto)
  7362. {
  7363. try
  7364. {
  7365. Result groupData = await _airTicketResRep.DeriveAirTicketRes(dto);
  7366. if (groupData.Code != 0)
  7367. {
  7368. return Ok(JsonView(StatusCodes.Status400BadRequest, groupData.Msg, ""));
  7369. }
  7370. else
  7371. {
  7372. List<AirTicketReservationsPayView> AirTicketReservations = groupData.Data.GetType().GetProperty("AirTicketRes").GetValue(groupData.Data);
  7373. if (AirTicketReservations.Count != 0)
  7374. {
  7375. Grp_DelegationInfo DelegationInfo = groupData.Data.GetType().GetProperty("Delegation").GetValue(groupData.Data);
  7376. Sys_Users _Users = groupData.Data.GetType().GetProperty("Users").GetValue(groupData.Data);
  7377. string diCode = DelegationInfo != null ? DelegationInfo.TourCode : "XXX";
  7378. string diName = DelegationInfo != null ? DelegationInfo.TeamName : "XXX";
  7379. var designer = new WorkbookDesigner
  7380. {
  7381. Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/机票预订费用报表模板.xlsx")
  7382. };
  7383. decimal countCost = 0;
  7384. foreach (var item in AirTicketReservations)
  7385. {
  7386. #region 处理客人姓名
  7387. string clientNames = _tourClientListRep.ResolveCustomerName(item.ClientName);
  7388. item.ClientName = clientNames;
  7389. #endregion
  7390. if (item.BankType == "其他")
  7391. {
  7392. item.BankNo = "--";
  7393. }
  7394. else
  7395. {
  7396. if (!string.IsNullOrEmpty(item.BankType))
  7397. {
  7398. item.BankNo = $"{item.BankType}:{item.BankNo?[..3]}";
  7399. }
  7400. }
  7401. item.PrePrice = System.Decimal.Round(item.PrePrice, 2);
  7402. item.Price = System.Decimal.Round(item.Price, 2);
  7403. countCost += Convert.ToDecimal(item.Price);
  7404. }
  7405. designer.SetDataSource("Export", AirTicketReservations);
  7406. designer.SetDataSource("ExportDiCode", diCode);
  7407. designer.SetDataSource("ExportDiName", diName);
  7408. designer.SetDataSource("ExportOpUserName", _Users.CnName);
  7409. designer.SetDataSource("ExportCountCost", countCost + "(" + AirTicketReservations[0].CurrencyStr);
  7410. designer.Process();
  7411. string fileName = ("AirfareStatement/" + diName + "机票费用报表" + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx").Replace(":", "");
  7412. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  7413. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  7414. return Ok(JsonView(true, "成功", url = rst));
  7415. }
  7416. else
  7417. {
  7418. return Ok(JsonView(StatusCodes.Status400BadRequest, "暂无数据!", ""));
  7419. }
  7420. }
  7421. }
  7422. catch (Exception ex)
  7423. {
  7424. return Ok(JsonView(StatusCodes.Status400BadRequest, ex.Message, ""));
  7425. throw;
  7426. }
  7427. }
  7428. private Dictionary<string, string> transDic = new Dictionary<string, string>();
  7429. /// <summary>
  7430. /// 行程单导出
  7431. /// </summary>
  7432. /// <param name="dto"></param>
  7433. /// <returns></returns>
  7434. [HttpPost]
  7435. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7436. public async Task<IActionResult> ItineraryAirTicketRes(ItineraryAirTicketResDto dto)
  7437. {
  7438. try
  7439. {
  7440. Result groupData = await _airTicketResRep.ItineraryAirTicketRes(dto);
  7441. if (groupData.Code != 0)
  7442. {
  7443. return Ok(JsonView(StatusCodes.Status400BadRequest, groupData.Msg, ""));
  7444. }
  7445. else
  7446. {
  7447. List<AirTicketReservationsView> _AirTicketReservations = groupData.Data;
  7448. if (dto.Language == "CN")
  7449. {
  7450. var doc = new Document(AppSettingsHelper.Get("WordBasePath") + "Template/电子客票行程单模板_CN.docx");
  7451. var builder = new DocumentBuilder(doc);
  7452. int tableIndex = 0;//表格索引
  7453. //得到文档中的第一个表格
  7454. Table table = (Table)doc.GetChild(NodeType.Table, tableIndex, true);
  7455. foreach (var item in _AirTicketReservations)
  7456. {
  7457. #region 处理固定数据
  7458. string[] FlightsCode = item.FlightsCode.Split('/');
  7459. if (FlightsCode.Length != 0)
  7460. {
  7461. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  7462. if (_AirCompany != null)
  7463. {
  7464. table.Range.Bookmarks["AirlineCompany"].Text = _AirCompany.CnName;
  7465. }
  7466. else
  7467. {
  7468. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  7469. }
  7470. }
  7471. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  7472. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  7473. string[] nameArray = Regex.Split(item.ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  7474. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  7475. string name = "";
  7476. foreach (string clientName in nameArray)
  7477. {
  7478. if (!name.Contains(clientName))
  7479. {
  7480. name += clientName + ",";
  7481. }
  7482. }
  7483. if (!string.IsNullOrWhiteSpace(name))
  7484. {
  7485. table.Range.Bookmarks["ClientName"].Text = name.Substring(0, name.Length - 1);
  7486. }
  7487. else
  7488. {
  7489. table.Range.Bookmarks["ClientName"].Text = "--";
  7490. }
  7491. table.Range.Bookmarks["TicketNumber"].Text = "--";
  7492. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  7493. table.Range.Bookmarks["JointTicket"].Text = "--";
  7494. table.Range.Bookmarks["TimeIssue"].Text = "--";
  7495. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  7496. table.Range.Bookmarks["NavigationCode"].Text = "--";
  7497. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  7498. table.Range.Bookmarks["AgentPhone"].Text = "--";
  7499. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  7500. #endregion
  7501. #region 循环数据处理
  7502. var airs = new List<AirInfo>();
  7503. string[] DayArray = Regex.Split(item.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase);
  7504. DayArray = DayArray.Where(s => s != " " && s != "" && !string.IsNullOrEmpty(s)).ToArray();
  7505. for (int i = 0; i < FlightsCode.Length; i++)
  7506. {
  7507. var air = new AirInfo();
  7508. string[] tempstr = DayArray[i]
  7509. .Replace("\r\n", string.Empty)
  7510. .Replace("\\r\\n", string.Empty)
  7511. .TrimStart().TrimEnd()
  7512. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  7513. Res_ThreeCode star_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(0, 3));
  7514. string starCity = "";
  7515. if (star_Three != null)
  7516. {
  7517. starCity = star_Three.AirPort;
  7518. }
  7519. Res_ThreeCode End_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(3, 3));
  7520. string EndCity = "";
  7521. if (End_Three != null)
  7522. {
  7523. EndCity = End_Three.AirPort;
  7524. }
  7525. air.Destination = starCity + "/" + EndCity;
  7526. air.Flight = FlightsCode[i];
  7527. air.SeatingClass = item.CTypeName;
  7528. string dateTime = tempstr[2];
  7529. string DateTemp = dateTime.Substring(2, 5).ToUpper();
  7530. air.FlightDate = DateTemp;
  7531. air.DepartureTime = tempstr[5];
  7532. air.LandingTime = tempstr[6];
  7533. air.ValidityPeriod = DateTemp + "/" + DateTemp;
  7534. air.TicketStatus = "--";
  7535. air.Luggage = "--";
  7536. air.DepartureTerminal = "--";
  7537. air.LandingTerminal = "--";
  7538. airs.Add(air);
  7539. }
  7540. int row = 13;
  7541. for (int i = 0; i < airs.Count; i++)
  7542. {
  7543. if (airs.Count > 2)
  7544. {
  7545. for (int j = 0; j < airs.Count - 2; j++)
  7546. {
  7547. var CopyRow = table.Rows[12].Clone(true);
  7548. table.Rows.Add(CopyRow);
  7549. }
  7550. }
  7551. PropertyInfo[] properties = airs[i].GetType().GetProperties();
  7552. int index = 0;
  7553. foreach (PropertyInfo property in properties)
  7554. {
  7555. string value = property.GetValue(airs[i]).ToString();
  7556. Cell ishcel0 = table.Rows[row].Cells[index];
  7557. var p = new Paragraph(doc);
  7558. string s = value;
  7559. p.AppendChild(new Run(doc, s));
  7560. p.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐
  7561. ishcel0.AppendChild(p);
  7562. ishcel0.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
  7563. index++;
  7564. }
  7565. row++;
  7566. }
  7567. #endregion
  7568. var lastParagraph = new Paragraph(doc);
  7569. //第一个表格末尾加段落
  7570. table.ParentNode.InsertAfter(lastParagraph, table);
  7571. //复制第一个表格
  7572. Table cloneTable = (Table)table.Clone(true);
  7573. //在文档末尾段落后面加入复制的表格
  7574. table.ParentNode.InsertAfter(cloneTable, lastParagraph);
  7575. if (item != _AirTicketReservations[_AirTicketReservations.Count - 1])
  7576. {
  7577. int rownewsIndex = 13;
  7578. for (int i = 0; i < 2; i++)
  7579. {
  7580. var CopyRow = table.Rows[12].Clone(true);
  7581. table.Rows.RemoveAt(13);
  7582. table.Rows.Add(CopyRow);
  7583. rownewsIndex++;
  7584. }
  7585. }
  7586. else
  7587. {
  7588. table.Rows.RemoveAt(12);
  7589. }
  7590. cloneTable.Rows.RemoveAt(12);
  7591. }
  7592. if (_AirTicketReservations.Count != 0)
  7593. {
  7594. string[] FlightsCode = _AirTicketReservations[0].FlightsCode.Split('/');
  7595. if (FlightsCode.Length != 0)
  7596. {
  7597. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  7598. if (_AirCompany != null)
  7599. {
  7600. table.Range.Bookmarks["AirlineCompany"].Text = _AirCompany.CnName;
  7601. }
  7602. else
  7603. {
  7604. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  7605. }
  7606. }
  7607. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  7608. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  7609. string[] nameArray = Regex.Split(_AirTicketReservations[0].ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  7610. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  7611. string name = "";
  7612. foreach (string clientName in nameArray)
  7613. {
  7614. if (!name.Contains(clientName))
  7615. {
  7616. name += clientName + ",";
  7617. }
  7618. }
  7619. if (!string.IsNullOrWhiteSpace(name))
  7620. {
  7621. table.Range.Bookmarks["ClientName"].Text = name.Substring(0, name.Length - 1);
  7622. }
  7623. else
  7624. {
  7625. table.Range.Bookmarks["ClientName"].Text = "--";
  7626. }
  7627. table.Range.Bookmarks["TicketNumber"].Text = "--";
  7628. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  7629. table.Range.Bookmarks["JointTicket"].Text = "--";
  7630. table.Range.Bookmarks["TimeIssue"].Text = "--";
  7631. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  7632. table.Range.Bookmarks["NavigationCode"].Text = "--";
  7633. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  7634. table.Range.Bookmarks["AgentPhone"].Text = "--";
  7635. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  7636. }
  7637. doc.MailMerge.Execute(new[] { "PageCount" }, new object[] { doc.PageCount });
  7638. //保存合并后的文档
  7639. string fileName = "AirItinerary/电子客票中文行程单_CN.docx";
  7640. string rst = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + fileName;
  7641. doc.Save(AppSettingsHelper.Get("WordBasePath") + fileName);
  7642. return Ok(JsonView(true, "成功!", rst));
  7643. }
  7644. else
  7645. {
  7646. var doc = new Document(AppSettingsHelper.Get("WordBasePath") + "Template/电子客票行程单模板_EN.docx");
  7647. var builder = new DocumentBuilder(doc);
  7648. int tableIndex = 0;//表格索引
  7649. //得到文档中的第一个表格
  7650. Table table = (Table)doc.GetChild(NodeType.Table, tableIndex, true);
  7651. var texts = new List<string>();
  7652. foreach (var item in _AirTicketReservations)
  7653. {
  7654. string[] FlightsCode = item.FlightsCode.Split('/');
  7655. if (FlightsCode.Length != 0)
  7656. {
  7657. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  7658. if (_AirCompany != null)
  7659. {
  7660. if (!transDic.ContainsKey(_AirCompany.CnName))
  7661. {
  7662. transDic.Add(_AirCompany.CnName, _AirCompany.EnName);
  7663. }
  7664. }
  7665. else
  7666. {
  7667. if (!transDic.ContainsKey("--"))
  7668. {
  7669. transDic.Add("--", "--");
  7670. }
  7671. }
  7672. }
  7673. string[] nameArray = Regex.Split(item.ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  7674. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  7675. string name = "";
  7676. foreach (string clientName in nameArray)
  7677. {
  7678. name += clientName + ",";
  7679. }
  7680. if (!texts.Contains(name))
  7681. {
  7682. texts.Add(name);
  7683. }
  7684. var airs = new List<AirInfo>();
  7685. string[] DayArray = Regex.Split(item.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase);
  7686. DayArray = DayArray.Where(s => s != " " && s != "" && !string.IsNullOrEmpty(s)).ToArray();
  7687. for (int i = 0; i < FlightsCode.Length; i++)
  7688. {
  7689. var air = new AirInfo();
  7690. string[] tempstr = DayArray[i]
  7691. .Replace("\r\n", string.Empty)
  7692. .Replace("\\r\\n", string.Empty)
  7693. .TrimStart().TrimEnd()
  7694. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  7695. Res_ThreeCode star_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(0, 3));
  7696. if (star_Three != null)
  7697. {
  7698. if (!transDic.ContainsKey(star_Three.AirPort))
  7699. {
  7700. transDic.Add(star_Three.AirPort, star_Three.AirPort_En);
  7701. }
  7702. }
  7703. Res_ThreeCode End_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(3, 3));
  7704. if (End_Three != null)
  7705. {
  7706. if (!transDic.ContainsKey(End_Three.AirPort))
  7707. {
  7708. transDic.Add(End_Three.AirPort, End_Three.AirPort_En);
  7709. }
  7710. }
  7711. if (!texts.Contains(item.CTypeName))
  7712. {
  7713. texts.Add(item.CTypeName);
  7714. }
  7715. }
  7716. }
  7717. List<TranslateResult> transData = await _airTicketResRep.ReTransBatch(texts, "en");
  7718. if (transData.Count > 0)
  7719. {
  7720. foreach (TranslateResult item in transData)
  7721. {
  7722. if (!transDic.ContainsKey(item.Query))
  7723. {
  7724. transDic.Add(item.Query, item.Translation);
  7725. }
  7726. }
  7727. }
  7728. foreach (var item in _AirTicketReservations)
  7729. {
  7730. #region 处理固定数据
  7731. string[] FlightsCode = item.FlightsCode.Split('/');
  7732. if (FlightsCode.Length != 0)
  7733. {
  7734. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  7735. if (_AirCompany != null)
  7736. {
  7737. string str = "--";
  7738. string translateResult = transDic.Where(s => s.Key == _AirCompany.CnName).FirstOrDefault().Value;
  7739. if (!string.IsNullOrEmpty(translateResult))
  7740. {
  7741. str = translateResult;
  7742. str = _airTicketResRep.Processing(str);
  7743. }
  7744. table.Range.Bookmarks["AirlineCompany"].Text = str;
  7745. }
  7746. else
  7747. {
  7748. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  7749. }
  7750. }
  7751. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  7752. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  7753. string[] nameArray = Regex.Split(item.ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  7754. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  7755. string names = "";
  7756. foreach (string clientName in nameArray)
  7757. {
  7758. names += clientName + ",";
  7759. }
  7760. if (!string.IsNullOrWhiteSpace(names))
  7761. {
  7762. string str = "--";
  7763. string translateResult = transDic.Where(s => s.Key == names).FirstOrDefault().Value;
  7764. if (!string.IsNullOrEmpty(translateResult))
  7765. {
  7766. str = translateResult;
  7767. str = _airTicketResRep.Processing(str);
  7768. }
  7769. table.Range.Bookmarks["ClientName"].Text = str;
  7770. }
  7771. else
  7772. {
  7773. table.Range.Bookmarks["ClientName"].Text = "--";
  7774. }
  7775. table.Range.Bookmarks["TicketNumber"].Text = "--";
  7776. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  7777. table.Range.Bookmarks["JointTicket"].Text = "--";
  7778. table.Range.Bookmarks["TimeIssue"].Text = "--";
  7779. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  7780. table.Range.Bookmarks["NavigationCode"].Text = "--";
  7781. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  7782. table.Range.Bookmarks["AgentPhone"].Text = "--";
  7783. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  7784. #endregion
  7785. #region 循环数据处理
  7786. var airs = new List<AirInfo>();
  7787. string[] DayArray = Regex.Split(item.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase);
  7788. DayArray = DayArray.Where(s => s != " " && s != "" && !string.IsNullOrEmpty(s)).ToArray();
  7789. for (int i = 0; i < FlightsCode.Length; i++)
  7790. {
  7791. var air = new AirInfo();
  7792. string[] tempstr = DayArray[i]
  7793. .Replace("\r\n", string.Empty)
  7794. .Replace("\\r\\n", string.Empty)
  7795. .TrimStart().TrimEnd()
  7796. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  7797. Res_ThreeCode star_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(0, 3));
  7798. string starCity = "";
  7799. if (star_Three != null)
  7800. {
  7801. string str2 = "--";
  7802. string translateResult2 = transDic.Where(s => s.Key == star_Three.AirPort).FirstOrDefault().Value;
  7803. if (!string.IsNullOrEmpty(translateResult2))
  7804. {
  7805. str2 = translateResult2;
  7806. str2 = _airTicketResRep.Processing(str2);
  7807. }
  7808. starCity = str2;
  7809. }
  7810. Res_ThreeCode End_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(3, 3));
  7811. string EndCity = "";
  7812. if (End_Three != null)
  7813. {
  7814. string str1 = "--";
  7815. string translateResult1 = transDic.Where(s => s.Key == End_Three.AirPort).FirstOrDefault().Value;
  7816. if (!string.IsNullOrEmpty(translateResult1))
  7817. {
  7818. str1 = translateResult1;
  7819. str1 = _airTicketResRep.Processing(str1);
  7820. }
  7821. EndCity = str1;
  7822. }
  7823. air.Destination = starCity + "/" + EndCity;
  7824. air.Flight = FlightsCode[i];
  7825. string str = "--";
  7826. string translateResult = transDic.Where(s => s.Key == item.CTypeName).FirstOrDefault().Value;
  7827. if (!string.IsNullOrEmpty(translateResult))
  7828. {
  7829. str = translateResult;
  7830. str = _airTicketResRep.Processing(str);
  7831. }
  7832. air.SeatingClass = str;
  7833. string dateTime = tempstr[2];
  7834. string DateTemp = dateTime.Substring(2, 5).ToUpper();
  7835. air.FlightDate = DateTemp;
  7836. air.DepartureTime = tempstr[5];
  7837. air.LandingTime = tempstr[6];
  7838. air.ValidityPeriod = DateTemp + "/" + DateTemp;
  7839. air.TicketStatus = "--";
  7840. air.Luggage = "--";
  7841. air.DepartureTerminal = "--";
  7842. air.LandingTerminal = "--";
  7843. airs.Add(air);
  7844. }
  7845. int row = 13;
  7846. for (int i = 0; i < airs.Count; i++)
  7847. {
  7848. if (airs.Count > 2)
  7849. {
  7850. for (int j = 0; j < airs.Count - 2; j++)
  7851. {
  7852. var CopyRow = table.Rows[12].Clone(true);
  7853. table.Rows.Add(CopyRow);
  7854. }
  7855. }
  7856. PropertyInfo[] properties = airs[i].GetType().GetProperties();
  7857. int index = 0;
  7858. foreach (PropertyInfo property in properties)
  7859. {
  7860. string value = property.GetValue(airs[i]).ToString();
  7861. Cell ishcel0 = table.Rows[row].Cells[index];
  7862. var p = new Paragraph(doc);
  7863. string s = value;
  7864. p.AppendChild(new Run(doc, s));
  7865. p.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐
  7866. ishcel0.AppendChild(p);
  7867. ishcel0.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
  7868. //ishcel0.CellFormat.VerticalAlignment=
  7869. index++;
  7870. }
  7871. row++;
  7872. }
  7873. #endregion
  7874. var lastParagraph = new Paragraph(doc);
  7875. //第一个表格末尾加段落
  7876. table.ParentNode.InsertAfter(lastParagraph, table);
  7877. //复制第一个表格
  7878. Table cloneTable = (Table)table.Clone(true);
  7879. //在文档末尾段落后面加入复制的表格
  7880. table.ParentNode.InsertAfter(cloneTable, lastParagraph);
  7881. if (item != _AirTicketReservations[_AirTicketReservations.Count - 1])
  7882. {
  7883. int rownewsIndex = 13;
  7884. for (int i = 0; i < 2; i++)
  7885. {
  7886. var CopyRow = table.Rows[12].Clone(true);
  7887. table.Rows.RemoveAt(13);
  7888. table.Rows.Add(CopyRow);
  7889. rownewsIndex++;
  7890. }
  7891. }
  7892. else
  7893. {
  7894. table.Rows.RemoveAt(12);
  7895. }
  7896. cloneTable.Rows.RemoveAt(12);
  7897. }
  7898. if (_AirTicketReservations.Count != 0)
  7899. {
  7900. string[] FlightsCode = _AirTicketReservations[0].FlightsCode.Split('/');
  7901. if (FlightsCode.Length != 0)
  7902. {
  7903. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  7904. if (_AirCompany != null)
  7905. {
  7906. string str = "--";
  7907. string translateResult = transDic.Where(s => s.Key == _AirCompany.CnName).FirstOrDefault().Value;
  7908. if (!string.IsNullOrEmpty(translateResult))
  7909. {
  7910. str = translateResult;
  7911. str = _airTicketResRep.Processing(str);
  7912. }
  7913. table.Range.Bookmarks["AirlineCompany"].Text = str;
  7914. }
  7915. else
  7916. {
  7917. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  7918. }
  7919. }
  7920. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  7921. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  7922. string[] nameArray = Regex.Split(_AirTicketReservations[0].ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  7923. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  7924. string names = "";
  7925. foreach (string clientName in nameArray)
  7926. {
  7927. names += clientName + ",";
  7928. }
  7929. if (!string.IsNullOrWhiteSpace(names))
  7930. {
  7931. string str = "--";
  7932. string translateResult = transDic.Where(s => s.Key == names).FirstOrDefault().Value;
  7933. if (!string.IsNullOrEmpty(translateResult))
  7934. {
  7935. str = translateResult;
  7936. str = _airTicketResRep.Processing(str);
  7937. }
  7938. table.Range.Bookmarks["ClientName"].Text = str;
  7939. }
  7940. else
  7941. {
  7942. table.Range.Bookmarks["ClientName"].Text = "--";
  7943. }
  7944. table.Range.Bookmarks["TicketNumber"].Text = "--";
  7945. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  7946. table.Range.Bookmarks["JointTicket"].Text = "--";
  7947. table.Range.Bookmarks["TimeIssue"].Text = "--";
  7948. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  7949. table.Range.Bookmarks["NavigationCode"].Text = "--";
  7950. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  7951. table.Range.Bookmarks["AgentPhone"].Text = "--";
  7952. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  7953. }
  7954. doc.MailMerge.Execute(new[] { "PageCount" }, new object[] { doc.PageCount });
  7955. //保存合并后的文档
  7956. string fileName = "AirItinerary/电子客票英文行程单_EN.docx";
  7957. string rst = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + fileName;
  7958. doc.Save(AppSettingsHelper.Get("WordBasePath") + fileName);
  7959. return Ok(JsonView(true, "成功!", rst));
  7960. }
  7961. }
  7962. }
  7963. catch (Exception ex)
  7964. {
  7965. return Ok(JsonView(StatusCodes.Status400BadRequest, "程序错误!", ""));
  7966. throw;
  7967. }
  7968. }
  7969. #endregion
  7970. #region 团组增减款项 --> 其他款项
  7971. /// <summary>
  7972. /// 团组增减款项下拉框绑定
  7973. /// </summary>
  7974. /// <param name="dto"></param>
  7975. /// <returns></returns>
  7976. [HttpPost]
  7977. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7978. public async Task<IActionResult> DecreasePaymentsSelect(DecreasePaymentsDto dto)
  7979. {
  7980. #region 参数验证
  7981. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  7982. if (dto.CTId < 1) return Ok(JsonView(false, "请传入有效的CTId参数!"));
  7983. #endregion
  7984. return Ok(await _decreasePaymentsRep.DecreasePaymentsSelect(dto));
  7985. }
  7986. /// <summary>
  7987. /// 根据团组Id查询团组增减款项
  7988. /// </summary>
  7989. /// <param name="dto"></param>
  7990. /// <returns></returns>
  7991. [HttpPost]
  7992. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7993. public async Task<IActionResult> DecreasePaymentsList(DecreasePaymentsListDto dto)
  7994. {
  7995. #region 参数验证
  7996. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  7997. if (dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId参数!"));
  7998. #endregion
  7999. return Ok(await _decreasePaymentsRep.DecreasePaymentsList(dto));
  8000. }
  8001. /// <summary>
  8002. /// 团组增减款项操作(Status:1.新增,2.修改)
  8003. /// </summary>
  8004. /// <param name="dto"></param>
  8005. /// <returns></returns>
  8006. [HttpPost]
  8007. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8008. public async Task<IActionResult> OpDecreasePayments(DecreasePaymentsOpDto dto)
  8009. {
  8010. JsonView groupData = await _decreasePaymentsRep.OpDecreasePayments(dto);
  8011. if (groupData.Code != 200)
  8012. {
  8013. return Ok(JsonView(false, groupData.Msg));
  8014. }
  8015. #region 应用推送
  8016. //int otherId = (int)groupData.Data.GetType().GetProperty("dataId").GetValue(groupData.Data, null);
  8017. //int ccpId = (int)groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  8018. //int sign = (int)groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  8019. int otherId = Convert.ToInt32(groupData.Data.GetType().GetProperty("dataId").GetValue(groupData.Data, null) ?? 0);
  8020. int ccpId = Convert.ToInt32(groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null) ?? 0);
  8021. int sign = Convert.ToInt32(groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null) ?? 0);
  8022. bool recheck = Convert.ToBoolean(groupData.Data.GetType().GetProperty("recheck").GetValue(groupData.Data, null) ?? "True");
  8023. if (recheck)
  8024. {
  8025. //自动审核
  8026. var autoAdit = await _feeAuditRep.FeeAutomaticAudit(3, dto.DiId, otherId);
  8027. }
  8028. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  8029. //2024-10-21 新增LZ UID
  8030. var userIds = new List<int>() { 21 };
  8031. string title = $"系统通知";
  8032. string content = "";
  8033. var diId = dto.DiId;
  8034. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  8035. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  8036. if (dto.Status == 1) content = $"[新增-其他款项({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  8037. else if (dto.Status == 2) content = $"[更新-其他款项({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  8038. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  8039. //await APNsTools.iOS_PushNotifications1("051", $"其他款项费用审核", "", content);
  8040. #endregion
  8041. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  8042. }
  8043. /// <summary>
  8044. /// 团组增减款项操作 删除
  8045. /// </summary>
  8046. /// <param name="dto"></param>
  8047. /// <returns></returns>
  8048. [HttpPost]
  8049. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8050. public async Task<IActionResult> DelDecreasePayments(DelBaseDto dto)
  8051. {
  8052. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数!"));
  8053. if (dto.DeleteUserId < 1) return Ok(JsonView(false, "请传入有效的DeleteUserId参数!"));
  8054. var res = await _decreasePaymentsRep._Del(dto.Id, dto.DeleteUserId);
  8055. if (res.Code == 0) return Ok(JsonView(true, "删除成功!"));
  8056. return Ok(JsonView(false, res?.Msg ?? "删除失败!"));
  8057. }
  8058. /// <summary>
  8059. /// 根据团组增减款项Id查询
  8060. /// </summary>
  8061. /// <param name="dto"></param>
  8062. /// <returns></returns>
  8063. [HttpPost]
  8064. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8065. public async Task<IActionResult> QueryDecreasePaymentsById(DecreasePaymentsByIdDto dto)
  8066. {
  8067. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的数据Id!"));
  8068. return Ok(await _decreasePaymentsRep.QueryDecreasePaymentsById(dto));
  8069. }
  8070. /// <summary>
  8071. /// 查询供应商名称
  8072. /// </summary>
  8073. /// <param name="dto"></param>
  8074. /// <returns></returns>
  8075. [HttpPost]
  8076. public IActionResult QueryAssociateSupplier(AssociateSupplierDto dto)
  8077. {
  8078. var dbResult = _sqlSugar.Queryable<Grp_DecreasePayments>()
  8079. .Where(x => x.SupplierName.Contains(dto.param) && x.IsDel == 0).ToList()
  8080. ?? new List<Grp_DecreasePayments>();
  8081. dbResult = dbResult.Distinct(new
  8082. ProductComparer()).ToList();
  8083. var jw = JsonView(true, "success", dbResult.OrderByDescending(x => x.Id).Select(x => new
  8084. {
  8085. x.Id,
  8086. x.SupplierAddress,
  8087. x.SupplierArea,
  8088. x.SupplierContact,
  8089. x.SupplierContactNumber,
  8090. x.SupplierEmail,
  8091. x.SupplierName,
  8092. x.SupplierSocialAccount,
  8093. x.SupplierTypeId,
  8094. }).ToList());
  8095. return Ok(jw);
  8096. }
  8097. /// <summary>
  8098. /// 团组增减款项 OTA匹配
  8099. /// </summary>
  8100. /// <param name="file"></param>
  8101. /// <returns></returns>
  8102. [HttpPost]
  8103. public async Task<IActionResult> DecreasePaymentsOTAMate(IFormFile file)
  8104. {
  8105. if (file.Length < 1) return Ok(JsonView(false, "请上传文件!"));
  8106. string fileName = file.FileName;
  8107. if (!fileName.EndsWith(".xlsx") && !fileName.EndsWith(".xls"))
  8108. {
  8109. return Ok(JsonView(false, "请上传Excel文件!"));
  8110. }
  8111. //D:\FTP\File\OA2023\Office\GrpFile\团组增减款项相关文件\团组其他款项(OTA)
  8112. var path = @$"{AppSettingsHelper.Get("GrpFileBasePath")}团组增减款项相关文件/团组其他款项(OTA)";
  8113. if (!Directory.Exists(path))
  8114. {
  8115. Directory.CreateDirectory(path);
  8116. }
  8117. var filePath = @$"{path}/{fileName}";
  8118. //保存文件
  8119. using (FileStream fs = System.IO.File.Create(filePath))
  8120. {
  8121. file.CopyTo(fs);
  8122. fs.Flush();
  8123. }
  8124. if (!System.IO.File.Exists(filePath)) return Ok(JsonView(false, "文件不存在!"));
  8125. //读取ExcelFile
  8126. DataTable dt = ConvertExcelToDataTable(filePath);
  8127. if (dt == null) return Ok(JsonView(false, $"您上传的Excel工作表没有内容,请检查!!!"));
  8128. dt.TableName = "TB";
  8129. //修改table列名
  8130. dt.Columns[0].ColumnName = "OrderNo"; // 订单号
  8131. dt.Columns[1].ColumnName = "OTAOrderNo"; // OTA订单号
  8132. dt.Columns[2].ColumnName = "PackageName"; // 套餐名
  8133. dt.Columns[3].ColumnName = "IsPay"; // 是否支付
  8134. dt.Columns[4].ColumnName = "IsShipments"; // 是否发货
  8135. dt.Columns[5].ColumnName = "IsSendBack"; // 是否寄回
  8136. dt.Columns[6].ColumnName = "OpUser"; // 使用人信息
  8137. dt.Columns[7].ColumnName = "OrderTime"; // 下单时间
  8138. dt.Columns[8].ColumnName = "UseTime"; // 使用时间
  8139. dt.Columns[9].ColumnName = "Quantity"; // 台数
  8140. dt.Columns[10].ColumnName = "Days"; // 租赁天数
  8141. dt.Columns[11].ColumnName = "QuantityShipped";// 发货数量
  8142. dt.Columns[12].ColumnName = "TotalPrice"; // 总金额
  8143. dt.Columns[13].ColumnName = "GroupName"; // 团组名称
  8144. dt.Columns[14].ColumnName = "OATotalPrice"; // OA金额
  8145. var otaOrderNos = new List<string>();
  8146. foreach (DataRow item in dt.Rows)
  8147. {
  8148. otaOrderNos.Add(item["OTAOrderNo"].ToString());
  8149. }
  8150. var oaDatas = await _sqlSugar.Queryable<Grp_DecreasePayments>()
  8151. .LeftJoin<Grp_DelegationInfo>((dp, di) => dp.DiId == di.Id)
  8152. .Where((dp, di) => dp.IsDel == 0 && dp.PriceName.Contains("wifi") || otaOrderNos.Contains(dp.OTAOrderNo))
  8153. .Select((dp, di) => new
  8154. {
  8155. dp.PriceName,
  8156. dp.OTAOrderNo,
  8157. dp.FeeTotal,
  8158. di.TeamName,
  8159. })
  8160. .ToListAsync();
  8161. foreach (DataRow item in dt.Rows)
  8162. {
  8163. var otaOrderNo = item["OTAOrderNo"].ToString();
  8164. var oaData = oaDatas.Find(x => !string.IsNullOrEmpty(x.OTAOrderNo) && x.OTAOrderNo.Contains(otaOrderNo));
  8165. if (oaData == null) continue;
  8166. item["GroupName"] = oaData.TeamName;
  8167. item["OATotalPrice"] = oaData.FeeTotal.ToString("#0.00");
  8168. }
  8169. string fileName1 = $"OTA_WIFI费用{DateTime.Now:yyyyMMddHHmmss}.xls";
  8170. var pairs = new Dictionary<string, object>();
  8171. var datas = new List<DataTable>
  8172. {
  8173. dt
  8174. };
  8175. url = AsposeHelper.ExpertExcelToModel("WIFI费用清单-模板.xlsx", $"GrpFile/团组增减款项相关文件/团组其他款项(OTA)", fileName1, pairs, datas);
  8176. return Ok(JsonView(true, "操作成功", new { url }));
  8177. }
  8178. #region
  8179. private static DataTable ConvertExcelToDataTable(string excelFilePath)
  8180. {
  8181. // 创建Workbook对象
  8182. var workbook = new Workbook(excelFilePath);
  8183. // 获取第一个工作表
  8184. var worksheet = workbook.Worksheets[0];
  8185. // 将工作表转换为DataTable
  8186. DataTable dataTable = worksheet.Cells.ExportDataTable(1, 0, worksheet.Cells.MaxDataRow + 1, worksheet.Cells.MaxDataColumn + 1);
  8187. return dataTable;
  8188. }
  8189. #endregion
  8190. /// <summary>
  8191. /// 世运会数据
  8192. /// </summary>
  8193. /// <returns></returns>
  8194. [HttpGet]
  8195. public IActionResult WorldGamesData()
  8196. {
  8197. var setData = _sqlSugar.Queryable<Grp_GamesBudgetMaster>().Where(x => x.IsDel == 0).ToList();
  8198. var groupMenu = setData.GroupBy(x => x.T0);
  8199. var resultArr = new List<DecreasePaymentsWorldGamesDataView>();
  8200. foreach (var item in groupMenu)
  8201. {
  8202. resultArr.Add(new DecreasePaymentsWorldGamesDataView
  8203. {
  8204. Data = new SetDataView
  8205. {
  8206. Name = item.Key
  8207. },
  8208. Child = item.Select(x => x.CalculationContent).ToList() ?? new List<string>()
  8209. });
  8210. }
  8211. return Ok(JsonView(true, "success", resultArr));
  8212. }
  8213. #endregion
  8214. #region 文件上传、删除
  8215. /// <summary>
  8216. /// region 文件上传 可以带参数
  8217. /// </summary>
  8218. /// <param name="file"></param>
  8219. /// <returns></returns>
  8220. [HttpPost]
  8221. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8222. public async Task<IActionResult> UploadProject(IFormFile file)
  8223. {
  8224. //var TypeName = Request.Headers["TypeName"].ToString();
  8225. //if (file == null) return Ok(JsonView(false, "文件不存在!"));
  8226. //var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  8227. ////文件名称
  8228. //string projectFileName = file.FileName;
  8229. ////上传的文件的路径
  8230. //string filePath = $"{fileDir}/{projectFileName}";
  8231. //if (TypeName == "A")//A代表团组增减款项
  8232. //{
  8233. // filePath = fileDir + $@"\团组增减款项相关文件";
  8234. // if (!Directory.Exists(filePath))
  8235. // {
  8236. // Directory.CreateDirectory(filePath);
  8237. // }
  8238. // //上传的文件的路径
  8239. // filePath += $@"\{projectFileName}";
  8240. //}
  8241. //else if (TypeName == "B")//B代表商邀相关文件
  8242. //{
  8243. // //上传的文件的路径
  8244. // filePath = fileDir + $@"\商邀相关文件\{projectFileName}";
  8245. // if (!Directory.Exists(filePath))
  8246. // {
  8247. // Directory.CreateDirectory(filePath);
  8248. // }
  8249. // //上传的文件的路径
  8250. // filePath = $@"\{projectFileName}";
  8251. //}
  8252. //try
  8253. //{
  8254. // using (FileStream fs = System.IO.File.Create(filePath))
  8255. // {
  8256. // file.CopyTo(fs);
  8257. // fs.Flush();
  8258. // }
  8259. //}
  8260. //catch (Exception ex)
  8261. //{
  8262. // return Ok(JsonView(false, $"文件上传失败! Error:{ex.Message}"));
  8263. //}
  8264. //return Ok(JsonView(true, "上传成功!", projectFileName));
  8265. try
  8266. {
  8267. var TypeName = Request.Headers["TypeName"].ToString();
  8268. if (file != null)
  8269. {
  8270. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  8271. //文件名称
  8272. string projectFileName = file.FileName;
  8273. //上传的文件的路径
  8274. string filePath = $"{fileDir}/{projectFileName}";
  8275. if (TypeName == "A")//A代表团组增减款项
  8276. {
  8277. if (!Directory.Exists(fileDir))
  8278. {
  8279. Directory.CreateDirectory(fileDir);
  8280. }
  8281. //上传的文件的路径
  8282. filePath = fileDir + $@"\团组增减款项相关文件\{projectFileName}";
  8283. }
  8284. else if (TypeName == "B")//B代表商邀相关文件
  8285. {
  8286. if (!Directory.Exists(fileDir))
  8287. {
  8288. Directory.CreateDirectory(fileDir);
  8289. }
  8290. //上传的文件的路径
  8291. filePath = fileDir + $@"\商邀相关文件\{projectFileName}";
  8292. }
  8293. using (FileStream fs = System.IO.File.Create(filePath))
  8294. {
  8295. file.CopyTo(fs);
  8296. fs.Flush();
  8297. }
  8298. return Ok(JsonView(true, "上传成功!", projectFileName));
  8299. }
  8300. else
  8301. {
  8302. return Ok(JsonView(false, "上传失败!"));
  8303. }
  8304. }
  8305. catch (Exception ex)
  8306. {
  8307. return Ok(JsonView(false, ex.Message));
  8308. }
  8309. }
  8310. /// <summary>
  8311. /// 删除指定文件
  8312. /// </summary>
  8313. /// <param name="dto"></param>
  8314. /// <returns></returns>
  8315. [HttpPost]
  8316. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8317. public async Task<IActionResult> DelFile(DelFileDto dto)
  8318. {
  8319. try
  8320. {
  8321. var TypeName = Request.Headers["TypeName"].ToString();
  8322. if (string.IsNullOrEmpty(TypeName)) return Ok(JsonView(false, "请选择选组对应模块!"));
  8323. string filePath = "";
  8324. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  8325. // 返回与指定虚拟路径相对应的物理路径即绝对路径
  8326. int id = 0;
  8327. if (TypeName == "A")
  8328. {
  8329. filePath = fileDir + "/团组增减款项相关文件/" + dto.fileName;
  8330. // 删除该文件
  8331. System.IO.File.Delete(filePath);
  8332. id = await _sqlSugar.Updateable<Grp_DecreasePayments>()
  8333. .Where(a => a.Id == dto.Id)
  8334. .SetColumns(a => new Grp_DecreasePayments { FilePath = "" })
  8335. .ExecuteCommandAsync();
  8336. }
  8337. else if (TypeName == "B")
  8338. {
  8339. filePath = fileDir + "/商邀相关文件/" + dto.fileName;
  8340. // 删除该文件
  8341. System.IO.File.Delete(filePath);
  8342. var info = await _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(x => x.Id == dto.Id && x.IsDel == 0).FirstAsync();
  8343. if (info != null)
  8344. {
  8345. string[] files = Array.Empty<string>();
  8346. if (!string.IsNullOrEmpty(info.Attachment))
  8347. {
  8348. try
  8349. {
  8350. files = JsonConvert.DeserializeObject<string[]>(info.Attachment);
  8351. }
  8352. catch (Exception)
  8353. {
  8354. files = new List<string>() { info.Attachment }.ToArray();
  8355. }
  8356. }
  8357. if (files.Length > 0)
  8358. {
  8359. var files1 = files.Where(x => !x.Equals(dto.fileName)).ToArray();
  8360. string filePath2 = string.Empty;
  8361. if (files1.Length > 0)
  8362. {
  8363. filePath2 = JsonConvert.SerializeObject(files1);
  8364. }
  8365. id = await _sqlSugar.Updateable<Grp_InvitationOfficialActivities>()
  8366. .Where(a => a.Id == dto.Id)
  8367. .SetColumns(a => new Grp_InvitationOfficialActivities { Attachment = filePath2 })
  8368. .ExecuteCommandAsync();
  8369. }
  8370. }
  8371. }
  8372. if (id != 0)
  8373. {
  8374. return Ok(JsonView(true, "成功!"));
  8375. }
  8376. else
  8377. {
  8378. return Ok(JsonView(false, "失败!"));
  8379. }
  8380. }
  8381. catch (Exception ex)
  8382. {
  8383. return Ok(JsonView(false, "程序错误!"));
  8384. throw;
  8385. }
  8386. }
  8387. /// <summary>
  8388. /// 文件上传多个文件 可以带参数
  8389. /// </summary>
  8390. /// <param name="files"></param>
  8391. /// <returns></returns>
  8392. [HttpPost]
  8393. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8394. public async Task<IActionResult> UploadProjects(IFormFile[] files)
  8395. {
  8396. try
  8397. {
  8398. var TypeName = Request.Headers["TypeName"].ToString();
  8399. if (string.IsNullOrEmpty(TypeName)) return Ok(JsonView(false, "请选择选组对应模块!"));
  8400. if (files.Length < 1) return Ok(JsonView(false, "请选择文件!"));
  8401. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  8402. var filePahts = new List<string>();
  8403. foreach (var file in files)
  8404. {
  8405. //文件名称
  8406. string projectFileName = file.FileName;
  8407. //上传的文件的路径
  8408. string filePath = $"{fileDir}/{projectFileName}";
  8409. if (TypeName == "A")//A代表团组增减款项
  8410. {
  8411. if (!Directory.Exists(fileDir))
  8412. {
  8413. Directory.CreateDirectory(fileDir);
  8414. }
  8415. //上传的文件的路径
  8416. filePath = fileDir + $@"\团组增减款项相关文件\{projectFileName}";
  8417. }
  8418. else if (TypeName == "B")//B代表商邀相关文件
  8419. {
  8420. if (!Directory.Exists(fileDir))
  8421. {
  8422. Directory.CreateDirectory(fileDir);
  8423. }
  8424. //上传的文件的路径
  8425. filePath = fileDir + $@"\商邀相关文件\{projectFileName}";
  8426. }
  8427. using (FileStream fs = System.IO.File.Create(filePath))
  8428. {
  8429. file.CopyTo(fs);
  8430. fs.Flush();
  8431. }
  8432. filePahts.Add(projectFileName);
  8433. }
  8434. return Ok(JsonView(true, "上传成功!", filePahts));
  8435. }
  8436. catch (Exception ex)
  8437. {
  8438. return Ok(JsonView(false, ex.Message));
  8439. }
  8440. }
  8441. #endregion
  8442. #region 商邀费用录入
  8443. /// <summary>
  8444. /// 根据团组Id查询商邀费用列表
  8445. /// </summary>
  8446. /// <param name="dto"></param>
  8447. /// <returns></returns>
  8448. [HttpPost]
  8449. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8450. public async Task<IActionResult> InvitationOfficialActivitiesList(InvitationOfficialActivitiesListDto dto)
  8451. {
  8452. Result groupData = await _InvitationOfficialActivitiesRep.InvitationOfficialActivitiesList(dto);
  8453. if (groupData.Code != 0)
  8454. {
  8455. return Ok(JsonView(false, groupData.Msg));
  8456. }
  8457. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  8458. }
  8459. /// <summary>
  8460. /// 商邀费用列表
  8461. /// 下载文件
  8462. /// </summary>
  8463. /// <param name="id"></param>
  8464. /// <returns></returns>
  8465. [HttpGet("{id}")]
  8466. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8467. public async Task<IActionResult> InvitationOfficialActivitiesListDownFile(int id)
  8468. {
  8469. if (id < 1) return Ok(JsonView(false, "请传入有效的Id!"));
  8470. var info = await _InvitationOfficialActivitiesRep.Query(x => x.Id == id).FirstAsync();
  8471. if (info == null) return Ok(JsonView(false, "数据不存在!"));
  8472. if (string.IsNullOrEmpty(info.Attachment)) return Ok(JsonView(false, "文件不存在!"));
  8473. var filePaths = new List<string>();
  8474. var filePathBase = @$"{AppSettingsHelper.Get("GrpFileBasePath")}/商邀相关文件/";
  8475. try
  8476. {
  8477. filePaths = JsonConvert.DeserializeObject<List<string>>(info.Attachment);
  8478. }
  8479. catch (Exception ex)
  8480. {
  8481. filePaths.Add(info.Attachment);
  8482. }
  8483. if (filePaths != null && filePaths.Count < 1) return Ok(JsonView(false, "文件不存在!"));
  8484. for (int i = 0; i < filePaths.Count; i++)
  8485. {
  8486. filePaths[i] = $"{filePathBase}{filePaths[i]}";
  8487. }
  8488. var zipFilePathGuid = $"{Guid.NewGuid()}.zip";
  8489. var zipFilePath = $"{AppSettingsHelper.Get("GrpFileBasePath")}/商邀相关文件/{zipFilePathGuid}";
  8490. using (var zipFileStream = new FileStream(zipFilePath, FileMode.Create))
  8491. {
  8492. using (var zipArchive = new ZipArchive(zipFileStream, ZipArchiveMode.Create))
  8493. {
  8494. foreach (string filePath in filePaths)
  8495. {
  8496. if (System.IO.File.Exists(filePath))
  8497. {
  8498. // 获取文件名
  8499. string fileName = Path.GetFileName(filePath);
  8500. // 将文件添加到ZIP归档中
  8501. zipArchive.CreateEntryFromFile(filePath, fileName);
  8502. }
  8503. }
  8504. }
  8505. }
  8506. return Ok(JsonView(new { url = @$"{AppSettingsHelper.Get("OfficeBaseUrl")}{AppSettingsHelper.Get("GrpFileFtpPath")}/商邀相关文件/{zipFilePathGuid}" }));
  8507. }
  8508. /// <summary>
  8509. /// 商邀费用 Info Page 基础数据源
  8510. /// </summary>
  8511. /// <returns></returns>
  8512. [HttpPost]
  8513. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8514. public async Task<IActionResult> InvitationOfficialActivityInitBasicData()
  8515. {
  8516. try
  8517. {
  8518. Result groupData = await _InvitationOfficialActivitiesRep.InitBasicData();
  8519. if (groupData.Code != 0)
  8520. {
  8521. return Ok(JsonView(false, groupData.Msg));
  8522. }
  8523. return Ok(JsonView(true, "操作成功", groupData.Data));
  8524. }
  8525. catch (Exception ex)
  8526. {
  8527. return Ok(JsonView(false, ex.Message));
  8528. throw;
  8529. }
  8530. }
  8531. /// <summary>
  8532. /// 根据商邀费用ID查询C表和商邀费用数据
  8533. /// </summary>
  8534. /// <param name="dto"></param>
  8535. /// <returns></returns>
  8536. [HttpPost]
  8537. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8538. public async Task<IActionResult> InvitationOfficialActivitiesById(InvitationOfficialActivitiesByIdDto dto)
  8539. {
  8540. try
  8541. {
  8542. Result groupData = await _InvitationOfficialActivitiesRep.InvitationOfficialActivitiesById(dto);
  8543. if (groupData.Code != 0)
  8544. {
  8545. return Ok(JsonView(false, groupData.Msg));
  8546. }
  8547. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  8548. }
  8549. catch (Exception ex)
  8550. {
  8551. return Ok(JsonView(false, ex.Message));
  8552. throw;
  8553. }
  8554. }
  8555. /// <summary>
  8556. /// 商邀费用录入操作(Status:1.新增,2.修改)
  8557. /// </summary>
  8558. /// <param name="dto"></param>
  8559. /// <returns></returns>
  8560. [HttpPost]
  8561. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8562. public async Task<IActionResult> OpInvitationOfficialActivities(OpInvitationOfficialActivitiesDto dto)
  8563. {
  8564. Result groupData = await _InvitationOfficialActivitiesRep.OpInvitationOfficialActivities(dto, _setDataRep.PostCurrencyByDiid);
  8565. if (groupData.Code != 0)
  8566. {
  8567. return Ok(JsonView(false, groupData.Msg));
  8568. }
  8569. #region 应用推送
  8570. try
  8571. {
  8572. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  8573. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  8574. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  8575. //2024-10-21 新增LZ UID
  8576. var userIds = new List<int>() { 21 };
  8577. string title = $"系统通知";
  8578. string content = "";
  8579. var diId = dto.DiId;
  8580. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  8581. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  8582. if (dto.Status == 1) content = $"[新增-商邀费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  8583. else if (dto.Status == 2) content = $"[更新-商邀费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  8584. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  8585. var h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "81" };
  8586. await APNsTools.iOS_PushNotifications1("051", $"商邀费用审核", "", content, true, "ExpenseAuditWebView", h5);
  8587. }
  8588. catch (Exception ex)
  8589. {
  8590. }
  8591. #endregion
  8592. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  8593. }
  8594. /// <summary>
  8595. /// 商邀删除
  8596. /// </summary>
  8597. /// <param name="dto"></param>
  8598. /// <returns></returns>
  8599. [HttpPost]
  8600. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8601. public async Task<IActionResult> DelInvitationOfficialActivities(DelBaseDto dto)
  8602. {
  8603. try
  8604. {
  8605. _sqlSugar.BeginTran();
  8606. var res1 = _sqlSugar.Updateable<Grp_InvitationOfficialActivities>()
  8607. .SetColumns(it => new Grp_InvitationOfficialActivities()
  8608. {
  8609. IsDel = 1,
  8610. DeleteUserId = dto.DeleteUserId,
  8611. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  8612. })
  8613. .Where(it => it.Id == dto.Id)
  8614. .ExecuteCommand();
  8615. if (res1 > 0)
  8616. {
  8617. int _diId = 0;
  8618. var _ioaInfo = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(it => it.Id == dto.Id).First();
  8619. if (_ioaInfo != null)
  8620. {
  8621. _diId = _ioaInfo.DiId;
  8622. }
  8623. var res2 = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  8624. .SetColumns(a => new Grp_CreditCardPayment()
  8625. {
  8626. IsDel = 1,
  8627. DeleteUserId = dto.DeleteUserId,
  8628. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  8629. })
  8630. .Where(a => a.CId == dto.Id && a.DIId == _diId && a.CTable == 81)
  8631. .ExecuteCommand();
  8632. if (res2 > 0)
  8633. {
  8634. _sqlSugar.CommitTran();
  8635. return Ok(JsonView(true, "删除成功!"));
  8636. }
  8637. }
  8638. _sqlSugar.RollbackTran();
  8639. return Ok(JsonView(false, "删除失败"));
  8640. }
  8641. catch (Exception ex)
  8642. {
  8643. _sqlSugar.RollbackTran();
  8644. return Ok(JsonView(false, ex.Message));
  8645. }
  8646. }
  8647. #endregion
  8648. #region 票据上传
  8649. /// <summary>
  8650. /// 团组模块文件上传
  8651. /// </summary>
  8652. /// <param name="dto"></param>
  8653. /// <returns></returns>
  8654. [HttpPost]
  8655. public IActionResult CommonSaveFile([FromForm] CommonSaveFileDto dto)
  8656. {
  8657. var jw = JsonView(false);
  8658. long M = 1024 * 1024;
  8659. if (dto.Files == null || dto.Files.Count == 0)
  8660. {
  8661. jw.Msg = "无文件信息!";
  8662. return Ok(jw);
  8663. }
  8664. if (dto.Files.Sum(x => x.Length) > 20 * M)
  8665. {
  8666. jw.Msg = "文件大小超过20M!";
  8667. return Ok(jw);
  8668. }
  8669. //var nameSp = dto.File.FileName.Split(".");
  8670. //if (nameSp.Length < 2)
  8671. //{
  8672. // jw.Msg = "拓展名称有误!";
  8673. // return Ok(jw);
  8674. //}
  8675. //var existsName = new string[]{ "RAR", "ZIP", "ARJ","GZ","Z","7Z","TAR" };
  8676. //if (!existsName.Contains(nameSp[1].ToUpper()))
  8677. //{
  8678. // jw.Msg = $"请使用指定拓展名!({string.Join("-",existsName)})";
  8679. // return Ok(jw);
  8680. //}
  8681. var Ctable = _sqlSugar.Queryable<Sys_SetData>().First(x => x.STid == 16 && x.IsDel == 0 && x.Id == dto.Ctable);
  8682. if (Ctable == null)
  8683. {
  8684. jw.Msg = "Ctable指向有误!";
  8685. return Ok(jw);
  8686. }
  8687. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  8688. if (groupInfo == null)
  8689. {
  8690. jw.Msg = "团组信息不存在!";
  8691. return Ok(jw);
  8692. }
  8693. Ctable.Name = Regex.Replace(Ctable.Name, @"[^\w\.@-]", "",
  8694. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  8695. groupInfo.TeamName = Regex.Replace(groupInfo.TeamName, @"[^\w\.@-]", "",
  8696. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  8697. var path = "\\GroupModelFiles\\" + groupInfo.TeamName + "\\" + Ctable.Name;
  8698. var fileBase = AppSettingsHelper.Get("GrpFileBasePath") + path;
  8699. try
  8700. {
  8701. if (!Directory.Exists(fileBase))
  8702. {
  8703. Directory.CreateDirectory(fileBase);
  8704. }
  8705. var saveArr = new List<Grp_GroupModelFile>();
  8706. foreach (var fileStream in dto.Files)
  8707. {
  8708. var fileName = fileStream.FileName;
  8709. string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
  8710. string extension = Path.GetExtension(fileName);
  8711. int counter = 0;
  8712. //文件重命名验证
  8713. string newFilePath;
  8714. string currFileName;
  8715. do
  8716. {
  8717. string newFileName;
  8718. if (counter == 0) newFileName = $"{fileNameWithoutExtension}{extension}";
  8719. else newFileName = $"{fileNameWithoutExtension} ({counter}){extension}";
  8720. currFileName = newFileName;
  8721. newFilePath = Path.Combine(fileBase, newFileName);
  8722. counter++;
  8723. } while (System.IO.File.Exists(newFilePath));
  8724. var saveFilePath = fileBase + "\\" + currFileName;
  8725. var file = new Grp_GroupModelFile()
  8726. {
  8727. Cid = dto.Cid,
  8728. CreateTime = DateTime.Now,
  8729. CreateUserId = dto.Userid,
  8730. Ctable = dto.Ctable,
  8731. Diid = dto.Diid,
  8732. IsDel = 0,
  8733. FilePath = saveFilePath,
  8734. FileName = currFileName
  8735. };
  8736. using (FileStream fs = System.IO.File.Create(saveFilePath))
  8737. {
  8738. fileStream.CopyTo(fs);
  8739. fs.Flush();
  8740. }
  8741. saveArr.Add(file);
  8742. }
  8743. var addResult = _sqlSugar.Insertable<Grp_GroupModelFile>(saveArr).ExecuteCommand();
  8744. //url = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("GrpFileFtpPath") + path + "\\" + dto.File.FileName
  8745. jw = JsonView(true, "保存成功!", new
  8746. {
  8747. count = addResult,
  8748. filesName = saveArr.Select(x => x.FileName)
  8749. });
  8750. }
  8751. catch (Exception ex)
  8752. {
  8753. jw = JsonView(false, $"保存失败! ({ex.Message}) ", new
  8754. {
  8755. count = 0,
  8756. filesName = Array.Empty<string>(),
  8757. });
  8758. }
  8759. return Ok(jw);
  8760. }
  8761. /// <summary>
  8762. /// 查询各模块已保存文件
  8763. /// </summary>
  8764. /// <param name="dto"></param>
  8765. /// <returns></returns>
  8766. [HttpPost]
  8767. public IActionResult QueryGroupModelFile(QueryGroupModelFileDto dto)
  8768. {
  8769. var expression = Expressionable.Create<Grp_GroupModelFile>()
  8770. .AndIF(dto.UserId != -1, x => x.CreateUserId == dto.UserId);
  8771. var visaIds = _sqlSugar.Queryable<Sys_Users>().Where(x => x.JobPostId == 26).Select(x => x.Id).ToList();
  8772. if (visaIds.Contains(dto.UserId) && dto.Ctable == 80)
  8773. {
  8774. expression = Expressionable.Create<Grp_GroupModelFile>()
  8775. .And(x => visaIds.Contains(x.CreateUserId));
  8776. }
  8777. var dbQuery = _sqlSugar.Queryable<Grp_GroupModelFile>()
  8778. .Where(x => x.IsDel == 0 && x.Cid == dto.Cid && x.Ctable == dto.Ctable && x.Diid == dto.Diid)
  8779. .Where(expression.ToExpression())
  8780. .ToList();
  8781. //.ToPageList(pagenumber, pageSize, ref totalCount, ref totalPage)
  8782. return Ok(JsonView(true, "success", dbQuery.Select(x => new
  8783. {
  8784. x.FileName,
  8785. x.Id,
  8786. Url = AppSettingsHelper.Get("GrpFileBaseUrl") + x.FilePath.Replace(AppSettingsHelper.Get("GrpFileBasePath"), AppSettingsHelper.Get("GrpFileFtpPath")),
  8787. CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH-mm"),
  8788. })));
  8789. }
  8790. /// <summary>
  8791. /// 下载该团组下的所有文件
  8792. /// </summary>
  8793. /// <param name="dto"></param>
  8794. /// <returns></returns>
  8795. [HttpPost]
  8796. public IActionResult ExportGroupZip(ExportGroupZipDto dto)
  8797. {
  8798. var jw = JsonView(false);
  8799. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.IsDel == 0 && x.Id == dto.Diid);
  8800. if (groupInfo == null)
  8801. {
  8802. jw.Msg = "团组信息不存在!";
  8803. return Ok(jw);
  8804. }
  8805. var dbQuery = _sqlSugar.Queryable<Grp_GroupModelFile>().Where(x => x.IsDel == 0 && x.Diid == dto.Diid).ToList();
  8806. var isModule = Convert.ToBoolean(dto.isModule);
  8807. var Zips = new Dictionary<string, Stream>();
  8808. var io = new IOOperatorHelper();
  8809. if (isModule)
  8810. {
  8811. var moduleGroup = dbQuery.GroupBy(x => x.Ctable);
  8812. foreach (var moduleArr in moduleGroup)
  8813. {
  8814. var key = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == moduleArr.Key && x.IsDel == 0);
  8815. key.Name = Regex.Replace(key.Name, @"[^\w\.@-]", "",
  8816. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  8817. var chiZips = new Dictionary<string, Stream>();
  8818. foreach (var item in moduleArr)
  8819. {
  8820. if (System.IO.File.Exists(item.FilePath))
  8821. {
  8822. using (var fileStream = new FileStream(item.FilePath, FileMode.Open, FileAccess.Read))
  8823. {
  8824. byte[] bytes = new byte[fileStream.Length];
  8825. fileStream.Read(bytes, 0, bytes.Length);
  8826. fileStream.Close();
  8827. Stream stream = new MemoryStream(bytes);
  8828. chiZips.Add(item.FileName, stream);
  8829. }
  8830. }
  8831. }
  8832. if (chiZips.Count > 0)
  8833. {
  8834. var byts = io.ConvertZipStream(chiZips);
  8835. Stream stream = new MemoryStream(byts);
  8836. Zips.Add(key.Name + "_.zip", stream);
  8837. }
  8838. }
  8839. }
  8840. else
  8841. {
  8842. foreach (var item in dbQuery)
  8843. {
  8844. using (var fileStream = new FileStream(item.FilePath, FileMode.Open, FileAccess.Read))
  8845. {
  8846. byte[] bytes = new byte[fileStream.Length];
  8847. fileStream.Read(bytes, 0, bytes.Length);
  8848. fileStream.Close();
  8849. var stream = new MemoryStream(bytes);
  8850. while (Zips.ContainsKey(item.FileName))
  8851. {
  8852. item.FileName = new Random().Next(100) + "_" + item.FileName;
  8853. }
  8854. Zips.Add(item.FileName, stream);
  8855. }
  8856. }
  8857. }
  8858. groupInfo.TeamName = Regex.Replace(groupInfo.TeamName, @"[^\w\.@-]", "",
  8859. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  8860. if (Zips.Count > 0)
  8861. {
  8862. var byts = io.ConvertZipStream(Zips);
  8863. var path = "\\GroupModelFiles\\" + groupInfo.TeamName;
  8864. io.ByteToFile(byts, AppSettingsHelper.Get("GrpFileBasePath") + $"{path}\\{groupInfo.TeamName}_.Zip");
  8865. jw = JsonView(true, "success", new { url = AppSettingsHelper.Get("GrpFileBaseUrl") + $"{AppSettingsHelper.Get("GrpFileFtpPath")}{path}\\{groupInfo.TeamName}_.zip" });
  8866. }
  8867. else
  8868. {
  8869. jw.Msg = "暂无生成文件!";
  8870. }
  8871. return Ok(jw);
  8872. }
  8873. /// <summary>
  8874. /// 下载该团组下此模块的所有文件
  8875. /// </summary>
  8876. /// <param name="dto"></param>
  8877. /// <returns></returns>
  8878. [HttpPost]
  8879. public IActionResult ExportGroupByModule(ExportGroupByModuleDto dto)
  8880. {
  8881. var jw = JsonView(false);
  8882. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.IsDel == 0 && x.Id == dto.Diid);
  8883. if (groupInfo == null)
  8884. {
  8885. jw.Msg = "团组信息不存在!";
  8886. return Ok(jw);
  8887. }
  8888. var dbQuery = _sqlSugar.Queryable<Grp_GroupModelFile>().Where(x => x.IsDel == 0 && x.Diid == dto.Diid && x.Ctable == dto.Ctable).ToList();
  8889. var key = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == dto.Ctable
  8890. && x.IsDel == 0);
  8891. if (key == null)
  8892. {
  8893. jw.Msg = "Ctable指向错误!";
  8894. return Ok(jw);
  8895. }
  8896. key.Name = Regex.Replace(key.Name, @"[^\w\.@-]", "",
  8897. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  8898. groupInfo.TeamName = Regex.Replace(groupInfo.TeamName, @"[^\w\.@-]", "",
  8899. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  8900. var io = new IOOperatorHelper();
  8901. var Zips = new Dictionary<string, Stream>();
  8902. foreach (var item in dbQuery)
  8903. {
  8904. if (System.IO.File.Exists(item.FilePath))
  8905. {
  8906. using (var fileStream = new FileStream(item.FilePath, FileMode.Open, FileAccess.Read))
  8907. {
  8908. byte[] bytes = new byte[fileStream.Length];
  8909. fileStream.Read(bytes, 0, bytes.Length);
  8910. fileStream.Close();
  8911. var stream = new MemoryStream(bytes);
  8912. while (Zips.ContainsKey(item.FileName))
  8913. {
  8914. item.FileName = new Random().Next(100) + "_" + item.FileName;
  8915. }
  8916. Zips.Add(item.FileName, stream);
  8917. }
  8918. }
  8919. }
  8920. if (Zips.Count > 0)
  8921. {
  8922. var byts = io.ConvertZipStream(Zips);
  8923. var path = "\\GroupModelFiles\\" + groupInfo.TeamName;
  8924. io.ByteToFile(byts, AppSettingsHelper.Get("GrpFileBasePath") + $"{path}\\{groupInfo.TeamName}_{key.Name}_.Zip");
  8925. jw = JsonView(true, "success", new { url = AppSettingsHelper.Get("GrpFileBaseUrl") + $"{AppSettingsHelper.Get("GrpFileFtpPath")}{path}\\{groupInfo.TeamName}_{key.Name}_.Zip" });
  8926. }
  8927. else
  8928. {
  8929. jw.Msg = "暂无生成文件!";
  8930. }
  8931. return Ok(jw);
  8932. }
  8933. /// <summary>
  8934. /// 删除该团组下的指定文件
  8935. /// </summary>
  8936. /// <param name="dto"></param>
  8937. /// <returns></returns>
  8938. [HttpPost]
  8939. public IActionResult DeleteGroupFile(DeleteGroupFileDto dto)
  8940. {
  8941. var jw = JsonView(false);
  8942. var sing = _sqlSugar.Queryable<Grp_GroupModelFile>().First(x => x.Id == dto.Id && x.IsDel == 0);
  8943. if (sing == null)
  8944. {
  8945. jw.Msg = "暂无";
  8946. return Ok(jw);
  8947. }
  8948. if (System.IO.File.Exists(sing.FilePath))
  8949. {
  8950. try
  8951. {
  8952. System.IO.File.Delete(sing.FilePath);
  8953. }
  8954. catch (Exception ex)
  8955. {
  8956. jw.Msg = "删除失败!" + ex.Message;
  8957. return Ok(jw);
  8958. }
  8959. }
  8960. sing.IsDel = 1;
  8961. sing.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  8962. sing.DeleteUserId = dto.UserId;
  8963. _sqlSugar.Updateable<Grp_GroupModelFile>(sing).ExecuteCommand();
  8964. jw = JsonView(true, "删除成功!");
  8965. return Ok(jw);
  8966. }
  8967. #endregion
  8968. #region 共享文件上传
  8969. /// <summary>
  8970. /// 超支通知推送
  8971. /// </summary>
  8972. /// <param name="dto"></param>
  8973. /// <returns></returns>
  8974. [HttpPost]
  8975. public async Task<IActionResult> qyWeChatNotification(qyWeChatNotificationDto dto)
  8976. {
  8977. //81 邀请/公务活动
  8978. var syCTable = new List<int> { 81 };
  8979. //76 酒店预订
  8980. //79 车/导游地接
  8981. //85 机票预订
  8982. var gjCTable = new List<int> { 76, 79, 85 };
  8983. var jw = JsonView(false);
  8984. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.IsDel == 0 && x.Id == dto.Diid);
  8985. if (di == null)
  8986. {
  8987. jw.Msg = "团组信息不存在!";
  8988. return Ok(jw);
  8989. }
  8990. var user = _sqlSugar.Queryable<Sys_Users>().First(x => x.IsDel == 0 && x.Id == dto.UserId);
  8991. if (user == null)
  8992. {
  8993. jw.Msg = "用户信息不存在!";
  8994. return Ok(jw);
  8995. }
  8996. if (syCTable.Contains(dto.CTable))
  8997. {
  8998. await AppNoticeLibrary.SendChatMsg_ExpenseOverrunsChat(dto.Diid, dto.UserId, dto.CTable, QiyeWeChatEnum.ExpenseOverrunsChat02);
  8999. }
  9000. else if (gjCTable.Contains(dto.CTable))
  9001. {
  9002. await AppNoticeLibrary.SendChatMsg_ExpenseOverrunsChat(dto.Diid, dto.UserId, dto.CTable, QiyeWeChatEnum.ExpenseOverrunsChat01);
  9003. }
  9004. else
  9005. {
  9006. jw.Msg = "CTABLE类型有误!";
  9007. }
  9008. jw = JsonView(true, "推送成功!", "");
  9009. return Ok(jw);
  9010. }
  9011. /// <summary>
  9012. /// 共享文件数据初始化
  9013. /// </summary>
  9014. /// <returns></returns>
  9015. [HttpGet]
  9016. public async Task<IActionResult> SharedFileInit(int userid, int portType)
  9017. {
  9018. var marketingDepartmentIds = new List<int> { 6, 26, 27, 28 };
  9019. var isMarketingDepartment = _sqlSugar.Queryable<Sys_Users>()
  9020. .Where(x => x.IsDel == 0 && marketingDepartmentIds.Contains(x.DepId))
  9021. .Select(x => x.Id)
  9022. .ToList()
  9023. .Contains(userid);
  9024. var dropDownType = _sqlSugar.Queryable<Sys_SetData>()
  9025. .Where(x => x.STid == 111 && x.IsDel == 0)
  9026. .Select(x => new
  9027. {
  9028. x.Name,
  9029. x.Id,
  9030. }).ToList();
  9031. if (isMarketingDepartment)
  9032. {
  9033. dropDownType = dropDownType.Where(x => x.Id == 1412).ToList();
  9034. }
  9035. if (portType == 1)
  9036. {
  9037. var provCityDatas = await _groupRepository.ProvinceCityBasicSource();
  9038. var dropDownGroupList = _sqlSugar.Queryable<Grp_DelegationInfo>()
  9039. .Where(x => x.IsDel == 0)
  9040. .OrderByDescending(x => x.VisitDate)
  9041. .Select(x => new
  9042. {
  9043. x.TeamName,
  9044. x.Id,
  9045. x.CityId,
  9046. })
  9047. .ToList()
  9048. .Select(x =>
  9049. {
  9050. var provinceId = x.CityId;
  9051. var isDefualtVal = true;
  9052. if (provinceId > 0)
  9053. {
  9054. var parentId = _groupRepository.FindParentIdByChildId(provCityDatas, provinceId);
  9055. if (parentId != null)
  9056. {
  9057. isDefualtVal = false;
  9058. provinceId = (int)parentId;
  9059. }
  9060. }
  9061. if (isDefualtVal)
  9062. {
  9063. provinceId = 122; //默认四川
  9064. }
  9065. return new
  9066. {
  9067. x.TeamName,
  9068. x.Id,
  9069. provinceId,
  9070. };
  9071. })
  9072. .ToList();
  9073. return Ok(JsonView(true, "SUCCESS!", new
  9074. {
  9075. dropDownType,
  9076. dropDownGroupList,
  9077. isMarketingDepartment
  9078. }));
  9079. }
  9080. else if (portType == 2 || portType == 3)
  9081. {
  9082. return Ok(JsonView(true, "SUCCESS!", new
  9083. {
  9084. dropDownType,
  9085. isMarketingDepartment
  9086. }));
  9087. }
  9088. else
  9089. {
  9090. return Ok(JsonView(false, "portType有误!"));
  9091. }
  9092. }
  9093. /// <summary>
  9094. /// 共享文件上传
  9095. /// </summary>
  9096. /// <param name="dto"></param>
  9097. /// <returns></returns>
  9098. [HttpPost]
  9099. public IActionResult SharedFileUpload([FromForm] SharedFileUploadDto dto)
  9100. {
  9101. var isGroup = new List<int> { 1412 };
  9102. if (isGroup.Contains(dto.FileType) && dto.Diid < 1)
  9103. {
  9104. return Ok(JsonView(false, "该文件需要关联团组!"));
  9105. }
  9106. if (dto.Files == null || dto.Files.Count == 0)
  9107. {
  9108. return Ok(JsonView(false, "无文件信息!"));
  9109. }
  9110. if (dto.Files.Sum(x => x.Length) > 20 * 1024 * 1024)
  9111. {
  9112. return Ok(JsonView(false, "文件大小超过20M!"));
  9113. }
  9114. if (dto.Userid < 1)
  9115. {
  9116. return Ok(JsonView(false, "请传入有效的Userid!"));
  9117. }
  9118. var jobInfo = _sqlSugar.Queryable<Sys_Users, Sys_JobPost>((u, j) => u.JobPostId == j.Id && j.IsDel == 0)
  9119. .Where(u => u.IsDel == 0 && u.Id == dto.Userid)
  9120. .Select((u, j) => new
  9121. {
  9122. u.CnName,
  9123. UserId = u.Id,
  9124. j.JobName,
  9125. })
  9126. .First();
  9127. if (jobInfo == null)
  9128. {
  9129. return Ok(JsonView(false, "请传入有效的Userid!"));
  9130. }
  9131. var commonFileExtensions = new List<string>
  9132. {
  9133. // 文本文件
  9134. ".txt", ".doc", ".docx", ".odt", ".pdf", ".rtf", ".md", ".log",
  9135. // 图片文件
  9136. ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".svg",
  9137. // 视频文件
  9138. ".mp4", ".avi", ".mov", ".mkv", ".wmv", ".flv", ".mpg", ".mpeg",
  9139. // 音频文件
  9140. ".mp3", ".wav", ".ogg", ".aac", ".flac",
  9141. // 压缩文件
  9142. ".zip", ".rar", ".7z", ".tar", ".gz", ".bz2",
  9143. // 数据文件
  9144. ".csv", ".xls", ".xlsx", ".json", ".xml", ".yaml", ".ini",
  9145. };
  9146. try
  9147. {
  9148. var setting = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == 1416);
  9149. var settingExtend = JsonConvert.DeserializeObject<List<string>>(setting.Remark);
  9150. commonFileExtensions.AddRange(settingExtend);
  9151. }
  9152. catch (Exception)
  9153. { }
  9154. var setdata = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == dto.FileType);
  9155. if (setdata == null)
  9156. {
  9157. return Ok(JsonView(false, "请传入有效的FileType!"));
  9158. }
  9159. var insertList = new List<Grp_GroupShareFile>();
  9160. string winPath = AppSettingsHelper.Get("ShareFileBasePath") + $"{setdata.Name}/";
  9161. if (!Directory.Exists(winPath))
  9162. {
  9163. Directory.CreateDirectory(winPath);
  9164. }
  9165. foreach (var item in dto.Files)
  9166. {
  9167. var houzui = Path.GetExtension(item.FileName);
  9168. if (!commonFileExtensions.Contains(houzui))
  9169. {
  9170. return Ok(JsonView(false, "未知后缀名称!"));
  9171. }
  9172. var fileName = $"{jobInfo.JobName}-{jobInfo.CnName}-{item.FileName}";
  9173. var saveFilePath = winPath + fileName;
  9174. using (FileStream fs = System.IO.File.Create(saveFilePath))
  9175. {
  9176. item.CopyTo(fs);
  9177. fs.Flush();
  9178. }
  9179. var fileDetail = new Grp_GroupShareFile()
  9180. {
  9181. CreateUserId = dto.Userid,
  9182. CreateTime = DateTime.Now,
  9183. UploadJob = jobInfo.JobName,
  9184. FileName = fileName,
  9185. FileType = dto.FileType,
  9186. Diid = dto.Diid,
  9187. FilePath = winPath + fileName,
  9188. };
  9189. insertList.Add(fileDetail);
  9190. }
  9191. _sqlSugar.Insertable<Grp_GroupShareFile>(insertList).ExecuteCommand();
  9192. return Ok(JsonView(true, "保存成功!"));
  9193. }
  9194. /// <summary>
  9195. /// 查询共享文件列表
  9196. /// </summary>
  9197. /// <param name="dto"></param>
  9198. /// <returns></returns>
  9199. [HttpPost]
  9200. public IActionResult QuerySharedFile(QuerySharedFileDto dto)
  9201. {
  9202. var isGroup = new List<int> { 1412 };
  9203. if (!isGroup.Contains(dto.FileType)) dto.Diid = 0;
  9204. var queryExpression = Expressionable.Create<Grp_GroupShareFile>()
  9205. .And(x => x.Diid == dto.Diid)
  9206. .And(x => x.FileType == dto.FileType)
  9207. .And(x => x.IsDel == 0)
  9208. .AndIF(!dto.FileName.IsNullOrWhiteSpace(), x => x.FileName.Contains(dto.FileName))
  9209. .AndIF(DateTime.TryParse(dto.StartTime, out DateTime Start), x => x.CreateTime >= Start)
  9210. .AndIF(DateTime.TryParse(dto.EndTime, out DateTime End), x => x.CreateTime <= End);
  9211. int totalCount = 0;
  9212. var dbQuery = _sqlSugar.Queryable<Grp_GroupShareFile>()
  9213. .Where(queryExpression.ToExpression())
  9214. .OrderBy(x => x.UploadJob)
  9215. .Select(x => new
  9216. {
  9217. x.Id,
  9218. FilePath = AppSettingsHelper.Get("ShareFileBaseUrl") + x.FilePath.Replace(AppSettingsHelper.Get("ShareFileBasePath"), AppSettingsHelper.Get("ShareFileFtpPath")),
  9219. x.FileName,
  9220. x.FileType,
  9221. x.CreateTime,
  9222. })
  9223. .ToPageList(dto.PageIndex, dto.PageSize, ref totalCount);
  9224. return Ok(JsonView(true, "SUCCESS!", new
  9225. {
  9226. FileList = dbQuery,
  9227. dto.PageSize,
  9228. dto.PageIndex,
  9229. totalCount
  9230. }));
  9231. }
  9232. /// <summary>
  9233. /// 删除共享文件模块下的指定文件
  9234. /// </summary>
  9235. /// <param name="dto"></param>
  9236. /// <returns></returns>
  9237. [HttpPost]
  9238. public IActionResult DeleteSharedFile(DeleteGroupFileDto dto)
  9239. {
  9240. var jw = JsonView(false);
  9241. var sing = _sqlSugar.Queryable<Grp_GroupShareFile>().First(x => x.Id == dto.Id && x.IsDel == 0);
  9242. if (sing == null)
  9243. {
  9244. jw.Msg = "暂无文件信息!";
  9245. return Ok(jw);
  9246. }
  9247. if (sing.CreateUserId != dto.UserId)
  9248. {
  9249. jw.Msg = "只能删除自己上传的文件!";
  9250. return Ok(jw);
  9251. }
  9252. if (System.IO.File.Exists(sing.FilePath))
  9253. {
  9254. try
  9255. {
  9256. System.IO.File.Delete(sing.FilePath);
  9257. }
  9258. catch (Exception ex)
  9259. {
  9260. jw.Msg = "删除失败!" + ex.Message;
  9261. return Ok(jw);
  9262. }
  9263. }
  9264. sing.IsDel = 1;
  9265. sing.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  9266. sing.DeleteUserId = dto.UserId;
  9267. _sqlSugar.Updateable<Grp_GroupShareFile>(sing).ExecuteCommand();
  9268. jw = JsonView(true, "删除成功!");
  9269. return Ok(jw);
  9270. }
  9271. #endregion
  9272. #region 团组英文资料
  9273. /// <summary>
  9274. /// 查询团组英文所有资料
  9275. /// </summary>
  9276. /// <param name="dto"></param>
  9277. /// <returns></returns>
  9278. [HttpPost]
  9279. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9280. public async Task<IActionResult> QueryDelegationEnData(QueryDelegationEnDataDto dto)
  9281. {
  9282. try
  9283. {
  9284. Result groupData = await _delegationEnDataRep.QueryDelegationEnData(dto);
  9285. if (groupData.Code != 0)
  9286. {
  9287. return Ok(JsonView(false, groupData.Msg));
  9288. }
  9289. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  9290. }
  9291. catch (Exception ex)
  9292. {
  9293. return Ok(JsonView(false, ex.Message));
  9294. throw;
  9295. }
  9296. }
  9297. /// <summary>
  9298. /// 团组英文资料操作(Status:1.新增,2.修改)
  9299. /// </summary>
  9300. /// <param name="dto"></param>
  9301. /// <returns></returns>
  9302. [HttpPost]
  9303. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9304. public async Task<IActionResult> OpDelegationEnData(OpDelegationEnDataDto dto)
  9305. {
  9306. try
  9307. {
  9308. Result groupData = await _delegationEnDataRep.OpDelegationEnData(dto);
  9309. if (groupData.Code != 0)
  9310. {
  9311. return Ok(JsonView(false, groupData.Msg));
  9312. }
  9313. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  9314. }
  9315. catch (Exception ex)
  9316. {
  9317. return Ok(JsonView(false, ex.Message));
  9318. throw;
  9319. }
  9320. }
  9321. /// <summary>
  9322. /// 团组英文资料Id查询数据
  9323. /// </summary>
  9324. /// <param name="dto"></param>
  9325. /// <returns></returns>
  9326. [HttpPost]
  9327. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9328. public async Task<IActionResult> QueryDelegationEnDataById(QueryDelegationEnDataByIdDto dto)
  9329. {
  9330. try
  9331. {
  9332. Grp_DelegationEnData _DelegationEnData = await _sqlSugar.Queryable<Grp_DelegationEnData>().FirstAsync(it => it.Id == dto.Id && it.IsDel == 0);
  9333. if (_DelegationEnData != null)
  9334. {
  9335. return Ok(JsonView(true, "查询成功!", _DelegationEnData));
  9336. }
  9337. return Ok(JsonView(true, "暂无数据!", _DelegationEnData));
  9338. }
  9339. catch (Exception ex)
  9340. {
  9341. return Ok(JsonView(false, "程序错误!"));
  9342. throw;
  9343. }
  9344. }
  9345. /// <summary>
  9346. /// 团组英文资料删除
  9347. /// </summary>
  9348. /// <param name="dto"></param>
  9349. /// <returns></returns>
  9350. [HttpPost]
  9351. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9352. public async Task<IActionResult> DelDelegationEnData(DelBaseDto dto)
  9353. {
  9354. try
  9355. {
  9356. var res = await _delegationEnDataRep.SoftDeleteByIdAsync<Grp_DelegationEnData>(dto.Id.ToString(), dto.DeleteUserId);
  9357. if (!res)
  9358. {
  9359. return Ok(JsonView(false, "删除失败"));
  9360. }
  9361. return Ok(JsonView(true, "删除成功!"));
  9362. }
  9363. catch (Exception ex)
  9364. {
  9365. return Ok(JsonView(false, ex.Message));
  9366. throw;
  9367. }
  9368. }
  9369. #endregion
  9370. #region 导出邀请函
  9371. /// <summary>
  9372. /// 导出邀请函页面初始化
  9373. /// </summary>
  9374. /// <param name="dto"></param>
  9375. /// <returns></returns>
  9376. [HttpPost]
  9377. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9378. public async Task<IActionResult> QueryinvitationLetter(DecreasePaymentsListDto dto)
  9379. {
  9380. try
  9381. {
  9382. var grp_Delegations = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(a => a.IsDel == 0).OrderBy(a => a.VisitStartDate, OrderByType.Desc).ToList();
  9383. var crm_Deles = new List<Crm_DeleClient>();
  9384. if (dto.DiId == 0)
  9385. {
  9386. crm_Deles = await _sqlSugar.Queryable<Crm_DeleClient>().Where(a => a.DiId == grp_Delegations[0].Id && a.IsDel == 0).ToListAsync();
  9387. }
  9388. else
  9389. {
  9390. crm_Deles = await _sqlSugar.Queryable<Crm_DeleClient>().Where(a => a.DiId == dto.DiId && a.IsDel == 0).ToListAsync();
  9391. }
  9392. return Ok(JsonView(true, "查询成功!", new
  9393. {
  9394. deleClient = crm_Deles,
  9395. delegations = grp_Delegations
  9396. }));
  9397. }
  9398. catch (Exception ex)
  9399. {
  9400. return Ok(JsonView(false, "程序错误!"));
  9401. throw;
  9402. }
  9403. }
  9404. /// <summary>
  9405. /// 导出邀请函
  9406. /// </summary>
  9407. /// <param name="dto"></param>
  9408. /// <returns></returns>
  9409. [HttpPost]
  9410. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9411. public async Task<IActionResult> invitationLetter(DecreasePaymentsListDto dto)
  9412. {
  9413. #region 参数验证
  9414. //if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  9415. if (dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId参数!"));
  9416. #endregion
  9417. try
  9418. {
  9419. var transDic = new Dictionary<string, string>();
  9420. string sql = string.Format(@"Select tcl.Id,tcl.DiId,temp.*,tcl.ShippingSpaceTypeId,tcl.ShippingSpaceSpecialNeeds,
  9421. tcl.HotelSpecialNeeds,tcl.MealSpecialNeeds,tcl.Remark
  9422. From Grp_TourClientList tcl
  9423. Left Join
  9424. (Select dc.Id As DcId,dc.LastName,dc.FirstName,dc.Pinyin,dc.Sex,ccom.CompanyFullName,dc.Job,
  9425. cc1.CertNo As IDCardNo,dc.Phone,dc.BirthDay,cc2.PassportType,cc2.CertNo As PassportNo,cc2.Country,
  9426. cc2.Area,cc2.IssueDt,cc2.ExpiryDt
  9427. From Crm_DeleClient dc
  9428. Left Join Crm_CustomerCompany ccom On dc.CrmCompanyId = ccom.Id And ccom.IsDel = 0
  9429. Left Join Crm_CustomerCert cc1 On dc.Id = cc1.DcId And cc1.SdId = 773 And cc1.IsDel = 0
  9430. Left Join Crm_CustomerCert cc2 On dc.Id = cc2.DcId And cc2.SdId = 774 And cc2.IsDel = 0
  9431. Where dc.IsDel = 0) temp
  9432. On temp.DcId =tcl.ClientId
  9433. Where tcl.IsDel = 0 And tcl.DiId = {0}", dto.DiId);
  9434. var datas = _sqlSugar.SqlQueryable<TourClientListDetailsView>(sql).ToList();
  9435. var texts = new List<string>();
  9436. if (datas.Count != 0)
  9437. {
  9438. foreach (TourClientListDetailsView item in datas)
  9439. {
  9440. if (!string.IsNullOrWhiteSpace(item.Pinyin))
  9441. {
  9442. transDic.Add(item.LastName + item.FirstName, item.Pinyin);
  9443. }
  9444. else
  9445. {
  9446. string name = item.LastName + item.FirstName;
  9447. texts.Add(name);
  9448. }
  9449. if (!string.IsNullOrEmpty(item.Job) && !texts.Contains(item.Job))
  9450. {
  9451. if (!transDic.ContainsKey(item.Job))
  9452. {
  9453. texts.Add(item.Job);
  9454. }
  9455. }
  9456. if (!string.IsNullOrEmpty(item.CompanyFullName))
  9457. {
  9458. texts.Add(item.CompanyFullName);
  9459. }
  9460. }
  9461. var transData = await _airTicketResRep.ReTransBatch(texts, "en");
  9462. if (transData.Count > 0)
  9463. {
  9464. foreach (TranslateResult item in transData)
  9465. {
  9466. if (!transDic.ContainsKey(item.Query))
  9467. {
  9468. transDic.Add(item.Query, item.Translation);
  9469. }
  9470. }
  9471. }
  9472. var list = new List<GuestList>();
  9473. foreach (var dele in datas)
  9474. {
  9475. var guestList = new GuestList();
  9476. if (!string.IsNullOrWhiteSpace(dele.Pinyin))
  9477. {
  9478. guestList.Name = dele.Pinyin;
  9479. }
  9480. else
  9481. {
  9482. string Name = transDic.Where(s => s.Key == dele.LastName + dele.FirstName).FirstOrDefault().Value;
  9483. guestList.Name = Name;
  9484. }
  9485. if (dele.Sex == 0)
  9486. {
  9487. guestList.Sex = "Male";
  9488. }
  9489. else if (dele.Sex == 1)
  9490. {
  9491. guestList.Sex = "Female";
  9492. }
  9493. guestList.DOB = dele.BirthDay.Replace('-', '.');
  9494. if (!string.IsNullOrEmpty(dele.Job))
  9495. {
  9496. guestList.Job = dele.Job;
  9497. }
  9498. list.Add(guestList);
  9499. }
  9500. //载入模板
  9501. var doc = new Document(AppSettingsHelper.Get("WordBasePath") + "Template/邀请函模板0210.docx");
  9502. var builder = new DocumentBuilder(doc);
  9503. //获取word里所有表格
  9504. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  9505. //获取所填表格的序数
  9506. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  9507. var rowStart = tableOne.Rows[0]; //获取第1行
  9508. //循环赋值
  9509. for (int i = 0; i < list.Count; i++)
  9510. {
  9511. builder.MoveToCell(0, i + 1, 0, 0);
  9512. builder.Write(list[i].Name.ToString());
  9513. builder.MoveToCell(0, i + 1, 1, 0);
  9514. builder.Write(list[i].Sex.ToString());
  9515. builder.MoveToCell(0, i + 1, 2, 0);
  9516. builder.Write(list[i].DOB.ToString());
  9517. builder.MoveToCell(0, i + 1, 3, 0);
  9518. builder.Write(list[i].Job.ToString());
  9519. }
  9520. //删除多余行
  9521. while (tableOne.Rows.Count > list.Count + 1)
  9522. {
  9523. tableOne.Rows.RemoveAt(list.Count + 1);
  9524. }
  9525. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  9526. string fileName = "邀请函" + DateTime.Now.ToString("yyyy-MM-dd") + ".docx";
  9527. string filePath = fileDir + $@"商邀相关文件/{fileName}";
  9528. doc.Save(filePath);
  9529. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/GrpFile/商邀相关文件/" + fileName;
  9530. return Ok(JsonView(true, "操作成功!", Url));
  9531. }
  9532. else
  9533. {
  9534. return Ok(JsonView(false, "该团组客户名单暂未录入!"));
  9535. }
  9536. }
  9537. catch (Exception ex)
  9538. {
  9539. return Ok(JsonView(false, ex.Message));
  9540. throw;
  9541. }
  9542. }
  9543. #endregion
  9544. #region 团组经理模块 出入境费用
  9545. /// <summary>
  9546. /// 团组模块 - 出入境费用 - 省份基础数据源
  9547. /// </summary>
  9548. /// <returns></returns>
  9549. [HttpGet]
  9550. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9551. public async Task<IActionResult> GetEnterExitProvBelongCostDataSource()
  9552. {
  9553. return Ok(JsonView(await _groupRepository.ProvinceBasicSource()));
  9554. }
  9555. /// <summary>
  9556. /// 团组模块 - 出入境费用 - 基础数据源(团组名称/币种类型)
  9557. /// </summary>
  9558. /// <param name="dto"></param>
  9559. /// <returns></returns>
  9560. [HttpPost]
  9561. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9562. public async Task<IActionResult> GetEnterExitCostDataSource(EnterExitCostDataSourceDto dto)
  9563. {
  9564. var groupNameData = await _groupRepository.EnterExitCostGroupNameAsync();
  9565. var groupNamFirst = groupNameData.FirstOrDefault();
  9566. //SetDataInfoView
  9567. var dataSource = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToListAsync();
  9568. var currencyData = dataSource.Where(it => it.STid == 66).ToList(); //所有币种
  9569. List<SetDataInfoView> _CurrencyData = _mapper.Map<List<SetDataInfoView>>(currencyData);
  9570. //验证城市归属并给默认值
  9571. int provinceId = 122;
  9572. if (groupNamFirst != null) provinceId = groupNamFirst.ProvinceId;
  9573. (SetDataInfoView[] wordTypeData, SetDataInfoView[] excelTypeData) = await _enterExitCostRep.FileOwner(provinceId);
  9574. var _currencyInfos = await GeneralMethod.EnterExitCostInitRate();
  9575. var viewPermissionData = await _enterExitCostRep.PermissionViewUsersAsync();
  9576. return Ok(JsonView(true, "查询成功!", new
  9577. {
  9578. GroupNameData = groupNameData,
  9579. CurrencyData = _CurrencyData,
  9580. WordTypeData = wordTypeData,
  9581. ExcelTypeData = excelTypeData,
  9582. CurrencyInit = _currencyInfos
  9583. }));
  9584. }
  9585. /// <summary>
  9586. /// 团组模块 - 出入境费用 - 文件类型list 跟据省份Id获取
  9587. /// </summary>
  9588. /// <returns></returns>
  9589. [HttpGet("{provinceId}")]
  9590. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9591. public async Task<IActionResult> EnterExitCostFileOwner([FromRoute] int provinceId = 122)
  9592. {
  9593. //验证城市归属并给默认值
  9594. if (provinceId < 1) provinceId = 122;
  9595. /*
  9596. * 122 四川
  9597. * 108 贵州
  9598. * 103 重庆
  9599. * 132 云南
  9600. */
  9601. (SetDataInfoView[] wordTypeData, SetDataInfoView[] excelTypeData) = await _enterExitCostDraftRep.FileOwner(provinceId);
  9602. return Ok(JsonView(true, "查询成功!", new
  9603. {
  9604. WordTypeData = wordTypeData,
  9605. ExcelTypeData = excelTypeData,
  9606. }));
  9607. }
  9608. /// <summary>
  9609. /// 团组模块 - 出入境费用
  9610. /// 实时汇率 tips
  9611. /// 签证费用 tips
  9612. /// 机票费用 tips
  9613. /// </summary>
  9614. /// <returns></returns>
  9615. [HttpPost]
  9616. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9617. public async Task<IActionResult> GetEnterExitCostCorrelationTips(EnterExitCostInfobyDiIdDto dto)
  9618. {
  9619. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(it => it.Id == dto.DiId && it.IsDel == 0);
  9620. //默认币种显示
  9621. var reteInfos = await GeneralMethod.EnterExitCostLiveRate();
  9622. var visaData = await _visaFeeInfoRep.EnterExitCostVisaTips(dto.DiId);
  9623. var airData = await GeneralMethod.EntryAndExitTips(dto.DiId);
  9624. return Ok(JsonView(true, "查询成功!", new
  9625. {
  9626. //GroupNameData = groupNameData.Data,
  9627. visaData = visaData.Data,
  9628. airData,
  9629. reteInfos
  9630. }));
  9631. }
  9632. #region 城市区间交通费
  9633. /// <summary>
  9634. /// 团组模块 - 出入境费用 - 基础数据源(境外用车)
  9635. /// </summary>
  9636. /// <param name="groupId"></param>
  9637. /// <returns></returns>
  9638. [HttpGet("{groupId}")]
  9639. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9640. public async Task<IActionResult> GetEnterExitCostOVByGroupId(int groupId)
  9641. {
  9642. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  9643. if (groupInfo == null)
  9644. {
  9645. return Ok(JsonView(false, "团组信息为空"));
  9646. }
  9647. var countryies = _groupRepository.GroupSplitCountry(groupInfo.VisitCountry);
  9648. if (countryies?.Any() != true)
  9649. {
  9650. return Ok(JsonView(false, "团组出访国家信息为空"));
  9651. }
  9652. var currencies = await GeneralMethod.EnterExitCostOVFeeUsedCurrencyAsync(groupId);
  9653. var currencyData = await _sqlSugar.Queryable<Sys_SetData>()
  9654. .Where(x => x.IsDel == 0 && x.STid == 66)
  9655. .ToListAsync();
  9656. var overseaVehicles = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  9657. .Where(x => x.IsDel == 0 && countryies.Contains(x.CountryName))
  9658. .ToListAsync();
  9659. var overseaVehicleIds = overseaVehicles.Select(x => x.Id).ToList();
  9660. //只返回接送机的数据
  9661. var overseaVehicleTypes = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  9662. .Where(x => x.IsDel == 0 && x.ServiceType == VehicleServiceTypeEnum.TransferService && overseaVehicleIds.Contains(x.OvId))
  9663. .ToListAsync();
  9664. var sysUers = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToListAsync();
  9665. var overseaVehicleCityDatas = new List<dynamic>() {
  9666. new
  9667. {
  9668. Id = 0,
  9669. area= "未选择",
  9670. CarTypeName = "",
  9671. serviceType = "",
  9672. Price = 0.00M,
  9673. guidePrice = 0.00M,
  9674. otherPrice = 0.00M,
  9675. currency = 0,
  9676. currencyName = "",
  9677. currRate = 1.0000M,
  9678. LastUpdateUserName = "",
  9679. LastUpdateTime = "",
  9680. Remark = ""
  9681. }};
  9682. foreach (var item in overseaVehicleTypes)
  9683. {
  9684. var parentInfo = overseaVehicles.FirstOrDefault(x => x.Id == item.OvId);
  9685. string area = string.Empty,
  9686. serviceType = "未设置",
  9687. currencyName = string.Empty;
  9688. decimal otherPrice = 0.00M;
  9689. if (parentInfo != null)
  9690. {
  9691. if (parentInfo.CountryName == parentInfo.CityName) area = parentInfo.CountryName;
  9692. else area = $"{parentInfo.CountryName}-{parentInfo.CityName}";
  9693. serviceType = item.ServiceType.GetDescription();
  9694. currencyName = currencyData.FirstOrDefault(x => x.Id == parentInfo.Currency)?.Name ?? "-";
  9695. otherPrice = parentInfo.OtherPrice1 + parentInfo.OtherPrice2;
  9696. }
  9697. //当前币种汇率值
  9698. var currRate = 1.0000M;
  9699. var currencyInfo = currencies.FirstOrDefault(x => x.CurrencyCode == currencyName);
  9700. if (currencyInfo != null) currRate = currencyInfo.Rate;
  9701. overseaVehicleCityDatas.add(new
  9702. {
  9703. item.Id,
  9704. area,
  9705. item.CarTypeName,
  9706. serviceType,
  9707. item.Price,
  9708. guidePrice = parentInfo?.GuidePrice ?? 0.00M,
  9709. otherPrice,
  9710. currency = parentInfo?.Currency ?? 0,
  9711. currencyName,
  9712. currRate,
  9713. LastUpdateUserName = sysUers.FirstOrDefault(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-",
  9714. item.LastUpdateTime,
  9715. item.Remark
  9716. });
  9717. }
  9718. var total = overseaVehicleCityDatas.Count;
  9719. var view = new
  9720. {
  9721. visitCountries = string.Join("、", countryies),
  9722. groupSize = groupInfo.VisitPNumber, //出访人数
  9723. defAirportTransferCoeff = Def_AirportTransferCoeff, //接送机默认报价系数
  9724. defServiceCount = Def_ServiceCount, //接送机默认服务次数
  9725. defTrainCoeff = Def_TrainCoeff, //火车默认报价系数
  9726. defPullCartCoeff = Def_PullCartCoeff, //拉车默认报价系数
  9727. defCityFlightCoeff = Def_CityFlightCoeff, //城市机票默认报价系数
  9728. Currencies = currencies,
  9729. data = overseaVehicleCityDatas
  9730. };
  9731. if (overseaVehicleCityDatas.Count == 0)
  9732. {
  9733. return Ok(JsonView(true, "暂无数据!", view));
  9734. }
  9735. return Ok(JsonView(true, "查询成功!", view, total));
  9736. }
  9737. /// <summary>
  9738. /// 团组模块 - 出入境费用 - 境外用车计算详细信息
  9739. /// </summary>
  9740. /// <param name="groupId"></param>
  9741. /// <param name="currUserId"></param>
  9742. /// <returns></returns>
  9743. [HttpGet("{groupId}")]
  9744. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9745. public async Task<IActionResult> GetEnterExitCostOVFeeDetails(int groupId, int currUserId)
  9746. {
  9747. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  9748. if (groupInfo == null)
  9749. {
  9750. return Ok(JsonView(false, "团组信息为空"));
  9751. }
  9752. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).FirstAsync();
  9753. //CityIntervalInfo
  9754. var info = new CityIntervalInfo();
  9755. if (eecInfo != null && !string.IsNullOrEmpty(eecInfo.CityIntervalFeeDetails))
  9756. {
  9757. info = JsonConvert.DeserializeObject<CityIntervalInfo>(eecInfo.CityIntervalFeeDetails);
  9758. return Ok(JsonView(true, "查询成功!", info));
  9759. }
  9760. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == currUserId).FirstAsync();
  9761. var userName = userInfo?.CnName ?? "-";
  9762. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  9763. //返回默认数据
  9764. info = new CityIntervalInfo()
  9765. {
  9766. APTFeeDetails = new List<RoundTripTransferInfo>() { new() { No = 1, Coefficient = Def_AirportTransferCoeff, ServiceCount = Def_ServiceCount } },
  9767. PullCartFeeDetails = new List<PullCartInfo>() { new() { No = 1, Coefficient = Def_PullCartCoeff } },
  9768. TrainFeeDetails = new List<TrainInfo>() { new() { No = 1, Coefficient = Def_TrainCoeff } },
  9769. CityAirTicketFeeDetails = new List<CityAirTicketInfo>() { new() { No = 1, Coefficient = Def_CityFlightCoeff } },
  9770. LastUpdateUserName = userName,
  9771. LastUpdateTime = nowTime,
  9772. CreateUserName = userName,
  9773. Currencies = await GeneralMethod.EnterExitCostOVFeeUsedCurrencyAsync(groupId),
  9774. CreateTime = nowTime
  9775. };
  9776. return Ok(JsonView(true, "查询成功!", info));
  9777. }
  9778. /// <summary>
  9779. /// 团组模块 - 出入境费用 - 境外用车计算 保存
  9780. /// </summary>
  9781. /// <param name="dto"></param>
  9782. /// <returns></returns>
  9783. [HttpPost]
  9784. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9785. public async Task<IActionResult> GetEnterExitCostOVFeeSave(GetEnterExitCostOVFeeSaveDto dto)
  9786. {
  9787. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == dto.GroupId).FirstAsync();
  9788. if (groupInfo == null)
  9789. {
  9790. return Ok(JsonView(false, "团组信息为空"));
  9791. }
  9792. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == dto.CurrUserId).FirstAsync();
  9793. if (userInfo == null)
  9794. {
  9795. return Ok(JsonView(false, "员工信息为空"));
  9796. }
  9797. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == dto.GroupId).FirstAsync();
  9798. if (eecInfo == null)
  9799. {
  9800. return Ok(JsonView(false, "出入境费用信息为空"));
  9801. }
  9802. var oldData = new CityIntervalInfo();
  9803. if (!string.IsNullOrEmpty(eecInfo.CityIntervalFeeDetails))
  9804. {
  9805. oldData = JsonConvert.DeserializeObject<CityIntervalInfo>(eecInfo.CityIntervalFeeDetails);
  9806. }
  9807. var userName = userInfo?.CnName ?? "-";
  9808. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  9809. var info = new CityIntervalInfo()
  9810. {
  9811. APTFeeTotal = dto.APTFeeTotal,
  9812. APTFeeDetails = dto.APTFeeDetails,
  9813. PullCartFeeTotal = dto.PullCartFeeTotal,
  9814. PullCartFeeDetails = dto.PullCartFeeDetails,
  9815. TrainFeeTotal = dto.TrainFeeTotal,
  9816. TrainFeeDetails = dto.TrainFeeDetails,
  9817. CityAirTicketFeeTotal = dto.CityAirTicketFeeTotal,
  9818. CityAirTicketFeeDetails = dto.CityAirTicketFeeDetails,
  9819. Currencies = dto.Currencies,
  9820. LastUpdateUserName = userName,
  9821. LastUpdateTime = nowTime,
  9822. CreateUserName = oldData?.CreateUserName ?? userName,
  9823. CreateTime = oldData?.CreateTime ?? nowTime
  9824. };
  9825. eecInfo.CityIntervalFeeDetails = JsonConvert.SerializeObject(info);
  9826. var upd = await _sqlSugar.Updateable<Grp_EnterExitCost>()
  9827. .SetColumns(it => it.CityIntervalFeeDetails == eecInfo.CityIntervalFeeDetails)
  9828. .SetColumns(it => it.LastUpdateUserId == dto.CurrUserId)
  9829. .SetColumns(it => it.LastUpdateTime == nowTime)
  9830. .Where(x => x.Id == eecInfo.Id)
  9831. .ExecuteCommandAsync();
  9832. if (upd < 1)
  9833. {
  9834. return Ok(JsonView(false));
  9835. }
  9836. //返回数据处理
  9837. var label = new StringBuilder();
  9838. //接送机
  9839. if (dto.APTFeeDetails?.Any() == true)
  9840. {
  9841. var ovIds = dto.APTFeeDetails.Select(x => x.OvId).ToList();
  9842. var areas = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  9843. .LeftJoin<Res_OverseaVehicle>((ovtp, ov) => ovtp.OvId == ov.Id)
  9844. .Where((ovtp, ov) => ovtp.IsDel == 0 && ovIds.Contains(ovtp.Id))
  9845. .Select((ovtp, ov) => new
  9846. {
  9847. ovtp.Id,
  9848. ov.CountryName,
  9849. ov.CityName
  9850. }).ToListAsync();
  9851. var items = dto.APTFeeDetails
  9852. .Select(item =>
  9853. {
  9854. var areaInfo = areas.FirstOrDefault(x => x.Id == item.OvId);
  9855. if (areaInfo == null) return null;
  9856. return areaInfo.CountryName == areaInfo.CityName
  9857. ? $"{areaInfo.CountryName}({item.Quote:#0.00} CNY)"
  9858. : $"{areaInfo.CountryName}-{areaInfo.CityName}({item.Quote:#0.00} CNY)";
  9859. })
  9860. .Where(item => item != null)
  9861. .ToList();
  9862. label.AppendLine($"接送机({string.Join("、", items)});");
  9863. }
  9864. //拉车
  9865. if (dto.PullCartFeeDetails?.Any() == true)
  9866. {
  9867. var feeLabel = string.Join("、",
  9868. dto.PullCartFeeDetails.Select(x =>
  9869. $"{x.Quote:#0.00} CNY"
  9870. ));
  9871. label.AppendLine($"拉车({feeLabel});");
  9872. }
  9873. //火车
  9874. if (dto.TrainFeeDetails?.Any() == true)
  9875. {
  9876. var feeLabel = string.Join("、",
  9877. dto.TrainFeeDetails.Select(x =>
  9878. $"{x.Quote:#0.00} CNY"
  9879. ));
  9880. label.AppendLine($"火车票({feeLabel});");
  9881. }
  9882. //城市机票
  9883. if (dto.CityAirTicketFeeDetails?.Any() == true)
  9884. {
  9885. var feeLabel = string.Join("、",
  9886. dto.CityAirTicketFeeDetails.Select(x =>
  9887. $"{x.Quote:#0.00} CNY"
  9888. ));
  9889. label.AppendLine($"城市机票({feeLabel});");
  9890. }
  9891. //费用
  9892. decimal quote = (dto.APTFeeTotal + dto.PullCartFeeTotal + dto.TrainFeeTotal + dto.CityAirTicketFeeTotal).ConvertToDecimal1();
  9893. decimal jjcQuote = quote;
  9894. decimal gwcQuote = quote;
  9895. decimal tdcQuote = quote;
  9896. var view = new
  9897. {
  9898. label = label.ToString(),
  9899. jjcQuote,
  9900. gwcQuote,
  9901. tdcQuote
  9902. };
  9903. return Ok(JsonView(view));
  9904. }
  9905. #endregion
  9906. /// <summary>
  9907. /// 团组模块 - 出入境费用 - Info
  9908. /// </summary>
  9909. /// <param name="dto"></param>
  9910. /// <returns></returns>
  9911. [HttpPost]
  9912. //[ApiLog("Grp_EnterExitCost", OperationEnum.Details)]
  9913. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9914. public async Task<IActionResult> GetEnterExitCostInfobyDiId(EnterExitCostInfobyDiIdDto dto)
  9915. {
  9916. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  9917. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  9918. return Ok(await _enterExitCostRep.GetEnterExitCostInfoByDiId(dto));
  9919. }
  9920. /// <summary>
  9921. /// 团组模块 - 出入境费用 - 设置view权限
  9922. /// </summary>
  9923. /// <returns></returns>
  9924. [HttpPost]
  9925. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9926. public async Task<IActionResult> EnterExitCostSetViewPermissiion(EnterExitCostSetViewPermissiionDto dto)
  9927. {
  9928. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  9929. if (dto.GroupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  9930. if (dto.UserIds.Length < 1) return Ok(JsonView(false, "请传入有效的userId;"));
  9931. var permissions = new List<Grp_EnterExitCostPermission>();
  9932. foreach (var userId in dto.UserIds)
  9933. {
  9934. permissions.Add(new Grp_EnterExitCostPermission { Permission = 1, GroupId = dto.GroupId, UserId = userId, CreateUserId = dto.CurrUserId });
  9935. }
  9936. if (permissions.Any())
  9937. {
  9938. _sqlSugar.BeginTran();
  9939. try
  9940. {
  9941. await _sqlSugar.Deleteable<Grp_EnterExitCostPermission>().Where(it => it.GroupId == dto.GroupId).ExecuteCommandAsync();
  9942. var result = await _sqlSugar.Insertable(permissions).ExecuteCommandAsync();
  9943. if (result < 1)
  9944. {
  9945. _sqlSugar.RollbackTran();
  9946. return Ok(JsonView(false));
  9947. }
  9948. }
  9949. catch (Exception ex)
  9950. {
  9951. _sqlSugar.RollbackTran();
  9952. return Ok(JsonView(false, ex.Message));
  9953. }
  9954. _sqlSugar.CommitTran();
  9955. return Ok(JsonView(true));
  9956. }
  9957. return Ok(JsonView(false));
  9958. }
  9959. /// <summary>
  9960. /// 团组模块 - 出入境费用 - Add And Update
  9961. /// </summary>
  9962. /// <returns></returns>
  9963. [HttpPost]
  9964. [ApiLog("Grp_EnterExitCost", OperationEnum.Add)]
  9965. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9966. public async Task<IActionResult> PostEnterExitCostOperate(EnterExitCostOperateDto dto)
  9967. {
  9968. try
  9969. {
  9970. var rateRecords = new List<RateRecordInfo>();
  9971. #region 汇率保存前存储
  9972. var info = await _sqlSugar.Queryable<Grp_EnterExitCost>().FirstAsync(x => x.IsDel == 0 && x.DiId == dto.DiId);
  9973. if (info != null)
  9974. {
  9975. var cacheRateInfos = CommonFun.GetCurrencyChinaToList(info.CurrencyRemark);
  9976. if (cacheRateInfos != null && cacheRateInfos.Count > 0)
  9977. {
  9978. rateRecords = cacheRateInfos.Select(x => new RateRecordInfo()
  9979. {
  9980. CurrencyCode = x.CurrencyCode,
  9981. CurrencyName = x.CurrencyName,
  9982. UpdatePreRate = x.Rate,
  9983. UpdateBreRate = dto.Currencys.Where(x1 => x1.CurrencyName.Equals(x.CurrencyName)).FirstOrDefault()?.Rate ?? 0.00M
  9984. }).ToList();
  9985. }
  9986. else
  9987. {
  9988. rateRecords = dto.Currencys.Select(x => new RateRecordInfo()
  9989. {
  9990. CurrencyCode = x.CurrencyCode,
  9991. CurrencyName = x.CurrencyName,
  9992. UpdatePreRate = 0.00M,
  9993. UpdateBreRate = x.Rate
  9994. }).ToList();
  9995. }
  9996. }
  9997. else
  9998. {
  9999. rateRecords = dto.Currencys.Select(x => new RateRecordInfo()
  10000. {
  10001. CurrencyCode = x.CurrencyCode,
  10002. CurrencyName = x.CurrencyName,
  10003. UpdatePreRate = 0.00M,
  10004. UpdateBreRate = x.Rate
  10005. }).ToList();
  10006. }
  10007. #endregion
  10008. var data = await _enterExitCostRep.PostEnterExitCostOperate(dto);
  10009. if (dto.DayOtherPriceData.Any())
  10010. {
  10011. var inserList = dto.DayOtherPriceData
  10012. .Where(x => x.Id == 0)
  10013. .Select(x => new Grp_DayOtherPrice
  10014. {
  10015. Cost = x.Cost,
  10016. Id = x.Id,
  10017. CreateTime = DateTime.Now,
  10018. CreateUserId = dto.UserId,
  10019. Currency = x.Currency,
  10020. Diid = x.DiId,
  10021. Index = x.Index,
  10022. IsDel = 0,
  10023. SetDataId = x.SetDataId,
  10024. SubTotal = x.SubTotal,
  10025. Remark = x.Remark
  10026. })
  10027. .ToList();
  10028. var updateList = dto.DayOtherPriceData
  10029. .Where(x => x.Id != 0)
  10030. .Select(x => new Grp_DayOtherPrice
  10031. {
  10032. Cost = x.Cost,
  10033. Id = x.Id,
  10034. CreateTime = DateTime.Now,
  10035. CreateUserId = dto.UserId,
  10036. Currency = x.Currency,
  10037. Diid = x.DiId,
  10038. Index = x.Index,
  10039. IsDel = 0,
  10040. SetDataId = x.SetDataId,
  10041. SubTotal = x.SubTotal,
  10042. Remark = x.Remark
  10043. })
  10044. .ToList();
  10045. //添加
  10046. _sqlSugar.BeginTran();
  10047. if (inserList.Any())
  10048. {
  10049. var rowCount = _sqlSugar.Insertable<Grp_DayOtherPrice>(inserList).ExecuteCommand();
  10050. }
  10051. if (updateList.Any())
  10052. {
  10053. var rowCount = _sqlSugar.Updateable<Grp_DayOtherPrice>(updateList).ExecuteCommand();
  10054. }
  10055. _sqlSugar.CommitTran();
  10056. }
  10057. if (data.Code != 0)
  10058. {
  10059. return Ok(JsonView(false, data.Msg));
  10060. }
  10061. //生成默认文件pdf并且通知人员
  10062. var fileView = await GeneralMethod.EnterExitCostDownload(new EnterExitCostDownloadDto()
  10063. {
  10064. DiId = dto.DiId,
  10065. ExportType = 1,
  10066. SubTypeId = 1005
  10067. }, "pdf");
  10068. //发送通知
  10069. string fileUrl = (string)fileView.Data.GetType().GetProperty("Url").GetValue(fileView.Data, null);
  10070. int sign = (int)data.Data.GetType().GetProperty("sign").GetValue(data.Data, null);
  10071. string md5Sign = GeneralMethod.Encrypt($"{sign}&fileName={fileUrl}");
  10072. string url = string.Format("http://oa.pan-american-intl.com:4399/#/Sankunginfo?sign={0}&fileName={1}", sign, fileUrl);
  10073. await AppNoticeLibrary.SendUserMsg_GroupShare_ToGM(dto.DiId, new List<string>() { "208", "233", "21" }, dto.UserId, url);
  10074. //汇率信息记录
  10075. await GeneralMethod.RateRecordSave(dto.UserId, sign, "出入境费用");
  10076. var checkCurrencys = await _enterExitCostRep.GetCheckCurrencies(dto.DiId);
  10077. //汇率验证、反推
  10078. (bool isSendMsg, string msgContent, List<CurrencyInfo> liveRates) = await GeneralMethod.EnterExitCostCheckRate(dto.DiId, checkCurrencys);
  10079. if (isSendMsg)
  10080. {
  10081. //消息推送
  10082. await AppNoticeLibrary.SendUserMsg_GroupShare_ToFin(dto.DiId, dto.UserId, msgContent);
  10083. }
  10084. #region 日志汇率记录
  10085. //按照已使用币种记录
  10086. if (checkCurrencys != null && checkCurrencys.Count > 0)
  10087. {
  10088. rateRecords = rateRecords.Where(x => checkCurrencys.Select(x1 => x1.CurrencyName).ToList().Contains(x.CurrencyName)).ToList();
  10089. //汇率记录中加入实时汇率
  10090. if (liveRates != null && liveRates.Count > 0)
  10091. {
  10092. foreach (var item in rateRecords)
  10093. {
  10094. item.CurrLiveRate = liveRates.Where(x => x.CurrencyName.Equals(item.CurrencyName)).FirstOrDefault()?.Rate ?? 0.00M;
  10095. }
  10096. }
  10097. var teamName = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == dto.DiId && x.IsDel == 0).Select(x => x.TeamName).FirstAsync();
  10098. var operationName = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == dto.UserId && x.IsDel == 0).Select(x => x.CnName).FirstAsync();
  10099. var logContent = new StringBuilder();
  10100. foreach (var item in rateRecords)
  10101. {
  10102. var blRate = (item.CurrLiveRate * 1.0350M).TruncDecimals(4);
  10103. string msg = $">- {item.CurrencyName}汇率:(页面保存前){item.UpdatePreRate:#0.0000}/(页面保存){item.UpdateBreRate:#0.0000}/实时汇率(已上浮1.0350):{blRate:#0.0000}【注:原接口输出汇率为:{item.CurrLiveRate:#0.0000}】";
  10104. logContent.AppendLine(msg);
  10105. }
  10106. _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());
  10107. }
  10108. #endregion
  10109. return Ok(JsonView(true, data.Msg, data.Data));
  10110. }
  10111. catch (Exception ex)
  10112. {
  10113. return Ok(JsonView(false, ex.Message));
  10114. }
  10115. }
  10116. /// <summary>
  10117. /// 团组模块 - 出入境费用 - Confirm 费用
  10118. /// </summary>
  10119. /// <returns></returns>
  10120. [HttpPost]
  10121. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10122. public async Task<IActionResult> PostEnterExitCostIsConfirm(ConfirmCostDto dto)
  10123. {
  10124. //TODO:测试完毕需把对应的用户ID更改
  10125. //1、数据表添加字段
  10126. //2、更改字段接口()
  10127. var _view = await _enterExitCostRep.ConfirmCost(dto);
  10128. //3、确认成功 给财务发送消息
  10129. if (_view.Code == 200)
  10130. {
  10131. if (dto.Type == 1)
  10132. {
  10133. int diId = _enterExitCostRep._sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.Id == dto.Id).First()?.DiId ?? 0;
  10134. await AppNoticeLibrary.SendUserMsg_GroupShare_ToFinance(diId);
  10135. }
  10136. }
  10137. return Ok(_view);
  10138. }
  10139. /// <summary>
  10140. /// 团组模块 - 出入境费用 - File download
  10141. /// </summary>
  10142. /// <param name="dto"></param>
  10143. /// <returns></returns>
  10144. [HttpPost]
  10145. //[ApiLog("Grp_EnterExitCost", OperationEnum.Download)]
  10146. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10147. public async Task<IActionResult> PostEnterExitCostDownload(EnterExitCostDownloadDto dto)
  10148. {
  10149. try
  10150. {
  10151. if (dto.DiId < 1) return Ok(JsonView(400, "请传入有效的DiId参数;", ""));
  10152. if (dto.ExportType < 1) return Ok(JsonView(400, "请传入有效的ExportType参数; 1 明细表 2 表格", ""));
  10153. if (dto.SubTypeId < 1) return Ok(JsonView(400, @"请传入有效的SubTypeId参数;
  10154. 1 明细表 --> 1005(默认明细表) 1006(因公出国(境)经费测算明细表) 1007(四川省商务厅出国经费财政先行审核表)
  10155. 2 表格 --> 1008(派员单位出(境)任务和预算审批意见表) 1009(省级单位出(境)经费报销单)
  10156. 3 团组成员名单 1 团组成员名单", ""));
  10157. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).OrderByDescending(x => x.CreateTime).First();
  10158. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).ToList();
  10159. if (_EnterExitCosts == null) return Ok(JsonView(400, "该团组未填写出入境费用;", ""));
  10160. var currencyInit = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToList();
  10161. var enterExitCostCurrencys = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(_EnterExitCosts.CurrencyRemark);
  10162. //数据源
  10163. var dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  10164. var dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  10165. var dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  10166. var dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  10167. var dac5 = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  10168. .LeftJoin<Sys_SetData>((x, a) => a.IsDel == 0 && a.Id == x.SetDataId)
  10169. .LeftJoin<Sys_SetData>((x, a, b) => b.IsDel == 0 && b.Id == x.Currency)
  10170. .Where((x, a, b) => x.IsDel == 0 && x.Diid == dto.DiId)
  10171. .Select((x, a, b) => new
  10172. {
  10173. x.Index,
  10174. itemName = a.Name,
  10175. CurrencyStr = b.Name,
  10176. x.Cost,
  10177. x.SubTotal,
  10178. x.Remark
  10179. })
  10180. .OrderBy((x) => x.Index)
  10181. .ToList(); //其他款项费用
  10182. var peiceItemCurrencys = new List<string>();
  10183. if (_DayAndCosts.Any())
  10184. {
  10185. var currencyIds = _DayAndCosts.Select(x => x.Currency).Distinct().ToList();
  10186. if (currencyIds.Any()) peiceItemCurrencys.AddRange(currencyInit.Where(x => currencyIds.Contains(x.Id)).Select(x => x.Name).ToList());
  10187. }
  10188. if (dac5.Any()) peiceItemCurrencys.AddRange(dac5.Select(x => x.CurrencyStr).Distinct().ToList());
  10189. var peiceItemCurrencyInfos = new List<CurrencyInfo>();
  10190. if (enterExitCostCurrencys.Any() && peiceItemCurrencys.Any())
  10191. {
  10192. peiceItemCurrencyInfos = enterExitCostCurrencys.Where(x => peiceItemCurrencys.Contains(x.CurrencyCode)).ToList();
  10193. }
  10194. var _CurrDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  10195. var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == dto.DiId).First();
  10196. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  10197. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  10198. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  10199. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
  10200. .Select((tcl, dc, cc) => new ClientInfo
  10201. {
  10202. LastName = dc.LastName,
  10203. FirstName = dc.FirstName,
  10204. Sex = dc.Sex,
  10205. Birthday = dc.BirthDay,
  10206. Company = cc.CompanyFullName,
  10207. Job = dc.Job
  10208. })
  10209. .ToList();
  10210. foreach (var item in DeleClientList)
  10211. {
  10212. EncryptionProcessor.DecryptProperties(item);
  10213. }
  10214. var blackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  10215. var threeCodes = _sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList();
  10216. var placeData = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  10217. var rateDatas = await _EnterExitCosts.CurrencyRemark.SplitExchangeRate();
  10218. _DelegationInfo.VisitCountry = _DelegationInfo.VisitCountry.Replace("|", "、");
  10219. if (dto.ExportType == 1) //明细表
  10220. {
  10221. if (dto.SubTypeId == 1005) //1005(默认明细表)
  10222. {
  10223. //获取模板
  10224. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/出入境费用表模板.docx");
  10225. //载入模板
  10226. var doc = new Document(tempPath);
  10227. var builder = new DocumentBuilder(doc);
  10228. var dic = new Dictionary<string, string>();
  10229. decimal stayFeeTotal = _EnterExitCosts.ChoiceThree == 1 ? _DayAndCosts.Where(it => it.Type == 1).Sum(it => it.SubTotal) : 0.00M; // 住宿费
  10230. decimal mealsFeeTotal = _EnterExitCosts.ChoiceFour == 1 ? _DayAndCosts.Where(it => it.Type == 2).Sum(it => it.SubTotal) : 0.00M; // 伙食费费
  10231. decimal miscellaneousFeeTotal = _EnterExitCosts.ChoiceFive == 1 ? _DayAndCosts.Where(it => it.Type == 3).Sum(it => it.SubTotal) : 0.00M; // 公杂费
  10232. decimal tainFeeTotal = _EnterExitCosts.ChoiceSix == 1 ? _DayAndCosts.Where(it => it.Type == 4).Sum(it => it.SubTotal) : 0.00M; // 培训费
  10233. decimal otherPriceTotal = _EnterExitCosts.OtherExpenses_Checked == 1 ? dac5.Sum(x => x.SubTotal) : 0.00M; //其他费用
  10234. decimal insidePayTotal = _EnterExitCosts.ChoiceOne == 1 ? _EnterExitCosts.InsidePay : 0.00M;
  10235. //境内费用(其他费用)
  10236. if (_EnterExitCosts.ChoiceOne == 1)
  10237. {
  10238. string row1_1 = "";
  10239. if (_EnterExitCosts.Visa > 0)
  10240. {
  10241. //insidePayTotal += _EnterExitCosts.Visa;
  10242. row1_1 = $"签证费:{_EnterExitCosts.Visa:#0.00} 元/人";
  10243. //if (!string.IsNullOrEmpty(_EnterExitCosts.VisaRemark))
  10244. //{
  10245. // row1_1 += $"\t签证费用描述: {_EnterExitCosts.VisaRemark} 人民币/人";
  10246. //}
  10247. }
  10248. string row1_2 = "";
  10249. if (_EnterExitCosts.YiMiao > 0)
  10250. {
  10251. //insidePayTotal += _EnterExitCosts.YiMiao;
  10252. row1_2 += $"疫苗费:{_EnterExitCosts.YiMiao:#0.00} 元/人";
  10253. }
  10254. if (_EnterExitCosts.HeSuan > 0)
  10255. {
  10256. //insidePayTotal += _EnterExitCosts.HeSuan;
  10257. row1_2 += $"核酸检测费:{_EnterExitCosts.HeSuan:#0.00} 元/人";
  10258. }
  10259. if (_EnterExitCosts.Service > 0)
  10260. {
  10261. //insidePayTotal += _EnterExitCosts.Service;
  10262. row1_2 += $"服务费:{_EnterExitCosts.Service:#0.00} 元/人";
  10263. }
  10264. string row1_3 = "";
  10265. if (_EnterExitCosts.Safe > 0)
  10266. {
  10267. //insidePayTotal += _EnterExitCosts.Safe;
  10268. row1_3 += $"保险费:{_EnterExitCosts.Safe:#0.00} 元/人";
  10269. }
  10270. if (_EnterExitCosts.Ticket > 0)
  10271. {
  10272. //insidePayTotal += _EnterExitCosts.Ticket;
  10273. row1_3 += $"参展门票:{_EnterExitCosts.Ticket:#0.00} 元/人";
  10274. }
  10275. string row1 = "";
  10276. if (!string.IsNullOrEmpty(row1_1)) row1 += $"{row1_1}\r\n";
  10277. if (!string.IsNullOrEmpty(row1_2)) row1 += $"{row1_2}\r\n";
  10278. if (!string.IsNullOrEmpty(row1_3)) row1 += $"{row1_3}\r\n";
  10279. row1 += $"备注:{_EnterExitCosts.Remark}";
  10280. dic.Add("InsidePay", insidePayTotal.ToString("#0.00"));
  10281. dic.Add("Row1Str", row1);
  10282. }
  10283. var airTotalStr = new StringBuilder();
  10284. var airPriceStr = new StringBuilder();
  10285. var cityTrafficLabel = new StringBuilder();
  10286. //经济舱
  10287. if (_EnterExitCosts.SumJJC == 1)
  10288. {
  10289. airTotalStr.AppendFormat($"{_EnterExitCosts.OutsideJJPay:#0.00}元/人(经济舱)");
  10290. airPriceStr.AppendFormat($"{_EnterExitCosts.AirJJ:#0.00}元/人(经济舱)");
  10291. cityTrafficLabel.AppendFormat("经济舱:{0:#0.00} 元/人 ", _EnterExitCosts.CityTranffic);
  10292. }
  10293. //公务舱
  10294. if (_EnterExitCosts.SumGWC == 1)
  10295. {
  10296. airTotalStr.AppendFormat($"{_EnterExitCosts.OutsideGWPay:#0.00} 元/人(公务舱)");
  10297. airPriceStr.AppendFormat($"{_EnterExitCosts.AirGW:#0.00} 元/人(公务舱)");
  10298. cityTrafficLabel.AppendFormat("公务舱:{0:#0.00} 元/人 ", _EnterExitCosts.CityTranffic1);
  10299. }
  10300. //头等舱
  10301. if (_EnterExitCosts.SumTDC == 1)
  10302. {
  10303. airTotalStr.AppendFormat($"{_EnterExitCosts.OutsideTDPay:#0.00} 元/人(头等舱)");
  10304. airPriceStr.AppendFormat($"{_EnterExitCosts.AirTD:#0.00} 元/人(头等舱)");
  10305. cityTrafficLabel.AppendFormat("头等舱:{0:#0.00} 元/人 ", _EnterExitCosts.CityTranffic2);
  10306. }
  10307. //描述
  10308. var remarkLable = new StringBuilder();
  10309. //第二项描述
  10310. remarkLable.Append("备注:");
  10311. if (!string.IsNullOrEmpty(_EnterExitCosts.TwoItemRemark)) remarkLable.AppendFormat(_EnterExitCosts.TwoItemRemark);
  10312. //汇率描述
  10313. if (peiceItemCurrencyInfos.Any())
  10314. {
  10315. remarkLable.AppendLine();
  10316. remarkLable.AppendFormat("汇率描述:");
  10317. foreach (var item in peiceItemCurrencyInfos)
  10318. {
  10319. remarkLable.AppendFormat($"{item.CurrencyName}({item.CurrencyCode}):{item.Rate:#0.0000} ");
  10320. }
  10321. }
  10322. dic.Add("AirTotalStr", airTotalStr.ToString());
  10323. dic.Add("AirPriceStr", airPriceStr.ToString());
  10324. dic.Add("CityTranffic", cityTrafficLabel.ToString());
  10325. dic.Add("TwoItemRemark", remarkLable.ToString());
  10326. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  10327. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  10328. int table1Row = 0,
  10329. table2Row = 0,
  10330. table3Row = 0,
  10331. table4Row = 0,
  10332. table5Row = 0;
  10333. //住宿费
  10334. if (_EnterExitCosts.ChoiceThree == 1)
  10335. {
  10336. dic.Add("SubZS", stayFeeTotal.ToString("#0.00"));
  10337. table1Row = dac1.Count;
  10338. #region 填充word表格内容
  10339. for (int i = 0; i < dac1.Count; i++)
  10340. {
  10341. Grp_DayAndCost dac = dac1[i];
  10342. if (dac == null) continue;
  10343. builder.MoveToCell(0, i, 0, 0);
  10344. builder.Write("第" + dac.Days.ToString() + "晚:");
  10345. builder.MoveToCell(0, i, 1, 0);
  10346. //builder.Write(placeData.Find(it => it.Id == dac.NationalTravelFeeId)?.Country ?? "Unknown");
  10347. //builder.Write(dac.Place == null ? "" : dac.Place);
  10348. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  10349. builder.MoveToCell(0, i, 2, 0);
  10350. builder.Write("费用标准:");
  10351. string curr = "";
  10352. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  10353. if (currData != null)
  10354. {
  10355. curr = currData.Name;
  10356. }
  10357. builder.MoveToCell(0, i, 3, 0);
  10358. builder.Write(dac.Cost.ToString("#0.00") + curr);
  10359. builder.MoveToCell(0, i, 4, 0);
  10360. builder.Write("费用小计:");
  10361. builder.MoveToCell(0, i, 5, 0);
  10362. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  10363. }
  10364. #endregion
  10365. }
  10366. else dic.Add("SubZS", "0.00");
  10367. //删除多余行
  10368. while (table1.Rows.Count > table1Row)
  10369. {
  10370. table1.Rows.RemoveAt(table1Row);
  10371. }
  10372. //伙食费
  10373. Aspose.Words.Tables.Table table2 = allTables[1] as Aspose.Words.Tables.Table;
  10374. if (_EnterExitCosts.ChoiceFour == 1)
  10375. {
  10376. dic.Add("SubHS", mealsFeeTotal.ToString("#0.00"));
  10377. table2Row = dac2.Count;
  10378. #region 填充word表格内容
  10379. for (int i = 0; i < dac2.Count; i++)
  10380. {
  10381. Grp_DayAndCost dac = dac2[i];
  10382. if (dac == null) continue;
  10383. builder.MoveToCell(1, i, 0, 0);
  10384. builder.Write("第" + dac.Days.ToString() + "天:");
  10385. builder.MoveToCell(1, i, 1, 0);
  10386. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  10387. builder.MoveToCell(1, i, 2, 0);
  10388. builder.Write("费用标准:");
  10389. string curr = "";
  10390. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  10391. if (currData != null)
  10392. {
  10393. curr = currData.Name;
  10394. }
  10395. builder.MoveToCell(1, i, 3, 0);
  10396. builder.Write(dac.Cost.ToString("#0.00") + curr);
  10397. builder.MoveToCell(1, i, 4, 0);
  10398. builder.Write("费用小计:");
  10399. builder.MoveToCell(1, i, 5, 0);
  10400. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  10401. }
  10402. #endregion
  10403. }
  10404. else dic.Add("SubHS", "0.00");
  10405. //删除多余行
  10406. while (table2.Rows.Count > table2Row)
  10407. {
  10408. table2.Rows.RemoveAt(table2Row);
  10409. }
  10410. //公杂费
  10411. Aspose.Words.Tables.Table table3 = allTables[2] as Aspose.Words.Tables.Table;
  10412. if (_EnterExitCosts.ChoiceFive == 1)
  10413. {
  10414. dic.Add("SubGZF", miscellaneousFeeTotal.ToString("#0.00"));
  10415. table3Row = dac3.Count;
  10416. #region 填充word表格内容
  10417. for (int i = 0; i < dac3.Count; i++)
  10418. {
  10419. Grp_DayAndCost dac = dac3[i];
  10420. if (dac == null) continue;
  10421. builder.MoveToCell(2, i, 0, 0);
  10422. builder.Write("第" + dac.Days.ToString() + "天:");
  10423. builder.MoveToCell(2, i, 1, 0);
  10424. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  10425. builder.MoveToCell(2, i, 2, 0);
  10426. builder.Write("费用标准:");
  10427. string curr = "";
  10428. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  10429. if (currData != null)
  10430. {
  10431. curr = currData.Name;
  10432. }
  10433. builder.MoveToCell(2, i, 3, 0);
  10434. builder.Write(dac.Cost.ToString("#0.00") + curr);
  10435. builder.MoveToCell(2, i, 4, 0);
  10436. builder.Write("费用小计:");
  10437. builder.MoveToCell(2, i, 5, 0);
  10438. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  10439. }
  10440. //删除多余行
  10441. while (table3.Rows.Count > table3Row)
  10442. {
  10443. table3.Rows.RemoveAt(table3Row);
  10444. }
  10445. #endregion
  10446. }
  10447. else dic.Add("SubGZF", "0.00");
  10448. //删除多余行
  10449. while (table3.Rows.Count > table3Row)
  10450. {
  10451. table3.Rows.RemoveAt(table3Row);
  10452. }
  10453. //培训费
  10454. Aspose.Words.Tables.Table table4 = allTables[3] as Aspose.Words.Tables.Table;
  10455. if (_EnterExitCosts.ChoiceSix == 1)
  10456. {
  10457. string pxStr = $"六、培训费合计: {tainFeeTotal:#0.00} 元/人";
  10458. dic.Add("SubPX", pxStr);
  10459. table4Row = dac4.Count;
  10460. #region 填充word表格内容
  10461. for (int i = 0; i < dac4.Count; i++)
  10462. {
  10463. Grp_DayAndCost dac = dac4[i];
  10464. if (dac == null) continue;
  10465. builder.MoveToCell(3, i, 0, 0);
  10466. builder.Write("第" + dac.Days.ToString() + "天:");
  10467. builder.MoveToCell(3, i, 1, 0);
  10468. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  10469. builder.MoveToCell(3, i, 2, 0);
  10470. builder.Write("费用标准:");
  10471. string curr = "";
  10472. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  10473. if (currData != null)
  10474. {
  10475. curr = currData.Name;
  10476. }
  10477. builder.MoveToCell(3, i, 3, 0);
  10478. builder.Write(dac.Cost.ToString("#0.00") + curr);
  10479. builder.MoveToCell(3, i, 4, 0);
  10480. builder.Write("费用小计:");
  10481. builder.MoveToCell(3, i, 5, 0);
  10482. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  10483. }
  10484. #endregion
  10485. }
  10486. //else dic.Add("SubPX", $"六、培训费合计: 0.00 元/人");
  10487. //删除多余行
  10488. while (table4.Rows.Count > table4Row)
  10489. {
  10490. table4.Rows.RemoveAt(table4Row);
  10491. }
  10492. //其他费用
  10493. Aspose.Words.Tables.Table table5 = allTables[4] as Aspose.Words.Tables.Table;
  10494. if (_EnterExitCosts.OtherExpenses_Checked == 1)
  10495. {
  10496. string qtStr = $"七、其他费用合计: {otherPriceTotal:#0.00} 元/人";
  10497. dic.Add("titleQi", qtStr);
  10498. table5Row = dac5.Count;
  10499. #region 填充word表格内容
  10500. for (int i = 0; i < dac5.Count; i++)
  10501. {
  10502. var dac = dac5[i];
  10503. if (dac == null) continue;
  10504. builder.MoveToCell(4, i, 0, 0);
  10505. builder.Write("第" + dac.Index.ToString() + "项:");
  10506. builder.MoveToCell(4, i, 1, 0);
  10507. builder.Write(dac.itemName);
  10508. builder.MoveToCell(4, i, 2, 0);
  10509. builder.Write("费用标准:");
  10510. builder.MoveToCell(4, i, 3, 0);
  10511. builder.Write(dac.Cost.ToString("#0.00") + dac.CurrencyStr);
  10512. builder.MoveToCell(4, i, 4, 0);
  10513. builder.Write("费用小计:");
  10514. builder.MoveToCell(4, i, 5, 0);
  10515. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  10516. builder.MoveToCell(4, i, 6, 0);
  10517. builder.Write("备注:");
  10518. builder.MoveToCell(4, i, 7, 0);
  10519. builder.Write(dac.Remark);
  10520. }
  10521. #endregion
  10522. }
  10523. //else dic.Add("SubQT", "七、其他费用合计: 0 元/人");
  10524. //删除多余行
  10525. while (table5.Rows.Count > table5Row)
  10526. {
  10527. table5.Rows.RemoveAt(table5Row);
  10528. }
  10529. //加上其他费用
  10530. decimal otherFeeTotal = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + otherPriceTotal;
  10531. decimal subJJC = 0.00M,
  10532. subGWC = 0.00M,
  10533. subTDC = 0.00M;
  10534. //全部费用总计: 元 / 人(经济舱) 元 / 人(公务舱) 元 / 人(头等舱)
  10535. string totalLabel = string.Format("全部费用总计:");
  10536. //经济舱
  10537. if (_EnterExitCosts.SumJJC == 1)
  10538. {
  10539. subJJC = otherFeeTotal + _EnterExitCosts.OutsideJJPay;
  10540. totalLabel += $"{subJJC:#0.00} 元/人(经济舱)";
  10541. }
  10542. //公务舱
  10543. if (_EnterExitCosts.SumGWC == 1)
  10544. {
  10545. subGWC = otherFeeTotal + _EnterExitCosts.OutsideGWPay;
  10546. totalLabel += $"{subGWC:#0.00} 元/人(公务舱)";
  10547. }
  10548. //头等舱
  10549. if (_EnterExitCosts.SumTDC == 1)
  10550. {
  10551. subTDC = otherFeeTotal + _EnterExitCosts.OutsideTDPay;
  10552. totalLabel += $"{subTDC:#0.00} 元/人(头等舱)";
  10553. }
  10554. //TotalLabel
  10555. dic.Add("TotalLabel", totalLabel);
  10556. //dic.Add("SubJJC", subJJC.ToString("#0.00"));
  10557. //dic.Add("SubGWC", subGWC.ToString("#0.00"));
  10558. //dic.Add("SubTDC", subTDC.ToString("#0.00"));
  10559. #region 填充word模板书签内容
  10560. foreach (var key in dic.Keys)
  10561. {
  10562. Bookmark bookmark = doc.Range.Bookmarks[key];
  10563. if (bookmark != null)
  10564. {
  10565. builder.MoveToBookmark(key);
  10566. builder.Write(dic[key]);
  10567. }
  10568. }
  10569. #endregion
  10570. #region 设置页眉
  10571. string userLabel = string.Empty;
  10572. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  10573. if (currUserInfo != null)
  10574. {
  10575. var userInfo = await _usersRep.GetUserBriefInfo(currUserInfo.UserId);
  10576. if (userInfo != null)
  10577. {
  10578. string ext = string.IsNullOrEmpty(userInfo.ExtensionNumber) ? "-" : userInfo.ExtensionNumber;
  10579. //userLabel = $"联系人:{userInfo.Name} 职位:{userInfo.Job}\r\n座机/分机号:{ext} 手机号:{userInfo.Tel} 公司邮箱:{userInfo.Email}";
  10580. userLabel = $"联系人:{userInfo.Name} 职 位:{userInfo.Job} 手机号:{userInfo.Tel}\r\n公司邮箱:{userInfo.Email}";
  10581. }
  10582. }
  10583. //设置页脚
  10584. //GeneralMethod.AsposeWordSetFooter(builder, userLabel, "华文仿宋", 10);
  10585. #endregion
  10586. var guid = CommonFun.GUID.Substring(0, 8);
  10587. //文件名
  10588. string strFileName = CommonFun.ValidFileName($"{_DelegationInfo.TeamName}出入境费用{guid}.docx");
  10589. AsposeHelper.removewatermark_v2180();
  10590. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  10591. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  10592. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  10593. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  10594. }
  10595. else if (dto.SubTypeId == 1006)//1006(因公出国(境)经费测算明细表)
  10596. {
  10597. //获取模板
  10598. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/因公出国(境)经费测算明细表.docx");
  10599. //载入模板
  10600. var doc = new Document(tempPath);
  10601. var builder = new DocumentBuilder(doc);
  10602. var dic = new Dictionary<string, string>();
  10603. if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  10604. {
  10605. var list = new List<string>();
  10606. try
  10607. {
  10608. var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  10609. foreach (var item in spilitArr)
  10610. {
  10611. var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  10612. var depCode = spDotandEmpty[2].Substring(0, 3);
  10613. var arrCode = spDotandEmpty[2].Substring(3, 3);
  10614. string depName = threeCodes.Find(it => it.Three.Equals(depCode)).City,
  10615. arrName = threeCodes.Find(it => it.Three.Equals(arrCode)).City;
  10616. list.Add(depName);
  10617. list.Add(arrName);
  10618. }
  10619. list = list.Distinct().ToList();
  10620. dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  10621. }
  10622. catch (Exception)
  10623. {
  10624. dic.Add("ReturnCode", "行程录入不正确!");
  10625. }
  10626. }
  10627. else
  10628. {
  10629. dic.Add("ReturnCode", "未录入行程!");
  10630. }
  10631. dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  10632. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  10633. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  10634. if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  10635. {
  10636. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  10637. dic.Add("Day", sp.Days.ToString());
  10638. }
  10639. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  10640. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  10641. //var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  10642. //dic.Add("Names", Names);
  10643. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  10644. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  10645. decimal dac1totalPrice = 0.00M;
  10646. int accommodationStartIndex = 6, foodandotherStartIndex = 22;
  10647. foreach (var dac in dac1)
  10648. {
  10649. if (dac.SubTotal == 0.00M)
  10650. {
  10651. continue;
  10652. }
  10653. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  10654. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  10655. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  10656. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  10657. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  10658. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  10659. builder.Write(currency);//币种
  10660. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  10661. builder.Write(dac.Cost.ToString("#0.00"));//标准
  10662. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  10663. builder.Write("");//人数
  10664. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  10665. builder.Write("");//天数
  10666. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  10667. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  10668. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  10669. decimal rate = 0.00M;
  10670. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  10671. builder.Write(rate.ToString("#0.0000"));//汇率
  10672. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  10673. decimal rbmPrice = dac.SubTotal;
  10674. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  10675. accommodationStartIndex++;
  10676. dac1totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  10677. }
  10678. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  10679. for (int i = 21; i > (dac1.Count == 0 ? 1 : dac1.Count) + 6; i--)
  10680. {
  10681. table1.Rows.RemoveAt(i - 1);
  10682. foodandotherStartIndex--;
  10683. }
  10684. if (dac2.Count == dac3.Count)//国家 币种 金额
  10685. {
  10686. for (int i = 0; i < dac2.Count; i++)
  10687. {
  10688. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  10689. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  10690. }
  10691. }
  10692. decimal dac2totalPrice = 0.00M;
  10693. foreach (var dac in dac2)
  10694. {
  10695. if (dac.SubTotal == 0)
  10696. {
  10697. continue;
  10698. }
  10699. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  10700. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  10701. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  10702. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  10703. builder.Write(currency);//币种
  10704. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  10705. builder.Write(dac.Cost.ToString("#0.00"));//标准
  10706. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  10707. builder.Write("");//人数
  10708. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  10709. builder.Write("");//天数
  10710. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  10711. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  10712. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  10713. decimal rate = 0.00M;
  10714. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  10715. builder.Write(rate.ToString("#0.0000"));//汇率
  10716. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  10717. decimal rbmPrice = dac.SubTotal;
  10718. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  10719. foodandotherStartIndex++;
  10720. dac2totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  10721. }
  10722. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  10723. for (int i = foodandotherStartIndex + (15 - dac2.Count); i > (dac2.Count == 0 ? 1 : 0) + foodandotherStartIndex; i--)
  10724. {
  10725. table1.Rows.RemoveAt(i - 1);
  10726. }
  10727. var cityTrafficLabel = new StringBuilder()
  10728. .AppendFormat(" 经济舱:{0:#0.00} 元", _EnterExitCosts.CityTranffic)
  10729. .AppendFormat(" 公务舱:{0:#0.00} 元", _EnterExitCosts.CityTranffic1)
  10730. .AppendFormat(" 头等舱:{0:#0.00} ", _EnterExitCosts.CityTranffic2)
  10731. .ToString();
  10732. dic.Add("CityTranffic", cityTrafficLabel);
  10733. string otherFeeStr = "";
  10734. if (_EnterExitCosts.Visa > 0) otherFeeStr += $"签证费:{_EnterExitCosts.Visa:#0.00} 元,";
  10735. if (_EnterExitCosts.Safe > 0) otherFeeStr += $"保险费:{_EnterExitCosts.Safe:#0.00} 元,";
  10736. if (_EnterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费:{_EnterExitCosts.Ticket:#0.00} 元,";
  10737. #region 其他款项费用 增加位置:模板第6项其他费用字符串追加
  10738. foreach (var otherInfo in dac5)
  10739. {
  10740. otherFeeStr += $"{otherInfo.itemName}:{otherInfo.SubTotal.ToString("#0.00")} 元,";
  10741. }
  10742. #endregion
  10743. if (otherFeeStr.Length > 0)
  10744. {
  10745. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  10746. otherFeeStr = $"({otherFeeStr})";
  10747. dic.Add("OtherFeeStr", otherFeeStr);
  10748. }
  10749. //总计
  10750. decimal allPrice = dac1totalPrice + dac2totalPrice + _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket;
  10751. //国际旅费
  10752. string outsideAir = string.Empty;
  10753. string allPriceAir = string.Empty;
  10754. if (_EnterExitCosts.SumJJC == 1)
  10755. {
  10756. outsideAir += string.Format(@"经济舱:{0} 元/人;", _EnterExitCosts.AirJJ.ToString("#0.00"));
  10757. allPriceAir += string.Format(@"经济舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideJJPay).ToString("#0.00"));
  10758. }
  10759. if (_EnterExitCosts.SumGWC == 1)
  10760. {
  10761. outsideAir += string.Format(@"公务舱:{0} 元/人;", _EnterExitCosts.AirGW.ToString("#0.00"));
  10762. allPriceAir += string.Format(@"公务舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  10763. }
  10764. if (_EnterExitCosts.SumTDC == 1)
  10765. {
  10766. outsideAir += string.Format(@"头等舱:{0} 元/人;", _EnterExitCosts.AirTD.ToString("#0.00"));
  10767. allPriceAir += string.Format(@"头等舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideTDPay).ToString("#0.00"));
  10768. }
  10769. dic.Add("InTravelPrice", $"({outsideAir})");
  10770. dic.Add("FinalSumPrice", $"({allPriceAir})");
  10771. //dic.Add("VisaPay", _EnterExitCosts.Visa.ToString("#0.00"));
  10772. //dic.Add("SafePay", _EnterExitCosts.Safe.ToString("#0.00"));
  10773. //dic.Add("YiMiao", _EnterExitCosts.YiMiao.ToString("#0.00"));
  10774. foreach (var key in dic.Keys)
  10775. {
  10776. builder.MoveToBookmark(key);
  10777. builder.Write(dic[key]);
  10778. }
  10779. //模板文件名
  10780. string strFileName = $"{_DelegationInfo.TeamName}因公出国(境)经费测算明细表{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
  10781. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  10782. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  10783. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  10784. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  10785. }
  10786. else if (dto.SubTypeId == 1007) //1007(四川省商务厅出国经费财政先行审核表)
  10787. {
  10788. //获取模板
  10789. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/四川省商务厅出国经费财政先行审核表.xls");
  10790. //载入模板
  10791. var designer = new WorkbookDesigner
  10792. {
  10793. Workbook = new Workbook(tempPath)
  10794. };
  10795. var dic = new Dictionary<string, string>();
  10796. if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  10797. {
  10798. var list = new List<string>();
  10799. try
  10800. {
  10801. var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  10802. foreach (var item in spilitArr)
  10803. {
  10804. var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  10805. var depCode = spDotandEmpty[2].Substring(0, 3);
  10806. var arrCode = spDotandEmpty[2].Substring(3, 3);
  10807. string depName = threeCodes.Find(it => it.Three.Equals(depCode))?.City ?? "Unknwon",
  10808. arrName = threeCodes.Find(it => it.Three.Equals(arrCode))?.City ?? "Unknown";
  10809. list.Add(depName);
  10810. list.Add(arrName);
  10811. }
  10812. list = list.Distinct().ToList();
  10813. dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  10814. }
  10815. catch (Exception)
  10816. {
  10817. dic.Add("ReturnCode", "行程录入不正确!");
  10818. }
  10819. }
  10820. else
  10821. {
  10822. dic.Add("ReturnCode", "未录入行程!");
  10823. }
  10824. dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  10825. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  10826. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  10827. if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  10828. {
  10829. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  10830. dic.Add("Day", sp.Days.ToString());
  10831. }
  10832. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  10833. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  10834. var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  10835. designer.SetDataSource("ClientUnit", _DelegationInfo.ClientUnit);
  10836. designer.SetDataSource("VisitCountry", _DelegationInfo.VisitCountry);
  10837. designer.SetDataSource("Group", _DelegationInfo.TeamName);
  10838. designer.SetDataSource("ClientUnitTitle", _DelegationInfo.TeamName);
  10839. designer.SetDataSource("Name", Names);
  10840. designer.SetDataSource("VisitStartDate", dic["VisitStartDate"] + "-" + dic["VisitEndDate"]);
  10841. designer.SetDataSource("Day", dic["Day"] + "天");
  10842. designer.SetDataSource("ReturnCode", dic["ReturnCode"]);
  10843. designer.SetDataSource("ReturnCodeAir", dic["ReturnCodeAir"]);
  10844. int startIndex = 10;
  10845. const int startIndexcopy = 10;
  10846. if (dac2.Count == dac3.Count)//国家 币种 金额
  10847. {
  10848. for (int i = 0; i < dac2.Count; i++)
  10849. {
  10850. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  10851. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  10852. }
  10853. }
  10854. var dtdac1 = new DataTable();
  10855. var place = new List<string>();
  10856. dtdac1.Columns.AddRange(new DataColumn[] {
  10857. new(){ ColumnName = "city"},
  10858. new(){ ColumnName = "curr"},
  10859. new(){ ColumnName = "criterion"},
  10860. new(){ ColumnName = "number",DataType = typeof(int)},
  10861. new(){ ColumnName = "day",DataType = typeof(int)},
  10862. new(){ ColumnName = "cost", DataType = typeof(decimal)},
  10863. new(){ ColumnName = "rate", DataType = typeof(decimal) },
  10864. new(){ ColumnName = "costRMB", DataType = typeof(decimal) },
  10865. });
  10866. var dtdac2 = new DataTable();
  10867. dtdac2.Columns.AddRange(new DataColumn[] {
  10868. new(){ ColumnName = "city"},
  10869. new(){ ColumnName = "curr"},
  10870. new(){ ColumnName = "criterion"},
  10871. new(){ ColumnName = "number",DataType = typeof(int)},
  10872. new(){ ColumnName = "day",DataType = typeof(int)},
  10873. new(){ ColumnName = "cost", DataType = typeof(decimal)},
  10874. new(){ ColumnName = "rate", DataType = typeof(decimal) },
  10875. new(){ ColumnName = "costRMB",DataType = typeof(decimal)},
  10876. });
  10877. dtdac1.TableName = "tb1";
  10878. dtdac2.TableName = "tb2";
  10879. decimal dac1totalPrice = 0.00M, dac2totalPrice = 0.00M;
  10880. foreach (var item in dac1)
  10881. {
  10882. item.Place = GetEnterExitCostExportCity(placeData, item.NationalTravelFeeId);
  10883. if (place.Contains(item.Place))
  10884. {
  10885. continue;
  10886. }
  10887. DataRow row = dtdac1.NewRow();
  10888. row["city"] = item.Place;
  10889. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  10890. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  10891. row["curr"] = currency;
  10892. row["rate"] = rate.ToString("#0.0000");
  10893. row["criterion"] = item.Cost.ToString("#0.00");
  10894. row["number"] = 1;
  10895. row["day"] = dac1.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  10896. //row["costRMB"] = rbmPrice;
  10897. dtdac1.Rows.Add(row);
  10898. place.Add(item.Place);
  10899. }
  10900. place = new List<string>();
  10901. foreach (var item in dac2)
  10902. {
  10903. item.Place = GetEnterExitCostExportCity(placeData, item.NationalTravelFeeId);
  10904. if (place.Contains(item.Place))
  10905. {
  10906. continue;
  10907. }
  10908. DataRow row = dtdac2.NewRow();
  10909. row["city"] = item.Place;
  10910. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  10911. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  10912. row["curr"] = currency;
  10913. row["rate"] = rate.ToString("#0.0000");
  10914. row["criterion"] = item.Cost.ToString("#0.00");
  10915. row["number"] = 1;
  10916. row["day"] = dac2.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  10917. //row["cost"] = item.SubTotal;
  10918. //row["costRMB"] = rbmPrice;
  10919. dtdac2.Rows.Add(row);
  10920. place.Add(item.Place);
  10921. //dac2totalPrice += rbmPrice;
  10922. }
  10923. dac1totalPrice = dac1.Sum(it => it.SubTotal);
  10924. dac2totalPrice = dac2.Sum(it => it.SubTotal);
  10925. designer.SetDataSource("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  10926. designer.SetDataSource("dac2totalPrice", dac2totalPrice);
  10927. var cityTrafficLabel = new StringBuilder()
  10928. .AppendFormat(" 其中:国外城市间")
  10929. .AppendFormat(" 经济舱费:{0:#0.00} 元、", _EnterExitCosts.CityTranffic)
  10930. .AppendFormat(" 公务舱费:{0:#0.00} 元、", _EnterExitCosts.CityTranffic1)
  10931. .AppendFormat(" 头等舱费:{0:#0.00} 元", _EnterExitCosts.CityTranffic2)
  10932. .ToString();
  10933. //decimal cityTraffic =_EnterExitCosts.CityTranffic + _EnterExitCosts.CityTranffic1 + _EnterExitCosts.CityTranffic2;
  10934. designer.SetDataSource("cityTranffic", cityTrafficLabel);
  10935. // designer.SetDataSource("sumCityTranffic", @$"{cityTraffic:#0.00} ");
  10936. string cell4Str1 = string.Empty;
  10937. if (_EnterExitCosts.SumJJC == 1) cell4Str1 += $"经济舱:{_EnterExitCosts.AirJJ:#0.00} 元/人;";
  10938. if (_EnterExitCosts.SumGWC == 1) cell4Str1 += $"公务舱:{_EnterExitCosts.AirGW:#0.00} 元/人;";
  10939. if (_EnterExitCosts.SumTDC == 1) cell4Str1 += $"公务舱:{_EnterExitCosts.AirTD:#0.00} 元/人;";
  10940. string cell4Str = $" 4.国际旅费:{cell4Str1}";
  10941. string cellStr = $" 5.其他费用(";
  10942. if (_EnterExitCosts.Visa > 0) cellStr += $"签证费:{_EnterExitCosts.Visa:#0.00}元,";
  10943. if (_EnterExitCosts.YiMiao > 0) cellStr += $"疫苗费:{_EnterExitCosts.YiMiao:#0.00}元,";
  10944. if (_EnterExitCosts.HeSuan > 0) cellStr += $"核酸费:{_EnterExitCosts.HeSuan:#0.00}元,";
  10945. if (_EnterExitCosts.Safe > 0) cellStr += $"保险费:{_EnterExitCosts.Safe:#0.00}元,";
  10946. if (_EnterExitCosts.Ticket > 0) cellStr += $"参展门票费:{_EnterExitCosts.Ticket:#0.00}元,";
  10947. if (_EnterExitCosts.Service > 0) cellStr += $"服务费:{_EnterExitCosts.Service:#0.00}元,";
  10948. #region 其他款项费用 增加位置:模板第5项其他费用字符串追加
  10949. var otherPriceTotal = dac5.Sum(x => x.SubTotal);
  10950. foreach (var otherInfo in dac5)
  10951. {
  10952. cellStr += $"{otherInfo.itemName}:{otherInfo.SubTotal.ToString("#0.00")} 元,";
  10953. }
  10954. #endregion
  10955. if (cellStr.Length > 8)
  10956. {
  10957. cellStr = cellStr.Substring(0, cellStr.Length - 1);
  10958. }
  10959. cellStr += ")";
  10960. decimal otherFee = _EnterExitCosts.Visa + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.Service + otherPriceTotal;
  10961. decimal s = dac1totalPrice + dac2totalPrice + _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay + otherFee;
  10962. decimal pxFee = dac4.Sum(it => it.Cost);
  10963. decimal glvFee = _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay;
  10964. string celllastStr1 = "";
  10965. if (dac1totalPrice > 0) celllastStr1 += $"住宿费 {dac1totalPrice:#0.00} 元";
  10966. if (dac2totalPrice > 0) celllastStr1 += $",伙食费和公杂费 {dac2totalPrice:#0.00} 元";
  10967. if (pxFee > 0) celllastStr1 += $",培训费 {pxFee:#0.00} 元";
  10968. celllastStr1 += $",国际旅费 元";
  10969. if (otherFee > 0) celllastStr1 += $",其他费用 {otherFee:#0.00} 元";
  10970. string celllastStr = $" 经审核,{celllastStr1},本次出国经费预算合计为 元。其中:市本级安排 。";
  10971. designer.SetDataSource("cell4Str", cell4Str);
  10972. designer.SetDataSource("cellStr", cellStr);
  10973. designer.SetDataSource("cellSum", otherFee.ToString("#0.00"));
  10974. designer.SetDataSource("cellSum4", (_EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  10975. designer.SetDataSource("celllastStr", celllastStr);
  10976. Workbook wb = designer.Workbook;
  10977. var sheet = wb.Worksheets[0];
  10978. //绑定datatable数据集
  10979. designer.SetDataSource(dtdac1);
  10980. designer.SetDataSource(dtdac2);
  10981. designer.Process();
  10982. var rowStart = dtdac1.Rows.Count;
  10983. while (rowStart > 0)
  10984. {
  10985. sheet.Cells[startIndex, 8].Formula = $"=G{startIndex + 1} * H{startIndex + 1}";
  10986. sheet.Cells[startIndex, 6].Formula = $"=E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  10987. startIndex++;
  10988. rowStart--;
  10989. }
  10990. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + 1}: I{startIndex})";
  10991. startIndex += 1; //总计行
  10992. rowStart = dtdac2.Rows.Count;
  10993. while (rowStart > 0)
  10994. {
  10995. sheet.Cells[startIndex, 8].Formula = $"= G{startIndex + 1} * H{startIndex + 1}";
  10996. sheet.Cells[startIndex, 6].Formula = $"= E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  10997. startIndex++;
  10998. rowStart--;
  10999. }
  11000. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + dtdac1.Rows.Count + 2}: I{startIndex})";
  11001. wb.CalculateFormula(true);
  11002. //模板文件名
  11003. string strFileName = $"{_DelegationInfo.TeamName}-四川省商务厅出国经费财政先行审核表{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  11004. designer.Workbook.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  11005. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  11006. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  11007. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  11008. }
  11009. else if (dto.SubTypeId == 1066) //成都市因公临时出国任务和预算审批意见表(外专培训团专用)
  11010. {
  11011. //获取模板
  11012. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/成都市因公临时出国任务和预算审批意见表.docx");
  11013. //载入模板
  11014. var doc = new Document(tempPath);
  11015. var builder = new DocumentBuilder(doc);
  11016. var dic = new Dictionary<string, string>
  11017. {
  11018. { "GroupName", _DelegationInfo.TeamName },
  11019. { "ClientUnit", _DelegationInfo.ClientUnit }
  11020. };
  11021. string missionLeader = ""; //团负责人默认接团客户名单第一个人
  11022. string missionLeaderJob = "";//负责人job
  11023. //int groupNumber = 0; //团人数
  11024. if (DeleClientList.Count > 0)
  11025. {
  11026. missionLeader = DeleClientList[0]?.Name ?? "";
  11027. missionLeaderJob = DeleClientList[0]?.Job ?? "";
  11028. }
  11029. dic.Add("MissionLeader", missionLeader); //团负责人
  11030. dic.Add("MissionLeaderJob", missionLeaderJob); //团负责人job
  11031. dic.Add("GroupNumber", _DelegationInfo.VisitPNumber.ToString()); //团人数
  11032. #region MyRegion
  11033. //if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  11034. //{
  11035. // List<string> list = new List<string>();
  11036. // try
  11037. // {
  11038. // var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  11039. // foreach (var item in spilitArr)
  11040. // {
  11041. // var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  11042. // var depCode = spDotandEmpty[2].Substring(0, 3);
  11043. // var arrCode = spDotandEmpty[2].Substring(3, 3);
  11044. // string depName = threeCodes.Find(it => it.Three.Equals(depCode)).City,
  11045. // arrName = threeCodes.Find(it => it.Three.Equals(arrCode)).City;
  11046. // list.Add(depName);
  11047. // list.Add(arrName);
  11048. // }
  11049. // list = list.Distinct().ToList();
  11050. // dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  11051. // }
  11052. // catch (Exception)
  11053. // {
  11054. // dic.Add("ReturnCode", "行程录入不正确!");
  11055. // }
  11056. //}
  11057. //else
  11058. //{
  11059. // dic.Add("ReturnCode", "未录入行程!");
  11060. //}
  11061. List<string> countrys = _groupRepository.GroupSplitCountry(_DelegationInfo.VisitCountry);
  11062. dic.Add("ReturnCode", string.Join("、", countrys));
  11063. #endregion
  11064. //dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  11065. //dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  11066. //dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  11067. //if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  11068. //{
  11069. // TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  11070. // dic.Add("Day", sp.Days.ToString());
  11071. //}
  11072. dic.Add("Day", _DelegationInfo.VisitDays.ToString());
  11073. dic.Add("CultivateDay", dac4.Count.ToString()); //培训天数
  11074. // dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  11075. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  11076. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  11077. //培训人员名单
  11078. int cultivateRowIndex = 7;
  11079. foreach (var item in DeleClientList)
  11080. {
  11081. builder.MoveToCell(0, cultivateRowIndex, 0, 0);
  11082. builder.Write(item.Name);
  11083. builder.MoveToCell(0, cultivateRowIndex, 1, 0);
  11084. builder.Write(item.Sex == 0 ? "男" : item.Sex == 1 ? "女" : "");
  11085. builder.MoveToCell(0, cultivateRowIndex, 2, 0);
  11086. string birthDay = "";
  11087. if (item.Birthday != null)
  11088. {
  11089. DateTime dt = Convert.ToDateTime(item.Birthday);
  11090. birthDay = $"{dt.Year}.{dt.Month}";
  11091. }
  11092. builder.Write(birthDay);
  11093. builder.MoveToCell(0, cultivateRowIndex, 3, 0);
  11094. builder.Write(item.Company);
  11095. builder.MoveToCell(0, cultivateRowIndex, 4, 0);
  11096. builder.Write(item.Job);
  11097. cultivateRowIndex++;
  11098. }
  11099. //删除多余行
  11100. //cultivateRowIndex -= 2;
  11101. int delRows = 10 + 7 - cultivateRowIndex;
  11102. if (delRows > 0)
  11103. {
  11104. for (int i = 0; i < delRows; i++)
  11105. {
  11106. table1.Rows.RemoveAt(cultivateRowIndex);
  11107. //cultivateRowIndex++;
  11108. }
  11109. }
  11110. decimal hotelFeeTotal = dac1.Sum(it => it.SubTotal);//住宿费
  11111. dic.Add("HotelFeeTotal", hotelFeeTotal.ToString("#0.00"));
  11112. decimal mealsFeeTotal = dac2.Sum(it => it.SubTotal);//伙食费
  11113. dic.Add("MealsFeeTotal", mealsFeeTotal.ToString("#0.00"));
  11114. decimal miscellaneousFeeTotal = dac3.Sum(it => it.SubTotal);//公杂费
  11115. dic.Add("MiscellaneousFeeTotal", miscellaneousFeeTotal.ToString("#0.00"));
  11116. decimal trainingFeeTotal = dac4.Sum(it => it.SubTotal);//培训费
  11117. dic.Add("TrainingFeeTotal", trainingFeeTotal.ToString("#0.00"));
  11118. //decimal cityTranfficFeeToatal = _EnterExitCosts.CityTranffic; //城市区间交通费
  11119. decimal cityTranfficFeeToatal = 0.00M;
  11120. //dic.Add("CityTranfficFeeToatal", cityTranfficFeeToatal.ToString("#0.00"));
  11121. //其他费用
  11122. decimal otherFeeTotal = _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Service + dac5.Sum(x => x.SubTotal);
  11123. dic.Add("OtherFeeTotal", otherFeeTotal.ToString("#0.00"));
  11124. //其他费用合计
  11125. decimal _otherFeeTotal = hotelFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + trainingFeeTotal + cityTranfficFeeToatal + otherFeeTotal;
  11126. decimal _jjcFeeToatal = _EnterExitCosts.OutsideJJPay + _otherFeeTotal; //经济舱
  11127. decimal _gwcFeeToatal = _EnterExitCosts.OutsideGWPay + _otherFeeTotal; //公务舱
  11128. //公务舱合计
  11129. //国际旅费
  11130. //string outsideJJ = "";
  11131. //string allPriceJJ = "";
  11132. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 0)
  11133. {
  11134. dic.Add("AirFeeTotal", _EnterExitCosts.OutsideJJPay.ToString("#0.00"));
  11135. dic.Add("FeeTotal", _jjcFeeToatal.ToString("#0.00"));
  11136. }
  11137. if (_EnterExitCosts.SumGWC == 1 && _EnterExitCosts.SumJJC == 0)
  11138. {
  11139. dic.Add("AirFeeTotal", _EnterExitCosts.OutsideGWPay.ToString("#0.00"));
  11140. dic.Add("FeeTotal", _gwcFeeToatal.ToString("#0.00"));
  11141. }
  11142. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 1)
  11143. {
  11144. string airFeeTotalStr = string.Format(@$"经济舱:{_EnterExitCosts.OutsideJJPay:#0.00} 公务舱:{_EnterExitCosts.OutsideGWPay:#0.00}");
  11145. dic.Add("AirFeeTotal", airFeeTotalStr);
  11146. string feeTotalStr = string.Format(@$"经济舱:{_jjcFeeToatal:#0.00} 公务舱:{_gwcFeeToatal:#0.00}");
  11147. dic.Add("FeeTotal", feeTotalStr);
  11148. }
  11149. foreach (var key in dic.Keys)
  11150. {
  11151. builder.MoveToBookmark(key);
  11152. builder.Write(dic[key]);
  11153. }
  11154. //模板文件名
  11155. string strFileName = $"{_DelegationInfo.TeamName}-成都市因公临时出国任务和预算审批意见表(外专培训团专用).docx";
  11156. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  11157. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  11158. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  11159. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  11160. }
  11161. }
  11162. else if (dto.ExportType == 2) //表格
  11163. {
  11164. //利用键值对存放数据
  11165. Dictionary<string, string> dic = new Dictionary<string, string>();
  11166. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  11167. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  11168. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  11169. dic.Add("Day", sp.Days.ToString());
  11170. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  11171. if (dto.SubTypeId == 1008) //1008(派员单位出(境)任务和预算审批意见表)
  11172. {
  11173. //获取模板
  11174. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/派员单位出(境)任务和预算审批意见表.docx");
  11175. //载入模板
  11176. var doc = new Document(tempPath);
  11177. var builder = new DocumentBuilder(doc);
  11178. dic.Add("TeamName", _DelegationInfo.TeamName);
  11179. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  11180. //dic.Add("TellPhone", _DelegationInfo.TellPhone);
  11181. string missionLeaderName = "",
  11182. missionLeaderJob = "";
  11183. if (DeleClientList.Count > 0)
  11184. {
  11185. missionLeaderName = DeleClientList[0].Name;
  11186. missionLeaderJob = DeleClientList[0].Job;
  11187. }
  11188. dic.Add("MissionLeaderName", missionLeaderName);
  11189. dic.Add("MissionLeaderJob", missionLeaderJob);
  11190. dic.Add("VisitPNumber", _DelegationInfo.VisitPNumber.ToString());
  11191. dic.Add("VisitPurpose", _DelegationInfo.VisitPurpose);
  11192. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  11193. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  11194. int rowCount = 10;//总人数行
  11195. int startRowIndex = 7; //起始行
  11196. for (int i = 0; i < DeleClientList.Count; i++)
  11197. {
  11198. builder.MoveToCell(0, startRowIndex, 0, 0);
  11199. builder.Write(DeleClientList[i].Name); //出国人员姓名
  11200. builder.MoveToCell(0, startRowIndex, 1, 0);
  11201. string sex = DeleClientList[i].Sex == 0 ? "男" : DeleClientList[i].Sex == 1 ? "女" : "";
  11202. builder.Write(sex);//性别
  11203. builder.MoveToCell(0, startRowIndex, 2, 0);
  11204. builder.Write(Convert.ToDateTime(DeleClientList[i].Birthday).ToString("yyyy年MM月dd日"));//出生年月
  11205. builder.MoveToCell(0, startRowIndex, 3, 0);
  11206. builder.Write(DeleClientList[i].Company);//工作单位
  11207. builder.MoveToCell(0, startRowIndex, 4, 0);
  11208. builder.Write(DeleClientList[i].Job);//职务及级别
  11209. builder.MoveToCell(0, startRowIndex, 5, 0);
  11210. builder.Write("");//人员属性
  11211. builder.MoveToCell(0, startRowIndex, 6, 0);
  11212. builder.Write("");//上次出国时间
  11213. startRowIndex++;
  11214. }
  11215. int nullRow = rowCount - DeleClientList.Count;//空行
  11216. for (int i = 0; i < nullRow; i++)
  11217. {
  11218. table1.Rows.Remove(table1.Rows[startRowIndex]);
  11219. }
  11220. foreach (var key in dic.Keys)
  11221. {
  11222. builder.MoveToBookmark(key);
  11223. builder.Write(dic[key]);
  11224. }
  11225. //模板文件名
  11226. string strFileName = $"派员单位出(境)任务和预算审批意见表.docx";
  11227. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  11228. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  11229. if (dto.PortType == 1) return Ok(JsonView(true, "成功", new { Url = url }));
  11230. else if (dto.PortType == 2 || dto.PortType == 3) return Ok(JsonView(true, "成功", url));
  11231. }
  11232. else if (dto.SubTypeId == 1009)//1009(省级单位出(境)经费报销单)
  11233. {
  11234. //获取模板
  11235. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/省级单位出(境)经费报销单.docx");
  11236. //载入模板
  11237. var doc = new Document(tempPath);
  11238. var builder = new DocumentBuilder(doc);
  11239. dic.Add("GroupClient", _DelegationInfo.ClientUnit);
  11240. var Names = string.Join("、", DeleClientList.Select(x => x.Name)).TrimEnd('、');
  11241. dic.Add("Names", Names);
  11242. int accommodationRows = 12;
  11243. //int foodandotherRows = 12;
  11244. var Dac1currCn = dac1.GroupBy(x => x.Currency).Select(x => x.Key).ToList();
  11245. var Dac2currCn = dac2.GroupBy(x => x.Currency).Select(x => x.Key).ToList();
  11246. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  11247. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  11248. int accommodationStartIndex = 6;
  11249. decimal dac1totalPrice = 0.00M;
  11250. foreach (var dac in dac1)
  11251. {
  11252. if (dac.SubTotal == 0)
  11253. {
  11254. continue;
  11255. }
  11256. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  11257. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  11258. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  11259. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));//城市
  11260. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  11261. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknwon";
  11262. builder.Write(currency);//币种
  11263. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  11264. builder.Write(dac.Cost.ToString("#0.00"));//标准
  11265. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  11266. builder.Write("");//人数
  11267. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  11268. builder.Write("");//天数
  11269. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  11270. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  11271. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  11272. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  11273. builder.Write(rate.ToString("#0.0000"));//汇率
  11274. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  11275. decimal rbmPrice = rate * dac.SubTotal;
  11276. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  11277. accommodationStartIndex++;
  11278. dac1totalPrice += rbmPrice;
  11279. }
  11280. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  11281. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  11282. builder.Write("小计");
  11283. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  11284. builder.Write(dac1totalPrice.ToString("#0.00"));
  11285. accommodationStartIndex++;
  11286. int nullRow = accommodationRows - dac1.Count;
  11287. //删除空行
  11288. //if (nullRow > 0)
  11289. //{
  11290. // int rowIndex = accommodationStartIndex;
  11291. // for (int i = 0; i < nullRow; i++)
  11292. // {
  11293. // Aspose.Words.Tables.Row row = table1.Rows[rowIndex];
  11294. // row.Remove();
  11295. // rowIndex++;
  11296. // }
  11297. //}
  11298. if (dac2.Count == dac3.Count)//国家 币种 金额
  11299. {
  11300. for (int i = 0; i < dac2.Count; i++)
  11301. {
  11302. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  11303. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  11304. }
  11305. }
  11306. int foodandotherStartIndex = 19;//
  11307. decimal dac2totalPrice = 0.00M;
  11308. foreach (var dac in dac2)
  11309. {
  11310. if (dac.SubTotal == 0)
  11311. {
  11312. continue;
  11313. }
  11314. //foodandotherStartIndex = 12;
  11315. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  11316. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));//城市
  11317. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  11318. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknwon";
  11319. builder.Write(currency);//币种
  11320. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  11321. builder.Write(dac.Cost.ToString("#0.00"));//标准
  11322. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  11323. builder.Write("");//人数
  11324. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  11325. builder.Write("");//天数
  11326. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  11327. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  11328. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  11329. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  11330. builder.Write(rate.ToString("#0.0000"));//汇率
  11331. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  11332. decimal rbmPrice = rate * dac.SubTotal;
  11333. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  11334. foodandotherStartIndex++;
  11335. dac2totalPrice += rbmPrice;
  11336. }
  11337. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  11338. Aspose.Words.Tables.Table table2 = allTables[1] as Aspose.Words.Tables.Table;
  11339. //删除空行
  11340. //if (dac2.Count < foodandotherRows)
  11341. //{
  11342. // while (table2.Rows.Count > dac2.Count)
  11343. // {
  11344. // table2.Rows.RemoveAt(dac2.Count);
  11345. // }
  11346. //}
  11347. var citytrafficLable = new StringBuilder()
  11348. .AppendFormat($"经济舱费用:{_EnterExitCosts.CityTranffic:#0.00} 元、")
  11349. .AppendFormat($"公务舱费用:{_EnterExitCosts.CityTranffic1:#0.00}元、")
  11350. .AppendFormat($"头等舱费用:{_EnterExitCosts.CityTranffic2:#0.00}")
  11351. .ToString();
  11352. dic.Add("CityTranffic", citytrafficLable);
  11353. string otherFeeStr = "";
  11354. if (_EnterExitCosts.Visa > 0) otherFeeStr += $"签证费:{_EnterExitCosts.Visa:#0.00}元,";
  11355. if (_EnterExitCosts.YiMiao > 0) otherFeeStr += $"疫苗费:{_EnterExitCosts.YiMiao:#0.00}元,";
  11356. if (_EnterExitCosts.HeSuan > 0) otherFeeStr += $"核酸费:{_EnterExitCosts.HeSuan:#0.00}元,";
  11357. if (_EnterExitCosts.Safe > 0) otherFeeStr += $"保险费:{_EnterExitCosts.Safe:#0.00}元,";
  11358. if (_EnterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费:{_EnterExitCosts.Ticket:#0.00}元,";
  11359. if (_EnterExitCosts.Service > 0) otherFeeStr += $"服务费:{_EnterExitCosts.Service:#0.00}元,";
  11360. #region 其他款项费用 增加位置:模板第6项其他费用字符串追加
  11361. foreach (var otherInfo in dac5)
  11362. {
  11363. otherFeeStr += $"{otherInfo.itemName}:{otherInfo.SubTotal:#0.00} 元,";
  11364. }
  11365. #endregion
  11366. if (otherFeeStr.Length > 0)
  11367. {
  11368. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  11369. otherFeeStr = $"({otherFeeStr})";
  11370. dic.Add("OtherFeeStr", otherFeeStr);
  11371. }
  11372. foreach (var key in dic.Keys)
  11373. {
  11374. builder.MoveToBookmark(key);
  11375. builder.Write(dic[key]);
  11376. }
  11377. //模板文件名
  11378. string strFileName = $"省级单位出(境)经费报销单{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
  11379. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  11380. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  11381. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  11382. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  11383. }
  11384. }
  11385. else if (dto.ExportType == 3)
  11386. {
  11387. if (dto.SubTypeId == 1) //团组成员名单
  11388. {
  11389. if (!DeleClientList.Any()) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组成员暂未录入!!!", ""));
  11390. //获取模板
  11391. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/dwon_团组人员列表模板.doc");
  11392. //载入模板
  11393. var doc = new Document(tempPath);
  11394. var builder = new DocumentBuilder(doc);
  11395. //获取word里所有表格
  11396. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  11397. //获取所填表格的序数
  11398. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  11399. var rowStart = tableOne.Rows[0]; //获取第1行
  11400. //循环赋值
  11401. for (int i = 0; i < DeleClientList.Count; i++)
  11402. {
  11403. builder.MoveToCell(0, i + 1, 0, 0);
  11404. builder.Write(DeleClientList[i].Name);
  11405. builder.MoveToCell(0, i + 1, 1, 0);
  11406. string sex = DeleClientList[i].Sex == 0 ? "男" : DeleClientList[i].Sex == 1 ? "女" : "";
  11407. builder.Write(sex);
  11408. builder.MoveToCell(0, i + 1, 2, 0);
  11409. builder.Write(Convert.ToDateTime(DeleClientList[i].Birthday).ToString("yyyy年MM月dd日"));
  11410. builder.MoveToCell(0, i + 1, 3, 0);
  11411. builder.Write(DeleClientList[i].Company);
  11412. builder.MoveToCell(0, i + 1, 4, 0);
  11413. builder.Write(DeleClientList[i].Job);
  11414. }
  11415. //删除多余行
  11416. while (tableOne.Rows.Count > DeleClientList.Count + 1)
  11417. {
  11418. tableOne.Rows.RemoveAt(DeleClientList.Count + 1);
  11419. }
  11420. string strFileName = $"{_DelegationInfo.TeamName}组团人员名单({DateTime.Now.ToString("yyyyMMddHHmmss")}).doc";
  11421. //C:/Server/File/OA2023/Office/Word/EnterExitCost/File/
  11422. //C:\Server\File\OA2023\Office\Word\EnterExitCost\File\
  11423. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  11424. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  11425. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  11426. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  11427. }
  11428. }
  11429. return Ok(JsonView(400, "操作失败!", ""));
  11430. }
  11431. catch (Exception ex)
  11432. {
  11433. return Ok(JsonView(400, ex.Message, ""));
  11434. }
  11435. }
  11436. /// <summary>
  11437. /// 获取三公费用标准city
  11438. /// </summary>
  11439. /// <param name="placeData"></param>
  11440. /// <param name="nationalTravelFeeId"></param>
  11441. /// <returns></returns>
  11442. private static string GetEnterExitCostExportCity(List<Grp_NationalTravelFee> placeData, int nationalTravelFeeId)
  11443. {
  11444. string _city = string.Empty;
  11445. if (placeData.Count < 1) return _city;
  11446. var data = placeData.Find(it => it.Id == nationalTravelFeeId);
  11447. if (data == null) return _city;
  11448. string country = data.Country;
  11449. string city = data.City;
  11450. if (city.Contains("其他城市") || city.Contains("所有城市")) _city = $"{country}-{city}";
  11451. else _city = city;
  11452. return _city;
  11453. }
  11454. ///// <summary>
  11455. ///// 团组模块 - 出入境费用 - 明细表导出
  11456. ///// </summary>
  11457. ///// <returns></returns>
  11458. //[HttpPost]
  11459. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11460. //public async Task<IActionResult> PostEnterExitCostExportDetailsList(EnterExitCostOperateDto dto)
  11461. //{
  11462. // var data = await _enterExitCostRep.PostEnterExitCostOperate(dto);
  11463. // if (data.Code != 0)
  11464. // {
  11465. // return Ok(JsonView(false, data.Msg));
  11466. // }
  11467. // return Ok(JsonView(true, data.Msg, data.Data));
  11468. //}
  11469. /// <summary>
  11470. /// 团组模块 - 出入境费用 - 一键清空
  11471. /// </summary>
  11472. /// <returns></returns>
  11473. [HttpPost]
  11474. //[ApiLog("Grp_EnterExitCost", OperationEnum.Del)]
  11475. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11476. public async Task<IActionResult> PostEnterExitCostOneClickClear(EnterExitCostOneClickClearDto dto)
  11477. {
  11478. if (dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId参数;"));
  11479. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数;"));
  11480. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数;"));
  11481. var _view = await _enterExitCostRep.OneClickClear(dto.Id, dto.DiId, dto.UserId);
  11482. await _sqlSugar.Updateable<Grp_DayOtherPrice>()
  11483. .Where(x => x.Diid == dto.DiId && x.IsDel == 0)
  11484. .SetColumns(x => new Grp_DayOtherPrice
  11485. {
  11486. IsDel = 1,
  11487. DeleteUserId = dto.UserId,
  11488. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  11489. })
  11490. .ExecuteCommandAsync();
  11491. if (_view.Code == 0)
  11492. {
  11493. return Ok(JsonView(true, "操作成功"));
  11494. }
  11495. return Ok(JsonView(false, "操作失败"));
  11496. }
  11497. /// <summary>
  11498. /// 团组模块 - 出入境费用 - 子项删除
  11499. /// </summary>
  11500. /// <returns></returns>
  11501. [HttpPost]
  11502. //[ApiLog("Grp_EnterExitCost", OperationEnum.Del)]
  11503. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11504. public async Task<IActionResult> PostEnterExitCostSubItemDel(EnterExitCostSubItemDelDto dto)
  11505. {
  11506. var data = await _enterExitCostRep.PostEnterExitCostSubItemDel(dto);
  11507. if (data.Code != 0)
  11508. {
  11509. return Ok(JsonView(false, data.Msg));
  11510. }
  11511. return Ok(JsonView(true, "操作成功!", data.Data));
  11512. }
  11513. /// <summary>
  11514. /// 删除三公其他费用
  11515. /// </summary>
  11516. /// <param name="dto"></param>
  11517. /// <returns></returns>
  11518. [HttpPost]
  11519. //[ApiLog("Grp_EnterExitCost", OperationEnum.Del)]
  11520. public IActionResult DeleteOtherExpenses(EnterExitCostSubItemDelDto dto)
  11521. {
  11522. var jw = JsonView(false, "删除失败!");
  11523. var data = new Grp_DayOtherPrice()
  11524. {
  11525. Id = dto.Id,
  11526. IsDel = 1,
  11527. DeleteUserId = dto.DeleteUserId,
  11528. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  11529. };
  11530. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  11531. if (del > 0)
  11532. {
  11533. jw.Code = 200;
  11534. jw.Msg = "删除成功!";
  11535. }
  11536. return Ok(jw);
  11537. }
  11538. /// <summary>
  11539. /// 团组模块 - 出入境国家费用标准 List
  11540. /// </summary>
  11541. /// <returns></returns>
  11542. [HttpPost]
  11543. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11544. public async Task<IActionResult> GetNationalTravelFeeData(NationalTravelFeeDataDto dto)
  11545. {
  11546. int provinceId = dto.ProvinceId;
  11547. if (provinceId < 1) provinceId = 122; //默认四川省数据
  11548. var nftData = await _sqlSugar
  11549. .Queryable<Grp_NationalTravelFee, Sys_SetData, Sys_Users, Sys_Cities>((ntf, sd1, u, c) => new JoinQueryInfos(
  11550. JoinType.Left, ntf.Currency == sd1.Id,
  11551. JoinType.Left, ntf.LastUpdateUserId == u.Id,
  11552. JoinType.Left, ntf.ProvinceId == c.Id
  11553. ))
  11554. .Where((ntf, sd1, u, c) => ntf.IsDel == 0 && ntf.ProvinceId == provinceId)
  11555. .Select((ntf, sd1, u, c) => new NationalTravelFeeInfoView
  11556. {
  11557. Id = ntf.Id,
  11558. ProvinceId = ntf.ProvinceId,
  11559. ProvinceName = c.Name_CN,
  11560. Continent = ntf.Continent,
  11561. Country = ntf.Country,
  11562. City = ntf.City,
  11563. Currency = ntf.Currency,
  11564. CurrencyCode = sd1.Name,
  11565. CurrencyName = sd1.Remark,
  11566. RoomCost = ntf.RoomCost,
  11567. FoodCost = ntf.FoodCost,
  11568. PublicCost = ntf.PublicCost,
  11569. LastUpdateUserId = ntf.LastUpdateUserId,
  11570. LastUpdateUserName = u.CnName,
  11571. LastUpdateTime = ntf.LastUpdateTime
  11572. })
  11573. .ToListAsync();
  11574. return Ok(JsonView(true, "查询成功!", nftData));
  11575. }
  11576. /// <summary>
  11577. /// 团组模块 - 出入境国家费用标准 Page List Data Source
  11578. /// </summary>
  11579. /// <returns></returns>
  11580. [HttpPost]
  11581. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11582. public async Task<IActionResult> GetNationalTravelFeePageDataSource()
  11583. {
  11584. string sql = string.Format(@"Select * From Grp_NationalTravelFee Where Isdel = 0 ");
  11585. var nationalTravelFeeData = await _groupRepository._sqlSugar.SqlQueryable<Grp_NationalTravelFee>(sql).ToListAsync();
  11586. List<string> countryData = new List<string>();
  11587. countryData.AddRange(nationalTravelFeeData.Select(it => it.Country!).ToList());
  11588. countryData = countryData.Distinct().ToList();
  11589. List<dynamic> dataSource = new List<dynamic>();
  11590. foreach (var item in countryData)
  11591. {
  11592. var cityData1 = new List<string>();
  11593. cityData1 = nationalTravelFeeData.Where(it => it.Country == item).Select(it => it.City ?? "").ToList();
  11594. var countryData2 = new
  11595. {
  11596. CountryName = item,
  11597. CityData = cityData1
  11598. };
  11599. if (!dataSource.Contains(countryData2))
  11600. {
  11601. dataSource.Add(countryData2);
  11602. }
  11603. }
  11604. return Ok(JsonView(true, "查询成功!", dataSource));
  11605. }
  11606. /// <summary>
  11607. /// 团组模块 - 出入境国家费用标准 Page List
  11608. /// </summary>
  11609. /// <returns></returns>
  11610. [HttpPost]
  11611. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11612. public async Task<IActionResult> PostNationalTravelFeePage(NationalTravelFeePageDto dto)
  11613. {
  11614. int portId = dto.PortType,
  11615. pageIndex = dto.PageIndex,
  11616. pageSize = dto.PageSize;
  11617. if (portId != 1 && portId != 2 && portId != 3) return Ok(JsonView(false, "请输入正确的端口号!\r\n请求端口分类1 Web 2 Android 3 IOS"));
  11618. if (pageIndex == 0) pageIndex = 1;
  11619. if (pageSize == 0) pageSize = 10;
  11620. RefAsync<int> total = 0;
  11621. var nationalTravelFeeData = await _sqlSugar
  11622. .Queryable<Grp_NationalTravelFee, Sys_SetData, Sys_Users, Sys_Cities>((ntf, sd1, u, sd2) => new JoinQueryInfos(
  11623. JoinType.Left, ntf.Currency == sd1.Id,
  11624. JoinType.Left, ntf.LastUpdateUserId == u.Id,
  11625. JoinType.Left, ntf.ProvinceId == sd2.Id
  11626. ))
  11627. .Where((ntf, sd1, u, sd2) => ntf.IsDel == 0)
  11628. .WhereIF(dto.ProvinceId > 0, (ntf, sd1, u, sd2) => ntf.ProvinceId == dto.ProvinceId)
  11629. .WhereIF(!string.IsNullOrEmpty(dto.Country), (ntf, sd1, u, sd2) => ntf.Country.Contains(dto.Country))
  11630. .WhereIF(!string.IsNullOrEmpty(dto.City), (ntf, sd1, u, sd2) => ntf.City.Contains(dto.City))
  11631. .OrderByDescending((ntf, sd1, u, sd2) => ntf.LastUpdateTime)
  11632. .Select((ntf, sd1, u, sd2) => new NationalTravelFeePageInfoView
  11633. {
  11634. RowNumber = SqlFunc.RowNumber($"{ntf.LastUpdateTime} Desc"),
  11635. Id = ntf.Id,
  11636. ProvinceId = ntf.ProvinceId,
  11637. ProvinceName = sd2.Name_CN,
  11638. Continent = ntf.Continent,
  11639. Country = ntf.Country,
  11640. City = ntf.City,
  11641. Currency = ntf.Currency,
  11642. CurrencyCode = sd1.Name,
  11643. CurrencyName = sd1.Remark,
  11644. RoomCost = ntf.RoomCost,
  11645. FoodCost = ntf.FoodCost,
  11646. PublicCost = ntf.PublicCost,
  11647. LastUpdateUserId = ntf.LastUpdateUserId,
  11648. LastUpdateUserName = u.CnName,
  11649. LastUpdateTime = ntf.LastUpdateTime,
  11650. Remark = ntf.Remark
  11651. })
  11652. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  11653. return Ok(JsonView(true, "查询成功!", nationalTravelFeeData, (int)total));
  11654. }
  11655. /// <summary>
  11656. /// 团组模块 - 出入境国家费用标准 根据城市查询
  11657. /// </summary>
  11658. /// <returns></returns>
  11659. [HttpPost]
  11660. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11661. public async Task<IActionResult> PostNationalTravelFeeInfoByCountryAndCity(NationalTravelFeeByCountryAndCityDto dto)
  11662. {
  11663. if (dto == null) return Ok(JsonView(false, "请传入参数!"));
  11664. int portId = dto.PortType;
  11665. if (portId != 1 && portId != 2 && portId != 3) return Ok(JsonView(false, "请输入正确的端口号!\r\n请求端口分类1 Web 2 Android 3 IOS"));
  11666. string whereSql = string.Empty;
  11667. if (!string.IsNullOrEmpty(dto.Country))
  11668. {
  11669. whereSql = string.Format(@"And Country = '{0}' ", dto.Country);
  11670. }
  11671. if (!string.IsNullOrEmpty(dto.City))
  11672. {
  11673. whereSql = string.Format(@"And City = '{0}' ", dto.City);
  11674. }
  11675. string sql = string.Format(@"Select gntf.Country,gntf.City,gntf.Currency,ssd.Name as CurrencyCode,
  11676. ssd.Remark as CurrencyName,gntf.RoomCost,gntf.FoodCost,gntf.PublicCost,gntf.TrainCost,
  11677. gntf.LastUpdateUserId,su.CnName as LastUpdateUserName,gntf.LastUpdateTime
  11678. From Grp_NationalTravelFee gntf
  11679. Left Join Sys_SetData ssd On ssd.STid = 66 And gntf.Currency = ssd.Id
  11680. Left Join Sys_Users su On gntf.LastUpdateUserId = su.Id
  11681. Where gntf.Isdel = 0 {0} ", whereSql);
  11682. var nationalTravelFeeData = await _groupRepository._sqlSugar.SqlQueryable<NationalTravelFeeInfoByCountryAndCityView>(sql).FirstAsync();
  11683. return Ok(JsonView(true, "查询成功!", nationalTravelFeeData));
  11684. }
  11685. /// <summary>
  11686. /// 团组模块 - 出入境国家费用标准 - Add Or Update
  11687. /// </summary>
  11688. /// <returns></returns>
  11689. [HttpPost]
  11690. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11691. public async Task<IActionResult> PostNationalTravelFeeOperate(NationalTravelFeeOperateDto dto)
  11692. {
  11693. return Ok(await _enterExitCostRep.PostNationalTravelFeeOperate(dto));
  11694. }
  11695. /// <summary>
  11696. /// 团组模块 - 出入境国家费用标准 - Del
  11697. /// </summary>
  11698. /// <returns></returns>
  11699. [HttpPost]
  11700. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11701. public async Task<IActionResult> PostNationalTravelFeeDel(NationalTravelFeeDelDto dto)
  11702. {
  11703. Grp_NationalTravelFee _nationalTravelFee = new Grp_NationalTravelFee()
  11704. {
  11705. Id = dto.Id,
  11706. DeleteUserId = dto.DeleteUserId,
  11707. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  11708. IsDel = 1
  11709. };
  11710. var delStatus = await _enterExitCostRep._sqlSugar.Updateable<Grp_NationalTravelFee>(_nationalTravelFee)
  11711. .UpdateColumns(it => new { it.DeleteTime, it.DeleteUserId, it.IsDel })
  11712. .WhereColumns(it => new { it.Id })
  11713. .ExecuteCommandAsync();
  11714. if (delStatus <= 0)
  11715. {
  11716. return Ok(JsonView(false, "删除失败!"));
  11717. }
  11718. return Ok(JsonView(true, "操作成功!"));
  11719. }
  11720. /// <summary>
  11721. /// 团组模块 - 出入境国家费用标准 - 费用导入收款账单
  11722. /// 注:Get 请求Headers 加 Token
  11723. /// </summary>
  11724. /// <param name="groupId"></param>
  11725. /// <returns></returns>
  11726. [HttpGet("{groupId}")]
  11727. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11728. public async Task<IActionResult> NationalTravelFeeImportReceivables(int groupId)
  11729. {
  11730. var _currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  11731. if (_currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  11732. var data = await GeneralMethod.ReceivablesImportFeeAsync(groupId);
  11733. data.ForEach(x =>
  11734. {
  11735. x.CreateUserId = _currUserInfo.UserId;
  11736. });
  11737. if (data.Any())
  11738. {
  11739. var add = await _sqlSugar.Insertable(data).ExecuteCommandAsync();
  11740. if (add > 0)
  11741. {
  11742. return Ok(JsonView(true, "操作成功!"));
  11743. }
  11744. }
  11745. return Ok(JsonView(false, "未操作!"));
  11746. }
  11747. #endregion
  11748. #region 团组经理模块 出入境费用-草稿
  11749. /// <summary>
  11750. /// 团组模块-出入境费用-草稿
  11751. /// 基础数据源-省份归属
  11752. /// </summary>
  11753. /// <returns></returns>
  11754. [HttpGet]
  11755. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11756. public async Task<IActionResult> EnterExitDraftProvBelongCostDataSource()
  11757. {
  11758. var provData = await _groupRepository.ProvinceBasicSource();
  11759. return Ok(JsonView(true, "查询成功!", provData));
  11760. }
  11761. /// <summary>
  11762. /// 团组模块-出入境费用-草稿
  11763. /// 文件类型list 根据省份Id获取
  11764. /// </summary>
  11765. /// <returns></returns>
  11766. [HttpGet("{provinceId}")]
  11767. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11768. public async Task<IActionResult> EnterExitCostDraftFileOwner([FromRoute] int provinceId = 122)
  11769. {
  11770. //验证城市归属并给默认值
  11771. if (provinceId < 1) provinceId = 122;
  11772. /*
  11773. * 122 四川
  11774. * 108 贵州
  11775. * 103 重庆
  11776. * 132 云南
  11777. */
  11778. (SetDataInfoView[] wordTypeData, SetDataInfoView[] excelTypeData) = await _enterExitCostDraftRep.FileOwner(provinceId);
  11779. return Ok(JsonView(true, "查询成功!", new
  11780. {
  11781. WordTypeData = wordTypeData,
  11782. ExcelTypeData = excelTypeData,
  11783. }));
  11784. }
  11785. /// <summary>
  11786. /// 团组模块 - 出入境费用-草稿
  11787. /// 基础数据源(团组名称/币种类型)
  11788. /// </summary>
  11789. /// <returns></returns>
  11790. [HttpPost]
  11791. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11792. public async Task<IActionResult> EnterExitCostDraftDataSource(EnterExitCostDraftDataSourceDto dto)
  11793. {
  11794. var draftNameDatas = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>()
  11795. .Where(x => x.IsDel == 0)
  11796. .OrderByDescending(x => x.CreateTime)
  11797. .Select(x => new { x.Id, x.DraftName })
  11798. .ToListAsync();
  11799. string sql = string.Format("Select * From Sys_SetData Where IsDel = 0");
  11800. //SetDataInfoView
  11801. var dataSource = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToListAsync();
  11802. var currencyData = dataSource.Where(it => it.STid == 66).ToList(); //所有币种
  11803. var _CurrencyData = _mapper.Map<List<SetDataInfoView>>(currencyData);
  11804. int provinceId = dto.ProvinceId;
  11805. if (provinceId < 1) provinceId = 122;
  11806. /*
  11807. * 122 四川
  11808. * 108 贵州
  11809. * 103 重庆
  11810. * 132 云南
  11811. */
  11812. (SetDataInfoView[] wordTypeData, SetDataInfoView[] excelTypeData) = await _enterExitCostRep.FileOwner(provinceId);
  11813. //默认币种显示
  11814. var _currencyInfos = await GeneralMethod.EnterExitCostInitRate();
  11815. var viewPermissionData = await _enterExitCostDraftRep.PermissionViewUsersAsync();
  11816. return Ok(JsonView(true, "查询成功!", new
  11817. {
  11818. DraftNameDatas = draftNameDatas,
  11819. CurrencyData = _CurrencyData,
  11820. WordTypeData = wordTypeData,
  11821. ExcelTypeData = excelTypeData,
  11822. CurrencyInit = _currencyInfos,
  11823. ViewPermissionData = viewPermissionData
  11824. }));
  11825. }
  11826. /// <summary>
  11827. /// 团组模块 - 出入境费用-草稿
  11828. /// 实时汇率 tips、机票费用 tips
  11829. /// </summary>
  11830. /// <returns></returns>
  11831. [HttpPost]
  11832. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11833. public async Task<IActionResult> EnterExitCostDraftCorrelationTips(EnterExitCostDraftCorrelationTipsDto dto)
  11834. {
  11835. //var airData = await _ticketBlackCodeRep.EntryAndExitTips(dto.DiId);
  11836. return Ok(JsonView(true, "查询成功!", new
  11837. {
  11838. //GroupNameData = groupNameData.Data,
  11839. //visaData = visaData.Data,
  11840. //airData = airData.Data,
  11841. reteInfos = await GeneralMethod.EnterExitCostLiveRate()
  11842. }));
  11843. }
  11844. /// <summary>
  11845. /// 团组模块 - 出入境费用-草稿
  11846. /// 签证费用 tips
  11847. /// </summary>
  11848. /// <returns></returns>
  11849. [HttpPost]
  11850. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11851. public async Task<IActionResult> EnterExitCostDraftVisaTips(EnterExitCostDraftVisaTipsDto dto)
  11852. {
  11853. //if (dto.DraftId < 1) return Ok(JsonView(false,MsgTips.Id));
  11854. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  11855. .Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId)
  11856. .Select(x => x.NationalTravelFeeId)
  11857. .Distinct()
  11858. .ToListAsync();
  11859. //if (!cityIds.Any()) return Ok(JsonView(false, "请先录入出入境费用明细!"));
  11860. var countrys = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  11861. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  11862. .Select(x => x.Country)
  11863. .Distinct()
  11864. .ToArrayAsync();
  11865. //if (!countrys.Any()) return Ok(JsonView(false, "请先录入出入境费用明细!"));
  11866. (decimal totalAmt, string remark) = await _visaFeeInfoRep.EnterExitCostDraftVisaTips(countrys);
  11867. return Ok(JsonView(true, "查询成功!", new
  11868. {
  11869. totalAmt,
  11870. remark
  11871. }));
  11872. }
  11873. #region 城市区间交通费
  11874. /// <summary>
  11875. /// 团组模块 - 出入境费用-草稿
  11876. /// 境外用车 基础数据源
  11877. /// </summary>
  11878. /// <param name="draftId">草稿Id</param>
  11879. /// <returns></returns>
  11880. [HttpGet("{draftId}")]
  11881. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11882. public async Task<IActionResult> EnterExitCostDraftOVByGroupId(int draftId)
  11883. {
  11884. var draftInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == draftId).FirstAsync();
  11885. if (draftInfo == null)
  11886. {
  11887. return Ok(JsonView(false, "三公费用草稿信息为空"));
  11888. }
  11889. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  11890. .Where(x => x.IsDel == 0 && x.ParentId == draftId)
  11891. .Select(x => x.NationalTravelFeeId)
  11892. .Distinct()
  11893. .ToListAsync();
  11894. var countries = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  11895. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  11896. .Select(x => x.Country)
  11897. .Distinct()
  11898. .ToListAsync();
  11899. if (countries?.Any() != true)
  11900. {
  11901. return Ok(JsonView(false, "草稿选择城市信息为空"));
  11902. }
  11903. var currencies = await GeneralMethod.EnterExitCostDrafOVFeeUsedCurrencyAsync(draftId);
  11904. var currencyData = await _sqlSugar.Queryable<Sys_SetData>()
  11905. .Where(x => x.IsDel == 0 && x.STid == 66)
  11906. .ToListAsync();
  11907. var overseaVehicles = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  11908. .Where(x => x.IsDel == 0 && countries.Contains(x.CountryName))
  11909. .ToListAsync();
  11910. var overseaVehicleIds = overseaVehicles.Select(x => x.Id).ToList();
  11911. //只返回接送机的数据
  11912. var overseaVehicleTypes = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  11913. .Where(x => x.IsDel == 0 && x.ServiceType == VehicleServiceTypeEnum.TransferService && overseaVehicleIds.Contains(x.OvId))
  11914. .ToListAsync();
  11915. var sysUers = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToListAsync();
  11916. var overseaVehicleCityDatas = new List<dynamic>() {
  11917. new
  11918. {
  11919. Id = 0,
  11920. area= "未选择",
  11921. CarTypeName = "",
  11922. serviceType = "",
  11923. Price = 0.00M,
  11924. guidePrice = 0.00M,
  11925. otherPrice = 0.00M,
  11926. currency = 0,
  11927. currencyName = "",
  11928. currRate = 1.0000M,
  11929. LastUpdateUserName = "",
  11930. LastUpdateTime = "",
  11931. Remark = ""
  11932. }};
  11933. foreach (var item in overseaVehicleTypes)
  11934. {
  11935. var parentInfo = overseaVehicles.FirstOrDefault(x => x.Id == item.OvId);
  11936. string area = string.Empty,
  11937. serviceType = "未设置",
  11938. currencyName = string.Empty;
  11939. decimal otherPrice = 0.00M;
  11940. if (parentInfo != null)
  11941. {
  11942. if (parentInfo.CountryName == parentInfo.CityName) area = parentInfo.CountryName;
  11943. else area = $"{parentInfo.CountryName}-{parentInfo.CityName}";
  11944. serviceType = item.ServiceType.GetDescription();
  11945. currencyName = currencyData.FirstOrDefault(x => x.Id == parentInfo.Currency)?.Name ?? "-";
  11946. otherPrice = parentInfo.OtherPrice1 + parentInfo.OtherPrice2;
  11947. }
  11948. //当前币种汇率值
  11949. var currRate = 1.0000M;
  11950. var currencyInfo = currencies.FirstOrDefault(x => x.CurrencyCode == currencyName);
  11951. if (currencyInfo != null) currRate = currencyInfo.Rate;
  11952. overseaVehicleCityDatas.add(new
  11953. {
  11954. item.Id,
  11955. area,
  11956. item.CarTypeName,
  11957. serviceType,
  11958. item.Price,
  11959. guidePrice = parentInfo?.GuidePrice ?? 0.00M,
  11960. otherPrice,
  11961. currency = parentInfo?.Currency ?? 0,
  11962. currencyName,
  11963. currRate,
  11964. LastUpdateUserName = sysUers.FirstOrDefault(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-",
  11965. item.LastUpdateTime,
  11966. item.Remark
  11967. });
  11968. }
  11969. var total = overseaVehicleCityDatas.Count;
  11970. var view = new
  11971. {
  11972. visitCountries = string.Join("、", countries),
  11973. groupSize = 0, //出访人数
  11974. defAirportTransferCoeff = Def_AirportTransferCoeff, //接送机默认报价系数
  11975. defServiceCount = Def_ServiceCount, //接送机默认服务次数
  11976. defTrainCoeff = Def_TrainCoeff, //火车默认报价系数
  11977. defPullCartCoeff = Def_PullCartCoeff, //拉车默认报价系数
  11978. defCityFlightCoeff = Def_CityFlightCoeff, //城市机票默认报价系数
  11979. Currencies = currencies,
  11980. data = overseaVehicleCityDatas
  11981. };
  11982. if (overseaVehicleCityDatas.Count == 0)
  11983. {
  11984. return Ok(JsonView(true, "暂无数据!", view));
  11985. }
  11986. return Ok(JsonView(true, "查询成功!", view, total));
  11987. }
  11988. /// <summary>
  11989. /// 团组模块 - 出入境费用-草稿
  11990. /// 境外用车 计算详细信息
  11991. /// </summary>
  11992. /// <param name="draftId"></param>
  11993. /// <param name="currUserId"></param>
  11994. /// <returns></returns>
  11995. [HttpGet("{draftId}")]
  11996. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11997. public async Task<IActionResult> EnterExitCostDraftOVFeeDetails(int draftId, int currUserId)
  11998. {
  11999. // 1. 验证草稿是否存在
  12000. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>()
  12001. .Where(x => x.Id == draftId && x.IsDel == 0)
  12002. .FirstAsync();
  12003. if (eecInfo == null)
  12004. {
  12005. return Ok(JsonView(false, "草稿信息为空"));
  12006. }
  12007. // 2. 获取用户信息
  12008. var userInfo = await _sqlSugar.Queryable<Sys_Users>()
  12009. .Where(x => x.IsDel == 0 && x.Id == currUserId)
  12010. .FirstAsync();
  12011. var userName = userInfo?.CnName ?? "-";
  12012. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  12013. // 3. 处理草稿信息
  12014. CityIntervalDraftInfo info;
  12015. if (eecInfo.CityIntervalFeeDetails != null)
  12016. {
  12017. info = eecInfo.CityIntervalFeeDetails;
  12018. // 检查费用详情是否为空
  12019. bool isEmpty = !info.APTFeeDetails.Any() &&
  12020. !info.PullCartFeeDetails.Any() &&
  12021. !info.TrainFeeDetails.Any() &&
  12022. !info.CityAirTicketFeeDetails.Any();
  12023. if (isEmpty)
  12024. {
  12025. info = await CreateDefaultCityIntervalDraftInfo(draftId, userName, nowTime);
  12026. }
  12027. else
  12028. {
  12029. // 更新时间和用户信息
  12030. info.LastUpdateUserName = userName;
  12031. info.LastUpdateTime = nowTime;
  12032. }
  12033. }
  12034. else
  12035. {
  12036. // 创建默认信息
  12037. info = await CreateDefaultCityIntervalDraftInfo(draftId, userName, nowTime);
  12038. }
  12039. return Ok(JsonView(true, "查询成功!", info));
  12040. }
  12041. /// <summary>
  12042. /// 创建默认的城市区间费用草稿信息
  12043. /// </summary>
  12044. private static async Task<CityIntervalDraftInfo> CreateDefaultCityIntervalDraftInfo(
  12045. int draftId,
  12046. string userName,
  12047. string nowTime)
  12048. {
  12049. return new CityIntervalDraftInfo()
  12050. {
  12051. APTFeeDetails = new List<RoundTripTransferInfo>()
  12052. {
  12053. new()
  12054. {
  12055. No = 1,
  12056. Coefficient = Def_AirportTransferCoeff,
  12057. ServiceCount = Def_ServiceCount
  12058. }
  12059. },
  12060. PullCartFeeDetails = new List<PullCartInfo>()
  12061. {
  12062. new()
  12063. {
  12064. No = 1,
  12065. Coefficient = Def_PullCartCoeff
  12066. }
  12067. },
  12068. TrainFeeDetails = new List<TrainInfo>()
  12069. {
  12070. new()
  12071. {
  12072. No = 1,
  12073. Coefficient = Def_TrainCoeff
  12074. }
  12075. },
  12076. CityAirTicketFeeDetails = new List<CityAirTicketInfo>()
  12077. {
  12078. new()
  12079. {
  12080. No = 1,
  12081. Coefficient = Def_CityFlightCoeff
  12082. }
  12083. },
  12084. LastUpdateUserName = userName,
  12085. LastUpdateTime = nowTime,
  12086. CreateUserName = userName,
  12087. CreateTime = nowTime,
  12088. Currencies = await GeneralMethod.EnterExitCostDrafOVFeeUsedCurrencyAsync(draftId)
  12089. };
  12090. }
  12091. /// <summary>
  12092. /// 团组模块 - 出入境费用-草稿
  12093. /// 境外用车 保存
  12094. /// </summary>
  12095. /// <param name="dto"></param>
  12096. /// <returns></returns>
  12097. [HttpPost]
  12098. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12099. public async Task<IActionResult> EnterExitCostDraftOVFeeSave(EnterExitCostDraftOVFeeSaveDto dto)
  12100. {
  12101. var draftInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == dto.DraftId).FirstAsync();
  12102. if (draftInfo == null)
  12103. {
  12104. return Ok(JsonView(false, "草稿信息为空"));
  12105. }
  12106. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == dto.CurrUserId).FirstAsync();
  12107. if (userInfo == null)
  12108. {
  12109. return Ok(JsonView(false, "员工信息为空"));
  12110. }
  12111. var userName = userInfo?.CnName ?? "-";
  12112. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  12113. var info = new CityIntervalDraftInfo()
  12114. {
  12115. GroupSize = dto.GroupSize,
  12116. APTFeeTotal = dto.APTFeeTotal,
  12117. APTFeeDetails = dto.APTFeeDetails,
  12118. PullCartFeeTotal = dto.PullCartFeeTotal,
  12119. PullCartFeeDetails = dto.PullCartFeeDetails,
  12120. TrainFeeTotal = dto.TrainFeeTotal,
  12121. TrainFeeDetails = dto.TrainFeeDetails,
  12122. CityAirTicketFeeTotal = dto.CityAirTicketFeeTotal,
  12123. CityAirTicketFeeDetails = dto.CityAirTicketFeeDetails,
  12124. Currencies = dto.Currencies,
  12125. LastUpdateUserName = userName,
  12126. LastUpdateTime = nowTime,
  12127. CreateUserName = draftInfo.CityIntervalFeeDetails?.CreateUserName ?? userName,
  12128. CreateTime = draftInfo.CityIntervalFeeDetails?.CreateTime ?? nowTime
  12129. };
  12130. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>()
  12131. .SetColumns(it => it.CityIntervalFeeDetails == info)
  12132. .Where(x => x.Id == draftInfo.Id)
  12133. .ExecuteCommandAsync();
  12134. if (upd < 1)
  12135. {
  12136. return Ok(JsonView(false));
  12137. }
  12138. //返回参数处理
  12139. var label = new StringBuilder();
  12140. if (dto.APTFeeDetails.Any())
  12141. {
  12142. var ovIds = dto.APTFeeDetails.Select(x => x.OvId).ToList();
  12143. var areas = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  12144. .LeftJoin<Res_OverseaVehicle>((ovtp, ov) => ovtp.OvId == ov.Id)
  12145. .Where((ovtp, ov) => ovtp.IsDel == 0 && ovIds.Contains(ovtp.Id))
  12146. .Select((ovtp, ov) => new
  12147. {
  12148. ovtp.Id,
  12149. ov.CountryName,
  12150. ov.CityName
  12151. })
  12152. .ToListAsync();
  12153. if (areas.Any())
  12154. {
  12155. var items = dto.APTFeeDetails
  12156. .Select(item =>
  12157. {
  12158. var areaInfo = areas.FirstOrDefault(x => x.Id == item.OvId);
  12159. if (areaInfo == null) return null;
  12160. return areaInfo.CountryName == areaInfo.CityName
  12161. ? $"{areaInfo.CountryName}({item.Quote:#0.00} CNY)"
  12162. : $"{areaInfo.CountryName}-{areaInfo.CityName}({item.Quote:#0.00} CNY)";
  12163. })
  12164. .Where(item => item != null)
  12165. .ToList();
  12166. string areaLabel = $"接送机({string.Join("、", items)});";
  12167. label.AppendLine(areaLabel);
  12168. }
  12169. }
  12170. if (dto.PullCartFeeDetails.Any())
  12171. {
  12172. var amounts = dto.PullCartFeeDetails.Select(item => $"{item.Quote:#0.00}");
  12173. string subLabel = $"拉车({string.Join("、", amounts)});";
  12174. label.AppendLine(subLabel);
  12175. }
  12176. if (dto.TrainFeeDetails.Any())
  12177. {
  12178. var amounts = dto.TrainFeeDetails.Select(item => $"{item.Quote:#0.00}");
  12179. string subLabel = $"火车票({string.Join("、", amounts)});";
  12180. label.AppendLine(subLabel);
  12181. }
  12182. if (dto.CityAirTicketFeeDetails.Any())
  12183. {
  12184. var amounts = dto.CityAirTicketFeeDetails.Select(item => $"{item.Quote:#0.00}");
  12185. string subLabel = $"城市机票({string.Join("、", amounts)});";
  12186. label.AppendLine(subLabel);
  12187. }
  12188. //费用
  12189. decimal quote = (dto.APTFeeTotal + dto.PullCartFeeTotal + dto.TrainFeeTotal + dto.CityAirTicketFeeTotal).ConvertToDecimal1();
  12190. decimal jjcQuote = quote;
  12191. decimal gwcQuote = quote;
  12192. decimal tdcQuote = quote;
  12193. var view = new
  12194. {
  12195. label = label.ToString(),
  12196. jjcQuote,
  12197. gwcQuote,
  12198. tdcQuote
  12199. };
  12200. return Ok(JsonView(view));
  12201. }
  12202. #endregion
  12203. /// <summary>
  12204. /// 团组模块 - 出入境费用-草稿
  12205. /// Info
  12206. /// </summary>
  12207. /// <returns></returns>
  12208. [HttpPost]
  12209. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Details)]
  12210. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12211. public async Task<IActionResult> EnterExitCostDraftInfoById(EnterExitCostDraftInfoByIdDto dto)
  12212. {
  12213. return Ok(await _enterExitCostDraftRep.EnterExitCostDraftInfoById(dto));
  12214. }
  12215. /// <summary>
  12216. /// 团组模块 - 出入境费用-草稿
  12217. /// 设置view权限
  12218. /// </summary>
  12219. /// <returns></returns>
  12220. [HttpPost]
  12221. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12222. public async Task<IActionResult> EnterExitCostDraftSetViewPermissiion(EnterExitCostDraftSetViewPermissiionDto dto)
  12223. {
  12224. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  12225. if (dto.DraftId < 1) return Ok(JsonView(false, "请传入有效的DraftId;"));
  12226. if (dto.UserIds.Length < 1) return Ok(JsonView(false, "请传入有效的userId;"));
  12227. var permissions = new List<Grp_EnterExitCostDraftPermission>();
  12228. foreach (var userId in dto.UserIds)
  12229. {
  12230. permissions.Add(new Grp_EnterExitCostDraftPermission { Permission = 1, DraftId = dto.DraftId, UserId = userId, CreateUserId = dto.CurrUserId });
  12231. }
  12232. if (permissions.Any())
  12233. {
  12234. _sqlSugar.BeginTran();
  12235. try
  12236. {
  12237. await _sqlSugar.Deleteable<Grp_EnterExitCostDraftPermission>().Where(it => it.DraftId == dto.DraftId).ExecuteCommandAsync();
  12238. var result = await _sqlSugar.Insertable(permissions).ExecuteCommandAsync();
  12239. if (result < 1)
  12240. {
  12241. _sqlSugar.RollbackTran();
  12242. return Ok(JsonView(false));
  12243. }
  12244. }
  12245. catch (Exception ex)
  12246. {
  12247. _sqlSugar.RollbackTran();
  12248. return Ok(JsonView(false, ex.Message));
  12249. }
  12250. _sqlSugar.CommitTran();
  12251. return Ok(JsonView(true));
  12252. }
  12253. return Ok(JsonView(false));
  12254. }
  12255. /// <summary>
  12256. /// 团组模块 - 出入境费用-草稿
  12257. /// Add And Update
  12258. /// </summary>
  12259. /// <returns></returns>
  12260. [HttpPost]
  12261. [ApiLog("Grp_EnterExitCostDraft", OperationEnum.Add)]
  12262. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12263. public async Task<IActionResult> EnterExitCostDraftOp(EnterExitCostDraftOpDto dto)
  12264. {
  12265. var data = await _enterExitCostDraftRep.EnterExitCostDraftOp(dto);
  12266. if (data.Code != 0)
  12267. {
  12268. return Ok(JsonView(false, data.Msg));
  12269. }
  12270. int sign = (int)data.Data.GetType().GetProperty("sign").GetValue(data.Data, null);
  12271. //汇率信息记录
  12272. await GeneralMethod.RateRecordSave(dto.UserId, sign, "出入境费用");
  12273. return Ok(JsonView(true, data.Msg, data.Data));
  12274. }
  12275. /// <summary>
  12276. /// 团组模块 - 出入境费用-草稿
  12277. /// File downlaod
  12278. /// </summary>
  12279. /// <param name="dto"></param>
  12280. /// <returns></returns>
  12281. [HttpPost]
  12282. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Download)]
  12283. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12284. public async Task<IActionResult> EnterExitCostDraftDownload(EnterExitCostDraftDownloadDto dto)
  12285. {
  12286. try
  12287. {
  12288. var id = dto.Id;
  12289. if (id < 1) return Ok(JsonView(400, "请传入有效的DiId参数;", ""));
  12290. if (dto.ExportType < 1) return Ok(JsonView(400, "请传入有效的ExportType参数; 1 明细表 2 表格", ""));
  12291. if (dto.SubTypeId < 1) return Ok(JsonView(400, @"请传入有效的SubTypeId参数;
  12292. 1 明细表 --> 1005(默认明细表) 1006(因公出国(境)经费测算明细表) 1007(四川省商务厅出国经费财政先行审核表)
  12293. 2 表格 --> 1008(派员单位出(境)任务和预算审批意见表) 1009(省级单位出(境)经费报销单)
  12294. 3 团组成员名单 1 团组成员名单", ""));
  12295. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(it => it.IsDel == 0 && it.Id == id).OrderByDescending(x => x.CreateTime).First();
  12296. if (_EnterExitCosts == null) return Ok(JsonView(400, "未填写出入境费用-草稿;", ""));
  12297. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCostDraft>().Where(it => it.IsDel == 0 && it.ParentId == id).ToList();
  12298. var countryIds = _DayAndCosts.Select(x => x.NationalTravelFeeId).ToList();
  12299. var nationalTravelFeeData = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0 && countryIds.Contains(it.Id)).ToList();
  12300. var enterExitCostCurrencys = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(_EnterExitCosts.CurrencyRemark);
  12301. //数据源
  12302. var dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  12303. var dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  12304. var dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  12305. var dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  12306. var dac5 = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>()
  12307. .LeftJoin<Sys_SetData>((x, a) => a.IsDel == 0 && a.Id == x.SetDataId)
  12308. .LeftJoin<Sys_SetData>((x, a, b) => b.IsDel == 0 && b.Id == x.Currency)
  12309. .Where((x, a, b) => x.IsDel == 0 && x.ParentId == id)
  12310. .Select((x, a, b) => new
  12311. {
  12312. x.Index,
  12313. itemName = a.Name,
  12314. CurrencyStr = b.Name,
  12315. x.Cost,
  12316. x.SubTotal,
  12317. x.Remark
  12318. })
  12319. .OrderBy((x) => x.Index)
  12320. .ToList(); //其他款项费用
  12321. var _CurrDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  12322. var peiceItemCurrencys = new List<string>();
  12323. if (_DayAndCosts.Any())
  12324. {
  12325. var currencyIds = _DayAndCosts.Select(x => x.Currency).Distinct().ToList();
  12326. if (currencyIds.Any()) peiceItemCurrencys.AddRange(_CurrDatas.Where(x => currencyIds.Contains(x.Id)).Select(x => x.Name).ToList());
  12327. }
  12328. if (dac5.Any()) peiceItemCurrencys.AddRange(dac5.Select(x => x.CurrencyStr).Distinct().ToList());
  12329. var peiceItemCurrencyInfos = new List<CurrencyInfo>();
  12330. if (enterExitCostCurrencys.Any() && peiceItemCurrencys.Any())
  12331. {
  12332. peiceItemCurrencyInfos = enterExitCostCurrencys.Where(x => peiceItemCurrencys.Contains(x.CurrencyCode)).ToList();
  12333. }
  12334. var threeCodes = _sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList();
  12335. var placeData = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  12336. var rateDatas = await _EnterExitCosts.CurrencyRemark.SplitExchangeRate();
  12337. if (dto.ExportType == 1) //明细表
  12338. {
  12339. if (dto.SubTypeId == 1005) //1005(默认明细表)
  12340. {
  12341. //获取模板
  12342. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/出入境费用表模板.docx");
  12343. //载入模板
  12344. Document doc = new Document(tempPath);
  12345. DocumentBuilder builder = new DocumentBuilder(doc);
  12346. //利用键值对存放数据
  12347. Dictionary<string, string> dic = new Dictionary<string, string>();
  12348. decimal stayFeeTotal = _EnterExitCosts.ChoiceThree == 1 ? _DayAndCosts.Where(it => it.Type == 1).Sum(it => it.SubTotal) : 0.00M; // 住宿费
  12349. decimal mealsFeeTotal = _EnterExitCosts.ChoiceFour == 1 ? _DayAndCosts.Where(it => it.Type == 2).Sum(it => it.SubTotal) : 0.00M; // 伙食费费
  12350. decimal miscellaneousFeeTotal = _EnterExitCosts.ChoiceFive == 1 ? _DayAndCosts.Where(it => it.Type == 3).Sum(it => it.SubTotal) : 0.00M; // 公杂费
  12351. decimal tainFeeTotal = _EnterExitCosts.ChoiceSix == 1 ? _DayAndCosts.Where(it => it.Type == 4).Sum(it => it.SubTotal) : 0.00M; // 培训费
  12352. decimal otherPriceTotal = _EnterExitCosts.OtherExpenses_Checked == 1 ? dac5.Sum(x => x.SubTotal) : 0.00M; //其他费用
  12353. decimal insidePayTotal = _EnterExitCosts.ChoiceOne == 1 ? _EnterExitCosts.InsidePay : 0.00M;
  12354. //境内费用(其他费用)
  12355. if (_EnterExitCosts.ChoiceOne == 1)
  12356. {
  12357. string row1_1 = "";
  12358. if (_EnterExitCosts.Visa > 0)
  12359. {
  12360. //insidePayTotal += _EnterExitCosts.Visa;
  12361. row1_1 = $"签证费:{_EnterExitCosts.Visa.ToString("#0.00")} 人民币/人";
  12362. //if (!string.IsNullOrEmpty(_EnterExitCosts.VisaRemark))
  12363. //{
  12364. // row1_1 += $"\t签证费用描述: {_EnterExitCosts.VisaRemark} 人民币/人";
  12365. //}
  12366. }
  12367. string row1_2 = "";
  12368. if (_EnterExitCosts.YiMiao > 0)
  12369. {
  12370. //insidePayTotal += _EnterExitCosts.YiMiao;
  12371. row1_2 += $"疫苗费:{_EnterExitCosts.YiMiao.ToString("#0.00")} 人民币/人";
  12372. }
  12373. if (_EnterExitCosts.HeSuan > 0)
  12374. {
  12375. //insidePayTotal += _EnterExitCosts.HeSuan;
  12376. row1_2 += $"核酸检测费:{_EnterExitCosts.HeSuan.ToString("#0.00")} 人民币/人";
  12377. }
  12378. if (_EnterExitCosts.Service > 0)
  12379. {
  12380. //insidePayTotal += _EnterExitCosts.Service;
  12381. row1_2 += $"服务费:{_EnterExitCosts.Service.ToString("#0.00")} 人民币/人";
  12382. }
  12383. string row1_3 = "";
  12384. if (_EnterExitCosts.Safe > 0)
  12385. {
  12386. //insidePayTotal += _EnterExitCosts.Safe;
  12387. row1_3 += $"保险费:{_EnterExitCosts.Safe.ToString("#0.00")} 人民币/人";
  12388. }
  12389. if (_EnterExitCosts.Ticket > 0)
  12390. {
  12391. //insidePayTotal += _EnterExitCosts.Ticket;
  12392. row1_3 += $"参展门票:{_EnterExitCosts.Ticket.ToString("#0.00")} 人民币/人";
  12393. }
  12394. string row1 = "";
  12395. if (!string.IsNullOrEmpty(row1_1)) row1 += $"{row1_1}\r\n";
  12396. if (!string.IsNullOrEmpty(row1_2)) row1 += $"{row1_2}\r\n";
  12397. if (!string.IsNullOrEmpty(row1_3)) row1 += $"{row1_3}\r\n";
  12398. row1 += $"备注:{_EnterExitCosts.Remark}";
  12399. dic.Add("InsidePay", insidePayTotal.ToString("#0.00"));
  12400. dic.Add("Row1Str", row1);
  12401. }
  12402. string airTotalStr = string.Empty,
  12403. airPriceStr = string.Empty;
  12404. //经济舱
  12405. if (_EnterExitCosts.SumJJC == 1)
  12406. {
  12407. airTotalStr += $"{_EnterExitCosts.OutsideJJPay.ToString("#0.00")}元/人(经济舱)";
  12408. airPriceStr += $"{_EnterExitCosts.AirJJ.ToString("#0.00")}元/人(经济舱)";
  12409. }
  12410. //公务舱
  12411. if (_EnterExitCosts.SumGWC == 1)
  12412. {
  12413. airTotalStr += $" {_EnterExitCosts.OutsideGWPay.ToString("#0.00")} 元/人(公务舱)";
  12414. airPriceStr += $" {_EnterExitCosts.AirGW.ToString("#0.00")} 元/人(公务舱)";
  12415. }
  12416. //头等舱
  12417. if (_EnterExitCosts.SumTDC == 1)
  12418. {
  12419. airTotalStr += $" {_EnterExitCosts.OutsideTDPay.ToString("#0.00")} 元/人(头等舱)";
  12420. airPriceStr += $" {_EnterExitCosts.AirTD.ToString("#0.00")} 元/人(头等舱)";
  12421. }
  12422. //汇率描述
  12423. string rateStr = "";
  12424. if (peiceItemCurrencyInfos.Any())
  12425. {
  12426. rateStr = "\r\n汇率描述:";
  12427. foreach (var item in peiceItemCurrencyInfos)
  12428. {
  12429. rateStr += $"{item.CurrencyName}({item.CurrencyCode}):{item.Rate.ToString("#0.0000")} ";
  12430. }
  12431. }
  12432. string twoItemRemark = "备注:";
  12433. if (!string.IsNullOrEmpty(_EnterExitCosts.TwoItemRemark)) twoItemRemark += _EnterExitCosts.TwoItemRemark;
  12434. if (!string.IsNullOrEmpty(rateStr)) twoItemRemark += rateStr;
  12435. dic.Add("AirTotalStr", airTotalStr);
  12436. dic.Add("AirPriceStr", airPriceStr);
  12437. dic.Add("CityTranffic", _EnterExitCosts.CityTranffic.ToString("#0.00"));
  12438. dic.Add("TwoItemRemark", twoItemRemark);
  12439. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  12440. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  12441. int table1Row = 0,
  12442. table2Row = 0,
  12443. table3Row = 0,
  12444. table4Row = 0,
  12445. table5Row = 0;
  12446. //住宿费
  12447. if (_EnterExitCosts.ChoiceThree == 1)
  12448. {
  12449. dic.Add("SubZS", stayFeeTotal.ToString("#0.00"));
  12450. table1Row = dac1.Count;
  12451. #region 填充word表格内容
  12452. for (int i = 0; i < dac1.Count; i++)
  12453. {
  12454. var dac = dac1[i];
  12455. if (dac == null) continue;
  12456. builder.MoveToCell(0, i, 0, 0);
  12457. builder.Write("第" + dac.Days.ToString() + "晚:");
  12458. builder.MoveToCell(0, i, 1, 0);
  12459. //builder.Write(placeData.Find(it => it.Id == dac.NationalTravelFeeId)?.Country ?? "Unknown");
  12460. //builder.Write(dac.Place == null ? "" : dac.Place);
  12461. builder.Write(GetEnterExitCostDraftExportCity(placeData, dac.NationalTravelFeeId));
  12462. builder.MoveToCell(0, i, 2, 0);
  12463. builder.Write("费用标准:");
  12464. string curr = "";
  12465. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  12466. if (currData != null)
  12467. {
  12468. curr = currData.Name;
  12469. }
  12470. builder.MoveToCell(0, i, 3, 0);
  12471. builder.Write(dac.Cost.ToString("#0.00") + curr);
  12472. builder.MoveToCell(0, i, 4, 0);
  12473. builder.Write("费用小计:");
  12474. builder.MoveToCell(0, i, 5, 0);
  12475. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  12476. }
  12477. #endregion
  12478. }
  12479. else dic.Add("SubZS", "0.00");
  12480. //删除多余行
  12481. while (table1.Rows.Count > table1Row)
  12482. {
  12483. table1.Rows.RemoveAt(table1Row);
  12484. }
  12485. //伙食费
  12486. Aspose.Words.Tables.Table table2 = allTables[1] as Aspose.Words.Tables.Table;
  12487. if (_EnterExitCosts.ChoiceFour == 1)
  12488. {
  12489. dic.Add("SubHS", mealsFeeTotal.ToString("#0.00"));
  12490. table2Row = dac2.Count;
  12491. #region 填充word表格内容
  12492. for (int i = 0; i < dac2.Count; i++)
  12493. {
  12494. var dac = dac2[i];
  12495. if (dac == null) continue;
  12496. builder.MoveToCell(1, i, 0, 0);
  12497. builder.Write("第" + dac.Days.ToString() + "天:");
  12498. builder.MoveToCell(1, i, 1, 0);
  12499. builder.Write(GetEnterExitCostDraftExportCity(placeData, dac.NationalTravelFeeId));
  12500. builder.MoveToCell(1, i, 2, 0);
  12501. builder.Write("费用标准:");
  12502. string curr = "";
  12503. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  12504. if (currData != null)
  12505. {
  12506. curr = currData.Name;
  12507. }
  12508. builder.MoveToCell(1, i, 3, 0);
  12509. builder.Write(dac.Cost.ToString("#0.00") + curr);
  12510. builder.MoveToCell(1, i, 4, 0);
  12511. builder.Write("费用小计:");
  12512. builder.MoveToCell(1, i, 5, 0);
  12513. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  12514. }
  12515. #endregion
  12516. }
  12517. else dic.Add("SubHS", "0.00");
  12518. //删除多余行
  12519. while (table2.Rows.Count > table2Row)
  12520. {
  12521. table2.Rows.RemoveAt(table2Row);
  12522. }
  12523. //公杂费
  12524. Aspose.Words.Tables.Table table3 = allTables[2] as Aspose.Words.Tables.Table;
  12525. if (_EnterExitCosts.ChoiceFive == 1)
  12526. {
  12527. dic.Add("SubGZF", miscellaneousFeeTotal.ToString("#0.00"));
  12528. table3Row = dac3.Count;
  12529. #region 填充word表格内容
  12530. for (int i = 0; i < dac3.Count; i++)
  12531. {
  12532. var dac = dac3[i];
  12533. if (dac == null) continue;
  12534. builder.MoveToCell(2, i, 0, 0);
  12535. builder.Write("第" + dac.Days.ToString() + "天:");
  12536. builder.MoveToCell(2, i, 1, 0);
  12537. builder.Write(GetEnterExitCostDraftExportCity(placeData, dac.NationalTravelFeeId));
  12538. builder.MoveToCell(2, i, 2, 0);
  12539. builder.Write("费用标准:");
  12540. string curr = "";
  12541. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  12542. if (currData != null)
  12543. {
  12544. curr = currData.Name;
  12545. }
  12546. builder.MoveToCell(2, i, 3, 0);
  12547. builder.Write(dac.Cost.ToString("#0.00") + curr);
  12548. builder.MoveToCell(2, i, 4, 0);
  12549. builder.Write("费用小计:");
  12550. builder.MoveToCell(2, i, 5, 0);
  12551. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  12552. }
  12553. //删除多余行
  12554. while (table3.Rows.Count > table3Row)
  12555. {
  12556. table3.Rows.RemoveAt(table3Row);
  12557. }
  12558. #endregion
  12559. }
  12560. else dic.Add("SubGZF", "0.00");
  12561. //删除多余行
  12562. while (table3.Rows.Count > table3Row)
  12563. {
  12564. table3.Rows.RemoveAt(table3Row);
  12565. }
  12566. //培训费
  12567. Aspose.Words.Tables.Table table4 = allTables[3] as Aspose.Words.Tables.Table;
  12568. if (_EnterExitCosts.ChoiceSix == 1)
  12569. {
  12570. string pxStr = $"六、培训费合计: {tainFeeTotal.ToString("#0.00")} 元/人";
  12571. dic.Add("SubPX", pxStr);
  12572. table4Row = dac4.Count;
  12573. #region 填充word表格内容
  12574. for (int i = 0; i < dac4.Count; i++)
  12575. {
  12576. var dac = dac4[i];
  12577. if (dac == null) continue;
  12578. builder.MoveToCell(3, i, 0, 0);
  12579. builder.Write("第" + dac.Days.ToString() + "天:");
  12580. builder.MoveToCell(3, i, 1, 0);
  12581. builder.Write(GetEnterExitCostDraftExportCity(placeData, dac.NationalTravelFeeId));
  12582. builder.MoveToCell(3, i, 2, 0);
  12583. builder.Write("费用标准:");
  12584. string curr = "";
  12585. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  12586. if (currData != null)
  12587. {
  12588. curr = currData.Name;
  12589. }
  12590. builder.MoveToCell(3, i, 3, 0);
  12591. builder.Write(dac.Cost.ToString("#0.00") + curr);
  12592. builder.MoveToCell(3, i, 4, 0);
  12593. builder.Write("费用小计:");
  12594. builder.MoveToCell(3, i, 5, 0);
  12595. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  12596. }
  12597. #endregion
  12598. }
  12599. //else dic.Add("SubPX", $"六、培训费合计: 0 元/人");
  12600. //删除多余行
  12601. while (table4.Rows.Count > table4Row)
  12602. {
  12603. table4.Rows.RemoveAt(table4Row);
  12604. }
  12605. //其他费用
  12606. Aspose.Words.Tables.Table table5 = allTables[4] as Aspose.Words.Tables.Table;
  12607. if (_EnterExitCosts.OtherExpenses_Checked == 1)
  12608. {
  12609. string qtStr = $"七、其他费用合计: {otherPriceTotal.ToString("#0.00")} 元/人";
  12610. dic.Add("titleQi", qtStr);
  12611. table5Row = dac5.Count;
  12612. #region 填充word表格内容
  12613. for (int i = 0; i < dac5.Count; i++)
  12614. {
  12615. var dac = dac5[i];
  12616. if (dac == null) continue;
  12617. builder.MoveToCell(4, i, 0, 0);
  12618. builder.Write("第" + dac.Index.ToString() + "项:");
  12619. builder.MoveToCell(4, i, 1, 0);
  12620. builder.Write(dac.itemName);
  12621. builder.MoveToCell(4, i, 2, 0);
  12622. builder.Write("费用标准:");
  12623. builder.MoveToCell(4, i, 3, 0);
  12624. builder.Write(dac.Cost.ToString("#0.00") + dac.CurrencyStr);
  12625. builder.MoveToCell(4, i, 4, 0);
  12626. builder.Write("费用小计:");
  12627. builder.MoveToCell(4, i, 5, 0);
  12628. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  12629. builder.MoveToCell(4, i, 6, 0);
  12630. builder.Write("备注:");
  12631. builder.MoveToCell(4, i, 7, 0);
  12632. builder.Write(dac.Remark);
  12633. }
  12634. #endregion
  12635. }
  12636. //else dic.Add("SubQT", "七、其他费用合计: 0 元/人");
  12637. //删除多余行
  12638. while (table5.Rows.Count > table5Row)
  12639. {
  12640. table5.Rows.RemoveAt(table5Row);
  12641. }
  12642. //加上其他费用
  12643. decimal otherFeeTotal = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + otherPriceTotal;
  12644. decimal subJJC = 0.00M,
  12645. subGWC = 0.00M,
  12646. subTDC = 0.00M;
  12647. //全部费用总计: 元 / 人(经济舱) 元 / 人(公务舱) 元 / 人(头等舱)
  12648. string totalLabel = string.Format("全部费用总计:");
  12649. //经济舱
  12650. if (_EnterExitCosts.SumJJC == 1)
  12651. {
  12652. subJJC = otherFeeTotal + _EnterExitCosts.OutsideJJPay;
  12653. totalLabel += $"{subJJC.ToString("#0.00")} 元/人(经济舱)";
  12654. }
  12655. //公务舱
  12656. if (_EnterExitCosts.SumGWC == 1)
  12657. {
  12658. subGWC = otherFeeTotal + _EnterExitCosts.OutsideGWPay;
  12659. totalLabel += $"{subGWC.ToString("#0.00")} 元/人(公务舱)";
  12660. }
  12661. //头等舱
  12662. if (_EnterExitCosts.SumTDC == 1)
  12663. {
  12664. subTDC = otherFeeTotal + _EnterExitCosts.OutsideTDPay;
  12665. totalLabel += $"{subTDC.ToString("#0.00")} 元/人(头等舱)";
  12666. }
  12667. //TotalLabel
  12668. dic.Add("TotalLabel", totalLabel);
  12669. #region 填充word模板书签内容
  12670. foreach (var key in dic.Keys)
  12671. {
  12672. Bookmark bookmark = doc.Range.Bookmarks[key];
  12673. if (bookmark != null)
  12674. {
  12675. builder.MoveToBookmark(key);
  12676. builder.Write(dic[key]);
  12677. }
  12678. }
  12679. #endregion
  12680. //文件名
  12681. string strFileName = $"{_EnterExitCosts.DraftName}_出入境费用-草稿{Guid.NewGuid().ToString()}.docx";
  12682. strFileName = CommonFun.ValidFileName(strFileName);
  12683. AsposeHelper.removewatermark_v2180();
  12684. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  12685. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  12686. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  12687. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  12688. }
  12689. else if (dto.SubTypeId == 1006)//1006(因公出国(境)经费测算明细表)
  12690. {
  12691. //获取模板
  12692. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/因公出国(境)经费测算明细表.docx");
  12693. //载入模板
  12694. Document doc = new Document(tempPath);
  12695. DocumentBuilder builder = new DocumentBuilder(doc);
  12696. Dictionary<string, string> dic = new Dictionary<string, string>();
  12697. string returnCodeLabel = string.Empty;
  12698. if (nationalTravelFeeData.Any())
  12699. {
  12700. List<string> list = new List<string>();
  12701. foreach (var item in nationalTravelFeeData)
  12702. {
  12703. list.Add($"{item.Country}({item.City})");
  12704. }
  12705. list = list.Distinct().ToList();
  12706. returnCodeLabel = string.Join("-", list).TrimEnd('-');
  12707. }
  12708. var countryLabel = string.Empty;
  12709. var countryData = nationalTravelFeeData.Select(x => x.Country).Distinct().ToList();
  12710. if (countryData.Any())
  12711. {
  12712. countryLabel = string.Join("、", countryData);
  12713. }
  12714. dic.Add("ReturnCodeAir", returnCodeLabel);
  12715. dic.Add("VisitStartDate", "-");
  12716. dic.Add("VisitEndDate", "-");
  12717. dic.Add("Day", "-");
  12718. dic.Add("VisitCountry", countryLabel);
  12719. dic.Add("ClientUnit", "-");
  12720. //var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  12721. //dic.Add("Names", Names);
  12722. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  12723. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  12724. decimal dac1totalPrice = 0.00M;
  12725. int accommodationStartIndex = 6, foodandotherStartIndex = 22;
  12726. foreach (var dac in dac1)
  12727. {
  12728. if (dac.SubTotal == 0.00M)
  12729. {
  12730. continue;
  12731. }
  12732. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  12733. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  12734. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  12735. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  12736. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  12737. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  12738. builder.Write(currency);//币种
  12739. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  12740. builder.Write(dac.Cost.ToString("#0.00"));//标准
  12741. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  12742. builder.Write("");//人数
  12743. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  12744. builder.Write("");//天数
  12745. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  12746. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  12747. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  12748. decimal rate = 0.00M;
  12749. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  12750. builder.Write(rate.ToString("#0.0000"));//汇率
  12751. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  12752. decimal rbmPrice = dac.SubTotal;
  12753. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  12754. accommodationStartIndex++;
  12755. dac1totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  12756. }
  12757. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  12758. for (int i = 21; i > (dac1.Count == 0 ? 1 : dac1.Count) + 6; i--)
  12759. {
  12760. table1.Rows.RemoveAt(i - 1);
  12761. foodandotherStartIndex--;
  12762. }
  12763. if (dac2.Count == dac3.Count)//国家 币种 金额
  12764. {
  12765. for (int i = 0; i < dac2.Count; i++)
  12766. {
  12767. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  12768. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  12769. }
  12770. }
  12771. decimal dac2totalPrice = 0.00M;
  12772. foreach (var dac in dac2)
  12773. {
  12774. if (dac.SubTotal == 0)
  12775. {
  12776. continue;
  12777. }
  12778. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  12779. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  12780. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  12781. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  12782. builder.Write(currency);//币种
  12783. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  12784. builder.Write(dac.Cost.ToString("#0.00"));//标准
  12785. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  12786. builder.Write("");//人数
  12787. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  12788. builder.Write("");//天数
  12789. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  12790. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  12791. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  12792. decimal rate = 0.00M;
  12793. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  12794. builder.Write(rate.ToString("#0.0000"));//汇率
  12795. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  12796. decimal rbmPrice = dac.SubTotal;
  12797. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  12798. foodandotherStartIndex++;
  12799. dac2totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  12800. }
  12801. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  12802. for (int i = foodandotherStartIndex + (15 - dac2.Count); i > (dac2.Count == 0 ? 1 : 0) + foodandotherStartIndex; i--)
  12803. {
  12804. table1.Rows.RemoveAt(i - 1);
  12805. }
  12806. dic.Add("CityTranffic", _EnterExitCosts.CityTranffic.ToString("#0.00"));
  12807. string otherFeeStr = "";
  12808. if (_EnterExitCosts.Visa > 0) otherFeeStr += $"签证费:{_EnterExitCosts.Visa.ToString("#0.00")} 元,";
  12809. if (_EnterExitCosts.Safe > 0) otherFeeStr += $"保险费:{_EnterExitCosts.Safe.ToString("#0.00")} 元,";
  12810. if (_EnterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费:{_EnterExitCosts.Ticket.ToString("#0.00")} 元,";
  12811. #region 其他款项费用 增加位置:模板第6项其他费用字符串追加
  12812. foreach (var otherInfo in dac5)
  12813. {
  12814. otherFeeStr += $"{otherInfo.itemName}:{otherInfo.SubTotal.ToString("#0.00")} 元,";
  12815. }
  12816. #endregion
  12817. if (otherFeeStr.Length > 0)
  12818. {
  12819. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  12820. otherFeeStr = $"({otherFeeStr})";
  12821. dic.Add("OtherFeeStr", otherFeeStr);
  12822. }
  12823. //总计
  12824. decimal allPrice = dac1totalPrice + dac2totalPrice + _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket;
  12825. //国际旅费
  12826. string outsideAir = string.Empty;
  12827. string allPriceAir = string.Empty;
  12828. if (_EnterExitCosts.SumJJC == 1)
  12829. {
  12830. outsideAir += string.Format(@"经济舱:{0} 元/人;", _EnterExitCosts.AirJJ.ToString("#0.00"));
  12831. allPriceAir += string.Format(@"经济舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideJJPay).ToString("#0.00"));
  12832. }
  12833. if (_EnterExitCosts.SumGWC == 1)
  12834. {
  12835. outsideAir += string.Format(@"公务舱:{0} 元/人;", _EnterExitCosts.AirGW.ToString("#0.00"));
  12836. allPriceAir += string.Format(@"公务舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  12837. }
  12838. if (_EnterExitCosts.SumTDC == 1)
  12839. {
  12840. outsideAir += string.Format(@"头等舱:{0} 元/人;", _EnterExitCosts.AirTD.ToString("#0.00"));
  12841. allPriceAir += string.Format(@"头等舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideTDPay).ToString("#0.00"));
  12842. }
  12843. dic.Add("InTravelPrice", $"({outsideAir})");
  12844. dic.Add("FinalSumPrice", $"({allPriceAir})");
  12845. //dic.Add("VisaPay", _EnterExitCosts.Visa.ToString("#0.00"));
  12846. //dic.Add("SafePay", _EnterExitCosts.Safe.ToString("#0.00"));
  12847. //dic.Add("YiMiao", _EnterExitCosts.YiMiao.ToString("#0.00"));
  12848. foreach (var key in dic.Keys)
  12849. {
  12850. builder.MoveToBookmark(key);
  12851. builder.Write(dic[key]);
  12852. }
  12853. //模板文件名
  12854. string strFileName = $"草稿_{_EnterExitCosts.DraftName}_因公出国(境)经费测算明细表{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
  12855. strFileName = CommonFun.ValidFileName(strFileName);
  12856. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  12857. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  12858. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  12859. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  12860. }
  12861. else if (dto.SubTypeId == 1007) //1007(四川省商务厅出国经费财政先行审核表)
  12862. {
  12863. //获取模板
  12864. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/四川省商务厅出国经费财政先行审核表.xls");
  12865. //载入模板
  12866. WorkbookDesigner designer = new WorkbookDesigner();
  12867. designer.Workbook = new Workbook(tempPath);
  12868. Dictionary<string, string> dic = new Dictionary<string, string>();
  12869. string returnCodeLabel = string.Empty;
  12870. if (nationalTravelFeeData.Any())
  12871. {
  12872. List<string> list = new List<string>();
  12873. foreach (var item in nationalTravelFeeData)
  12874. {
  12875. list.Add($"{item.Country}({item.City})");
  12876. }
  12877. list = list.Distinct().ToList();
  12878. returnCodeLabel = string.Join("-", list).TrimEnd('-');
  12879. }
  12880. var countryLabel = string.Empty;
  12881. var countryData = nationalTravelFeeData.Select(x => x.Country).Distinct().ToList();
  12882. if (countryData.Any())
  12883. {
  12884. countryLabel = string.Join("、", countryData);
  12885. }
  12886. dic.Add("ReturnCodeAir", returnCodeLabel);
  12887. dic.Add("VisitStartDate", "-");
  12888. dic.Add("VisitEndDate", "-");
  12889. dic.Add("Day", "0");
  12890. dic.Add("VisitCountry", countryLabel);
  12891. dic.Add("ClientUnit", "-");
  12892. designer.SetDataSource("ClientUnit", "-");
  12893. designer.SetDataSource("VisitCountry", countryLabel);
  12894. designer.SetDataSource("Group", "-");
  12895. designer.SetDataSource("ClientUnitTitle", "-");
  12896. designer.SetDataSource("Name", "-");
  12897. designer.SetDataSource("VisitStartDate", "-");
  12898. designer.SetDataSource("Day", "0");
  12899. designer.SetDataSource("ReturnCode", returnCodeLabel);
  12900. designer.SetDataSource("ReturnCodeAir", "-");
  12901. int startIndex = 10;
  12902. const int startIndexcopy = 10;
  12903. if (dac2.Count == dac3.Count)//国家 币种 金额
  12904. {
  12905. for (int i = 0; i < dac2.Count; i++)
  12906. {
  12907. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  12908. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  12909. }
  12910. }
  12911. DataTable dtdac1 = new DataTable();
  12912. List<string> place = new List<string>();
  12913. dtdac1.Columns.AddRange(new DataColumn[] {
  12914. new DataColumn(){ ColumnName = "city"},
  12915. new DataColumn(){ ColumnName = "curr"},
  12916. new DataColumn(){ ColumnName = "criterion"},
  12917. new DataColumn(){ ColumnName = "number",DataType = typeof(int)},
  12918. new DataColumn(){ ColumnName = "day",DataType = typeof(int)},
  12919. new DataColumn(){ ColumnName = "cost", DataType = typeof(decimal)},
  12920. new DataColumn(){ ColumnName = "rate", DataType = typeof(decimal) },
  12921. new DataColumn(){ ColumnName = "costRMB", DataType = typeof(decimal) },
  12922. });
  12923. DataTable dtdac2 = new DataTable();
  12924. dtdac2.Columns.AddRange(new DataColumn[] {
  12925. new DataColumn(){ ColumnName = "city"},
  12926. new DataColumn(){ ColumnName = "curr"},
  12927. new DataColumn(){ ColumnName = "criterion"},
  12928. new DataColumn(){ ColumnName = "number",DataType = typeof(int)},
  12929. new DataColumn(){ ColumnName = "day",DataType = typeof(int)},
  12930. new DataColumn(){ ColumnName = "cost", DataType = typeof(decimal)},
  12931. new DataColumn(){ ColumnName = "rate", DataType = typeof(decimal) },
  12932. new DataColumn(){ ColumnName = "costRMB",DataType = typeof(decimal)},
  12933. });
  12934. dtdac1.TableName = "tb1";
  12935. dtdac2.TableName = "tb2";
  12936. decimal dac1totalPrice = 0.00M, dac2totalPrice = 0.00M;
  12937. foreach (var item in dac1)
  12938. {
  12939. item.Place = GetEnterExitCostDraftExportCity(placeData, item.NationalTravelFeeId);
  12940. if (place.Contains(item.Place))
  12941. {
  12942. continue;
  12943. }
  12944. DataRow row = dtdac1.NewRow();
  12945. row["city"] = item.Place;
  12946. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  12947. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  12948. row["curr"] = currency;
  12949. row["rate"] = rate.ToString("#0.0000");
  12950. row["criterion"] = item.Cost.ToString("#0.00");
  12951. row["number"] = 1;
  12952. row["day"] = dac1.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  12953. //row["costRMB"] = rbmPrice;
  12954. dtdac1.Rows.Add(row);
  12955. place.Add(item.Place);
  12956. }
  12957. place = new List<string>();
  12958. foreach (var item in dac2)
  12959. {
  12960. item.Place = GetEnterExitCostDraftExportCity(placeData, item.NationalTravelFeeId);
  12961. if (place.Contains(item.Place))
  12962. {
  12963. continue;
  12964. }
  12965. DataRow row = dtdac2.NewRow();
  12966. row["city"] = item.Place;
  12967. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  12968. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  12969. row["curr"] = currency;
  12970. row["rate"] = rate.ToString("#0.0000");
  12971. row["criterion"] = item.Cost.ToString("#0.00");
  12972. row["number"] = 1;
  12973. row["day"] = dac2.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  12974. //row["cost"] = item.SubTotal;
  12975. //row["costRMB"] = rbmPrice;
  12976. dtdac2.Rows.Add(row);
  12977. place.Add(item.Place);
  12978. //dac2totalPrice += rbmPrice;
  12979. }
  12980. dac1totalPrice = dac1.Sum(it => it.SubTotal);
  12981. dac2totalPrice = dac2.Sum(it => it.SubTotal);
  12982. designer.SetDataSource("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  12983. designer.SetDataSource("dac2totalPrice", dac2totalPrice);
  12984. designer.SetDataSource("cityTranffic", @$"其中:国外城市间机票费: {_EnterExitCosts.CityTranffic:#0.00} 元");
  12985. designer.SetDataSource("sumCityTranffic", @$"{_EnterExitCosts.CityTranffic:#0.00} ");
  12986. string cell4Str1 = string.Empty;
  12987. if (_EnterExitCosts.SumJJC == 1) cell4Str1 += $"经济舱:{_EnterExitCosts.AirJJ:#0.00} 元/人;";
  12988. if (_EnterExitCosts.SumGWC == 1) cell4Str1 += $"公务舱:{_EnterExitCosts.AirGW:#0.00} 元/人;";
  12989. if (_EnterExitCosts.SumTDC == 1) cell4Str1 += $"公务舱:{_EnterExitCosts.AirTD:#0.00} 元/人;";
  12990. string cell4Str = $" 4.国际旅费:{cell4Str1}";
  12991. string cellStr = $" 5.其他费用(";
  12992. if (_EnterExitCosts.Visa > 0) cellStr += $"签证费:{_EnterExitCosts.Visa:#0.00}元,";
  12993. if (_EnterExitCosts.YiMiao > 0) cellStr += $"疫苗费:{_EnterExitCosts.YiMiao:#0.00}元,";
  12994. if (_EnterExitCosts.HeSuan > 0) cellStr += $"核酸费:{_EnterExitCosts.HeSuan:#0.00}元,";
  12995. if (_EnterExitCosts.Safe > 0) cellStr += $"保险费:{_EnterExitCosts.Safe:#0.00}元,";
  12996. if (_EnterExitCosts.Ticket > 0) cellStr += $"参展门票费:{_EnterExitCosts.Ticket:#0.00}元,";
  12997. if (_EnterExitCosts.Service > 0) cellStr += $"服务费:{_EnterExitCosts.Service:#0.00}元,";
  12998. #region 其他款项费用 增加位置:模板第5项其他费用字符串追加
  12999. var otherPriceTotal = dac5.Sum(x => x.SubTotal);
  13000. foreach (var otherInfo in dac5)
  13001. {
  13002. cellStr += $"{otherInfo.itemName}:{otherInfo.SubTotal:#0.00} 元,";
  13003. }
  13004. #endregion
  13005. if (cellStr.Length > 8)
  13006. {
  13007. cellStr = cellStr.Substring(0, cellStr.Length - 1);
  13008. }
  13009. cellStr += ")";
  13010. decimal otherFee = _EnterExitCosts.Visa + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.Service + otherPriceTotal;
  13011. decimal s = dac1totalPrice + dac2totalPrice + _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay + otherFee;
  13012. decimal pxFee = dac4.Sum(it => it.Cost);
  13013. decimal glvFee = _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay;
  13014. string celllastStr1 = "";
  13015. if (dac1totalPrice > 0) celllastStr1 += $"住宿费 {dac1totalPrice:#0.00} 元";
  13016. if (dac2totalPrice > 0) celllastStr1 += $",伙食费和公杂费 {dac2totalPrice:#0.00} 元";
  13017. if (pxFee > 0) celllastStr1 += $",培训费 {pxFee:#0.00} 元";
  13018. celllastStr1 += $",国际旅费 元";
  13019. if (otherFee > 0) celllastStr1 += $",其他费用 {otherFee:#0.00} 元";
  13020. string celllastStr = $" 经审核,{celllastStr1},本次出国经费预算合计为 元。其中:市本级安排 。";
  13021. designer.SetDataSource("cell4Str", cell4Str);
  13022. designer.SetDataSource("cellStr", cellStr);
  13023. designer.SetDataSource("cellSum", otherFee.ToString("#0.00"));
  13024. designer.SetDataSource("cellSum4", (_EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  13025. designer.SetDataSource("celllastStr", celllastStr);
  13026. Workbook wb = designer.Workbook;
  13027. var sheet = wb.Worksheets[0];
  13028. //绑定datatable数据集
  13029. designer.SetDataSource(dtdac1);
  13030. designer.SetDataSource(dtdac2);
  13031. designer.Process();
  13032. var rowStart = dtdac1.Rows.Count;
  13033. while (rowStart > 0)
  13034. {
  13035. sheet.Cells[startIndex, 8].Formula = $"=G{startIndex + 1} * H{startIndex + 1}";
  13036. sheet.Cells[startIndex, 6].Formula = $"=E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  13037. startIndex++;
  13038. rowStart--;
  13039. }
  13040. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + 1}: I{startIndex})";
  13041. startIndex += 1; //总计行
  13042. rowStart = dtdac2.Rows.Count;
  13043. while (rowStart > 0)
  13044. {
  13045. sheet.Cells[startIndex, 8].Formula = $"= G{startIndex + 1} * H{startIndex + 1}";
  13046. sheet.Cells[startIndex, 6].Formula = $"= E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  13047. startIndex++;
  13048. rowStart--;
  13049. }
  13050. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + dtdac1.Rows.Count + 2}: I{startIndex})";
  13051. wb.CalculateFormula(true);
  13052. //模板文件名
  13053. string strFileName = $"草稿_{_EnterExitCosts.DraftName}_四川省商务厅出国经费财政先行审核表{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  13054. designer.Workbook.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  13055. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  13056. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  13057. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  13058. }
  13059. else if (dto.SubTypeId == 1066) //成都市因公临时出国任务和预算审批意见表(外专培训团专用)
  13060. {
  13061. //获取模板
  13062. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/成都市因公临时出国任务和预算审批意见表.docx");
  13063. //载入模板
  13064. Document doc = new Document(tempPath);
  13065. DocumentBuilder builder = new DocumentBuilder(doc);
  13066. Dictionary<string, string> dic = new Dictionary<string, string>();
  13067. dic.Add("GroupName", "-");
  13068. dic.Add("ClientUnit", "-");
  13069. //string missionLeader = ""; //团负责人默认接团客户名单第一个人
  13070. //string missionLeaderJob = "";//负责人job
  13071. //int groupNumber = 0; //团人数
  13072. dic.Add("MissionLeader", "-"); //团负责人
  13073. dic.Add("MissionLeaderJob", "-"); //团负责人job
  13074. dic.Add("GroupNumber", "0"); //团人数
  13075. dic.Add("Day", "0");
  13076. dic.Add("CultivateDay", dac4.Count.ToString()); //培训天数
  13077. // dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  13078. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  13079. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  13080. decimal hotelFeeTotal = dac1.Sum(it => it.SubTotal);//住宿费
  13081. dic.Add("HotelFeeTotal", hotelFeeTotal.ToString("#0.00"));
  13082. decimal mealsFeeTotal = dac2.Sum(it => it.SubTotal);//伙食费
  13083. dic.Add("MealsFeeTotal", mealsFeeTotal.ToString("#0.00"));
  13084. decimal miscellaneousFeeTotal = dac3.Sum(it => it.SubTotal);//公杂费
  13085. dic.Add("MiscellaneousFeeTotal", miscellaneousFeeTotal.ToString("#0.00"));
  13086. decimal trainingFeeTotal = dac4.Sum(it => it.SubTotal);//培训费
  13087. dic.Add("TrainingFeeTotal", trainingFeeTotal.ToString("#0.00"));
  13088. decimal cityTranfficFeeToatal = _EnterExitCosts.CityTranffic; //城市区间交通费
  13089. dic.Add("CityTranfficFeeToatal", cityTranfficFeeToatal.ToString("#0.00"));//
  13090. //其他费用
  13091. decimal otherFeeTotal = _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Service + dac5.Sum(x => x.SubTotal);
  13092. dic.Add("OtherFeeTotal", otherFeeTotal.ToString("#0.00"));
  13093. //其他费用合计
  13094. decimal _otherFeeTotal = hotelFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + trainingFeeTotal + cityTranfficFeeToatal + otherFeeTotal;
  13095. decimal _jjcFeeToatal = _EnterExitCosts.AirJJ + _otherFeeTotal; //经济舱
  13096. decimal _gwcFeeToatal = _EnterExitCosts.AirGW + _otherFeeTotal; //公务舱
  13097. //公务舱合计
  13098. //国际旅费
  13099. //string outsideJJ = "";
  13100. //string allPriceJJ = "";
  13101. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 0)
  13102. {
  13103. dic.Add("AirFeeTotal", _EnterExitCosts.AirJJ.ToString("#0.00"));
  13104. dic.Add("FeeTotal", _jjcFeeToatal.ToString("#0.00"));
  13105. }
  13106. if (_EnterExitCosts.SumGWC == 1 && _EnterExitCosts.SumJJC == 0)
  13107. {
  13108. dic.Add("AirFeeTotal", _EnterExitCosts.AirGW.ToString("#0.00"));
  13109. dic.Add("FeeTotal", _gwcFeeToatal.ToString("#0.00"));
  13110. }
  13111. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 1)
  13112. {
  13113. string airFeeTotalStr = string.Format(@$"经济舱:{_EnterExitCosts.AirJJ:#0.00} 公务舱:{_EnterExitCosts.AirGW:#0.00}");
  13114. dic.Add("AirFeeTotal", airFeeTotalStr);
  13115. string feeTotalStr = string.Format(@$"经济舱:{_jjcFeeToatal:#0.00} 公务舱:{_gwcFeeToatal:#0.00}");
  13116. dic.Add("FeeTotal", feeTotalStr);
  13117. }
  13118. foreach (var key in dic.Keys)
  13119. {
  13120. builder.MoveToBookmark(key);
  13121. builder.Write(dic[key]);
  13122. }
  13123. //模板文件名
  13124. string strFileName = $"草稿_{_EnterExitCosts.DraftName}_成都市因公临时出国任务和预算审批意见表(外专培训团专用).docx";
  13125. strFileName = CommonFun.ValidFileName(strFileName);
  13126. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  13127. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  13128. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  13129. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  13130. }
  13131. }
  13132. else if (dto.ExportType == 2) //表格
  13133. {
  13134. return Ok(JsonView(400, "因需关联团组信息和客户信息,请在出入境费用明细里下载!", ""));
  13135. }
  13136. else if (dto.ExportType == 3)
  13137. {
  13138. return Ok(JsonView(400, "因需关联团组信息和客户信息,请在出入境费用明细里下载!", ""));
  13139. }
  13140. return Ok(JsonView(400, "只可导出明细表!", ""));
  13141. }
  13142. catch (Exception ex)
  13143. {
  13144. return Ok(JsonView(400, ex.Message, ""));
  13145. }
  13146. }
  13147. /// <summary>
  13148. /// 团组模块 - 出入境费用-草稿
  13149. /// 获取三公费用标准city
  13150. /// </summary>
  13151. /// <param name="placeData"></param>
  13152. /// <param name="nationalTravelFeeId"></param>
  13153. /// <returns></returns>
  13154. private string GetEnterExitCostDraftExportCity(List<Grp_NationalTravelFee> placeData, int nationalTravelFeeId)
  13155. {
  13156. string _city = string.Empty;
  13157. if (!placeData.Any()) return _city;
  13158. var data = placeData.Find(it => it.Id == nationalTravelFeeId);
  13159. if (data == null) return _city;
  13160. string country = data.Country;
  13161. string city = data.City;
  13162. if (city.Contains("其他城市") || city.Contains("所有城市")) _city = $"{country}-{city}";
  13163. else _city = city;
  13164. return _city;
  13165. }
  13166. /// <summary>
  13167. /// 团组模块 - 出入境费用-草稿
  13168. /// 一键清空
  13169. /// </summary>
  13170. /// <returns></returns>
  13171. [HttpPost]
  13172. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Del)]
  13173. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13174. public async Task<IActionResult> EnterExitCostDraftOneClickEmpty(EnterExitCostDraftOneClickEmptyDto dto)
  13175. {
  13176. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数;"));
  13177. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数;"));
  13178. var _view = await _enterExitCostDraftRep.OneClickEmpty(dto.Id, dto.UserId);
  13179. if (_view.Code == 0)
  13180. {
  13181. return Ok(JsonView(true, "操作成功"));
  13182. }
  13183. return Ok(JsonView(false, "操作失败"));
  13184. }
  13185. /// <summary>
  13186. /// 团组模块 - 出入境费用-草稿
  13187. /// 子项删除
  13188. /// </summary>
  13189. /// <returns></returns>
  13190. [HttpPost]
  13191. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Del)]
  13192. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13193. public async Task<IActionResult> EnterExitCostDraftSubItemDel(EnterExitCostDraftSubItemDelDto dto)
  13194. {
  13195. var data = await _enterExitCostDraftRep.EnterExitCostDraftSubItemDel(dto);
  13196. if (data.Code != 0)
  13197. {
  13198. return Ok(JsonView(false, data.Msg));
  13199. }
  13200. return Ok(JsonView(true, "操作成功!", data.Data));
  13201. }
  13202. /// <summary>
  13203. /// 团组模块 - 出入境费用-草稿
  13204. /// 删除
  13205. /// </summary>
  13206. /// <param name="dto"></param>
  13207. /// <returns></returns>
  13208. [HttpPost]
  13209. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Del)]
  13210. public IActionResult EnterExitCostDraftOtherExpensesDel(EnterExitCostDraftOtherExpensesDelDto dto)
  13211. {
  13212. var jw = JsonView(false, "删除失败!");
  13213. var data = new Grp_DayOtherPriceDraft()
  13214. {
  13215. Id = dto.Id,
  13216. IsDel = 1,
  13217. DeleteUserId = dto.DeleteUserId,
  13218. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  13219. };
  13220. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  13221. if (del > 0)
  13222. {
  13223. jw.Code = 200;
  13224. jw.Msg = "删除成功!";
  13225. }
  13226. return Ok(jw);
  13227. }
  13228. /// <summary>
  13229. /// 团组模块 - 出入境费用-草稿
  13230. /// 导入正式出入境费用基础数据
  13231. /// </summary>
  13232. /// <returns></returns>
  13233. [HttpPost]
  13234. public async Task<IActionResult> EnterExitCostDraftImportDataInit()
  13235. {
  13236. var jw = JsonView(false);
  13237. var groupNameDatas = await _groupRepository.EnterExitCostGroupNameAsync();
  13238. var draftDatas = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.IsDel == 0).OrderByDescending(x => x.CreateTime).Select(x => new { x.Id, x.DraftName }).ToListAsync();
  13239. jw.Code = StatusCodes.Status200OK;
  13240. jw.Msg = "操作成功!";
  13241. jw.Data = new { groupNameDatas, draftNames = draftDatas };
  13242. return Ok(jw);
  13243. }
  13244. /// <summary>
  13245. /// 团组模块 - 出入境费用-草稿
  13246. /// 导入正式出入境费用
  13247. /// </summary>
  13248. /// <param name="dto"></param>
  13249. /// <returns></returns>
  13250. [HttpPost]
  13251. public async Task<IActionResult> EnterExitCostDraftImportData(EnterExitCostDraftImportDataDto dto)
  13252. {
  13253. int userId = dto.UserId,
  13254. portId = dto.PortType,
  13255. groupId = dto.GroupId,
  13256. draftId = dto.DraftId;
  13257. _portTypeData.Add(1);
  13258. if (userId < 1) return Ok(JsonView(false, MsgTips.UserId));
  13259. if (!_portTypeData.Contains(portId)) return Ok(JsonView(false, MsgTips.Port));
  13260. if (groupId < 1) return Ok(JsonView(false, "请传入有效的GroupId!"));
  13261. if (draftId < 1) return Ok(JsonView(false, "请传入有效的DraftId!"));
  13262. _sqlSugar.BeginTran();
  13263. try
  13264. {
  13265. var draftDatas = _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.IsDel == 0 && x.Id == draftId).First();
  13266. if (draftDatas == null)
  13267. {
  13268. _sqlSugar.RollbackTran();
  13269. return Ok(JsonView(false, "草稿数据为空,不可导入!"));
  13270. }
  13271. //验证可覆盖已有数据 两边创建人需为同一人;
  13272. int draftCreateUserId = draftDatas.CreateUserId,
  13273. formalCreateUserId = 0;
  13274. var formalData = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).First();
  13275. if (formalData != null)
  13276. {
  13277. formalCreateUserId = formalData.CreateUserId;
  13278. if (draftCreateUserId != formalCreateUserId)
  13279. {
  13280. _sqlSugar.RollbackTran();
  13281. return Ok(JsonView(false, "由草稿数据到入至正式数据,两边创建人为同一人才可导入正式版!"));
  13282. }
  13283. }
  13284. //默认添加查看、编辑权限(创建人、自己)
  13285. await _enterExitCostRep.InitPerm(dto.GroupId, dto.UserId);
  13286. var dayDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>().Where(x => x.IsDel == 0 && x.ParentId == draftId).ToList();
  13287. var otherDatas = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>().Where(x => x.IsDel == 0 && x.ParentId == draftId).ToList();
  13288. var newExterData = _mapper.Map<Grp_EnterExitCost>(draftDatas);
  13289. newExterData.DiId = groupId;
  13290. newExterData.CreateUserId = userId;
  13291. newExterData.Remark = $"由草稿数据导入;草稿数Id:{draftId}";
  13292. var newDayDatas = _mapper.Map<List<Grp_DayAndCost>>(dayDatas);
  13293. if (newDayDatas.Any()) newDayDatas.Select(x => { x.DiId = groupId; x.CreateUserId = userId; return x; }).ToList();
  13294. var newOtherDatas = _mapper.Map<List<Grp_DayOtherPrice>>(otherDatas);
  13295. if (newOtherDatas.Any()) newOtherDatas.Select(x => { x.Diid = groupId; x.CreateUserId = userId; return x; }).ToList();
  13296. var enterExitCostInfo = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).First();
  13297. //数据如果存在执行删除
  13298. if (enterExitCostInfo != null)
  13299. {
  13300. _sqlSugar.Updateable<Grp_EnterExitCost>()
  13301. .SetColumns(x => new Grp_EnterExitCost() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Remark = "由草稿数据导入前软删除数据!" })
  13302. .Where(x => x.Id == enterExitCostInfo.Id)
  13303. .ExecuteCommand();
  13304. _sqlSugar.Updateable<Grp_DayAndCost>()
  13305. .SetColumns(x => new Grp_DayAndCost() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
  13306. .Where(x => x.DiId == groupId)
  13307. .ExecuteCommand();
  13308. _sqlSugar.Updateable<Grp_DayOtherPrice>()
  13309. .SetColumns(x => new Grp_DayOtherPrice() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
  13310. .Where(x => x.Diid == groupId)
  13311. .ExecuteCommand();
  13312. _sqlSugar.Updateable<Grp_EnterExitCostPermission>()
  13313. .SetColumns(x => new Grp_EnterExitCostPermission() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
  13314. .Where(x => x.GroupId == groupId)
  13315. .ExecuteCommand();
  13316. }
  13317. //执行insert
  13318. var insertId = _sqlSugar.Insertable(newExterData).ExecuteReturnIdentity();
  13319. if (insertId < 1)
  13320. {
  13321. _sqlSugar.RollbackTran();
  13322. return Ok(JsonView(false, "草稿数据导入失败!"));
  13323. }
  13324. if (newDayDatas.Any()) _sqlSugar.Insertable(newDayDatas).ExecuteCommand();
  13325. if (newOtherDatas.Any()) _sqlSugar.Insertable(newOtherDatas).ExecuteCommand();
  13326. #region 默认添加权限
  13327. #endregion
  13328. _sqlSugar.CommitTran();
  13329. //执行操作之后
  13330. //生成默认文件pdf并且通知人员
  13331. var fileView = await GeneralMethod.EnterExitCostDownload(new EnterExitCostDownloadDto()
  13332. {
  13333. DiId = groupId,
  13334. ExportType = 1,
  13335. SubTypeId = 1005
  13336. }, "pdf");
  13337. //发送通知
  13338. string fileUrl = (string)fileView.Data.GetType().GetProperty("Url").GetValue(fileView.Data, null);
  13339. string md5Sign = GeneralMethod.Encrypt($"{insertId}&fileName={fileUrl}");
  13340. string url = string.Format("http://oa.pan-american-intl.com:4399/#/Sankunginfo?sign={0}&fileName={1}", insertId, fileUrl);
  13341. await AppNoticeLibrary.SendUserMsg_GroupShare_ToGM(groupId, new List<string>() { "208", "233", "21" }, dto.UserId, url);
  13342. //汇率信息记录
  13343. await GeneralMethod.RateRecordSave(userId, insertId, "出入境费用-草稿导入");
  13344. return Ok(JsonView(true));
  13345. }
  13346. catch (Exception ex)
  13347. {
  13348. _sqlSugar.RollbackTran();
  13349. return Ok(JsonView(false, ex.Message));
  13350. }
  13351. }
  13352. #endregion
  13353. #region 团组经理模块 出入境费用 移动端(Android/IOS)
  13354. #region 城市区间交通费
  13355. /// <summary>
  13356. /// 团组模块 - 出入境费用 - 移动端 - 基础数据源(境外用车)
  13357. /// </summary>
  13358. /// <param name="groupId"></param>
  13359. /// <returns></returns>
  13360. [HttpGet("{groupId}")]
  13361. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13362. public async Task<IActionResult> EnterExitCostMobileOVByGroupId(int groupId)
  13363. {
  13364. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  13365. if (groupInfo == null)
  13366. {
  13367. return Ok(JsonView(false, "团组信息为空"));
  13368. }
  13369. var countryies = _groupRepository.GroupSplitCountry(groupInfo.VisitCountry);
  13370. if (countryies?.Any() != true)
  13371. {
  13372. return Ok(JsonView(false, "团组出访国家信息为空"));
  13373. }
  13374. var currencies = await GeneralMethod.EnterExitCostOVFeeUsedCurrencyAsync(groupId);
  13375. var currencyData = await _sqlSugar.Queryable<Sys_SetData>()
  13376. .Where(x => x.IsDel == 0 && x.STid == 66)
  13377. .ToListAsync();
  13378. var overseaVehicles = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  13379. .Where(x => x.IsDel == 0 && countryies.Contains(x.CountryName))
  13380. .ToListAsync();
  13381. var overseaVehicleIds = overseaVehicles.Select(x => x.Id).ToList();
  13382. //只返回接送机的数据
  13383. var overseaVehicleTypes = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  13384. .Where(x => x.IsDel == 0 && x.ServiceType == VehicleServiceTypeEnum.TransferService && overseaVehicleIds.Contains(x.OvId))
  13385. .ToListAsync();
  13386. var sysUers = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToListAsync();
  13387. var overseaVehicleCityDatas = new List<dynamic>() {
  13388. new
  13389. {
  13390. Id = 0,
  13391. area= "未选择",
  13392. CarTypeName = "",
  13393. serviceType = "",
  13394. Price = 0.00M,
  13395. guidePrice = 0.00M,
  13396. otherPrice = 0.00M,
  13397. currency = 0,
  13398. currencyName = "",
  13399. currRate = 1.0000M,
  13400. LastUpdateUserName = "",
  13401. LastUpdateTime = "",
  13402. Remark = ""
  13403. }};
  13404. foreach (var item in overseaVehicleTypes)
  13405. {
  13406. var parentInfo = overseaVehicles.FirstOrDefault(x => x.Id == item.OvId);
  13407. string area = string.Empty,
  13408. serviceType = "未设置",
  13409. currencyName = string.Empty;
  13410. decimal otherPrice = 0.00M;
  13411. if (parentInfo != null)
  13412. {
  13413. if (parentInfo.CountryName == parentInfo.CityName) area = parentInfo.CountryName;
  13414. else area = $"{parentInfo.CountryName}-{parentInfo.CityName}";
  13415. serviceType = item.ServiceType.GetDescription();
  13416. currencyName = currencyData.FirstOrDefault(x => x.Id == parentInfo.Currency)?.Name ?? "-";
  13417. otherPrice = parentInfo.OtherPrice1 + parentInfo.OtherPrice2;
  13418. }
  13419. //当前币种汇率值
  13420. var currRate = 1.0000M;
  13421. var currencyInfo = currencies.FirstOrDefault(x => x.CurrencyCode == currencyName);
  13422. if (currencyInfo != null) currRate = currencyInfo.Rate;
  13423. overseaVehicleCityDatas.add(new
  13424. {
  13425. item.Id,
  13426. area,
  13427. item.CarTypeName,
  13428. serviceType,
  13429. item.Price,
  13430. guidePrice = parentInfo?.GuidePrice ?? 0.00M,
  13431. otherPrice,
  13432. currency = parentInfo?.Currency ?? 0,
  13433. currencyName,
  13434. currRate,
  13435. LastUpdateUserName = sysUers.FirstOrDefault(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-",
  13436. item.LastUpdateTime,
  13437. item.Remark
  13438. });
  13439. }
  13440. var total = overseaVehicleCityDatas.Count;
  13441. var view = new
  13442. {
  13443. visitCountries = string.Join("、", countryies),
  13444. groupSize = groupInfo.VisitPNumber, //出访人数
  13445. defAirportTransferCoeff = Def_AirportTransferCoeff, //接送机默认报价系数
  13446. defServiceCount = Def_ServiceCount, //接送机默认服务次数
  13447. defTrainCoeff = Def_TrainCoeff, //火车默认报价系数
  13448. defPullCartCoeff = Def_PullCartCoeff, //拉车默认报价系数
  13449. defCityFlightCoeff = Def_CityFlightCoeff, //城市机票默认报价系数
  13450. Currencies = currencies,
  13451. data = overseaVehicleCityDatas
  13452. };
  13453. if (overseaVehicleCityDatas.Count == 0)
  13454. {
  13455. return Ok(JsonView(true, "暂无数据!", view));
  13456. }
  13457. return Ok(JsonView(true, "查询成功!", view, total));
  13458. }
  13459. /// <summary>
  13460. /// 团组模块 - 出入境费用 - 移动端 - 境外用车计算详细信息
  13461. /// </summary>
  13462. /// <param name="groupId"></param>
  13463. /// <param name="currUserId"></param>
  13464. /// <returns></returns>
  13465. [HttpGet("{groupId}")]
  13466. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13467. public async Task<IActionResult> EnterExitCostMobileOVFeeDetails(int groupId, int currUserId)
  13468. {
  13469. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  13470. if (groupInfo == null)
  13471. {
  13472. return Ok(JsonView(false, "团组信息为空"));
  13473. }
  13474. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).FirstAsync();
  13475. //CityIntervalInfo
  13476. var info = new CityIntervalInfo();
  13477. if (eecInfo != null && !string.IsNullOrEmpty(eecInfo.CityIntervalFeeDetails))
  13478. {
  13479. info = JsonConvert.DeserializeObject<CityIntervalInfo>(eecInfo.CityIntervalFeeDetails);
  13480. return Ok(JsonView(true, "查询成功!", info));
  13481. }
  13482. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == currUserId).FirstAsync();
  13483. var userName = userInfo?.CnName ?? "-";
  13484. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  13485. //返回默认数据
  13486. info = new CityIntervalInfo()
  13487. {
  13488. APTFeeDetails = new List<RoundTripTransferInfo>() { new() { No = 1, Coefficient = Def_AirportTransferCoeff, ServiceCount = Def_ServiceCount } },
  13489. PullCartFeeDetails = new List<PullCartInfo>() { new() { No = 1, Coefficient = Def_PullCartCoeff } },
  13490. TrainFeeDetails = new List<TrainInfo>() { new() { No = 1, Coefficient = Def_TrainCoeff } },
  13491. CityAirTicketFeeDetails = new List<CityAirTicketInfo>() { new() { No = 1, Coefficient = Def_CityFlightCoeff } },
  13492. LastUpdateUserName = userName,
  13493. LastUpdateTime = nowTime,
  13494. CreateUserName = userName,
  13495. Currencies = await GeneralMethod.EnterExitCostOVFeeUsedCurrencyAsync(groupId),
  13496. CreateTime = nowTime
  13497. };
  13498. return Ok(JsonView(true, "查询成功!", info));
  13499. }
  13500. /// <summary>
  13501. /// 团组模块 - 出入境费用 - 移动端 - 境外用车计算 保存
  13502. /// </summary>
  13503. /// <param name="dto"></param>
  13504. /// <returns></returns>
  13505. [HttpPost]
  13506. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13507. public async Task<IActionResult> EnterExitCostMobileOVFeeSave(GetEnterExitCostOVFeeSaveDto dto)
  13508. {
  13509. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == dto.GroupId).FirstAsync();
  13510. if (groupInfo == null)
  13511. {
  13512. return Ok(JsonView(false, "团组信息为空"));
  13513. }
  13514. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == dto.CurrUserId).FirstAsync();
  13515. if (userInfo == null)
  13516. {
  13517. return Ok(JsonView(false, "员工信息为空"));
  13518. }
  13519. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == dto.GroupId).FirstAsync();
  13520. if (eecInfo == null)
  13521. {
  13522. return Ok(JsonView(false, "出入境费用信息为空"));
  13523. }
  13524. var oldData = new CityIntervalInfo();
  13525. if (!string.IsNullOrEmpty(eecInfo.CityIntervalFeeDetails))
  13526. {
  13527. oldData = JsonConvert.DeserializeObject<CityIntervalInfo>(eecInfo.CityIntervalFeeDetails);
  13528. }
  13529. var userName = userInfo?.CnName ?? "-";
  13530. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  13531. var info = new CityIntervalInfo()
  13532. {
  13533. APTFeeTotal = dto.APTFeeTotal,
  13534. APTFeeDetails = dto.APTFeeDetails,
  13535. PullCartFeeTotal = dto.PullCartFeeTotal,
  13536. PullCartFeeDetails = dto.PullCartFeeDetails,
  13537. TrainFeeTotal = dto.TrainFeeTotal,
  13538. TrainFeeDetails = dto.TrainFeeDetails,
  13539. CityAirTicketFeeTotal = dto.CityAirTicketFeeTotal,
  13540. CityAirTicketFeeDetails = dto.CityAirTicketFeeDetails,
  13541. Currencies = dto.Currencies,
  13542. LastUpdateUserName = userName,
  13543. LastUpdateTime = nowTime,
  13544. CreateUserName = oldData?.CreateUserName ?? userName,
  13545. CreateTime = oldData?.CreateTime ?? nowTime
  13546. };
  13547. eecInfo.CityIntervalFeeDetails = JsonConvert.SerializeObject(info);
  13548. var upd = await _sqlSugar.Updateable<Grp_EnterExitCost>()
  13549. .SetColumns(it => it.CityIntervalFeeDetails == eecInfo.CityIntervalFeeDetails)
  13550. .SetColumns(it => it.LastUpdateUserId == dto.CurrUserId)
  13551. .SetColumns(it => it.LastUpdateTime == nowTime)
  13552. .Where(x => x.Id == eecInfo.Id)
  13553. .ExecuteCommandAsync();
  13554. if (upd < 1)
  13555. {
  13556. return Ok(JsonView(false));
  13557. }
  13558. //返回数据处理
  13559. var label = new StringBuilder();
  13560. //接送机
  13561. if (dto.APTFeeDetails?.Any() == true)
  13562. {
  13563. var ovIds = dto.APTFeeDetails.Select(x => x.OvId).ToList();
  13564. var areas = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  13565. .LeftJoin<Res_OverseaVehicle>((ovtp, ov) => ovtp.OvId == ov.Id)
  13566. .Where((ovtp, ov) => ovtp.IsDel == 0 && ovIds.Contains(ovtp.Id))
  13567. .Select((ovtp, ov) => new
  13568. {
  13569. ovtp.Id,
  13570. ov.CountryName,
  13571. ov.CityName
  13572. }).ToListAsync();
  13573. var items = dto.APTFeeDetails
  13574. .Select(item =>
  13575. {
  13576. var areaInfo = areas.FirstOrDefault(x => x.Id == item.OvId);
  13577. if (areaInfo == null) return null;
  13578. return areaInfo.CountryName == areaInfo.CityName
  13579. ? $"{areaInfo.CountryName}({item.Quote:#0.00} CNY)"
  13580. : $"{areaInfo.CountryName}-{areaInfo.CityName}({item.Quote:#0.00} CNY)";
  13581. })
  13582. .Where(item => item != null)
  13583. .ToList();
  13584. label.AppendLine($"接送机({string.Join("、", items)});");
  13585. }
  13586. //拉车
  13587. if (dto.PullCartFeeDetails?.Any() == true)
  13588. {
  13589. var feeLabel = string.Join("、",
  13590. dto.PullCartFeeDetails.Select(x =>
  13591. $"{x.Quote:#0.00} CNY"
  13592. ));
  13593. label.AppendLine($"拉车({feeLabel});");
  13594. }
  13595. //火车
  13596. if (dto.TrainFeeDetails?.Any() == true)
  13597. {
  13598. var feeLabel = string.Join("、",
  13599. dto.TrainFeeDetails.Select(x =>
  13600. $"{x.Quote:#0.00} CNY"
  13601. ));
  13602. label.AppendLine($"火车票({feeLabel});");
  13603. }
  13604. //城市机票
  13605. if (dto.CityAirTicketFeeDetails?.Any() == true)
  13606. {
  13607. var feeLabel = string.Join("、",
  13608. dto.CityAirTicketFeeDetails.Select(x =>
  13609. $"{x.Quote:#0.00} CNY"
  13610. ));
  13611. label.AppendLine($"城市机票({feeLabel});");
  13612. }
  13613. //费用
  13614. decimal quote = (dto.APTFeeTotal + dto.PullCartFeeTotal + dto.TrainFeeTotal + dto.CityAirTicketFeeTotal).ConvertToDecimal1();
  13615. decimal jjcQuote = quote;
  13616. decimal gwcQuote = quote;
  13617. decimal tdcQuote = quote;
  13618. var view = new
  13619. {
  13620. label = label.ToString(),
  13621. jjcQuote,
  13622. gwcQuote,
  13623. tdcQuote
  13624. };
  13625. return Ok(JsonView(view));
  13626. }
  13627. #endregion
  13628. /// <summary>
  13629. /// 获取币种基础数据(含逻辑处理)
  13630. /// </summary>
  13631. /// <returns></returns>
  13632. private async Task<List<CurrencyInfo>> EnterExitCostMobileGetCurrencyInit()
  13633. {
  13634. return await GeneralMethod.EnterExitCostInitRate();
  13635. }
  13636. /// <summary>
  13637. /// 团组模块 - 出入境费用-移动端 - 基础数据源(Word明细类型、Excel明细类型、默认币种显示)
  13638. /// </summary>
  13639. /// <returns></returns>
  13640. [HttpPost]
  13641. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13642. public async Task<IActionResult> EnterExitCostMobileDataSource(EnterExitCostMobileDataSourceDto dto)
  13643. {
  13644. //验证城市归属并给默认值
  13645. int provinceId = dto.ProvinceId;
  13646. if (provinceId < 1) provinceId = 122;
  13647. var dataSource = await _sqlSugar
  13648. .Queryable<Sys_SetData>()
  13649. .Where(x => x.IsDel == 0 && (x.STid == 72 || x.STid == 73) && x.Remark.Contains(provinceId.ToString()))
  13650. .ToListAsync();
  13651. var fileTypes = new List<EecSetDataInfoView>();
  13652. //三公费用-Word明细类型
  13653. var wordTypeData = dataSource
  13654. .Where(it => it.STid == 72)
  13655. .Select(x => new EecSetDataInfoView
  13656. {
  13657. ParentId = 1,
  13658. Id = x.Id,
  13659. Name = x.Name
  13660. })
  13661. .ToArray();
  13662. if (wordTypeData.Any()) fileTypes.AddRange(wordTypeData);
  13663. var excelTypeData = dataSource
  13664. .Where(it => it.STid == 73)
  13665. .Select(x => new EecSetDataInfoView
  13666. {
  13667. ParentId = 2,
  13668. Id = x.Id,
  13669. Name = x.Name
  13670. })
  13671. .ToArray();
  13672. if (excelTypeData.Any()) fileTypes.AddRange(excelTypeData);
  13673. var groupNameList = new EecSetDataInfoView() { ParentId = 3, Id = 1, Name = "团组成员名单" };
  13674. fileTypes.Add(groupNameList);
  13675. fileTypes = fileTypes.OrderBy(x => x.ParentId).ThenBy(x => x.Id).ToList();
  13676. //默认币种显示
  13677. var _currencyInfos = await EnterExitCostMobileGetCurrencyInit();
  13678. var viewPermissionData = await _enterExitCostRep.PermissionViewUsersAsync();
  13679. return Ok(JsonView(true, "查询成功!", new
  13680. {
  13681. FileTypeData = fileTypes,
  13682. CurrencyInit = _currencyInfos,
  13683. viewPermissionData = viewPermissionData
  13684. }));
  13685. }
  13686. /// <summary>
  13687. /// 团组模块 - 出入境费用-移动端 - 团组基础数据Data
  13688. /// </summary>
  13689. /// <returns></returns>
  13690. [HttpPost]
  13691. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13692. public async Task<IActionResult> EnterExitCostMobileGroupData(PostEnterExitCostMobileGroupDataDto dto)
  13693. {
  13694. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  13695. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  13696. RefAsync<int> total = 0;
  13697. int diId = 0;
  13698. var status = int.TryParse(dto.GroupName, out diId);
  13699. var basicUserId = await _enterExitCostRep.PermissionViewUsersAsync();
  13700. var data = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  13701. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.TeamName))
  13702. .WhereIF(!string.IsNullOrEmpty(dto.GroupName) && diId > 0, x => x.Id == diId)
  13703. .WhereIF(!string.IsNullOrEmpty(dto.GroupName) && !status, x => x.TeamName.Contains(dto.GroupName))
  13704. .OrderByDescending(x => x.VisitStartDate)
  13705. .Select(x => new EnterExitCostMobileGroupView()
  13706. {
  13707. Id = x.Id,
  13708. GroupName = x.TeamName,
  13709. IsNull = SqlFunc.Subqueryable<Grp_EnterExitCost>().Where(x1 => x1.DiId == x.Id && x1.IsDel == 0).Any() ? false : true,
  13710. IsView = SqlFunc.Subqueryable<Grp_EnterExitCostPermission>().Where(x1 => x1.GroupId == x.Id && x1.UserId == dto.CurrUserId).Any(),
  13711. ProvinceId = x.CityId
  13712. })
  13713. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  13714. //处理省份Id
  13715. if (data.Any())
  13716. {
  13717. var provCityDatas = await _groupRepository.ProvinceCityBasicSource();
  13718. if (provCityDatas.Any())
  13719. {
  13720. foreach (var item in data)
  13721. {
  13722. var provinceId = item.ProvinceId;
  13723. var isDefualtVal = true;
  13724. if (provinceId > 0)
  13725. {
  13726. var parentId = _groupRepository.FindParentIdByChildId(provCityDatas, provinceId);
  13727. if (parentId != null)
  13728. {
  13729. isDefualtVal = false;
  13730. item.ProvinceId = (int)parentId;
  13731. }
  13732. }
  13733. if (isDefualtVal)
  13734. {
  13735. item.ProvinceId = 122; //默认四川
  13736. }
  13737. }
  13738. }
  13739. }
  13740. //处理是否显示
  13741. if (basicUserId.Any(x => x.Id == dto.CurrUserId))
  13742. {
  13743. foreach (var item in data)
  13744. {
  13745. item.IsView = true;
  13746. }
  13747. }
  13748. return Ok(JsonView(true, "查询成功!", data, total));
  13749. }
  13750. /// <summary>
  13751. /// 团组模块 - 出入境费用-移动端 - 币种基础数据Data
  13752. /// </summary>
  13753. /// <returns></returns>
  13754. [HttpPost]
  13755. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13756. public async Task<IActionResult> EnterExitCostMobileCurrencyData(PostEnterExitCostMobileCurrencyDataDto dto)
  13757. {
  13758. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  13759. RefAsync<int> total = 0;
  13760. var data = await _sqlSugar.Queryable<Sys_SetData>()
  13761. .Where(x => x.IsDel == 0 && x.STid == 66)
  13762. .WhereIF(!string.IsNullOrEmpty(dto.CurrencyName), x => x.Name.ToLower().Contains(dto.CurrencyName) || x.Remark.Contains(dto.CurrencyName))
  13763. .Select(x => new
  13764. {
  13765. id = x.Id,
  13766. name = x.Name,
  13767. remark = x.Remark,
  13768. })
  13769. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  13770. return Ok(JsonView(true, "查询成功!", data, total));
  13771. }
  13772. /// <summary>
  13773. /// 团组模块 - 出入境费用-移动端 - 其他款项 - 币种、费用类型基础数据Data
  13774. /// </summary>
  13775. /// <returns></returns>
  13776. [HttpPost]
  13777. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13778. public async Task<IActionResult> EnterExitCostMobileOtherItemCurrencyData(PostEnterExitCostMobileOtherItemCurrencyDataDto dto)
  13779. {
  13780. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  13781. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  13782. var groupRateData = await GeneralMethod.PostGroupTeamRateByDiIdAndCTableId(dto.PortType, dto.DiId, 98);
  13783. if (groupRateData == null) return Ok(JsonView(false, "请填写“团组汇率-->其他款项”汇率!"));
  13784. var groupOtherRateData = groupRateData.TeamRates;
  13785. var enterExitCostInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().FirstAsync(it => it.DiId == dto.DiId && it.IsDel == 0);
  13786. if (enterExitCostInfo == null) return Ok(JsonView(groupOtherRateData));
  13787. var eecRateData = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(enterExitCostInfo.CurrencyRemark);
  13788. groupOtherRateData = groupOtherRateData
  13789. .Select(x => new TeamRateDescAddCurrencyIdView
  13790. {
  13791. CurrencyId = x.CurrencyId,
  13792. CurrencyName = x.CurrencyName,
  13793. CurrencyCode = x.CurrencyCode,
  13794. Rate = eecRateData.Find(it => it.CurrencyCode.ToUpper().Equals(x.CurrencyCode.ToUpper()))?.Rate ?? x.Rate
  13795. }).ToList();
  13796. var otherFeeTypeData = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 92).Select(x => new { x.Id, x.Name }).ToListAsync();
  13797. return Ok(JsonView(true, "查询成功!", new { groupOtherRateData = groupOtherRateData, otherFeeTypeData = otherFeeTypeData }));
  13798. }
  13799. /// <summary>
  13800. /// 团组模块 - 出入境费用-移动端 - 实时汇率、签证费用、机票费用 Tips
  13801. /// </summary>
  13802. /// <returns></returns>
  13803. [HttpPost]
  13804. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13805. public async Task<IActionResult> EnterExitCostMobileFeeTips(GetEnterExitCostMobileFeeTipsDto dto)
  13806. {
  13807. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  13808. if (dto.GroupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  13809. var tipsData = new List<int>() { 1, 2, 3 };
  13810. if (!tipsData.Contains(dto.TipsType)) return Ok(JsonView(false, $"请传入有效的TipsType参数;1 实时汇率;2 签证费用;3 机票费用;"));
  13811. if (dto.TipsType == 1)
  13812. {
  13813. return Ok(JsonView(true, "查询成功!", await GeneralMethod.EnterExitCostLiveRate()));
  13814. }
  13815. else if (dto.TipsType == 2)
  13816. {
  13817. var visaData = await _visaFeeInfoRep.EnterExitCostVisaTips(dto.GroupId);
  13818. return Ok(JsonView(true, "查询成功!", visaData.Data));
  13819. }
  13820. else if (dto.TipsType == 3)
  13821. {
  13822. var airData = await GeneralMethod.EntryAndExitTips(dto.GroupId);
  13823. return Ok(JsonView(true, "查询成功!", airData));
  13824. }
  13825. return Ok(JsonView(false));
  13826. }
  13827. /// <summary>
  13828. /// 团组模块 - 出入境国家费用标准-移动端 List
  13829. /// </summary>
  13830. /// <returns></returns>
  13831. [HttpPost]
  13832. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13833. public async Task<IActionResult> NationalTravelFeeMobileData(PostNationalTravelFeeMobileDataDto dto)
  13834. {
  13835. Stopwatch sw = new Stopwatch();
  13836. sw.Start();
  13837. int provinceId = dto.ProvinceId;
  13838. if (provinceId < 1) provinceId = 122; // 默认四川
  13839. RefAsync<int> total = 0;
  13840. var data = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  13841. .LeftJoin<Sys_SetData>((ntf, sd) => ntf.Currency == sd.Id)
  13842. .LeftJoin<Sys_Users>((ntf, sd, u) => ntf.CreateUserId == u.Id)
  13843. .LeftJoin<Sys_Cities>((ntf, sd, u, sd1) => ntf.ProvinceId == sd1.Id)
  13844. .Where((ntf, sd, u, sd1) => ntf.IsDel == 0 && ntf.ProvinceId == provinceId)
  13845. .WhereIF(!string.IsNullOrEmpty(dto.Search), (ntf, sd, u, sd1) => dto.Search.Contains(ntf.Country) || dto.Search.Contains(ntf.City))
  13846. .Select((ntf, sd, u, sd1) => new
  13847. {
  13848. Id = ntf.Id,
  13849. Area = $"{ntf.Country}-{ntf.City}",
  13850. Currency = ntf.Currency,
  13851. CurrencyCode = sd.Name,
  13852. CurrencyName = sd.Remark,
  13853. RoomCost = ntf.RoomCost,
  13854. FoodCost = ntf.FoodCost,
  13855. PublicCost = ntf.PublicCost,
  13856. TrainCost = ntf.TrainCost,
  13857. LastUpdateUserId = ntf.LastUpdateUserId,
  13858. LastUpdateUserName = u.CnName,
  13859. LastUpdateTime = ntf.LastUpdateTime
  13860. })
  13861. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  13862. sw.Stop();
  13863. return Ok(JsonView(true, "查询成功!耗时:" + sw.ElapsedMilliseconds + "ms", data, total));
  13864. }
  13865. /// <summary>
  13866. /// 团组模块 - 出入境费用-移动端 - Info
  13867. /// </summary>
  13868. /// <returns></returns>
  13869. [HttpPost]
  13870. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13871. public async Task<IActionResult> EnterExitCostMobileInfo(EnterExitCostInfobyDiIdDto dto)
  13872. {
  13873. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  13874. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  13875. var data = await _enterExitCostRep.GetEnterExitCostInfoByDiId(dto);
  13876. return Ok(data);
  13877. }
  13878. /// <summary>
  13879. /// 团组模块 - 出入境费用-移动端 - ParentInfo
  13880. /// </summary>
  13881. /// <returns></returns>
  13882. [HttpPost]
  13883. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13884. public async Task<IActionResult> EnterExitCostMobileParentInfo(EnterExitCostInfobyDiIdDto dto)
  13885. {
  13886. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  13887. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  13888. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  13889. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.DiId == dto.DiId && it.IsDel == 0);
  13890. var mobileInfo = new EnterExitCostMobileParentInfoView();
  13891. mobileInfo.DiId = dto.DiId;
  13892. mobileInfo.Currencys = await EnterExitCostMobileGetCurrencyInit();
  13893. if (eecInfo == null) return Ok(mobileInfo);
  13894. //验证查看权限
  13895. (bool isView, bool isSet) = await _enterExitCostRep.PermissionValidationAsync(dto.DiId, dto.CurrUserId);
  13896. if (!isView) return Ok(JsonView(false, "没有查看权限!"));
  13897. mobileInfo = _mapper.Map<EnterExitCostMobileParentInfoView>(eecInfo);
  13898. mobileInfo.IsAssignPerm = isSet;
  13899. var dayAndCostData = _sqlSugar.Queryable<Grp_DayAndCost>()
  13900. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  13901. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  13902. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId)
  13903. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  13904. {
  13905. SubId = dac.Id,
  13906. DiId = dac.DiId,
  13907. Type = dac.Type,
  13908. Days = dac.Days,
  13909. NationalTravelFeeId = dac.NationalTravelFeeId,
  13910. Arae = $"{ntf.Country}-{ntf.City}",
  13911. Cost = dac.Cost,
  13912. Currency = dac.Currency,
  13913. CurrencyName = sd.Name,
  13914. SubTotal = dac.SubTotal,
  13915. })
  13916. .ToList();
  13917. mobileInfo.ChoiceOneTotalCost = eecInfo.InsidePay;
  13918. mobileInfo.ChoiceTwoJJ = eecInfo.SumJJC;
  13919. mobileInfo.ChoiceTwoGW = eecInfo.SumGWC;
  13920. mobileInfo.ChoiceTwoTD = eecInfo.SumTDC;
  13921. mobileInfo.Currencys = !string.IsNullOrEmpty(eecInfo.CurrencyRemark) ? CommonFun.GetCurrencyChinaToList(eecInfo.CurrencyRemark) : mobileInfo.Currencys;
  13922. mobileInfo.ChoiceThreeTotalCost = dayAndCostData.Where(it => it.Type == 1).Sum(x => x.SubTotal); //住宿费 1
  13923. mobileInfo.ChoiceFourTotalCost = dayAndCostData.Where(it => it.Type == 2).Sum(x => x.SubTotal); //伙食费 2
  13924. mobileInfo.ChoiceFiveTotalCost = dayAndCostData.Where(it => it.Type == 3).Sum(x => x.SubTotal); //公杂费 3
  13925. mobileInfo.ChoiceSixTotalCost = dayAndCostData.Where(it => it.Type == 4).Sum(x => x.SubTotal); //培训费 4
  13926. //其他款项
  13927. var otherData = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  13928. .LeftJoin<Sys_SetData>((dop, sd1) => dop.SetDataId == sd1.Id)
  13929. .LeftJoin<Sys_SetData>((dop, sd1, sd2) => dop.Currency == sd2.Id)
  13930. .Where((dop, sd1, sd2) => dop.IsDel == 0 && dop.Diid == dto.DiId)
  13931. .OrderBy((dop, sd1, sd2) => dop.Index)
  13932. .Select((dop, sd1, sd2) => new DayOtherPriceMobileInfoView
  13933. {
  13934. SubId = dop.Id,
  13935. DiId = dop.Diid,
  13936. Index = dop.Index,
  13937. SetDataId = dop.SetDataId,
  13938. SetDataName = sd1.Name,
  13939. Cost = dop.Cost,
  13940. Currency = dop.Currency,
  13941. CurrencyName = sd2.Remark,
  13942. SubTotal = dop.SubTotal,
  13943. Remark = dop.Remark,
  13944. })
  13945. .ToArray();
  13946. mobileInfo.OtherExpensesTotalCost = otherData.Sum(x => x.SubTotal);
  13947. return Ok(mobileInfo);
  13948. }
  13949. /// <summary>
  13950. /// 团组模块 - 出入境费用-移动端 - 查看权限用户
  13951. /// </summary>
  13952. /// <returns></returns>
  13953. [HttpPost]
  13954. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13955. public async Task<IActionResult> EnterExitCostMobileViewPermissionUsers(EnterExitCostMobileViewPermissionUsersDto dto)
  13956. {
  13957. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  13958. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  13959. //验证查看权限
  13960. (bool viewPerm, bool assignPerm) = await _enterExitCostRep.PermissionValidationAsync(dto.DiId, dto.CurrUserId);//分配权限
  13961. if (!viewPerm) return Ok(JsonView(false, "未分配查看权限,如要查看,请联系市场部或国交部负责人!"));
  13962. var userIds = await _sqlSugar
  13963. .Queryable<Grp_EnterExitCostPermission>()
  13964. .Where(x => x.IsDel == 0 && x.GroupId == dto.DiId)
  13965. .Select(x => x.UserId)
  13966. .ToArrayAsync();
  13967. var perUsers = await _enterExitCostRep.PermissionViewUsersAsync();
  13968. var perUsersView = new List<dynamic>();
  13969. foreach (var item in perUsers)
  13970. {
  13971. bool isView1 = false;
  13972. if (userIds.Any(x => x == item.Id)) isView1 = true;
  13973. perUsersView.Add(new { Id = item.Id, Name = item.Name, IsView = isView1 });
  13974. }
  13975. return Ok(JsonView(perUsersView));
  13976. }
  13977. /// <summary>
  13978. /// 团组模块 - 出入境费用-移动端 - SubInfo
  13979. /// </summary>
  13980. /// <returns></returns>
  13981. [HttpPost]
  13982. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13983. public async Task<IActionResult> EnterExitCostMobileSubInfo(PostEnterExitCostMobileSubInfoDto dto)
  13984. {
  13985. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  13986. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  13987. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  13988. var subTypes = new List<int>() { 1, 2, 3, 4, 5, 6, 7 };
  13989. if (!subTypes.Contains(dto.SubType)) return Ok(JsonView(false, $"请传入有效的subTypeId!"));
  13990. //验证查看权限
  13991. //(bool isView, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId);
  13992. //if (!isView) return Ok(JsonView(false, msg));
  13993. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.DiId == dto.DiId && it.IsDel == 0);
  13994. if (eecInfo == null) return Ok(JsonView(false, $"出入境费用明细未录入!"));
  13995. var subType = dto.SubType;
  13996. if (subType == 1) //1:境内费用
  13997. {
  13998. var oneData = new ChoiceOneMobileSubInfoView()
  13999. {
  14000. Id = eecInfo.Id,
  14001. ChoiceOne = eecInfo.ChoiceOne,
  14002. ChoiceOneTotalCost = eecInfo.InsidePay,
  14003. Visa = eecInfo.Visa,
  14004. VisaRemark = eecInfo.VisaRemark,
  14005. YiMiao = eecInfo.YiMiao,
  14006. HeSuan = eecInfo.HeSuan,
  14007. Service = eecInfo.Service,
  14008. Ticket = eecInfo.Ticket,
  14009. Safe = eecInfo.Safe,
  14010. FirstItemRemark = eecInfo.FirstItemRemark
  14011. };
  14012. return Ok(JsonView(oneData));
  14013. }
  14014. else if (subType == 2) //2:国际旅费
  14015. {
  14016. var twoData = new ChoiceTwoMobileSubInfoView()
  14017. {
  14018. Id = eecInfo.Id,
  14019. ChoiceTwoJJ = eecInfo.SumJJC,
  14020. OutsideJJPay = eecInfo.OutsideJJPay,
  14021. ChoiceTwoGW = eecInfo.SumGWC,
  14022. OutsideGWPay = eecInfo.OutsideGWPay,
  14023. ChoiceTwoTD = eecInfo.SumTDC,
  14024. OutsideTDPay = eecInfo.OutsideTDPay,
  14025. AirJJ = eecInfo.AirJJ,
  14026. AirGW = eecInfo.AirGW,
  14027. AirTD = eecInfo.AirTD,
  14028. CityTranffic = eecInfo.CityTranffic,
  14029. CityTranffic1 = eecInfo.CityTranffic1,
  14030. CityTranffic2 = eecInfo.CityTranffic2,
  14031. TwoItemRemark = eecInfo.TwoItemRemark
  14032. };
  14033. return Ok(JsonView(twoData));
  14034. }
  14035. else if (subType == 3) //3:住宿费
  14036. {
  14037. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCost>()
  14038. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  14039. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  14040. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId && dac.Type == 1)
  14041. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  14042. {
  14043. SubId = dac.Id,
  14044. DiId = dac.DiId,
  14045. Type = dac.Type,
  14046. Days = dac.Days,
  14047. NationalTravelFeeId = dac.NationalTravelFeeId,
  14048. Arae = $"{ntf.Country}-{ntf.City}",
  14049. Cost = dac.Cost,
  14050. Currency = dac.Currency,
  14051. CurrencyName = sd.Name,
  14052. SubTotal = dac.SubTotal,
  14053. })
  14054. .ToArray();
  14055. var data = new ChoiceMobileSubInfo3To6View()
  14056. {
  14057. ParentId = eecInfo.Id,
  14058. Choice = eecInfo.ChoiceThree,
  14059. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  14060. Details = dayAndCostDatas
  14061. };
  14062. return Ok(JsonView(data));
  14063. }
  14064. else if (subType == 4) //4:伙食费
  14065. {
  14066. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCost>()
  14067. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  14068. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  14069. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId && dac.Type == 2)
  14070. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  14071. {
  14072. SubId = dac.Id,
  14073. DiId = dac.DiId,
  14074. Type = dac.Type,
  14075. Days = dac.Days,
  14076. NationalTravelFeeId = dac.NationalTravelFeeId,
  14077. Arae = $"{ntf.Country}-{ntf.City}",
  14078. Cost = dac.Cost,
  14079. Currency = dac.Currency,
  14080. CurrencyName = sd.Name,
  14081. SubTotal = dac.SubTotal,
  14082. })
  14083. .ToArray();
  14084. var data = new ChoiceMobileSubInfo3To6View()
  14085. {
  14086. ParentId = eecInfo.Id,
  14087. Choice = eecInfo.ChoiceFour,
  14088. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  14089. Details = dayAndCostDatas
  14090. };
  14091. return Ok(JsonView(data));
  14092. }
  14093. else if (subType == 5) //5:公杂费
  14094. {
  14095. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCost>()
  14096. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  14097. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  14098. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId && dac.Type == 3)
  14099. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  14100. {
  14101. SubId = dac.Id,
  14102. DiId = dac.DiId,
  14103. Type = dac.Type,
  14104. Days = dac.Days,
  14105. NationalTravelFeeId = dac.NationalTravelFeeId,
  14106. Arae = $"{ntf.Country}-{ntf.City}",
  14107. Cost = dac.Cost,
  14108. Currency = dac.Currency,
  14109. CurrencyName = sd.Name,
  14110. SubTotal = dac.SubTotal,
  14111. })
  14112. .ToArray();
  14113. var data = new ChoiceMobileSubInfo3To6View()
  14114. {
  14115. ParentId = eecInfo.Id,
  14116. Choice = eecInfo.ChoiceFive,
  14117. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  14118. Details = dayAndCostDatas
  14119. };
  14120. return Ok(JsonView(data));
  14121. }
  14122. else if (subType == 6) //6:培训费
  14123. {
  14124. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCost>()
  14125. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  14126. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  14127. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId && dac.Type == 4)
  14128. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  14129. {
  14130. SubId = dac.Id,
  14131. DiId = dac.DiId,
  14132. Type = dac.Type,
  14133. Days = dac.Days,
  14134. NationalTravelFeeId = dac.NationalTravelFeeId,
  14135. Arae = $"{ntf.Country}-{ntf.City}",
  14136. Cost = dac.Cost,
  14137. Currency = dac.Currency,
  14138. CurrencyName = sd.Name,
  14139. SubTotal = dac.SubTotal,
  14140. })
  14141. .ToArray();
  14142. var data = new ChoiceMobileSubInfo3To6View()
  14143. {
  14144. ParentId = eecInfo.Id,
  14145. Choice = eecInfo.ChoiceSix,
  14146. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  14147. Details = dayAndCostDatas
  14148. };
  14149. return Ok(JsonView(data));
  14150. }
  14151. else if (subType == 7) //7:其他
  14152. {
  14153. //其他款项
  14154. var otherData = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  14155. .LeftJoin<Sys_SetData>((dop, sd1) => dop.SetDataId == sd1.Id)
  14156. .LeftJoin<Sys_SetData>((dop, sd1, sd2) => dop.Currency == sd2.Id)
  14157. .Where((dop, sd1, sd2) => dop.IsDel == 0 && dop.Diid == dto.DiId)
  14158. .OrderBy((dop, sd1, sd2) => dop.Index)
  14159. .Select((dop, sd1, sd2) => new DayOtherPriceMobileInfoView
  14160. {
  14161. SubId = dop.Id,
  14162. DiId = dop.Diid,
  14163. Index = dop.Index,
  14164. SetDataId = dop.SetDataId,
  14165. SetDataName = sd1.Name,
  14166. Cost = dop.Cost,
  14167. Currency = dop.Currency,
  14168. CurrencyName = sd2.Name,
  14169. SubTotal = dop.SubTotal,
  14170. Remark = dop.Remark,
  14171. })
  14172. .ToArray();
  14173. var data = new ChoiceSevenMobileSubInfoView()
  14174. {
  14175. ParentId = eecInfo.Id,
  14176. OtherExpenses_Checked = eecInfo.OtherExpenses_Checked,
  14177. OtherExpensesTotalCost = otherData.Sum(x => x.SubTotal),
  14178. Details = otherData
  14179. };
  14180. return Ok(JsonView(data));
  14181. }
  14182. return Ok(JsonView(false));
  14183. }
  14184. #region op
  14185. ///// <summary>
  14186. ///// 移动端更新费用消息通知
  14187. ///// </summary>
  14188. ///// <param name="diid"></param>
  14189. ///// <param name="id"></param>
  14190. ///// <param name="currUserId"></param>
  14191. //private async Task EnterExitCostMobileOpNotice(int diid, int id, int currUserId)
  14192. //{
  14193. // try
  14194. // {
  14195. // ////生成默认文件pdf并且通知人员
  14196. // //var fileView = await GeneralMethod.EnterExitCostDownload(new EnterExitCostDownloadDto()
  14197. // //{
  14198. // // DiId = diid,
  14199. // // ExportType = 1,
  14200. // // SubTypeId = 1005
  14201. // //}, "pdf");
  14202. // ////发送通知
  14203. // //string fileUrl = (string)fileView.Data.GetType().GetProperty("Url").GetValue(fileView.Data, null);
  14204. // //string md5Sign = GeneralMethod.Encrypt($"{id}&fileName={fileUrl}");
  14205. // //string url = string.Format("http://oa.pan-american-intl.com:4399/#/Sankunginfo?sign={0}&fileName={1}", id, fileUrl);
  14206. // //await AppNoticeLibrary.SendUserMsg_GroupShare_ToGM(diid, new List<string>() { "208", "233", "21" }, currUserId, url);
  14207. // ////汇率信息记录
  14208. // //await GeneralMethod.RateRecordSave(currUserId, id, "出入境费用");
  14209. // }
  14210. // catch (Exception ex)
  14211. // {
  14212. // //记录日志
  14213. // throw;
  14214. // }
  14215. //}
  14216. /// <summary>
  14217. /// 验证出入境费用数据是否存在
  14218. /// 不存在添加
  14219. /// </summary>
  14220. /// <param name="diId"></param>
  14221. /// <param name="currUserId"></param>
  14222. /// <returns></returns>
  14223. /// <exception cref="CustomException"></exception>
  14224. private async Task<int> EnterExitCostVerifyIsNull(int diId, int currUserId)
  14225. {
  14226. var parentId = 0;
  14227. var info = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == diId).OrderByDescending(x => x.CreateTime).FirstAsync();
  14228. if (info != null)
  14229. {
  14230. parentId = info.Id;
  14231. }
  14232. else
  14233. {
  14234. var currencys = await EnterExitCostMobileGetCurrencyInit();
  14235. int addId = await _sqlSugar.Insertable(new Grp_EnterExitCost() { DiId = diId, CreateUserId = currUserId, CurrencyRemark = JsonConvert.SerializeObject(currencys) }).ExecuteReturnIdentityAsync();
  14236. if (addId < 1) throw new CustomException("出入境费用添加失败!");
  14237. parentId = addId;
  14238. }
  14239. return parentId;
  14240. }
  14241. /// <summary>
  14242. /// 团组模块 - 出入境费用-移动端 - 设置view权限
  14243. /// </summary>
  14244. /// <returns></returns>
  14245. [HttpPost]
  14246. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14247. public async Task<IActionResult> EnterExitCostMobileSetViewPermissiion(EnterExitCostMobileSetViewPermissiionDto dto)
  14248. {
  14249. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14250. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14251. if (dto.UserIds.Length < 1) return Ok(JsonView(false, "请传入有效的userId;"));
  14252. //验证编辑权限
  14253. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  14254. //if (!isEdit) return Ok(JsonView(false, msg));
  14255. var permissions = new List<Grp_EnterExitCostPermission>();
  14256. foreach (var userId in dto.UserIds)
  14257. {
  14258. permissions.Add(new Grp_EnterExitCostPermission { Permission = 1, GroupId = dto.DiId, UserId = userId, CreateUserId = dto.CurrUserId });
  14259. }
  14260. if (permissions.Any())
  14261. {
  14262. if (!permissions.Any(x => x.UserId == dto.CurrUserId))
  14263. {
  14264. permissions.Add(new Grp_EnterExitCostPermission { Permission = 1, GroupId = dto.DiId, UserId = dto.CurrUserId, CreateUserId = dto.CurrUserId });
  14265. }
  14266. _sqlSugar.BeginTran();
  14267. await _sqlSugar.Deleteable<Grp_EnterExitCostPermission>().Where(it => it.GroupId == dto.DiId).ExecuteCommandAsync();
  14268. var result = await _sqlSugar.Insertable(permissions).ExecuteCommandAsync();
  14269. if (result < 1)
  14270. {
  14271. _sqlSugar.RollbackTran();
  14272. return Ok(JsonView(false));
  14273. }
  14274. _sqlSugar.CommitTran();
  14275. return Ok(JsonView(true));
  14276. }
  14277. return Ok(JsonView(false));
  14278. }
  14279. /// <summary>
  14280. /// 团组模块 - 出入境费用-移动端 - OP --> 汇率
  14281. /// </summary>
  14282. /// <returns></returns>
  14283. [HttpPost]
  14284. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14285. public async Task<IActionResult> EnterExitCostMobileOpRate(PostEnterExitCostMobileFeeRateOpDto dto)
  14286. {
  14287. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14288. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14289. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14290. if (dto.Currencys.Length < 1) return Ok(JsonView(false, "请传入有效的汇率信息!"));
  14291. var currencyStr = CommonFun.GetCurrencyChinaToString(dto.Currencys.ToList());
  14292. int id = dto.Id;
  14293. if (id <= 0) //add
  14294. {
  14295. //int provinceId = dto.ProvinceId;
  14296. int groupId = dto.DiId;
  14297. //if (provinceId < 1) provinceId = 122;
  14298. var info = new Grp_EnterExitCost() { DiId = groupId, CurrencyRemark = currencyStr, CreateUserId = dto.CurrUserId };
  14299. info.LastUpdateUserId = dto.CurrUserId;
  14300. info.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  14301. var add = await _sqlSugar.Insertable(info).ExecuteCommandAsync();
  14302. if (add < 1) return Ok(JsonView(false));
  14303. id = add;
  14304. }
  14305. else //update
  14306. {
  14307. ////验证编辑权限
  14308. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  14309. //if (!isEdit) return Ok(JsonView(false, msg));
  14310. var upd = await _sqlSugar.Updateable<Grp_EnterExitCost>().SetColumns(x => new Grp_EnterExitCost()
  14311. {
  14312. CurrencyRemark = currencyStr,
  14313. LastUpdateUserId = dto.CurrUserId,
  14314. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  14315. }).Where(x => x.Id == dto.Id).ExecuteCommandAsync();
  14316. if (upd < 1) return Ok(JsonView(false));
  14317. }
  14318. #region 汇率变更时更改币种相关费用
  14319. var opDayCosts = new List<Grp_DayAndCost>();
  14320. var opDayOtherCosts = new List<Grp_DayOtherPrice>();
  14321. var eecCurrencys = dto.Currencys.Select(x => x.CurrencyCode.ToUpper()).ToList();
  14322. var dayCosts = _sqlSugar.Queryable<Grp_DayAndCost>()
  14323. .LeftJoin<Sys_SetData>((dac, sd) => dac.Currency == sd.Id)
  14324. .Where((dac, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId)
  14325. .Select((dac, sd) => new
  14326. {
  14327. dac.Id,
  14328. dac.DiId,
  14329. CurrencyCode = sd.Name,
  14330. dac.Cost
  14331. })
  14332. .ToList();
  14333. var dayOtherCosts = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  14334. .LeftJoin<Sys_SetData>((dop, sd) => dop.Currency == sd.Id)
  14335. .Where((dop, sd) => dop.IsDel == 0 && dop.Diid == dto.DiId)
  14336. .Select((dop, sd) => new
  14337. {
  14338. dop.Id,
  14339. dop.Diid,
  14340. CurrencyCode = sd.Name,
  14341. dop.Cost
  14342. })
  14343. .ToList();
  14344. if (dayCosts.Count > 0)
  14345. {
  14346. var new_dayCosts = dayCosts.Where(x => eecCurrencys.Contains(x.CurrencyCode.ToUpper())).GroupBy(x => x.CurrencyCode);
  14347. foreach (var dc in new_dayCosts)
  14348. {
  14349. var thisCurrency = dc.Key.ToUpper();
  14350. var thisRate = dto.Currencys.Where(x => x.CurrencyCode.ToUpper().Equals(thisCurrency)).First()?.Rate ?? 0.00M;
  14351. if (thisRate == 0.00M) continue;
  14352. foreach (var dcSub in dc)
  14353. {
  14354. opDayCosts.Add(new Grp_DayAndCost()
  14355. {
  14356. Id = dcSub.Id,
  14357. DiId = dcSub.DiId,
  14358. Cost = dcSub.Cost,
  14359. SubTotal = dcSub.Cost * thisRate,
  14360. Remark = $"[移动端->汇率变更时费用变更][变更信息:currency:{thisCurrency}、opDatetime:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}、opUserId:{dto.CurrUserId}]"
  14361. });
  14362. }
  14363. }
  14364. if (opDayCosts.Count > 0)
  14365. {
  14366. await _sqlSugar.Updateable(opDayCosts).UpdateColumns(x => new { x.SubTotal, x.Remark }).WhereColumns(x => new { x.Id }).ExecuteCommandAsync();
  14367. }
  14368. }
  14369. if (dayOtherCosts.Count > 0)
  14370. {
  14371. var new_dayOtherCosts = dayOtherCosts.Where(x => eecCurrencys.Contains(x.CurrencyCode.ToUpper())).GroupBy(x => x.CurrencyCode);
  14372. foreach (var dc in new_dayOtherCosts)
  14373. {
  14374. var thisCurrency = dc.Key.ToUpper();
  14375. var thisRate = dto.Currencys.Where(x => x.CurrencyCode.ToUpper().Equals(thisCurrency)).First()?.Rate ?? 0.00M;
  14376. if (thisRate == 0.00M) continue;
  14377. foreach (var dcSub in dc)
  14378. {
  14379. opDayOtherCosts.Add(new Grp_DayOtherPrice()
  14380. {
  14381. Id = dcSub.Id,
  14382. Diid = dcSub.Diid,
  14383. Cost = dcSub.Cost,
  14384. SubTotal = dcSub.Cost * thisRate,
  14385. // Remark = $"[移动端->汇率变更时费用变更][变更信息:currency:{thisCurrency}、opDatetime:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}、opUserId:{dto.CurrUserId}]"
  14386. });
  14387. }
  14388. }
  14389. if (opDayOtherCosts.Count > 0)
  14390. {
  14391. await _sqlSugar.Updateable(opDayOtherCosts).UpdateColumns(x => new { x.SubTotal }).WhereColumns(x => new { x.Id }).ExecuteCommandAsync();
  14392. }
  14393. }
  14394. #endregion
  14395. //消息通知
  14396. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  14397. //汇率信息记录
  14398. await GeneralMethod.RateRecordSave(dto.CurrUserId, id, "出入境费用");
  14399. return Ok(JsonView(new { parentId = id }));
  14400. }
  14401. /// <summary>
  14402. /// 团组模块 - 出入境费用-移动端 - OP --> 复选框
  14403. /// </summary>
  14404. /// <returns></returns>
  14405. [HttpPost]
  14406. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14407. public async Task<IActionResult> EnterExitCostMobileOpCheckbox(PostEnterExitCostMobileFeeOpCheckboxDto dto)
  14408. {
  14409. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14410. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14411. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14412. //if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  14413. var checkboxInfo = _mapper.Map<Grp_EnterExitCost>(dto);
  14414. checkboxInfo.LastUpdateUserId = dto.CurrUserId;
  14415. checkboxInfo.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  14416. int id = dto.Id;
  14417. if (id <= 0) //add
  14418. {
  14419. checkboxInfo.CreateUserId = dto.CurrUserId;
  14420. checkboxInfo.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  14421. var add = await _sqlSugar.Insertable(checkboxInfo).ExecuteCommandAsync();
  14422. if (add < 1) return Ok(JsonView(false));
  14423. }
  14424. else //update
  14425. {
  14426. ////验证编辑权限
  14427. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  14428. //if (!isEdit) return Ok(JsonView(false, msg));
  14429. var upd = await _sqlSugar.Updateable(checkboxInfo)
  14430. .UpdateColumns(x => new
  14431. {
  14432. x.ChoiceOne,
  14433. x.ChoiceTwo,
  14434. x.SumJJC,
  14435. x.SumGWC,
  14436. x.SumTDC,
  14437. x.ChoiceThree,
  14438. x.ChoiceFour,
  14439. x.ChoiceFive,
  14440. x.ChoiceSix,
  14441. x.OtherExpenses_Checked
  14442. })
  14443. .Where(x => x.Id == id)
  14444. .ExecuteCommandAsync();
  14445. if (upd < 1) return Ok(JsonView(false));
  14446. }
  14447. return Ok(JsonView(new { parentId = id }));
  14448. }
  14449. /// <summary>
  14450. /// 团组模块 - 出入境费用-移动端 - OP --> 3-7项复选框单个复选框更改
  14451. /// </summary>
  14452. /// <returns></returns>
  14453. [HttpPost]
  14454. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14455. public async Task<IActionResult> EnterExitCostMobileOpSingleCheckbox(EnterExitCostMobileOpSingleCheckboxDto dto)
  14456. {
  14457. int itemTypeId = dto.ItemType, id = dto.Id, currUserId = dto.CurrUserId, diId = dto.DiId, isSelected = dto.IsSelected;
  14458. // if (provinceId < 1) provinceId = 122;
  14459. var itemTypes = new List<int>() { 3, 4, 5, 6, 7 };
  14460. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14461. if (diId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14462. if (currUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14463. if (!itemTypes.Contains(itemTypeId)) return Ok(JsonView(false, $"请传入要修改的项类型;3:住宿费; 4:伙食费; 5:公杂费; 6:培训费;7:其他;"));
  14464. var checkboxInfo = new Grp_EnterExitCost()
  14465. {
  14466. Id = id,
  14467. //ProvinceId = provinceId,
  14468. DiId = diId,
  14469. CreateUserId = currUserId,
  14470. LastUpdateUserId = dto.CurrUserId,
  14471. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  14472. };
  14473. if (itemTypeId == 3) checkboxInfo.ChoiceThree = isSelected;
  14474. else if (itemTypeId == 4) checkboxInfo.ChoiceFour = isSelected;
  14475. else if (itemTypeId == 5) checkboxInfo.ChoiceFive = isSelected;
  14476. else if (itemTypeId == 6) checkboxInfo.ChoiceSix = isSelected;
  14477. else if (itemTypeId == 7) checkboxInfo.OtherExpenses_Checked = isSelected;
  14478. if (id <= 0) //add
  14479. {
  14480. checkboxInfo.CreateUserId = dto.CurrUserId;
  14481. checkboxInfo.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  14482. var add = await _sqlSugar.Insertable(checkboxInfo).ExecuteCommandAsync();
  14483. if (add < 1) return Ok(JsonView(false));
  14484. }
  14485. else //update
  14486. {
  14487. ////验证编辑权限
  14488. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  14489. //if (!isEdit) return Ok(JsonView(false, msg));
  14490. var upd = await _sqlSugar.Updateable<Grp_EnterExitCost>()
  14491. .SetColumns(it => it.LastUpdateUserId == dto.CurrUserId)
  14492. .SetColumns(it => it.LastUpdateTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  14493. .SetColumnsIF(itemTypeId == 3, it => it.ChoiceThree == isSelected)
  14494. .SetColumnsIF(itemTypeId == 4, it => it.ChoiceFour == isSelected)
  14495. .SetColumnsIF(itemTypeId == 5, it => it.ChoiceFive == isSelected)
  14496. .SetColumnsIF(itemTypeId == 6, it => it.ChoiceSix == isSelected)
  14497. .SetColumnsIF(itemTypeId == 7, it => it.OtherExpenses_Checked == isSelected)
  14498. .Where(x => x.Id == id)
  14499. .ExecuteCommandAsync();
  14500. if (upd < 1) return Ok(JsonView(false));
  14501. }
  14502. return Ok(JsonView(new { parentId = id }));
  14503. }
  14504. /// <summary>
  14505. /// 团组模块 - 出入境费用-移动端 - OP --> 境内费用 Step1
  14506. /// </summary>
  14507. /// <returns></returns>
  14508. [HttpPost]
  14509. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14510. public async Task<IActionResult> EnterExitCostMobileOpStep1(PostEnterExitCostMobileOpStep1Dto dto)
  14511. {
  14512. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14513. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14514. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14515. //if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  14516. var info = _mapper.Map<Grp_EnterExitCost>(dto);
  14517. info.FirstItemRemark = dto.FirstItemRemark;
  14518. info.LastUpdateUserId = dto.CurrUserId;
  14519. info.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  14520. info.InsidePay = dto.Visa + dto.Service + dto.Safe + dto.Ticket + dto.HeSuan + dto.YiMiao;
  14521. int id = dto.Id;
  14522. if (id <= 0) //add
  14523. {
  14524. info.CreateUserId = dto.CurrUserId;
  14525. info.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  14526. var add = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  14527. if (add < 1) return Ok(JsonView(false));
  14528. id = add;
  14529. }
  14530. else //update
  14531. {
  14532. ////验证编辑权限
  14533. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  14534. //if (!isEdit) return Ok(JsonView(false, msg));
  14535. var upd = await _sqlSugar.Updateable(info)
  14536. .UpdateColumns(x => new
  14537. {
  14538. x.ChoiceOne,
  14539. x.InsidePay,
  14540. x.VisaRemark,
  14541. x.Visa,
  14542. x.Service,
  14543. x.Safe,
  14544. x.Ticket,
  14545. x.HeSuan,
  14546. x.YiMiao,
  14547. x.FirstItemRemark,
  14548. x.LastUpdateUserId,
  14549. x.LastUpdateTime
  14550. })
  14551. .Where(x => x.Id == id)
  14552. .ExecuteCommandAsync();
  14553. if (upd < 1) return Ok(JsonView(false));
  14554. }
  14555. //消息通知
  14556. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  14557. return Ok(JsonView(new { parentId = id, itemTotal = info.InsidePay }));
  14558. }
  14559. /// <summary>
  14560. /// 团组模块 - 出入境费用-移动端 - OP --> 国际旅费 Step2
  14561. /// </summary>
  14562. /// <returns></returns>
  14563. [HttpPost]
  14564. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14565. public async Task<IActionResult> EnterExitCostMobileOpStep2(PostEnterExitCostMobileOpStep2Dto dto)
  14566. {
  14567. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14568. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14569. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14570. //if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  14571. var info = _mapper.Map<Grp_EnterExitCost>(dto);
  14572. info.DiId = dto.DiId;
  14573. //info.ProvinceId = dto.ProvinceId;
  14574. info.OutsideJJPay = dto.OutsideJJPay;
  14575. info.OutsideGWPay = dto.OutsideGWPay;
  14576. info.OutsideTDPay = dto.OutsideTDPay;
  14577. info.AirJJ = dto.AirJJ;
  14578. info.AirGW = dto.AirGW;
  14579. info.AirTD = dto.AirTD;
  14580. info.CityTranffic = dto.CityTranffic;
  14581. info.CityTranffic1 = dto.CityTranffic1;
  14582. info.CityTranffic2 = dto.CityTranffic2;
  14583. info.TwoItemRemark = dto.TwoItemRemark;
  14584. info.SumJJC = dto.ChoiceTwoJJ;
  14585. info.SumGWC = dto.ChoiceTwoGW;
  14586. info.SumTDC = dto.ChoiceTwoTD;
  14587. info.LastUpdateUserId = dto.CurrUserId;
  14588. info.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  14589. int id = dto.Id;
  14590. decimal jjcItemTotal = 0.00M, gwcItemTotal = 0.00M, tdcItemTotal = 0.00M;
  14591. if (id <= 0) //add i
  14592. {
  14593. info.CreateUserId = dto.CurrUserId;
  14594. info.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  14595. var addId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  14596. if (addId <= 0) return Ok(JsonView(false));
  14597. id = addId;
  14598. }
  14599. else //update
  14600. {
  14601. ////验证编辑权限
  14602. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  14603. //if (!isEdit) return Ok(JsonView(false, msg));
  14604. var upd = await _sqlSugar.Updateable(info)
  14605. .UpdateColumns(x => new
  14606. {
  14607. x.SumJJC,
  14608. x.OutsideJJPay,
  14609. x.SumGWC,
  14610. x.OutsideGWPay,
  14611. x.SumTDC,
  14612. x.OutsideTDPay,
  14613. x.AirJJ,
  14614. x.AirGW,
  14615. x.AirTD,
  14616. x.CityTranffic,
  14617. x.CityTranffic1,
  14618. x.CityTranffic2,
  14619. x.TwoItemRemark,
  14620. x.LastUpdateTime,
  14621. x.LastUpdateUserId
  14622. })
  14623. .Where(x => x.Id == id)
  14624. .ExecuteCommandAsync();
  14625. if (upd < 1) return Ok(JsonView(false));
  14626. }
  14627. jjcItemTotal = info.AirJJ + info.CityTranffic;
  14628. gwcItemTotal = info.AirGW + info.CityTranffic1;
  14629. tdcItemTotal = info.AirTD + info.CityTranffic2;
  14630. //消息通知
  14631. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  14632. return Ok(JsonView(new
  14633. {
  14634. parentId = id,
  14635. choiceTwoJJ = dto.ChoiceTwoJJ,
  14636. jjcItemTotal = jjcItemTotal,
  14637. choiceTwoGW = dto.ChoiceTwoGW,
  14638. gwcItemTotal = gwcItemTotal,
  14639. choiceTwoTD = dto.ChoiceTwoTD,
  14640. tdcItemTotal = tdcItemTotal
  14641. }));
  14642. }
  14643. /// <summary>
  14644. /// 团组模块 - 出入境费用-移动端 - OP --> 批量(住宿、伙食、公杂、培训) Step3-Step6
  14645. /// </summary>
  14646. /// <returns></returns>
  14647. [HttpPost]
  14648. [ApiExplorerSettings(IgnoreApi = true)]
  14649. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14650. public async Task<IActionResult> EnterExitCostMobileOpBatchStep3To6(PostEnterExitCostMobileOpStep3To6Dto dto)
  14651. {
  14652. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14653. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14654. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14655. if (dto.Infos.Length < 1) return Ok(JsonView(false, "请传入有效的费用信息!"));
  14656. var feeTypeIds = new List<int>() { 1, 2, 3, 4, };
  14657. if (!feeTypeIds.Contains(dto.FeeType)) return Ok(JsonView(false, "请传入有效的费用类型!"));
  14658. var infos1 = _mapper.Map<List<Grp_DayAndCost>>(dto.Infos);
  14659. var infos = infos1.Select(x => new Grp_DayAndCost
  14660. {
  14661. Id = x.Id,
  14662. DiId = dto.DiId,
  14663. Type = dto.FeeType,
  14664. Days = x.Days,
  14665. NationalTravelFeeId = x.NationalTravelFeeId,
  14666. Cost = x.Cost,
  14667. Currency = x.Currency,
  14668. SubTotal = x.SubTotal,
  14669. CreateUserId = dto.CurrUserId
  14670. })
  14671. .ToList();
  14672. var adds = infos.Where(x => x.Id <= 0).ToList();
  14673. var upds = infos.Where(x => x.Id > 0).ToList();
  14674. if (adds.Count > 0)
  14675. {
  14676. var add = await _sqlSugar.Insertable(adds).ExecuteCommandAsync();
  14677. if (add < 1) return Ok(JsonView(false));
  14678. }
  14679. if (upds.Count > 0)
  14680. {
  14681. var upd = await _sqlSugar.Updateable(adds)
  14682. .UpdateColumns(x => new
  14683. {
  14684. x.Days,
  14685. x.NationalTravelFeeId,
  14686. x.Cost,
  14687. x.Currency,
  14688. x.SubTotal
  14689. })
  14690. .WhereColumns(x => new { x.Id })
  14691. .ExecuteCommandAsync();
  14692. if (upd < 1) return Ok(JsonView(false));
  14693. }
  14694. var itemTotal = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.IsDel == 0 && x.DiId == dto.DiId && x.Type == dto.FeeType).Sum(x => x.SubTotal);
  14695. //消息通知
  14696. var id = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == dto.DiId).First()?.Id ?? 0;
  14697. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  14698. return Ok(JsonView(new { itemTotal = itemTotal }));
  14699. }
  14700. /// <summary>
  14701. /// 团组模块 - 出入境费用-移动端 - OP --> 单条(住宿、伙食、公杂、培训) Step3-Step6
  14702. /// </summary>
  14703. /// <returns></returns>
  14704. [HttpPost]
  14705. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14706. public async Task<IActionResult> EnterExitCostMobileOpSingleStep3To6(PostEnterExitCostMobileOpSingleStep3To6Dto dto)
  14707. {
  14708. var feeTypeIds = new List<int>() { 3, 4, 5, 6 };
  14709. int subId = dto.SubId, feeType = dto.FeeType;
  14710. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14711. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14712. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14713. if (!feeTypeIds.Contains(dto.FeeType)) return Ok(JsonView(false, "请传入有效的费用类型!"));
  14714. var subInfo = _mapper.Map<Grp_DayAndCost>(dto);
  14715. subInfo.Id = subId;
  14716. subInfo.DiId = dto.DiId;
  14717. if (feeType == 3) subInfo.Type = 1;
  14718. else if (feeType == 4) subInfo.Type = 2;
  14719. else if (feeType == 5) subInfo.Type = 3;
  14720. else if (feeType == 6) subInfo.Type = 4;
  14721. subInfo.CreateUserId = dto.CurrUserId;
  14722. int parentId = await EnterExitCostVerifyIsNull(dto.DiId, dto.CurrUserId); //主表验证
  14723. if (parentId < 1) return Ok(JsonView(false));
  14724. //子表op
  14725. if (subId < 1)
  14726. {
  14727. var subAdd = await _sqlSugar.Insertable(subInfo).ExecuteCommandAsync();
  14728. if (subAdd < 1) return Ok(JsonView(false));
  14729. }
  14730. else
  14731. {
  14732. ////验证编辑权限
  14733. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  14734. //if (!isEdit) return Ok(JsonView(false, msg));
  14735. var subUpd = await _sqlSugar.Updateable(subInfo)
  14736. .UpdateColumns(x => new
  14737. {
  14738. x.Days,
  14739. x.NationalTravelFeeId,
  14740. x.Cost,
  14741. x.Currency,
  14742. x.SubTotal
  14743. })
  14744. .WhereColumns(x => new { x.Id })
  14745. .ExecuteCommandAsync();
  14746. if (subUpd < 1) return Ok(JsonView(false));
  14747. }
  14748. var itemTotal = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.IsDel == 0 && x.DiId == dto.DiId && x.Type == feeType).Sum(x => x.SubTotal);
  14749. //await EnterExitCostMobileOpNotice(dto.DiId, parentId, dto.CurrUserId);
  14750. return Ok(JsonView(new { parentId = parentId, itemTotal = itemTotal }));
  14751. }
  14752. /// <summary>
  14753. /// 团组模块 - 出入境费用-移动端 - OP --> 其他费用-批量 Step7
  14754. /// </summary>
  14755. /// <returns></returns>
  14756. [HttpPost]
  14757. [ApiExplorerSettings(IgnoreApi = true)]
  14758. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14759. public async Task<IActionResult> EnterExitCostMobileOpBatchStep7(PostEnterExitCostMobileOpStep7Dto dto)
  14760. {
  14761. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14762. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14763. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14764. var infos1 = _mapper.Map<List<Grp_DayOtherPrice>>(dto.Infos);
  14765. var infos = infos1.Select(x => new Grp_DayOtherPrice()
  14766. {
  14767. Id = x.Id,
  14768. Diid = dto.DiId,
  14769. SetDataId = x.SetDataId,
  14770. Index = x.Index,
  14771. Cost = x.Cost,
  14772. Currency = x.Currency,
  14773. SubTotal = x.SubTotal,
  14774. CreateUserId = dto.CurrUserId,
  14775. Remark = x.Remark
  14776. }).ToList();
  14777. var adds = infos.Where(x => x.Id <= 0).ToList();
  14778. var upds = infos.Where(x => x.Id > 0).ToList();
  14779. if (adds.Count > 0)
  14780. {
  14781. var add = await _sqlSugar.Insertable(adds).ExecuteCommandAsync();
  14782. if (add < 1) return Ok(JsonView(false));
  14783. }
  14784. if (upds.Count > 0)
  14785. {
  14786. var upd = await _sqlSugar.Updateable(adds)
  14787. .UpdateColumns(x => new
  14788. {
  14789. x.Index,
  14790. x.SetDataId,
  14791. x.Cost,
  14792. x.Currency,
  14793. x.SubTotal,
  14794. x.Remark
  14795. })
  14796. .WhereColumns(x => new { x.Id })
  14797. .ExecuteCommandAsync();
  14798. if (upd < 1) return Ok(JsonView(false));
  14799. }
  14800. var itemTotal = _sqlSugar.Queryable<Grp_DayOtherPrice>().Where(x => x.IsDel == 0 && x.Diid == dto.DiId).Sum(x => x.SubTotal);
  14801. //消息通知
  14802. var id = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == dto.DiId).First()?.Id ?? 0;
  14803. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  14804. return Ok(JsonView(new { itemTotal = itemTotal }));
  14805. }
  14806. /// <summary>
  14807. /// 团组模块 - 出入境费用-移动端 - OP --> 其他费用-单条 Step7
  14808. /// </summary>
  14809. /// <returns></returns>
  14810. [HttpPost]
  14811. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14812. public async Task<IActionResult> EnterExitCostMobileOpSingleStep7(PostEnterExitCostMobileOpSingleStep7Dto dto)
  14813. {
  14814. int subId = dto.SubId;
  14815. int diId = dto.Diid;
  14816. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14817. if (diId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14818. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14819. var subInfo = _mapper.Map<Grp_DayOtherPrice>(dto);
  14820. subInfo.Id = subId;
  14821. subInfo.Diid = dto.Diid;
  14822. subInfo.CreateUserId = dto.CurrUserId;
  14823. int parentId = await EnterExitCostVerifyIsNull(diId, dto.CurrUserId); //主表验证
  14824. if (parentId < 1) return Ok(JsonView(false));
  14825. #region 子表op
  14826. if (subId < 1)//add
  14827. {
  14828. var subAdd = await _sqlSugar.Insertable(subInfo).ExecuteCommandAsync();
  14829. if (subAdd < 1) return Ok(JsonView(false));
  14830. }
  14831. else //upd
  14832. {
  14833. ////验证编辑权限
  14834. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.Diid, dto.CurrUserId, 2);
  14835. //if (!isEdit) return Ok(JsonView(false, msg));
  14836. var subUpd = await _sqlSugar.Updateable(subInfo)
  14837. .UpdateColumns(x => new
  14838. {
  14839. x.Index,
  14840. x.SetDataId,
  14841. x.Cost,
  14842. x.Currency,
  14843. x.SubTotal,
  14844. x.Remark
  14845. })
  14846. .WhereColumns(x => new { x.Id })
  14847. .ExecuteCommandAsync();
  14848. if (subUpd < 1) return Ok(JsonView(false));
  14849. }
  14850. #endregion
  14851. var itemTotal = _sqlSugar.Queryable<Grp_DayOtherPrice>().Where(x => x.IsDel == 0 && x.Diid == diId).Sum(x => x.SubTotal);
  14852. //消息通知
  14853. //await EnterExitCostMobileOpNotice(dto.Diid, parentId, dto.CurrUserId);
  14854. return Ok(JsonView(new { parentId = parentId, itemTotal = itemTotal }));
  14855. }
  14856. /// <summary>
  14857. /// 团组模块 - 出入境费用-移动端 - 3-6子项删除
  14858. /// </summary>
  14859. /// <returns></returns>
  14860. [HttpPost]
  14861. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14862. public async Task<IActionResult> EnterExitCostMobileSubItemDel(EnterExitCostSubItemDelDto dto)
  14863. {
  14864. var data = await _enterExitCostRep.PostEnterExitCostSubItemDel(dto);
  14865. if (data.Code != 0)
  14866. {
  14867. return Ok(JsonView(false, data.Msg));
  14868. }
  14869. return Ok(JsonView(true, "操作成功!", data.Data));
  14870. }
  14871. /// <summary>
  14872. /// 团组模块 - 出入境费用-移动端 - 其他费用删除
  14873. /// </summary>
  14874. /// <param name="dto"></param>
  14875. /// <returns></returns>
  14876. [HttpPost]
  14877. public IActionResult EnterExitCostMobileOtherFeeDel(EnterExitCostSubItemDelDto dto)
  14878. {
  14879. var data = new Grp_DayOtherPrice()
  14880. {
  14881. Id = dto.Id,
  14882. IsDel = 1,
  14883. DeleteUserId = dto.DeleteUserId,
  14884. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  14885. };
  14886. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  14887. if (del > 0) return Ok(JsonView(true, "删除成功!"));
  14888. return Ok(JsonView(false, "删除失败!"));
  14889. }
  14890. #endregion
  14891. #endregion
  14892. #region 团组经理模块 出入境费用-草稿 移动端(Android/IOS)
  14893. /// <summary>
  14894. /// 团组模块 - 出入境费用-草稿 - 基础数据源 - 省份归属
  14895. /// </summary>
  14896. /// <returns></returns>
  14897. [HttpGet]
  14898. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14899. public async Task<IActionResult> EnterExitDraftMobileProvBelongCostDataSource()
  14900. {
  14901. var provData = await _groupRepository.ProvinceBasicSource();
  14902. return Ok(JsonView(true, "查询成功!", provData));
  14903. }
  14904. /// <summary>
  14905. /// 团组模块 - 出入境费用-草稿-移动端 - 草稿名称数据Data
  14906. /// </summary>
  14907. /// <returns></returns>
  14908. [HttpPost]
  14909. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14910. public async Task<IActionResult> EnterExitCostDraftMobileNameData(EnterExitCostDraftMobileNameDataDto dto)
  14911. {
  14912. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14913. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14914. RefAsync<int> total = 0;
  14915. var data = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>()
  14916. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.DraftName))
  14917. .WhereIF(!string.IsNullOrEmpty(dto.DraftName), x => x.DraftName.Contains(dto.DraftName))
  14918. .Select(x => new
  14919. {
  14920. Id = x.Id,
  14921. DraftName = x.DraftName,
  14922. IsViewOrEdit = SqlFunc.Subqueryable<Grp_EnterExitCostDraftPermission>()
  14923. .Where(x1 => x1.IsDel == 0 && x1.Permission == 1 && x1.DraftId == x.Id && x1.UserId == dto.CurrUserId)
  14924. .Any()
  14925. })
  14926. .OrderByDescending(x => x.Id)
  14927. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  14928. return Ok(JsonView(true, "查询成功!", data, total));
  14929. }
  14930. /// <summary>
  14931. /// 出入境费用-草稿 移动端
  14932. /// 获取币种基础数据(含逻辑处理)
  14933. /// </summary>
  14934. /// <returns></returns>
  14935. private async Task<List<CurrencyInfo>> EnterExitCostDraftMobileGetCurrencyInit()
  14936. {
  14937. return await GeneralMethod.EnterExitCostInitRate();
  14938. }
  14939. /// <summary>
  14940. /// 团组模块 - 出入境费用-草稿-移动端 - 基础数据源(Word明细类型、Excel明细类型、默认币种显示)
  14941. /// </summary>
  14942. /// <returns></returns>
  14943. [HttpPost]
  14944. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14945. public async Task<IActionResult> EnterExitCostDraftMobileDataSource(EnterExitCostDraftMobileDataSourceDto dto)
  14946. {
  14947. //验证城市归属并给默认值
  14948. int provinceId = dto.ProvinceId;
  14949. if (provinceId < 1) provinceId = 122;
  14950. var dataSource = await _sqlSugar
  14951. .Queryable<Sys_SetData>()
  14952. .Where(x => x.IsDel == 0 && (x.STid == 72 || x.STid == 73) && x.Remark.Contains(provinceId.ToString()))
  14953. .ToListAsync();
  14954. //三公费用-Word明细类型
  14955. var wordTypeData = dataSource.Where(it => it.STid == 72)
  14956. .Select(x => new SetDataInfoView
  14957. {
  14958. Id = x.Id,
  14959. Name = x.Name,
  14960. Remark = x.Remark
  14961. })
  14962. .ToList();
  14963. //三公费用-Excel明细类型
  14964. var excelTypeData = dataSource.Where(it => it.STid == 73)
  14965. .Select(x => new SetDataInfoView
  14966. {
  14967. Id = x.Id,
  14968. Name = x.Name,
  14969. Remark = x.Remark
  14970. })
  14971. .ToList();
  14972. //默认币种显示
  14973. var _currencyInfos = await EnterExitCostMobileGetCurrencyInit();
  14974. var viewPermissionData = await _enterExitCostRep.PermissionViewUsersAsync();
  14975. return Ok(JsonView(true, "查询成功!", new
  14976. {
  14977. WordTypeData = wordTypeData,
  14978. ExcelTypeData = excelTypeData,
  14979. CurrencyInit = _currencyInfos,
  14980. viewPermissionData = viewPermissionData
  14981. }));
  14982. }
  14983. /// <summary>
  14984. /// 团组模块 - 出入境费用-草稿-移动端 - 团组基础数据Data
  14985. /// </summary>
  14986. /// <returns></returns>
  14987. [HttpPost]
  14988. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14989. public async Task<IActionResult> EnterExitCostDraftMobileGroupData(PostEnterExitCostDraftMobileGroupDataDto dto)
  14990. {
  14991. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14992. RefAsync<int> total = 0;
  14993. int diId = 0;
  14994. var status = int.TryParse(dto.GroupName, out diId);
  14995. var data = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  14996. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.TeamName))
  14997. .WhereIF(!string.IsNullOrEmpty(dto.GroupName) && diId > 0, x => x.Id == diId)
  14998. .WhereIF(!string.IsNullOrEmpty(dto.GroupName) && !status, x => x.TeamName.Contains(dto.GroupName))
  14999. .OrderByDescending(x => x.VisitStartDate)
  15000. .Select(x => new
  15001. {
  15002. Id = x.Id,
  15003. GroupName = x.TeamName
  15004. })
  15005. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  15006. return Ok(JsonView(true, "查询成功!", data, total));
  15007. }
  15008. /// <summary>
  15009. /// 团组模块 - 出入境费用-草稿-移动端 - 币种基础数据Data
  15010. /// </summary>
  15011. /// <returns></returns>
  15012. [HttpPost]
  15013. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15014. public async Task<IActionResult> EnterExitCostDraftMobileCurrencyData(PostEnterExitCostDraftMobileCurrencyDataDto dto)
  15015. {
  15016. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  15017. RefAsync<int> total = 0;
  15018. var data = await _sqlSugar.Queryable<Sys_SetData>()
  15019. .Where(x => x.IsDel == 0 && x.STid == 66)
  15020. .WhereIF(!string.IsNullOrEmpty(dto.CurrencyName), x => x.Name.ToLower().Contains(dto.CurrencyName) || x.Remark.Contains(dto.CurrencyName))
  15021. .Select(x => new
  15022. {
  15023. id = x.Id,
  15024. name = x.Name,
  15025. remark = x.Remark,
  15026. })
  15027. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  15028. return Ok(JsonView(true, "查询成功!", data, total));
  15029. }
  15030. /// <summary>
  15031. /// 团组模块 - 出入境费用-草稿-移动端 - 其他款项 - 币种、费用类型基础数据Data
  15032. /// </summary>
  15033. /// <returns></returns>
  15034. [HttpPost]
  15035. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15036. public async Task<IActionResult> EnterExitCostDraftMobileOtherItemCurrencyData(PostEnterExitCostDraftMobileOtherItemCurrencyDataDto dto)
  15037. {
  15038. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  15039. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  15040. var groupRateData = await GeneralMethod.PostGroupTeamRateByDiIdAndCTableId(1, 2477, 98);
  15041. if (groupRateData == null) return Ok(JsonView(false, "请填写“团组汇率-->其他款项”汇率!"));
  15042. var groupOtherRateData = groupRateData.TeamRates;
  15043. var enterExitCostInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().FirstAsync(it => it.Id == dto.DraftId && it.IsDel == 0);
  15044. if (enterExitCostInfo == null) return Ok(JsonView(groupOtherRateData));
  15045. var eecRateData = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(enterExitCostInfo.CurrencyRemark);
  15046. groupOtherRateData = groupOtherRateData
  15047. .Select(x => new TeamRateDescAddCurrencyIdView
  15048. {
  15049. CurrencyId = x.CurrencyId,
  15050. CurrencyName = x.CurrencyName,
  15051. CurrencyCode = x.CurrencyCode,
  15052. Rate = eecRateData.Find(it => it.CurrencyCode.ToUpper().Equals(x.CurrencyCode.ToUpper()))?.Rate ?? x.Rate
  15053. }).ToList();
  15054. var otherFeeTypeData = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 92).Select(x => new { x.Id, x.Name }).ToListAsync();
  15055. return Ok(JsonView(true, "查询成功!", new { groupOtherRateData = groupOtherRateData, otherFeeTypeData = otherFeeTypeData }));
  15056. }
  15057. /// <summary>
  15058. /// 团组模块 - 出入境费用-草稿-移动端 - 实时汇率、签证费用、机票费用 Tips
  15059. /// </summary>
  15060. /// <returns></returns>
  15061. [HttpPost]
  15062. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15063. public async Task<IActionResult> EnterExitCostDraftMobileFeeTips(EnterExitCostDraftMobileFeeTipsDto dto)
  15064. {
  15065. int portType = dto.PortType;
  15066. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  15067. var tipsData = new List<int>() { 1, 2, 3 };
  15068. if (!tipsData.Contains(dto.TipsType)) return Ok(JsonView(false, $"请传入有效的TipsType参数;1 实时汇率;2 签证费用;3 机票费用;"));
  15069. if (dto.TipsType == 1)
  15070. {
  15071. return Ok(JsonView(true, "查询成功!", await GeneralMethod.EnterExitCostLiveRate()));
  15072. }
  15073. else if (dto.TipsType == 2)
  15074. {
  15075. if (portType == 2)
  15076. {
  15077. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  15078. }
  15079. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  15080. .Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId)
  15081. .Select(x => x.NationalTravelFeeId)
  15082. .Distinct()
  15083. .ToListAsync();
  15084. if (portType == 2)
  15085. {
  15086. if (!cityIds.Any()) return Ok(JsonView(false, "请先录入出入境费用明细!"));
  15087. }
  15088. var countrys = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  15089. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  15090. .Select(x => x.Country)
  15091. .Distinct()
  15092. .ToArrayAsync();
  15093. if (portType == 2)
  15094. {
  15095. if (!countrys.Any()) return Ok(JsonView(false, "请先录入出入境费用明细!"));
  15096. }
  15097. (decimal totalAmt, string remark) = await _visaFeeInfoRep.EnterExitCostDraftVisaTips(countrys);
  15098. return Ok(JsonView(true, "查询成功!", new
  15099. {
  15100. totalAmt = totalAmt,
  15101. remark = remark
  15102. }));
  15103. }
  15104. else if (dto.TipsType == 3)
  15105. {
  15106. return Ok(JsonView(false, "暂无机票费用提示信息!"));
  15107. }
  15108. return Ok(JsonView(false));
  15109. }
  15110. #region 城市区间交通费
  15111. /// <summary>
  15112. /// 团组模块 - 出入境费用 - 草稿 - 移动端 - 基础数据源(境外用车)
  15113. /// </summary>
  15114. /// <param name="draftId">草稿Id</param>
  15115. /// <returns></returns>
  15116. [HttpGet("{darfId}")]
  15117. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15118. public async Task<IActionResult> EnterExitCostDraftOVMobileByGroupId(int draftId)
  15119. {
  15120. var groupInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == draftId).FirstAsync();
  15121. if (groupInfo == null)
  15122. {
  15123. return Ok(JsonView(false, "三公费用草稿信息为空"));
  15124. }
  15125. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  15126. .Where(x => x.IsDel == 0 && x.ParentId == draftId)
  15127. .Select(x => x.NationalTravelFeeId)
  15128. .Distinct()
  15129. .ToListAsync();
  15130. var countries = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  15131. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  15132. .Select(x => x.Country)
  15133. .Distinct()
  15134. .ToListAsync();
  15135. if (countries?.Any() != true)
  15136. {
  15137. return Ok(JsonView(false, "草稿选择城市信息为空"));
  15138. }
  15139. var currencies = await GeneralMethod.EnterExitCostDrafOVFeeUsedCurrencyAsync(draftId);
  15140. var currencyData = await _sqlSugar.Queryable<Sys_SetData>()
  15141. .Where(x => x.IsDel == 0 && x.STid == 66)
  15142. .ToListAsync();
  15143. var overseaVehicles = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  15144. .Where(x => x.IsDel == 0 && countries.Contains(x.CountryName))
  15145. .ToListAsync();
  15146. var overseaVehicleIds = overseaVehicles.Select(x => x.Id).ToList();
  15147. //只返回接送机的数据
  15148. var overseaVehicleTypes = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  15149. .Where(x => x.IsDel == 0 && x.ServiceType == VehicleServiceTypeEnum.TransferService && overseaVehicleIds.Contains(x.OvId))
  15150. .ToListAsync();
  15151. var sysUers = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToListAsync();
  15152. var overseaVehicleCityDatas = new List<dynamic>() {
  15153. new
  15154. {
  15155. Id = 0,
  15156. area= "未选择",
  15157. CarTypeName = "",
  15158. serviceType = "",
  15159. Price = 0.00M,
  15160. guidePrice = 0.00M,
  15161. otherPrice = 0.00M,
  15162. currency = 0,
  15163. currencyName = "",
  15164. currRate = 1.0000M,
  15165. LastUpdateUserName = "",
  15166. LastUpdateTime = "",
  15167. Remark = ""
  15168. }};
  15169. foreach (var item in overseaVehicleTypes)
  15170. {
  15171. var parentInfo = overseaVehicles.FirstOrDefault(x => x.Id == item.OvId);
  15172. string area = string.Empty,
  15173. serviceType = "未设置",
  15174. currencyName = string.Empty;
  15175. decimal otherPrice = 0.00M;
  15176. if (parentInfo != null)
  15177. {
  15178. if (parentInfo.CountryName == parentInfo.CityName) area = parentInfo.CountryName;
  15179. else area = $"{parentInfo.CountryName}-{parentInfo.CityName}";
  15180. serviceType = item.ServiceType.GetDescription();
  15181. currencyName = currencyData.FirstOrDefault(x => x.Id == parentInfo.Currency)?.Name ?? "-";
  15182. otherPrice = parentInfo.OtherPrice1 + parentInfo.OtherPrice2;
  15183. }
  15184. //当前币种汇率值
  15185. var currRate = 1.0000M;
  15186. var currencyInfo = currencies.FirstOrDefault(x => x.CurrencyCode == currencyName);
  15187. if (currencyInfo != null) currRate = currencyInfo.Rate;
  15188. overseaVehicleCityDatas.add(new
  15189. {
  15190. item.Id,
  15191. area,
  15192. item.CarTypeName,
  15193. serviceType,
  15194. item.Price,
  15195. guidePrice = parentInfo?.GuidePrice ?? 0.00M,
  15196. otherPrice,
  15197. currency = parentInfo?.Currency ?? 0,
  15198. currencyName,
  15199. currRate,
  15200. LastUpdateUserName = sysUers.FirstOrDefault(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-",
  15201. item.LastUpdateTime,
  15202. item.Remark
  15203. });
  15204. }
  15205. var total = overseaVehicleCityDatas.Count;
  15206. var view = new
  15207. {
  15208. visitCountries = string.Join("、", countries),
  15209. //groupSize = 0, //出访人数
  15210. defAirportTransferCoeff = Def_AirportTransferCoeff, //接送机默认报价系数
  15211. defServiceCount = Def_ServiceCount, //接送机默认服务次数
  15212. defTrainCoeff = Def_TrainCoeff, //火车默认报价系数
  15213. defPullCartCoeff = Def_PullCartCoeff, //拉车默认报价系数
  15214. defCityFlightCoeff = Def_CityFlightCoeff, //城市机票默认报价系数
  15215. Currencies = currencies,
  15216. data = overseaVehicleCityDatas
  15217. };
  15218. if (overseaVehicleCityDatas.Count == 0)
  15219. {
  15220. return Ok(JsonView(true, "暂无数据!", view));
  15221. }
  15222. return Ok(JsonView(true, "查询成功!", view, total));
  15223. }
  15224. /// <summary>
  15225. /// 团组模块 - 出入境费用 - 草稿 - 境外用车计算详细信息
  15226. /// </summary>
  15227. /// <param name="draftId"></param>
  15228. /// <param name="currUserId"></param>
  15229. /// <returns></returns>
  15230. [HttpGet("{groupId}")]
  15231. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15232. public async Task<IActionResult> EnterExitCostDraftOVFeeMobileDetails(int draftId, int currUserId)
  15233. {
  15234. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == draftId && x.IsDel == 0).FirstAsync();
  15235. if (eecInfo == null)
  15236. {
  15237. return Ok(JsonView(false, "草稿信息为空"));
  15238. }
  15239. var info = new CityIntervalDraftInfo();
  15240. if (eecInfo != null)
  15241. {
  15242. info = eecInfo.CityIntervalFeeDetails;
  15243. return Ok(JsonView(true, "查询成功!", info));
  15244. }
  15245. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == currUserId).FirstAsync();
  15246. var userName = userInfo?.CnName ?? "-";
  15247. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  15248. //返回默认数据
  15249. info = new CityIntervalDraftInfo()
  15250. {
  15251. APTFeeDetails = new List<RoundTripTransferInfo>() { new() { No = 1, Coefficient = Def_AirportTransferCoeff, ServiceCount = Def_ServiceCount } },
  15252. PullCartFeeDetails = new List<PullCartInfo>() { new() { No = 1, Coefficient = Def_PullCartCoeff } },
  15253. TrainFeeDetails = new List<TrainInfo>() { new() { No = 1, Coefficient = Def_TrainCoeff } },
  15254. CityAirTicketFeeDetails = new List<CityAirTicketInfo>() { new() { No = 1, Coefficient = Def_CityFlightCoeff } },
  15255. LastUpdateUserName = userName,
  15256. LastUpdateTime = nowTime,
  15257. CreateUserName = userName,
  15258. Currencies = await GeneralMethod.EnterExitCostDrafOVFeeUsedCurrencyAsync(draftId),
  15259. CreateTime = nowTime
  15260. };
  15261. return Ok(JsonView(true, "查询成功!", info));
  15262. }
  15263. /// <summary>
  15264. /// 团组模块 - 出入境费用 - 草稿 - 境外用车计算 保存
  15265. /// </summary>
  15266. /// <param name="dto"></param>
  15267. /// <returns></returns>
  15268. [HttpPost]
  15269. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15270. public async Task<IActionResult> EnterExitCostDraftOVFeeMobileSave(EnterExitCostDraftOVFeeSaveDto dto)
  15271. {
  15272. var draftInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == dto.DraftId).FirstAsync();
  15273. if (draftInfo == null)
  15274. {
  15275. return Ok(JsonView(false, "草稿信息为空"));
  15276. }
  15277. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == dto.CurrUserId).FirstAsync();
  15278. if (userInfo == null)
  15279. {
  15280. return Ok(JsonView(false, "员工信息为空"));
  15281. }
  15282. var userName = userInfo?.CnName ?? "-";
  15283. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  15284. var info = new CityIntervalDraftInfo()
  15285. {
  15286. GroupSize = dto.GroupSize,
  15287. APTFeeTotal = dto.APTFeeTotal,
  15288. APTFeeDetails = dto.APTFeeDetails,
  15289. PullCartFeeTotal = dto.PullCartFeeTotal,
  15290. PullCartFeeDetails = dto.PullCartFeeDetails,
  15291. TrainFeeTotal = dto.TrainFeeTotal,
  15292. TrainFeeDetails = dto.TrainFeeDetails,
  15293. CityAirTicketFeeTotal = dto.CityAirTicketFeeTotal,
  15294. CityAirTicketFeeDetails = dto.CityAirTicketFeeDetails,
  15295. Currencies = dto.Currencies,
  15296. LastUpdateUserName = userName,
  15297. LastUpdateTime = nowTime,
  15298. CreateUserName = draftInfo.CityIntervalFeeDetails?.CreateUserName ?? userName,
  15299. CreateTime = draftInfo.CityIntervalFeeDetails?.CreateTime ?? nowTime
  15300. };
  15301. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>()
  15302. .SetColumns(it => it.CityIntervalFeeDetails == info)
  15303. .Where(x => x.Id == draftInfo.Id)
  15304. .ExecuteCommandAsync();
  15305. if (upd < 1)
  15306. {
  15307. return Ok(JsonView(false));
  15308. }
  15309. //返回参数处理
  15310. var label = new StringBuilder();
  15311. if (dto.APTFeeDetails.Any())
  15312. {
  15313. var ovIds = dto.APTFeeDetails.Select(x => x.OvId).ToList();
  15314. var areas = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  15315. .LeftJoin<Res_OverseaVehicle>((ovtp, ov) => ovtp.OvId == ov.Id)
  15316. .Where((ovtp, ov) => ovtp.IsDel == 0 && ovIds.Contains(ovtp.Id))
  15317. .Select((ovtp, ov) => new
  15318. {
  15319. ovtp.Id,
  15320. ov.CountryName,
  15321. ov.CityName
  15322. })
  15323. .ToListAsync();
  15324. if (areas.Any())
  15325. {
  15326. var items = dto.APTFeeDetails
  15327. .Select(item =>
  15328. {
  15329. var areaInfo = areas.FirstOrDefault(x => x.Id == item.OvId);
  15330. if (areaInfo == null) return null;
  15331. return areaInfo.CountryName == areaInfo.CityName
  15332. ? $"{areaInfo.CountryName}({item.Quote:#0.00} CNY)"
  15333. : $"{areaInfo.CountryName}-{areaInfo.CityName}({item.Quote:#0.00} CNY)";
  15334. })
  15335. .Where(item => item != null)
  15336. .ToList();
  15337. string areaLabel = $"接送机({string.Join("、", items)});";
  15338. label.AppendLine(areaLabel);
  15339. }
  15340. }
  15341. if (dto.PullCartFeeDetails.Any())
  15342. {
  15343. var amounts = dto.PullCartFeeDetails.Select(item => $"{item.Quote:#0.00}");
  15344. string subLabel = $"拉车({string.Join("、", amounts)});";
  15345. label.AppendLine(subLabel);
  15346. }
  15347. if (dto.TrainFeeDetails.Any())
  15348. {
  15349. var amounts = dto.TrainFeeDetails.Select(item => $"{item.Quote:#0.00}");
  15350. string subLabel = $"火车票({string.Join("、", amounts)});";
  15351. label.AppendLine(subLabel);
  15352. }
  15353. if (dto.CityAirTicketFeeDetails.Any())
  15354. {
  15355. var amounts = dto.CityAirTicketFeeDetails.Select(item => $"{item.Quote:#0.00}");
  15356. string subLabel = $"城市机票({string.Join("、", amounts)});";
  15357. label.AppendLine(subLabel);
  15358. }
  15359. //费用
  15360. decimal quote = (dto.APTFeeTotal + dto.PullCartFeeTotal + dto.TrainFeeTotal + dto.CityAirTicketFeeTotal).ConvertToDecimal1();
  15361. decimal jjcQuote = quote;
  15362. decimal gwcQuote = quote;
  15363. decimal tdcQuote = quote;
  15364. var view = new
  15365. {
  15366. label = label.ToString(),
  15367. jjcQuote,
  15368. gwcQuote,
  15369. tdcQuote
  15370. };
  15371. return Ok(JsonView(view));
  15372. }
  15373. #endregion
  15374. /// <summary>
  15375. /// 团组模块 - 出入境费用-草稿-移动端 - 创建
  15376. /// </summary>
  15377. /// <returns></returns>
  15378. [HttpPost]
  15379. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15380. public async Task<IActionResult> EnterExitCostDraftMobileCreate(EnterExitCostDraftMobileCreateDto dto)
  15381. {
  15382. if (string.IsNullOrEmpty(dto.DraftName)) return Ok(JsonView(false, "草稿名称为空!"));
  15383. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15384. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  15385. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.DraftName.Equals(dto.DraftName) && it.IsDel == 0);
  15386. if (eecInfo != null) return Ok(JsonView(false, "草稿名称重复!"));
  15387. var rateInfos = await EnterExitCostMobileGetCurrencyInit();
  15388. var info = new Grp_EnterExitCostDraft()
  15389. {
  15390. ProvinceId = dto.ProvinceId,
  15391. DraftName = dto.DraftName,
  15392. CurrencyRemark = CommonFun.GetCurrencyChinaToString(rateInfos),
  15393. CreateUserId = dto.CurrUserId
  15394. };
  15395. _sqlSugar.BeginTran();
  15396. var draftId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  15397. if (draftId < 1)
  15398. {
  15399. _sqlSugar.RollbackTran();
  15400. return Ok(JsonView(false, "草稿创建失败!"));
  15401. }
  15402. //添加默认权限
  15403. await _enterExitCostDraftRep.InitPerm(draftId, dto.CurrUserId);
  15404. _sqlSugar.CommitTran();
  15405. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(draftId, dto.CurrUserId);
  15406. var mobileInfo = new EnterExitCostDraftMobileParentInfoView();
  15407. mobileInfo.Id = draftId;
  15408. mobileInfo.DraftName = dto.DraftName;
  15409. mobileInfo.Currencys = rateInfos;
  15410. mobileInfo.IsAssignPerm = assignPerm;
  15411. return Ok(JsonView(mobileInfo));
  15412. }
  15413. /// <summary>
  15414. /// 出入境费用-草稿-移动端 查看编辑提示消息
  15415. /// </summary>
  15416. private static string _viewPermStr = $"未分配查看权限,如要查看,请联系市场部或国交部负责人!";
  15417. /// <summary>
  15418. /// 团组模块 - 出入境费用-草稿-移动端 - ParentInfo
  15419. /// </summary>
  15420. /// <returns></returns>
  15421. [HttpPost]
  15422. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15423. public async Task<IActionResult> EnterExitCostDraftMobileParentInfo(EnterExitCostDraftMobileParentInfoDto dto)
  15424. {
  15425. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  15426. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15427. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.Id == dto.DraftId && it.IsDel == 0);
  15428. var mobileInfo = new EnterExitCostDraftMobileParentInfoView();
  15429. mobileInfo.Currencys = await EnterExitCostMobileGetCurrencyInit();
  15430. if (eecInfo == null) return Ok(JsonView(mobileInfo));
  15431. //验证查看编辑权限
  15432. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  15433. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  15434. mobileInfo = _mapper.Map<EnterExitCostDraftMobileParentInfoView>(eecInfo);
  15435. mobileInfo.ProvinceId = eecInfo.ProvinceId;
  15436. mobileInfo.IsAssignPerm = assignPerm;
  15437. var dayAndCostData = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  15438. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  15439. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  15440. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId)
  15441. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  15442. {
  15443. ParentId = dac.ParentId,
  15444. SubId = dac.Id,
  15445. Type = dac.Type,
  15446. Days = dac.Days,
  15447. NationalTravelFeeId = dac.NationalTravelFeeId,
  15448. Arae = $"{ntf.Country}-{ntf.City}",
  15449. Cost = dac.Cost,
  15450. Currency = dac.Currency,
  15451. CurrencyName = sd.Name,
  15452. SubTotal = dac.SubTotal,
  15453. })
  15454. .ToList();
  15455. mobileInfo.ChoiceOneTotalCost = eecInfo.InsidePay;
  15456. mobileInfo.ChoiceTwoJJ = eecInfo.SumJJC;
  15457. mobileInfo.ChoiceTwoGW = eecInfo.SumGWC;
  15458. mobileInfo.ChoiceTwoTD = eecInfo.SumTDC;
  15459. mobileInfo.Currencys = !string.IsNullOrEmpty(eecInfo.CurrencyRemark) ? CommonFun.GetCurrencyChinaToList(eecInfo.CurrencyRemark) : mobileInfo.Currencys;
  15460. mobileInfo.ChoiceThreeTotalCost = dayAndCostData.Where(it => it.Type == 1).Sum(x => x.SubTotal); //住宿费 1
  15461. mobileInfo.ChoiceFourTotalCost = dayAndCostData.Where(it => it.Type == 2).Sum(x => x.SubTotal); //伙食费 2
  15462. mobileInfo.ChoiceFiveTotalCost = dayAndCostData.Where(it => it.Type == 3).Sum(x => x.SubTotal); //公杂费 3
  15463. mobileInfo.ChoiceSixTotalCost = dayAndCostData.Where(it => it.Type == 4).Sum(x => x.SubTotal); //培训费 4
  15464. //其他款项
  15465. var otherData = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>()
  15466. .LeftJoin<Sys_SetData>((dop, sd1) => dop.SetDataId == sd1.Id)
  15467. .LeftJoin<Sys_SetData>((dop, sd1, sd2) => dop.Currency == sd2.Id)
  15468. .Where((dop, sd1, sd2) => dop.IsDel == 0 && dop.ParentId == dto.DraftId)
  15469. .OrderBy((dop, sd1, sd2) => dop.Index)
  15470. .Select((dop, sd1, sd2) => new DayOtherPriceDraftMobileInfoView
  15471. {
  15472. ParentId = dop.ParentId,
  15473. SubId = dop.Id,
  15474. Index = dop.Index,
  15475. SetDataId = dop.SetDataId,
  15476. SetDataName = sd1.Name,
  15477. Cost = dop.Cost,
  15478. Currency = dop.Currency,
  15479. CurrencyName = sd2.Remark,
  15480. SubTotal = dop.SubTotal,
  15481. Remark = dop.Remark,
  15482. })
  15483. .ToArray();
  15484. mobileInfo.OtherExpensesTotalCost = otherData.Sum(x => x.SubTotal);
  15485. return Ok(mobileInfo);
  15486. }
  15487. /// <summary>
  15488. /// 团组模块 - 出入境费用-草稿-移动端 - SubInfo
  15489. /// </summary>
  15490. /// <returns></returns>
  15491. [HttpPost]
  15492. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15493. public async Task<IActionResult> EnterExitCostDraftMobileSubInfo(PostEnterExitCostDraftMobileSubInfoDto dto)
  15494. {
  15495. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  15496. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  15497. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15498. var subTypes = new List<int>() { 1, 2, 3, 4, 5, 6, 7 };
  15499. if (!subTypes.Contains(dto.SubType)) return Ok(JsonView(false, $"请传入有效的subTypeId!"));
  15500. //验证查看编辑权限
  15501. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  15502. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  15503. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.Id == dto.DraftId && it.IsDel == 0);
  15504. if (eecInfo == null) return Ok(JsonView(false, $"出入境费用明细未录入!"));
  15505. var subType = dto.SubType;
  15506. if (subType == 1) //1:境内费用
  15507. {
  15508. var oneData = new ChoiceOneMobileSubInfoView()
  15509. {
  15510. Id = eecInfo.Id,
  15511. ChoiceOne = eecInfo.ChoiceOne,
  15512. ChoiceOneTotalCost = eecInfo.InsidePay,
  15513. Visa = eecInfo.Visa,
  15514. VisaRemark = eecInfo.VisaRemark,
  15515. YiMiao = eecInfo.YiMiao,
  15516. HeSuan = eecInfo.HeSuan,
  15517. Service = eecInfo.Service,
  15518. Ticket = eecInfo.Ticket,
  15519. Safe = eecInfo.Safe,
  15520. FirstItemRemark = eecInfo.FirstItemRemark
  15521. };
  15522. return Ok(JsonView(oneData));
  15523. }
  15524. else if (subType == 2) //2:国际旅费
  15525. {
  15526. var twoData = new ChoiceTwoMobileSubInfoView()
  15527. {
  15528. Id = eecInfo.Id,
  15529. ChoiceTwoJJ = eecInfo.SumJJC,
  15530. OutsideJJPay = eecInfo.OutsideJJPay,
  15531. ChoiceTwoGW = eecInfo.SumGWC,
  15532. OutsideGWPay = eecInfo.OutsideGWPay,
  15533. ChoiceTwoTD = eecInfo.SumTDC,
  15534. OutsideTDPay = eecInfo.OutsideTDPay,
  15535. AirJJ = eecInfo.AirJJ,
  15536. AirGW = eecInfo.AirGW,
  15537. AirTD = eecInfo.AirTD,
  15538. CityTranffic = eecInfo.CityTranffic,
  15539. CityTranffic1 = eecInfo.CityTranffic1,
  15540. CityTranffic2 = eecInfo.CityTranffic2,
  15541. TwoItemRemark = eecInfo.TwoItemRemark
  15542. };
  15543. return Ok(JsonView(twoData));
  15544. }
  15545. else if (subType == 3) //3:住宿费
  15546. {
  15547. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  15548. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  15549. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  15550. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId && dac.Type == 1)
  15551. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  15552. {
  15553. ParentId = dac.ParentId,
  15554. SubId = dac.Id,
  15555. Type = dac.Type,
  15556. Days = dac.Days,
  15557. NationalTravelFeeId = dac.NationalTravelFeeId,
  15558. Arae = $"{ntf.Country}-{ntf.City}",
  15559. Cost = dac.Cost,
  15560. Currency = dac.Currency,
  15561. CurrencyName = sd.Name,
  15562. SubTotal = dac.SubTotal,
  15563. })
  15564. .ToArray();
  15565. var data = new ChoiceDraftMobileSubInfo3To6View()
  15566. {
  15567. ParentId = eecInfo.Id,
  15568. Choice = eecInfo.ChoiceThree,
  15569. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  15570. Details = dayAndCostDatas
  15571. };
  15572. return Ok(JsonView(data));
  15573. }
  15574. else if (subType == 4) //4:伙食费
  15575. {
  15576. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  15577. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  15578. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  15579. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId && dac.Type == 2)
  15580. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  15581. {
  15582. ParentId = dac.ParentId,
  15583. SubId = dac.Id,
  15584. Type = dac.Type,
  15585. Days = dac.Days,
  15586. NationalTravelFeeId = dac.NationalTravelFeeId,
  15587. Arae = $"{ntf.Country}-{ntf.City}",
  15588. Cost = dac.Cost,
  15589. Currency = dac.Currency,
  15590. CurrencyName = sd.Name,
  15591. SubTotal = dac.SubTotal,
  15592. })
  15593. .ToArray();
  15594. var data = new ChoiceDraftMobileSubInfo3To6View()
  15595. {
  15596. ParentId = eecInfo.Id,
  15597. Choice = eecInfo.ChoiceFour,
  15598. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  15599. Details = dayAndCostDatas
  15600. };
  15601. return Ok(JsonView(data));
  15602. }
  15603. else if (subType == 5) //5:公杂费
  15604. {
  15605. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  15606. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  15607. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  15608. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId && dac.Type == 3)
  15609. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  15610. {
  15611. ParentId = dac.ParentId,
  15612. SubId = dac.Id,
  15613. Type = dac.Type,
  15614. Days = dac.Days,
  15615. NationalTravelFeeId = dac.NationalTravelFeeId,
  15616. Arae = $"{ntf.Country}-{ntf.City}",
  15617. Cost = dac.Cost,
  15618. Currency = dac.Currency,
  15619. CurrencyName = sd.Name,
  15620. SubTotal = dac.SubTotal,
  15621. })
  15622. .ToArray();
  15623. var data = new ChoiceDraftMobileSubInfo3To6View()
  15624. {
  15625. ParentId = eecInfo.Id,
  15626. Choice = eecInfo.ChoiceFive,
  15627. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  15628. Details = dayAndCostDatas
  15629. };
  15630. return Ok(JsonView(data));
  15631. }
  15632. else if (subType == 6) //6:培训费
  15633. {
  15634. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  15635. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  15636. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  15637. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId && dac.Type == 4)
  15638. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  15639. {
  15640. ParentId = dac.ParentId,
  15641. SubId = dac.Id,
  15642. Type = dac.Type,
  15643. Days = dac.Days,
  15644. NationalTravelFeeId = dac.NationalTravelFeeId,
  15645. Arae = $"{ntf.Country}-{ntf.City}",
  15646. Cost = dac.Cost,
  15647. Currency = dac.Currency,
  15648. CurrencyName = sd.Name,
  15649. SubTotal = dac.SubTotal,
  15650. })
  15651. .ToArray();
  15652. var data = new ChoiceDraftMobileSubInfo3To6View()
  15653. {
  15654. ParentId = eecInfo.Id,
  15655. Choice = eecInfo.ChoiceSix,
  15656. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  15657. Details = dayAndCostDatas
  15658. };
  15659. return Ok(JsonView(data));
  15660. }
  15661. else if (subType == 7) //7:其他
  15662. {
  15663. //其他款项
  15664. var otherData = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>()
  15665. .LeftJoin<Sys_SetData>((dop, sd1) => dop.SetDataId == sd1.Id)
  15666. .LeftJoin<Sys_SetData>((dop, sd1, sd2) => dop.Currency == sd2.Id)
  15667. .Where((dop, sd1, sd2) => dop.IsDel == 0 && dop.ParentId == dto.DraftId)
  15668. .OrderBy((dop, sd1, sd2) => dop.Index)
  15669. .Select((dop, sd1, sd2) => new DayOtherPriceDraftMobileInfoView
  15670. {
  15671. ParentId = dop.ParentId,
  15672. SubId = dop.Id,
  15673. Index = dop.Index,
  15674. SetDataId = dop.SetDataId,
  15675. SetDataName = sd1.Name,
  15676. Cost = dop.Cost,
  15677. Currency = dop.Currency,
  15678. CurrencyName = sd2.Name,
  15679. SubTotal = dop.SubTotal,
  15680. Remark = dop.Remark,
  15681. })
  15682. .ToArray();
  15683. var data = new ChoiceSevenDraftMobileSubInfoView()
  15684. {
  15685. ParentId = eecInfo.Id,
  15686. OtherExpenses_Checked = eecInfo.OtherExpenses_Checked,
  15687. OtherExpensesTotalCost = otherData.Sum(x => x.SubTotal),
  15688. Details = otherData
  15689. };
  15690. return Ok(JsonView(data));
  15691. }
  15692. return Ok(JsonView(false));
  15693. }
  15694. #region op
  15695. ///// <summary>
  15696. ///// 移动端更新费用消息通知
  15697. ///// </summary>
  15698. ///// <param name="draftId"></param>
  15699. ///// <param name="id"></param>
  15700. ///// <param name="currUserId"></param>
  15701. //private async Task EnterExitCostDraftMobileOpNotice(int draftId, int id, int currUserId)
  15702. //{
  15703. // try
  15704. // {
  15705. // ////生成默认文件pdf并且通知人员
  15706. // //var fileView = await GeneralMethod.EnterExitCostDownload(new EnterExitCostDownloadDto()
  15707. // //{
  15708. // // DiId = draftId,
  15709. // // ExportType = 1,
  15710. // // SubTypeId = 1005
  15711. // //}, "pdf");
  15712. // ////发送通知
  15713. // //string fileUrl = (string)fileView.Data.GetType().GetProperty("Url").GetValue(fileView.Data, null);
  15714. // //string md5Sign = GeneralMethod.Encrypt($"{id}&fileName={fileUrl}");
  15715. // //string url = string.Format("http://oa.pan-american-intl.com:4399/#/Sankunginfo?sign={0}&fileName={1}", id, fileUrl);
  15716. // //await AppNoticeLibrary.SendUserMsg_GroupShare_ToGM(draftId, new List<string>() { "208", "233", "21" }, currUserId, url);
  15717. // ////汇率信息记录
  15718. // //await GeneralMethod.RateRecordSave(currUserId, id, "出入境费用");
  15719. // }
  15720. // catch (Exception ex)
  15721. // {
  15722. // //记录日志
  15723. // throw;
  15724. // }
  15725. //}
  15726. /// <summary>
  15727. /// 验证出入境费用数据是否存在
  15728. /// 不存在添加
  15729. /// </summary>
  15730. /// <param name="draftId"></param>
  15731. /// <param name="currUserId"></param>
  15732. /// <returns></returns>
  15733. /// <exception cref="CustomException"></exception>
  15734. private async Task<int> EnterExitCostDraftVerifyIsNull(int draftId, int currUserId)
  15735. {
  15736. var parentId = 0;
  15737. var info = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.IsDel == 0 && x.Id == draftId).OrderByDescending(x => x.CreateTime).FirstAsync();
  15738. if (info != null) parentId = info.Id;
  15739. else
  15740. {
  15741. var currencys = await EnterExitCostDraftMobileGetCurrencyInit();
  15742. int addId = await _sqlSugar.Insertable(new Grp_EnterExitCostDraft() { CreateUserId = currUserId, CurrencyRemark = JsonConvert.SerializeObject(currencys) }).ExecuteReturnIdentityAsync();
  15743. if (addId < 1) throw new CustomException("出入境费用添加失败!");
  15744. parentId = addId;
  15745. }
  15746. return parentId;
  15747. }
  15748. /// <summary>
  15749. /// 团组模块 - 出入境费用-草稿-移动端 - 查看权限用户
  15750. /// </summary>
  15751. /// <returns></returns>
  15752. [HttpPost]
  15753. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15754. public async Task<IActionResult> EnterExitCostDraftMobileViewPermissionUsers(EnterExitCostDraftMobileViewPermissionUsersDto dto)
  15755. {
  15756. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  15757. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15758. //验证查看权限
  15759. (bool isView, bool isSet) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  15760. if (!isView) return Ok(JsonView(false, _viewPermStr));
  15761. var userIds = await _sqlSugar
  15762. .Queryable<Grp_EnterExitCostDraftPermission>()
  15763. .Where(x => x.IsDel == 0 && x.DraftId == dto.DraftId)
  15764. .Select(x => x.UserId)
  15765. .ToArrayAsync();
  15766. var perUsers = await _enterExitCostDraftRep.PermissionViewUsersAsync();
  15767. var perUsersView = new List<dynamic>();
  15768. var feeBasePerm = AppSettingsHelper.Get<FeeBasePermView>("FeeBasePerm");
  15769. var viewPermissionData = new List<PermissionViewUserview>();
  15770. if (feeBasePerm.Any())
  15771. {
  15772. foreach (var item in feeBasePerm)
  15773. {
  15774. if (item.Users.Any())
  15775. {
  15776. viewPermissionData.AddRange(item.Users);
  15777. }
  15778. }
  15779. }
  15780. foreach (var item in perUsers)
  15781. {
  15782. bool isView1 = false;
  15783. if (userIds.Any(x => x == item.Id)) isView1 = true;
  15784. else if (viewPermissionData.Any(x => x.Id == dto.CurrUserId) && item.Id == dto.CurrUserId) isView1 = true;
  15785. perUsersView.Add(new { Id = item.Id, Name = item.Name, IsView = isView1 });
  15786. }
  15787. return Ok(JsonView(perUsersView));
  15788. }
  15789. /// <summary>
  15790. /// 团组模块 - 出入境费用-草稿-移动端 - 设置view权限
  15791. /// </summary>
  15792. /// <returns></returns>
  15793. [HttpPost]
  15794. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15795. public async Task<IActionResult> EnterExitCostDraftMobileSetViewPermissiion(EnterExitCostDraftMobileSetViewPermissiionDto dto)
  15796. {
  15797. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15798. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  15799. if (dto.UserIds.Length < 1) return Ok(JsonView(false, "请传入有效的userId;"));
  15800. //验证查看编辑权限
  15801. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  15802. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  15803. var permissions = new List<Grp_EnterExitCostDraftPermission>() { };
  15804. foreach (var userId in dto.UserIds)
  15805. {
  15806. permissions.Add(new Grp_EnterExitCostDraftPermission { Permission = 1, DraftId = dto.DraftId, UserId = userId, CreateUserId = dto.CurrUserId });
  15807. }
  15808. if (permissions.Any())
  15809. {
  15810. if (!permissions.Any(x => x.UserId == dto.CurrUserId))
  15811. {
  15812. permissions.Add(new Grp_EnterExitCostDraftPermission { Permission = 1, DraftId = dto.DraftId, UserId = dto.CurrUserId, CreateUserId = dto.CurrUserId });
  15813. }
  15814. _sqlSugar.BeginTran();
  15815. await _sqlSugar.Deleteable<Grp_EnterExitCostDraftPermission>().Where(it => it.DraftId == dto.DraftId).ExecuteCommandAsync();
  15816. var result = await _sqlSugar.Insertable(permissions).ExecuteCommandAsync();
  15817. if (result < 1)
  15818. {
  15819. _sqlSugar.RollbackTran();
  15820. return Ok(JsonView(false));
  15821. }
  15822. _sqlSugar.CommitTran();
  15823. return Ok(JsonView(true));
  15824. }
  15825. return Ok(JsonView(false));
  15826. }
  15827. /// <summary>
  15828. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 省份
  15829. /// </summary>
  15830. /// <returns></returns>
  15831. [HttpPost]
  15832. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15833. public async Task<IActionResult> EnterExitCostDraftMobileOpProv(EnterExitCostDraftMobileOpProvDto dto)
  15834. {
  15835. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  15836. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15837. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15838. if (dto.ProvinceId < 1) return Ok(JsonView(false, "请传入有效的省份Id!"));
  15839. int id = dto.DraftId;
  15840. if (id <= 0) //add
  15841. {
  15842. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  15843. var add = await _sqlSugar.Insertable(new Grp_EnterExitCostDraft() { ProvinceId = dto.ProvinceId, CreateUserId = dto.CurrUserId }).ExecuteCommandAsync();
  15844. if (add < 1) return Ok(JsonView(false));
  15845. id = add;
  15846. }
  15847. else //update
  15848. {
  15849. //验证查看编辑权限
  15850. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  15851. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  15852. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>().SetColumns(x => new Grp_EnterExitCostDraft() { ProvinceId = dto.ProvinceId }).Where(x => x.Id == dto.DraftId).ExecuteCommandAsync();
  15853. if (upd < 1) return Ok(JsonView(false));
  15854. }
  15855. return Ok(JsonView(new { parentId = id }));
  15856. }
  15857. /// <summary>
  15858. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 汇率
  15859. /// </summary>
  15860. /// <returns></returns>
  15861. [HttpPost]
  15862. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15863. public async Task<IActionResult> EnterExitCostDraftMobileOpRate(PostEnterExitCostDraftMobileFeeRateOpDto dto)
  15864. {
  15865. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  15866. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15867. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15868. if (dto.Currencys.Length < 1) return Ok(JsonView(false, "请传入有效的汇率信息!"));
  15869. var currencyStr = CommonFun.GetCurrencyChinaToString(dto.Currencys.ToList());
  15870. int id = dto.DraftId;
  15871. if (id <= 0) //add
  15872. {
  15873. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  15874. var add = await _sqlSugar.Insertable(new Grp_EnterExitCostDraft() { ProvinceId = dto.ProvinceId, CurrencyRemark = currencyStr, CreateUserId = dto.CurrUserId }).ExecuteCommandAsync();
  15875. if (add < 1) return Ok(JsonView(false));
  15876. id = add;
  15877. }
  15878. else //update
  15879. {
  15880. //验证查看编辑权限
  15881. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  15882. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  15883. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>().SetColumns(x => new Grp_EnterExitCostDraft() { CurrencyRemark = currencyStr }).Where(x => x.Id == dto.DraftId).ExecuteCommandAsync();
  15884. if (upd < 1) return Ok(JsonView(false));
  15885. }
  15886. #region 汇率变更时更改币种相关费用
  15887. var opDayCosts = new List<Grp_DayAndCostDraft>();
  15888. var opDayOtherCosts = new List<Grp_DayOtherPriceDraft>();
  15889. var eecCurrencys = dto.Currencys.Select(x => x.CurrencyCode.ToUpper()).ToList();
  15890. var dayCosts = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  15891. .LeftJoin<Sys_SetData>((dac, sd) => dac.Currency == sd.Id)
  15892. .Where((dac, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId)
  15893. .Select((dac, sd) => new
  15894. {
  15895. dac.Id,
  15896. dac.ParentId,
  15897. CurrencyCode = sd.Name,
  15898. dac.Cost
  15899. })
  15900. .ToList();
  15901. var dayOtherCosts = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>()
  15902. .LeftJoin<Sys_SetData>((dop, sd) => dop.Currency == sd.Id)
  15903. .Where((dop, sd) => dop.IsDel == 0 && dop.ParentId == dto.DraftId)
  15904. .Select((dop, sd) => new
  15905. {
  15906. dop.Id,
  15907. dop.ParentId,
  15908. CurrencyCode = sd.Name,
  15909. dop.Cost
  15910. })
  15911. .ToList();
  15912. if (dayCosts.Count > 0)
  15913. {
  15914. var new_dayCosts = dayCosts.Where(x => eecCurrencys.Contains(x.CurrencyCode.ToUpper())).GroupBy(x => x.CurrencyCode);
  15915. foreach (var dc in new_dayCosts)
  15916. {
  15917. var thisCurrency = dc.Key.ToUpper();
  15918. var thisRate = dto.Currencys.Where(x => x.CurrencyCode.ToUpper().Equals(thisCurrency)).First()?.Rate ?? 0.00M;
  15919. if (thisRate == 0.00M) continue;
  15920. foreach (var dcSub in dc)
  15921. {
  15922. opDayCosts.Add(new Grp_DayAndCostDraft()
  15923. {
  15924. Id = dcSub.Id,
  15925. ParentId = dcSub.ParentId,
  15926. Cost = dcSub.Cost,
  15927. SubTotal = dcSub.Cost * thisRate,
  15928. Remark = $"[移动端->汇率变更时费用变更][变更信息:currency:{thisCurrency}、opDatetime:{DateTime.Now:yyyy-MM-dd HH:mm:ss}、opUserId:{dto.CurrUserId}]"
  15929. });
  15930. }
  15931. }
  15932. if (opDayCosts.Count > 0)
  15933. {
  15934. await _sqlSugar.Updateable(opDayCosts).UpdateColumns(x => new { x.SubTotal, x.Remark }).WhereColumns(x => new { x.Id }).ExecuteCommandAsync();
  15935. }
  15936. }
  15937. if (dayOtherCosts.Count > 0)
  15938. {
  15939. var new_dayOtherCosts = dayOtherCosts.Where(x => eecCurrencys.Contains(x.CurrencyCode.ToUpper())).GroupBy(x => x.CurrencyCode);
  15940. foreach (var dc in new_dayOtherCosts)
  15941. {
  15942. var thisCurrency = dc.Key.ToUpper();
  15943. var thisRate = dto.Currencys.Where(x => x.CurrencyCode.ToUpper().Equals(thisCurrency)).First()?.Rate ?? 0.00M;
  15944. if (thisRate == 0.00M) continue;
  15945. foreach (var dcSub in dc)
  15946. {
  15947. opDayOtherCosts.Add(new Grp_DayOtherPriceDraft()
  15948. {
  15949. Id = dcSub.Id,
  15950. ParentId = dcSub.ParentId,
  15951. Cost = dcSub.Cost,
  15952. SubTotal = dcSub.Cost * thisRate,
  15953. // Remark = $"[移动端->汇率变更时费用变更][变更信息:currency:{thisCurrency}、opDatetime:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}、opUserId:{dto.CurrUserId}]"
  15954. });
  15955. }
  15956. }
  15957. if (opDayOtherCosts.Count > 0)
  15958. {
  15959. await _sqlSugar.Updateable(opDayOtherCosts).UpdateColumns(x => new { x.SubTotal }).WhereColumns(x => new { x.Id }).ExecuteCommandAsync();
  15960. }
  15961. }
  15962. #endregion
  15963. ////消息通知
  15964. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  15965. ////汇率信息记录
  15966. //await GeneralMethod.RateRecordSave(dto.CurrUserId, id, "出入境费用");
  15967. return Ok(JsonView(new { parentId = id }));
  15968. }
  15969. /// <summary>
  15970. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 复选框
  15971. /// </summary>
  15972. /// <returns></returns>
  15973. [HttpPost]
  15974. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15975. public async Task<IActionResult> EnterExitCostDraftMobileOpCheckbox(PostEnterExitCostDraftMobileFeeOpCheckboxDto dto)
  15976. {
  15977. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  15978. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  15979. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15980. var checkboxInfo = _mapper.Map<Grp_EnterExitCostDraft>(dto);
  15981. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  15982. int id = dto.DraftId;
  15983. if (id <= 0) //add
  15984. {
  15985. checkboxInfo.ProvinceId = dto.ProvinceId;
  15986. checkboxInfo.CreateUserId = dto.CurrUserId;
  15987. checkboxInfo.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostDraftMobileGetCurrencyInit());
  15988. var add = await _sqlSugar.Insertable(checkboxInfo).ExecuteCommandAsync();
  15989. if (add < 1) return Ok(JsonView(false));
  15990. }
  15991. else //update
  15992. {
  15993. var upd = await _sqlSugar.Updateable(checkboxInfo)
  15994. .UpdateColumns(x => new
  15995. {
  15996. x.ChoiceOne,
  15997. x.ChoiceTwo,
  15998. x.SumJJC,
  15999. x.SumGWC,
  16000. x.SumTDC,
  16001. x.ChoiceThree,
  16002. x.ChoiceFour,
  16003. x.ChoiceFive,
  16004. x.ChoiceSix,
  16005. x.OtherExpenses_Checked
  16006. })
  16007. .Where(x => x.Id == id)
  16008. .ExecuteCommandAsync();
  16009. if (upd < 1) return Ok(JsonView(false));
  16010. }
  16011. return Ok(JsonView(new { parentId = id }));
  16012. }
  16013. /// <summary>
  16014. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 3-7项复选框单个复选框
  16015. /// </summary>
  16016. /// <returns></returns>
  16017. [HttpPost]
  16018. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16019. public async Task<IActionResult> EnterExitCostDraftMobileOpSingleCheckbox(EnterExitCostDarftMobileOpSingleCheckboxDto dto)
  16020. {
  16021. int itemTypeId = dto.ItemType, currUserId = dto.CurrUserId, draftId = dto.DraftId, isSelected = dto.IsSelected;
  16022. var itemTypes = new List<int>() { 3, 4, 5, 6, 7 };
  16023. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  16024. if (draftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  16025. if (currUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16026. if (!itemTypes.Contains(itemTypeId)) return Ok(JsonView(false, $"请传入要修改的项类型;3:住宿费; 4:伙食费; 5:公杂费; 6:培训费;7:其他;"));
  16027. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  16028. var checkboxInfo = new Grp_EnterExitCostDraft()
  16029. {
  16030. Id = draftId,
  16031. ProvinceId = dto.ProvinceId,
  16032. CreateUserId = currUserId
  16033. };
  16034. if (itemTypeId == 3) checkboxInfo.ChoiceThree = isSelected;
  16035. else if (itemTypeId == 4) checkboxInfo.ChoiceFour = isSelected;
  16036. else if (itemTypeId == 5) checkboxInfo.ChoiceFive = isSelected;
  16037. else if (itemTypeId == 6) checkboxInfo.ChoiceSix = isSelected;
  16038. else if (itemTypeId == 7) checkboxInfo.OtherExpenses_Checked = isSelected;
  16039. if (draftId <= 0) //add
  16040. {
  16041. checkboxInfo.CreateUserId = dto.CurrUserId;
  16042. checkboxInfo.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  16043. var add = await _sqlSugar.Insertable(checkboxInfo).ExecuteCommandAsync();
  16044. if (add < 1) return Ok(JsonView(false));
  16045. }
  16046. else //update
  16047. {
  16048. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>()
  16049. .SetColumnsIF(itemTypeId == 3, it => it.ChoiceThree == isSelected)
  16050. .SetColumnsIF(itemTypeId == 4, it => it.ChoiceFour == isSelected)
  16051. .SetColumnsIF(itemTypeId == 5, it => it.ChoiceFive == isSelected)
  16052. .SetColumnsIF(itemTypeId == 6, it => it.ChoiceSix == isSelected)
  16053. .SetColumnsIF(itemTypeId == 7, it => it.OtherExpenses_Checked == isSelected)
  16054. .Where(x => x.Id == draftId)
  16055. .ExecuteCommandAsync();
  16056. if (upd < 1) return Ok(JsonView(false));
  16057. }
  16058. return Ok(JsonView(new { parentId = draftId }));
  16059. }
  16060. /// <summary>
  16061. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 境内费用 Step1
  16062. /// </summary>
  16063. /// <returns></returns>
  16064. [HttpPost]
  16065. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16066. public async Task<IActionResult> EnterExitCostDraftMobileOpStep1(PostEnterExitCostDraftMobileOpStep1Dto dto)
  16067. {
  16068. int id = dto.DraftId, currUserId = dto.CurrUserId;
  16069. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  16070. if (id < 1) return Ok(JsonView(false, MsgTips.DiId));
  16071. if (currUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16072. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  16073. var info = _mapper.Map<Grp_EnterExitCostDraft>(dto);
  16074. info.ProvinceId = dto.ProvinceId;
  16075. info.FirstItemRemark = dto.FirstItemRemark;
  16076. info.InsidePay = dto.Visa + dto.Service + dto.Safe + dto.Ticket + dto.HeSuan + dto.YiMiao;
  16077. if (id <= 0) //add
  16078. {
  16079. info.CreateUserId = dto.CurrUserId;
  16080. info.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  16081. var add = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  16082. if (add < 1) return Ok(JsonView(false));
  16083. id = add;
  16084. }
  16085. else //update
  16086. {
  16087. var upd = await _sqlSugar.Updateable(info)
  16088. .UpdateColumns(x => new
  16089. {
  16090. x.ChoiceOne,
  16091. x.InsidePay,
  16092. x.VisaRemark,
  16093. x.Visa,
  16094. x.Service,
  16095. x.Safe,
  16096. x.Ticket,
  16097. x.HeSuan,
  16098. x.YiMiao,
  16099. x.FirstItemRemark
  16100. })
  16101. .Where(x => x.Id == id)
  16102. .ExecuteCommandAsync();
  16103. if (upd < 1) return Ok(JsonView(false));
  16104. }
  16105. ////消息通知
  16106. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  16107. return Ok(JsonView(new { parentId = id, itemTotal = info.InsidePay }));
  16108. }
  16109. /// <summary>
  16110. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 国际旅费 Step2
  16111. /// </summary>
  16112. /// <returns></returns>
  16113. [HttpPost]
  16114. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16115. public async Task<IActionResult> EnterExitCostDraftMobileOpStep2(PostEnterExitCostDraftMobileOpStep2Dto dto)
  16116. {
  16117. int id = dto.DraftId;
  16118. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  16119. if (id < 1) return Ok(JsonView(false, MsgTips.DiId));
  16120. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16121. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  16122. var info = _mapper.Map<Grp_EnterExitCostDraft>(dto);
  16123. info.ProvinceId = dto.ProvinceId;
  16124. info.OutsideJJPay = dto.OutsideJJPay;
  16125. info.OutsideGWPay = dto.OutsideGWPay;
  16126. info.OutsideTDPay = dto.OutsideTDPay;
  16127. info.AirJJ = dto.AirJJ;
  16128. info.AirGW = dto.AirGW;
  16129. info.AirTD = dto.AirTD;
  16130. info.CityTranffic = dto.CityTranffic;
  16131. info.CityTranffic1 = dto.CityTranffic1;
  16132. info.CityTranffic2 = dto.CityTranffic2;
  16133. info.TwoItemRemark = dto.TwoItemRemark;
  16134. info.SumJJC = dto.ChoiceTwoJJ;
  16135. info.SumGWC = dto.ChoiceTwoGW;
  16136. info.SumTDC = dto.ChoiceTwoTD;
  16137. decimal jjcItemTotal = 0.00M, gwcItemTotal = 0.00M, tdcItemTotal = 0.00M;
  16138. if (id <= 0) //add
  16139. {
  16140. info.CreateUserId = dto.CurrUserId;
  16141. info.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  16142. var addId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  16143. if (addId <= 0) return Ok(JsonView(false));
  16144. id = addId;
  16145. }
  16146. else //update
  16147. {
  16148. var upd = await _sqlSugar.Updateable(info)
  16149. .UpdateColumns(x => new
  16150. {
  16151. x.SumJJC,
  16152. x.OutsideJJPay,
  16153. x.SumGWC,
  16154. x.OutsideGWPay,
  16155. x.SumTDC,
  16156. x.OutsideTDPay,
  16157. x.AirJJ,
  16158. x.AirGW,
  16159. x.AirTD,
  16160. x.CityTranffic,
  16161. x.CityTranffic1,
  16162. x.CityTranffic2,
  16163. x.TwoItemRemark
  16164. })
  16165. .Where(x => x.Id == id)
  16166. .ExecuteCommandAsync();
  16167. if (upd < 1) return Ok(JsonView(false));
  16168. }
  16169. jjcItemTotal = info.AirJJ + info.CityTranffic;
  16170. gwcItemTotal = info.AirGW + info.CityTranffic;
  16171. tdcItemTotal = info.AirTD + info.CityTranffic;
  16172. ////消息通知
  16173. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  16174. return Ok(JsonView(new
  16175. {
  16176. parentId = id,
  16177. choiceTwoJJ = dto.ChoiceTwoJJ,
  16178. jjcItemTotal = jjcItemTotal,
  16179. choiceTwoGW = dto.ChoiceTwoGW,
  16180. gwcItemTotal = gwcItemTotal,
  16181. choiceTwoTD = dto.ChoiceTwoTD,
  16182. tdcItemTotal = tdcItemTotal
  16183. }));
  16184. }
  16185. /// <summary>
  16186. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 批量(住宿、伙食、公杂、培训) Step3-Step6
  16187. /// </summary>
  16188. /// <returns></returns>
  16189. [HttpPost]
  16190. [ApiExplorerSettings(IgnoreApi = true)]
  16191. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16192. public async Task<IActionResult> EnterExitCostDraftMobileOpBatchStep3To6(PostEnterExitCostDraftMobileOpStep3To6Dto dto)
  16193. {
  16194. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  16195. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  16196. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16197. if (dto.Infos.Length < 1) return Ok(JsonView(false, "请传入有效的费用信息!"));
  16198. var feeTypeIds = new List<int>() { 1, 2, 3, 4, };
  16199. if (!feeTypeIds.Contains(dto.FeeType)) return Ok(JsonView(false, "请传入有效的费用类型!"));
  16200. var infos1 = _mapper.Map<List<Grp_DayAndCostDraft>>(dto.Infos);
  16201. var infos = infos1.Select(x => new Grp_DayAndCostDraft
  16202. {
  16203. Id = x.Id,
  16204. ParentId = dto.DraftId,
  16205. Type = dto.FeeType,
  16206. Days = x.Days,
  16207. NationalTravelFeeId = x.NationalTravelFeeId,
  16208. Cost = x.Cost,
  16209. Currency = x.Currency,
  16210. SubTotal = x.SubTotal,
  16211. CreateUserId = dto.CurrUserId
  16212. })
  16213. .ToList();
  16214. var adds = infos.Where(x => x.Id <= 0).ToList();
  16215. var upds = infos.Where(x => x.Id > 0).ToList();
  16216. if (adds.Count > 0)
  16217. {
  16218. var add = await _sqlSugar.Insertable(adds).ExecuteCommandAsync();
  16219. if (add < 1) return Ok(JsonView(false));
  16220. }
  16221. if (upds.Count > 0)
  16222. {
  16223. var upd = await _sqlSugar.Updateable(adds)
  16224. .UpdateColumns(x => new
  16225. {
  16226. x.Days,
  16227. x.NationalTravelFeeId,
  16228. x.Cost,
  16229. x.Currency,
  16230. x.SubTotal
  16231. })
  16232. .WhereColumns(x => new { x.Id })
  16233. .ExecuteCommandAsync();
  16234. if (upd < 1) return Ok(JsonView(false));
  16235. }
  16236. var itemTotal = _sqlSugar.Queryable<Grp_DayAndCostDraft>().Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId && x.Type == dto.FeeType).Sum(x => x.SubTotal);
  16237. ////消息通知
  16238. //var id = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId).First()?.Id ?? 0;
  16239. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  16240. return Ok(JsonView(new { itemTotal = itemTotal }));
  16241. }
  16242. /// <summary>
  16243. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 单条(住宿、伙食、公杂、培训) Step3-Step6
  16244. /// </summary>
  16245. /// <returns></returns>
  16246. [HttpPost]
  16247. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16248. public async Task<IActionResult> EnterExitCostDraftMobileOpSingleStep3To6(PostEnterExitCostDraftMobileOpSingleStep3To6Dto dto)
  16249. {
  16250. var feeTypeIds = new List<int>() { 3, 4, 5, 6 };
  16251. int subId = dto.SubId, feeType = dto.FeeType;
  16252. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  16253. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  16254. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16255. if (!feeTypeIds.Contains(dto.FeeType)) return Ok(JsonView(false, "请传入有效的费用类型!"));
  16256. var subInfo = _mapper.Map<Grp_DayAndCostDraft>(dto);
  16257. subInfo.Id = subId;
  16258. subInfo.ParentId = dto.DraftId;
  16259. if (feeType == 3) subInfo.Type = 1;
  16260. else if (feeType == 4) subInfo.Type = 2;
  16261. else if (feeType == 5) subInfo.Type = 3;
  16262. else if (feeType == 6) subInfo.Type = 4;
  16263. subInfo.CreateUserId = dto.CurrUserId;
  16264. int parentId = await EnterExitCostDraftVerifyIsNull(dto.DraftId, dto.CurrUserId); //主表验证
  16265. if (parentId < 1) return Ok(JsonView(false));
  16266. //子表op
  16267. if (subId < 1)
  16268. {
  16269. var subAdd = await _sqlSugar.Insertable(subInfo).ExecuteCommandAsync();
  16270. if (subAdd < 1) return Ok(JsonView(false));
  16271. }
  16272. else
  16273. {
  16274. var subUpd = await _sqlSugar.Updateable(subInfo)
  16275. .UpdateColumns(x => new
  16276. {
  16277. x.Days,
  16278. x.NationalTravelFeeId,
  16279. x.Cost,
  16280. x.Currency,
  16281. x.SubTotal
  16282. })
  16283. .WhereColumns(x => new { x.Id })
  16284. .ExecuteCommandAsync();
  16285. if (subUpd < 1) return Ok(JsonView(false));
  16286. }
  16287. var itemTotal = _sqlSugar.Queryable<Grp_DayAndCostDraft>().Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId && x.Type == feeType).Sum(x => x.SubTotal);
  16288. return Ok(JsonView(new { parentId = parentId, itemTotal = itemTotal }));
  16289. }
  16290. /// <summary>
  16291. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 其他费用-批量 Step7
  16292. /// </summary>
  16293. /// <returns></returns>
  16294. [HttpPost]
  16295. [ApiExplorerSettings(IgnoreApi = true)]
  16296. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16297. public async Task<IActionResult> EnterExitCostDraftMobileOpBatchStep7(PostEnterExitCostDraftMobileOpStep7Dto dto)
  16298. {
  16299. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  16300. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  16301. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16302. var infos1 = _mapper.Map<List<Grp_DayOtherPriceDraft>>(dto.Infos);
  16303. var infos = infos1.Select(x => new Grp_DayOtherPriceDraft()
  16304. {
  16305. Id = x.Id,
  16306. ParentId = dto.DraftId,
  16307. SetDataId = x.SetDataId,
  16308. Index = x.Index,
  16309. Cost = x.Cost,
  16310. Currency = x.Currency,
  16311. SubTotal = x.SubTotal,
  16312. CreateUserId = dto.CurrUserId,
  16313. Remark = x.Remark
  16314. }).ToList();
  16315. var adds = infos.Where(x => x.Id <= 0).ToList();
  16316. var upds = infos.Where(x => x.Id > 0).ToList();
  16317. if (adds.Count > 0)
  16318. {
  16319. var add = await _sqlSugar.Insertable(adds).ExecuteCommandAsync();
  16320. if (add < 1) return Ok(JsonView(false));
  16321. }
  16322. if (upds.Count > 0)
  16323. {
  16324. var upd = await _sqlSugar.Updateable(adds)
  16325. .UpdateColumns(x => new
  16326. {
  16327. x.Index,
  16328. x.SetDataId,
  16329. x.Cost,
  16330. x.Currency,
  16331. x.SubTotal,
  16332. x.Remark
  16333. })
  16334. .WhereColumns(x => new { x.Id })
  16335. .ExecuteCommandAsync();
  16336. if (upd < 1) return Ok(JsonView(false));
  16337. }
  16338. var itemTotal = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>().Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId).Sum(x => x.SubTotal);
  16339. //消息通知
  16340. //var id = _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.IsDel == 0 && x.Id == dto.DraftId).First()?.Id ?? 0;
  16341. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  16342. return Ok(JsonView(new { itemTotal = itemTotal }));
  16343. }
  16344. /// <summary>
  16345. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 其他费用-单条 Step7
  16346. /// </summary>
  16347. /// <returns></returns>
  16348. [HttpPost]
  16349. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16350. public async Task<IActionResult> EnterExitCostDraftMobileOpSingleStep7(PostEnterExitCostDraftMobileOpSingleStep7Dto dto)
  16351. {
  16352. int subId = dto.SubId, id = dto.DraftId;
  16353. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  16354. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  16355. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16356. var subInfo = _mapper.Map<Grp_DayOtherPriceDraft>(dto);
  16357. subInfo.Id = subId;
  16358. subInfo.ParentId = id;
  16359. subInfo.CreateUserId = dto.CurrUserId;
  16360. int parentId = await EnterExitCostDraftVerifyIsNull(id, dto.CurrUserId); //主表验证
  16361. if (parentId < 1) return Ok(JsonView(false));
  16362. #region 子表op
  16363. if (subId < 1)//add
  16364. {
  16365. var subAdd = await _sqlSugar.Insertable(subInfo).ExecuteCommandAsync();
  16366. if (subAdd < 1) return Ok(JsonView(false));
  16367. }
  16368. else //upd
  16369. {
  16370. var subUpd = await _sqlSugar.Updateable(subInfo)
  16371. .UpdateColumns(x => new
  16372. {
  16373. x.Index,
  16374. x.SetDataId,
  16375. x.Cost,
  16376. x.Currency,
  16377. x.SubTotal,
  16378. x.Remark
  16379. })
  16380. .WhereColumns(x => new { x.Id })
  16381. .ExecuteCommandAsync();
  16382. if (subUpd < 1) return Ok(JsonView(false));
  16383. }
  16384. #endregion
  16385. var itemTotal = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>().Where(x => x.IsDel == 0 && x.ParentId == id).Sum(x => x.SubTotal);
  16386. ////消息通知
  16387. //await EnterExitCostMobileOpNotice(dto.Diid, parentId, dto.CurrUserId);
  16388. return Ok(JsonView(new { parentId = parentId, itemTotal = itemTotal }));
  16389. }
  16390. /// <summary>
  16391. /// 团组模块 - 出入境费用-草稿-移动端 - 3-6子项删除
  16392. /// </summary>
  16393. /// <returns></returns>
  16394. [HttpPost]
  16395. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16396. public async Task<IActionResult> EnterExitCostDraftMobileSubItemDel(EnterExitCostDraftSubItemDelDto dto)
  16397. {
  16398. var data = await _enterExitCostDraftRep.EnterExitCostDraftSubItemDel(dto);
  16399. if (data.Code != 0)
  16400. {
  16401. return Ok(JsonView(false, data.Msg));
  16402. }
  16403. return Ok(JsonView(true, "操作成功!", data.Data));
  16404. }
  16405. /// <summary>
  16406. /// 团组模块 - 出入境费用-草稿-移动端 - 其他费用删除
  16407. /// </summary>
  16408. /// <param name="dto"></param>
  16409. /// <returns></returns>
  16410. [HttpPost]
  16411. public IActionResult EnterExitCostDraftMobileOtherFeeDel(EnterExitCostDraftSubItemDelDto dto)
  16412. {
  16413. var data = new Grp_DayOtherPriceDraft()
  16414. {
  16415. Id = dto.Id,
  16416. IsDel = 1,
  16417. DeleteUserId = dto.DeleteUserId,
  16418. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  16419. };
  16420. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  16421. if (del > 0) return Ok(JsonView(true, "删除成功!"));
  16422. return Ok(JsonView(false, "删除失败!"));
  16423. }
  16424. #endregion
  16425. #endregion
  16426. #region 团组经理模块 出入境费用报价表
  16427. /// <summary>
  16428. /// 团组模块 - 出入境费用报价表 - 初始化数据源(币种类型)
  16429. /// </summary>
  16430. /// <returns></returns>
  16431. [HttpPost]
  16432. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16433. public async Task<IActionResult> EnterExitCostQuoteInitData(PortDtoBase dto)
  16434. {
  16435. var initRates = await GeneralMethod.EnterExitCostInitRate();
  16436. var liveRates = await GeneralMethod.EnterExitCostLiveRate();
  16437. var cnyInfo = new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.0000M };
  16438. initRates.Insert(0, cnyInfo);
  16439. liveRates.Insert(0, cnyInfo);
  16440. return Ok(JsonView(true, "查询成功!", new
  16441. {
  16442. InitRates = initRates,
  16443. LiveRates = liveRates
  16444. }));
  16445. }
  16446. /// <summary>
  16447. /// 团组模块 - 出入境费用报价表 - 报价表名称列表
  16448. /// </summary>
  16449. /// <returns></returns>
  16450. [HttpPost]
  16451. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16452. public async Task<IActionResult> EnterExitCostQuoteNameList(EnterExitCostQuoteNameListDto dto)
  16453. {
  16454. return Ok(await _enterExitCostQuoteRep.QuoteNameListAsync(dto));
  16455. }
  16456. /// <summary>
  16457. /// 团组模块 - 出入境费用报价表 - 团组名称列表
  16458. /// </summary>
  16459. /// <returns></returns>
  16460. [HttpPost]
  16461. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16462. public async Task<IActionResult> EnterExitCostQuoteGroupNameList(EnterExitCostQuoteGroupNameListDto dto)
  16463. {
  16464. return Ok(await _enterExitCostQuoteRep.GroupNameListAsync(dto));
  16465. }
  16466. /// <summary>
  16467. /// 团组模块 - 出入境费用报价表 - 根据团组Id获出入境费用相关信息
  16468. /// </summary>
  16469. /// <returns></returns>
  16470. [HttpPost]
  16471. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16472. public async Task<IActionResult> EnterExitCostQuoteEntryExitCosts(EnterExitCostInfobyDiIdDto dto)
  16473. {
  16474. int groupId = dto.DiId,
  16475. currUserId = dto.CurrUserId;
  16476. if (groupId < 1) return Ok(JsonView(false, "请传入有效的GroupId;"));
  16477. if (currUserId < 1) return Ok(JsonView(false, "请传入有效的CurrUserId;"));
  16478. //验证报价数据是否存在
  16479. var isNull = await _sqlSugar.Queryable<Grp_EnterExitCostQuote>().FirstAsync(x => x.IsDel == 0 && x.GroupId == dto.DiId);
  16480. if (isNull != null)
  16481. {
  16482. var info1 = await _enterExitCostQuoteRep.InfoAsync(new EnterExitCostQuoteInfoDto() { Id = isNull.Id });
  16483. if (!info1.Rates.Any())
  16484. {
  16485. var rates = await GeneralMethod.EnterExitCostInitRate();
  16486. rates.Insert(0, new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
  16487. info1.Rates = rates.ToArray();
  16488. }
  16489. return Ok(JsonView(info1));
  16490. }
  16491. var result = await _enterExitCostQuoteRep.InfoByGroupIdAsync(dto.DiId);
  16492. result.GroupId = groupId;
  16493. //处理报价名称
  16494. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.DiId && x.IsDel == 0);
  16495. if (groupInfo != null)
  16496. {
  16497. var visitCountry = groupInfo.VisitCountry;
  16498. if (!string.IsNullOrEmpty(visitCountry))
  16499. {
  16500. string quoteName = string.Empty;
  16501. if (visitCountry.Contains("|"))
  16502. {
  16503. var countrys = visitCountry.Split("|");
  16504. quoteName = string.Join("、", countrys);
  16505. }
  16506. else quoteName = visitCountry;
  16507. quoteName += $"团组报价表";
  16508. result.Name = quoteName;
  16509. }
  16510. }
  16511. var info = await _enterExitCostRep.GetEnterExitCostInfoByDiId(dto);
  16512. if (info.Code != StatusCodes.Status200OK)
  16513. {
  16514. if (!result.Rates.Any())
  16515. {
  16516. var rates = await GeneralMethod.EnterExitCostInitRate();
  16517. result.Rates = rates.ToArray();
  16518. }
  16519. return Ok(JsonView(true, $"出入境费用明细未填写!", result));
  16520. }
  16521. var infoView = info.Data as EnterExitCostInfoView;
  16522. if (infoView == null) return Ok(JsonView(false, "数据类型转换失败!;"));
  16523. var countryFees = await _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x => x.IsDel == 0).ToListAsync();
  16524. var cityFilter = new List<string>() { "全部城市", "其他城市" };
  16525. var currencys = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToListAsync();
  16526. var eecRates = infoView.Currencys;
  16527. //默认添加人名币
  16528. if (!eecRates.Any(x => x.CurrencyCode.Equals("CNY")))
  16529. {
  16530. eecRates.Insert(0, new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
  16531. }
  16532. //处理团组人数
  16533. int pplNum = 1;
  16534. if (groupInfo != null) pplNum = groupInfo.VisitPNumber;
  16535. var views = new List<QuoteSubItemInfo>();
  16536. #region 数据填充
  16537. var intTravelCosts = new List<QuoteSubItemInfo>();
  16538. #region 机票费用 1354
  16539. int intTravelIndex = 1;
  16540. if (infoView.SumJJC == 1)
  16541. {
  16542. intTravelCosts.Add(new QuoteSubItemInfo
  16543. {
  16544. ItemId = 1354,
  16545. Index = intTravelIndex,
  16546. FeeName = "经济舱",
  16547. UnitPrice = infoView.AirJJ,
  16548. Currency = "CNY",
  16549. Quantity = 1,
  16550. PplNum = 1,
  16551. TotalAmt = infoView.AirJJ,
  16552. Remark = "",
  16553. });
  16554. intTravelIndex++;
  16555. }
  16556. if (infoView.SumGWC == 1)
  16557. {
  16558. intTravelCosts.Add(new QuoteSubItemInfo
  16559. {
  16560. ItemId = 1354,
  16561. Index = intTravelIndex,
  16562. FeeName = "公务舱",
  16563. UnitPrice = infoView.AirGW,
  16564. Currency = "CNY",
  16565. Quantity = 1,
  16566. PplNum = 1,
  16567. TotalAmt = infoView.AirGW,
  16568. Remark = "",
  16569. });
  16570. intTravelIndex++;
  16571. }
  16572. if (infoView.SumTDC == 1)
  16573. {
  16574. intTravelCosts.Add(new QuoteSubItemInfo
  16575. {
  16576. ItemId = 1354,
  16577. Index = intTravelIndex,
  16578. FeeName = "头等舱",
  16579. UnitPrice = infoView.AirTD,
  16580. Currency = "CNY",
  16581. Quantity = 1,
  16582. PplNum = 1,
  16583. TotalAmt = infoView.AirTD,
  16584. Remark = "",
  16585. });
  16586. intTravelIndex++;
  16587. }
  16588. intTravelCosts.Add(new QuoteSubItemInfo
  16589. {
  16590. ItemId = 1354,
  16591. Index = intTravelIndex,
  16592. FeeName = "城市间交通费用(经济舱)",
  16593. UnitPrice = infoView.CityTranffic,
  16594. Currency = "CNY",
  16595. Quantity = 1,
  16596. PplNum = pplNum,
  16597. TotalAmt = infoView.CityTranffic * pplNum,
  16598. Remark = "",
  16599. });
  16600. intTravelCosts.Add(new QuoteSubItemInfo
  16601. {
  16602. ItemId = 1354,
  16603. Index = intTravelIndex,
  16604. FeeName = "城市间交通费用(公务舱)",
  16605. UnitPrice = infoView.CityTranffic1,
  16606. Currency = "CNY",
  16607. Quantity = 1,
  16608. PplNum = pplNum,
  16609. TotalAmt = infoView.CityTranffic1 * pplNum,
  16610. Remark = "",
  16611. });
  16612. intTravelCosts.Add(new QuoteSubItemInfo
  16613. {
  16614. ItemId = 1354,
  16615. Index = intTravelIndex,
  16616. FeeName = "城市间交通费用(头等舱)",
  16617. UnitPrice = infoView.CityTranffic2,
  16618. Currency = "CNY",
  16619. Quantity = 1,
  16620. PplNum = pplNum,
  16621. TotalAmt = infoView.CityTranffic2 * pplNum,
  16622. Remark = "",
  16623. });
  16624. views.AddRange(intTravelCosts);
  16625. #endregion
  16626. var accomCosts = new List<QuoteSubItemInfo>();
  16627. #region 住宿费 1355
  16628. if (infoView.QuarterageData.Any())
  16629. {
  16630. int accomIndex = 1;
  16631. int accomItemTypeId = 1355;
  16632. var groupData = infoView.QuarterageData.GroupBy(x => x.NationalTravelFeeId);
  16633. foreach (var item in groupData)
  16634. {
  16635. string feeName = string.Empty;
  16636. var countryInfo = countryFees.FirstOrDefault(x => x.Id == item.Key);
  16637. if (countryInfo != null)
  16638. {
  16639. feeName = countryInfo.Country;
  16640. var city = countryInfo.City;
  16641. if (!string.IsNullOrEmpty(city) && cityFilter.Any(x => !x.Contains(city)))
  16642. {
  16643. feeName += $"-{city}";
  16644. }
  16645. }
  16646. var hotelInfo = item.FirstOrDefault();
  16647. if (hotelInfo == null) continue;
  16648. var thisCurrency = currencys.FirstOrDefault(x => x.Id == hotelInfo.Currency)?.Name ?? "nuknow";
  16649. var thisRate = eecRates.FirstOrDefault(x => x.CurrencyCode.Equals(thisCurrency))?.Rate ?? 1.0000M;
  16650. int quantity = item.ToList().Count;
  16651. accomCosts.Add(new QuoteSubItemInfo
  16652. {
  16653. ItemId = accomItemTypeId,
  16654. Index = accomIndex,
  16655. FeeName = feeName,
  16656. UnitPrice = hotelInfo.Cost,
  16657. Currency = thisCurrency,
  16658. Quantity = quantity,
  16659. PplNum = pplNum,
  16660. TotalAmt = hotelInfo.Cost * thisRate * quantity * pplNum,
  16661. Remark = "",
  16662. });
  16663. accomIndex++;
  16664. }
  16665. views.AddRange(accomCosts);
  16666. }
  16667. #endregion
  16668. var mealCosts = new List<QuoteSubItemInfo>();
  16669. #region 餐饮费 1356
  16670. if (infoView.BoardWagesData.Any())
  16671. {
  16672. var mealIndex = 1;
  16673. int mealItemTypeId = 1356;
  16674. var groupData = infoView.BoardWagesData.GroupBy(x => x.NationalTravelFeeId);
  16675. foreach (var item in groupData)
  16676. {
  16677. string feeName = string.Empty;
  16678. var countryInfo = countryFees.FirstOrDefault(x => x.Id == item.Key);
  16679. if (countryInfo != null)
  16680. {
  16681. feeName = countryInfo.Country;
  16682. var city = countryInfo.City;
  16683. if (!string.IsNullOrEmpty(city) && cityFilter.Any(x => !x.Contains(city)))
  16684. {
  16685. feeName += $"-{city}";
  16686. }
  16687. }
  16688. var mealInfo = item.FirstOrDefault();
  16689. if (mealInfo == null) continue;
  16690. var thisCurrency = currencys.FirstOrDefault(x => x.Id == mealInfo.Currency)?.Name ?? "nuknow";
  16691. var thisRate = eecRates.FirstOrDefault(x => x.CurrencyCode.Equals(thisCurrency))?.Rate ?? 1.0000M;
  16692. int quantity = item.ToList().Count;
  16693. mealCosts.Add(new QuoteSubItemInfo
  16694. {
  16695. ItemId = mealItemTypeId,
  16696. Index = mealIndex,
  16697. FeeName = feeName,
  16698. UnitPrice = mealInfo.Cost,
  16699. Currency = thisCurrency,
  16700. Quantity = quantity,
  16701. PplNum = pplNum,
  16702. TotalAmt = mealInfo.Cost * thisRate * quantity * pplNum,
  16703. Remark = "",
  16704. });
  16705. mealIndex++;
  16706. }
  16707. views.AddRange(mealCosts);
  16708. }
  16709. #endregion
  16710. var miscCosts = new List<QuoteSubItemInfo>();
  16711. #region 公杂费 1364
  16712. if (infoView.MiscellaneousFeeData.Any())
  16713. {
  16714. var miscIndex = 1;
  16715. int miscItemTypeId = 1364;
  16716. var groupData = infoView.MiscellaneousFeeData.GroupBy(x => x.NationalTravelFeeId);
  16717. foreach (var item in groupData)
  16718. {
  16719. string feeName = string.Empty;
  16720. var countryInfo = countryFees.FirstOrDefault(x => x.Id == item.Key);
  16721. if (countryInfo != null)
  16722. {
  16723. feeName = countryInfo.Country;
  16724. var city = countryInfo.City;
  16725. if (!string.IsNullOrEmpty(city) && cityFilter.Any(x => !x.Contains(city)))
  16726. {
  16727. feeName += $"-{city}";
  16728. }
  16729. }
  16730. var miscInfo = item.FirstOrDefault();
  16731. if (miscInfo == null) continue;
  16732. var thisCurrency = currencys.FirstOrDefault(x => x.Id == miscInfo.Currency)?.Name ?? "nuknow";
  16733. var thisRate = eecRates.FirstOrDefault(x => x.CurrencyCode.Equals(thisCurrency))?.Rate ?? 1.0000M;
  16734. int quantity = item.ToList().Count;
  16735. miscCosts.Add(new QuoteSubItemInfo
  16736. {
  16737. ItemId = miscItemTypeId,
  16738. Index = miscIndex,
  16739. FeeName = feeName,
  16740. UnitPrice = miscInfo.Cost,
  16741. Currency = thisCurrency,
  16742. Quantity = quantity,
  16743. PplNum = pplNum,
  16744. TotalAmt = miscInfo.Cost * thisRate * quantity * pplNum,
  16745. Remark = "",
  16746. });
  16747. miscIndex++;
  16748. }
  16749. views.AddRange(miscCosts);
  16750. }
  16751. #endregion
  16752. #region 签证+保险 1362
  16753. int visaInsIndex = 1;
  16754. int visaInsItemTypeId = 1362;
  16755. if (infoView.Visa > 0)
  16756. {
  16757. views.Add(new QuoteSubItemInfo()
  16758. {
  16759. ItemId = visaInsItemTypeId,
  16760. Index = visaInsIndex,
  16761. FeeName = $"签证",
  16762. UnitPrice = infoView.Visa,
  16763. Currency = $"CNY",
  16764. Quantity = 1,
  16765. PplNum = pplNum,
  16766. TotalAmt = infoView.Visa * pplNum,
  16767. Remark = "",
  16768. });
  16769. visaInsIndex++;
  16770. }
  16771. if (infoView.Safe > 0)
  16772. {
  16773. views.Add(new QuoteSubItemInfo()
  16774. {
  16775. ItemId = visaInsItemTypeId,
  16776. Index = visaInsIndex,
  16777. FeeName = $"保险",
  16778. UnitPrice = infoView.Safe,
  16779. Currency = $"CNY",
  16780. Quantity = 1,
  16781. PplNum = pplNum,
  16782. TotalAmt = infoView.Safe * pplNum,
  16783. Remark = "",
  16784. });
  16785. }
  16786. #endregion
  16787. #region 服务费 1363
  16788. int serviceFeeIndex = 1;
  16789. int serviceFeeItemTypeId = 1363;
  16790. if (infoView.Service > 0)
  16791. {
  16792. views.Add(new QuoteSubItemInfo()
  16793. {
  16794. ItemId = serviceFeeItemTypeId,
  16795. Index = serviceFeeIndex,
  16796. FeeName = $"服务费",
  16797. UnitPrice = infoView.Service,
  16798. Currency = $"CNY",
  16799. Quantity = 1,
  16800. PplNum = pplNum,
  16801. TotalAmt = infoView.Service * pplNum,
  16802. Remark = "",
  16803. });
  16804. }
  16805. #endregion
  16806. #endregion
  16807. if (result.FeeItems.Any())
  16808. {
  16809. result.FeeItems.Select(x =>
  16810. {
  16811. var feeInfos = views.Where(y => y.ItemId == x.ItemId).OrderBy(y => y.Index).ToArray();
  16812. if (feeInfos.Any()) x.Infos = feeInfos;
  16813. return x;
  16814. }
  16815. ).OrderBy(x => x.Index)
  16816. .ToList();
  16817. if (!result.Rates.Any())
  16818. {
  16819. if (eecRates.Any()) result.Rates = eecRates?.ToArray() ?? Array.Empty<CurrencyInfo>();
  16820. else
  16821. {
  16822. var rates = await GeneralMethod.EnterExitCostInitRate();
  16823. rates.Insert(0, new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
  16824. result.Rates = rates.ToArray();
  16825. }
  16826. }
  16827. }
  16828. return Ok(JsonView(result));
  16829. }
  16830. /// <summary>
  16831. /// 团组模块 - 出入境费用报价表 - Info
  16832. /// </summary>
  16833. /// <returns></returns>
  16834. [HttpPost]
  16835. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16836. public async Task<IActionResult> EnterExitCostQuoteInfo(EnterExitCostQuoteInfoDto dto)
  16837. {
  16838. var info = await _enterExitCostQuoteRep.InfoAsync(dto);
  16839. if (!info.Rates.Any())
  16840. {
  16841. var rates = await GeneralMethod.EnterExitCostInitRate();
  16842. rates.Add(new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
  16843. info.Rates = rates.ToArray();
  16844. }
  16845. return Ok(JsonView(info));
  16846. }
  16847. /// <summary>
  16848. /// 团组模块 - 出入境费用报价表 - OP
  16849. /// </summary>
  16850. /// <returns></returns>
  16851. [HttpPost]
  16852. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16853. public async Task<IActionResult> EnterExitCostQuoteOp(EnterExitCostQuoteOpDto dto)
  16854. {
  16855. return Ok(await _enterExitCostQuoteRep.OpAsync(dto));
  16856. }
  16857. /// <summary>
  16858. /// 团组模块 - 出入境费用报价表 - 删除 项
  16859. /// </summary>
  16860. /// <returns></returns>
  16861. [HttpPost]
  16862. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16863. public async Task<IActionResult> EnterExitCostQuoteItemDel(EnterExitCostQuoteItemDelDto dto)
  16864. {
  16865. if (dto.Id < 1) return Ok(JsonView(false, MsgTips.Id));
  16866. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16867. return Ok(await _enterExitCostQuoteRep.ItemDelAsync(dto));
  16868. }
  16869. /// <summary>
  16870. /// 团组模块 - 出入境费用报价表 - 导出
  16871. /// </summary>
  16872. /// <returns></returns>
  16873. [HttpPost]
  16874. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16875. public async Task<IActionResult> EnterExitCostQuoteExcelExport(EnterExitCostQuoteExcelExportDto dto)
  16876. {
  16877. if (dto.Id < 1) return Ok(JsonView(false, MsgTips.Id));
  16878. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16879. var info = await _enterExitCostQuoteRep.InfoAsync(new EnterExitCostQuoteInfoDto() { Id = dto.Id });
  16880. if (info == null) return Ok(JsonView(false, "报价信息未填写!"));
  16881. var rates = info.Rates;
  16882. var intTravelCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1354);//国际旅费
  16883. var accomCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1355); //住宿费
  16884. var mealCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1356); //餐饮费
  16885. var vehArranges = info.FeeItems.FirstOrDefault(x => x.ItemId == 1357); //车辆安排
  16886. var inviteTo = info.FeeItems.FirstOrDefault(x => x.ItemId == 1358); //邀请函发放对象
  16887. var inviteCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1359); //邀请函费用
  16888. var inviteTime = info.FeeItems.FirstOrDefault(x => x.ItemId == 1360); //邀请函发放时间
  16889. var officialActs = info.FeeItems.FirstOrDefault(x => x.ItemId == 1361); //公务活动
  16890. var visaIns = info.FeeItems.FirstOrDefault(x => x.ItemId == 1362); //签证+保险
  16891. var serviceCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1363); //服务费
  16892. var pubMiscs = info.FeeItems.FirstOrDefault(x => x.ItemId == 1364); //公杂费
  16893. var taxCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1365); //税费
  16894. //获取模板
  16895. string tempPath = AppSettingsHelper.Get("ExcelBasePath") + "Template/出入境费用明细报价表模板.xlsx";
  16896. var designer = new WorkbookDesigner();
  16897. designer.Workbook = new Workbook(tempPath);
  16898. designer.SetDataSource("QuoteName", info.Name);
  16899. designer.SetDataSource("CompanyTitle", "公司名称");
  16900. designer.SetDataSource("CompanyLabel", "");
  16901. #region 国际旅费
  16902. designer.SetDataSource("IntTravelTitle", intTravelCosts?.ItemWrapName ?? "国际旅费\r\n(公务舱和经济舱分别罗列)");
  16903. if (intTravelCosts != null && intTravelCosts.Infos.Any())
  16904. {
  16905. var cabClassFilter = new string[] { "经济舱", "公务舱", "头等舱" };
  16906. var label = new StringBuilder();
  16907. var infos = intTravelCosts.Infos.Where(x => cabClassFilter.Contains(x.FeeName)).ToArray();
  16908. if (infos.Any())
  16909. {
  16910. label.Append(infos.Sum(x => x.PplNum));
  16911. label.Append("人全程机票:");
  16912. label.Append(infos.Sum(x => x.TotalAmt).TruncDecimals(2));
  16913. label.AppendLine("元");
  16914. }
  16915. foreach (var item in intTravelCosts.Infos)
  16916. {
  16917. label.Append(item.FeeName);
  16918. label.Append(":");
  16919. label.Append(item.UnitPrice.TruncDecimals(2));
  16920. label.Append("元/人*");
  16921. label.Append(item.PplNum);
  16922. label.AppendLine("人");
  16923. }
  16924. if (label.HasValue())
  16925. {
  16926. label.Append("\r\n以上小计:");
  16927. label.Append(intTravelCosts.TotalAmt.TruncDecimals(2));
  16928. label.Append("元");
  16929. }
  16930. designer.SetDataSource("IntTravelLabel", label.ToString());
  16931. }
  16932. #endregion
  16933. #region 住宿费
  16934. designer.SetDataSource("AccomTitle", accomCosts?.ItemWrapName ?? "住宿费\r\n(请备注明酒店星级)");
  16935. if (accomCosts != null && accomCosts.Infos.Any())
  16936. {
  16937. string currencyName = string.Empty,
  16938. countryName = string.Empty;
  16939. decimal rate = 1.0000M;
  16940. var label = new StringBuilder();
  16941. label.AppendLine("全程五星酒店,每人1间房");
  16942. foreach (var item in accomCosts.Infos)
  16943. {
  16944. //乌兹别克斯坦: 塔什干:120美金/间/晚*2*6人
  16945. string name = string.Empty, thisCountryName = string.Empty;
  16946. if (item.FeeName.Contains('-'))
  16947. {
  16948. var feeName = item.FeeName.Split('-');
  16949. thisCountryName = feeName[0];
  16950. if (!thisCountryName.Equals(countryName)) countryName = feeName[0];
  16951. name = feeName[1];
  16952. }
  16953. else name = item.FeeName;
  16954. string thisFeeName = string.Empty;
  16955. if (!thisCountryName.Equals(countryName)) thisFeeName = $"{countryName}:\r\n{name}:";
  16956. else thisFeeName = $"\r\n{name}:";
  16957. var rateInfo = rates.FirstOrDefault(x => item.Currency.Equals(x.CurrencyCode));
  16958. currencyName = rateInfo?.CurrencyName ?? "UnKnow";
  16959. rate = rateInfo?.Rate ?? 1.0000M;
  16960. string subLabel = string.Format("{0}{1}{2}/间/晚*{3}*{4}人", thisFeeName, item.UnitPrice.TruncDecimals(2), currencyName, item.Quantity.ToString("#0"), item.PplNum.ToString("#0"));
  16961. label.AppendLine(subLabel);
  16962. }
  16963. if (label.HasValue())
  16964. {
  16965. //以上小计:52440元(美金汇率:7.5 )
  16966. string subLabel = string.Format("\r\n以上小计:{0}元({1}汇率:{2})", accomCosts.TotalAmt.TruncDecimals(2), currencyName, rate.TruncDecimals(4));
  16967. label.AppendLine(subLabel);
  16968. }
  16969. designer.SetDataSource("AccomLabel", label.ToString());
  16970. }
  16971. #endregion
  16972. #region 餐饮费
  16973. designer.SetDataSource("MealTitle", mealCosts?.ItemWrapName ?? "餐饮费");
  16974. if (mealCosts != null && mealCosts.Infos.Any())
  16975. {
  16976. string currencyName = string.Empty;
  16977. decimal rate = 1.0000M;
  16978. var label = new StringBuilder();
  16979. label.Append("全程酒店含早,\r\n若因航班过早,\r\n酒店准备路早。\r\n\r\n");
  16980. foreach (var item in mealCosts.Infos)
  16981. {
  16982. string name = string.Empty;
  16983. if (item.FeeName.Contains('-'))
  16984. {
  16985. var feeName = item.FeeName.Split('-');
  16986. name = $"\r\n{feeName[0]}:\r\n{feeName[1]}:";
  16987. }
  16988. else name = $"\r\n{item.FeeName}:";
  16989. var rateInfo = rates.FirstOrDefault(x => item.Currency.Equals(x.CurrencyCode));
  16990. currencyName = rateInfo?.CurrencyName ?? "UnKnow";
  16991. rate = rateInfo?.Rate ?? 1.0000M;
  16992. label.Append(name);
  16993. label.Append(item.UnitPrice.TruncDecimals(2));
  16994. label.Append(currencyName);
  16995. label.Append("/天*");
  16996. label.Append(item.Quantity.ToString("#0"));
  16997. label.Append('*');
  16998. label.Append(item.PplNum);
  16999. label.Append("人\r\n");
  17000. }
  17001. if (label.HasValue())
  17002. {
  17003. label.Append("\r\n以上小计:");
  17004. label.Append(accomCosts.TotalAmt.TruncDecimals(2));
  17005. label.Append("元\r\n(");
  17006. label.Append("汇率:");
  17007. label.Append(rate.TruncDecimals(4));
  17008. label.Append(')');
  17009. }
  17010. designer.SetDataSource("MealLabel", label.ToString());
  17011. }
  17012. #endregion
  17013. #region 车辆安排
  17014. designer.SetDataSource("VehArrangeTitle", vehArranges?.ItemWrapName ?? "车辆安排\r\n(司兼导分开的情况下,车辆品牌、座位及费用)");
  17015. if (vehArranges != null && vehArranges.Infos.Any())
  17016. {
  17017. string currencyName = string.Empty;
  17018. //decimal rate = 1.0000M;
  17019. var label = new StringBuilder();
  17020. foreach (var item in vehArranges.Infos)
  17021. {
  17022. label.AppendLine();
  17023. label.AppendLine();
  17024. label.Append(item.FeeName);
  17025. label.Append($"\r\n\r\n费用:{item.TotalAmt.TruncDecimals(2)}元");
  17026. }
  17027. designer.SetDataSource("VehArrangeLabel", label.ToString());
  17028. }
  17029. #endregion
  17030. #region 邀请函发放对象
  17031. designer.SetDataSource("InviteToTitle", inviteTo?.ItemWrapName ?? "邀请函发放对象");
  17032. designer.SetDataSource("InviteToContent", "");
  17033. #endregion
  17034. #region 邀请函费
  17035. designer.SetDataSource("InviteCostTitle", inviteCosts?.ItemWrapName ?? "邀请函费用");
  17036. var is_label = new StringBuilder();
  17037. if (inviteCosts != null && inviteCosts.Infos.Any())
  17038. {
  17039. string currencyName = string.Empty;
  17040. decimal rate = 1.0000M;
  17041. foreach (var item in inviteCosts.Infos)
  17042. {
  17043. //乌兹别克斯坦:2000美金
  17044. currencyName = item.Currency;
  17045. rate = rates.FirstOrDefault(x => currencyName.Equals(x.CurrencyCode))?.Rate ?? 1.0000M;
  17046. string label = string.Format("{0}:{1}{2}", item.FeeName, item.UnitPrice.TruncDecimals(2), currencyName);
  17047. is_label.AppendLine(label);
  17048. }
  17049. if (is_label.HasValue())
  17050. {
  17051. //以上小计:28500元(美金汇率:7.5)
  17052. string label = string.Format("以上小计:{0}{1}({2}汇率:{3})", inviteCosts.TotalAmt.TruncDecimals(2), "元", currencyName, rate.TruncDecimals(4));
  17053. is_label.AppendLine(label);
  17054. }
  17055. }
  17056. designer.SetDataSource("InviteCostContent", is_label.ToString());
  17057. #endregion
  17058. #region 邀请函发放时间
  17059. designer.SetDataSource("InviteToTimeTitle", inviteTime?.ItemWrapName ?? "邀请函发放时间");
  17060. designer.SetDataSource("InviteToTimeContent", "拿到团员名单10-15工作日");
  17061. #endregion
  17062. #region 公务活动(含翻译)
  17063. designer.SetDataSource("OfficialActsTitle", officialActs?.ItemWrapName ?? "公务活动(含翻译)");
  17064. var oa_label = new StringBuilder();
  17065. if (officialActs != null && officialActs.Infos.Any())
  17066. {
  17067. string currencyName = string.Empty;
  17068. decimal rate = 1.0000M;
  17069. string label_title = string.Empty, label_content = "超出报价部分需额付费:\r\n";
  17070. foreach (var item in officialActs.Infos)
  17071. {
  17072. //乌兹别克斯坦:1000美金/场
  17073. currencyName = item.Currency;
  17074. rate = rates.FirstOrDefault(x => currencyName.Equals(x.CurrencyCode))?.Rate ?? 1.0000M;
  17075. string label_remark = string.Empty;
  17076. if (!string.IsNullOrEmpty(item.Remark)) label_remark = $"({item.Remark})";
  17077. label_content += string.Format("{0}:{1}{2}/场{3}\r\n", item.FeeName, item.UnitPrice.TruncDecimals(2), currencyName, label_remark);
  17078. }
  17079. label_content += "*总费用中未含超出公务活动价格";
  17080. //8场公务活动(以上小计:60000元)
  17081. var quantity = officialActs.Infos.Sum(x => x.Quantity);
  17082. label_title = string.Format("{0}场公务活动(以上小计:{1}元)", quantity, officialActs.TotalAmt.TruncDecimals(2));
  17083. oa_label.AppendLine(label_title);
  17084. oa_label.AppendLine(label_content);
  17085. }
  17086. designer.SetDataSource("OfficialActsContent", oa_label.ToString());
  17087. #endregion
  17088. #region 签证+保险
  17089. designer.SetDataSource("VisaInsTitle", visaIns?.ItemWrapName ?? "签证+保险\r\n(单位:元)");
  17090. var vi_label = new StringBuilder();
  17091. if (visaIns != null && visaIns.Infos.Any())
  17092. {
  17093. foreach (var item in visaIns.Infos)
  17094. {
  17095. //签证:500元/人
  17096. string label = string.Format("{0}:{1}元/人*{2}人", item.FeeName, item.UnitPrice.TruncDecimals(2), item.PplNum);
  17097. vi_label.AppendLine(label);
  17098. }
  17099. if (vi_label.HasValue())
  17100. {
  17101. //以上小计:6000元
  17102. string label = string.Format("以上小计:{0}元", visaIns.TotalAmt.TruncDecimals(2));
  17103. vi_label.AppendLine(label);
  17104. }
  17105. }
  17106. designer.SetDataSource("VisaInsContent", vi_label.ToString());
  17107. #endregion
  17108. #region 服务费
  17109. designer.SetDataSource("ServiceCostTitle", serviceCosts?.ItemWrapName ?? "服务费");
  17110. designer.SetDataSource("ServiceCostContent", serviceCosts?.TotalAmt.TruncDecimals(2) ?? 0.00M);
  17111. #endregion
  17112. #region 公杂费
  17113. designer.SetDataSource("PubMiscsTitle", pubMiscs?.ItemWrapName ?? "公杂费\r\n(发给团组成员)");
  17114. var pm_label = new StringBuilder();
  17115. if (pubMiscs != null && pubMiscs.Infos.Any())
  17116. {
  17117. string currencyName = string.Empty,
  17118. countryName = string.Empty;
  17119. decimal rate = 1.0000M;
  17120. foreach (var item in pubMiscs.Infos)
  17121. {
  17122. //乌兹别克斯坦:塔什干:32美金 / 天 * 3 * 6人
  17123. string name = string.Empty, thisCountryName = string.Empty;
  17124. if (item.FeeName.Contains('-'))
  17125. {
  17126. var feeName = item.FeeName.Split('-');
  17127. thisCountryName = feeName[0];
  17128. if (!thisCountryName.Equals(countryName)) countryName = feeName[0];
  17129. name = feeName[1];
  17130. }
  17131. else name = item.FeeName;
  17132. string thisFeeName = string.Empty;
  17133. if (!thisCountryName.Equals(countryName)) thisFeeName = $"{countryName}:\r\n{name}:";
  17134. else thisFeeName = $"\r\n{name}:";
  17135. var rateInfo = rates.FirstOrDefault(x => item.Currency.Equals(x.CurrencyCode));
  17136. currencyName = rateInfo?.CurrencyName ?? "UnKnow";
  17137. rate = rateInfo?.Rate ?? 1.0000M;
  17138. string label = string.Format("{0}:{1}{2}/天*{3}*{4}人", thisFeeName, item.UnitPrice.TruncDecimals(2), currencyName, item.Quantity, item.PplNum);
  17139. pm_label.AppendLine(label);
  17140. }
  17141. if (pm_label.HasValue())
  17142. {
  17143. //以上小计:13497.6元\r\n(美金汇率:7.5 )\r\n部分发放成员
  17144. pm_label.AppendLine(string.Format("以上小计:{0}元", pubMiscs.TotalAmt.TruncDecimals(2)));
  17145. pm_label.AppendLine(string.Format("({0}汇率:{1})", currencyName, rate.TruncDecimals(4)));
  17146. pm_label.AppendLine(string.Format("部分发放成员"));
  17147. }
  17148. }
  17149. designer.SetDataSource("PubMiscsContent", pm_label.ToString());
  17150. #endregion
  17151. #region 税费
  17152. designer.SetDataSource("TaxCostTitle", taxCosts?.ItemWrapName ?? "税费");
  17153. designer.SetDataSource("TaxCostContent", taxCosts?.TotalAmt.TruncDecimals(2) ?? 0.00M);
  17154. #endregion
  17155. #region 合计(单位:元)
  17156. designer.SetDataSource("CostTotalTitle", "合计\r\n(单位:元)");
  17157. designer.SetDataSource("CostTotalContent", info.FeeItems.Sum(x => x.TotalAmt).TruncDecimals(2));
  17158. #endregion
  17159. #region 汇率 Remark
  17160. var rate_label = new StringBuilder();
  17161. var rateGroups = rates.GroupBy(x => x.CurrencyName);
  17162. foreach (var item in rateGroups)
  17163. {
  17164. //美元汇率按\r\n1:7.5
  17165. string label = string.Format("{0}汇率按\r\n1:{1}", item.Key, item.FirstOrDefault()?.Rate.TruncDecimals(4) ?? 0.0000M);
  17166. rate_label.AppendLine(label);
  17167. }
  17168. designer.SetDataSource("RateLabel", rate_label.ToString());
  17169. #endregion
  17170. designer.Process();
  17171. //文件名
  17172. string fileName = $"{info.Name}{DateTime.Now:yyyyMMddHHmmss}.xls";
  17173. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + "EnterExitCostQuote/" + fileName);
  17174. string url = AppSettingsHelper.Get("ExcelBaseUrl") + "Office/Excel/EnterExitCostQuote/" + fileName;
  17175. return Ok(JsonView(true, "成功", url));
  17176. }
  17177. #endregion
  17178. #region 签证费用录入
  17179. /// <summary>
  17180. /// 根据diid查询签证费用列表
  17181. /// </summary>
  17182. /// <param name="dto"></param>
  17183. /// <returns></returns>
  17184. [HttpPost]
  17185. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17186. public async Task<IActionResult> QueryVisaByDiId(VisaPriceDto dto)
  17187. {
  17188. Result groupData = await _visaPriceRep.PostVisaByDiId(dto);
  17189. if (groupData.Code != 0)
  17190. {
  17191. return Ok(JsonView(false, groupData.Msg));
  17192. }
  17193. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  17194. }
  17195. /// <summary>
  17196. /// 根据签证费用Id查询单条数据及c表数据
  17197. /// </summary>
  17198. /// <param name="dto"></param>
  17199. /// <returns></returns>
  17200. [HttpPost]
  17201. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17202. public async Task<IActionResult> QueryVisaById(PostVisaByIdDto dto)
  17203. {
  17204. Result groupData = await _visaPriceRep.PostVisaById(dto);
  17205. if (groupData.Code != 0)
  17206. {
  17207. return Ok(JsonView(false, groupData.Msg));
  17208. }
  17209. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  17210. }
  17211. /// <summary>
  17212. /// 签证费用删除
  17213. /// </summary>
  17214. /// <param name="dto"></param>
  17215. /// <returns></returns>
  17216. [HttpPost]
  17217. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17218. public async Task<IActionResult> DelVisaPrice(DelBaseDto dto)
  17219. {
  17220. _sqlSugar.BeginTran();
  17221. var res = await _visaPriceRep.SoftDeleteByIdAsync<Grp_VisaInfo>(dto.Id.ToString(), dto.DeleteUserId);
  17222. if (!res)
  17223. {
  17224. _sqlSugar.RollbackTran();
  17225. return Ok(JsonView(false, "删除失败"));
  17226. }
  17227. var resSub = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  17228. .Where(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 80)
  17229. .SetColumns(a => new Grp_CreditCardPayment()
  17230. {
  17231. IsDel = 1,
  17232. DeleteUserId = dto.DeleteUserId,
  17233. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  17234. })
  17235. .ExecuteCommand();
  17236. if (resSub < 1)
  17237. {
  17238. _sqlSugar.RollbackTran();
  17239. return Ok(JsonView(false, "删除失败"));
  17240. }
  17241. _sqlSugar.CommitTran();
  17242. return Ok(JsonView(true, "删除成功!"));
  17243. }
  17244. /// <summary>
  17245. /// 签证费用录入下拉框初始化
  17246. /// </summary>
  17247. /// <returns></returns>
  17248. [HttpPost]
  17249. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17250. public async Task<IActionResult> VisaPriceAddSelect()
  17251. {
  17252. //支付方式
  17253. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  17254. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  17255. //币种
  17256. List<Sys_SetData> CurrencyList = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 66 && a.IsDel == 0).ToList();
  17257. List<SetDataInfoView> _CurrencyList = _mapper.Map<List<SetDataInfoView>>(CurrencyList);
  17258. //乘客类型
  17259. List<Sys_SetData> PassengerType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 69 && a.IsDel == 0).ToList();
  17260. List<SetDataInfoView> _PassengerType = _mapper.Map<List<SetDataInfoView>>(PassengerType);
  17261. //卡类型
  17262. List<Sys_SetData> BankCard = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  17263. List<SetDataInfoView> _BankCard = _mapper.Map<List<SetDataInfoView>>(BankCard);
  17264. //代办费类型
  17265. var agencyFeeTypeData = new List<dynamic>() {
  17266. new { id = 0 , Text = "未选择" },
  17267. new { id = 1 , Text = "小公务" },
  17268. new { id = 2 , Text = "大公务" },
  17269. };
  17270. //签证费用标准国家Data
  17271. var visaSql = string.Format(@"select
  17272. id,
  17273. case
  17274. when FeeType = 0 then Country+'(因公)'
  17275. when FeeType = 1 then Country+'(因私)'
  17276. else Country+'(未设置)'
  17277. end as 'country'
  17278. from Res_VisaFeeStandard where isdel = 0");
  17279. var visaCountryFeeData = _sqlSugar.SqlQueryable<dynamic>(visaSql).ToList();
  17280. var data = new
  17281. {
  17282. Payment = _Payment,
  17283. CurrencyList = _CurrencyList,
  17284. PassengerType = _PassengerType,
  17285. BankCard = _BankCard,
  17286. AgencyFeeType = agencyFeeTypeData,
  17287. CountryFeeData = visaCountryFeeData
  17288. };
  17289. return Ok(JsonView(true, "查询成功!", data));
  17290. }
  17291. /// <summary>
  17292. /// 签证费用录入操作(Status:1.新增,2.修改)
  17293. /// </summary>
  17294. /// <param name="dto"></param>
  17295. /// <returns></returns>
  17296. [HttpPost]
  17297. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17298. public async Task<IActionResult> OpVisaPrice(OpVisaPriceDto dto)
  17299. {
  17300. Result groupData = await _visaPriceRep.OpVisaPrice(dto);
  17301. if (groupData.Code != 0)
  17302. {
  17303. return Ok(JsonView(false, groupData.Msg));
  17304. }
  17305. #region 应用推送
  17306. try
  17307. {
  17308. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  17309. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  17310. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  17311. //2024-10-21 新增LZ UID
  17312. var userIds = new List<int>() { 21 };
  17313. string title = $"系统通知";
  17314. string content = "";
  17315. var diId = dto.DiId;
  17316. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  17317. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  17318. if (dto.Status == 1) content = $"[新增-签证费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate):#0.00} CNY;";
  17319. else if (dto.Status == 2) content = $"[更新-签证费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate):#0.00} CNY;";
  17320. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  17321. var h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "80" };
  17322. await APNsTools.iOS_PushNotifications1("051", $"签证费用审核", "", content, true, "ExpenseAuditWebView", h5);
  17323. }
  17324. catch (Exception ex)
  17325. {
  17326. }
  17327. #endregion
  17328. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  17329. }
  17330. #endregion
  17331. #region 签证提成录入
  17332. /// <summary>
  17333. /// 签证提成录入
  17334. /// 基础数据
  17335. /// </summary>
  17336. /// <returns></returns>
  17337. [HttpGet]
  17338. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17339. public async Task<IActionResult> VisaCommissionInit()
  17340. {
  17341. return Ok(await _visaCommissionRep.Init());
  17342. }
  17343. /// <summary>
  17344. /// 签证提成录入
  17345. /// Item
  17346. /// </summary>
  17347. /// <param name="_dto"></param>
  17348. /// <returns></returns>
  17349. [HttpPost]
  17350. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17351. public async Task<IActionResult> VisaCommissionItem(VisaCommissionItemDto _dto)
  17352. {
  17353. var validator = new VisaCommissionItemDtoValidator();
  17354. var validatorRes = await validator.ValidateAsync(_dto);
  17355. if (!validatorRes.IsValid)
  17356. {
  17357. var sb = new StringBuilder();
  17358. foreach (var item in validatorRes.Errors)
  17359. {
  17360. sb.AppendLine(item.ErrorMessage);
  17361. }
  17362. return Ok(JsonView(false, sb.ToString()));
  17363. }
  17364. return Ok(await _visaCommissionRep.Item(_dto));
  17365. }
  17366. /// <summary>
  17367. /// 签证提成录入
  17368. /// Save
  17369. /// </summary>
  17370. /// <param name="_dto"></param>
  17371. /// <returns></returns>
  17372. [HttpPost]
  17373. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17374. public async Task<IActionResult> VisaCommissionSave(VisaCommissionSaveDto _dto)
  17375. {
  17376. //参数验证
  17377. if (_dto.Items.Length < 1) return Ok(JsonView(false, "请输入有效的请求!"));
  17378. foreach (var item in _dto.Items)
  17379. {
  17380. if (item.CurrUserId < 1) return Ok(JsonView(false, "请输入有效的CurrUserId!"));
  17381. if (item.DiId < 1) return Ok(JsonView(false, "请输入有效的DiId!"));
  17382. if (string.IsNullOrEmpty(item.Country)) return Ok(JsonView(false, "国家为空!"));
  17383. //if (item.Quantity < 1) return Ok(JsonView(false, "请输入有效的Qauntity!"));
  17384. }
  17385. return Ok(await _visaCommissionRep.Save(_dto));
  17386. }
  17387. /// <summary>
  17388. /// 签证提成录入
  17389. /// Create
  17390. /// </summary>
  17391. /// <param name="_dto"></param>
  17392. /// <returns></returns>
  17393. [HttpPost]
  17394. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17395. public async Task<IActionResult> VisaCommissionCreate(VisaCommissionCreateDto _dto)
  17396. {
  17397. var validator = new VisaCommissionCreateDtoValidator();
  17398. var validatorRes = await validator.ValidateAsync(_dto);
  17399. if (!validatorRes.IsValid)
  17400. {
  17401. var sb = new StringBuilder();
  17402. foreach (var item in validatorRes.Errors)
  17403. {
  17404. sb.AppendLine(item.ErrorMessage);
  17405. }
  17406. return Ok(JsonView(false, sb.ToString()));
  17407. }
  17408. return Ok(await _visaCommissionRep.Create(_dto));
  17409. }
  17410. /// <summary>
  17411. /// 签证提成录入
  17412. /// Put(编辑)
  17413. /// </summary>
  17414. /// <param name="id"></param>
  17415. /// <param name="_dto"></param>
  17416. /// <returns></returns>
  17417. [HttpPut]
  17418. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17419. public async Task<IActionResult> VisaCommissionEdit(int id, VisaCommissionCreateDto _dto)
  17420. {
  17421. if (id < 1) return Ok(JsonView(false, "请输入正确的id参数!"));
  17422. var validator = new VisaCommissionCreateDtoValidator();
  17423. var validatorRes = await validator.ValidateAsync(_dto);
  17424. if (!validatorRes.IsValid)
  17425. {
  17426. var sb = new StringBuilder();
  17427. foreach (var item in validatorRes.Errors)
  17428. {
  17429. sb.AppendLine(item.ErrorMessage);
  17430. }
  17431. return Ok(JsonView(false, sb.ToString()));
  17432. }
  17433. return Ok(await _visaCommissionRep.Edit(id, _dto));
  17434. }
  17435. /// <summary>
  17436. /// 签证提成录入
  17437. /// Del
  17438. /// </summary>
  17439. /// <param name="id"></param>
  17440. /// <param name="currUserId"></param>
  17441. /// <returns></returns>
  17442. [HttpPost]
  17443. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17444. public async Task<IActionResult> VisaCommissionDel(int id, int currUserId)
  17445. {
  17446. if (id < 1) return Ok(JsonView(false, "请输入正确的id参数!"));
  17447. if (currUserId < 1) return Ok(JsonView(false, "请输入正确的currUserId参数!"));
  17448. return Ok(await _visaCommissionRep.Del(id, currUserId));
  17449. }
  17450. #endregion
  17451. #region op费用录入
  17452. /// <summary>
  17453. /// 根据diid查询op费用列表
  17454. /// </summary>
  17455. /// <param name="dto"></param>
  17456. /// <returns></returns>
  17457. [HttpPost]
  17458. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17459. public async Task<IActionResult> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  17460. {
  17461. Result groupData = await _carTouristGuideGroundRep.QueryCarTouristGuideGroundByDiId(dto);
  17462. if (groupData.Code != 0)
  17463. {
  17464. return Ok(JsonView(false, groupData.Msg));
  17465. }
  17466. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  17467. }
  17468. /// <summary>
  17469. /// 根据op费用Id查询单条数据及c表数据
  17470. /// </summary>
  17471. /// <param name="dto"></param>
  17472. /// <returns></returns>
  17473. [HttpPost]
  17474. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17475. public async Task<IActionResult> QueryCarTouristGuideGroundById(CarTouristGuideGroundIdDto dto)
  17476. {
  17477. try
  17478. {
  17479. Grp_CarTouristGuideGroundReservations _groupData = await _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().FirstAsync(a => a.Id == dto.Id && a.IsDel == 0);
  17480. Grp_CreditCardPayment _creditCardPayment = await _sqlSugar.Queryable<Grp_CreditCardPayment>().FirstAsync(a => a.CId == dto.Id && a.CTable == 79 && a.IsDel == 0);
  17481. var data = new
  17482. {
  17483. CarTouristGuideGround = _groupData,
  17484. CreditCardPayment = _creditCardPayment
  17485. };
  17486. return Ok(JsonView(true, "查询成功!", data));
  17487. }
  17488. catch (Exception ex)
  17489. {
  17490. return Ok(JsonView(false, "程序错误!"));
  17491. }
  17492. }
  17493. /// <summary>
  17494. /// op费用删除
  17495. /// </summary>
  17496. /// <param name="dto"></param>
  17497. /// <returns></returns>
  17498. [HttpPost]
  17499. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17500. public async Task<IActionResult> DelCarTouristGuideGround(DelBaseDto dto)
  17501. {
  17502. try
  17503. {
  17504. _sqlSugar.BeginTran();
  17505. var res = await _carTouristGuideGroundRep.SoftDeleteByIdAsync<Grp_CarTouristGuideGroundReservations>(dto.Id.ToString(), dto.DeleteUserId);
  17506. if (!res)
  17507. {
  17508. return Ok(JsonView(false, "删除失败"));
  17509. }
  17510. var result = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.CTGGRId == dto.Id && a.IsDel == 0).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent()
  17511. {
  17512. IsDel = 1,
  17513. DeleteUserId = dto.DeleteUserId,
  17514. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  17515. }).ExecuteCommandAsync();
  17516. var resultC = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79).SetColumns(a => new Grp_CreditCardPayment()
  17517. {
  17518. IsDel = 1,
  17519. DeleteUserId = dto.DeleteUserId,
  17520. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  17521. }).ExecuteCommandAsync();
  17522. #region 删除超支相关数据
  17523. //删除导入的超支数据
  17524. var ids = _sqlSugar.Queryable<Fin_LocalGuideRelevancyOverspend>().Where(x => x.LocalGuideId == dto.Id && x.IsDel == 0).Select(x => x.OverspendId).ToList();
  17525. var count = _sqlSugar.Updateable<Fin_GroupExtraCost>().Where(x => ids.Contains(x.Id) && x.IsDel == 0).SetColumns(x => new Fin_GroupExtraCost
  17526. {
  17527. IsDel = 1,
  17528. DeleteUserId = dto.DeleteUserId,
  17529. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  17530. }).ExecuteCommand();
  17531. count = _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(x => x.CTable == 1015 && x.IsDel == 0 && ids.Contains(x.CId)).SetColumns(x => new Grp_CreditCardPayment
  17532. {
  17533. IsDel = 1,
  17534. DeleteUserId = dto.DeleteUserId,
  17535. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  17536. }).ExecuteCommand();
  17537. count = _sqlSugar.Updateable<Fin_LocalGuideRelevancyOverspend>().Where(x => x.IsDel == 0 && x.LocalGuideId == dto.Id).SetColumns(x => new Fin_LocalGuideRelevancyOverspend
  17538. {
  17539. IsDel = 1,
  17540. DeleteUserId = dto.DeleteUserId,
  17541. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  17542. }).ExecuteCommand();
  17543. #endregion
  17544. _sqlSugar.CommitTran();
  17545. return Ok(JsonView(true, "删除成功!"));
  17546. }
  17547. catch (Exception ex)
  17548. {
  17549. _sqlSugar.RollbackTran();
  17550. return Ok(JsonView(false, "程序错误!" + ex.Message));
  17551. }
  17552. }
  17553. /// <summary>
  17554. /// op费用录入操作(Status:1.新增,2.修改)
  17555. /// </summary>
  17556. /// <param name="dto"></param>
  17557. /// <returns></returns>
  17558. [HttpPost]
  17559. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17560. public async Task<IActionResult> OpCarTouristGuideGround(OpCarTouristGuideGroundDto dto)
  17561. {
  17562. Result groupData = await _carTouristGuideGroundRep.OpCarTouristGuideGround(dto);
  17563. if (groupData.Code != 0)
  17564. {
  17565. return Ok(JsonView(false, groupData.Msg));
  17566. }
  17567. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  17568. }
  17569. /// <summary>
  17570. /// 填写费用详细页面初始化绑定
  17571. /// </summary>
  17572. /// <param name="dto"></param>
  17573. /// <returns></returns>
  17574. [HttpPost]
  17575. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17576. public IActionResult CarTouristGuideGroundContentInitialize(CarTouristGuideGroundContentDto dto)
  17577. {
  17578. try
  17579. {
  17580. Result groupData = _carTouristGuideGroundRep.CarTouristGuideGroundContent(dto);
  17581. if (groupData.Code != 0)
  17582. {
  17583. return Ok(JsonView(false, groupData.Msg));
  17584. }
  17585. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  17586. }
  17587. catch (Exception ex)
  17588. {
  17589. return Ok(JsonView(false, ex.Message));
  17590. }
  17591. }
  17592. /// <summary>
  17593. /// 根据op费用Id查询详细数据
  17594. /// </summary>
  17595. /// <param name="dto"></param>
  17596. /// <returns></returns>
  17597. [HttpPost]
  17598. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17599. public IActionResult OpCarTouristGuideGroundContentById(CarTouristGuideGroundIdDto dto)
  17600. {
  17601. try
  17602. {
  17603. Result groupData = _carTouristGuideGroundRep.OpCarTouristGuideGroundContentById(dto);
  17604. if (groupData.Code != 0)
  17605. {
  17606. return Ok(JsonView(false, groupData.Msg));
  17607. }
  17608. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  17609. }
  17610. catch (Exception ex)
  17611. {
  17612. return Ok(JsonView(false, ex.Message));
  17613. }
  17614. }
  17615. /// <summary>
  17616. /// OP费用录入填写详情
  17617. /// </summary>
  17618. /// <param name="dto"></param>
  17619. /// <returns></returns>
  17620. [HttpPost]
  17621. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17622. public async Task<IActionResult> OpCarTouristGuideGroundContent(OpCarTouristGuideGroundContentDto dto)
  17623. {
  17624. try
  17625. {
  17626. #region 参数校验
  17627. if (dto.Currency <= 0) return Ok(JsonView(false, "币种错误!"));
  17628. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.DiId && x.IsDel == 0);
  17629. if (di == null) return Ok(JsonView(false, "团组错误!"));
  17630. #endregion
  17631. Result groupData = await _carTouristGuideGroundRep.OpCarTouristGuideGroundContent(dto);
  17632. if (groupData.Code != 0)
  17633. {
  17634. return Ok(JsonView(false, groupData.Msg));
  17635. }
  17636. //自动审核
  17637. await _feeAuditRep.FeeAutomaticAudit(2, dto.DiId, dto.CTGGRId);
  17638. #region 尾款自动审核
  17639. var opinfos = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  17640. .First(x => x.IsDel == 0 && x.DiId == dto.DiId && x.Id == dto.CTGGRId);
  17641. if (opinfos.PriceType == 1062)
  17642. {
  17643. var isAuto = false;
  17644. //找对应的首付款
  17645. var firstPrice = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  17646. .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))
  17647. .First(x => x.IsDel == 0 && x.DiId == dto.DiId && x.PriceName == opinfos.PriceName &&
  17648. x.ServiceStartTime == opinfos.ServiceStartTime && x.ServiceEndTime == opinfos.ServiceEndTime && x.Area == opinfos.Area &&
  17649. x.PriceType == 1061 && x.DiId == dto.DiId);
  17650. if (firstPrice != null && !(opinfos.SelectCheck.Contains("超时") || opinfos.SelectCheck.Contains("超支")) && firstPrice.CId == opinfos.CId)
  17651. {
  17652. var cprice = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(x => x.IsDel == 0 && x.CId == firstPrice.Id && x.CTable == 79);
  17653. var balance = firstPrice.ServiceQuotedPrice * (100 - cprice.PayPercentage) / 100;
  17654. //合计中排除城市税
  17655. var cityPrice = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>()
  17656. .Where(x => x.SId == 1452 && x.IsDel == 0 && x.DiId == dto.DiId && x.CTGGRId == dto.CTGGRId)
  17657. .Sum(x => x.Price * x.Count);
  17658. opinfos.ServiceQuotedPrice = opinfos.ServiceQuotedPrice - cityPrice;
  17659. if (balance >= opinfos.ServiceQuotedPrice)
  17660. {
  17661. isAuto = true;
  17662. }
  17663. }
  17664. if (isAuto)
  17665. {
  17666. var execCount = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  17667. .SetColumns(a => new Grp_CreditCardPayment
  17668. {
  17669. IsAuditGM = 3, //自动审核通过
  17670. AuditGMOperate = 4,
  17671. AuditGMDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  17672. })
  17673. .Where(a => a.CId == dto.CTGGRId && a.CTable == 79 && a.DIId == dto.DiId)
  17674. .ExecuteCommand();
  17675. }
  17676. }
  17677. #endregion
  17678. #region 应用推送
  17679. try
  17680. {
  17681. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  17682. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  17683. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  17684. //2024-10-21 新增LZ UID
  17685. var userIds = new List<int>() { 21 };
  17686. string title = $"系统通知";
  17687. var diId = dto.DiId;
  17688. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  17689. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  17690. string content = $"[更新-OP费用录入填写详情({groupInfo?.TeamName ?? "-"})]一项费用:{(((ccpInfo.PayMoney * ccpInfo.DayRate) / 100) * ccpInfo.PayPercentage):#0.00} CNY;";
  17691. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  17692. var h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "79" };
  17693. await APNsTools.iOS_PushNotifications1("051", $"OP费用审核", "", content, true, "ExpenseAuditWebView", h5);
  17694. }
  17695. catch (Exception ex)
  17696. {
  17697. }
  17698. #endregion
  17699. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  17700. }
  17701. catch (Exception ex)
  17702. {
  17703. return Ok(JsonView(false, ex.Message));
  17704. }
  17705. }
  17706. /// <summary>
  17707. /// 获取三公详细所有城市
  17708. /// </summary>
  17709. /// <returns></returns>
  17710. [HttpGet]
  17711. public IActionResult OpCarCityResult()
  17712. {
  17713. var jw = JsonView(false);
  17714. var data = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x => x.IsDel == 0).Select(x => new
  17715. {
  17716. x.Id,
  17717. x.Country,
  17718. x.City,
  17719. }).ToList();
  17720. if (data.Count > 0)
  17721. {
  17722. jw = JsonView(true, "获取成功!", data);
  17723. }
  17724. else
  17725. {
  17726. jw.Msg = "城市数据为空!";
  17727. jw.Data = Array.Empty<string>();
  17728. }
  17729. return Ok(jw);
  17730. }
  17731. /// <summary>
  17732. /// 导出地接费用明细
  17733. /// </summary>
  17734. /// <param name="dto"></param>
  17735. /// <returns></returns>
  17736. [HttpPost]
  17737. public IActionResult ExportLocalGuidePriceDetail(ExportLocalGuidePriceDetailDto dto)
  17738. {
  17739. var jw = JsonView(false);
  17740. if (dto.Diid < 1)
  17741. {
  17742. jw.Msg = "请输入正确的diid!";
  17743. return Ok(jw);
  17744. }
  17745. var group = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  17746. if (group == null)
  17747. {
  17748. jw.Msg = "未找到团组信息!";
  17749. return Ok(jw);
  17750. }
  17751. var localGuideArr = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(x => x.DiId == dto.Diid && x.IsDel == 0).ToList();
  17752. if (localGuideArr.Count == 0)
  17753. {
  17754. jw.Msg = "该团组暂无地接信息!";
  17755. return Ok(jw);
  17756. }
  17757. var localGroup = localGuideArr.GroupBy(x => x.Area).ToList();
  17758. var overspendSoure = new Dictionary<int, int>
  17759. {
  17760. { 91, 982 }, //车
  17761. { 92 , 1059} ,//导游
  17762. { 994 , 1073}, //翻译
  17763. { 988 , 1074 }, //早餐
  17764. { 93 , 1075 }, //午餐
  17765. { 989 , 1076 }, //晚餐
  17766. };
  17767. var Zips = new Dictionary<string, Stream>();
  17768. foreach (var groupArr in localGroup)
  17769. {
  17770. var keyValue = groupArr.Key;
  17771. if (int.TryParse(keyValue, out int cityid))
  17772. {
  17773. var city = _sqlSugar.Queryable<Grp_NationalTravelFee>().First(x => x.Id == cityid && x.IsDel == 0);
  17774. keyValue = city == null ? keyValue : city.Country + "-" + city.City;
  17775. }
  17776. var contentArr = new List<List<Grp_CarTouristGuideGroundReservationsContentExtend>>();
  17777. foreach (var item in groupArr)
  17778. {
  17779. var content = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent, Sys_SetData>((a, b) => a.SId == b.Id
  17780. ).Where((a, b) => a.CTGGRId == item.Id && a.Price != 0M && a.IsDel == 0 && b.IsDel == 0).Select((a, b) =>
  17781. new Grp_CarTouristGuideGroundReservationsContentExtend
  17782. {
  17783. Count = a.Count,
  17784. CreateTime = a.CreateTime,
  17785. CreateUserId = a.CreateUserId,
  17786. CTGGRId = a.CTGGRId,
  17787. Currency = a.Currency,
  17788. DatePrice = a.DatePrice,
  17789. DeleteTime = a.DeleteTime,
  17790. DeleteUserId = a.DeleteUserId,
  17791. DiId = a.DiId,
  17792. Id = a.Id,
  17793. IsDel = a.IsDel,
  17794. Price = a.Price,
  17795. PriceContent = a.PriceContent,
  17796. Remark = a.Remark,
  17797. SId = a.SId,
  17798. SidName = b.Name,
  17799. Units = a.Units,
  17800. }
  17801. ).ToList();
  17802. if (content.Count > 0)
  17803. {
  17804. contentArr.Add(content);
  17805. }
  17806. }
  17807. //open excel
  17808. //set excel
  17809. //save excel
  17810. try
  17811. {
  17812. string filePath = AppSettingsHelper.Get("ExcelBasePath") + "\\Template\\地接费用明细.xlsx";
  17813. IWorkbook workbook;
  17814. if (Path.GetExtension(filePath).ToLower() == ".xls")
  17815. {
  17816. workbook = new NPOI.HSSF.UserModel.HSSFWorkbook(new FileStream(filePath, FileMode.Open, FileAccess.Read));
  17817. }
  17818. else
  17819. {
  17820. workbook = new XSSFWorkbook(new FileStream(filePath, FileMode.Open, FileAccess.Read));
  17821. }
  17822. ISheet sheet = workbook.GetSheetAt(0);
  17823. var rowStartIndex = 2;
  17824. var clounmCount = 10;
  17825. var initStyleRow = sheet.GetRow(2);
  17826. var arr = contentArr.SelectMany(x => x).OrderBy(x => x.SId).ToList();
  17827. //var overspendArrDetail =
  17828. var existsId = new List<CarCompare>();
  17829. var lastElem = arr.Last();
  17830. var thisSid = -1;
  17831. var curr = arr.Count > 0 ? arr[0].Currency : -1;
  17832. var currObj = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == curr && x.IsDel == 0) ?? new Sys_SetData
  17833. {
  17834. Name = "未知币种!",
  17835. Remark = "未知币种!",
  17836. };
  17837. sheet.GetRow(0).GetCell(1).SetCellValue($"{keyValue}费用明细(货币:{currObj.Remark})");
  17838. Action cloneRowFn = () =>
  17839. {
  17840. rowStartIndex++;
  17841. var cloneRow = sheet.CreateRow(rowStartIndex);
  17842. // 复制样式
  17843. for (int i = initStyleRow.FirstCellNum; i < initStyleRow.LastCellNum; i++)
  17844. {
  17845. ICell sourceCell = initStyleRow.GetCell(i);
  17846. ICell targetCell = cloneRow.GetCell(i) ?? cloneRow.CreateCell(i);
  17847. // 确保单元格存在样式
  17848. if (sourceCell.CellStyle != null)
  17849. {
  17850. targetCell.CellStyle = sourceCell.CellStyle;
  17851. }
  17852. }
  17853. };
  17854. var mergeRow = () =>
  17855. {
  17856. for (int i = 2; i < sheet.LastRowNum; i++)
  17857. {
  17858. var row = sheet.GetRow(i);
  17859. var cellFirst = row.GetCell(0);
  17860. var thisIndex = i + 1;
  17861. while (thisIndex < sheet.LastRowNum)
  17862. {
  17863. var nextRow = sheet.GetRow(thisIndex);
  17864. var nextCellFirst = nextRow.GetCell(0);
  17865. if (cellFirst != null && nextCellFirst != null && cellFirst.ToString().Trim() == nextCellFirst.ToString().Trim())
  17866. {
  17867. thisIndex++;
  17868. }
  17869. else
  17870. {
  17871. break;
  17872. }
  17873. }
  17874. thisIndex--;
  17875. if (thisIndex != i)
  17876. {
  17877. //合并row
  17878. var cellRangeAddress = new CellRangeAddress(
  17879. i, // 起始行索引(0-based)
  17880. thisIndex, // 结束行索引(0-based)
  17881. 0, // 起始列索引(0-based)
  17882. 0 // 结束列索引(0-based)
  17883. );
  17884. sheet.AddMergedRegion(cellRangeAddress);
  17885. i = thisIndex;
  17886. }
  17887. }
  17888. };
  17889. var chaoshiNumber = 0;
  17890. var totalNumber = 0.00M;
  17891. string lastStr = "";
  17892. var queryCarArrByCityAndDiid = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations, Grp_CreditCardPayment>((x, b) => x.Id == b.CId && b.IsDel == 0 && b.CTable == 79)
  17893. .Where(x => x.DiId == dto.Diid && x.Area == groupArr.Key).Select((x, b) => new
  17894. {
  17895. b.IsAuditGM,
  17896. x.Id,
  17897. x.Area,
  17898. b.PayPercentage,
  17899. b.PayMoney,
  17900. }).ToList();
  17901. string yesPayment = "", noPayment = "";
  17902. foreach (var item in queryCarArrByCityAndDiid)
  17903. {
  17904. if (item.IsAuditGM == 1)
  17905. {
  17906. yesPayment += $"已支付团款({(int)item.PayPercentage}%):{item.PayMoney} {currObj.Remark}(如有需要,请在此处填写明细)\r\n";
  17907. }
  17908. else
  17909. {
  17910. noPayment += $"剩余团款:{item.PayMoney}{currObj.Remark}(如有需要,请在此处填写明细)\r\n";
  17911. }
  17912. }
  17913. lastStr = yesPayment + noPayment;
  17914. foreach (var item in arr)
  17915. {
  17916. if (existsId.FirstOrDefault(x => x.Sid == item.SId && DateTime.Compare(x.DataPrice, item.DatePrice.ObjToDate()) == 0) == null && !overspendSoure.ContainsValue(item.SId))
  17917. {
  17918. if (thisSid != item.SId)
  17919. {
  17920. if (thisSid == -1)
  17921. {
  17922. thisSid = item.SId;
  17923. }
  17924. else
  17925. {
  17926. //合并小计行
  17927. //创建合并区域的实例
  17928. var cellRangeAddress = new CellRangeAddress(
  17929. rowStartIndex, // 起始行索引(0-based)
  17930. rowStartIndex, // 结束行索引(0-based)
  17931. 0, // 起始列索引(0-based)
  17932. 3 // 结束列索引(0-based)
  17933. );
  17934. sheet.AddMergedRegion(cellRangeAddress);
  17935. var CellStyle = workbook.CreateCellStyle();
  17936. CellStyle.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(0).CellStyle);
  17937. CellStyle.FillForegroundColor = IndexedColors.Yellow.Index; // 选择填充颜色
  17938. CellStyle.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground; // 填充方式
  17939. for (int i = 0; i <= clounmCount; i++)
  17940. {
  17941. if (i > 6)
  17942. {
  17943. var CellStyle1 = workbook.CreateCellStyle();
  17944. CellStyle1.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(0).CellStyle);
  17945. IFont Font = workbook.CreateFont(); // 创建字体
  17946. Font.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(i).CellStyle.GetFont(workbook));
  17947. Font.Color = IndexedColors.Red.Index; // 选择字体颜色
  17948. CellStyle1.SetFont(Font);
  17949. sheet.GetRow(rowStartIndex).GetCell(i).CellStyle = CellStyle1;
  17950. }
  17951. else
  17952. {
  17953. sheet.GetRow(rowStartIndex).GetCell(i).CellStyle = CellStyle;
  17954. }
  17955. }
  17956. sheet.GetRow(rowStartIndex).GetCell(0).SetCellValue("合计:");
  17957. sheet.GetRow(rowStartIndex).GetCell(4).SetCellValue(arr.Where(x => x.SId == thisSid).Sum(x => x.Count * x.Price).ToString("F2"));
  17958. //超时合计
  17959. sheet.GetRow(rowStartIndex).GetCell(7).SetCellValue("超时合计:");
  17960. //超时数
  17961. sheet.GetRow(rowStartIndex).GetCell(8).SetCellValue(chaoshiNumber == 0 ? "" : chaoshiNumber.ToString());
  17962. //超时合计费用
  17963. sheet.GetRow(rowStartIndex).GetCell(9).SetCellValue(totalNumber == 0 ? "" : totalNumber.ToString());
  17964. thisSid = item.SId;
  17965. cloneRowFn();
  17966. chaoshiNumber = 0;
  17967. totalNumber = 0;
  17968. }
  17969. }
  17970. IRow row = sheet.GetRow(rowStartIndex);
  17971. var whereForResult = arr.Where(x => x.SId == item.SId && DateTime.Compare(x.DatePrice.ObjToDate(), item.DatePrice.ObjToDate()) == 0).ToList();
  17972. var isOpenOverspendSoure = overspendSoure.ContainsKey(item.SId);
  17973. List<Grp_CarTouristGuideGroundReservationsContentExtend> overspendWhereForResult = null;
  17974. if (isOpenOverspendSoure)
  17975. {
  17976. overspendWhereForResult = arr.Where(x => x.SId == overspendSoure[item.SId] && DateTime.Compare(x.DatePrice.ObjToDate(), item.DatePrice.ObjToDate()) == 0).ToList();
  17977. chaoshiNumber += overspendWhereForResult.Sum(x => x.Count);
  17978. totalNumber += overspendWhereForResult.Sum(x => x.Count * x.Price);
  17979. }
  17980. for (int i = 0; i <= clounmCount; i++)
  17981. {
  17982. var cell = row.GetCell(i);
  17983. var setCellValue = InIndexOutFunction(i, whereForResult, overspendWhereForResult);
  17984. if (cell == null)
  17985. {
  17986. cell = row.CreateCell(i);
  17987. }
  17988. var fontRed = workbook.CreateCellStyle(); // 创建单元格样式
  17989. fontRed.CloneStyleFrom(cell.CellStyle);
  17990. IFont Font = workbook.CreateFont(); // 创建字体
  17991. Font.CloneStyleFrom(cell.CellStyle.GetFont(workbook));
  17992. Font.Color = IndexedColors.Red.Index; // 选择字体颜色
  17993. fontRed.SetFont(Font);
  17994. byte[] rgb = new byte[3] { 255, 242, 204 };
  17995. var BackgroundColor255_242_204 = workbook.CreateCellStyle();
  17996. BackgroundColor255_242_204.CloneStyleFrom(cell.CellStyle);
  17997. byte[] rgb1 = new byte[3] { 189, 215, 238 };
  17998. if (workbook is XSSFWorkbook)
  17999. {
  18000. BackgroundColor255_242_204.FillForegroundColor = 0;
  18001. ((XSSFColor)BackgroundColor255_242_204.FillForegroundColorColor).SetRgb(rgb);
  18002. BackgroundColor255_242_204.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
  18003. }
  18004. else
  18005. {
  18006. BackgroundColor255_242_204.FillForegroundColor = (((NPOI.HSSF.UserModel.HSSFWorkbook)workbook).GetCustomPalette().FindSimilarColor(rgb[0], rgb[1], rgb[2])).Indexed;
  18007. }
  18008. if (i == 1 || i > 6)
  18009. {
  18010. if (i > 6)
  18011. {
  18012. fontRed.FillForegroundColor = 0;
  18013. ((XSSFColor)fontRed.FillForegroundColorColor).SetRgb(rgb1);
  18014. fontRed.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
  18015. }
  18016. cell.CellStyle = fontRed;
  18017. }
  18018. if (i > 2 && i < 7)
  18019. {
  18020. cell.CellStyle = BackgroundColor255_242_204;
  18021. }
  18022. cell.SetCellValue(setCellValue); //写入单元格
  18023. }
  18024. if (overspendSoure.ContainsKey(thisSid))
  18025. {
  18026. var overspendId = overspendSoure[thisSid];
  18027. whereForResult = arr.Where(x => x.SId == item.SId && DateTime.Compare(x.DatePrice.ObjToDate(), item.DatePrice.ObjToDate()) == 0).ToList();
  18028. }
  18029. cloneRowFn();
  18030. existsId.Add(new CarCompare
  18031. {
  18032. DataPrice = item.DatePrice.ObjToDate(),
  18033. Sid = item.SId
  18034. });
  18035. }
  18036. if (item.Equals(lastElem))
  18037. {
  18038. //合并小计行
  18039. //创建合并区域的实例
  18040. var cellRangeAddress = new CellRangeAddress(
  18041. rowStartIndex, // 起始行索引(0-based)
  18042. rowStartIndex, // 结束行索引(0-based)
  18043. 0, // 起始列索引(0-based)
  18044. 3 // 结束列索引(0-based)
  18045. );
  18046. sheet.AddMergedRegion(cellRangeAddress);
  18047. var CellStyle = workbook.CreateCellStyle();
  18048. CellStyle.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(0).CellStyle);
  18049. CellStyle.FillForegroundColor = IndexedColors.Yellow.Index; // 选择填充颜色
  18050. CellStyle.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground; // 填充方式
  18051. for (int i = 0; i <= clounmCount; i++)
  18052. {
  18053. if (i > 6)
  18054. {
  18055. var CellStyle1 = workbook.CreateCellStyle();
  18056. CellStyle1.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(0).CellStyle);
  18057. IFont Font = workbook.CreateFont(); // 创建字体
  18058. Font.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(i).CellStyle.GetFont(workbook));
  18059. Font.Color = IndexedColors.Red.Index; // 选择字体颜色
  18060. CellStyle1.SetFont(Font);
  18061. sheet.GetRow(rowStartIndex).GetCell(i).CellStyle = CellStyle1;
  18062. }
  18063. else
  18064. {
  18065. sheet.GetRow(rowStartIndex).GetCell(i).CellStyle = CellStyle;
  18066. }
  18067. }
  18068. sheet.GetRow(rowStartIndex).GetCell(0).SetCellValue("合计:");
  18069. sheet.GetRow(rowStartIndex).GetCell(4).SetCellValue(arr.Where(x => x.SId == thisSid).Sum(x => x.Count * x.Price).ToString("F2"));
  18070. //超时合计
  18071. sheet.GetRow(rowStartIndex).GetCell(7).SetCellValue("超时合计:");
  18072. //超时数
  18073. sheet.GetRow(rowStartIndex).GetCell(8).SetCellValue(chaoshiNumber == 0 ? "" : chaoshiNumber.ToString());
  18074. //超时合计费用
  18075. sheet.GetRow(rowStartIndex).GetCell(9).SetCellValue(totalNumber == 0 ? "" : totalNumber.ToString());
  18076. cloneRowFn();
  18077. // 创建合并区域的实例
  18078. cellRangeAddress = new CellRangeAddress(
  18079. rowStartIndex, // 起始行索引(0-based)
  18080. rowStartIndex, // 结束行索引(0-based)
  18081. 0, // 起始列索引(0-based)
  18082. initStyleRow.LastCellNum - 1 // 结束列索引(0-based)
  18083. );
  18084. // 添加合并区域
  18085. sheet.AddMergedRegion(cellRangeAddress);
  18086. sheet.GetRow(rowStartIndex).Height = 30 * 30;
  18087. sheet.GetRow(rowStartIndex).GetCell(0).SetCellValue(lastStr);
  18088. }
  18089. }
  18090. mergeRow();
  18091. // 保存修改后的Excel文件到新文件
  18092. //string newFilePath = Path.Combine(Path.GetDirectoryName(filePath), keyValue +"_" + Path.GetFileName(filePath));
  18093. // new FileStream(newFilePath, FileMode.CreateNew)
  18094. using (var stream = new MemoryStream())
  18095. {
  18096. workbook.Write(stream, true);
  18097. stream.Flush();
  18098. stream.Seek(0, SeekOrigin.Begin);
  18099. var memoryStream = new MemoryStream();
  18100. stream.CopyTo(memoryStream);
  18101. memoryStream.Seek(0, SeekOrigin.Begin);
  18102. Zips.Add(keyValue + "_" + "费用明细表.xlsx", memoryStream);
  18103. }
  18104. workbook.Close();
  18105. workbook.Dispose();
  18106. }
  18107. catch (Exception ex)
  18108. {
  18109. jw.Msg = "出现异常!" + ex.Message;
  18110. return Ok(jw);
  18111. }
  18112. }
  18113. if (Zips.Count > 0)
  18114. {
  18115. var io = new IOOperatorHelper();
  18116. var byts = io.ConvertZipStream(Zips);
  18117. io.ByteToFile(byts, AppSettingsHelper.Get("ExcelBasePath") + $"\\ExportLocalGuidePriceDetail\\{group.TeamName}_地接费用明细.zip");
  18118. //http://132.232.92.186:24/Office/Word/EnterExitCost/File/
  18119. jw = JsonView(true, "success", new { url = AppSettingsHelper.Get("OfficeBaseUrl") + $"\\Office\\Excel\\ExportLocalGuidePriceDetail\\{group.TeamName}_地接费用明细.zip" });
  18120. }
  18121. else
  18122. {
  18123. jw.Msg = "暂无生成文件!";
  18124. }
  18125. return Ok(jw);
  18126. }
  18127. private string InIndexOutFunction(int i, List<Grp_CarTouristGuideGroundReservationsContentExtend> arr, List<Grp_CarTouristGuideGroundReservationsContentExtend> arrOverspendSoure)
  18128. {
  18129. string outStr = string.Empty;
  18130. switch (i)
  18131. {
  18132. case 0:
  18133. outStr = arr[0].SidName;
  18134. break;
  18135. case 1:
  18136. outStr = arr[0].DataPriceStr;
  18137. break;
  18138. case 2:
  18139. outStr = string.Join("-", arr.Select(x => x.PriceContent));
  18140. break;
  18141. case 4:
  18142. outStr = arr.Sum(x => x.Subtotal).ToString("F2");
  18143. break;
  18144. case 7:
  18145. if (arrOverspendSoure != null && arrOverspendSoure.Count > 0)
  18146. {
  18147. var curr = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == arrOverspendSoure[0].Currency && x.IsDel == 0);
  18148. var unit = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == arrOverspendSoure[0].Units && x.IsDel == 0);
  18149. outStr = arrOverspendSoure.Sum(x => x.Price).ToString("F2") + curr?.Remark + "/" + unit?.Name;
  18150. }
  18151. break;
  18152. case 8:
  18153. if (arrOverspendSoure != null && arrOverspendSoure.Count > 0)
  18154. {
  18155. outStr = arrOverspendSoure.Sum(x => x.Count).ToString();
  18156. }
  18157. break;
  18158. case 9:
  18159. if (arrOverspendSoure != null && arrOverspendSoure.Count > 0)
  18160. {
  18161. outStr = arrOverspendSoure.Sum(x => x.Count * x.Price).ToString();
  18162. }
  18163. break;
  18164. case 10:
  18165. if (arrOverspendSoure != null && arrOverspendSoure.Count > 0)
  18166. {
  18167. outStr = string.Join("-", arrOverspendSoure.Select(x => x.PriceContent));
  18168. }
  18169. break;
  18170. }
  18171. return outStr;
  18172. }
  18173. #region OP行程单
  18174. /// <summary>
  18175. /// OP行程单初始化
  18176. /// </summary>
  18177. /// <param name="dto"></param>
  18178. /// <returns></returns>
  18179. [HttpPost]
  18180. public IActionResult InitOpTravel(InitOpTravelDto dto)
  18181. {
  18182. var jw = JsonView(false);
  18183. var groupList = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0).OrderByDescending(x => x.VisitStartDate).ToList();
  18184. var group = groupList.First();
  18185. var diid = dto.Diid == -1 ? group?.Id : dto.Diid;
  18186. if (group == null)
  18187. {
  18188. jw.Msg = "暂无团组!";
  18189. return Ok(jw);
  18190. }
  18191. group = groupList.Find(x => x.Id == diid);
  18192. if (group == null)
  18193. {
  18194. jw.Msg = "请输入正确的团组ID!";
  18195. return Ok(jw);
  18196. }
  18197. string city = string.Empty;
  18198. var blackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && x.DiId == diid).ToList();
  18199. if (blackCode.Count > 0)
  18200. {
  18201. var black = blackCode.First();
  18202. black.BlackCode = black.BlackCode ?? "";
  18203. var blackSp = Regex.Split(black.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  18204. if (blackSp.Length > 0)
  18205. {
  18206. try
  18207. {
  18208. var cityArrCode = new List<string>(20);
  18209. foreach (var item in blackSp)
  18210. {
  18211. var itemSp = item.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  18212. var IndexSelect = itemSp[2];
  18213. var cityArrCodeLength = cityArrCode.Count - 1;
  18214. var startCity = IndexSelect.Substring(0, 3);
  18215. if (cityArrCodeLength > 0)
  18216. {
  18217. var arrEndCity = cityArrCode[cityArrCodeLength];
  18218. if (arrEndCity != startCity)
  18219. {
  18220. cityArrCode.Add(startCity.ToUpper());
  18221. }
  18222. }
  18223. else
  18224. {
  18225. cityArrCode.Add(startCity.ToUpper());
  18226. }
  18227. var endCity = IndexSelect.Substring(3, 3);
  18228. cityArrCode.Add(endCity.ToUpper());
  18229. }
  18230. var cityThree = string.Empty;
  18231. cityArrCode.ForEach(x => cityThree += "'" + x + "',");
  18232. cityThree = cityThree.TrimEnd(',');
  18233. if (string.IsNullOrWhiteSpace(cityThree))
  18234. {
  18235. throw new
  18236. Exception("error");
  18237. }
  18238. string sql = $"SELECT * FROM Res_ThreeCode rtc WHERE UPPER(rtc.Three) in ({cityThree}) ";
  18239. var cityArr = _sqlSugar.SqlQueryable<Res_ThreeCode>(sql).ToList();
  18240. foreach (var item in cityArrCode)
  18241. {
  18242. var find = cityArr.Find(x => x.Three.ToUpper() == item.ToUpper());
  18243. if (find != null)
  18244. {
  18245. city += find.City + "/";
  18246. }
  18247. else
  18248. {
  18249. city += item + "三字码未收入/";
  18250. }
  18251. }
  18252. city = city.TrimEnd('/');
  18253. }
  18254. catch (Exception e)
  18255. {
  18256. city = "黑屏代码格式不正确!";
  18257. }
  18258. }
  18259. }
  18260. else
  18261. {
  18262. city = "未录入黑屏代码";
  18263. }
  18264. var OpTravelList = _sqlSugar.Queryable<Grp_TravelList>().Where(x => x.Diid == diid && x.IsDel == 0).OrderBy(x => x.Days).Select(x => new TravelArrView
  18265. {
  18266. Date = x.Date,
  18267. Days = x.Days,
  18268. Diffgroup = x.Diffgroup,
  18269. Diid = x.Diid,
  18270. Traffic_First = x.Traffic_First,
  18271. Traffic_Second = x.Traffic_Second,
  18272. Trip = x.Trip,
  18273. WeekDay = x.WeekDay,
  18274. Id = x.Id
  18275. }).ToList();
  18276. jw.Data = new
  18277. {
  18278. groupList = groupList.Select(x => new
  18279. {
  18280. x.Id,
  18281. x.TeamName,
  18282. x.TourCode
  18283. }).ToList(),
  18284. groupInfo = new
  18285. {
  18286. group.VisitDays,
  18287. group.TourCode,
  18288. group.VisitPNumber,
  18289. group.TeamName,
  18290. city
  18291. },
  18292. OpTravelList
  18293. };
  18294. jw.Code = 200;
  18295. jw.Msg = "操作成功!";
  18296. return Ok(jw);
  18297. }
  18298. /// <summary>
  18299. /// 删除团组行程单
  18300. /// </summary>
  18301. /// <returns></returns>
  18302. [HttpPost]
  18303. public IActionResult DelTravel(DelOpTravelDto dto)
  18304. {
  18305. var jw = JsonView(false);
  18306. if (dto.UserId <= 0 || dto.Diid <= 0)
  18307. {
  18308. jw.Msg = "请输入正确的参数!";
  18309. return Ok(jw);
  18310. }
  18311. var isTrue = _sqlSugar.Updateable<Grp_TravelList>().Where(x => x.Diid == dto.Diid && x.IsDel == 0)
  18312. .SetColumns(x => new Grp_TravelList
  18313. {
  18314. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  18315. DeleteUserId = dto.UserId,
  18316. IsDel = 1,
  18317. }).ExecuteCommand();
  18318. jw = JsonView(true);
  18319. return Ok(jw);
  18320. }
  18321. /// <summary>
  18322. /// 行程单保存
  18323. /// </summary>
  18324. /// <returns></returns>
  18325. [HttpPost]
  18326. public IActionResult TravelSave(TravelSaveDto dto)
  18327. {
  18328. var jw = JsonView(false);
  18329. if (dto.Arr.Count > 0)
  18330. {
  18331. try
  18332. {
  18333. var travelList_DB = _sqlSugar.Queryable<Grp_TravelList>()
  18334. .Where(x => dto.Arr.Select(x => x.Id).Contains(x.Id))
  18335. .ToList();
  18336. _sqlSugar.BeginTran();
  18337. foreach (var item in dto.Arr)
  18338. {
  18339. if (item.Id == 0)
  18340. {
  18341. throw new Exception("请传入正确的Id");
  18342. }
  18343. //比较上一次的差异
  18344. var findTravel = travelList_DB.Find(x => x.Id == item.Id);
  18345. if (findTravel != null)
  18346. {
  18347. item.Trip = item.Trip.Replace("[++]", string.Empty);
  18348. findTravel.Trip = findTravel.Trip.Replace("[++]", string.Empty);
  18349. item.Trip = CheckStr(findTravel.Trip, item.Trip);
  18350. }
  18351. _sqlSugar.Updateable<Grp_TravelList>().Where(x => x.Id == item.Id)
  18352. .SetColumns(x => new Grp_TravelList
  18353. {
  18354. Trip = item.Trip
  18355. }).ExecuteCommand();
  18356. }
  18357. _sqlSugar.CommitTran();
  18358. jw = JsonView(true);
  18359. }
  18360. catch (Exception ex)
  18361. {
  18362. _sqlSugar.RollbackTran();
  18363. jw.Msg = "程序异常!" + ex.Message;
  18364. }
  18365. }
  18366. else
  18367. {
  18368. jw.Msg = "请传入正确的参数!";
  18369. }
  18370. return Ok(jw);
  18371. }
  18372. private static string CheckStr(string original, string changed)
  18373. {
  18374. // 创建diff_match_patch对象
  18375. var dmp = new diff_match_patch();
  18376. // 计算差异
  18377. List<Diff> diffs = dmp.diff_main(original, changed);
  18378. // 清理和合并差异
  18379. dmp.diff_cleanupSemantic(diffs);
  18380. // 使用StringBuilder构建最终的字符串
  18381. var finalString = new StringBuilder();
  18382. // 输出差异结果,并构建变动后的字符串
  18383. foreach (Diff diff in diffs)
  18384. {
  18385. switch (diff.operation)
  18386. {
  18387. case Operation.EQUAL:
  18388. // 相等的部分,直接添加到最终字符串
  18389. finalString.Append(diff.text);
  18390. break;
  18391. case Operation.INSERT:
  18392. // 插入的部分,添加标记并添加到最终字符串
  18393. finalString.Append("[++]" + diff.text + "[++]");
  18394. break;
  18395. case Operation.DELETE:
  18396. // 删除的部分,不添加到最终字符串
  18397. //finalString.Append("[++]" + diff.text + "[++]");
  18398. break;
  18399. }
  18400. }
  18401. // 输出变动后的字符串
  18402. return finalString.ToString();
  18403. }
  18404. private class tagContent
  18405. {
  18406. public DateTime Date { get; set; }
  18407. public string StartTag { get; set; }
  18408. public string EndTag { get; set; }
  18409. public string Content { get; set; }
  18410. public static int tagLength { get { return 3; } }
  18411. public static Tuple<string, string> TagFormat { get { return new Tuple<string, string>("【#", "#】"); } }
  18412. public string QueryTag { get { return this.StartTag + this.EndTag; } }
  18413. public bool IsFinally { get; set; }
  18414. }
  18415. private static List<string> ExtractContentBetweenTags(string input, string tag)
  18416. {
  18417. var results = new List<string>();
  18418. // 构造正则表达式,匹配形如 [++]内容[++] 的部分
  18419. string pattern = $@"{Regex.Escape(tag)}(.*?){Regex.Escape(tag)}";
  18420. // 添加 RegexOptions.Singleline 选项使 . 匹配包括换行符在内的所有字符
  18421. MatchCollection matches = Regex.Matches(input, pattern, RegexOptions.Singleline);
  18422. string[] strValueArr = new string[1];
  18423. foreach (System.Text.RegularExpressions.Match match in matches)
  18424. {
  18425. var strValue = match.Groups[1].Value;
  18426. strValueArr = Regex.Split(strValue, @"\r\n|\n");
  18427. }
  18428. results.AddRange(strValueArr.Where(x => !string.IsNullOrWhiteSpace(x)));
  18429. return results;
  18430. }
  18431. /// <summary>
  18432. /// 导出行程单
  18433. /// </summary>
  18434. /// <param name="dto"></param>
  18435. /// <returns></returns>
  18436. [HttpPost]
  18437. public IActionResult ExportTravel(ExportTravelDto dto)
  18438. {
  18439. var jw = JsonView(false);
  18440. jw.Data = "";
  18441. int diid = 0;
  18442. var Find = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid);
  18443. if (Find == null)
  18444. {
  18445. jw.Msg = "请选择正确的团组!";
  18446. return Ok(jw);
  18447. }
  18448. else
  18449. {
  18450. diid = Find.Id;
  18451. }
  18452. //数据源
  18453. var _travelList = new List<Grp_TravelList>();
  18454. DataTable dtBlack = null;
  18455. try
  18456. {
  18457. dtBlack = GeneralMethod.GetTableByBlackCode(diid);
  18458. }
  18459. catch (Exception)
  18460. {
  18461. jw.Msg = "机票黑屏代码有误!";
  18462. return Ok(jw);
  18463. }
  18464. string CityStr = string.Empty;
  18465. if (dtBlack.Rows.Count == 0)
  18466. {
  18467. jw.Msg = "机票黑屏代码有误!";
  18468. return Ok(jw);
  18469. }
  18470. else
  18471. {
  18472. foreach (DataRow row in dtBlack.Rows)
  18473. {
  18474. if (!string.IsNullOrWhiteSpace(row["Error"].ToString()))
  18475. {
  18476. jw.Msg = "机票黑屏代码有误!" + row["Error"].ToString();
  18477. return Ok(jw);
  18478. }
  18479. }
  18480. CityStr = GeneralMethod.GetGroupCityLine(diid, "/");
  18481. _travelList = _sqlSugar.Queryable<Grp_TravelList>().Where(x => x.Diid == diid && x.IsDel == 0 && x.Issel == 1).ToList();
  18482. }
  18483. // 指定的文字
  18484. var targetTextDic = new Dictionary<string, List<string>>();
  18485. //创建数据源Table
  18486. var dtSource = new DataTable();
  18487. dtSource.Columns.Add("Days", typeof(string));
  18488. dtSource.Columns.Add("Date", typeof(string));
  18489. dtSource.Columns.Add("Week", typeof(string));
  18490. dtSource.Columns.Add("Traffic", typeof(string));
  18491. dtSource.Columns.Add("Trip", typeof(string));
  18492. //获取数据,放到datatable
  18493. foreach (var item in _travelList)
  18494. {
  18495. targetTextDic.Add(item.Date, ExtractContentBetweenTags(item.Trip, "[++]"));
  18496. item.Trip = item.Trip.Replace(tagContent.TagFormat.Item1, string.Empty)
  18497. .Replace(tagContent.TagFormat.Item2, string.Empty)
  18498. .Replace("[++]", string.Empty);
  18499. DataRow dr = dtSource.NewRow();
  18500. dr["Days"] = item.Days;
  18501. dr["Date"] = item.Date;
  18502. dr["Week"] = item.WeekDay;
  18503. dr["Traffic"] = item.Traffic_First
  18504. + "\r\n"
  18505. + item.Traffic_Second;
  18506. dr["Trip"] = item.Trip;
  18507. dtSource.Rows.Add(dr);
  18508. }
  18509. var dic = new Dictionary<string, string>
  18510. {
  18511. { "Dele", Find.TeamName.ToString() + GetNum(Find.VisitDays.ToString()) },
  18512. { "City", CityStr },
  18513. { "Days", Find.VisitDays.ToString() },
  18514. { "DeleCode", Find.TourCode },
  18515. { "Pnum", Find.VisitPNumber.ToString() }
  18516. };
  18517. //模板路径
  18518. string tempPath = AppSettingsHelper.Get("WordBasePath") + "Travel/日行程3.docx";
  18519. //载入模板
  18520. Document doc = null;
  18521. DocumentBuilder builder = null;
  18522. try
  18523. {
  18524. //载入模板
  18525. doc = new Document(tempPath);
  18526. builder = new DocumentBuilder(doc);
  18527. }
  18528. catch (Exception)
  18529. {
  18530. jw.Msg = "模板位置不存在!";
  18531. return Ok(jw);
  18532. }
  18533. foreach (var key in dic.Keys)
  18534. {
  18535. Bookmark bookmark = doc.Range.Bookmarks[key];
  18536. if (bookmark != null)
  18537. {
  18538. builder.MoveToBookmark(key);
  18539. builder.Write(dic[key]);
  18540. }
  18541. }
  18542. //获取word里所有表格
  18543. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  18544. //获取所填表格的序数
  18545. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  18546. try
  18547. {
  18548. //循环赋值
  18549. for (int i = 0; i < dtSource.Rows.Count; i++)
  18550. {
  18551. builder.MoveToCell(0, i + 1, 0, 0);
  18552. builder.Write(dtSource.Rows[i]["Days"].ToString());
  18553. builder.MoveToCell(0, i + 1, 1, 0);
  18554. builder.Write(dtSource.Rows[i]["Date"].ToString() + "\r\n" + dtSource.Rows[i]["Week"].ToString());
  18555. builder.MoveToCell(0, i + 1, 2, 0);
  18556. builder.Write(dtSource.Rows[i]["Traffic"].ToString());
  18557. var trip = dtSource.Rows[i]["Trip"].ToString();
  18558. builder.MoveToCell(0, i + 1, 3, 0);
  18559. builder.Write(trip);
  18560. var cell = (Aspose.Words.Tables.Cell)doc.GetChild(NodeType.Cell, ((i + 2) * 4) - 1, true);
  18561. var paragraphs = cell.GetChildNodes(NodeType.Paragraph, true);
  18562. // 获取特定索引的段落
  18563. Paragraph paragraph = (Paragraph)paragraphs[0];
  18564. Run run = paragraph.Runs[0];
  18565. Aspose.Words.Font font = run.Font;
  18566. font.Name = "黑体";
  18567. //设置双休红色
  18568. cell = (Aspose.Words.Tables.Cell)doc.GetChild(NodeType.Cell, ((i + 2) * 4) - 3, true);
  18569. paragraphs = cell.GetChildNodes(NodeType.Paragraph, true);
  18570. paragraph = (Paragraph)paragraphs[1];
  18571. if (paragraph.GetText().Contains("星期六") || paragraph.GetText().Contains("星期日"))
  18572. {
  18573. run = paragraph.Runs[0];
  18574. font = run.Font;
  18575. font.Color = Color.Red;
  18576. }
  18577. }
  18578. }
  18579. catch (Exception ex)
  18580. {
  18581. }
  18582. //删除多余行
  18583. while (tableOne.Rows.Count > 1 + dtSource.Rows.Count)
  18584. {
  18585. tableOne.Rows.RemoveAt(1 + dtSource.Rows.Count);//(1+dtSource.Rows.Count + 1)-1
  18586. }
  18587. var targetTextList = new List<string>();
  18588. // 遍历文档中的表格
  18589. foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
  18590. {
  18591. foreach (Aspose.Words.Tables.Row row in table.Rows)
  18592. {
  18593. var cellIndex = 0;
  18594. foreach (Cell cell in row.Cells)
  18595. {
  18596. if (cellIndex == 1 && row.Cells.Count == 4)
  18597. {
  18598. foreach (var target in targetTextDic.Keys)
  18599. {
  18600. if (cell.GetText().Contains(target))
  18601. {
  18602. targetTextList = targetTextDic[target];
  18603. break;
  18604. }
  18605. }
  18606. }
  18607. // 遍历单元格中的所有段落
  18608. foreach (Paragraph paragraph in cell.Paragraphs)
  18609. {
  18610. // 使用临时列表存储原始 Runs,避免修改时影响遍历
  18611. var runs = new List<Run>();
  18612. foreach (Run run in paragraph.Runs)
  18613. {
  18614. runs.Add(run);
  18615. }
  18616. foreach (Run run in runs)
  18617. {
  18618. foreach (var targetText in targetTextList)
  18619. {
  18620. // 检查文字是否包含指定文字
  18621. if (run.Text.Contains(targetText))
  18622. {
  18623. // 将包含的部分设置为红色
  18624. HighlightText(run, targetText, Color.Red);
  18625. }
  18626. }
  18627. }
  18628. }
  18629. cellIndex++;
  18630. }
  18631. }
  18632. }
  18633. string savePath = AppSettingsHelper.Get("WordBasePath") + "Travel/export/";
  18634. if (!Directory.Exists(savePath))
  18635. {
  18636. try
  18637. {
  18638. Directory.CreateDirectory(savePath);
  18639. }
  18640. catch
  18641. {
  18642. }
  18643. }
  18644. string path = savePath + Find.TeamName + "出访日程";
  18645. string ftpPath = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + "Travel/export/" + Find.TeamName + "出访日程";
  18646. try
  18647. {
  18648. Aspose.Words.SaveFormat saveFormat = Aspose.Words.SaveFormat.Doc;
  18649. string postfix = ".docx";
  18650. if (dto.IsPDF == 1)
  18651. {
  18652. saveFormat = Aspose.Words.SaveFormat.Pdf;
  18653. postfix = ".pdf";
  18654. }
  18655. doc.Save(path + postfix, saveFormat);
  18656. jw = JsonView(true, "导出成功", ftpPath + postfix);
  18657. }
  18658. catch (Exception)
  18659. {
  18660. jw = JsonView(false);
  18661. }
  18662. return Ok(jw);
  18663. }
  18664. /// <summary>
  18665. /// 根据大写数字返回小写数字或根据小写数字返回大写数字
  18666. /// </summary>
  18667. /// <param name="num"></param>
  18668. /// <returns></returns>
  18669. static string GetNum(string num)
  18670. {
  18671. string str = "";
  18672. switch (num)
  18673. {
  18674. case "1":
  18675. str = "一";
  18676. break;
  18677. case "2":
  18678. str = "二";
  18679. break;
  18680. case "3":
  18681. str = "三";
  18682. break;
  18683. case "4":
  18684. str = "四";
  18685. break;
  18686. case "5":
  18687. str = "五";
  18688. break;
  18689. case "6":
  18690. str = "六";
  18691. break;
  18692. case "7":
  18693. str = "七";
  18694. break;
  18695. case "8":
  18696. str = "八";
  18697. break;
  18698. case "9":
  18699. str = "九";
  18700. break;
  18701. case "10":
  18702. str = "十";
  18703. break;
  18704. case "11":
  18705. str = "十一";
  18706. break;
  18707. case "12":
  18708. str = "十二";
  18709. break;
  18710. case "一":
  18711. str = "1";
  18712. break;
  18713. case "二":
  18714. str = "2";
  18715. break;
  18716. case "三":
  18717. str = "3";
  18718. break;
  18719. case "四":
  18720. str = "4";
  18721. break;
  18722. case "五":
  18723. str = "5";
  18724. break;
  18725. case "六":
  18726. str = "6";
  18727. break;
  18728. case "七":
  18729. str = "7";
  18730. break;
  18731. case "八":
  18732. str = "8";
  18733. break;
  18734. case "九":
  18735. str = "9";
  18736. break;
  18737. case "十":
  18738. str = "10";
  18739. break;
  18740. case "十一":
  18741. str = "11";
  18742. break;
  18743. case "十二":
  18744. str = "12";
  18745. break;
  18746. }
  18747. return str;
  18748. }
  18749. /// <summary>
  18750. /// 高亮包含指定文字的部分
  18751. /// </summary>
  18752. /// <param name="run"></param>
  18753. /// <param name="targetText"></param>
  18754. /// <param name="color"></param>
  18755. static void HighlightText(Run run, string targetText, Color color)
  18756. {
  18757. string text = run.Text;
  18758. int startIndex = text.IndexOf(targetText, StringComparison.Ordinal);
  18759. if (startIndex >= 0)
  18760. {
  18761. Paragraph parentParagraph = (Paragraph)run.ParentNode;
  18762. // 前部分
  18763. if (startIndex > 0)
  18764. {
  18765. Run beforeRun = (Run)run.Clone(true);
  18766. beforeRun.Text = text.Substring(0, startIndex);
  18767. parentParagraph.InsertBefore(beforeRun, run);
  18768. }
  18769. // 匹配部分
  18770. Run matchRun = (Run)run.Clone(true);
  18771. matchRun.Text = text.Substring(startIndex, targetText.Length);
  18772. matchRun.Font.Color = color;
  18773. parentParagraph.InsertBefore(matchRun, run);
  18774. // 后部分
  18775. if (startIndex + targetText.Length < text.Length)
  18776. {
  18777. Run afterRun = (Run)run.Clone(true);
  18778. afterRun.Text = text.Substring(startIndex + targetText.Length);
  18779. parentParagraph.InsertBefore(afterRun, run);
  18780. }
  18781. // 删除原始Run
  18782. run.Remove();
  18783. }
  18784. }
  18785. #endregion
  18786. #endregion
  18787. #region 团组成本
  18788. /// <summary>
  18789. /// 团组成本数据初始化
  18790. /// </summary>
  18791. /// <param name="dto"></param>
  18792. /// <returns></returns>
  18793. [HttpPost]
  18794. public async Task<IActionResult> GroupCostInit(GroupCostInItDto dto)
  18795. {
  18796. var groupList = _sqlSugar.SqlQueryable<DelegationInfoAndIsTrueView>($@"
  18797. Select a.Id,TeamName GroupName,b.isTrue From Grp_DelegationInfo a left join (select top 100 percent Diid, CASE
  18798. WHEN COUNT(*) >= 0 THEN 'True'
  18799. ELSE 'False' END as isTrue from Grp_GroupCost where Isdel = 0 and date != '' group by Diid) b on a.Id = b.Diid
  18800. Where TeamName != '' And IsDel = 0 Order By a.VisitStartDate Desc
  18801. ").ToList(); //团组列表
  18802. int diid = dto.Diid == -1 ? groupList.First().Id : dto.Diid;
  18803. var groupInfo = await _groupRepository.PostShareGroupInfo(new ShareGroupInfoDto { PortType = 1, Id = diid }); //团组信息
  18804. var visaCountryInfoArr = new ArrayList();
  18805. var groupinfoValue = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == diid && x.IsDel == 0);
  18806. if (groupinfoValue != null)
  18807. {
  18808. var countryArr = groupinfoValue.VisitCountry ??= string.Empty;
  18809. var dicity = _sqlSugar.Queryable<Sys_Cities>().First(x => x.IsDel == 0 && x.Id == groupinfoValue.CityId);
  18810. dicity ??= new Sys_Cities()
  18811. {
  18812. ParentId = 122
  18813. };
  18814. var diparent = _sqlSugar.Queryable<Sys_Cities>().First(x => x.IsDel == 0 && x.Id == dicity.ParentId);
  18815. var spArr = new string[1] { countryArr };
  18816. if (countryArr.Contains("|"))
  18817. {
  18818. spArr = countryArr.Split("|");
  18819. }
  18820. else if (countryArr.Contains("、"))
  18821. {
  18822. spArr = countryArr.Split("、");
  18823. }
  18824. foreach (var item in spArr.Where(x => !string.IsNullOrWhiteSpace(x)).ToList())
  18825. {
  18826. try
  18827. {
  18828. var visa = _sqlSugar.Queryable<Res_VisaFeeStandard>()
  18829. .Where(x => x.IsDel == 0 && x.Country == item)
  18830. .ToList();
  18831. if (!visa.Any())
  18832. {
  18833. visa = _sqlSugar.Queryable<Res_VisaFeeStandard>()
  18834. .Where(x => x.IsDel == 0 && x.Country.Contains(item))
  18835. .ToList();
  18836. }
  18837. if (visa.Any())
  18838. {
  18839. var visainfo = _sqlSugar.Queryable<Res_VisaFeeStandardDetails>()
  18840. .Where(x => x.IsDel == 0 && visa.Select(x => x.Id).Contains(x.ParentId))
  18841. .ToList();
  18842. var visaMain = visainfo.FirstOrDefault(x => x.ProvinceId == diparent.Id);
  18843. var visayinsiValue = visainfo.FirstOrDefault(x => x.ParentId == visa.FirstOrDefault(x => x.FeeType == 1)?.Id);
  18844. visaCountryInfoArr.Add(new
  18845. {
  18846. country = item,
  18847. yinsi = new
  18848. {
  18849. Id = visayinsiValue.Id,
  18850. value = visayinsiValue.SmallVisaPrice
  18851. },
  18852. visaMain = new
  18853. {
  18854. Id = visaMain.Id,
  18855. IsVisaOnArrival = visaMain.IsVisaOnArrival ? "是" : "否",
  18856. IsElectronicSign = visaMain.IsElectronicSign ? "是" : "否",
  18857. VisaTime = visaMain.VisaTime,
  18858. IsVisaExemptionLarge = visaMain.IsVisaExemptionLarge ? "是" : "否",
  18859. LargeVisaPrice = visaMain.LargeVisaPrice,
  18860. LargeAgencyFee = visaMain.LargeAgencyFee,
  18861. IsVisaExemptionSmall = visaMain.IsVisaExemptionSmall ? "是" : "否",
  18862. SmallVisaPrice = visaMain.SmallVisaPrice,
  18863. SmallAgencyFee = visaMain.SmallAgencyFee,
  18864. NormExtFee = visaMain.NormExtFee,
  18865. UrgExtFee = visaMain.UrgExtFee,
  18866. IsUrgent = visaMain.IsUrgent ? "是" : "否",
  18867. UrgentTime = visaMain.UrgentTime,
  18868. UrgentPrice = visaMain.UrgentPrice,
  18869. UrgentPriceDesc = visaMain.UrgentPriceDesc,
  18870. Remark = visaMain.Remark,
  18871. }
  18872. });
  18873. }
  18874. }
  18875. catch (Exception ex)
  18876. {
  18877. //写入日志
  18878. _logger.LogError(ex, "团组成本解析签证异常!");
  18879. }
  18880. }
  18881. }
  18882. var groupChecks = _checkBoxs.GetCheckBoxsByDiid(diid); //团组选中信息 可枚举
  18883. var groupCost = _GroupCostRepository.GetAllByDiid(diid); //团组列表信息
  18884. #region 屏蔽黑屏代码生成
  18885. //var create = _GroupCostRepository.
  18886. // CreateGroupCostByBlackCode(dto.Diid);
  18887. //if (groupCost.Count == 0 && create.Code == 0)
  18888. //{
  18889. // groupCost = (create.Data as List<Grp_GroupCost>) ?? new List<Grp_GroupCost>();
  18890. //}
  18891. #endregion
  18892. var groupCostMap = _mapper.Map<List<Grp_GroupCostDto>>(groupCost);
  18893. var hotelNumber = _CostTypeHotelNumberRepository.GetCostTypeHotelNumberByDiid(diid); //酒店数量 可枚举
  18894. var GroupCostParameter = _GroupCostParameterRepository.GetGroupCostParameterListByDiid(diid); //成本系数 可枚举
  18895. groupCostMap = groupCostMap.Select(x =>
  18896. {
  18897. if (DateTime.TryParse(x.Date, out DateTime dataForamt))
  18898. {
  18899. x.Date = dataForamt.ToString("yyyy-MM-dd");
  18900. }
  18901. return x;
  18902. }).ToList();
  18903. //GroupCostParameter.Add(new
  18904. // Grp_GroupCostParameter());
  18905. var GroupCostParameterMap = _mapper.Map<List<Grp_GroupCostParameterDto>>(GroupCostParameter);
  18906. bool hotelIsTrue = _sqlSugar.Queryable<Grp_HotelInquiry>().Where(x => x.DiId == diid && x.IsDel == 0).Count() > 0;
  18907. var groupModuleOperators = GeneralMethod.GetGroupModuleOperators(diid);
  18908. return Ok(JsonView(new
  18909. {
  18910. groupList,
  18911. groupInfo,
  18912. groupChecks,
  18913. groupCost = groupCostMap,
  18914. hotelNumber,
  18915. GroupCostParameter = GroupCostParameterMap,
  18916. visaCountryInfoArr = visaCountryInfoArr,
  18917. baoPi = _GroupCostParameterRepository.GetBaoPi(diid),
  18918. blackCodeIsTrue = _sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && x.DiId == diid).Any(), //create.Code == 0 ? true : false,
  18919. hotelIsTrue,
  18920. groupModuleOperators
  18921. }));
  18922. }
  18923. /// <summary>
  18924. /// 团组成本信息保存
  18925. /// </summary>
  18926. /// <param name="dto"></param>
  18927. /// <returns></returns>
  18928. [HttpPost]
  18929. public async Task<IActionResult> SaveGroupCost(GroupCostSavaDto dto)
  18930. {
  18931. if (dto.Diid <= 0 || dto.Userid <= 0)
  18932. {
  18933. return Ok(JsonView(false));
  18934. }
  18935. JsonView jw = null;
  18936. bool isTrue = false;
  18937. #region 复制团组成本
  18938. //if (dto.Diid == 2581)
  18939. //{
  18940. // dto.Diid = 2599;
  18941. // dto.CheckBoxs.ForEach(x =>
  18942. // {
  18943. // x.Diid = 2599;
  18944. // });
  18945. // dto.GroupCosts.ForEach(x =>
  18946. // {
  18947. // x.Diid = 2599;
  18948. // });
  18949. // dto.CostTypeHotelNumbers.ForEach(x =>
  18950. // {
  18951. // x.Diid = 2599;
  18952. // });
  18953. // dto.GroupCostParameters.ForEach(x =>
  18954. // {
  18955. // x.DiId = 2599;
  18956. // });
  18957. //}
  18958. #endregion
  18959. var Grp_groups = _mapper.Map<List<Grp_GroupCost>>(dto.GroupCosts);
  18960. Grp_groups.ForEach(x => { x.CreateUserId = dto.Userid; x.CreateTime = DateTime.Now; }); //.ToString("yyyy-MM-dd HH:mm:ss")
  18961. var Grp_CheckBoxs = _mapper.Map<List<Grp_CheckBoxs>>(dto.CheckBoxs);
  18962. Grp_CheckBoxs.ForEach(x => { x.CreateUserId = dto.Userid; x.CreateTime = DateTime.Now; });
  18963. var Grp_HotelNumber = _mapper.Map<List<Grp_CostTypeHotelNumber>>(dto.CostTypeHotelNumbers);
  18964. var Grp_CostParameters = _mapper.Map<List<Grp_GroupCostParameter>>(dto.GroupCostParameters);
  18965. try
  18966. {
  18967. _sqlSugar.BeginTran();
  18968. isTrue = await _GroupCostRepository.
  18969. SaveGroupCostList(Grp_groups, dto.Diid, dto.Userid); //列表
  18970. isTrue = await _checkBoxs.SaveCheckBoxs(Grp_CheckBoxs, dto.Diid); //选中项
  18971. isTrue = await _CostTypeHotelNumberRepository.SaveHotelNumber(Grp_HotelNumber, dto.Userid, dto.Diid); //酒店房间数量
  18972. isTrue = await _GroupCostParameterRepository.SaveAsync(Grp_CostParameters, dto.Userid, dto.Diid); //系数
  18973. _sqlSugar.CommitTran();
  18974. jw = JsonView(true, "保存成功!", isTrue);
  18975. }
  18976. catch (Exception)
  18977. {
  18978. _sqlSugar.RollbackTran();
  18979. jw = JsonView(false);
  18980. }
  18981. return Ok(jw);
  18982. }
  18983. /// <summary>
  18984. /// 复制团组成本信息
  18985. /// </summary>
  18986. /// <param name="dto"></param>
  18987. /// <returns></returns>
  18988. [HttpPost]
  18989. public async Task<IActionResult> CopyGroupCost(CopyGroupCostDto dto)
  18990. {
  18991. if (dto.Diid <= 0 || dto.Userid <= 0 || dto.ToGroupId <= 0)
  18992. {
  18993. return Ok(JsonView(false, "参数有误!"));
  18994. }
  18995. #region 复制团组成本
  18996. dto.Diid = dto.ToGroupId;
  18997. dto.CheckBoxs.ForEach(x =>
  18998. {
  18999. x.Diid = dto.ToGroupId;
  19000. });
  19001. dto.GroupCosts.ForEach(x =>
  19002. {
  19003. x.Diid = dto.ToGroupId;
  19004. });
  19005. dto.CostTypeHotelNumbers.ForEach(x =>
  19006. {
  19007. x.Diid = dto.ToGroupId;
  19008. });
  19009. dto.GroupCostParameters.ForEach(x =>
  19010. {
  19011. x.DiId = dto.ToGroupId;
  19012. });
  19013. #endregion
  19014. JsonView jw = null;
  19015. bool isTrue = false;
  19016. var Grp_groups = _mapper.Map<List<Grp_GroupCost>>(dto.GroupCosts);
  19017. Grp_groups.ForEach(x => { x.CreateUserId = dto.Userid; x.CreateTime = DateTime.Now; }); //.ToString("yyyy-MM-dd HH:mm:ss")
  19018. var Grp_CheckBoxs = _mapper.Map<List<Grp_CheckBoxs>>(dto.CheckBoxs);
  19019. Grp_CheckBoxs.ForEach(x => { x.CreateUserId = dto.Userid; x.CreateTime = DateTime.Now; });
  19020. var Grp_HotelNumber = _mapper.Map<List<Grp_CostTypeHotelNumber>>(dto.CostTypeHotelNumbers);
  19021. var Grp_CostParameters = _mapper.Map<List<Grp_GroupCostParameter>>(dto.GroupCostParameters);
  19022. try
  19023. {
  19024. _sqlSugar.BeginTran();
  19025. isTrue = await _GroupCostRepository.
  19026. SaveGroupCostList(Grp_groups, dto.Diid, dto.Userid); //列表
  19027. isTrue = await _checkBoxs.SaveCheckBoxs(Grp_CheckBoxs, dto.Diid); //选中项
  19028. isTrue = await _CostTypeHotelNumberRepository.SaveHotelNumber(Grp_HotelNumber, dto.Userid, dto.Diid); //酒店房间数量
  19029. isTrue = await _GroupCostParameterRepository.SaveAsync(Grp_CostParameters, dto.Userid, dto.Diid); //系数
  19030. _sqlSugar.CommitTran();
  19031. jw = JsonView(true, "保存成功!", isTrue);
  19032. }
  19033. catch (Exception)
  19034. {
  19035. _sqlSugar.RollbackTran();
  19036. jw = JsonView(false);
  19037. }
  19038. return Ok(jw);
  19039. }
  19040. /// <summary>
  19041. /// 司兼导数据
  19042. /// </summary>
  19043. /// <param name="dto"></param>
  19044. /// <returns></returns>
  19045. [HttpPost]
  19046. public IActionResult GetCarGuides(CarGuidesDto dto)
  19047. {
  19048. var Data = _sqlSugar.SqlQueryable<Grp_CarGuides>($@" select * from Grp_CarGuides where isdel = 0 ").ToList();
  19049. return Ok(JsonView(true, "获取成功!", Data));
  19050. }
  19051. /// <summary>
  19052. /// 导游数据
  19053. /// </summary>
  19054. /// <param name="dto"></param>
  19055. /// <returns></returns>
  19056. [HttpPost]
  19057. public IActionResult GetGuidesInfo(CarGuidesDto dto)
  19058. {
  19059. //var Data = _sqlSugar.SqlQueryable<Grp_GuidesInfo>($@" SELECT* FROM (
  19060. // 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
  19061. // where RowNumber BETWEEN {(dto.Page - 1) * dto.Size + 1} and {(dto.Page) * dto.Size}").ToList();
  19062. var Data = _sqlSugar.SqlQueryable<Grp_GuidesInfo>($@" select * from Grp_GuidesInfo where isdel = 0 ").ToList();
  19063. return Ok(JsonView(true, "获取成功!", Data));
  19064. }
  19065. /// <summary>
  19066. /// 成本车数据
  19067. /// </summary>
  19068. /// <param name="dto"></param>
  19069. /// <returns></returns>
  19070. [HttpPost]
  19071. public IActionResult GetCarInfo(CarGuidesDto dto)
  19072. {
  19073. var Data = _sqlSugar.SqlQueryable<Grp_CarInfo>($@" select * from Grp_CarInfo where isdel = 0 ").ToList();
  19074. return Ok(JsonView(true, "获取成功!", Data));
  19075. }
  19076. /// <summary>
  19077. /// 景点数据
  19078. /// </summary>
  19079. /// <param name="dto"></param>
  19080. /// <returns></returns>
  19081. [HttpPost]
  19082. public IActionResult GetScenicSpotInfo(CarGuidesDto dto)
  19083. {
  19084. var Data = _sqlSugar.SqlQueryable<Grp_ScenicSpotInfo>($@" select * from Grp_ScenicSpotInfo where isdel = 0 ").ToList();
  19085. return Ok(JsonView(true, "获取成功!", Data));
  19086. }
  19087. /// <summary>
  19088. /// 成本通知
  19089. /// </summary>
  19090. /// <param name="dto"></param>
  19091. /// <returns></returns>
  19092. [HttpPost]
  19093. public async Task<IActionResult> GroupIsShare(GroupIsShareDto dto)
  19094. {
  19095. if (dto.Diid < 0)
  19096. {
  19097. return Ok(JsonView(false));
  19098. }
  19099. JsonView jw;
  19100. var GroupCostParameter = _GroupCostParameterRepository.GetGroupCostParameterMainByDiid(dto.Diid);
  19101. if (GroupCostParameter != null)
  19102. {
  19103. int IsShare = 0;
  19104. if (GroupCostParameter.IsShare == 0) IsShare = 1;
  19105. else if (GroupCostParameter.IsShare == 1) IsShare = 0;
  19106. bool isTrue = await _GroupCostParameterRepository.UpdateIsShareById(GroupCostParameter.Id, IsShare);
  19107. string msg = string.Empty;
  19108. if (isTrue)
  19109. {
  19110. if (IsShare == 0)
  19111. {
  19112. msg = "禁止通知,其他模块操作人员不可见此成本信息!";
  19113. }
  19114. else
  19115. {
  19116. #region 企微通知对应岗位用户
  19117. try
  19118. {
  19119. await AppNoticeLibrary.SendUserMsg_GroupShare_ToJob(dto.Diid);
  19120. //机票预算群通知
  19121. await AppNoticeLibrary.SendChatMsg_AirCostChat(dto.Diid, QiyeWeChatEnum.AirCostChat01);
  19122. }
  19123. catch (Exception)
  19124. {
  19125. }
  19126. #endregion
  19127. msg = "通知成功,其他模块操作人员可见此成本信息!";
  19128. }
  19129. jw = JsonView(isTrue, msg, new { IsShare });
  19130. }
  19131. else
  19132. {
  19133. msg = "修改失败!";
  19134. jw = JsonView(isTrue, msg);
  19135. }
  19136. }
  19137. else
  19138. {
  19139. jw = JsonView(false, "该团没有数据,请添加数据,保存后再操作!");
  19140. }
  19141. return Ok(jw);
  19142. }
  19143. /// <summary>
  19144. /// 导出报价单
  19145. /// </summary>
  19146. /// <param name="dto"></param>
  19147. /// <returns></returns>
  19148. [HttpPost]
  19149. public async Task<IActionResult> ExportPriceCheckWordFile(GroupCostExportWordFile dto)
  19150. {
  19151. if (dto.Diid == 0)
  19152. {
  19153. return Ok(JsonView(false, "请传递团组id"));
  19154. }
  19155. var deleInfo = await _groupRepository.PostGroupInfo(new GroupInfoDto { Id = dto.Diid, PortType = 1 });
  19156. if (deleInfo.Code != 0)
  19157. {
  19158. return Ok(JsonView(false, "团组信息查询失败!"));
  19159. }
  19160. var di = deleInfo.Data as DelegationInfoWebView;
  19161. if (di != null)
  19162. {
  19163. di.TeamName = di.TeamName.Replace("|", "、");
  19164. di.VisitCountry = di.VisitCountry.Replace("|", "、");
  19165. //文件名
  19166. string strFileName = di.TeamName + "-收款账单.doc";
  19167. //获取模板
  19168. string tmppath = (AppSettingsHelper.Get("WordBasePath") + "Template/收款账单(四川)模板.doc");
  19169. //载入模板
  19170. Document doc = new Document(tmppath);
  19171. decimal TotalPrice = 0.00M;
  19172. string itemStr = string.Empty;
  19173. Dictionary<string, string> airSouer = new Dictionary<string, string>();
  19174. //airSouer.Add("JJCTBR", "经济舱及酒店双人间");
  19175. airSouer.Add("JJCTBR", "经济舱及酒店双人间");
  19176. airSouer.Add("JJCSGR", "经济舱及酒店单人间");
  19177. airSouer.Add("GWCSGR", "公务舱及酒店单人间");
  19178. airSouer.Add("GWCJSES", "公务舱及酒店小套房");
  19179. airSouer.Add("GWCSUITE", "公务舱及酒店套房");
  19180. airSouer.Add("JJCSUITE", "经济舱及酒店套房");
  19181. var groupCostType = dto.airs.GroupBy(x => x.costType).OrderBy(x => x.Key);
  19182. foreach (var cost in groupCostType)
  19183. {
  19184. var List = cost.ToList();
  19185. if (cost.Key == "A")
  19186. {
  19187. foreach (var ListItem in List)
  19188. {
  19189. if (ListItem.number > 0)
  19190. {
  19191. if (ListItem.code.Contains("TBR"))
  19192. {
  19193. itemStr += "团费(" + airSouer[ListItem.code] + ") RMB " + ListItem.price.ToString("F2") + "/人*" + ListItem.number + "(" + (ListItem.number / 2) + "间) ............合计 RMB " + (ListItem.number * ListItem.price).ToString("#0.00") + "\n";
  19194. }
  19195. else
  19196. {
  19197. itemStr += "团费(" + airSouer[ListItem.code] + ") RMB " + ListItem.price.ToString("F2") + "/人*" + ListItem.number + "(" + ListItem.number + "间) ............合计 RMB " + (ListItem.number * ListItem.price).ToString("#0.00") + "\n";
  19198. }
  19199. TotalPrice += (ListItem.number * ListItem.price);
  19200. }
  19201. }
  19202. }
  19203. else
  19204. {
  19205. itemStr = itemStr.Insert(0, "A段\r\n");
  19206. itemStr += "B段\r\n";
  19207. foreach (var ListItem in List)
  19208. {
  19209. if (ListItem.number > 0)
  19210. {
  19211. if (ListItem.code.Contains("TBR"))
  19212. {
  19213. itemStr += "团费(" + airSouer[ListItem.code] + ") RMB " + ListItem.price.ToString("F2") + "/人*" + ListItem.number + "(" + (ListItem.number / 2) + "间) ............合计 RMB " + (ListItem.number * ListItem.price).ToString("#0.00") + "\n";
  19214. }
  19215. else
  19216. {
  19217. itemStr += "团费(" + airSouer[ListItem.code] + ") RMB " + ListItem.price.ToString("F2") + "/人*" + ListItem.number + "(" + ListItem.number + "间) ............合计 RMB " + (ListItem.number * ListItem.price).ToString("#0.00") + "\n";
  19218. }
  19219. TotalPrice += (ListItem.number * ListItem.price);
  19220. }
  19221. }
  19222. }
  19223. }
  19224. #region 替换Word模板书签内容
  19225. Dictionary<string, string> marks = new Dictionary<string, string>();
  19226. marks.Add("To", di.ClientUnit);//付款方
  19227. marks.Add("ToTel", di.TellPhone);//付款方电话
  19228. marks.Add("Date", DateTime.Now.ToString("yyyy-MM-dd"));//导出时间
  19229. marks.Add("Team", di.VisitCountry.Replace(" ", "、"));//团队名称
  19230. marks.Add("TontractTime", (di.VisitDate).ToString("yyyy年MM月dd日"));//付款日期
  19231. marks.Add("PayDay", (di.PayDay).ToString());//付款预期
  19232. marks.Add("PaymentMoney", (di.PaymentMoney).ToString("#0.00"));//付款金额
  19233. marks.Add("WeChat", di.WeChatNo ?? "");//微信号
  19234. marks.Add("PayItemContent", itemStr);//详细信息
  19235. marks.Add("Total", TotalPrice.ToString("F2"));//合计
  19236. #endregion
  19237. ////注
  19238. //if (doc.Range.Bookmarks["Attention"] != null)
  19239. //{
  19240. // Bookmark mark = doc.Range.Bookmarks["Attention"];
  19241. // mark.Text = frList[0].Attention;
  19242. //}
  19243. foreach (var item in marks.Keys)
  19244. {
  19245. if (doc.Range.Bookmarks[item] != null)
  19246. {
  19247. Bookmark mark = doc.Range.Bookmarks[item];
  19248. mark.Text = marks[item];
  19249. }
  19250. }
  19251. byte[] bytes = null;
  19252. using (MemoryStream stream = new MemoryStream())
  19253. {
  19254. doc.Save(stream, Aspose.Words.SaveFormat.Doc);
  19255. bytes = stream.ToArray();
  19256. }
  19257. //doc.Save((AppSettingsHelper.Get("WordBasePath") + "Template/") + strFileName);
  19258. return Ok(JsonView(true, "", new
  19259. {
  19260. Data = bytes,
  19261. strFileName,
  19262. }));
  19263. }
  19264. else
  19265. {
  19266. return Ok(JsonView(false, "团组信息不存在!"));
  19267. }
  19268. }
  19269. /// <summary>
  19270. /// 导出团组成本
  19271. /// </summary>
  19272. /// <param name="dto"></param>
  19273. /// <returns></returns>
  19274. [HttpPost]
  19275. public async Task<IActionResult> ExportGroupCostExcelFile(GroupCostExportExcelFile dto)
  19276. {
  19277. var jw = JsonView(false);
  19278. if (dto.Diid == 0)
  19279. {
  19280. return Ok(JsonView(false, "请传递团组id"));
  19281. }
  19282. var deleInfo = await _groupRepository.PostGroupInfo(new GroupInfoDto { Id = dto.Diid, PortType = 1 });
  19283. if (deleInfo.Code != 0)
  19284. {
  19285. return Ok(JsonView(false, "团组信息查询失败!"));
  19286. }
  19287. var di = deleInfo.Data as DelegationInfoWebView;
  19288. if (di == null)
  19289. {
  19290. return Ok(JsonView(false, "团组信息查询失败!"));
  19291. }
  19292. List<GroupCost_Excel> List_GC1 = new List<GroupCost_Excel>();
  19293. WorkbookDesigner designer = new WorkbookDesigner();
  19294. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + ("Template/团组-成本.xls"));
  19295. var List_GC = _GroupCostRepository.GetAllByDiid(dto.Diid);
  19296. List<int> hideColumnList = new List<int>();
  19297. var ColumnSetting = new[]
  19298. {
  19299. new { tag = "VF", Index = 4, P = "CarCost" },
  19300. new { tag = "VN", Index = 5, P = "CarNumber" },
  19301. new { tag = "VRD", Index = 6, P = "CarTiming" },
  19302. new { tag = "T/G S", Index = 7, P = "TGS" },
  19303. new { tag = "TGWH", Index = 8, P = "TGWH" },
  19304. new { tag = "T/G OF", Index = 9, P = "TGOF" },
  19305. new { tag = "T/G M", Index = 10, P = "TGM" },
  19306. new { tag = "T/G A", Index = 11, P = "TGA" },
  19307. new { tag = "T/G TF", Index = 12, P = "TGTF" },
  19308. new { tag = "T/G EF", Index = 13, P = "TGEF" },
  19309. new { tag = "C/F S", Index = 14, P = "CFS" },
  19310. new { tag = "C/F M", Index = 15, P = "CFM" },
  19311. new { tag = "C/F OF", Index = 16, P = "CFOF" },
  19312. new { tag = "B", Index = 17, P = "B" },
  19313. new { tag = "L", Index = 18, P = "L" },
  19314. new { tag = "D", Index = 19, P = "D" },
  19315. new { tag = "TBR", Index = 20, P = "TBR" },
  19316. new { tag = "SGR", Index = 21, P = "SGR" },
  19317. new { tag = "JS/ES", Index = 22, P = "JS_ES" },
  19318. new { tag = "Suite", Index = 23, P = "Suite" },
  19319. new { tag = "ACCO N", Index = 24, P = "ACCON" },
  19320. new { tag = "T/V", Index = 25, P = "TV" },
  19321. new { tag = "1/L", Index = 26, P = "iL" },
  19322. new { tag = "I/F", Index = 27, P = "IF" },
  19323. new { tag = "EF", Index = 28, P = "EF" },
  19324. new { tag = "B/R/F", Index = 29, P = "B_R_F" },
  19325. new { tag = "TE", Index = 30, P = "TE" },
  19326. new { tag = "T/G T", Index = 31, P = "TGTips" },
  19327. new { tag = "DRV T", Index = 32, P = "DRVTips" },
  19328. new { tag = "P/C", Index = 33, P = "PC" },
  19329. new { tag = "T/L F", Index = 34, P = "TLF" },
  19330. new { tag = "E/C T", Index = 35, P = "ECT" }
  19331. };
  19332. Func<string, bool> isEmpty = (str) =>
  19333. {
  19334. if (decimal.TryParse(str, out decimal str_De) && str_De == 0)
  19335. {
  19336. return true;
  19337. }
  19338. if (string.IsNullOrWhiteSpace(str))
  19339. {
  19340. return true;
  19341. }
  19342. return false;
  19343. };
  19344. for (int i = 0; i < List_GC.Count; i++)
  19345. {
  19346. GroupCost_Excel gc = new GroupCost_Excel();
  19347. gc.Id = List_GC[i].Id;
  19348. gc.Diid = List_GC[i].Diid.ToString();
  19349. gc.DAY = List_GC[i].DAY;
  19350. string week = "";
  19351. if (!string.IsNullOrEmpty(List_GC[i].Date.Trim()))
  19352. week = CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(Convert.ToDateTime(List_GC[i].Date).DayOfWeek);
  19353. gc.Date = (List_GC[i].Date + "\n" + week).ToString();
  19354. gc.ITIN = List_GC[i].ITIN;
  19355. gc.CarType = List_GC[i].CarType;
  19356. gc.CarTiming = isEmpty(List_GC[i].CarTiming.ToString()) ? "" : List_GC[i].CarTiming.ToString();
  19357. gc.CarCost = isEmpty(List_GC[i].CarCost.ToString()) ? "" : List_GC[i].CarCost.ToString();
  19358. gc.CarNumber = isEmpty(List_GC[i].CarNumber.ToString()) ? "" : List_GC[i].CarNumber.ToString();
  19359. gc.TGS = isEmpty(List_GC[i].TGS.ToString()) ? "" : List_GC[i].TGS.ToString();
  19360. gc.TGWH = isEmpty(List_GC[i].TGWH.ToString()) ? "" : List_GC[i].TGWH.ToString();
  19361. gc.TGN = isEmpty(List_GC[i].TGN.ToString()) ? "" : List_GC[i].TGN.ToString();
  19362. gc.TGOF = isEmpty(List_GC[i].TGOF.ToString()) ? "" : List_GC[i].TGOF.ToString();
  19363. gc.TGM = isEmpty(List_GC[i].TGM.ToString()) ? "" : List_GC[i].TGM.ToString();
  19364. gc.TGA = isEmpty(List_GC[i].TGA.ToString()) ? "" : List_GC[i].TGA.ToString();
  19365. gc.TGTF = isEmpty(List_GC[i].TGTF.ToString()) ? "" : List_GC[i].TGTF.ToString();
  19366. gc.TGEF = isEmpty(List_GC[i].TGEF.ToString()) ? "" : List_GC[i].TGEF.ToString();
  19367. gc.CFS = isEmpty(List_GC[i].CFS.ToString()) ? "" : List_GC[i].CFS.ToString();
  19368. gc.CFM = isEmpty(List_GC[i].CFM.ToString()) ? "" : List_GC[i].CFM.ToString();
  19369. gc.CFOF = isEmpty(List_GC[i].CFOF.ToString()) ? "" : List_GC[i].CFOF.ToString();
  19370. gc.B = isEmpty(List_GC[i].B.ToString()) ? "" : List_GC[i].B.ToString();
  19371. gc.L = isEmpty(List_GC[i].L.ToString()) ? "" : List_GC[i].L.ToString();
  19372. gc.D = isEmpty(List_GC[i].D.ToString()) ? "" : List_GC[i].D.ToString();
  19373. gc.TBR = isEmpty(List_GC[i].TBR.ToString()) ? "" : List_GC[i].TBR.ToString();
  19374. gc.SGR = isEmpty(List_GC[i].SGR.ToString()) ? "" : List_GC[i].SGR.ToString();
  19375. gc.JS_ES = isEmpty(List_GC[i].JS_ES.ToString()) ? "" : List_GC[i].JS_ES.ToString();
  19376. gc.Suite = isEmpty(List_GC[i].Suite.ToString()) ? "" : List_GC[i].Suite.ToString();
  19377. gc.ACCON = isEmpty(List_GC[i].ACCON.ToString()) ? "" : List_GC[i].ACCON.ToString();
  19378. gc.TV = isEmpty(List_GC[i].TV.ToString()) ? "" : List_GC[i].TV.ToString();
  19379. gc.iL = isEmpty(List_GC[i].iL.ToString()) ? "" : List_GC[i].iL.ToString();
  19380. gc.IF = isEmpty(List_GC[i].IF.ToString()) ? "" : List_GC[i].IF.ToString();
  19381. gc.EF = isEmpty(List_GC[i].EF.ToString()) ? "" : List_GC[i].EF.ToString();
  19382. gc.B_R_F = isEmpty(List_GC[i].B_R_F.ToString()) ? "" : List_GC[i].B_R_F.ToString();
  19383. gc.TE = isEmpty(List_GC[i].TE.ToString()) ? "" : List_GC[i].TE.ToString();
  19384. gc.TGTips = isEmpty(List_GC[i].TGTips.ToString()) ? "" : List_GC[i].TGTips.ToString();
  19385. gc.DRVTips = isEmpty(List_GC[i].DRVTips.ToString()) ? "" : List_GC[i].DRVTips.ToString();
  19386. gc.PC = isEmpty(List_GC[i].PC.ToString()) ? "" : List_GC[i].PC.ToString();
  19387. gc.TLF = isEmpty(List_GC[i].TLF.ToString()) ? "" : List_GC[i].TLF.ToString();
  19388. gc.ECT = isEmpty(List_GC[i].ECT.ToString()) ? "" : List_GC[i].ECT.ToString();
  19389. gc.EFR = List_GC[i].EFR;
  19390. List_GC1.Add(gc);
  19391. }
  19392. if (List_GC1.Count > 0)
  19393. {
  19394. var p = List_GC1[0];
  19395. var prs = p.GetType().GetProperties();
  19396. foreach (var item in prs)
  19397. {
  19398. var tp = item.PropertyType;
  19399. if (tp == typeof(int))
  19400. {
  19401. var val = List_GC1.Sum(x => (int)x.GetType().GetProperty(item.Name).GetValue(x));
  19402. if (val == 0)
  19403. {
  19404. var columnSetting = ColumnSetting.FirstOrDefault(x => x.P == item.Name);
  19405. if (columnSetting != null)
  19406. {
  19407. hideColumnList.Add(columnSetting.Index);
  19408. }
  19409. }
  19410. }
  19411. if (tp == typeof(decimal))
  19412. {
  19413. var val = List_GC1.Sum(x => (decimal)x.GetType().GetProperty(item.Name).GetValue(x));
  19414. if (val == 0)
  19415. {
  19416. var columnSetting = ColumnSetting.FirstOrDefault(x => x.P == item.Name);
  19417. if (columnSetting != null)
  19418. {
  19419. hideColumnList.Add(columnSetting.Index);
  19420. }
  19421. }
  19422. }
  19423. if (tp == typeof(string))
  19424. {
  19425. var val = List_GC1.Sum(x =>
  19426. {
  19427. var str = (string)x.GetType().GetProperty(item.Name).GetValue(x);
  19428. if (decimal.TryParse(str, out decimal str_De))
  19429. {
  19430. return str_De;
  19431. }
  19432. else
  19433. {
  19434. return string.IsNullOrEmpty((string)x.GetType().GetProperty(item.Name).GetValue(x)) ? 0 : 1;
  19435. }
  19436. });
  19437. if (val == 0)
  19438. {
  19439. var columnSetting = ColumnSetting.FirstOrDefault(x => x.P == item.Name);
  19440. if (columnSetting != null)
  19441. {
  19442. hideColumnList.Add(columnSetting.Index);
  19443. }
  19444. }
  19445. }
  19446. }
  19447. }
  19448. var dt = CommonFun.GetDataTableFromIList(List_GC1);
  19449. dt.TableName = "TB";
  19450. //报表标题等不用dt的值
  19451. designer.SetDataSource("TeamName", dto.title.TeamName);
  19452. designer.SetDataSource("Pnumber", dto.title.GroupNumber);
  19453. designer.SetDataSource("Tax", dto.title.Tax);
  19454. //designer.SetDataSource("FFYS", lblHotelCB.Text);
  19455. designer.SetDataSource("Currency", dto.title.Currency);
  19456. //designer.SetDataSource("HotelXS", txtHotelXS.Text);
  19457. designer.SetDataSource("Rate", dto.title.Rate);
  19458. var hotels = _CostTypeHotelNumberRepository.GetCostTypeHotelNumberByDiid(dto.Diid);
  19459. var Aparams = hotels.Find(x => x.Type == "Default");
  19460. if (Aparams == null)
  19461. {
  19462. return Ok(jw);
  19463. }
  19464. //酒店数量
  19465. var txtSGRNumber = Aparams.SGR.ToString();
  19466. var txtTBRNumber = Aparams.TBR.ToString();
  19467. var txtJSESNumber = Aparams.JSES.ToString();
  19468. var txtSUITENumbe = Aparams.SUITE.ToString();
  19469. if (dto.costType == "B")
  19470. {
  19471. Aparams = hotels.Find(x => x.Type == "A");
  19472. var Bparams = hotels.Find(x => x.Type == "B");
  19473. if (Aparams == null || Bparams == null)
  19474. {
  19475. return Ok(jw);
  19476. }
  19477. txtSGRNumber = "A段人数:" + Aparams.SGR.ToString() + " B段人数:" + Bparams.SGR.ToString();
  19478. txtTBRNumber = "A段人数:" + Aparams.TBR.ToString() + " B段人数:" + Bparams.TBR.ToString();
  19479. txtJSESNumber = "A段人数:" + Aparams.JSES.ToString() + " B段人数:" + Bparams.JSES.ToString();
  19480. txtSUITENumbe = "A段人数:" + Aparams.SUITE.ToString() + " B段人数:" + Bparams.SUITE.ToString();
  19481. }
  19482. designer.SetDataSource("SGRNumber", txtSGRNumber);
  19483. designer.SetDataSource("TBRNumber", txtTBRNumber);
  19484. designer.SetDataSource("JSESNumber", txtJSESNumber);
  19485. designer.SetDataSource("SUITENumber", txtSUITENumbe);
  19486. var ws = designer.Workbook.Worksheets[1];
  19487. int Row = List_GC.Count;
  19488. int startIndex = 0;
  19489. int HideRows = 0;
  19490. Row = 0;
  19491. List<int> hideRowsList = new List<int>();
  19492. decimal TzZCB2 = 0.00M, TzZLR2 = 0.00M, TzZBJ2 = 0.00M;
  19493. #region A段left数据
  19494. var left = dto.leftInfo.Find(x => x.Type == "A");
  19495. if (left == null)
  19496. {
  19497. return Ok(jw);
  19498. }
  19499. var leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("签证"));
  19500. if (leftBindData != null)
  19501. {
  19502. designer.SetDataSource("VisaDRCB", leftBindData.cb);
  19503. designer.SetDataSource("VisaRS", leftBindData.rs);
  19504. designer.SetDataSource("VisaXS", leftBindData.xs);
  19505. designer.SetDataSource("VisaZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19506. designer.SetDataSource("VisaDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19507. designer.SetDataSource("VisaZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19508. designer.SetDataSource("VisaDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19509. designer.SetDataSource("VisaZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19510. }
  19511. else
  19512. {
  19513. hideRowsList.Add(Row + startIndex + HideRows);
  19514. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19515. }
  19516. HideRows += 2;
  19517. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("保险"));
  19518. if (leftBindData != null)
  19519. {
  19520. designer.SetDataSource("BXDRCB", leftBindData.cb);
  19521. designer.SetDataSource("BXRS", leftBindData.rs);
  19522. designer.SetDataSource("BXXS", leftBindData.xs);
  19523. designer.SetDataSource("BXZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19524. designer.SetDataSource("BXDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19525. designer.SetDataSource("BXZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19526. designer.SetDataSource("BXDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19527. designer.SetDataSource("BXZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19528. }
  19529. else
  19530. {
  19531. hideRowsList.Add(Row + startIndex + HideRows);
  19532. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19533. }
  19534. HideRows += 2;
  19535. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("核酸"));
  19536. if (leftBindData != null)
  19537. {
  19538. designer.SetDataSource("HSDRCB", leftBindData.cb);
  19539. designer.SetDataSource("HSRS", leftBindData.rs);
  19540. designer.SetDataSource("HSXS", leftBindData.xs);
  19541. designer.SetDataSource("HSZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19542. designer.SetDataSource("HSDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19543. designer.SetDataSource("HSZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19544. designer.SetDataSource("HSDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19545. designer.SetDataSource("HSZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19546. }
  19547. else
  19548. {
  19549. hideRowsList.Add(Row + startIndex + HideRows);
  19550. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19551. }
  19552. HideRows += 2;
  19553. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("经济舱"));
  19554. if (leftBindData != null)
  19555. {
  19556. designer.SetDataSource("JPJJCCB", leftBindData.cb);
  19557. designer.SetDataSource("JPJJCPnum", leftBindData.rs);
  19558. designer.SetDataSource("JPJJCXS", leftBindData.xs);
  19559. designer.SetDataSource("JPJJCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19560. designer.SetDataSource("JPJJCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19561. designer.SetDataSource("JPJJCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19562. designer.SetDataSource("JPJJCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19563. designer.SetDataSource("JPJJCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19564. }
  19565. else
  19566. {
  19567. hideRowsList.Add(Row + startIndex + HideRows);
  19568. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19569. }
  19570. HideRows += 2;
  19571. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("公务舱"));
  19572. if (leftBindData != null)
  19573. {
  19574. designer.SetDataSource("JPGWCCB", leftBindData.cb);
  19575. designer.SetDataSource("JPGWCPNum", leftBindData.rs);
  19576. designer.SetDataSource("JPGWCXS", leftBindData.xs);
  19577. designer.SetDataSource("JPGWCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19578. designer.SetDataSource("JPGWCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19579. designer.SetDataSource("JPGWCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19580. designer.SetDataSource("JPGWCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19581. designer.SetDataSource("JPGWCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19582. }
  19583. else
  19584. {
  19585. hideRowsList.Add(Row + startIndex + HideRows);
  19586. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19587. }
  19588. HideRows += 2;
  19589. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("头等舱"));
  19590. if (leftBindData != null)
  19591. {
  19592. designer.SetDataSource("JPTDCCB", leftBindData.cb);
  19593. designer.SetDataSource("JPTDCPNum", leftBindData.rs);
  19594. designer.SetDataSource("JPTDCXS", leftBindData.xs);
  19595. designer.SetDataSource("JPTDCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19596. designer.SetDataSource("JPTDCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19597. designer.SetDataSource("JPTDCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19598. designer.SetDataSource("JPTDCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19599. designer.SetDataSource("JPTDCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19600. }
  19601. else
  19602. {
  19603. hideRowsList.Add(Row + startIndex + HideRows);
  19604. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19605. }
  19606. HideRows += 2;
  19607. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("TBR"));
  19608. if (leftBindData != null)
  19609. {
  19610. ////TBR
  19611. designer.SetDataSource("HotelTBRDRCB", leftBindData.cb);
  19612. designer.SetDataSource("HotelTBRRS", leftBindData.rs);
  19613. designer.SetDataSource("HotelTBRXS", leftBindData.xs);
  19614. designer.SetDataSource("HotelTBRCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19615. designer.SetDataSource("HotelTBRDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19616. designer.SetDataSource("HotelTBRZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19617. designer.SetDataSource("HotelTBRDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19618. designer.SetDataSource("HotelTBRZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19619. }
  19620. else
  19621. {
  19622. hideRowsList.Add(Row + startIndex + HideRows);
  19623. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19624. }
  19625. HideRows += 2;
  19626. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("SGR"));
  19627. if (leftBindData != null)
  19628. {
  19629. ////SGR
  19630. designer.SetDataSource("HotelSGRDRCB", leftBindData.cb);
  19631. designer.SetDataSource("HotelSGRRS", leftBindData.rs);
  19632. designer.SetDataSource("HotelSGRXS", leftBindData.xs);
  19633. designer.SetDataSource("HotelSGRCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19634. designer.SetDataSource("HotelSGRDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19635. designer.SetDataSource("HotelSGRZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19636. designer.SetDataSource("HotelSGRDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19637. designer.SetDataSource("HotelSGRZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19638. }
  19639. else
  19640. {
  19641. hideRowsList.Add(Row + startIndex + HideRows);
  19642. // ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19643. }
  19644. HideRows += 2;
  19645. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("JSES"));
  19646. if (leftBindData != null)
  19647. {
  19648. ////JS/ES
  19649. designer.SetDataSource("HotelJSESDRCB", leftBindData.cb);
  19650. designer.SetDataSource("HotelJSESRS", leftBindData.rs);
  19651. designer.SetDataSource("HotelJSESXS", leftBindData.xs);
  19652. designer.SetDataSource("HotelJSESCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19653. designer.SetDataSource("HotelJSESDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19654. designer.SetDataSource("HotelJSESZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19655. designer.SetDataSource("HotelJSESDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19656. designer.SetDataSource("HotelJSESZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19657. }
  19658. else
  19659. {
  19660. hideRowsList.Add(Row + startIndex + HideRows);
  19661. // ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19662. }
  19663. HideRows += 2;
  19664. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("SUITE"));
  19665. if (leftBindData != null)
  19666. {
  19667. ////SUITE
  19668. designer.SetDataSource("HotelSUITEDRCB", leftBindData.cb);
  19669. designer.SetDataSource("HotelSUITERS", leftBindData.rs);
  19670. designer.SetDataSource("HotelSUITEXS", leftBindData.xs);
  19671. designer.SetDataSource("HotelSUITECB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19672. designer.SetDataSource("HotelSUITEDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19673. designer.SetDataSource("HotelSUITEZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19674. designer.SetDataSource("HotelSUITEDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19675. designer.SetDataSource("HotelSUITEZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19676. }
  19677. else
  19678. {
  19679. hideRowsList.Add(Row + startIndex + HideRows);
  19680. // ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19681. }
  19682. HideRows += 2;
  19683. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("地接"));
  19684. if (leftBindData != null)
  19685. {
  19686. designer.SetDataSource("DJDRCB", leftBindData.cb);
  19687. designer.SetDataSource("DJRS", leftBindData.rs);
  19688. designer.SetDataSource("DJXS", leftBindData.xs);
  19689. designer.SetDataSource("DJCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19690. designer.SetDataSource("DJDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19691. designer.SetDataSource("DJZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19692. designer.SetDataSource("DJDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19693. designer.SetDataSource("DJZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19694. }
  19695. else
  19696. {
  19697. hideRowsList.Add(Row + startIndex + HideRows);
  19698. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19699. }
  19700. HideRows += 2;
  19701. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("火车票"));
  19702. if (leftBindData != null)
  19703. {
  19704. designer.SetDataSource("HCPCB", leftBindData.cb);
  19705. designer.SetDataSource("HCPRS", leftBindData.rs);
  19706. designer.SetDataSource("HCPXS", leftBindData.xs);
  19707. designer.SetDataSource("HCPZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19708. designer.SetDataSource("HCPDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19709. designer.SetDataSource("HCPZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19710. designer.SetDataSource("HCPDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19711. designer.SetDataSource("HCPZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19712. }
  19713. else
  19714. {
  19715. hideRowsList.Add(Row + startIndex + HideRows);
  19716. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19717. }
  19718. HideRows += 2;
  19719. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("船票"));
  19720. if (leftBindData != null)
  19721. {
  19722. designer.SetDataSource("CPCB", leftBindData.cb);
  19723. designer.SetDataSource("CPRS", leftBindData.rs);
  19724. designer.SetDataSource("CPXS", leftBindData.xs);
  19725. designer.SetDataSource("CPZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19726. designer.SetDataSource("CPDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19727. designer.SetDataSource("CPZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19728. designer.SetDataSource("CPDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19729. designer.SetDataSource("CPZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19730. }
  19731. else
  19732. {
  19733. hideRowsList.Add(Row + startIndex + HideRows);
  19734. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19735. }
  19736. HideRows += 2;
  19737. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("公务单人"));
  19738. if (leftBindData != null)
  19739. {
  19740. designer.SetDataSource("GWDRCD", leftBindData.cb);
  19741. designer.SetDataSource("GWRS", leftBindData.rs);
  19742. designer.SetDataSource("GWXS", leftBindData.xs);
  19743. designer.SetDataSource("GWCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19744. designer.SetDataSource("GWDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19745. designer.SetDataSource("GWZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19746. designer.SetDataSource("GWDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19747. designer.SetDataSource("GWZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19748. }
  19749. else
  19750. {
  19751. hideRowsList.Add(Row + startIndex + HideRows);
  19752. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19753. }
  19754. HideRows += 2;
  19755. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("零用金"));
  19756. if (leftBindData != null)
  19757. {
  19758. designer.SetDataSource("LYJDRCB", leftBindData.cb);
  19759. designer.SetDataSource("LYJRS", leftBindData.rs);
  19760. designer.SetDataSource("LYJXS", leftBindData.xs);
  19761. designer.SetDataSource("LYJCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19762. designer.SetDataSource("LYJDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19763. designer.SetDataSource("LYJZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19764. designer.SetDataSource("LYJDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19765. designer.SetDataSource("LYJZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19766. }
  19767. else
  19768. {
  19769. hideRowsList.Add(Row + startIndex + HideRows);
  19770. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19771. }
  19772. #endregion
  19773. #region A段Right信息
  19774. var right = dto.rightInfo.Find(x => x.Type == "A");
  19775. if (right == null)
  19776. {
  19777. return Ok(jw);
  19778. }
  19779. HideRows += 4;
  19780. var rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 TBR"));
  19781. if (rightBindData != null)
  19782. {
  19783. //经济舱 + 双人间 TBR
  19784. designer.SetDataSource("lblJJCTBRDRCB", rightBindData.cb);
  19785. designer.SetDataSource("txtJJCTBRRS", rightBindData.rs);
  19786. designer.SetDataSource("lblJJCTBRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  19787. designer.SetDataSource("lblJJCTBRDRBJ", rightBindData.bj);
  19788. designer.SetDataSource("lblJJCTBRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  19789. designer.SetDataSource("lblJJCTBRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  19790. designer.SetDataSource("lblJJCTBRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  19791. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  19792. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  19793. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  19794. }
  19795. else
  19796. {
  19797. hideRowsList.Add(Row + startIndex + HideRows);
  19798. }
  19799. HideRows += 2;
  19800. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 SGR"));
  19801. if (rightBindData != null)
  19802. {
  19803. //经济舱 + 单人间 SGR
  19804. designer.SetDataSource("lblJJCSGRDRCB", rightBindData.cb);
  19805. designer.SetDataSource("txtJJCSGRRS", rightBindData.rs);
  19806. designer.SetDataSource("lblJJCSGRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  19807. designer.SetDataSource("lblJJCSGRDRBJ", rightBindData.bj);
  19808. designer.SetDataSource("lblJJCSGRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  19809. designer.SetDataSource("lblJJCSGRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  19810. designer.SetDataSource("lblJJCSGRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  19811. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  19812. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  19813. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  19814. }
  19815. else
  19816. {
  19817. hideRowsList.Add(Row + startIndex + HideRows);
  19818. }
  19819. HideRows += 2;
  19820. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 SGR"));
  19821. if (rightBindData != null)
  19822. {
  19823. //公务舱 + 单人间 SGR
  19824. designer.SetDataSource("lblGWCSGRCB", rightBindData.cb);
  19825. designer.SetDataSource("lblGWCSGRRS", rightBindData.rs);
  19826. designer.SetDataSource("lblGWCSGRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  19827. designer.SetDataSource("lblGWCSGRDRBJ", rightBindData.bj);
  19828. designer.SetDataSource("lblGWCSGRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  19829. designer.SetDataSource("lblGWCSGRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  19830. designer.SetDataSource("lblGWCSGRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  19831. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  19832. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  19833. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  19834. }
  19835. else
  19836. {
  19837. hideRowsList.Add(Row + startIndex + HideRows);
  19838. }
  19839. HideRows += 2;
  19840. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 JS/ES"));
  19841. if (rightBindData != null)
  19842. {
  19843. //公务舱 + 小套房 JSES
  19844. designer.SetDataSource("lblGWCJSESDRCB", rightBindData.cb);
  19845. designer.SetDataSource("txtGWCJSESRS", rightBindData.rs);
  19846. designer.SetDataSource("lblGWCJSESZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  19847. designer.SetDataSource("lblGWCJSESDRBJ", rightBindData.bj);
  19848. designer.SetDataSource("lblGWCJSESZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  19849. designer.SetDataSource("lblGWCJSESDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  19850. designer.SetDataSource("lblGWCJSESZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  19851. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  19852. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  19853. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  19854. }
  19855. else
  19856. {
  19857. hideRowsList.Add(Row + startIndex + HideRows);
  19858. }
  19859. HideRows += 2;
  19860. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 SUITE"));
  19861. if (rightBindData != null)
  19862. {
  19863. //公务舱 + 小套房 JSES
  19864. designer.SetDataSource("lblGWCSUITEDRCB", rightBindData.cb);
  19865. designer.SetDataSource("txtGWCSUITERS", rightBindData.rs);
  19866. designer.SetDataSource("lblGWCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  19867. designer.SetDataSource("lblGWCSUITEDRBJ", rightBindData.bj);
  19868. designer.SetDataSource("lblGWCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  19869. designer.SetDataSource("lblGWCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  19870. designer.SetDataSource("lblGWCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  19871. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  19872. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  19873. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  19874. }
  19875. else
  19876. {
  19877. hideRowsList.Add(Row + startIndex + HideRows);
  19878. }
  19879. HideRows += 2;
  19880. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 SUITE"));
  19881. if (rightBindData != null)
  19882. {
  19883. //经济舱 + 大套房
  19884. designer.SetDataSource("lblJJCSUITEDRCB", rightBindData.cb);
  19885. designer.SetDataSource("txtJJCSUITERS", rightBindData.rs);
  19886. designer.SetDataSource("lblJJCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  19887. designer.SetDataSource("lblJJCSUITEDRBJ", rightBindData.bj);
  19888. designer.SetDataSource("lblJJCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  19889. designer.SetDataSource("lblJJCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  19890. designer.SetDataSource("lblJJCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  19891. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  19892. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  19893. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  19894. }
  19895. else
  19896. {
  19897. hideRowsList.Add(Row + startIndex + HideRows);
  19898. }
  19899. HideRows += 2;
  19900. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("头等舱 JS/ES"));
  19901. if (rightBindData != null)
  19902. {
  19903. //头等舱 + 小套房 JSES
  19904. designer.SetDataSource("lblTDCJSESDRCB", rightBindData.cb);
  19905. designer.SetDataSource("txtTDCJSESRS", rightBindData.rs);
  19906. designer.SetDataSource("lblTDCJSESZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  19907. designer.SetDataSource("lblTDCJSESDRBJ", rightBindData.bj);
  19908. designer.SetDataSource("lblTDCJSESZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  19909. designer.SetDataSource("lblTDCJSESDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  19910. designer.SetDataSource("lblTDCJSESZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  19911. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  19912. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  19913. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  19914. }
  19915. else
  19916. {
  19917. hideRowsList.Add(Row + startIndex + HideRows);
  19918. }
  19919. HideRows += 2;
  19920. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("头等舱 SUITE"));
  19921. if (rightBindData != null)
  19922. {
  19923. //头等舱 + 大套房
  19924. designer.SetDataSource("lblTDCSUITEDRCB", rightBindData.cb);
  19925. designer.SetDataSource("txtTDCSUITERS", rightBindData.rs);
  19926. designer.SetDataSource("lblTDCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  19927. designer.SetDataSource("lblTDCSUITEDRBJ", rightBindData.bj);
  19928. designer.SetDataSource("lblTDCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  19929. designer.SetDataSource("lblTDCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  19930. designer.SetDataSource("lblTDCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  19931. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  19932. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  19933. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  19934. }
  19935. else
  19936. {
  19937. hideRowsList.Add(Row + startIndex + HideRows);
  19938. }
  19939. #endregion
  19940. #region B段标题清空
  19941. designer.SetDataSource("CostBDRCB", "");
  19942. designer.SetDataSource("CostBRS", "");
  19943. designer.SetDataSource("CostBXS", "");
  19944. designer.SetDataSource("CostBZCB", "");
  19945. designer.SetDataSource("CostBDRBJ", "");
  19946. designer.SetDataSource("CostBZBJ", "");
  19947. designer.SetDataSource("CostBDRLR", "");
  19948. designer.SetDataSource("CostBZLR", "");
  19949. designer.SetDataSource("CostBDRCBOM", "");
  19950. designer.SetDataSource("CostBRSOM", "");
  19951. designer.SetDataSource("CostBZCBOM", "");
  19952. designer.SetDataSource("CostBDRBJOM", "");
  19953. designer.SetDataSource("CostBZBJOM", "");
  19954. designer.SetDataSource("CostBDRLROM", "");
  19955. designer.SetDataSource("CostBZLROM", "");
  19956. #endregion
  19957. designer.SetDataSource("HotelTBRName", "酒店TBR单间成本(CNY)");
  19958. designer.SetDataSource("HotelSGRName", "酒店SGR单间成本(CNY)");
  19959. designer.SetDataSource("HotelJSESName", "酒店JSES单间成本(CNY)");
  19960. designer.SetDataSource("HotelSUITEName", "酒店SUITE单间成本(CNY)");
  19961. designer.SetDataSource("DJName", "地接(CNY)");
  19962. designer.SetDataSource("HCPName", "地接-火车票(CNY)");
  19963. designer.SetDataSource("CPName", "地接-船票(CNY)");
  19964. designer.SetDataSource("GWName", "公务(CNY)");
  19965. designer.SetDataSource("YQHName", "邀请函(CNY)");
  19966. designer.SetDataSource("LYJName", "零用金(CNY)");
  19967. designer.SetDataSource("HSName", "核酸检测(CNY)");
  19968. designer.SetDataSource("AirGWCName", "机票-公务舱(CNY)");
  19969. designer.SetDataSource("AirJJCName", "机票-经济舱(CNY)");
  19970. designer.SetDataSource("AirTDCName", "机票-头等舱(CNY)");
  19971. designer.SetDataSource("BXName", "保险(CNY)");
  19972. designer.SetDataSource("VisaName", "签证(CNY)");
  19973. #region B段基本数据
  19974. if (dto.costType == "B")
  19975. {
  19976. left = dto.leftInfo.Find(x => x.Type == "B");
  19977. if (left == null)
  19978. {
  19979. return Ok(jw);
  19980. }
  19981. #region B段left数据
  19982. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("核酸"));
  19983. if (leftBindData != null)
  19984. {
  19985. designer.SetDataSource("BHSDRCB", leftBindData.cb);
  19986. designer.SetDataSource("BHSRS", leftBindData.rs);
  19987. designer.SetDataSource("BHSXS", leftBindData.xs);
  19988. designer.SetDataSource("BHSZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19989. designer.SetDataSource("BHSDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19990. designer.SetDataSource("BHSZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19991. designer.SetDataSource("BHSDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19992. designer.SetDataSource("BHSZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19993. }
  19994. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("经济舱"));
  19995. if (leftBindData != null)
  19996. {
  19997. designer.SetDataSource("BJPJJCCB", leftBindData.cb);
  19998. designer.SetDataSource("BJPJJCPnum", leftBindData.rs);
  19999. designer.SetDataSource("BJPJJCXS", leftBindData.xs);
  20000. designer.SetDataSource("BJPJJCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20001. designer.SetDataSource("BJPJJCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20002. designer.SetDataSource("BJPJJCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20003. designer.SetDataSource("BJPJJCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20004. designer.SetDataSource("BJPJJCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20005. }
  20006. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("公务舱"));
  20007. if (leftBindData != null)
  20008. {
  20009. designer.SetDataSource("BJPGWCCB", leftBindData.cb);
  20010. designer.SetDataSource("BJPGWCPNum", leftBindData.rs);
  20011. designer.SetDataSource("BJPGWCXS", leftBindData.xs);
  20012. designer.SetDataSource("BJPGWCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20013. designer.SetDataSource("BJPGWCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20014. designer.SetDataSource("BJPGWCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20015. designer.SetDataSource("BJPGWCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20016. designer.SetDataSource("BJPGWCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20017. }
  20018. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("头等舱"));
  20019. if (leftBindData != null)
  20020. {
  20021. designer.SetDataSource("BJPTDCCB", leftBindData.cb);
  20022. designer.SetDataSource("BJPTDCPNum", leftBindData.rs);
  20023. designer.SetDataSource("BJPTDCXS", leftBindData.xs);
  20024. designer.SetDataSource("BJPTDCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20025. designer.SetDataSource("BJPTDCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20026. designer.SetDataSource("BJPTDCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20027. designer.SetDataSource("BJPTDCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20028. designer.SetDataSource("BJPTDCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20029. }
  20030. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("火车票"));
  20031. if (leftBindData != null)
  20032. {
  20033. designer.SetDataSource("BHCPCB", leftBindData.cb);
  20034. designer.SetDataSource("BHCPRS", leftBindData.rs);
  20035. designer.SetDataSource("BHCPXS", leftBindData.xs);
  20036. designer.SetDataSource("BHCPZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20037. designer.SetDataSource("BHCPDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20038. designer.SetDataSource("BHCPZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20039. designer.SetDataSource("BHCPDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20040. designer.SetDataSource("BHCPZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20041. }
  20042. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("船票"));
  20043. if (leftBindData != null)
  20044. {
  20045. designer.SetDataSource("BCPCB", leftBindData.cb);
  20046. designer.SetDataSource("BCPRS", leftBindData.rs);
  20047. designer.SetDataSource("BCPXS", leftBindData.xs);
  20048. designer.SetDataSource("BCPZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20049. designer.SetDataSource("BCPDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20050. designer.SetDataSource("BCPZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20051. designer.SetDataSource("BCPDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20052. designer.SetDataSource("BCPZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20053. }
  20054. //TBR
  20055. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("TBR"));
  20056. if (leftBindData != null)
  20057. {
  20058. designer.SetDataSource("BHotelTBRDRCB", leftBindData.cb);
  20059. designer.SetDataSource("BHotelTBRRS", leftBindData.rs);
  20060. designer.SetDataSource("BHotelTBRXS", leftBindData.xs);
  20061. designer.SetDataSource("BHotelTBRCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20062. designer.SetDataSource("BHotelTBRDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20063. designer.SetDataSource("BHotelTBRZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20064. designer.SetDataSource("BHotelTBRDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20065. designer.SetDataSource("BHotelTBRZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20066. }
  20067. //SGR
  20068. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("SGR"));
  20069. if (leftBindData != null)
  20070. {
  20071. designer.SetDataSource("BHotelSGRDRCB", leftBindData.cb);
  20072. designer.SetDataSource("BHotelSGRRS", leftBindData.rs);
  20073. designer.SetDataSource("BHotelSGRXS", leftBindData.xs);
  20074. designer.SetDataSource("BHotelSGRCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20075. designer.SetDataSource("BHotelSGRDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20076. designer.SetDataSource("BHotelSGRZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20077. designer.SetDataSource("BHotelSGRDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20078. designer.SetDataSource("BHotelSGRZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20079. }
  20080. //JS/ES
  20081. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("JSES"));
  20082. if (leftBindData != null)
  20083. {
  20084. designer.SetDataSource("BHotelJSESDRCB", leftBindData.cb);
  20085. designer.SetDataSource("BHotelJSESRS", leftBindData.rs);
  20086. designer.SetDataSource("BHotelJSESXS", leftBindData.xs);
  20087. designer.SetDataSource("BHotelJSESCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20088. designer.SetDataSource("BHotelJSESDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20089. designer.SetDataSource("BHotelJSESZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20090. designer.SetDataSource("BHotelJSESDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20091. designer.SetDataSource("BHotelJSESZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20092. }
  20093. //SUITE
  20094. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("SUITE"));
  20095. if (leftBindData != null)
  20096. {
  20097. designer.SetDataSource("BHotelSUITEDRCB", leftBindData.cb);
  20098. designer.SetDataSource("BHotelSUITERS", leftBindData.rs);
  20099. designer.SetDataSource("BHotelSUITEXS", leftBindData.xs);
  20100. designer.SetDataSource("BHotelSUITECB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20101. designer.SetDataSource("BHotelSUITEDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20102. designer.SetDataSource("BHotelSUITEZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20103. designer.SetDataSource("BHotelSUITEDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20104. designer.SetDataSource("BHotelSUITEZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20105. }
  20106. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("地接"));
  20107. if (leftBindData != null)
  20108. {
  20109. designer.SetDataSource("BDJDRCB", leftBindData.cb);
  20110. designer.SetDataSource("BDJRS", leftBindData.rs);
  20111. designer.SetDataSource("BDJXS", leftBindData.xs);
  20112. designer.SetDataSource("BDJCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20113. designer.SetDataSource("BDJDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20114. designer.SetDataSource("BDJZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20115. designer.SetDataSource("BDJDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20116. designer.SetDataSource("BDJZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20117. }
  20118. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("公务单人"));
  20119. if (leftBindData != null)
  20120. {
  20121. designer.SetDataSource("BGWDRCD", leftBindData.cb);
  20122. designer.SetDataSource("BGWRS", leftBindData.rs);
  20123. designer.SetDataSource("BGWXS", leftBindData.xs);
  20124. designer.SetDataSource("BGWCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20125. designer.SetDataSource("BGWDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20126. designer.SetDataSource("BGWZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20127. designer.SetDataSource("BGWDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20128. designer.SetDataSource("BGWZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20129. }
  20130. #region 优化方案
  20131. //Dictionary<string, object> excelBind = new Dictionary<string, object>();
  20132. //excelBind.Add("零用金", new {
  20133. //cb="",
  20134. //rs="",
  20135. //xs ="",
  20136. //zcb = "",
  20137. //});
  20138. #endregion
  20139. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("零用金"));
  20140. if (leftBindData != null)
  20141. {
  20142. designer.SetDataSource("BLYJDRCB", leftBindData.cb);
  20143. designer.SetDataSource("BLYJRS", leftBindData.rs);
  20144. designer.SetDataSource("BLYJXS", leftBindData.xs);
  20145. designer.SetDataSource("BLYJCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20146. designer.SetDataSource("BLYJDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20147. designer.SetDataSource("BLYJZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20148. designer.SetDataSource("BLYJDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20149. designer.SetDataSource("BLYJZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20150. }
  20151. #endregion
  20152. #region B段Right信息
  20153. right = dto.rightInfo.Find(x => x.Type == "B");
  20154. if (right == null)
  20155. {
  20156. return Ok(jw);
  20157. }
  20158. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 TBR"));
  20159. if (rightBindData != null)
  20160. {
  20161. //经济舱 + 双人间 TBR
  20162. designer.SetDataSource("BlblJJCTBRDRCB", rightBindData.cb);
  20163. designer.SetDataSource("BtxtJJCTBRRS", rightBindData.rs);
  20164. designer.SetDataSource("BlblJJCTBRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20165. designer.SetDataSource("BlblJJCTBRDRBJ", rightBindData.bj);
  20166. designer.SetDataSource("BlblJJCTBRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20167. designer.SetDataSource("BlblJJCTBRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20168. designer.SetDataSource("BlblJJCTBRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20169. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20170. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20171. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20172. }
  20173. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 SGR"));
  20174. if (rightBindData != null)
  20175. {
  20176. //经济舱 + 单人间 SGR
  20177. designer.SetDataSource("BlblJJCSGRDRCB", rightBindData.cb);
  20178. designer.SetDataSource("BtxtJJCSGRRS", rightBindData.rs);
  20179. designer.SetDataSource("BlblJJCSGRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20180. designer.SetDataSource("BlblJJCSGRDRBJ", rightBindData.bj);
  20181. designer.SetDataSource("BlblJJCSGRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20182. designer.SetDataSource("BlblJJCSGRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20183. designer.SetDataSource("BlblJJCSGRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20184. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20185. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20186. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20187. }
  20188. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 SGR"));
  20189. if (rightBindData != null)
  20190. {
  20191. //公务舱 + 单人间 SGR
  20192. designer.SetDataSource("BlblGWCSGRCB", rightBindData.cb);
  20193. designer.SetDataSource("BlblGWCSGRRS", rightBindData.rs);
  20194. designer.SetDataSource("BlblGWCSGRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20195. designer.SetDataSource("BlblGWCSGRDRBJ", rightBindData.bj);
  20196. designer.SetDataSource("BlblGWCSGRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20197. designer.SetDataSource("BlblGWCSGRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20198. designer.SetDataSource("BlblGWCSGRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20199. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20200. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20201. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20202. }
  20203. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 JS/ES"));
  20204. if (rightBindData != null)
  20205. {
  20206. //公务舱 + 小套房 JSES
  20207. designer.SetDataSource("BlblGWCJSESDRCB", rightBindData.cb);
  20208. designer.SetDataSource("BtxtGWCJSESRS", rightBindData.rs);
  20209. designer.SetDataSource("BlblGWCJSESZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20210. designer.SetDataSource("BlblGWCJSESDRBJ", rightBindData.bj);
  20211. designer.SetDataSource("BlblGWCJSESZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20212. designer.SetDataSource("BlblGWCJSESDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20213. designer.SetDataSource("BlblGWCJSESZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20214. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20215. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20216. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20217. }
  20218. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 SUITE"));
  20219. if (rightBindData != null)
  20220. {
  20221. //公务舱 + 小套房 JSES
  20222. designer.SetDataSource("BlblGWCSUITEDRCB", rightBindData.cb);
  20223. designer.SetDataSource("BtxtGWCSUITERS", rightBindData.rs);
  20224. designer.SetDataSource("BlblGWCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20225. designer.SetDataSource("BlblGWCSUITEDRBJ", rightBindData.bj);
  20226. designer.SetDataSource("BlblGWCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20227. designer.SetDataSource("BlblGWCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20228. designer.SetDataSource("BlblGWCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20229. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20230. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20231. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20232. }
  20233. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 SUITE"));
  20234. if (rightBindData != null)
  20235. {
  20236. //经济舱 + 大套房
  20237. designer.SetDataSource("BlblJJCSUITEDRCB", rightBindData.cb);
  20238. designer.SetDataSource("BtxtJJCSUITERS", rightBindData.rs);
  20239. designer.SetDataSource("BlblJJCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20240. designer.SetDataSource("BlblJJCSUITEDRBJ", rightBindData.bj);
  20241. designer.SetDataSource("BlblJJCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20242. designer.SetDataSource("BlblJJCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20243. designer.SetDataSource("BlblJJCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20244. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20245. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20246. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20247. }
  20248. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("头等舱 JS/ES"));
  20249. if (rightBindData != null)
  20250. {
  20251. //头等舱 + 小套房 JSES
  20252. designer.SetDataSource("BlblTDCJSESDRCB", rightBindData.cb);
  20253. designer.SetDataSource("BtxtTDCJSESRS", rightBindData.rs);
  20254. designer.SetDataSource("BlblTDCJSESZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20255. designer.SetDataSource("BlblTDCJSESDRBJ", rightBindData.bj);
  20256. designer.SetDataSource("BlblTDCJSESZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20257. designer.SetDataSource("BlblTDCJSESDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20258. designer.SetDataSource("BlblTDCJSESZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20259. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20260. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20261. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20262. }
  20263. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("头等舱 SUITE"));
  20264. if (rightBindData != null)
  20265. {
  20266. //头等舱 + 大套房
  20267. designer.SetDataSource("BlblTDCSUITEDRCB", rightBindData.cb);
  20268. designer.SetDataSource("BtxtTDCSUITERS", rightBindData.rs);
  20269. designer.SetDataSource("BlblTDCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20270. designer.SetDataSource("BlblTDCSUITEDRBJ", rightBindData.bj);
  20271. designer.SetDataSource("BlblTDCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20272. designer.SetDataSource("BlblTDCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20273. designer.SetDataSource("BlblTDCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20274. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20275. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20276. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20277. }
  20278. #endregion
  20279. #region 标题
  20280. designer.SetDataSource("CostBDRCB", "单人成本");
  20281. designer.SetDataSource("CostBRS", "人数");
  20282. designer.SetDataSource("CostBXS", "系数");
  20283. designer.SetDataSource("CostBZCB", "总成本");
  20284. designer.SetDataSource("CostBDRBJ", "单人报价");
  20285. designer.SetDataSource("CostBZBJ", "总报价");
  20286. designer.SetDataSource("CostBDRLR", "单人利润");
  20287. designer.SetDataSource("CostBZLR", "总利润");
  20288. designer.SetDataSource("CostBDRCBOM", "单人成本");
  20289. designer.SetDataSource("CostBRSOM", "人数");
  20290. designer.SetDataSource("CostBZCBOM", "总成本");
  20291. designer.SetDataSource("CostBDRBJOM", "单人报价");
  20292. designer.SetDataSource("CostBZBJOM", "总报价");
  20293. designer.SetDataSource("CostBDRLROM", "单人利润");
  20294. designer.SetDataSource("CostBZLROM", "总利润");
  20295. #endregion
  20296. }
  20297. #endregion
  20298. designer.SetDataSource("TzZCB2", TzZCB2);
  20299. designer.SetDataSource("TzZBJ2", TzZBJ2);
  20300. designer.SetDataSource("TzZLR2", TzZLR2);
  20301. string[] dataSourceKeys = new string[]
  20302. {
  20303. "VF",
  20304. "TGS",
  20305. "TGOF",
  20306. "TGM",
  20307. "TGA",
  20308. "TGTF",
  20309. "TGEF",
  20310. "CFM",
  20311. "CFOF",
  20312. "B",
  20313. "L",
  20314. "D",
  20315. "TBR",
  20316. "SGR",
  20317. "JSES",
  20318. "Suite",
  20319. "TV",
  20320. "1L",
  20321. "IF",
  20322. "EF",
  20323. "BRF",
  20324. "TE",
  20325. "TGT",
  20326. "DRVT",
  20327. "PC",
  20328. "TLF",
  20329. "ECT"
  20330. };
  20331. foreach (var item in dataSourceKeys)
  20332. {
  20333. Func<TitleModel, bool> expr = x => x.label.Replace(" ", "").Replace("/", "") == item
  20334. || x.label.Replace(" ", "").Replace("/", "").ToUpper() == item.ToUpper();
  20335. var find = dto.titleModel.FirstOrDefault(expr);
  20336. if (find != null)
  20337. {
  20338. designer.SetDataSource(item, find.text);
  20339. }
  20340. else
  20341. {
  20342. designer.SetDataSource(item, 0);
  20343. }
  20344. }
  20345. designer.SetDataSource(dt);
  20346. //根据数据源处理生成报表内容
  20347. designer.Process();
  20348. designer.Workbook.Worksheets[0].Name = "费用明细";
  20349. designer.Workbook.Worksheets[1].Name = "费用总核算";
  20350. Worksheet sheet = designer.Workbook.Worksheets[0];
  20351. #region 隐藏舱位
  20352. var settingAir = new[]
  20353. {
  20354. new { key = "经济舱", index = 7 },
  20355. new { key = "公务舱", index = 19 },
  20356. new { key = "头等舱", index = 11 }
  20357. };
  20358. var airType = _sqlSugar.Queryable<Grp_TourClientList>()
  20359. .LeftJoin<Sys_SetData>((c, s) => s.IsDel == 0 && c.ShippingSpaceTypeId == s.Id)
  20360. .Where((c, s) => c.IsDel == 0 && c.DiId == di.Id)
  20361. .Select((c, s) => s.Name)
  20362. .ToList()
  20363. .GroupBy(x => x)
  20364. .Select(x => x.Key);
  20365. foreach (var item in settingAir)
  20366. {
  20367. if (!airType.Contains(item.key))
  20368. {
  20369. hideRowsList.Add(item.index);
  20370. }
  20371. }
  20372. #endregion
  20373. foreach (var Rowindex in hideRowsList)
  20374. {
  20375. ws.Cells.HideRows(Rowindex, 2);
  20376. }
  20377. ws = designer.Workbook.Worksheets[0];
  20378. foreach (var Column in hideColumnList)
  20379. {
  20380. ws.Cells.HideColumns(Column, 1);
  20381. }
  20382. byte[] bytes = null;
  20383. string strFileName = di.TeamName + "-团组-成本.xls";
  20384. using (MemoryStream stream = new MemoryStream())
  20385. {
  20386. designer.Workbook.Save(stream, Aspose.Cells.SaveFormat.Xlsx);
  20387. bytes = stream.ToArray();
  20388. }
  20389. return Ok(JsonView(true, "", new
  20390. {
  20391. Data = bytes,
  20392. strFileName,
  20393. }));
  20394. }
  20395. /// <summary>
  20396. /// 导出客户报表
  20397. /// </summary>
  20398. /// <returns></returns>
  20399. [HttpPost]
  20400. public async Task<IActionResult> ExportClientWordFile(ExportClientWordFileDto dto)
  20401. {
  20402. var jw = JsonView(false);
  20403. if (dto.Diid == 0)
  20404. {
  20405. return Ok(JsonView(false, "请传递团组id"));
  20406. }
  20407. var deleInfo = await _groupRepository.PostGroupInfo(new GroupInfoDto { Id = dto.Diid, PortType = 1 });
  20408. if (deleInfo.Code != 0)
  20409. {
  20410. return Ok(JsonView(false, "团组信息查询失败!"));
  20411. }
  20412. var di = deleInfo.Data as DelegationInfoWebView;
  20413. if (di == null)
  20414. {
  20415. return Ok(JsonView(false, "团组信息查询失败!"));
  20416. }
  20417. //文件名
  20418. //string strFileName = di.TeamName + "-团组-客户报价.doc";
  20419. //获取模板
  20420. string tmppath = (AppSettingsHelper.Get("WordBasePath") + "Template/团组-客户报价.doc");
  20421. //载入模板
  20422. Document doc = new Document(tmppath);
  20423. Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
  20424. Dictionary<string, string> DickeyValue = new Dictionary<string, string>();
  20425. DickeyValue.Add("DickeyValue", di.TeamName); //团组名
  20426. var ParameterList = _GroupCostParameterRepository.GetGroupCostParameterListByDiid(dto.Diid);
  20427. var AParameter = ParameterList.Find(x => x.CostType == "A");
  20428. var BParameter = ParameterList.Find(x => x.CostType == "B");
  20429. if (AParameter == null)
  20430. {
  20431. return Ok(JsonView(false, "系数不存在!"));
  20432. }
  20433. string CarGuides, TzNumber, CarGuides1, Meal, SubsidizedMeals, NightRepair, AttractionsTickets, MiscellaneousFees, ATip, TzHotelDesc, Offcial, PettyCash, Visa, TrainTicket, TicketPrice
  20434. , TzAirDesc, TzZCost;
  20435. CarGuides = TzNumber = CarGuides1 = Meal = SubsidizedMeals = NightRepair = AttractionsTickets = MiscellaneousFees = ATip = TzHotelDesc = Offcial = PettyCash = Visa = TrainTicket = TicketPrice
  20436. = TzAirDesc = TzZCost = string.Empty;
  20437. TzNumber = AParameter.CostTypenumber.ToString();
  20438. CarGuides = "RMB " + (AParameter.DJCB * AParameter.DJXS).ToString("#0.00");
  20439. CarGuides1 = dto.CarGuides1;
  20440. Meal = dto.Meal;
  20441. SubsidizedMeals = dto.SubsidizedMeals;
  20442. NightRepair = dto.NightRepair;
  20443. AttractionsTickets = dto.AttractionsTickets;
  20444. MiscellaneousFees = dto.MiscellaneousFees;
  20445. ATip = dto.ATip;
  20446. TzHotelDesc = "";
  20447. Offcial = "RMB " + (AParameter.GWCB * AParameter.GWXS).ToString("#0.00");
  20448. PettyCash = "RMB " + (AParameter.LYJCB * AParameter.LYJXS).ToString("#0.00");
  20449. Visa = "RMB " + (AParameter.VisaCB * AParameter.VisaXS + AParameter.HSCB * AParameter.HSXS + AParameter.BXCB * AParameter.BXXS).ToString("#0.00");
  20450. TrainTicket = "RMB " + (AParameter.HCPCB * AParameter.HCPXS).ToString("#0.00");
  20451. TicketPrice = "RMB " + (AParameter.CPCB * AParameter.CPXS).ToString("#0.00");
  20452. TzAirDesc = "";
  20453. TzZCost = dto.TzZCost;
  20454. var TzHotelDescArr = new string[] { "SGR", "JSES", "SUITE", "TBR" };
  20455. var TzAirDescArr = new string[] { "经济舱", "公务舱" };
  20456. var index = 1;
  20457. var AinfoArr = dto.leftInfo.Find(x => x.Type == "A");
  20458. foreach (var item in TzHotelDescArr)
  20459. {
  20460. if (AinfoArr != null)
  20461. {
  20462. var Ainfo = AinfoArr.leftinfoNumber.Find(x => x.title.Contains(item));
  20463. if (Ainfo != null)
  20464. {
  20465. if (int.Parse(Ainfo.rs) <= 0)
  20466. {
  20467. continue;
  20468. }
  20469. var hotelText = string.Empty;
  20470. switch (item)
  20471. {
  20472. case "SGR":
  20473. hotelText = "单人间";
  20474. break;
  20475. case "JSES":
  20476. hotelText = "小套房";
  20477. break;
  20478. case "SUITE":
  20479. hotelText = "套房";
  20480. break;
  20481. case "TBR":
  20482. hotelText = "双人间";
  20483. break;
  20484. }
  20485. if (item != "TBR")
  20486. {
  20487. 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";
  20488. }
  20489. else
  20490. {
  20491. 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";
  20492. }
  20493. index++;
  20494. }
  20495. }
  20496. }
  20497. index = 1;
  20498. foreach (var item in TzAirDescArr)
  20499. {
  20500. if (AinfoArr != null)
  20501. {
  20502. var Ainfo = AinfoArr.leftinfoNumber.Find(x => x.title.Contains(item));
  20503. if (Ainfo != null)
  20504. {
  20505. if (int.Parse(Ainfo.rs) <= 0)
  20506. {
  20507. continue;
  20508. }
  20509. 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";
  20510. index++;
  20511. }
  20512. }
  20513. }
  20514. if (dto.costType == "B")
  20515. {
  20516. if (BParameter == null)
  20517. {
  20518. return Ok(JsonView(false, "B段系数不存在!"));
  20519. }
  20520. CarGuides = CarGuides.Insert(0, "A段 ") + " B段 RMB" + (BParameter.DJCB * BParameter.DJXS).ToString("#0.00");
  20521. Offcial = Offcial.Insert(0, "A段 ") + " B段 RMB " + (BParameter.GWCB * BParameter.GWXS).ToString("#0.00");
  20522. PettyCash = PettyCash.Insert(0, "A段 ") + " B段 RMB " + (BParameter.LYJCB * BParameter.LYJXS).ToString("#0.00");
  20523. Visa = Visa.Insert(0, "A段 ") + " B段 RMB " + (BParameter.VisaCB * BParameter.VisaXS + BParameter.HSCB * BParameter.HSXS + BParameter.BXCB * BParameter.BXXS).ToString("#0.00");
  20524. TrainTicket = TrainTicket.Insert(0, "A段 ") + " B段 RMB " + (BParameter.HCPCB * BParameter.HCPXS).ToString("#0.00");
  20525. TicketPrice = TicketPrice.Insert(0, "A段 ") + " B段 RMB " + (BParameter.CPCB * BParameter.CPXS).ToString("#0.00");
  20526. AinfoArr = dto.leftInfo.Find(x => x.Type == "B");
  20527. foreach (var item in TzHotelDescArr)
  20528. {
  20529. if (AinfoArr != null)
  20530. {
  20531. TzHotelDesc += "B段信息 \r\n";
  20532. var Ainfo = AinfoArr.leftinfoNumber.Find(x => x.title.Contains(item));
  20533. if (Ainfo != null)
  20534. {
  20535. if (int.Parse(Ainfo.rs) <= 0)
  20536. {
  20537. continue;
  20538. }
  20539. var hotelText = string.Empty;
  20540. switch (item)
  20541. {
  20542. case "SGR":
  20543. hotelText = "单人间";
  20544. break;
  20545. case "JSES":
  20546. hotelText = "小套房";
  20547. break;
  20548. case "SUITE":
  20549. hotelText = "套房";
  20550. break;
  20551. case "TBR":
  20552. hotelText = "双人间";
  20553. break;
  20554. }
  20555. if (item != "TBR")
  20556. {
  20557. 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";
  20558. }
  20559. else
  20560. {
  20561. 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";
  20562. }
  20563. index++;
  20564. }
  20565. TzHotelDesc = TzHotelDesc.Insert(0, "A段信息 \r\n");
  20566. }
  20567. }
  20568. index = 1;
  20569. foreach (var item in TzAirDescArr)
  20570. {
  20571. if (AinfoArr != null)
  20572. {
  20573. var Ainfo = AinfoArr.leftinfoNumber.Find(x => x.title.Contains(item));
  20574. if (Ainfo != null)
  20575. {
  20576. if (int.Parse(Ainfo.rs) <= 0)
  20577. {
  20578. continue;
  20579. }
  20580. 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";
  20581. index++;
  20582. }
  20583. }
  20584. }
  20585. }
  20586. Visa = Visa.Insert(0, "签证及保险(含核酸检测): ");
  20587. DickeyValue.Add("TzNumber", TzNumber); //团组人数
  20588. DickeyValue.Add("CarGuides", CarGuides); //地接单人报价
  20589. DickeyValue.Add("CarGuides1", CarGuides1); // 地接 - 车导费
  20590. DickeyValue.Add("Meal", Meal); // 地接 - 餐费
  20591. DickeyValue.Add("SubsidizedMeals", SubsidizedMeals);// 地接 - 餐补
  20592. DickeyValue.Add("NightRepair", NightRepair); // 地接 - 宿补
  20593. DickeyValue.Add("AttractionsTickets", AttractionsTickets); // 地接 - 景点
  20594. DickeyValue.Add("MiscellaneousFees", MiscellaneousFees); // 地接 - 杂费
  20595. DickeyValue.Add("ATip", ATip); // 地接 - 小费
  20596. DickeyValue.Add("TzHotelDesc", TzHotelDesc); //酒店
  20597. DickeyValue.Add("Offcial", Offcial); // 公务单人报价
  20598. DickeyValue.Add("PettyCash", PettyCash); // 零用金单人报价
  20599. DickeyValue.Add("Visa", Visa); // 签证单人报价
  20600. DickeyValue.Add("TrainTicket", TrainTicket); //火车票
  20601. DickeyValue.Add("TicketPrice", TicketPrice); //船票
  20602. DickeyValue.Add("TzAirDesc", TzAirDesc); //机票
  20603. DickeyValue.Add("TzZCost", TzZCost);
  20604. foreach (var key in DickeyValue.Keys)
  20605. {
  20606. if (doc.Range.Bookmarks[key] != null)
  20607. {
  20608. Bookmark mark = doc.Range.Bookmarks[key];
  20609. mark.Text = DickeyValue[key];
  20610. }
  20611. }
  20612. byte[] bytes = null;
  20613. string strFileName = di.TeamName + "-客户报价.doc";
  20614. using (MemoryStream stream = new MemoryStream())
  20615. {
  20616. doc.Save(stream, Aspose.Words.SaveFormat.Doc);
  20617. bytes = stream.ToArray();
  20618. }
  20619. return Ok(JsonView(true, "", new
  20620. {
  20621. Data = bytes,
  20622. strFileName,
  20623. }));
  20624. }
  20625. /// <summary>
  20626. /// 团组成本 各模块(酒店,地接,机票)成本提示
  20627. /// </summary>
  20628. /// <param name="dto"></param>
  20629. /// <returns></returns>
  20630. [HttpPost]
  20631. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20632. public async Task<IActionResult> PostGroupCostModulePrompt(GroupCostModulePromptDto dto)
  20633. {
  20634. try
  20635. {
  20636. #region 参数验证
  20637. if (dto.DiId < 0)
  20638. {
  20639. return Ok(JsonView(false, "请传入有效的DiId参数!"));
  20640. }
  20641. List<int> cTableIds = new List<int>() {
  20642. 76 ,//酒店预订
  20643. 77 ,//行程
  20644. 79 ,//车/导游地接
  20645. 80 ,//签证
  20646. 81 ,//邀请/公务活
  20647. 82 ,//团组客户保险
  20648. 85 ,//机票预订
  20649. 98 ,//其他款项
  20650. 285 ,//收款退还
  20651. 751 ,//酒店早餐
  20652. 1015 // 超支费用
  20653. };
  20654. if (dto.CTable < 0 && !cTableIds.Contains(dto.CTable))
  20655. {
  20656. return Ok(JsonView(false, "请传入有效的CTable参数!"));
  20657. }
  20658. #endregion
  20659. //Grp_GroupCostParameter 预算表 Grp_GroupCost 详细费用列表
  20660. var _GroupCostParameters = _usersRep._sqlSugar.Queryable<Grp_GroupCostParameter>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).ToList();
  20661. if (_GroupCostParameters.Count <= 0)
  20662. {
  20663. return Ok(JsonView(false, "暂无该团组成本信息!", new List<dynamic>()));
  20664. }
  20665. if (_GroupCostParameters[0].IsShare == 0)
  20666. {
  20667. return Ok(JsonView(false, "该团组成本未完成!", new List<dynamic>()));
  20668. }
  20669. var _GroupCosts = _usersRep._sqlSugar.Queryable<Grp_GroupCost>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  20670. //处理date为空问题
  20671. if (_GroupCosts.Count > 0)
  20672. {
  20673. for (int i = 0; i < _GroupCosts.Count; i++)
  20674. {
  20675. if (string.IsNullOrEmpty(_GroupCosts[i].Date))
  20676. {
  20677. if (i > 0)
  20678. {
  20679. _GroupCosts[i].Date = _GroupCosts[i - 1].Date;
  20680. }
  20681. }
  20682. }
  20683. }
  20684. GroupCostModulePromptView _view = new GroupCostModulePromptView();
  20685. List<GroupCostModulePromptInfo> _ModulePromptInfos = new List<GroupCostModulePromptInfo>(); //机票存储多段
  20686. var currDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  20687. string currCode = "";
  20688. #region currCode 验证
  20689. bool isInt = int.TryParse(_GroupCostParameters[0].Currency, out int intCurrency);
  20690. if (isInt)
  20691. {
  20692. var currData = currDatas.Find(it => it.Id == intCurrency);
  20693. if (currData != null)
  20694. {
  20695. currCode = currData.Name;
  20696. }
  20697. }
  20698. else
  20699. {
  20700. currCode = _GroupCostParameters[0].Currency.Trim();
  20701. }
  20702. #endregion
  20703. //op,酒店单段模式存储
  20704. GroupCostModulePromptInfo _ModulePromptInfo = new GroupCostModulePromptInfo()
  20705. {
  20706. CurrencyCode = currCode,
  20707. Rate = _GroupCostParameters[0].Rate,
  20708. CostType = _GroupCostParameters[0].CostType,
  20709. CostTypeStartTime = Convert.ToDateTime(_GroupCostParameters[0].CostTypeStartTime).ToString("yyyy-MM-dd"),
  20710. CostTypeEndTime = Convert.ToDateTime(_GroupCostParameters[0].CostTypeendTime).ToString("yyyy-MM-dd"),
  20711. CostTypeNumber = _GroupCostParameters[0].CostTypenumber
  20712. };
  20713. List<dynamic> _ModuleSubPromptInfo = new List<dynamic>(); // 存储CTbale != 85 的动态数据
  20714. if (_GroupCostParameters.Count == 2)
  20715. {
  20716. _ModulePromptInfo.CostTypeEndTime = Convert.ToDateTime(_GroupCostParameters[1].CostTypeendTime).ToString("yyyy-MM-dd");
  20717. }
  20718. foreach (var item in _GroupCostParameters)
  20719. {
  20720. decimal _rate = 1;
  20721. decimal _rate1 = item.Rate;
  20722. decimal _scale = 1;
  20723. //decimal _scale = 0.95M; 雷怡 2024-06-11 10:06:08 屏蔽
  20724. #region 处理地接价格比例 总经理 国交部经理 主管 不下调 其他人 下调 5%
  20725. //var userInfo = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.Id == dto.UserId).First();
  20726. //if (userInfo != null)
  20727. //{
  20728. // if (userInfo.DepId == 1 || userInfo.DepId == 7)
  20729. // {
  20730. // if (userInfo.JobPostId == 1 || userInfo.JobPostId == 22 || userInfo.JobPostId == 32)
  20731. // {
  20732. // _scale = 1.00M;
  20733. // }
  20734. // }
  20735. //}
  20736. #endregion
  20737. GroupCostModulePromptInfo modulePromptInfo = new GroupCostModulePromptInfo()
  20738. {
  20739. CurrencyCode = currCode,
  20740. Rate = _rate1,
  20741. CostType = item.CostType,
  20742. CostTypeStartTime = Convert.ToDateTime(item.CostTypeStartTime).ToString("yyyy-MM-dd"),
  20743. CostTypeEndTime = Convert.ToDateTime(item.CostTypeendTime).ToString("yyyy-MM-dd"),
  20744. CostTypeNumber = item.CostTypenumber
  20745. };
  20746. if (_GroupCostParameters.Count > 1)
  20747. {
  20748. modulePromptInfo.CostTypeNumber = item.CostTypenumber;
  20749. }
  20750. else
  20751. {
  20752. modulePromptInfo.CostTypeNumber = item.LYJRS;
  20753. }
  20754. if (dto.CTable == 79)//
  20755. {
  20756. modulePromptInfo.IndividualCost = item.DJCB / modulePromptInfo.CostTypeNumber;
  20757. modulePromptInfo.TotalCost = item.DJCB;
  20758. }
  20759. List<string> costTypes = new List<string>() { "A", "B" };
  20760. List<Grp_GroupCost> _GroupCostsTypeData = new List<Grp_GroupCost>();
  20761. var _GroupCostsDuplicates = _GroupCostParameters.GroupBy(x => x.CostType).Select(y => y.FirstOrDefault());
  20762. if (_GroupCostsDuplicates.Count() == 1)
  20763. {
  20764. _GroupCostsTypeData = _GroupCosts;
  20765. }
  20766. else
  20767. {
  20768. _GroupCostsTypeData = _GroupCosts.Where(it => Convert.ToDateTime(it.Date) >= Convert.ToDateTime(item.CostTypeStartTime) &&
  20769. Convert.ToDateTime(it.Date) <= Convert.ToDateTime(item.CostTypeendTime)).ToList();
  20770. }
  20771. /*
  20772. * 76 酒店预订
  20773. * 77 行程
  20774. * 79 车/导游地接
  20775. * 80 签证
  20776. * 81 邀请/公务活动
  20777. * 82 团组客户保险
  20778. * 85 机票预订
  20779. * 98 其他款项
  20780. * 285 收款退还
  20781. * 751 酒店早餐
  20782. * 1015 超支费用
  20783. */
  20784. switch (dto.CTable)
  20785. {
  20786. case 76: // 酒店预订
  20787. _ModuleSubPromptInfo.AddRange(
  20788. _GroupCostsTypeData.Select(it => new
  20789. {
  20790. it.DAY,
  20791. it.Date,
  20792. it.ACCON,
  20793. it.ITIN,
  20794. it.SGR,
  20795. it.TBR,
  20796. it.JS_ES,
  20797. it.Suite
  20798. })
  20799. );
  20800. break;
  20801. case 79: // 车/导游地接
  20802. _ModuleSubPromptInfo.AddRange(
  20803. _GroupCostsTypeData.Select(it => new
  20804. {
  20805. Date = it.Date, //日期
  20806. CarFee = it.CarCost * _rate * _scale, //车费用
  20807. CarType = it.CarType, //车型
  20808. DriverFee = it.CFS * _rate * _scale, //司机工资
  20809. DriverTipsFee = it.DRVTips * _rate * _scale, //司机小费
  20810. DriverMealSubsidy = it.CFM * _rate * _scale, //司机餐补
  20811. DriverOvertimeFee = it.CFOF * _rate * _scale, //司机超时费用
  20812. GuideFee = it.TGS * _rate * _scale, //导游费用
  20813. GuideOvertimeFee = it.TGOF * _rate * _scale, //导游超时费用
  20814. GuideMealSubsidy = it.TGM * _rate * _scale, //导游餐补
  20815. GuideRoomSubsidy = it.TGA * _rate * _scale, //导游房补
  20816. GuideCarFare = it.TGTF * _rate * _scale, //导游交通费
  20817. GuideSpotFee = it.TGEF * _rate * _scale, //导游景点费
  20818. GuideTipsFee = it.TGTips * _rate * _scale, //导游小费
  20819. Breakfast = it.B * _rate * _scale, //早餐费
  20820. Lunch = it.L * _rate * _scale, //午餐费
  20821. Dinner = it.D * _rate * _scale, //晚餐费
  20822. OfficialActivitiesFee = it.TV * _rate * _scale,//会务活动费 --新加
  20823. OfficialTransFee = it.IF * _rate * _scale, //公务翻译费 --新加
  20824. InvitationFee = it.iL * _rate * _scale, //邀请函费用 --新加
  20825. TicketFee = it.EF * _rate * _scale, //门票费
  20826. TicketRemark = it.EFR, //门票费描述
  20827. DrinksSnacksFruitFee = it.B_R_F * _rate * _scale, //饮料零食水果
  20828. TravelSupplies = it.TE * _rate * _scale, //出行物资
  20829. SpentCash = it.PC * _rate * _scale, //零用金
  20830. LeadersFee = it.TLF * _rate * _scale, //领队费
  20831. ActivitiesFee = it.ECT * _rate * _scale, //会务费 --新加
  20832. })
  20833. );
  20834. break;
  20835. case 85: // 机票
  20836. List<dynamic> datas = new List<dynamic>();
  20837. datas.Add(
  20838. new
  20839. {
  20840. AirType = "经济舱",
  20841. AirNum = item.JJCRS,
  20842. AirDRCB = item.JJCCB,
  20843. AirZCB = (item.JJCRS * item.JJCCB)
  20844. }
  20845. );
  20846. datas.Add(
  20847. new
  20848. {
  20849. AirType = "公务舱",
  20850. AirNum = item.GWCRS,
  20851. AirDRCB = item.GWCCB,
  20852. AirZCB = (item.GWCRS * item.GWCCB)
  20853. }
  20854. );
  20855. var groupCosts = _usersRep._sqlSugar.Queryable<Grp_GroupCost>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  20856. var initDatas = groupCosts.Select(it => new { date = it.Date, week = it.Date.GetWeek() == "" ? "-" : it.Date.GetWeek(), itinerary = it.ITIN }).ToList();
  20857. modulePromptInfo.Data = new
  20858. {
  20859. airFeeData = datas,
  20860. airInitData = initDatas
  20861. };
  20862. _ModulePromptInfos.Add(modulePromptInfo);
  20863. break;
  20864. default:
  20865. break;
  20866. }
  20867. }
  20868. if (dto.CTable != 85)
  20869. {
  20870. _ModulePromptInfo.Data = _ModuleSubPromptInfo;
  20871. _ModulePromptInfos.Add(_ModulePromptInfo);
  20872. }
  20873. _view.ModulePromptInfos = _ModulePromptInfos;
  20874. return Ok(JsonView(true, "操作成功!", _view));
  20875. }
  20876. catch (Exception ex)
  20877. {
  20878. return Ok(JsonView(false, ex.Message));
  20879. }
  20880. }
  20881. /// <summary>
  20882. /// 根据黑屏代码重新生成行程
  20883. /// </summary>
  20884. /// <param name="dto"></param>
  20885. /// <returns></returns>
  20886. [HttpPost]
  20887. public IActionResult CraeteGroupCostTravel(GroupCostInItDto dto)
  20888. {
  20889. var jw = JsonView(false, "Error");
  20890. var Create = _sqlSugar.Queryable<Air_TicketBlackCode>()
  20891. .Where(x => x.IsDel == 0 && x.DiId == dto.Diid)
  20892. .Select(x => new
  20893. {
  20894. x.Id,
  20895. x.Title
  20896. })
  20897. .ToList();
  20898. if (Create.Any())
  20899. {
  20900. jw.Msg = "获取成功!";
  20901. jw.Code = 200;
  20902. jw.Data = new
  20903. {
  20904. BlackCodeListSelect = Create,
  20905. blackCodeIsTrue = true
  20906. };
  20907. }
  20908. else
  20909. {
  20910. jw.Code = 400;
  20911. jw.Data = new
  20912. {
  20913. BlackCodeListSelect = Create,
  20914. blackCodeIsTrue = false,
  20915. };
  20916. }
  20917. return Ok(jw);
  20918. }
  20919. /// <summary>
  20920. /// 根据黑屏代码Id重新生成行程
  20921. /// </summary>
  20922. /// <param name="dto"></param>
  20923. /// <returns></returns>
  20924. [HttpPost]
  20925. public IActionResult CraeteGroupCostTravelById(CraeteGroupCostTravelByIdDto dto)
  20926. {
  20927. var jw = JsonView(false, "Error");
  20928. var result = _GroupCostRepository.CreateGroupCostByBlackCode(dto.DiId, dto.BlackCodeId);
  20929. if (result.Code == 0)
  20930. {
  20931. jw.Msg = "获取成功!";
  20932. jw.Code = 200;
  20933. jw.Data = new
  20934. {
  20935. groupCost = result.Data,
  20936. blackCodeIsTrue = true
  20937. };
  20938. }
  20939. else
  20940. {
  20941. jw.Code = 400;
  20942. jw.Data = new
  20943. {
  20944. groupCost = result.Data,
  20945. blackCodeIsTrue = false,
  20946. };
  20947. }
  20948. return Ok(jw);
  20949. }
  20950. /// <summary>
  20951. /// 成本获取OP历史车费用
  20952. /// </summary>
  20953. /// <param name="dto"></param>
  20954. /// <returns></returns>
  20955. [HttpPost]
  20956. public async Task<IActionResult> GetHistoryCarData(HistoryCarDataDto dto)
  20957. {
  20958. var jw = JsonView(false);
  20959. try
  20960. {
  20961. List<HistoryCarDataView> dbResult = new List<HistoryCarDataView>();
  20962. //获取现有所有车的数据
  20963. if (!dto.Param.IsNullOrWhiteSpace())
  20964. {
  20965. string sql = $@"
  20966. SELECT gdi.TeamName , gctggr.Area, gctggr.PriceName , gctggrc.Id ,gctggrc.Price , gctggrc.DatePrice , gctggrc.PriceContent , gctggrc.Currency , gctggr.ServiceStartTime , gctggr.ServiceEndTime
  20967. FROM Grp_CarTouristGuideGroundReservationsContent gctggrc inner join Grp_CarTouristGuideGroundReservations gctggr on
  20968. gctggrc.CTGGRId = gctggr.Id inner JOIN Grp_DelegationInfo gdi on gctggr.DiId = gdi.Id LEFT JOIN Sys_SetData ssd on ssd.Id = gctggr.PriceType
  20969. 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
  20970. AND gctggr.ServiceEndTime is not NULL
  20971. ORDER by gctggrc.id DESC
  20972. ";
  20973. dbResult = await _sqlSugar.SqlQueryable<HistoryCarDataView>(sql).ToListAsync();
  20974. var numeberResult = await Task.Run(() =>
  20975. {
  20976. var numberArr = dbResult.Where(x => int.TryParse(x.Area, out int number)).ToList();
  20977. _ = dbResult.RemoveAll(x => int.TryParse(x.Area, out int number));
  20978. return numberArr;
  20979. });
  20980. var cityArr = await _sqlSugar.Queryable<Grp_NationalTravelFee>().ToListAsync();
  20981. foreach (var item in numeberResult)
  20982. {
  20983. var find = cityArr.Find(x => x.Id == int.Parse(item.Area)) ?? new Grp_NationalTravelFee
  20984. {
  20985. Country = "数据异常!",
  20986. City = string.Empty,
  20987. };
  20988. item.Area = find.Country + " " + find.City;
  20989. }
  20990. dbResult.AddRange(numeberResult);
  20991. if (dto.Param.Contains("、"))
  20992. {
  20993. var sp = dto.Param.Split("、");
  20994. dbResult = dbResult.AsParallel().WithDegreeOfParallelism(Environment.ProcessorCount)
  20995. .Where(x =>
  20996. {
  20997. return System.Array.Exists(sp, e =>
  20998. {
  20999. bool where = false;
  21000. if (x.Area != null)
  21001. {
  21002. where = x.Area.Contains(e);
  21003. if (x.Area.Contains("尾款") || x.PriceName.Contains("尾款"))
  21004. {
  21005. return false;
  21006. }
  21007. }
  21008. if (x.PriceName != null && !where)
  21009. {
  21010. where = x.PriceName.Contains(e);
  21011. if (x.PriceName.Contains("尾款") || x.PriceName.Contains("尾款"))
  21012. {
  21013. return false;
  21014. }
  21015. }
  21016. return where;
  21017. });
  21018. }).ToList();
  21019. }
  21020. else
  21021. {
  21022. dbResult = dbResult.AsParallel().WithDegreeOfParallelism(Environment.ProcessorCount)
  21023. .Where(x =>
  21024. {
  21025. bool where = false;
  21026. if (x.Area != null)
  21027. {
  21028. where = x.Area.Contains(dto.Param);
  21029. if (x.Area.Contains("尾款") || x.PriceName.Contains("尾款"))
  21030. {
  21031. return false;
  21032. }
  21033. }
  21034. if (x.PriceName != null && !where)
  21035. {
  21036. where = x.PriceName.Contains(dto.Param);
  21037. if (x.PriceName.Contains("尾款") || x.PriceName.Contains("尾款"))
  21038. {
  21039. return false;
  21040. }
  21041. }
  21042. return where;
  21043. }
  21044. )
  21045. .ToList();
  21046. }
  21047. }
  21048. var view = dbResult.Select(x =>
  21049. {
  21050. decimal dp = 0.00M;
  21051. var startB = DateTime.TryParse(x.Start.ToString(), out DateTime startD);
  21052. var endB = DateTime.TryParse(x.End.ToString(), out DateTime endD);
  21053. if (string.IsNullOrWhiteSpace(x.DatePrice))
  21054. {
  21055. if (startB && endB)
  21056. {
  21057. var timesp = endD.Subtract(startD);
  21058. if ((timesp.Days + 1) != 0)
  21059. {
  21060. dp = x.Price / (timesp.Days + 1);
  21061. }
  21062. }
  21063. }
  21064. else
  21065. {
  21066. dp = x.Price;
  21067. }
  21068. return new
  21069. {
  21070. start = startB ? startD.ToString("yyyy-MM-dd") : "",
  21071. end = endB ? endD.ToString("yyyy-MM-dd") : "",
  21072. x.Area,
  21073. x.id,
  21074. price = x.Price.ToString("F2"),
  21075. x.PriceName,
  21076. x.PriceContent,
  21077. x.TeamName,
  21078. x.DatePrice,
  21079. dayPrice = dp.ToString("F2"),
  21080. };
  21081. }).OrderByDescending(x => x.id).ToList();
  21082. jw = JsonView(true, "获取成功!", view);
  21083. }
  21084. catch (Exception e)
  21085. {
  21086. jw = JsonView(false, e.Message);
  21087. }
  21088. return Ok(jw);
  21089. }
  21090. [HttpPost]
  21091. public async Task<IActionResult> SearchGroupByKeyword(SearchGroupByKeywordDto dto)
  21092. {
  21093. var jw = JsonView(true);
  21094. List<DelegationInfoAndIsTrueView> matches = new List<DelegationInfoAndIsTrueView>();
  21095. #region SQL语句
  21096. //if (string.IsNullOrWhiteSpace(dto.Keyword))
  21097. //{
  21098. // matches = _sqlSugar.SqlQueryable<DelegationInfoAndIsTrueView>($@"
  21099. // Select a.Id,TeamName GroupName,b.isTrue From Grp_DelegationInfo a left join (select top 100 percent Diid, CASE
  21100. // WHEN COUNT(*) >= 0 THEN 'True'
  21101. // ELSE 'False' END as isTrue from Grp_GroupCost where Isdel = 0 and date != '' group by Diid) b on a.Id = b.Diid
  21102. // Where TeamName != '' And IsDel = 0 Order By a.VisitStartDate Desc
  21103. // ")
  21104. // .ToList();
  21105. //}
  21106. //else
  21107. //{
  21108. // string likeKey = string.Empty;
  21109. // foreach (var item in dto.Keyword)
  21110. // {
  21111. // likeKey += "%" + item;
  21112. // }
  21113. // likeKey += "%";
  21114. // matches = _sqlSugar.SqlQueryable<DelegationInfoAndIsTrueView>($@"
  21115. // Select a.Id,TeamName GroupName,b.isTrue From Grp_DelegationInfo a left join (select top 100 percent Diid, CASE
  21116. // WHEN COUNT(*) >= 0 THEN 'True'
  21117. // ELSE 'False' END as isTrue from Grp_GroupCost where Isdel = 0 and date != '' group by Diid) b on a.Id = b.Diid
  21118. // Where TeamName != '' And IsDel = 0 And TeamName LIKE '{likeKey}' Order By a.VisitStartDate Desc
  21119. // ")
  21120. // .ToList();
  21121. //}
  21122. #endregion
  21123. var table = _sqlSugar.Ado.UseStoredProcedure().GetDataTable("SearchGroupByKeyword", new
  21124. {
  21125. @KeyWord = dto.Keyword
  21126. });
  21127. if (table != null && table.Rows.Count > 0)
  21128. {
  21129. foreach (DataRow row in table.Rows)
  21130. {
  21131. matches.Add(new DelegationInfoAndIsTrueView
  21132. {
  21133. Id = row.Field<int>("Id"),
  21134. GroupName = row.Field<string>("GroupName"),
  21135. isTrue = row.Field<string>("isTrue")
  21136. });
  21137. }
  21138. }
  21139. if (matches.Any())
  21140. {
  21141. jw.Data = matches;
  21142. }
  21143. else
  21144. {
  21145. jw.Code = 201;
  21146. jw.Msg = "empty list";
  21147. jw.Data = new List<string>(1);
  21148. }
  21149. return Ok(jw);
  21150. }
  21151. /// <summary>
  21152. /// 报价Word下载
  21153. /// </summary>
  21154. /// <param name="dto"></param>
  21155. /// <returns></returns>
  21156. [HttpPost]
  21157. public async Task<IActionResult> GroupQuotationsFileDown(GroupQuotationsFileDownDto dto)
  21158. {
  21159. var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  21160. .FirstAsync(x => x.Id == dto.Diid && x.IsDel == 0);
  21161. if (di == null)
  21162. {
  21163. return Ok(JsonView(false, "团组不存在!"));
  21164. }
  21165. var mainPrice = _GroupCostParameterRepository.GetGroupCostParameterMainByDiid(dto.Diid);
  21166. if (mainPrice == null || mainPrice.IsShare == 0)
  21167. {
  21168. return Ok(JsonView(false, "团组成本不存在!"));
  21169. }
  21170. var costTypeHotelNumbers = await _sqlSugar.Queryable<Grp_CostTypeHotelNumber>()
  21171. .FirstAsync(x => x.Type == "Default" && x.Diid == dto.Diid && x.IsDel == 0);
  21172. if (costTypeHotelNumbers == null)
  21173. {
  21174. return Ok(JsonView(false, "团组成本不存在!"));
  21175. }
  21176. //文件名
  21177. string strFileName = di.TeamName + "-收款账单.doc";
  21178. //获取模板
  21179. string tmppath = (AppSettingsHelper.Get("WordBasePath") + "Template/收款账单(四川)模板.doc");
  21180. //载入模板
  21181. Document doc = new Document(tmppath);
  21182. decimal allPrice = 0.00M;
  21183. string itemStr = string.Empty;
  21184. Dictionary<string, string> airSouer = new Dictionary<string, string>();
  21185. airSouer.Add("经济舱TBR", "经济舱及酒店双人间");
  21186. airSouer.Add("经济舱SGR", "经济舱及酒店单人间");
  21187. airSouer.Add("公务舱SGR", "公务舱及酒店单人间");
  21188. airSouer.Add("公务舱JSES", "公务舱及酒店小套房");
  21189. airSouer.Add("公务舱SUITE", "公务舱及酒店套房");
  21190. airSouer.Add("经济舱SUITE", "经济舱及酒店套房");
  21191. airSouer.Add("头等舱JSES", "头等舱及酒店小套房");
  21192. airSouer.Add("头等舱SUITE", "头等舱及酒店套房");
  21193. airSouer.Add("经济舱JSES", "经济舱及酒店小套房");
  21194. var priceDataList = new List<(string rsName, string cbName, string xsName, string prefix)>
  21195. {
  21196. ("VisaRS", "VisaCB", "VisaXS", "qz"),
  21197. ("BXRS", "BXCB", "BXXS", "bx"),
  21198. ("HCPRS", "HCPCB", "HCPXS", "hcp"),
  21199. ("JJCRS", "JJCCB", "JJCXS", "jjc"),
  21200. ("GWCRS", "GWCCB", "GWCXS", "gwc"),
  21201. ("TDCRS", "TDCCB", "TDCXS", "tdc"),
  21202. ("CPRS", "CPCB", "CPXS", "cp"),
  21203. ("HSRS", "HSCB", "HSXS", "hsjc"),
  21204. ("TBRNumber", "TBRCB", "TBRXS", "tbr"),
  21205. ("SGRNumber", "SGRCB", "SGRXS", "sgr"),
  21206. ("JSESNumber", "JSESCB", "JSESXS", "jses"),
  21207. ("SUITENumber", "SUITECB", "SUITEXS", "suite"),
  21208. ("DJRS", "DJCB", "DJXS", "dj"),
  21209. ("GWRS", "GWCB", "GWXS", "gw"),
  21210. ("LYJRS", "LYJCB", "LYJXS", "lyj"),
  21211. };
  21212. var OtherCostPropertyBJ = new string[] { "qz", "hcp", "cp", "bx", "hsjc", "dj", "gw", "lyj" };
  21213. var rightSum = 0.00M;
  21214. foreach (var (rsName, cbName, xsName, prefix) in priceDataList)
  21215. {
  21216. var rsValue = (int)mainPrice.GetType().GetProperty(rsName).GetValue(mainPrice);
  21217. var cbValue = (decimal)mainPrice.GetType().GetProperty(cbName).GetValue(mainPrice);
  21218. var xsValue = (decimal)mainPrice.GetType().GetProperty(xsName).GetValue(mainPrice);
  21219. if (prefix == "tbr")
  21220. {
  21221. rsValue *= 2;
  21222. cbValue /= 2;
  21223. }
  21224. if (OtherCostPropertyBJ.Contains(prefix))
  21225. {
  21226. rightSum += cbValue * xsValue;
  21227. }
  21228. }
  21229. var hotelRooms = new Dictionary<string, int>
  21230. {
  21231. { "SGR", costTypeHotelNumbers.SGR },
  21232. { "TBR", costTypeHotelNumbers.TBR },
  21233. { "JSES", costTypeHotelNumbers.JSES },
  21234. { "SUITE", costTypeHotelNumbers.SUITE }
  21235. };
  21236. var flights = new Dictionary<string, int>
  21237. {
  21238. { "经济舱", mainPrice.JJCRS },
  21239. { "公务舱", mainPrice.GWCRS },
  21240. { "头等舱", mainPrice.TDCRS }
  21241. };
  21242. var flightRoomMatchingRules = new Dictionary<string, string[]>
  21243. {
  21244. { "经济舱", new[] { "TBR", "SGR", "JSES", "SUITE" } },
  21245. { "公务舱", new[] { "SUITE", "JSES", "SGR" } },
  21246. { "头等舱", new[] { "SUITE", "JSES" } }
  21247. };
  21248. var result = new Dictionary<string, int>();
  21249. List<AirHotelPrice> airHotelPriceList = new List<AirHotelPrice>();
  21250. foreach (var flight in flights.Keys)
  21251. {
  21252. // 获取当前舱位的匹配规则
  21253. if (flightRoomMatchingRules.TryGetValue(flight, out string[] roomTypes))
  21254. {
  21255. MatchRooms(ref hotelRooms, ref flights, roomTypes, flight, ref result);
  21256. }
  21257. }
  21258. #region right计算
  21259. if (result.Keys.Contains("经济舱TBR") && result["经济舱TBR"] > 0)
  21260. {
  21261. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  21262. var hotel = (mainPrice.TBRCB * mainPrice.TBRXS) / 2;
  21263. airHotelPriceList.Add(new
  21264. AirHotelPrice
  21265. {
  21266. Name = "经济舱TBR",
  21267. Price = rightSum + air + hotel,
  21268. Count = result["经济舱TBR"] * 2
  21269. });
  21270. allPrice += (rightSum + air + hotel) * result["经济舱TBR"] * 2;
  21271. }
  21272. if (result.Keys.Contains("经济舱SGR") && result["经济舱SGR"] > 0)
  21273. {
  21274. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  21275. var hotel = mainPrice.SGRCB * mainPrice.SGRXS;
  21276. airHotelPriceList.Add(new
  21277. AirHotelPrice
  21278. {
  21279. Name = "经济舱SGR",
  21280. Price = rightSum + air + hotel,
  21281. Count = result["经济舱SGR"]
  21282. });
  21283. allPrice += (rightSum + air + hotel) * result["经济舱SGR"];
  21284. }
  21285. if (result.Keys.Contains("公务舱SGR") && result["公务舱SGR"] > 0)
  21286. {
  21287. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  21288. var hotel = mainPrice.SGRCB * mainPrice.SGRXS;
  21289. airHotelPriceList.Add(new
  21290. AirHotelPrice
  21291. {
  21292. Name = "公务舱SGR",
  21293. Price = rightSum + air + hotel,
  21294. Count = result["公务舱SGR"]
  21295. });
  21296. allPrice += (rightSum + air + hotel) * result["公务舱SGR"];
  21297. }
  21298. if (result.Keys.Contains("公务舱JSES") && result["公务舱JSES"] > 0)
  21299. {
  21300. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  21301. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  21302. airHotelPriceList.Add(new
  21303. AirHotelPrice
  21304. {
  21305. Name = "公务舱JSES",
  21306. Price = rightSum + air + hotel,
  21307. Count = result["公务舱JSES"]
  21308. });
  21309. allPrice += (rightSum + air + hotel) * result["公务舱JSES"];
  21310. }
  21311. if (result.Keys.Contains("公务舱SUITE") && result["公务舱SUITE"] > 0)
  21312. {
  21313. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  21314. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  21315. airHotelPriceList.Add(new
  21316. AirHotelPrice
  21317. {
  21318. Name = "公务舱SUITE",
  21319. Price = rightSum + air + hotel,
  21320. Count = result["公务舱SUITE"]
  21321. });
  21322. allPrice += (rightSum + air + hotel) * result["公务舱SUITE"];
  21323. }
  21324. if (result.Keys.Contains("经济舱SUITE") && result["经济舱SUITE"] > 0)
  21325. {
  21326. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  21327. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  21328. airHotelPriceList.Add(new
  21329. AirHotelPrice
  21330. {
  21331. Name = "经济舱SUITE",
  21332. Price = rightSum + air + hotel,
  21333. Count = result["经济舱SUITE"]
  21334. });
  21335. allPrice += (rightSum + air + hotel) * result["经济舱SUITE"];
  21336. }
  21337. if (result.Keys.Contains("头等舱JSES") && result["头等舱JSES"] > 0)
  21338. {
  21339. var air = mainPrice.TDCCB * mainPrice.TDCXS;
  21340. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  21341. airHotelPriceList.Add(new
  21342. AirHotelPrice
  21343. {
  21344. Name = "头等舱JSES",
  21345. Price = rightSum + air + hotel,
  21346. Count = result["头等舱JSES"]
  21347. });
  21348. allPrice += (rightSum + air + hotel) * result["头等舱JSES"];
  21349. }
  21350. if (result.Keys.Contains("头等舱SUITE") && result["头等舱SUITE"] > 0)
  21351. {
  21352. var air = mainPrice.TDCCB * mainPrice.TDCXS;
  21353. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  21354. airHotelPriceList.Add(new
  21355. AirHotelPrice
  21356. {
  21357. Name = "头等舱SUITE",
  21358. Price = rightSum + air + hotel,
  21359. Count = result["头等舱SUITE"]
  21360. });
  21361. allPrice += (rightSum + air + hotel) * result["头等舱SUITE"];
  21362. }
  21363. if (result.Keys.Contains("经济舱JSES") && result["经济舱JSES"] > 0)
  21364. {
  21365. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  21366. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  21367. airHotelPriceList.Add(new
  21368. AirHotelPrice
  21369. {
  21370. Name = "经济舱JSES",
  21371. Price = rightSum + air + hotel,
  21372. Count = result["经济舱JSES"]
  21373. });
  21374. allPrice += (rightSum + air + hotel) * result["经济舱JSES"];
  21375. }
  21376. #endregion
  21377. foreach (var item in airSouer.Keys)
  21378. {
  21379. var find = airHotelPriceList.FirstOrDefault(x => x.Name == item);
  21380. if (find != null && find.Count > 0)
  21381. {
  21382. if (item.Contains("TBR"))
  21383. {
  21384. itemStr += "团费(" + airSouer[item] + ") RMB " + find.Price.ToString("F2") + "/人*" + find.Count + "(" + (find.Count / 2) + "间) ............合计 RMB " + (find.Count * find.Price).ToString("#0.00") + "\n";
  21385. }
  21386. else
  21387. {
  21388. itemStr += "团费(" + airSouer[item] + ") RMB " + find.Price.ToString("F2") + "/人*" + find.Count + "(" + find.Count + "间) ............合计 RMB " + (find.Count * find.Price).ToString("#0.00") + "\n";
  21389. }
  21390. }
  21391. }
  21392. #region 替换Word模板书签内容
  21393. Dictionary<string, string> marks = new Dictionary<string, string>();
  21394. marks.Add("To", di.ClientUnit);//付款方
  21395. marks.Add("ToTel", di.TellPhone);//付款方电话
  21396. marks.Add("Date", DateTime.Now.ToString("yyyy-MM-dd"));//导出时间
  21397. marks.Add("Team", di.VisitCountry.Replace(" ", "、"));//团队名称
  21398. marks.Add("TontractTime", (di.VisitDate).ToString("yyyy年MM月dd日"));//付款日期
  21399. marks.Add("PayDay", (di.PayDay).ToString());//付款预期
  21400. marks.Add("PaymentMoney", (di.PaymentMoney).ToString("#0.00"));//付款金额
  21401. marks.Add("WeChat", di.WeChatNo ?? "");//微信号
  21402. marks.Add("PayItemContent", itemStr);//详细信息
  21403. marks.Add("Total", allPrice.ToString("F2"));//合计
  21404. #endregion
  21405. foreach (var item in marks.Keys)
  21406. {
  21407. if (doc.Range.Bookmarks[item] != null)
  21408. {
  21409. Bookmark mark = doc.Range.Bookmarks[item];
  21410. mark.Text = marks[item];
  21411. }
  21412. }
  21413. string savePaht = $"{AppSettingsHelper.Get("WordBasePath")}GroupCostQuotations/{di.TeamName}_报批费用.doc";
  21414. doc.Save(savePaht);
  21415. var jw = new JsonView();
  21416. jw.Msg = "生成成功!";
  21417. jw.Code = 200;
  21418. jw.Data = new { Url = AppSettingsHelper.Get("WordBaseUrl") + savePaht.Replace(AppSettingsHelper.Get("WordBasePath"), AppSettingsHelper.Get("WordFtpPath")) };
  21419. return Ok(jw);
  21420. }
  21421. /// <summary>
  21422. /// 详细报价费用Excel下载
  21423. /// </summary>
  21424. /// <param name="dto"></param>
  21425. /// <returns></returns>
  21426. [HttpPost]
  21427. public async Task<IActionResult> GroupQuotationsDetailFileDown(GroupQuotationsFileDownDto dto)
  21428. {
  21429. var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  21430. .FirstAsync(x => x.Id == dto.Diid && x.IsDel == 0);
  21431. if (di == null)
  21432. {
  21433. return Ok(JsonView(false, "团组不存在!"));
  21434. }
  21435. var mainPrice = _GroupCostParameterRepository.GetGroupCostParameterMainByDiid(dto.Diid);
  21436. if (mainPrice == null || mainPrice.IsShare == 0)
  21437. {
  21438. return Ok(JsonView(false, "团组成本不存在!"));
  21439. }
  21440. var costTypeHotelNumbers = await _sqlSugar.Queryable<Grp_CostTypeHotelNumber>()
  21441. .FirstAsync(x => x.Type == "Default" && x.Diid == dto.Diid && x.IsDel == 0);
  21442. if (costTypeHotelNumbers == null)
  21443. {
  21444. return Ok(JsonView(false, "团组成本不存在!"));
  21445. }
  21446. WorkbookDesigner designer = new WorkbookDesigner();
  21447. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + ("Template/报价详细表.xls"));
  21448. List<int> hideRowsList = new List<int>();
  21449. int conterStartIndex = 3;
  21450. int rowIndex = conterStartIndex;
  21451. designer.SetDataSource("GroupName", di.TeamName);
  21452. var priceDataList = new List<(string rsName, string cbName, string xsName, string prefix)>
  21453. {
  21454. ("VisaRS", "VisaCB", "VisaXS", "qz"),
  21455. ("BXRS", "BXCB", "BXXS", "bx"),
  21456. ("HCPRS", "HCPCB", "HCPXS", "hcp"),
  21457. ("JJCRS", "JJCCB", "JJCXS", "jjc"),
  21458. ("GWCRS", "GWCCB", "GWCXS", "gwc") ,
  21459. ("TDCRS", "TDCCB", "TDCXS", "tdc") ,
  21460. ("CPRS", "CPCB", "CPXS", "cp") ,
  21461. ("HSRS", "HSCB", "HSXS", "hsjc") ,
  21462. ("TBRNumber", "TBRCB", "TBRXS", "tbr") ,
  21463. ("SGRNumber", "SGRCB", "SGRXS", "sgr") ,
  21464. ("JSESNumber", "JSESCB", "JSESXS", "jses") ,
  21465. ("SUITENumber", "SUITECB", "SUITEXS", "suite") ,
  21466. ("DJRS", "DJCB", "DJXS", "dj") ,
  21467. ("GWRS", "GWCB", "GWXS", "gw") ,
  21468. ("LYJRS", "LYJCB", "LYJXS", "lyj") ,
  21469. };
  21470. var OtherCostPropertyBJ = new string[] { "qz", "hcp", "cp", "bx", "hsjc", "dj", "gw", "lyj" };
  21471. var rightSum = 0.00M;
  21472. foreach (var (rsName, cbName, xsName, prefix) in priceDataList)
  21473. {
  21474. var rsValue = (int)mainPrice.GetType().GetProperty(rsName).GetValue(mainPrice);
  21475. var cbValue = (decimal)mainPrice.GetType().GetProperty(cbName).GetValue(mainPrice);
  21476. var xsValue = (decimal)mainPrice.GetType().GetProperty(xsName).GetValue(mainPrice);
  21477. if (prefix == "tbr")
  21478. {
  21479. rsValue *= 2;
  21480. cbValue /= 2;
  21481. }
  21482. if (OtherCostPropertyBJ.Contains(prefix))
  21483. {
  21484. rightSum += cbValue * xsValue;
  21485. }
  21486. if (rsValue == 0)
  21487. {
  21488. hideRowsList.Add(rowIndex);
  21489. }
  21490. else
  21491. {
  21492. designer.SetDataSource($"{prefix}rs", rsValue);
  21493. designer.SetDataSource($"{prefix}bj", cbValue * xsValue);
  21494. designer.SetDataSource($"{prefix}zbj", cbValue * xsValue * rsValue);
  21495. }
  21496. rowIndex += 2;
  21497. }
  21498. var hotelRooms = new Dictionary<string, int>
  21499. {
  21500. { "SGR", costTypeHotelNumbers.SGR },
  21501. { "TBR", costTypeHotelNumbers.TBR },
  21502. { "JSES", costTypeHotelNumbers.JSES },
  21503. { "SUITE", costTypeHotelNumbers.SUITE }
  21504. };
  21505. var flights = new Dictionary<string, int>
  21506. {
  21507. { "经济舱", mainPrice.JJCRS },
  21508. { "公务舱", mainPrice.GWCRS },
  21509. { "头等舱", mainPrice.TDCRS }
  21510. };
  21511. var flightRoomMatchingRules = new Dictionary<string, string[]>
  21512. {
  21513. { "经济舱", new[] { "TBR", "SGR", "JSES", "SUITE" } },
  21514. { "公务舱", new[] { "SUITE", "JSES", "SGR" } },
  21515. { "头等舱", new[] { "SUITE", "JSES" } }
  21516. };
  21517. var result = new Dictionary<string, int>();
  21518. foreach (var flight in flights.Keys)
  21519. {
  21520. // 获取当前舱位的匹配规则
  21521. if (flightRoomMatchingRules.TryGetValue(flight, out string[] roomTypes))
  21522. {
  21523. MatchRooms(ref hotelRooms, ref flights, roomTypes, flight, ref result);
  21524. }
  21525. }
  21526. var allPrice = 0.00M;
  21527. #region right计算
  21528. int airRowIndex = 35;
  21529. if (result.Keys.Contains("经济舱TBR") && result["经济舱TBR"] > 0)
  21530. {
  21531. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  21532. var hotel = (mainPrice.TBRCB * mainPrice.TBRXS) / 2;
  21533. designer.SetDataSource("jjctbrrs", result["经济舱TBR"] * 2);
  21534. designer.SetDataSource("jjctbrbj", rightSum + air + hotel);
  21535. designer.SetDataSource("jjctbrzbj", (rightSum + air + hotel) * result["经济舱TBR"] * 2);
  21536. allPrice += (rightSum + air + hotel) * result["经济舱TBR"] * 2;
  21537. }
  21538. else
  21539. {
  21540. hideRowsList.Add(airRowIndex);
  21541. }
  21542. airRowIndex += 2;
  21543. if (result.Keys.Contains("经济舱SGR") && result["经济舱SGR"] > 0)
  21544. {
  21545. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  21546. var hotel = mainPrice.SGRCB * mainPrice.SGRXS;
  21547. designer.SetDataSource("jjcsgrrs", result["经济舱SGR"]);
  21548. designer.SetDataSource("jjcsgrbj", rightSum + air + hotel);
  21549. designer.SetDataSource("jjcsgrzbj", (rightSum + air + hotel) * result["经济舱SGR"]);
  21550. allPrice += (rightSum + air + hotel) * result["经济舱SGR"];
  21551. }
  21552. else
  21553. {
  21554. hideRowsList.Add(airRowIndex);
  21555. }
  21556. airRowIndex += 2;
  21557. if (result.Keys.Contains("公务舱SGR") && result["公务舱SGR"] > 0)
  21558. {
  21559. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  21560. var hotel = mainPrice.SGRCB * mainPrice.SGRXS;
  21561. designer.SetDataSource("gwcsgrrs", result["公务舱SGR"]);
  21562. designer.SetDataSource("gwcsgrbj", rightSum + air + hotel);
  21563. designer.SetDataSource("gwcsgrzbj", (rightSum + air + hotel) * result["公务舱SGR"]);
  21564. allPrice += (rightSum + air + hotel) * result["公务舱SGR"];
  21565. }
  21566. else
  21567. {
  21568. hideRowsList.Add(airRowIndex);
  21569. }
  21570. airRowIndex += 2;
  21571. if (result.Keys.Contains("公务舱JSES") && result["公务舱JSES"] > 0)
  21572. {
  21573. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  21574. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  21575. designer.SetDataSource("gwcjsesrs", result["公务舱JSES"]);
  21576. designer.SetDataSource("gwcjsesbj", rightSum + air + hotel);
  21577. designer.SetDataSource("gwcjseszbj", (rightSum + air + hotel) * result["公务舱JSES"]);
  21578. allPrice += (rightSum + air + hotel) * result["公务舱JSES"];
  21579. }
  21580. else
  21581. {
  21582. hideRowsList.Add(airRowIndex);
  21583. }
  21584. airRowIndex += 2;
  21585. if (result.Keys.Contains("公务舱SUITE") && result["公务舱SUITE"] > 0)
  21586. {
  21587. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  21588. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  21589. designer.SetDataSource("gwcsuiters", result["公务舱SUITE"]);
  21590. designer.SetDataSource("gwcsuitebj", rightSum + air + hotel);
  21591. designer.SetDataSource("gwcsuitezbj", (rightSum + air + hotel) * result["公务舱SUITE"]);
  21592. allPrice += (rightSum + air + hotel) * result["公务舱SUITE"];
  21593. }
  21594. else
  21595. {
  21596. hideRowsList.Add(airRowIndex);
  21597. }
  21598. airRowIndex += 2;
  21599. if (result.Keys.Contains("经济舱SUITE") && result["经济舱SUITE"] > 0)
  21600. {
  21601. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  21602. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  21603. designer.SetDataSource("jjcsuiters", result["经济舱SUITE"]);
  21604. designer.SetDataSource("jjcsuitebj", rightSum + air + hotel);
  21605. designer.SetDataSource("jjcsuitezbj", (rightSum + air + hotel) * result["经济舱SUITE"]);
  21606. allPrice += (rightSum + air + hotel) * result["经济舱SUITE"];
  21607. }
  21608. else
  21609. {
  21610. hideRowsList.Add(airRowIndex);
  21611. }
  21612. airRowIndex += 2;
  21613. if (result.Keys.Contains("头等舱JSES") && result["头等舱JSES"] > 0)
  21614. {
  21615. var air = mainPrice.TDCCB * mainPrice.TDCXS;
  21616. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  21617. designer.SetDataSource("tdcjsesrs", result["头等舱JSES"]);
  21618. designer.SetDataSource("tdcjsesbj", rightSum + air + hotel);
  21619. designer.SetDataSource("tdcjseszbj", (rightSum + air + hotel) * result["头等舱JSES"]);
  21620. allPrice += (rightSum + air + hotel) * result["头等舱JSES"];
  21621. }
  21622. else
  21623. {
  21624. hideRowsList.Add(airRowIndex);
  21625. }
  21626. airRowIndex += 2;
  21627. if (result.Keys.Contains("头等舱SUITE") && result["头等舱SUITE"] > 0)
  21628. {
  21629. var air = mainPrice.TDCCB * mainPrice.TDCXS;
  21630. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  21631. designer.SetDataSource("tdcsuiters", result["头等舱SUITE"]);
  21632. designer.SetDataSource("tdcsuitebj", rightSum + air + hotel);
  21633. designer.SetDataSource("tdcsuitezbj", (rightSum + air + hotel) * result["头等舱SUITE"]);
  21634. allPrice += (rightSum + air + hotel) * result["头等舱SUITE"];
  21635. }
  21636. else
  21637. {
  21638. hideRowsList.Add(airRowIndex);
  21639. }
  21640. airRowIndex += 2;
  21641. if (result.Keys.Contains("经济舱JSES") && result["经济舱JSES"] > 0)
  21642. {
  21643. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  21644. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  21645. designer.SetDataSource("jjcjsesrs", result["经济舱JSES"]);
  21646. designer.SetDataSource("jjcjsesbj", rightSum + air + hotel);
  21647. designer.SetDataSource("jjcjseszbj", (rightSum + air + hotel) * result["经济舱JSES"]);
  21648. allPrice += (rightSum + air + hotel) * result["经济舱JSES"];
  21649. }
  21650. else
  21651. {
  21652. hideRowsList.Add(airRowIndex);
  21653. }
  21654. #endregion
  21655. designer.SetDataSource("AllPrice", "总金额:" + allPrice.ToString("#0.00"));
  21656. string savePaht = AppSettingsHelper.Get("ExcelBasePath") + "GroupCostQuotations/" + di.TeamName + "_详细报批费用.xls";
  21657. var ws = designer.Workbook.Worksheets[0];
  21658. foreach (var Rowindex in hideRowsList)
  21659. {
  21660. ws.Cells.HideRows(Rowindex, 2);
  21661. }
  21662. designer.Process();
  21663. designer.Workbook.Save(savePaht);
  21664. return Ok(JsonView(true, "生成成功!", new
  21665. {
  21666. Url = AppSettingsHelper.Get("ExcelBaseUrl") + savePaht.Replace(AppSettingsHelper.Get("ExcelBasePath"), AppSettingsHelper.Get("ExcelFtpPath"))
  21667. }));
  21668. }
  21669. private void MatchRooms(ref Dictionary<string, int> hotelRooms, ref Dictionary<string, int> flights, string[] roomTypes, string flightType, ref Dictionary<string, int> result)
  21670. {
  21671. foreach (var roomType in roomTypes)
  21672. {
  21673. while (hotelRooms[roomType] > 0 && flights[flightType] > 0)
  21674. {
  21675. hotelRooms[roomType]--;
  21676. flights[flightType]--;
  21677. if (roomType == "TBR")
  21678. {
  21679. flights[flightType]--; // 双人间在减少1
  21680. }
  21681. string key = flightType + roomType;
  21682. if (result.Keys.Contains(key))
  21683. {
  21684. result[key]++;
  21685. }
  21686. else
  21687. {
  21688. result.Add(key, 1);
  21689. }
  21690. }
  21691. }
  21692. }
  21693. private class AirHotelPrice
  21694. {
  21695. public string Name { get; set; }
  21696. public decimal Price { get; set; }
  21697. public int Count { get; set; }
  21698. }
  21699. /// <summary>
  21700. /// 团组系数设置
  21701. /// </summary>
  21702. /// <param name="dto"></param>
  21703. /// <returns></returns>
  21704. [HttpPost]
  21705. public async Task<IActionResult> QueryGroupCostCoefficient(QueryGroupCostCoefficientDto dto)
  21706. {
  21707. var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  21708. .FirstAsync(x => x.Id == dto.Diid && x.IsDel == 0);
  21709. if (di == null)
  21710. {
  21711. return Ok(JsonView(false, "团组不存在!"));
  21712. }
  21713. //var firstExpression = Expressionable.Create<Grp_GroupCostParameter>()
  21714. // .And(x => x.CostType == "A" && x.DiId == di.Id && x.IsDel == 0);
  21715. //var groupCostMainPrice = await _sqlSugar.Queryable<Grp_GroupCostParameter>().
  21716. // FirstAsync(firstExpression.ToExpression());
  21717. #region JSON
  21718. string hcpJson = @"
  21719. [
  21720. {
  21721. ""min"": 1,
  21722. ""max"": 500,
  21723. ""value"": 1.50
  21724. },
  21725. {
  21726. ""min"": 501,
  21727. ""max"": 1000,
  21728. ""value"": 1.40
  21729. },
  21730. {
  21731. ""min"": 1001,
  21732. ""max"": 2000,
  21733. ""value"": 1.35
  21734. }
  21735. ]";
  21736. #endregion
  21737. var hcpPriceRange = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PriceRange>>(hcpJson);
  21738. List<(Predicate<decimal>, decimal)> hcpSwitchDictionary = hcpPriceRange
  21739. .Select(pr => (new Predicate<decimal>(x => x >= pr.Min && x <= pr.Max), pr.Value))
  21740. .ToList();
  21741. List<(Predicate<decimal>, List<(Predicate<decimal>, decimal)>)> jjcSwitchDictionary =
  21742. new List<(Predicate<decimal>, List<(Predicate<decimal>, decimal)>)>();
  21743. //jjcSwitchDictionary.Add((new Predicate<decimal>(x => x >= 1 && x <= 3),
  21744. // new List<(Predicate<decimal>, decimal)>()
  21745. // {
  21746. // (new Predicate<decimal>(y => y >= 1000 && y <= 3000), 2.6M),
  21747. // (new Predicate<decimal>(y => y > 3000), 2.5M)
  21748. // }
  21749. // ));
  21750. #region 签证系数
  21751. var visaXS = 0.00M;
  21752. switch (dto.VisaCB)
  21753. {
  21754. case decimal n when (n > 1 && n < 500):
  21755. switch (dto.VisaRS)
  21756. {
  21757. case 2 or 3:
  21758. visaXS = 1.35M;
  21759. break;
  21760. case 4 or 5:
  21761. visaXS = 1.30M;
  21762. break;
  21763. case 6 or 7:
  21764. visaXS = 1.25M;
  21765. break;
  21766. case 8 or 9 or 10:
  21767. visaXS = 1.20M;
  21768. break;
  21769. case > 10:
  21770. visaXS = 1.15M;
  21771. break;
  21772. default:
  21773. visaXS = 0.00M;
  21774. break;
  21775. }
  21776. break;
  21777. case decimal n when (n >= 500 && n < 1000):
  21778. switch (dto.VisaRS)
  21779. {
  21780. case 2 or 3 or 4:
  21781. visaXS = 1.30M;
  21782. break;
  21783. case 5 or 6 or 7 or 8:
  21784. visaXS = 1.25M;
  21785. break;
  21786. case 9 or 10:
  21787. visaXS = 1.20M;
  21788. break;
  21789. case > 10:
  21790. visaXS = 1.15M;
  21791. break;
  21792. default:
  21793. visaXS = 0.00M;
  21794. break;
  21795. }
  21796. break;
  21797. default:
  21798. switch (dto.VisaRS)
  21799. {
  21800. case 2 or 3 or 4:
  21801. visaXS = 1.30M;
  21802. break;
  21803. case 5 or 6 or 7 or 8:
  21804. visaXS = 1.25M;
  21805. break;
  21806. case 9 or 10:
  21807. visaXS = 1.20M;
  21808. break;
  21809. case > 10:
  21810. visaXS = 1.15M;
  21811. break;
  21812. default:
  21813. visaXS = 0.00M;
  21814. break;
  21815. }
  21816. break;
  21817. }
  21818. #endregion
  21819. #region 火车系数
  21820. var hcpXS = 0.00M;
  21821. foreach (var (condition, result) in hcpSwitchDictionary)
  21822. {
  21823. if (condition(dto.HCPCB))
  21824. {
  21825. hcpXS = result;
  21826. break;
  21827. }
  21828. }
  21829. #endregion
  21830. #region 机票系数
  21831. #region 经济舱系数
  21832. var jjcXS = 0.00M;
  21833. switch (dto.JJCCB)
  21834. {
  21835. case decimal x when (x >= 1000 && x <= 3000):
  21836. jjcXS = 2.6M;
  21837. break;
  21838. case decimal x when (x >= 3001 && x <= 8000):
  21839. jjcXS = 2.3M;
  21840. break;
  21841. case decimal x when (x >= 8001 && x <= 15000):
  21842. jjcXS = 2.1M;
  21843. break;
  21844. case decimal x when (x >= 15001 && x <= 30000):
  21845. jjcXS = 1.95M;
  21846. break;
  21847. case > 30000:
  21848. jjcXS = 1.8M;
  21849. break;
  21850. default:
  21851. break;
  21852. }
  21853. #endregion
  21854. #region 公务舱系数
  21855. var gwcXS = 0.00M;
  21856. switch (dto.GWCCB)
  21857. {
  21858. case decimal x when (x >= 1000 && x <= 3000):
  21859. gwcXS = 2.5M;
  21860. break;
  21861. case decimal x when (x >= 3001 && x <= 8000):
  21862. gwcXS = 2.2M;
  21863. break;
  21864. case decimal x when (x >= 8001 && x <= 15000):
  21865. gwcXS = 2.0M;
  21866. break;
  21867. case decimal x when (x >= 15001 && x <= 30000):
  21868. gwcXS = 1.85M;
  21869. break;
  21870. case > 30000:
  21871. gwcXS = 1.7M;
  21872. break;
  21873. default:
  21874. break;
  21875. }
  21876. #endregion
  21877. #region 头等舱系数
  21878. var tdcXS = 0.00M;
  21879. switch (dto.TDCCB)
  21880. {
  21881. case > 70000:
  21882. tdcXS = 1.5M;
  21883. break;
  21884. default:
  21885. tdcXS = 1.9M;
  21886. break;
  21887. }
  21888. #endregion
  21889. #endregion
  21890. #region 酒店系数
  21891. Dictionary<decimal, List<string>> dic = new Dictionary<decimal, List<string>>()
  21892. {
  21893. {1.6M, new List<string>(){"新西兰","澳大利亚" }},
  21894. {1.5M, new List<string>(){"越南社会主义共和国",
  21895. "老挝",
  21896. "柬埔寨",
  21897. "泰国",
  21898. "缅甸",
  21899. "马来西亚",
  21900. //"新加坡",
  21901. "文莱达鲁萨兰",
  21902. "印度尼西亚",
  21903. "东帝汶"}},
  21904. {1.2M, new List<string>(){ "日本","新加坡","法国","意大利","荷兰"}},
  21905. };
  21906. #region SGR
  21907. var sgrXS = 1.25M;
  21908. #endregion
  21909. #region TBR
  21910. var tbrXS = 1.25M;
  21911. #endregion
  21912. #region JSES
  21913. var jsesXS = 1.25M;
  21914. #endregion
  21915. #region SUITE
  21916. var suiteXS = 1.25M;
  21917. #endregion
  21918. var countryArr = di.VisitCountry.Split("|");
  21919. foreach (var item in dic)
  21920. {
  21921. var extsisCount = item.Value.Where(x => countryArr.Contains(x))
  21922. .Count();
  21923. if (extsisCount > 0)
  21924. {
  21925. jsesXS = item.Key;
  21926. sgrXS = item.Key;
  21927. tbrXS = item.Key;
  21928. suiteXS = item.Key;
  21929. }
  21930. }
  21931. #endregion
  21932. #region 地接系数
  21933. var djXS = 0.00M;
  21934. switch (dto.DJRS)
  21935. {
  21936. case 2 or 3:
  21937. djXS = 2.65M;
  21938. break;
  21939. case 4:
  21940. djXS = 2.6M;
  21941. break;
  21942. case 5 or 6:
  21943. djXS = 2.5M;
  21944. break;
  21945. case 7 or 8:
  21946. djXS = 2.4M;
  21947. break;
  21948. case 9 or 10:
  21949. djXS = 2.3M;
  21950. break;
  21951. case 11:
  21952. djXS = 2.2M;
  21953. break;
  21954. case 12:
  21955. djXS = 2.1M;
  21956. break;
  21957. case 13 or 14:
  21958. djXS = 2M;
  21959. break;
  21960. case 15:
  21961. djXS = 1.9M;
  21962. break;
  21963. case 16 or 17 or 18:
  21964. djXS = 1.8M;
  21965. break;
  21966. case 19 or 20:
  21967. djXS = 1.7M;
  21968. break;
  21969. }
  21970. #endregion
  21971. #region 零用金系数
  21972. var lyjXS = 0.00M;
  21973. switch (dto.LYJRS)
  21974. {
  21975. case 2:
  21976. lyjXS = 1.25M;
  21977. break;
  21978. case 3 or 4 or 5:
  21979. lyjXS = 1.2M;
  21980. break;
  21981. case int number when (number > 5 && number < 10):
  21982. lyjXS = 1.15M;
  21983. break;
  21984. case > 10:
  21985. lyjXS = 1.1M;
  21986. break;
  21987. default:
  21988. break;
  21989. }
  21990. #endregion
  21991. return Ok(JsonView(true, "查询成功", new ArrayList()
  21992. {
  21993. new { label = "火车票系数", value = hcpXS, key = "hcpXS" },
  21994. new { label = "经济舱系数", value = jjcXS, key = "jjcXS" },
  21995. new { label = "公务舱系数", value = gwcXS, key = "gwcXS" },
  21996. new { label = "头等舱系数", value = tdcXS, key = "tdcXS" },
  21997. new { label = "SGR系数", value = sgrXS, key = "sgrXS" },
  21998. new { label = "TBR系数", value = tbrXS, key = "tbrXS" },
  21999. new { label = "JSES系数", value = jsesXS, key = "jsesXS" },
  22000. new { label = "SUITE系数", value = suiteXS, key = "suiteXS" },
  22001. new { label = "地接系数", value = djXS, key = "djXS" },
  22002. new { label = "零用金系数", value = lyjXS, key = "lyjXS" },
  22003. new { label = "公务系数", value = 2M, key = "gwXS" }
  22004. }));
  22005. }
  22006. #endregion
  22007. #region 酒店预订 New 2023-12-28 17:45
  22008. /// <summary>
  22009. /// 酒店预订
  22010. /// 酒店费用列表 根据团组Id查询
  22011. /// </summary>
  22012. /// <param name="_dto"></param>
  22013. /// <returns></returns>
  22014. [HttpPost]
  22015. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22016. public async Task<IActionResult> PostHotelReservationsItemsByDiId(HotelReservationItemDto _dto)
  22017. {
  22018. #region 参数验证
  22019. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  22020. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  22021. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  22022. #region 团组操作权限验证 76 酒店预定模块
  22023. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22024. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  22025. #endregion
  22026. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22027. #region 页面操作权限验证
  22028. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22029. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  22030. #endregion
  22031. #endregion
  22032. return Ok(await _hotelPriceRep.ItemsByDiId(_dto.PortType, _dto.DiId));
  22033. }
  22034. /// <summary>
  22035. /// 酒店预订
  22036. /// 基础数据
  22037. /// </summary>
  22038. /// <param name="_dto"></param>
  22039. /// <returns></returns>
  22040. [HttpPost]
  22041. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22042. public async Task<IActionResult> PostHotelReservationsBasicsDataInit(HotelReservationBasicsDataInitDto _dto)
  22043. {
  22044. #region 参数验证
  22045. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  22046. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  22047. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  22048. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22049. #region 页面操作权限验证
  22050. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22051. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  22052. #endregion
  22053. #region 团组操作权限验证 76 酒店预定模块
  22054. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22055. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  22056. #endregion
  22057. #endregion
  22058. return Ok(await _hotelPriceRep.BasicsDataInit(_dto.PortType, _dto.DiId));
  22059. }
  22060. /// <summary>
  22061. /// 酒店预订
  22062. /// 创建 入住卷号码
  22063. /// </summary>
  22064. /// <param name="_dto"></param>
  22065. /// <returns></returns>
  22066. [HttpPost]
  22067. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22068. public async Task<IActionResult> PostHotelReservationsCreateCheckVolumeNo(HotelReservationBasicsDataInitDto _dto)
  22069. {
  22070. #region 参数验证
  22071. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  22072. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  22073. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  22074. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22075. #region 页面操作权限验证
  22076. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22077. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  22078. #endregion
  22079. #region 团组操作权限验证 76 酒店预定模块
  22080. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22081. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  22082. #endregion
  22083. #endregion
  22084. Result data = await _hotelPriceRep.CreateCheckVolumeNo(_dto.DiId);
  22085. if (data.Code != 0)
  22086. {
  22087. return Ok(JsonView(false, data.Msg));
  22088. }
  22089. return Ok(JsonView(true, data.Msg, data.Data));
  22090. }
  22091. /// <summary>
  22092. /// 酒店预订
  22093. /// 详情
  22094. /// </summary>
  22095. /// <param name="_dto"></param>
  22096. /// <returns></returns>
  22097. [HttpPost]
  22098. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22099. public async Task<IActionResult> PostHotelReservationsDetails(HotelReservationsDetailsDto _dto)
  22100. {
  22101. #region 参数验证
  22102. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入正确的UserId参数"));
  22103. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  22104. if (_dto.DiId < 1) return Ok(JsonView(false, "请传入正确的DiId参数"));
  22105. #region 团组操作权限验证 76 酒店预定模块
  22106. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22107. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  22108. #endregion
  22109. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22110. #region 页面操作权限验证
  22111. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22112. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  22113. #endregion
  22114. #endregion
  22115. return Ok(await _hotelPriceRep.Details(_dto.PortType, _dto.Id));
  22116. }
  22117. /// <summary>
  22118. /// 酒店预订
  22119. /// Add Or Edit
  22120. /// </summary>
  22121. /// <param name="_dto"></param>
  22122. /// <returns></returns>
  22123. [HttpPost]
  22124. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22125. public async Task<IActionResult> PostHotelReservationsAddOrEdit(HotelReservationsAddOrEditDto _dto)
  22126. {
  22127. #region 参数验证
  22128. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  22129. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  22130. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  22131. #region 团组操作权限验证 76 酒店预定模块
  22132. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22133. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  22134. #endregion
  22135. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22136. #region 页面操作权限验证
  22137. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22138. if (_dto.Id == 0) // Add
  22139. {
  22140. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
  22141. }
  22142. else if (_dto.Id > 1) // Edit
  22143. {
  22144. if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
  22145. }
  22146. else return Ok(JsonView(false, "请输入正确的数据Id!"));
  22147. #endregion
  22148. #endregion
  22149. JsonView _view = await _hotelPriceRep.AddOrEdit(_dto);
  22150. if (_view.Code != 200)
  22151. {
  22152. return Ok(_view);
  22153. }
  22154. #region 成本无酒店价格数据进入超支
  22155. _sqlSugar.BeginTran();
  22156. var start_Bool = DateTime.TryParse(_dto.CheckInDate, out DateTime start_Time);
  22157. var end_Bool = DateTime.TryParse(_dto.CheckOutDate, out DateTime end_Time);
  22158. var groupCost = _sqlSugar.Queryable<Grp_GroupCost>().Where(x => x.Diid == _dto.DiId && x.IsDel == 0).ToList();
  22159. for (int i = 0; i < groupCost.Count; i++)
  22160. {
  22161. if (groupCost[i].Date.IsNullOrWhiteSpace() && i != 0)
  22162. {
  22163. groupCost[i].Date = groupCost[i - 1].Date;
  22164. }
  22165. }
  22166. var groupCost_Grp = groupCost.GroupBy(x => x.Date).ToList();
  22167. List<Fin_GroupExtraCostDto_OP> extraCostList = new
  22168. List<Fin_GroupExtraCostDto_OP>();
  22169. if (start_Bool && end_Bool)
  22170. {
  22171. while (start_Time < end_Time)
  22172. {
  22173. foreach (var item in groupCost_Grp)
  22174. {
  22175. if (DateTime.TryParse(item.Key, out DateTime cost_Time))
  22176. {
  22177. if (DateTime.Compare(start_Time, cost_Time) == 0 && item.Sum(x => x.SGR + x.Suite + x.TBR + x.JS_ES) == 0)
  22178. {
  22179. extraCostList.Add(new
  22180. Fin_GroupExtraCostDto_OP
  22181. {
  22182. Area = _dto.AreaId,
  22183. coefficient = 1.5M,
  22184. createUser = _dto.UserId,
  22185. currency = _dto.CardPriceCurrency,
  22186. diId = _dto.DiId,
  22187. ManagerConfirm = 0,
  22188. SupervisorConfirm = 0,
  22189. SYsupervisorConfirm = 0,
  22190. editType = 1,
  22191. PortType = 1,
  22192. price = _dto.CardPrice,
  22193. PriceCount = 1,
  22194. priceType = 1027,
  22195. priceDetailType = 1044,
  22196. PriceDt = start_Time.ToString("yyyy-MM-dd"),
  22197. priceName = $"酒店超支费用-酒店导入-({start_Time.ToString("yyyy/MM/dd")})",
  22198. });
  22199. }
  22200. }
  22201. }
  22202. start_Time = start_Time.AddDays(1);
  22203. }
  22204. }
  22205. if (extraCostList.Any())
  22206. {
  22207. await _carTouristGuideGroundRep.GroupExtraCost_OperatorList(extraCostList);
  22208. }
  22209. _sqlSugar.CommitTran();
  22210. #endregion
  22211. #region 应用推送
  22212. try
  22213. {
  22214. //int ccpId = (int)_view.Data.GetType().GetProperty("ccpId").GetValue(_view.Data, null);
  22215. //int sign = (int)_view.Data.GetType().GetProperty("sign").GetValue(_view.Data, null);
  22216. //int hotelId = (int)_view.Data.GetType().GetProperty("hotelId").GetValue(_view.Data, null);
  22217. int ccpId = Convert.ToInt32(_view.Data.GetType().GetProperty("ccpId").GetValue(_view.Data, null) ?? 0);
  22218. int sign = Convert.ToInt32(_view.Data.GetType().GetProperty("sign").GetValue(_view.Data, null) ?? 0);
  22219. int hotelId = Convert.ToInt32(_view.Data.GetType().GetProperty("hotelId").GetValue(_view.Data, null) ?? 0);
  22220. var diId = _dto.DiId;
  22221. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  22222. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  22223. #region 操作记录
  22224. var opInfo = new Crm_TableOperationRecord()
  22225. {
  22226. TableName = "Grp_HotelReservations",
  22227. PortType = _dto.PortType,
  22228. DataId = hotelId,
  22229. CreateUserId = _dto.UserId
  22230. };
  22231. //var opStatus = OperationEnum.NoOperation;
  22232. if (_dto.Id < 1) //添加操作
  22233. {
  22234. opInfo.OperationItem = OperationEnum.Add;
  22235. }
  22236. else if (_dto.Id > 0)
  22237. {
  22238. opInfo.OperationItem = OperationEnum.Edit;
  22239. }
  22240. string opRemark = string.Empty;
  22241. if (ccpInfo != null)
  22242. {
  22243. // USD 1211.86、 CNY 8761.75、汇率:7.2300
  22244. var currency = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.Id == ccpInfo.PaymentCurrency).First()?.Name;
  22245. var cnyPrice = ccpInfo.PayMoney * ccpInfo.DayRate;
  22246. opRemark = $"{currency} {ccpInfo.PayMoney.ToString("#0.00")}、CNY {cnyPrice.ToString("#0.00")}、汇率:{ccpInfo.DayRate.ToString("#0.0000")}";
  22247. }
  22248. opInfo.Remark = opRemark;
  22249. await _tableorRep.AddAsync(opInfo);
  22250. #endregion
  22251. _logger.LogInformation($"【iOS推送通知Exception】Begin");
  22252. //2024-10-21 新增LZ UID
  22253. var userIds = new List<int>() { 21 };
  22254. string title = $"费用审核";
  22255. string content = "";
  22256. if (_dto.Id == 0) content = $"[新增-酒店费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  22257. else if (_dto.Id > 0) content = $"[更新-酒店费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  22258. try
  22259. {
  22260. PageParam_PriceAuditH5 h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "76" };
  22261. await APNsTools.iOS_PushNotifications1("051", title, "", content, true, "ExpenseAuditWebView", h5);
  22262. //Logs($"【iOS推送通知PostHotelReservationsAddOrEdit】Start");
  22263. //var iosRes = await APNsTools.iOS_PushNotifications("051", title, "", content);
  22264. //Logs($"【iOS推送通知PostHotelReservationsAddOrEdit】End Response:[{JsonConvert.SerializeObject(iosRes)}]");
  22265. }
  22266. catch (Exception ex)
  22267. {
  22268. Logs($"【iOS推送通知-PostHotelReservationsAddOrEdit-Exception】[{ex.Message}]");
  22269. }
  22270. }
  22271. catch (Exception ex)
  22272. {
  22273. Logs($"【iOS推送通知Exception】【{ex.Message}】");
  22274. }
  22275. try
  22276. {
  22277. //int ccpId = (int)_view.Data.GetType().GetProperty("ccpId").GetValue(_view.Data, null);
  22278. //int sign = (int)_view.Data.GetType().GetProperty("sign").GetValue(_view.Data, null);
  22279. //int hotelId = (int)_view.Data.GetType().GetProperty("hotelId").GetValue(_view.Data, null);
  22280. int ccpId = Convert.ToInt32(_view.Data.GetType().GetProperty("ccpId").GetValue(_view.Data, null) ?? 0);
  22281. int sign = Convert.ToInt32(_view.Data.GetType().GetProperty("sign").GetValue(_view.Data, null) ?? 0);
  22282. int hotelId = Convert.ToInt32(_view.Data.GetType().GetProperty("hotelId").GetValue(_view.Data, null) ?? 0);
  22283. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  22284. //自动审核
  22285. var autoAdit = await _feeAuditRep.FeeAutomaticAudit(1, _dto.DiId, hotelId);
  22286. //if (autoAdit.Code != 200) _view.Msg += $"\r\n{autoAdit.Msg}";
  22287. _logger.LogInformation($"【酒店自动审核】【{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}】执行调用 调用结果:{JsonConvert.SerializeObject(autoAdit)}");
  22288. //2024-10-21 新增LZ UID
  22289. var userIds = new List<int>() { 21 };
  22290. string title = $"系统通知";
  22291. var diId = _dto.DiId;
  22292. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  22293. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  22294. string content = "";
  22295. if (_dto.Id == 0) content = $"[新增-酒店费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  22296. else if (_dto.Id > 0) content = $"[更新-酒店费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  22297. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  22298. }
  22299. catch (Exception ex)
  22300. {
  22301. }
  22302. #endregion
  22303. return Ok(_view);
  22304. }
  22305. /// <summary>
  22306. /// 酒店自动审核测试
  22307. /// Add Or Edit
  22308. /// </summary>
  22309. /// <param name="diid"></param>
  22310. /// <param name="dataId"></param>
  22311. /// <returns></returns>
  22312. [HttpPost]
  22313. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22314. public async Task<IActionResult> PostHotelAutoAuditTest(int diid, int dataId)
  22315. {
  22316. #region 应用推送
  22317. try
  22318. {
  22319. //自动审核
  22320. await _feeAuditRep.FeeAutomaticAudit(1, diid, dataId);
  22321. }
  22322. catch (Exception ex)
  22323. {
  22324. return Ok(JsonView(false, ex.Message));
  22325. }
  22326. #endregion
  22327. return Ok(JsonView(false, "操作成功"));
  22328. }
  22329. /// <summary>
  22330. /// 酒店预订
  22331. /// Del
  22332. /// </summary>
  22333. /// <param name="_dto"></param>
  22334. /// <returns></returns>
  22335. [HttpPost]
  22336. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22337. public async Task<IActionResult> PostHotelReservationsDel(HotelReservationsDelDto _dto)
  22338. {
  22339. #region 参数验证
  22340. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  22341. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  22342. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  22343. #region 团组操作权限验证 76 酒店预定模块
  22344. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22345. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  22346. #endregion
  22347. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22348. #region 页面操作权限验证
  22349. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22350. if (pageFunAuthView.DeleteAuth == 0) return Ok(JsonView(false, "您没有删除权限!"));
  22351. #endregion
  22352. #endregion
  22353. var data = await _hotelPriceRep.Del(_dto.Id, _dto.UserId);
  22354. #region 操作记录
  22355. await _tableorRep.AddAsync(new Crm_TableOperationRecord()
  22356. {
  22357. TableName = "Grp_HotelReservations",
  22358. PortType = _dto.PortType,
  22359. OperationItem = OperationEnum.Del,
  22360. DataId = _dto.Id,
  22361. CreateUserId = _dto.UserId
  22362. });
  22363. #endregion
  22364. return Ok(data);
  22365. }
  22366. /// <summary>
  22367. /// 酒店预订
  22368. /// 生成VOUCHER
  22369. /// 2024.05.06 之前版本
  22370. /// </summary>
  22371. /// <param name="_dto"></param>
  22372. /// <returns></returns>
  22373. [HttpPost]
  22374. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22375. public async Task<IActionResult> PostHotelReservationsCreateVoucherOld(HotelReservationsCreateVoucherDto _dto)
  22376. {
  22377. try
  22378. {
  22379. #region 参数验证
  22380. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  22381. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  22382. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  22383. if (_dto.Id < 1) return Ok(JsonView(false, "Id为空"));
  22384. #region 团组操作权限验证 76 酒店预定模块
  22385. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22386. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  22387. #endregion
  22388. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22389. #region 页面操作权限验证
  22390. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22391. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  22392. #endregion
  22393. #endregion
  22394. Grp_HotelReservations hr = await _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && it.Id == _dto.Id).FirstAsync();
  22395. //判断数据是否完整
  22396. if (hr != null)
  22397. {
  22398. if (!string.IsNullOrEmpty(hr.DetermineNo))
  22399. {
  22400. string strFileName = "HotelStatement/";
  22401. Grp_DelegationInfo dele = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == _dto.DiId).FirstAsync();
  22402. if (dele != null)
  22403. strFileName += dele.TourCode;
  22404. //载入模板
  22405. string sss = AppSettingsHelper.Get("WordBasePath") + "Template/酒店预订模板.doc";
  22406. Document doc = new Document(sss);
  22407. DocumentBuilder builder = new DocumentBuilder(doc);
  22408. #region 替换Word模板书签内容
  22409. //这里可以创建个DataTable循环添加书签的值,这里提示一下就不多做修改了
  22410. //入住卷预定号码
  22411. if (doc.Range.Bookmarks["VNO"] != null)
  22412. {
  22413. Bookmark mark = doc.Range.Bookmarks["VNO"];
  22414. mark.Text = hr.CheckNumber;
  22415. }
  22416. //酒店时间
  22417. if (doc.Range.Bookmarks["Date"] != null)
  22418. {
  22419. Bookmark mark = doc.Range.Bookmarks["Date"];
  22420. mark.Text = Convert.ToDateTime(hr.CreateTime).ToString("yyyy-MM-dd");
  22421. }
  22422. //团号
  22423. if (doc.Range.Bookmarks["TNo"] != null)
  22424. {
  22425. Bookmark mark = doc.Range.Bookmarks["TNo"];
  22426. mark.Text = dele.TourCode;
  22427. }
  22428. //预定号码
  22429. if (doc.Range.Bookmarks["BookingId"] != null)
  22430. {
  22431. Bookmark mark = doc.Range.Bookmarks["BookingId"];
  22432. mark.Text = hr.ReservationsNo;
  22433. }
  22434. if (doc.Range.Bookmarks["HotelConfirmNo"] != null)
  22435. {
  22436. Bookmark mark = doc.Range.Bookmarks["HotelConfirmNo"];
  22437. mark.Text = hr.DetermineNo;
  22438. }
  22439. //酒店城市
  22440. if (doc.Range.Bookmarks["City"] != null)
  22441. {
  22442. Bookmark mark = doc.Range.Bookmarks["City"];
  22443. mark.Text = hr.City;
  22444. }
  22445. //酒店名称
  22446. if (doc.Range.Bookmarks["HName"] != null)
  22447. {
  22448. Bookmark mark = doc.Range.Bookmarks["HName"];
  22449. mark.Text = hr.HotelName;
  22450. }
  22451. //酒店地址
  22452. if (doc.Range.Bookmarks["Address"] != null)
  22453. {
  22454. Bookmark mark = doc.Range.Bookmarks["Address"];
  22455. mark.Text = hr.HotelAddress;
  22456. }
  22457. //酒店电话
  22458. if (doc.Range.Bookmarks["Tel"] != null)
  22459. {
  22460. Bookmark mark = doc.Range.Bookmarks["Tel"];
  22461. mark.Text = hr.HotelTel;
  22462. }
  22463. //酒店传真
  22464. if (doc.Range.Bookmarks["Fax"] != null)
  22465. {
  22466. Bookmark mark = doc.Range.Bookmarks["Fax"];
  22467. if (!string.IsNullOrWhiteSpace(hr.HotelFax))
  22468. {
  22469. mark.Text = hr.HotelFax;
  22470. }
  22471. }
  22472. //入住时间
  22473. if (doc.Range.Bookmarks["CIn"] != null)
  22474. {
  22475. DateTime dtCheckIn = Convert.ToDateTime(hr.CheckInDate);
  22476. Bookmark mark = doc.Range.Bookmarks["CIn"];
  22477. mark.Text = dtCheckIn.Day + " " + dtCheckIn.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckIn.Year;
  22478. }
  22479. //退房时间
  22480. if (doc.Range.Bookmarks["COut"] != null)
  22481. {
  22482. DateTime dtCheckOut = Convert.ToDateTime(hr.CheckOutDate);
  22483. Bookmark mark = doc.Range.Bookmarks["COut"];
  22484. mark.Text = dtCheckOut.Day + " " + dtCheckOut.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckOut.Year;
  22485. }
  22486. //客户名称
  22487. if (doc.Range.Bookmarks["GName"] != null)
  22488. {
  22489. string guestName = "";
  22490. string[] clients = Array.Empty<string>();
  22491. if (hr.GuestName.Contains(","))
  22492. {
  22493. clients = hr.GuestName.Split(",");
  22494. }
  22495. else
  22496. {
  22497. clients = new string[] { hr.GuestName };
  22498. }
  22499. List<int> clientIds_int = new List<int>();
  22500. if (clients.Length > 0)
  22501. {
  22502. foreach (var item in clients)
  22503. {
  22504. if (item.IsNumeric())
  22505. {
  22506. clientIds_int.Add(int.Parse(item));
  22507. }
  22508. }
  22509. }
  22510. if (clientIds_int.Count > 0)
  22511. {
  22512. var _clientDatas = _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0 && clientIds_int.Contains(it.Id)).ToList();
  22513. foreach (var client in _clientDatas)
  22514. {
  22515. //男
  22516. if (client.Sex == 0) guestName += $"Mr.";
  22517. //女
  22518. else if (client.Sex == 1) guestName += $"Ms.";
  22519. if (!String.IsNullOrEmpty(client.FirstName + client.LastName))
  22520. {
  22521. guestName += $"{string.Join("", client.FirstName.GetTotalPingYin()).ToUpper()} {string.Join("", client.LastName.GetTotalPingYin()).ToUpper()},";
  22522. }
  22523. //guestName += $"{client.Pinyin},";
  22524. }
  22525. if (guestName.Length > 0)
  22526. {
  22527. guestName = guestName.Substring(0, guestName.Length - 1);
  22528. }
  22529. }
  22530. else
  22531. {
  22532. guestName = hr.GuestName;
  22533. }
  22534. Bookmark mark = doc.Range.Bookmarks["GName"];
  22535. mark.Text = guestName;
  22536. }
  22537. //房间介绍
  22538. if (doc.Range.Bookmarks["ROOM"] != null)
  22539. {
  22540. Bookmark mark = doc.Range.Bookmarks["ROOM"];
  22541. mark.Text = hr.RoomExplanation;
  22542. }
  22543. //报价描述
  22544. if (doc.Range.Bookmarks["NOTE"] != null)
  22545. {
  22546. Bookmark mark = doc.Range.Bookmarks["NOTE"];
  22547. Sys_SetData ss = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == hr.ReservationsWebsite);
  22548. if (ss != null)
  22549. mark.Text = ss.Name;
  22550. }
  22551. //入住时间
  22552. if (doc.Range.Bookmarks["CheckIn"] != null)
  22553. {
  22554. DateTime dtCheckIn = Convert.ToDateTime(hr.CheckInDate);
  22555. Bookmark mark = doc.Range.Bookmarks["CheckIn"];
  22556. mark.Text = dtCheckIn.Day + " " + dtCheckIn.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckIn.Year + " ";
  22557. }
  22558. //退房时间
  22559. if (doc.Range.Bookmarks["CheckOut"] != null)
  22560. {
  22561. DateTime dtCheckOut = Convert.ToDateTime(hr.CheckOutDate);
  22562. Bookmark mark = doc.Range.Bookmarks["CheckOut"];
  22563. mark.Text = " " + dtCheckOut.Day + " " + dtCheckOut.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckOut.Year;
  22564. }
  22565. //日期
  22566. if (doc.Range.Bookmarks["DT"] != null)
  22567. {
  22568. Bookmark mark = doc.Range.Bookmarks["DT"];
  22569. mark.Text = Convert.ToDateTime(hr.CreateTime).ToString("yyyy-MM-dd");
  22570. }
  22571. //名称
  22572. if (doc.Range.Bookmarks["VName"] != null)
  22573. {
  22574. Bookmark mark = doc.Range.Bookmarks["VName"];
  22575. mark.Text = hr.HotelName;
  22576. }
  22577. //号码
  22578. if (doc.Range.Bookmarks["VOUCHERNO"] != null)
  22579. {
  22580. Bookmark mark = doc.Range.Bookmarks["VOUCHERNO"];
  22581. mark.Text = hr.CheckNumber;
  22582. }
  22583. #endregion
  22584. strFileName += "VOUCHER.doc";
  22585. var fileDir = AppSettingsHelper.Get("WordBasePath") + strFileName;
  22586. doc.Save(fileDir);
  22587. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/" + strFileName;
  22588. return Ok(JsonView(true, "操作成功!", Url));
  22589. }
  22590. else
  22591. {
  22592. return Ok(JsonView(false, "酒店确定号码未填写,无法生成Voucher!"));
  22593. }
  22594. }
  22595. else
  22596. {
  22597. return Ok(JsonView(false, "该条数据已删除或不存在!"));
  22598. }
  22599. }
  22600. catch (Exception ex)
  22601. {
  22602. return Ok(JsonView(false, ex.Message));
  22603. }
  22604. }
  22605. /// <summary>
  22606. /// 酒店预订
  22607. /// 生成VOUCHER
  22608. /// 2024.05.06 之后版本
  22609. /// </summary>
  22610. /// <param name="_dto"></param>
  22611. /// <returns></returns>
  22612. [HttpPost]
  22613. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22614. public async Task<IActionResult> PostHotelReservationsCreateVoucher(HotelReservationsCreateVoucherDto _dto)
  22615. {
  22616. #region 参数验证
  22617. if (_dto.UserId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "员工Id为空", ""));
  22618. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  22619. if (_dto.DiId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组Id为空", ""));
  22620. #region 团组操作权限验证 76 酒店预定模块
  22621. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22622. if (groupAuthView.Code != 0) return Ok(JsonView(StatusCodes.Status400BadRequest, groupAuthView.Msg, ""));
  22623. #endregion
  22624. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22625. #region 页面操作权限验证
  22626. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22627. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  22628. #endregion
  22629. #endregion
  22630. List<Grp_HotelReservations> hrDtas = await _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && it.DiId == _dto.DiId).ToListAsync();
  22631. //判断数据是否完整
  22632. if (hrDtas.Count < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "请先录入酒店预订信息!", ""));
  22633. hrDtas = hrDtas.OrderBy(it => it.CheckInDate).ToList();
  22634. string strFileName = "HotelStatement/";
  22635. string guestNames = ""; //格式Mr.xxx Ms.xxx
  22636. List<HotelVoucherInfoView> vouchers = new List<HotelVoucherInfoView>();
  22637. #region 数据处理
  22638. List<int> guestIds = new List<int>();
  22639. //int index = 0;
  22640. foreach (var item in hrDtas)
  22641. {
  22642. if (item.GuestName.Contains(","))
  22643. {
  22644. string[] guestIdArr = item.GuestName.Split(',');
  22645. foreach (var guestIdStr in guestIdArr)
  22646. {
  22647. bool guestBool = int.TryParse(guestIdStr, out int guestId);
  22648. if (guestBool)
  22649. {
  22650. guestIds.Add(guestId);
  22651. }
  22652. }
  22653. }
  22654. else guestNames += item.GuestName;
  22655. var voucherInfo = new HotelVoucherInfoView()
  22656. {
  22657. HotelName = item.HotelName,
  22658. CheckInDate = item.CheckInDate,
  22659. CheckOutDate = item.CheckOutDate,
  22660. ConfirmationNumber = item.DetermineNo.Trim(),
  22661. RoomType = item.RoomExplanation
  22662. };
  22663. vouchers.Add(voucherInfo);
  22664. }
  22665. if (guestIds.Count > 0)
  22666. {
  22667. guestIds = guestIds.Distinct().ToList();
  22668. var guestDatas = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0 && guestIds.Contains(it.Id)).ToListAsync();
  22669. if (guestDatas.Count > 0)
  22670. {
  22671. guestNames = "";
  22672. foreach (var guest in guestDatas)
  22673. {
  22674. string guestName = "";
  22675. if (guest.Sex == 0) guestName += @"MR.";
  22676. else if (guest.Sex == 1) guestName += @"MS.";
  22677. if (guest.Pinyin == null) guestName += $"{string.Join("", guest.LastName.GetTotalPingYin()).ToUpper()}/{string.Join("", guest.FirstName.GetTotalPingYin()).ToUpper()}";
  22678. else guestName += @$"{guest.Pinyin.Replace(" ", "")}";
  22679. guestNames += @$"{guestName.Trim()}、";
  22680. }
  22681. if (guestNames.Length > 0)
  22682. {
  22683. guestNames = guestNames.Substring(0, guestNames.Length - 1);
  22684. }
  22685. }
  22686. }
  22687. #endregion
  22688. //载入模板
  22689. string sss = AppSettingsHelper.Get("WordBasePath") + "Template/Voucher-2024Versions.docx";
  22690. Document doc = new Document(sss);
  22691. DocumentBuilder builder = new DocumentBuilder(doc);
  22692. if (doc.Range.Bookmarks["GuestName"] != null)
  22693. {
  22694. Bookmark mark = doc.Range.Bookmarks["GuestName"];
  22695. mark.Text = guestNames;
  22696. }
  22697. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  22698. Aspose.Words.Tables.Table table = allTables[0] as Aspose.Words.Tables.Table;
  22699. vouchers = vouchers.OrderBy(it => it.CheckInDate).ToList();
  22700. for (int i = 1; i <= vouchers.Count; i++)
  22701. {
  22702. HotelVoucherInfoView hviv = vouchers[i - 1];
  22703. builder.MoveToCell(0, i, 0, 0);
  22704. builder.Write(hviv.HotelName);
  22705. builder.MoveToCell(0, i, 1, 0);
  22706. builder.Write(hviv.CheckInDate);
  22707. builder.MoveToCell(0, i, 2, 0);
  22708. builder.Write(hviv.CheckOutDate);
  22709. builder.MoveToCell(0, i, 3, 0);
  22710. builder.Write(hviv.RoomType);
  22711. builder.MoveToCell(0, i, 4, 0);
  22712. builder.Write(hviv.ConfirmationNumber);
  22713. }
  22714. //删除多余行
  22715. int currRowIndex = vouchers.Count + 1;
  22716. int delRows = 21 - currRowIndex;
  22717. if (delRows > 0)
  22718. {
  22719. for (int i = 0; i < delRows; i++)
  22720. {
  22721. table.Rows.RemoveAt(currRowIndex);
  22722. //cultivateRowIndex++;
  22723. }
  22724. }
  22725. strFileName += "VOUCHER.docx";
  22726. var fileDir = AppSettingsHelper.Get("WordBasePath") + strFileName;
  22727. doc.Save(fileDir);
  22728. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/" + strFileName;
  22729. return Ok(JsonView(true, "操作成功!", Url));
  22730. }
  22731. /// <summary>
  22732. /// 酒店预订
  22733. /// 生成VOUCHER 批量生成
  22734. /// New
  22735. /// </summary>
  22736. /// <param name="_dto"></param>
  22737. /// <returns></returns>
  22738. [HttpPost]
  22739. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22740. public async Task<IActionResult> PostHotelReservationsCreateVoucherBatchNew(HotelReservationsCreateVoucherDto _dto)
  22741. {
  22742. #region 参数验证
  22743. if (_dto.UserId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "员工Id为空", ""));
  22744. if (_dto.PageId < 1) _dto.PageId = 28;
  22745. if (_dto.DiId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组Id为空", ""));
  22746. #region 团组操作权限验证 76 酒店预定模块
  22747. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22748. if (groupAuthView.Code != 0) return Ok(JsonView(StatusCodes.Status400BadRequest, groupAuthView.Msg, ""));
  22749. #endregion
  22750. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22751. #region 页面操作权限验证
  22752. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22753. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  22754. #endregion
  22755. #endregion
  22756. var hrDtas = await _sqlSugar.Queryable<Grp_HotelReservations>()
  22757. .Where(it => it.IsDel == 0 && it.DiId == _dto.DiId)
  22758. .OrderBy(x => x.CheckInDate)
  22759. .ToListAsync();
  22760. //判断数据是否完整
  22761. if (hrDtas.Count < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "请先录入酒店预订信息!", ""));
  22762. string strFileName = "HotelStatement/";
  22763. var dele = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == _dto.DiId).FirstAsync();
  22764. if (dele != null)
  22765. strFileName += $"{dele?.TeamName ?? ""}_{dele.TourCode}_";
  22766. var guestDatas = await _sqlSugar.Queryable<Crm_DeleClient>()
  22767. .Select(x => new Crm_DeleClient { Id = x.Id, FirstName = x.FirstName, LastName = x.LastName, Pinyin = x.Pinyin })
  22768. .Where(it => it.IsDel == 0)
  22769. .ToListAsync();
  22770. foreach (var item in guestDatas) EncryptionProcessor.DecryptProperties(item);
  22771. for (int i = 0; i < hrDtas.Count; i++)
  22772. {
  22773. string guestNames = string.Empty;
  22774. List<int> guestIds = new List<int>();
  22775. var item = hrDtas[i];
  22776. //处理客户姓名
  22777. if (item.GuestName.Contains(","))
  22778. {
  22779. string[] guestIdArr = item.GuestName.Split(',');
  22780. foreach (var guestIdStr in guestIdArr)
  22781. if (int.TryParse(guestIdStr, out int guestId))
  22782. guestIds.Add(guestId);
  22783. }
  22784. else
  22785. {
  22786. bool guestIdBool = int.TryParse(item.GuestName, out int guestId);
  22787. if (guestIdBool)
  22788. {
  22789. guestIds.Add(guestId);
  22790. }
  22791. //NaN
  22792. if (item.GuestName.Contains("NaN"))
  22793. {
  22794. guestNames += item.GuestName.Replace("NaN", "").Replace(",", "");
  22795. }
  22796. }
  22797. if (guestIds.Count > 0)
  22798. {
  22799. guestIds = guestIds.Distinct().ToList();
  22800. var guestDatas1 = guestDatas.Where(it => guestIds.Contains(it.Id)).ToList();
  22801. if (guestDatas1.Count > 0)
  22802. {
  22803. guestNames = "";
  22804. foreach (var guest in guestDatas1)
  22805. {
  22806. string guestName = "";
  22807. if (guest.Sex == 0) guestName += @"MR.";
  22808. else if (guest.Sex == 1) guestName += @"MS.";
  22809. if (guest.Pinyin == null) guestName += $"{string.Join("", guest.LastName.GetTotalPingYin()).ToUpper()}/{string.Join("", guest.FirstName.GetTotalPingYin()).ToUpper()}";
  22810. else guestName += @$"{guest.Pinyin.Replace(" ", "")}";
  22811. guestNames += @$"{guestName.Trim()}、";
  22812. }
  22813. if (guestNames.Length > 0)
  22814. {
  22815. guestNames = guestNames.Substring(0, guestNames.Length - 1);
  22816. }
  22817. }
  22818. }
  22819. //if (!string.IsNullOrEmpty(guestNames))
  22820. //{
  22821. hrDtas[i].GuestName = guestNames;
  22822. //}
  22823. }
  22824. strFileName += $"VOUCHER_{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
  22825. Document doc = new Document();
  22826. DocumentBuilder builder = new DocumentBuilder(doc);
  22827. try
  22828. {
  22829. builder.MoveToDocumentStart();
  22830. foreach (var item in hrDtas)
  22831. {
  22832. //标题
  22833. builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Title;
  22834. builder.ParagraphFormat.LineSpacing = 1;
  22835. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  22836. builder.ParagraphFormat.Style.Font.Size = 9;
  22837. builder.ParagraphFormat.Style.Font.Bold = true;
  22838. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  22839. builder.Writeln(@$"ACCOMMODATION VOUCHER");
  22840. builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Title;
  22841. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  22842. builder.ParagraphFormat.LineSpacing = 1;
  22843. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  22844. builder.ParagraphFormat.Style.Font.Size = 9;
  22845. builder.ParagraphFormat.Style.Font.Bold = true;
  22846. builder.Writeln(@$"VOUCHER No:{item.CheckNumber} DATE: {item.CreateTime.ToString("yyyy-MM-dd")}");
  22847. builder.StartTable();
  22848. // 设置边框颜色
  22849. builder.CellFormat.Borders.Top.Color = System.Drawing.Color.Black;
  22850. //设置边框样式
  22851. builder.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.Dot;
  22852. //表格
  22853. #region 第一行
  22854. builder.InsertCell();
  22855. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  22856. builder.CellFormat.HorizontalMerge = CellMerge.None;
  22857. //builder.CellFormat.AllowAutoFit = false;
  22858. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  22859. builder.ParagraphFormat.Style.Font.Size = 7.5;
  22860. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  22861. builder.CellFormat.WrapText = true; //自动换行
  22862. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  22863. builder.RowFormat.AllowBreakAcrossPages = false; //文字自适应大小
  22864. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  22865. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  22866. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  22867. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  22868. builder.Write("TOUR NO:");
  22869. builder.InsertCell();
  22870. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  22871. builder.CellFormat.HorizontalMerge = CellMerge.None;
  22872. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  22873. builder.ParagraphFormat.Style.Font.Size = 7.5;
  22874. builder.ParagraphFormat.Style.Font.Bold = false;
  22875. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  22876. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  22877. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  22878. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  22879. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  22880. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  22881. builder.Write($"{dele?.TourCode ?? "-"}");
  22882. builder.InsertCell();
  22883. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  22884. builder.CellFormat.HorizontalMerge = CellMerge.None;
  22885. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  22886. builder.ParagraphFormat.Style.Font.Size = 7.5;
  22887. builder.ParagraphFormat.Style.Font.Bold = false;
  22888. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  22889. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  22890. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  22891. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  22892. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  22893. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  22894. builder.Write($"CITY:");
  22895. builder.InsertCell();
  22896. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  22897. builder.CellFormat.HorizontalMerge = CellMerge.None;
  22898. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  22899. builder.ParagraphFormat.Style.Font.Size = 7.5;
  22900. builder.ParagraphFormat.Style.Font.Bold = false;
  22901. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  22902. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  22903. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  22904. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  22905. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  22906. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  22907. builder.Write($"{item.City}");
  22908. builder.EndRow();
  22909. #endregion
  22910. #region 第二行
  22911. builder.InsertCell();
  22912. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  22913. builder.CellFormat.HorizontalMerge = CellMerge.None;
  22914. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  22915. builder.ParagraphFormat.Style.Font.Size = 7.5;
  22916. builder.ParagraphFormat.Style.Font.Bold = false;
  22917. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  22918. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  22919. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  22920. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  22921. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  22922. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  22923. builder.Write("CONFIRMATION NO:");
  22924. builder.InsertCell();
  22925. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  22926. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  22927. builder.ParagraphFormat.Style.Font.Size = 8;
  22928. builder.ParagraphFormat.Style.Font.Bold = false;
  22929. builder.CellFormat.HorizontalMerge = CellMerge.None;
  22930. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  22931. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  22932. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  22933. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  22934. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  22935. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  22936. builder.CellFormat.HorizontalMerge = CellMerge.First;
  22937. builder.Write($"{item.DetermineNo}");
  22938. builder.InsertCell();
  22939. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  22940. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  22941. builder.InsertCell();
  22942. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  22943. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  22944. builder.EndRow();
  22945. #endregion
  22946. #region 第三行
  22947. builder.InsertCell();
  22948. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  22949. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  22950. builder.ParagraphFormat.Style.Font.Size = 7.5;
  22951. builder.ParagraphFormat.Style.Font.Bold = false;
  22952. builder.CellFormat.HorizontalMerge = CellMerge.None;
  22953. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  22954. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  22955. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  22956. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  22957. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  22958. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  22959. builder.Write($"HOTEL NAME:");
  22960. builder.InsertCell();
  22961. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  22962. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  22963. builder.ParagraphFormat.Style.Font.Size = 7.5;
  22964. builder.ParagraphFormat.Style.Font.Bold = false;
  22965. builder.CellFormat.HorizontalMerge = CellMerge.None;
  22966. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  22967. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  22968. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  22969. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  22970. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  22971. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  22972. builder.CellFormat.HorizontalMerge = CellMerge.First;
  22973. builder.Write($"{item.HotelName}");
  22974. builder.InsertCell();
  22975. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  22976. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  22977. builder.InsertCell();
  22978. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  22979. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  22980. builder.EndRow();
  22981. #endregion
  22982. #region 第四行
  22983. builder.InsertCell();
  22984. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  22985. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  22986. builder.ParagraphFormat.Style.Font.Size = 7.5;
  22987. builder.ParagraphFormat.Style.Font.Bold = false;
  22988. builder.CellFormat.HorizontalMerge = CellMerge.None;
  22989. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  22990. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  22991. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  22992. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  22993. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  22994. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  22995. builder.Write($"HOTEL ADDRESS:");
  22996. builder.InsertCell();
  22997. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  22998. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  22999. builder.ParagraphFormat.Style.Font.Size = 8;
  23000. builder.ParagraphFormat.Style.Font.Bold = false;
  23001. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23002. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23003. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  23004. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23005. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23006. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23007. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23008. builder.CellFormat.HorizontalMerge = CellMerge.First;
  23009. builder.Write($"{item.HotelAddress}");
  23010. builder.InsertCell();
  23011. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23012. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23013. builder.InsertCell();
  23014. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23015. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23016. builder.EndRow();
  23017. #endregion
  23018. #region 第五行
  23019. builder.InsertCell();
  23020. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23021. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23022. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23023. builder.ParagraphFormat.Style.Font.Bold = false;
  23024. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23025. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23026. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  23027. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23028. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23029. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23030. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23031. builder.Write("TEL:");
  23032. builder.InsertCell();
  23033. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23034. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23035. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23036. builder.ParagraphFormat.Style.Font.Bold = false;
  23037. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23038. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23039. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  23040. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23041. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23042. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23043. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23044. builder.Write($"{item.HotelTel}");
  23045. builder.InsertCell();
  23046. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23047. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23048. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23049. builder.ParagraphFormat.Style.Font.Bold = false;
  23050. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23051. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23052. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  23053. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23054. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23055. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23056. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23057. builder.Write($"FAX:");
  23058. builder.InsertCell();
  23059. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23060. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23061. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23062. builder.ParagraphFormat.Style.Font.Bold = false;
  23063. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23064. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23065. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  23066. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23067. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23068. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23069. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23070. builder.Write($"{item.HotelFax}");
  23071. builder.EndRow();
  23072. #endregion
  23073. #region 第六行
  23074. builder.InsertCell();
  23075. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23076. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23077. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23078. builder.ParagraphFormat.Style.Font.Bold = false;
  23079. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23080. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23081. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  23082. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23083. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23084. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23085. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23086. builder.Write("CHECK IN:");
  23087. builder.InsertCell();
  23088. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23089. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23090. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23091. builder.ParagraphFormat.Style.Font.Bold = false;
  23092. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23093. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23094. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  23095. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23096. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23097. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23098. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23099. DateTime dtCheckIn = Convert.ToDateTime(item.CheckInDate);
  23100. string checkInStr = dtCheckIn.Day + " " + dtCheckIn.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckIn.Year + " ";
  23101. builder.Write($"{checkInStr}");
  23102. builder.InsertCell();
  23103. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23104. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23105. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23106. builder.ParagraphFormat.Style.Font.Bold = false;
  23107. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23108. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23109. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  23110. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23111. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23112. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23113. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23114. builder.Write($"CHECK OUT:");
  23115. builder.InsertCell();
  23116. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23117. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23118. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23119. builder.ParagraphFormat.Style.Font.Bold = false;
  23120. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23121. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23122. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  23123. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23124. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23125. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23126. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23127. DateTime dtCheckOut = Convert.ToDateTime(item.CheckOutDate);
  23128. string checkOutStr = dtCheckOut.Day + " " + dtCheckOut.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckOut.Year + " ";
  23129. builder.Write($"{checkOutStr}");
  23130. builder.EndRow();
  23131. #endregion
  23132. #region 第七行
  23133. builder.InsertCell();
  23134. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23135. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23136. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23137. builder.ParagraphFormat.Style.Font.Bold = false;
  23138. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23139. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23140. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  23141. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23142. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23143. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23144. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23145. builder.Write($"GUEST NAME:");
  23146. builder.InsertCell();
  23147. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23148. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23149. builder.ParagraphFormat.Style.Font.Size = 8;
  23150. builder.ParagraphFormat.Style.Font.Bold = false;
  23151. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23152. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23153. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  23154. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23155. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23156. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23157. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23158. builder.CellFormat.HorizontalMerge = CellMerge.First;
  23159. builder.Write($"{item.GuestName.Trim()}");
  23160. builder.InsertCell();
  23161. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23162. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23163. builder.InsertCell();
  23164. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23165. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23166. builder.EndRow();
  23167. #endregion
  23168. #region 第八行
  23169. builder.InsertCell();
  23170. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23171. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23172. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23173. builder.ParagraphFormat.Style.Font.Bold = false;
  23174. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23175. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23176. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  23177. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23178. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23179. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23180. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23181. builder.Write($"ROOM TYPE:");
  23182. builder.InsertCell();
  23183. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23184. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23185. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23186. builder.ParagraphFormat.Style.Font.Bold = false;
  23187. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23188. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23189. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  23190. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23191. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23192. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23193. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23194. builder.CellFormat.HorizontalMerge = CellMerge.First;
  23195. builder.Write($"{item.RoomExplanation}");
  23196. builder.InsertCell();
  23197. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23198. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23199. builder.InsertCell();
  23200. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23201. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23202. builder.EndRow();
  23203. #endregion
  23204. #region 第九行
  23205. builder.InsertCell();
  23206. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23207. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23208. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23209. builder.ParagraphFormat.Style.Font.Bold = false;
  23210. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23211. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23212. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  23213. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23214. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23215. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23216. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23217. builder.Write($"NOTE:");
  23218. builder.InsertCell();
  23219. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23220. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23221. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23222. builder.ParagraphFormat.Style.Font.Bold = false;
  23223. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23224. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23225. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  23226. builder.CellFormat.HorizontalMerge = CellMerge.First;
  23227. 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.");
  23228. builder.InsertCell();
  23229. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23230. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23231. builder.InsertCell();
  23232. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23233. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23234. builder.EndRow();
  23235. #endregion
  23236. builder.EndTable();
  23237. //换行
  23238. builder.Writeln("");
  23239. builder.Writeln("");
  23240. }
  23241. #region 获取文档中的所有表格 设置文字自适应
  23242. // 获取文档中的所有表格。
  23243. foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
  23244. {
  23245. // 遍历表格中的所有行。
  23246. foreach (Aspose.Words.Tables.Row row in table.Rows)
  23247. {
  23248. foreach (Cell cell in row.Cells)
  23249. {
  23250. Aspose.Words.Tables.CellFormat cellFormat = cell.CellFormat;
  23251. cellFormat.Width = 0;
  23252. }
  23253. }
  23254. }
  23255. #endregion
  23256. #region 设置页眉
  23257. builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
  23258. string voucherHeaderPath = $"./Images/VoucherHeader.png";
  23259. if (System.IO.File.Exists(voucherHeaderPath))
  23260. {
  23261. byte[] imageBytes = System.IO.File.ReadAllBytes(voucherHeaderPath);
  23262. //Image image = Image.FromStream(imageBytes, ImageType.Png);
  23263. //builder.InsertImage(imageBytes, RelativeHorizontalPosition.Margin, 0, RelativeVerticalPosition.Margin, 0, 81, 36, WrapType.None);
  23264. Aspose.Words.Drawing.Shape shape = builder.InsertImage(imageBytes);
  23265. // 调整图片位置
  23266. shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page; // 将图片的水平位置设置为页面
  23267. shape.RelativeVerticalPosition = RelativeVerticalPosition.TopMargin; // 将图片的垂直位置设置为页眉上边距
  23268. shape.Top = 50; // 将图片距离页眉上边缘的距离
  23269. shape.Left = 0; // 将图片距离页面左边缘的距离
  23270. shape.Width = 81; // 设置图片宽度
  23271. shape.Height = 36; // 设置图片高度
  23272. }
  23273. //靠右
  23274. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  23275. //// 设置页脚上下边距
  23276. //builder.PageSetup.HeaderDistance = 42;
  23277. // 添加页眉线
  23278. Aspose.Words.Border borderHeader = null;
  23279. try
  23280. {
  23281. borderHeader = builder.ParagraphFormat.Borders.Bottom;
  23282. }
  23283. catch (Exception e)
  23284. {
  23285. // TODO Auto-generated catch block
  23286. //e.printStackTrace();
  23287. }
  23288. borderHeader.Shadow = true;
  23289. borderHeader.DistanceFromText = 2;
  23290. borderHeader.LineStyle = Aspose.Words.LineStyle.Single;
  23291. #endregion
  23292. }
  23293. catch (Exception ex)
  23294. {
  23295. }
  23296. var fileDir = AppSettingsHelper.Get("WordBasePath") + strFileName;
  23297. doc.Save(fileDir);
  23298. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/" + strFileName;
  23299. return Ok(JsonView(true, "操作成功!", Url));
  23300. }
  23301. /// <summary>
  23302. /// 酒店预订
  23303. /// 生成 预定成本 Excel
  23304. /// </summary>
  23305. /// <param name="_dto"></param>
  23306. /// <returns></returns>
  23307. [HttpPost]
  23308. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  23309. public async Task<IActionResult> PostHotelReservationsPredictedCostFileDownload(HotelReservations_PCFD_DTO _dto)
  23310. {
  23311. #region 参数验证
  23312. var vadalitor = new HotelReservations_PCFD_DTOFoalidator();
  23313. var vadalitorRes = await vadalitor.ValidateAsync(_dto);
  23314. if (!vadalitorRes.IsValid)
  23315. {
  23316. var errors = new StringBuilder();
  23317. foreach (var valid in vadalitorRes.Errors) errors.AppendLine(valid.ErrorMessage);
  23318. return Ok(JsonView(StatusCodes.Status400BadRequest, errors.ToString(), ""));
  23319. }
  23320. #region 团组操作权限验证 76 酒店预定模块
  23321. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  23322. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  23323. #endregion
  23324. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  23325. #region 页面操作权限验证
  23326. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  23327. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  23328. #endregion
  23329. #endregion
  23330. decimal _rate = 1.00M;
  23331. string _currency = string.Empty;
  23332. var currDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.STid == 66).ToList();
  23333. var hrDtas = _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && it.DiId == _dto.DiId).ToList();
  23334. if (hrDtas.Count < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "酒店预订费用未录入,不支持预定成本Excel导出", ""));
  23335. var hotelSubData = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => it.IsDel == 0 && it.DiId == _dto.DiId).ToList();
  23336. var ccpData = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.IsDel == 0 && it.DIId == _dto.DiId && it.CTable == 76).ToList();
  23337. var _GroupCostParameter = _sqlSugar.Queryable<Grp_GroupCostParameter>().Where(it => it.IsDel == 0 && it.DiId == _dto.DiId).First();
  23338. //if (_GroupCostParameter == null) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组成本费用未录入,不支持预定成本Excel导出", ""));
  23339. if (_GroupCostParameter == null)
  23340. {
  23341. //return Ok(JsonView(StatusCodes.Status400BadRequest, "团组成本费用“币种为录入”未录入,不支持预定成本Excel导出", ""));
  23342. bool isIntType = int.TryParse(_currency, out int currId);
  23343. if (isIntType)
  23344. {
  23345. _currency = currDatas.Find(it => it.Id == currId)?.Name ?? "";
  23346. }
  23347. var teamRate = await _teamRateRep.PostGroupTeamRateItemByDiIdAndCTableId(1, _dto.DiId, 76);
  23348. var currInfo = teamRate.Find(it => it.CurrencyCode.Equals(_currency));
  23349. if (currInfo == null)
  23350. {
  23351. //return Ok(JsonView(StatusCodes.Status400BadRequest, $"团组汇率-->酒店模块 {_currency} 币种未设置汇率,不支持预定成本Excel导出", ""));
  23352. }
  23353. else _rate = currInfo.Rate;
  23354. if (!string.IsNullOrEmpty(_currency) && !_currency.ToUpper().Equals("CNY"))
  23355. {
  23356. _rate = _GroupCostParameter.Rate;
  23357. }
  23358. hrDtas = hrDtas.OrderBy(it => it.CheckInDate).ToList();
  23359. //string strFileName = "HotelStatement/";
  23360. //string guestNames = ""; //格式Mr.xxx Ms.xxx
  23361. List<HotelReservations_PCFD_View> pcfds = new List<HotelReservations_PCFD_View>();
  23362. var rateDatas = new List<dynamic>();
  23363. #region 数据处理
  23364. foreach (var item in hrDtas)
  23365. {
  23366. var ccpInfo = ccpData.Where(it => it.DIId == _dto.DiId && it.CId == item.Id).First();
  23367. var roomInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 1).FirstOrDefault(); //房费
  23368. var breakfastInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 2).FirstOrDefault(); //早餐
  23369. var governmentRentInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 3).FirstOrDefault(); //地税
  23370. var cityTaxInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 4).FirstOrDefault(); //城市税
  23371. if (ccpInfo == null || roomInfo == null || breakfastInfo == null || governmentRentInfo == null || cityTaxInfo == null)
  23372. {
  23373. continue;
  23374. }
  23375. string roomCurr = currDatas.Find(it => it.Id == roomInfo?.Currency)?.Name ?? "";
  23376. if (string.IsNullOrEmpty(_currency)) _currency = $"CNY";
  23377. string singleRoomFeeStr = string.Empty,
  23378. doubleRoomFeeStr = string.Empty,
  23379. suiteRoomFeeStr = string.Empty,
  23380. otherRoomFeeStr = string.Empty,
  23381. payMoneyStr = string.Empty,
  23382. cardPriceStr = string.Empty;
  23383. if (roomCurr.Equals("CNY"))
  23384. {
  23385. rateDatas.Add(new { code = "CNY", rate = 1.0000 });
  23386. singleRoomFeeStr = $"{item.SingleRoomPrice.ToString("#0.00")} {roomCurr}";
  23387. doubleRoomFeeStr = $"{item.DoubleRoomPrice.ToString("#0.00")} {roomCurr}";
  23388. suiteRoomFeeStr = $"{item.SuiteRoomPrice.ToString("#0.00")} {roomCurr}";
  23389. otherRoomFeeStr = $"{item.OtherRoomPrice.ToString("#0.00")} {roomCurr}";
  23390. payMoneyStr = $"{ccpInfo.PayMoney.ToString("#0.00")} {currDatas.Find(it => it.Id == ccpInfo?.PaymentCurrency)?.Name ?? ""}";
  23391. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} {currDatas.Find(it => it.Id == item.CardPriceCurrency)?.Name ?? ""}";
  23392. }
  23393. else
  23394. {
  23395. //singleRoomFeeStr = $"{((item.SingleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.SingleRoomPrice.ToString("#0.00")} {roomCurr}";
  23396. //doubleRoomFeeStr = $"{((item.DoubleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.DoubleRoomPrice.ToString("#0.00")} {roomCurr}";
  23397. //suiteRoomFeeStr = $"{((item.SuiteRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.SuiteRoomPrice.ToString("#0.00")} {roomCurr}";
  23398. //otherRoomFeeStr = $"{((item.OtherRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.OtherRoomPrice.ToString("#0.00")} {roomCurr}";
  23399. //payMoneyStr = $"{((ccpInfo.PayMoney * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{ccpInfo.PayMoney.ToString("#0.00")} {roomCurr}";
  23400. //cardPriceStr = $"{((item.CardPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.CardPrice.ToString("#0.00")} {roomCurr}";
  23401. singleRoomFeeStr = $"{item.SingleRoomPrice.ToString("#0.00")} {roomCurr}\r\n{((item.SingleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}";
  23402. doubleRoomFeeStr = $"{item.DoubleRoomPrice.ToString("#0.00")} {roomCurr}\r\n{((item.DoubleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}";
  23403. suiteRoomFeeStr = $"{item.SuiteRoomPrice.ToString("#0.00")} {roomCurr}\r\n{((item.SuiteRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}";
  23404. otherRoomFeeStr = $"{item.OtherRoomPrice.ToString("#0.00")} {roomCurr}\r\n{((item.OtherRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}";
  23405. rateDatas.Add(new { code = roomCurr, rate = roomInfo.Rate });
  23406. var ccpPaymentCurrency = currDatas.Find(it => it.Id == ccpInfo?.PaymentCurrency)?.Name ?? "";
  23407. if (ccpPaymentCurrency.Equals("CNY"))
  23408. {
  23409. payMoneyStr = $"{ccpInfo.PayMoney.ToString("#0.00")} CNY";
  23410. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} CNY";
  23411. }
  23412. else
  23413. {
  23414. rateDatas.Add(new { code = ccpPaymentCurrency, rate = ccpInfo.DayRate });
  23415. payMoneyStr = $"{ccpInfo.PayMoney.ToString("#0.00")} {ccpPaymentCurrency}\r\n{((ccpInfo.PayMoney * ccpInfo.DayRate) / _rate).ToString("#0.00")} CNY";
  23416. }
  23417. var hotelcardPriceCurrency = currDatas.Find(it => it.Id == item?.CardPriceCurrency)?.Name ?? "";
  23418. if (hotelcardPriceCurrency.Equals("CNY"))
  23419. {
  23420. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} CNY";
  23421. }
  23422. else
  23423. {
  23424. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} {hotelcardPriceCurrency}\r\n{((item.CardPrice * roomInfo.Rate) / _rate).ToString("#0.00")} CNY";
  23425. }
  23426. }
  23427. string breakfastPriceStr = string.Empty,
  23428. breakfastCurrency = currDatas.Find(it => it.Id == item.BreakfastCurrency)?.Name ?? "",
  23429. governmentRentStr = string.Empty,
  23430. governmentRentCurrency = currDatas.Find(it => it.Id == item.GovernmentRentCurrency)?.Name ?? "",
  23431. cityTaxStr = string.Empty,
  23432. cityTaxStrCurrency = currDatas.Find(it => it.Id == item.CityTaxCurrency)?.Name ?? "";
  23433. var breakfastCurrency1 = currDatas.Find(it => it.Id == breakfastInfo?.Currency)?.Name;
  23434. if (!string.IsNullOrEmpty(breakfastCurrency1))
  23435. {
  23436. if (breakfastCurrency1.Equals("CNY"))
  23437. {
  23438. breakfastPriceStr = $"{breakfastInfo?.Price.ToString("#0.00")} {breakfastCurrency1}";
  23439. }
  23440. else
  23441. {
  23442. rateDatas.Add(new { code = breakfastCurrency1, rate = breakfastInfo.Rate });
  23443. var breakfastPriceCny = breakfastInfo.Price * breakfastInfo.Rate;
  23444. breakfastPriceStr = $"{breakfastInfo?.Price.ToString("#0.00")} {breakfastCurrency1}\r\n{breakfastPriceCny.ToString("#0.00")} CNY";
  23445. }
  23446. }
  23447. else breakfastPriceStr = $"{breakfastInfo?.Price.ToString("#0.00")} {breakfastCurrency1}";
  23448. var governmentRentCurrency1 = currDatas.Find(it => it.Id == governmentRentInfo?.Currency)?.Name;
  23449. if (!string.IsNullOrEmpty(governmentRentCurrency1))
  23450. {
  23451. if (governmentRentCurrency.Equals("CNY"))
  23452. {
  23453. governmentRentStr = $"{governmentRentInfo?.Price.ToString("#0.00")} {governmentRentCurrency1}";
  23454. }
  23455. else
  23456. {
  23457. rateDatas.Add(new { code = governmentRentCurrency1, rate = governmentRentInfo.Rate });
  23458. var governmentRentCny = governmentRentInfo.Price * governmentRentInfo.Rate;
  23459. governmentRentStr = $"{governmentRentInfo?.Price.ToString("#0.00")} {governmentRentCurrency1}\r\n{governmentRentCny.ToString("#0.00")} CNY";
  23460. }
  23461. }
  23462. else governmentRentStr = $"{governmentRentInfo?.Price.ToString("#0.00")} {governmentRentCurrency1}";
  23463. var cityTaxStrCurrency1 = currDatas.Find(it => it.Id == cityTaxInfo?.Currency)?.Name;
  23464. if (!string.IsNullOrEmpty(cityTaxStrCurrency1))
  23465. {
  23466. if (cityTaxStrCurrency1.Equals("CNY"))
  23467. {
  23468. cityTaxStr = $"{cityTaxInfo?.Price.ToString("#0.00")} {cityTaxStrCurrency1}";
  23469. }
  23470. else
  23471. {
  23472. rateDatas.Add(new { code = cityTaxStrCurrency1, rate = cityTaxInfo.Rate });
  23473. var cityTaxCny = cityTaxInfo.Price * cityTaxInfo.Rate;
  23474. cityTaxStr = $"{cityTaxInfo?.Price.ToString("#0.00")} {cityTaxStrCurrency1}\r\n{cityTaxCny.ToString("#0.00")} CNY";
  23475. }
  23476. }
  23477. else cityTaxStr = $"{cityTaxInfo?.Price.ToString("#0.00")} {cityTaxStrCurrency1}";
  23478. int payDId = roomInfo?.PayDId ?? 0;
  23479. pcfds.Add(new HotelReservations_PCFD_View()
  23480. {
  23481. City = item.City,
  23482. HotelName = item.HotelName,
  23483. Date = $"{item.CheckInDate} - {item.CheckOutDate}",
  23484. // SingleRoomCount = item.SingleRoomCount,
  23485. SingleRoomPrice = singleRoomFeeStr,
  23486. // DoubleRoomCount = item.DoubleRoomCount,
  23487. DoubleRoomPrice = doubleRoomFeeStr,
  23488. //SuiteRoomCount = item.SuiteRoomCount,
  23489. SuiteRoomPrice = suiteRoomFeeStr,
  23490. OtherRoomPrice = otherRoomFeeStr,
  23491. //OtherRoomCount = item.OtherRoomCount,
  23492. BreakfastPrice = breakfastPriceStr,
  23493. GovernmentRent = governmentRentStr,
  23494. CityTax = cityTaxStr,
  23495. RoomExplanation = item.RoomExplanation,
  23496. PayTypeName = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == payDId).First()?.Name ?? "",
  23497. PayTime = roomInfo?.ConsumptionDate,
  23498. BankNo = roomInfo?.BankNo,
  23499. PayMoney = payMoneyStr,
  23500. //PayMoneys = ccpInfo.PayMoney.ToString("#0.00"),
  23501. ConsumptionPatterns = roomInfo?.ConsumptionPatterns,
  23502. CardPrice = cardPriceStr,
  23503. Remark = ccpInfo.Remark
  23504. });
  23505. }
  23506. #endregion
  23507. //载入模板
  23508. WorkbookDesigner designer = new WorkbookDesigner();
  23509. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/酒店预订成本.xls");
  23510. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == _dto.DiId).First();
  23511. var userInfo = _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == hrDtas[0].CreateUserId).First();
  23512. designer.SetDataSource("TourNo", groupInfo.TourCode);
  23513. var rateDatas1 = rateDatas.Distinct();
  23514. var rateStr = string.Empty;
  23515. foreach (var item in rateDatas1)
  23516. {
  23517. rateStr += $"{item.code} {item.rate.ToString("#0.0000")} \t\t";
  23518. }
  23519. designer.SetDataSource("TeamName", $"酒店模块汇率:{rateStr}");
  23520. designer.SetDataSource("Opertor", userInfo.CnName);
  23521. DataTable dt = CommonFun.GetDataTableFromIList<HotelReservations_PCFD_View>(pcfds);
  23522. dt.TableName = "ViewMyHotelReservations";
  23523. designer.SetDataSource(dt);
  23524. designer.Process();
  23525. string fileName = $"HotelReservation/{groupInfo.TeamName.Replace("/", "").Replace(@"\", "").Trim()}_酒店预订成本_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  23526. string serverPath = AppSettingsHelper.Get("ExcelBasePath") + fileName;
  23527. designer.Workbook.Save(serverPath);
  23528. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  23529. #region 删除指定行
  23530. bool singleDel = true, doubleDel = true, suiteDel = true, otherDel = true, zcDel = true, dsDel = true, cssDel = true, cpDel = true, remarkDel = true;
  23531. int singleIndex = dt.Columns["SingleRoomPrice"].Ordinal,
  23532. doubleIndex = dt.Columns["DoubleRoomPrice"].Ordinal,
  23533. suiteIndex = dt.Columns["SuiteRoomPrice"].Ordinal,
  23534. otherIndex = dt.Columns["OtherRoomPrice"].Ordinal,
  23535. zcIndex = dt.Columns["BreakfastPrice"].Ordinal,
  23536. dsIndex = dt.Columns["GovernmentRent"].Ordinal,
  23537. cssIndex = dt.Columns["CityTax"].Ordinal,
  23538. cpIndex = dt.Columns["ConsumptionPatterns"].Ordinal,
  23539. remarkIndex = dt.Columns["Remark"].Ordinal;
  23540. //删除指定列
  23541. foreach (DataRow item in dt.Rows)
  23542. {
  23543. string singleStr = item["SingleRoomPrice"].ToString();
  23544. bool containsDigitButNotZero1 = !singleStr.StartsWith("0") && Regex.IsMatch(singleStr, @"[1-9]");
  23545. if (containsDigitButNotZero1) singleDel = false;
  23546. singleIndex = dt.Columns["SingleRoomPrice"].Ordinal;
  23547. string doubleStr = item["DoubleRoomPrice"].ToString();
  23548. bool containsDigitButNotZero2 = !doubleStr.StartsWith("0") && Regex.IsMatch(doubleStr, @"[1-9]");
  23549. if (containsDigitButNotZero2) doubleDel = false;
  23550. string suiteStr = item["SuiteRoomPrice"].ToString();
  23551. bool containsDigitButNotZero3 = !singleStr.StartsWith("0") && Regex.IsMatch(doubleStr, @"[1-9]");
  23552. if (containsDigitButNotZero3) suiteDel = false;
  23553. string otherStr = item["OtherRoomPrice"].ToString();
  23554. bool containsDigitButNotZero4 = !otherStr.StartsWith("0") && Regex.IsMatch(otherStr, @"[1-9]");
  23555. if (containsDigitButNotZero4) otherDel = false;
  23556. string zcStr = item["BreakfastPrice"].ToString();
  23557. bool containsDigitButNotZero5 = !zcStr.StartsWith("0") && Regex.IsMatch(zcStr, @"[1-9]");
  23558. if (containsDigitButNotZero5) zcDel = false;
  23559. string dsStr = item["GovernmentRent"].ToString();
  23560. bool containsDigitButNotZero6 = !dsStr.StartsWith("0") && Regex.IsMatch(dsStr, @"[1-9]");
  23561. if (containsDigitButNotZero6) dsDel = false;
  23562. string cssStr = item["CityTax"].ToString();
  23563. bool containsDigitButNotZero7 = !cssStr.StartsWith("0") && Regex.IsMatch(cssStr, @"[1-9]");
  23564. if (containsDigitButNotZero7) cssDel = false;
  23565. string cpStr = item["ConsumptionPatterns"].ToString();
  23566. if (!string.IsNullOrEmpty(cpStr)) cpDel = false;
  23567. string remarkStr = item["Remark"].ToString();
  23568. if (!string.IsNullOrEmpty(remarkStr)) remarkDel = false;
  23569. }
  23570. DeleteColumn(serverPath, remarkIndex, remarkDel);
  23571. DeleteColumn(serverPath, cpIndex, cpDel);
  23572. DeleteColumn(serverPath, dsIndex, dsDel);
  23573. DeleteColumn(serverPath, cssIndex, cssDel);
  23574. DeleteColumn(serverPath, zcIndex, zcDel);
  23575. DeleteColumn(serverPath, otherIndex, otherDel);
  23576. DeleteColumn(serverPath, suiteIndex, suiteDel);
  23577. DeleteColumn(serverPath, doubleIndex, doubleDel);
  23578. DeleteColumn(serverPath, singleIndex, singleDel);
  23579. #endregion
  23580. //只保留第一个表格
  23581. DeleteSheet(serverPath);
  23582. return Ok(JsonView(true, "操作成功", url = rst));
  23583. }
  23584. else
  23585. {
  23586. _currency = _GroupCostParameter.Currency;
  23587. bool isIntType = int.TryParse(_currency, out int currId);
  23588. if (isIntType)
  23589. {
  23590. _currency = currDatas.Find(it => it.Id == currId)?.Name ?? "";
  23591. }
  23592. var teamRate = await _teamRateRep.PostGroupTeamRateItemByDiIdAndCTableId(1, _dto.DiId, 76);
  23593. var currInfo = teamRate.Find(it => it.CurrencyCode.Equals(_currency));
  23594. if (currInfo == null)
  23595. {
  23596. return Ok(JsonView(StatusCodes.Status400BadRequest, $"团组汇率-->酒店模块 {_currency} 币种未设置汇率,不支持预定成本Excel导出", ""));
  23597. }
  23598. if (!_currency.ToUpper().Equals("CNY"))
  23599. {
  23600. _rate = _GroupCostParameter.Rate;
  23601. }
  23602. _rate = currInfo.Rate;
  23603. hrDtas = hrDtas.OrderBy(it => it.CheckInDate).ToList();
  23604. //string strFileName = "HotelStatement/";
  23605. //string guestNames = ""; //格式Mr.xxx Ms.xxx
  23606. List<HotelReservations_PCFD_View> pcfds = new List<HotelReservations_PCFD_View>();
  23607. #region 数据处理
  23608. foreach (var item in hrDtas)
  23609. {
  23610. var ccpInfo = ccpData.Where(it => it.DIId == _dto.DiId && it.CId == item.Id).First();
  23611. var roomInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 1).FirstOrDefault(); //房费
  23612. var breakfastInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 2).FirstOrDefault(); //早餐
  23613. var governmentRentInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 3).FirstOrDefault(); //地税
  23614. var cityTaxInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 4).FirstOrDefault(); //城市税
  23615. string roomCurr = currDatas.Find(it => it.Id == roomInfo?.Currency)?.Name ?? "";
  23616. string singleRoomFeeStr = string.Empty,
  23617. doubleRoomFeeStr = string.Empty,
  23618. suiteRoomFeeStr = string.Empty,
  23619. otherRoomFeeStr = string.Empty,
  23620. payMoneyStr = string.Empty,
  23621. cardPriceStr = string.Empty;
  23622. if (roomCurr.Equals(_currency))
  23623. {
  23624. singleRoomFeeStr = $"{item.SingleRoomPrice.ToString("#0.00")} {_currency}";
  23625. doubleRoomFeeStr = $"{item.DoubleRoomPrice.ToString("#0.00")} {_currency}";
  23626. suiteRoomFeeStr = $"{item.SuiteRoomPrice.ToString("#0.00")} {_currency}";
  23627. otherRoomFeeStr = $"{item.OtherRoomPrice.ToString("#0.00")} {_currency}";
  23628. payMoneyStr = $"{ccpInfo.PayMoney.ToString("#0.00")} {_currency}";
  23629. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} {_currency}";
  23630. }
  23631. else
  23632. {
  23633. singleRoomFeeStr = $"{((item.SingleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.SingleRoomPrice.ToString("#0.00")} {roomCurr}";
  23634. doubleRoomFeeStr = $"{((item.DoubleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.DoubleRoomPrice.ToString("#0.00")} {roomCurr}";
  23635. suiteRoomFeeStr = $"{((item.SuiteRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.SuiteRoomPrice.ToString("#0.00")} {roomCurr}";
  23636. otherRoomFeeStr = $"{((item.OtherRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.OtherRoomPrice.ToString("#0.00")} {roomCurr}";
  23637. payMoneyStr = $"{((ccpInfo.PayMoney * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{ccpInfo.PayMoney.ToString("#0.00")} {roomCurr}";
  23638. cardPriceStr = $"{((item.CardPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.CardPrice.ToString("#0.00")} {roomCurr}";
  23639. }
  23640. string breakfastPriceStr = string.Empty,
  23641. breakfastCurrency = currDatas.Find(it => it.Id == item.BreakfastCurrency)?.Name ?? "",
  23642. governmentRentStr = string.Empty,
  23643. governmentRentCurrency = currDatas.Find(it => it.Id == item.GovernmentRentCurrency)?.Name ?? "",
  23644. cityTaxStrStr = string.Empty,
  23645. cityTaxStrCurrency = currDatas.Find(it => it.Id == item.CityTaxCurrency)?.Name ?? "";
  23646. breakfastPriceStr = $"{breakfastInfo?.Price.ToString("#0.00")} {currDatas.Find(it => it.Id == breakfastInfo?.Currency)?.Name}";
  23647. governmentRentStr = $"{governmentRentInfo?.Price.ToString("#0.00")} {currDatas.Find(it => it.Id == governmentRentInfo?.Currency)?.Name}";
  23648. cityTaxStrStr = $"{cityTaxInfo?.Price.ToString("#0.00")} {currDatas.Find(it => it.Id == cityTaxInfo?.Currency)?.Name}";
  23649. int payDId = roomInfo?.PayDId ?? 0;
  23650. pcfds.Add(new HotelReservations_PCFD_View()
  23651. {
  23652. City = item.City,
  23653. HotelName = item.HotelName,
  23654. Date = $"{item.CheckInDate} - {item.CheckOutDate}",
  23655. // SingleRoomCount = item.SingleRoomCount,
  23656. SingleRoomPrice = singleRoomFeeStr,
  23657. // DoubleRoomCount = item.DoubleRoomCount,
  23658. DoubleRoomPrice = doubleRoomFeeStr,
  23659. //SuiteRoomCount = item.SuiteRoomCount,
  23660. SuiteRoomPrice = suiteRoomFeeStr,
  23661. OtherRoomPrice = otherRoomFeeStr,
  23662. //OtherRoomCount = item.OtherRoomCount,
  23663. BreakfastPrice = breakfastPriceStr,
  23664. GovernmentRent = governmentRentStr,
  23665. CityTax = cityTaxStrStr,
  23666. RoomExplanation = item.RoomExplanation,
  23667. PayTypeName = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == payDId).First()?.Name ?? "",
  23668. PayTime = roomInfo?.ConsumptionDate,
  23669. BankNo = roomInfo?.BankNo,
  23670. PayMoney = payMoneyStr,
  23671. //PayMoneys = ccpInfo.PayMoney.ToString("#0.00"),
  23672. ConsumptionPatterns = roomInfo?.ConsumptionPatterns,
  23673. CardPrice = cardPriceStr,
  23674. Remark = ccpInfo.Remark
  23675. });
  23676. }
  23677. #endregion
  23678. //载入模板
  23679. WorkbookDesigner designer = new WorkbookDesigner();
  23680. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/酒店预订成本.xls");
  23681. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == _dto.DiId).First();
  23682. var userInfo = _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == hrDtas[0].CreateUserId).First();
  23683. designer.SetDataSource("TourNo", groupInfo.TourCode);
  23684. designer.SetDataSource("TeamName", $"{groupInfo.TeamName} 团组成本币种:{_currency} 团组汇率-->酒店模块汇率:{_rate.ToString("#0.0000")}");
  23685. designer.SetDataSource("Opertor", userInfo.CnName);
  23686. DataTable dt = CommonFun.GetDataTableFromIList<HotelReservations_PCFD_View>(pcfds);
  23687. dt.TableName = "ViewMyHotelReservations";
  23688. designer.SetDataSource(dt);
  23689. designer.Process();
  23690. string fileName = $"HotelReservation/{groupInfo.TeamName.Replace("/", "").Replace(@"\", "").Trim()}_酒店预订成本_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  23691. string serverPath = AppSettingsHelper.Get("ExcelBasePath") + fileName;
  23692. designer.Workbook.Save(serverPath);
  23693. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  23694. #region 删除指定行
  23695. bool singleDel = true, doubleDel = true, suiteDel = true, otherDel = true, zcDel = true, dsDel = true, cssDel = true, cpDel = true, remarkDel = true;
  23696. int singleIndex = dt.Columns["SingleRoomPrice"].Ordinal,
  23697. doubleIndex = dt.Columns["DoubleRoomPrice"].Ordinal,
  23698. suiteIndex = dt.Columns["SuiteRoomPrice"].Ordinal,
  23699. otherIndex = dt.Columns["OtherRoomPrice"].Ordinal,
  23700. zcIndex = dt.Columns["BreakfastPrice"].Ordinal,
  23701. dsIndex = dt.Columns["GovernmentRent"].Ordinal,
  23702. cssIndex = dt.Columns["CityTax"].Ordinal,
  23703. cpIndex = dt.Columns["ConsumptionPatterns"].Ordinal,
  23704. remarkIndex = dt.Columns["Remark"].Ordinal;
  23705. //删除指定列
  23706. foreach (DataRow item in dt.Rows)
  23707. {
  23708. string singleStr = item["SingleRoomPrice"].ToString();
  23709. bool containsDigitButNotZero1 = !singleStr.StartsWith("0") && Regex.IsMatch(singleStr, @"[1-9]");
  23710. if (containsDigitButNotZero1) singleDel = false;
  23711. singleIndex = dt.Columns["SingleRoomPrice"].Ordinal;
  23712. string doubleStr = item["DoubleRoomPrice"].ToString();
  23713. bool containsDigitButNotZero2 = !doubleStr.StartsWith("0") && Regex.IsMatch(doubleStr, @"[1-9]");
  23714. if (containsDigitButNotZero2) doubleDel = false;
  23715. string suiteStr = item["SuiteRoomPrice"].ToString();
  23716. bool containsDigitButNotZero3 = !singleStr.StartsWith("0") && Regex.IsMatch(doubleStr, @"[1-9]");
  23717. if (containsDigitButNotZero3) suiteDel = false;
  23718. string otherStr = item["OtherRoomPrice"].ToString();
  23719. bool containsDigitButNotZero4 = !otherStr.StartsWith("0") && Regex.IsMatch(otherStr, @"[1-9]");
  23720. if (containsDigitButNotZero4) otherDel = false;
  23721. string zcStr = item["BreakfastPrice"].ToString();
  23722. bool containsDigitButNotZero5 = !zcStr.StartsWith("0") && Regex.IsMatch(zcStr, @"[1-9]");
  23723. if (containsDigitButNotZero5) zcDel = false;
  23724. string dsStr = item["GovernmentRent"].ToString();
  23725. bool containsDigitButNotZero6 = !dsStr.StartsWith("0") && Regex.IsMatch(dsStr, @"[1-9]");
  23726. if (containsDigitButNotZero6) dsDel = false;
  23727. string cssStr = item["CityTax"].ToString();
  23728. bool containsDigitButNotZero7 = !cssStr.StartsWith("0") && Regex.IsMatch(cssStr, @"[1-9]");
  23729. if (containsDigitButNotZero7) cssDel = false;
  23730. string cpStr = item["ConsumptionPatterns"].ToString();
  23731. if (!string.IsNullOrEmpty(cpStr)) cpDel = false;
  23732. string remarkStr = item["Remark"].ToString();
  23733. if (!string.IsNullOrEmpty(remarkStr)) remarkDel = false;
  23734. }
  23735. DeleteColumn(serverPath, remarkIndex, remarkDel);
  23736. DeleteColumn(serverPath, cpIndex, cpDel);
  23737. DeleteColumn(serverPath, dsIndex, dsDel);
  23738. DeleteColumn(serverPath, cssIndex, cssDel);
  23739. DeleteColumn(serverPath, zcIndex, zcDel);
  23740. DeleteColumn(serverPath, otherIndex, otherDel);
  23741. DeleteColumn(serverPath, suiteIndex, suiteDel);
  23742. DeleteColumn(serverPath, doubleIndex, doubleDel);
  23743. DeleteColumn(serverPath, singleIndex, singleDel);
  23744. #endregion
  23745. //只保留第一个表格
  23746. DeleteSheet(serverPath);
  23747. return Ok(JsonView(true, "操作成功", url = rst));
  23748. }
  23749. //return Ok(JsonView(false));
  23750. }
  23751. /// <summary>
  23752. /// 删除指定列
  23753. /// </summary>
  23754. /// <param name="file"></param>
  23755. /// <param name="columnIndex"></param>
  23756. /// <param name="isDel"></param>
  23757. private void DeleteColumn(string file, int columnIndex, bool isDel)
  23758. {
  23759. Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(file);
  23760. //wb.Save(file);
  23761. Aspose.Cells.Worksheet sheet1 = wb.Worksheets[0];
  23762. if (sheet1 != null)
  23763. {
  23764. if (isDel)
  23765. {
  23766. Cells cells = sheet1.Cells;
  23767. cells.DeleteColumn(columnIndex);
  23768. }
  23769. }
  23770. wb.Save(file);
  23771. }
  23772. /// <summary>
  23773. /// 删除sheet
  23774. /// </summary>
  23775. /// <param name="file"></param>
  23776. private void DeleteSheet(string file)
  23777. {
  23778. Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(file);
  23779. //wb.Save(file);
  23780. List<string> sheets = new List<string>();
  23781. foreach (var item in wb.Worksheets)
  23782. {
  23783. sheets.Add(item.Name);
  23784. }
  23785. if (sheets.Count > 0)
  23786. {
  23787. sheets.RemoveAt(0);//不删除第一个sheet
  23788. foreach (var item in sheets)
  23789. {
  23790. wb.Worksheets.RemoveAt(item);
  23791. }
  23792. }
  23793. wb.Save(file);
  23794. }
  23795. /// <summary>
  23796. /// 酒店预订
  23797. /// 确认单
  23798. /// </summary>
  23799. /// <param name="_dto"></param>
  23800. /// <returns></returns>
  23801. [HttpPost]
  23802. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  23803. public async Task<IActionResult> PostHotelReservationsConfirmationSlip(HotelReservationsConfirmationSlipDto _dto)
  23804. {
  23805. try
  23806. {
  23807. #region 参数验证
  23808. if (_dto.UserId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "员工Id为空", ""));
  23809. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  23810. if (_dto.DiId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组Id为空", ""));
  23811. #region 团组操作权限验证 76 酒店预定模块
  23812. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  23813. if (groupAuthView.Code != 0) return Ok(JsonView(StatusCodes.Status400BadRequest, groupAuthView.Msg, ""));
  23814. #endregion
  23815. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  23816. #region 页面操作权限验证
  23817. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  23818. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  23819. #endregion
  23820. #endregion
  23821. //团组信息
  23822. Grp_DelegationInfo di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(a => a.Id == _dto.DiId);
  23823. //酒店数据
  23824. List<Grp_HotelReservations> listhoteldata = await _sqlSugar.Queryable<Grp_HotelReservations>().Where(a => a.DiId == _dto.DiId && a.IsDel == 0).ToListAsync();
  23825. if (listhoteldata.Count < 0)
  23826. {
  23827. return Ok(JsonView(StatusCodes.Status400BadRequest, "当前团组暂无酒店预订信息!", ""));
  23828. }
  23829. //利datatable存储
  23830. DataTable dt = new DataTable();
  23831. dt.Columns.Add("CheckInDate", typeof(string));
  23832. dt.Columns.Add("City", typeof(string));
  23833. dt.Columns.Add("Hotel", typeof(string));
  23834. dt.Columns.Add("Room", typeof(string));
  23835. for (int i = 0; i < listhoteldata.Count; i++)
  23836. {
  23837. DateTime dayStart = Convert.ToDateTime(listhoteldata[i].CheckInDate);
  23838. DateTime dayEnd = Convert.ToDateTime(listhoteldata[i].CheckOutDate);
  23839. while (dayStart < dayEnd)
  23840. {
  23841. string temp = "";
  23842. DataRow row = dt.NewRow();
  23843. row["CheckInDate"] = dayStart.ToString("yyyy-MM-dd");
  23844. row["City"] = listhoteldata[i].City;
  23845. row["Hotel"] = listhoteldata[i].HotelName;
  23846. if (listhoteldata[i].SingleRoomCount > 0)
  23847. {
  23848. temp = listhoteldata[i].SingleRoomCount + "个单间" + "\r\n";
  23849. }
  23850. if (listhoteldata[i].DoubleRoomCount > 0)
  23851. {
  23852. temp = temp + listhoteldata[i].DoubleRoomCount + "个标间" + "\r\n";
  23853. }
  23854. if (listhoteldata[i].SuiteRoomCount > 0)
  23855. {
  23856. temp = temp + listhoteldata[i].SuiteRoomCount + "个套房" + "\r\n";
  23857. }
  23858. if (listhoteldata[i].OtherRoomCount > 0)
  23859. {
  23860. temp = temp + listhoteldata[i].OtherRoomCount + "个其他房型" + "\r\n";
  23861. }
  23862. row["Room"] = temp;
  23863. dt.Rows.Add(row);
  23864. dayStart = dayStart.AddDays(1);
  23865. }
  23866. }
  23867. Dictionary<string, string> dic = new Dictionary<string, string>();
  23868. dic.Add("Dele", di.TeamName);
  23869. dic.Add("City", di.VisitCountry);
  23870. //模板路径
  23871. string tempPath = AppSettingsHelper.Get("WordBasePath") + "Template/酒店用房确认单-模板.doc";
  23872. //载入模板
  23873. Aspose.Words.Document doc = new Aspose.Words.Document(tempPath);
  23874. DocumentBuilder builder = new DocumentBuilder(doc);
  23875. foreach (var key in dic.Keys)
  23876. {
  23877. builder.MoveToBookmark(key);
  23878. builder.Write(dic[key]);
  23879. }
  23880. //获取word里所有表格
  23881. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  23882. //获取所填表格的序数
  23883. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  23884. var rowStart = tableOne.Rows[0]; //获取第1行
  23885. //循环赋值
  23886. for (int i = 0; i < dt.Rows.Count; i++)
  23887. {
  23888. builder.MoveToCell(0, i + 1, 0, 0);
  23889. builder.Write(dt.Rows[i]["CheckInDate"].ToString());
  23890. builder.MoveToCell(0, i + 1, 1, 0);
  23891. builder.Write(dt.Rows[i]["City"].ToString());
  23892. builder.MoveToCell(0, i + 1, 2, 0);
  23893. builder.Write(dt.Rows[i]["Hotel"].ToString());
  23894. builder.MoveToCell(0, i + 1, 3, 0);
  23895. builder.Write(dt.Rows[i]["Room"].ToString());
  23896. }
  23897. //删除多余行
  23898. while (tableOne.Rows.Count > dt.Rows.Count + 1)
  23899. {
  23900. tableOne.Rows.RemoveAt(dt.Rows.Count + 1);
  23901. }
  23902. string strFileName = di.TeamName + "酒店确认单.doc";
  23903. doc.Save(AppSettingsHelper.Get("WordBasePath") + "HotelStatement/" + strFileName);
  23904. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/HotelStatement/" + strFileName;
  23905. return Ok(JsonView(true, "成功", url));
  23906. }
  23907. catch (Exception ex)
  23908. {
  23909. return Ok(JsonView(StatusCodes.Status400BadRequest, ex.Message, ""));
  23910. }
  23911. }
  23912. #endregion
  23913. #region 团组状态
  23914. /// <summary>
  23915. /// 团组状态列表 Page
  23916. /// </summary>
  23917. /// <param name="dto">团组列表请求dto</param>
  23918. /// <returns></returns>
  23919. [HttpPost]
  23920. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  23921. public async Task<IActionResult> PostGroupStatusPageList(GroupStatusListDto dto)
  23922. {
  23923. if (dto == null) return Ok(JsonView(false, "请输入搜索条件!"));
  23924. if (dto.PortType == 1 || dto.PortType == 2) // web/Android
  23925. {
  23926. string sqlWhere = string.Empty;
  23927. if (dto.IsSure == 0) //未完成
  23928. {
  23929. sqlWhere += string.Format(@" And IsSure = 0");
  23930. }
  23931. else if (dto.IsSure == 1) //已完成
  23932. {
  23933. sqlWhere += string.Format(@" And IsSure = 1");
  23934. }
  23935. if (!string.IsNullOrEmpty(dto.SearchCriteria))
  23936. {
  23937. string tj = dto.SearchCriteria;
  23938. 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}%')",
  23939. tj, tj, tj, tj, tj);
  23940. }
  23941. string sql = string.Format(@"Select Row_Number,Id,SalesQuoteNo,TourCode,TeamTypeId, TeamType,
  23942. TeamLevId,TeamLev,TeamName,ClientName,ClientUnit,
  23943. VisitDate,VisitDays,VisitPNumber,JietuanOperator,IsSure,CreateTime
  23944. From (
  23945. Select row_number() over(order by gdi.VisitStartDate Desc) as Row_Number,
  23946. gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,
  23947. ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,
  23948. VisitDate,VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure,gdi.CreateTime
  23949. From Grp_DelegationInfo gdi
  23950. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  23951. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  23952. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  23953. Where gdi.IsDel = 0 {0}
  23954. ) temp ", sqlWhere);
  23955. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  23956. var _DelegationList = await _sqlSugar.SqlQueryable<GroupStatusView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);//ToPageAsync
  23957. return Ok(JsonView(true, "查询成功!", _DelegationList, total));
  23958. }
  23959. else
  23960. {
  23961. return Ok(JsonView(false, "查询失败"));
  23962. }
  23963. }
  23964. /// <summary>
  23965. /// 团组状态
  23966. /// 设置操作完成
  23967. /// </summary>
  23968. /// <param name="dto">团组列表请求dto</param>
  23969. /// <returns></returns>
  23970. [HttpPost]
  23971. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  23972. public async Task<IActionResult> PostGroupStatusSetOperationComplete(GroupStatusSetOperationCompleteDto dto)
  23973. {
  23974. if (dto == null) return Ok(JsonView(false, "请输入搜索条件!"));
  23975. Grp_DelegationInfo _DelegationInfo = new Grp_DelegationInfo()
  23976. {
  23977. Id = dto.Id,
  23978. IsSure = 1
  23979. };
  23980. var result = await _sqlSugar.Updateable(_DelegationInfo)
  23981. .UpdateColumns(it => new { it.IsSure })
  23982. .WhereColumns(it => new { it.Id })
  23983. .ExecuteCommandAsync();
  23984. if (result > 0)
  23985. {
  23986. return Ok(JsonView(true, "操作完成!"));
  23987. }
  23988. return Ok(JsonView(false, "操作失败!"));
  23989. }
  23990. #endregion
  23991. #region 保险费用录入
  23992. /// <summary>
  23993. /// 根据团组Id查询保险费用列表
  23994. /// </summary>
  23995. /// <param name="dto"></param>
  23996. /// <returns></returns>
  23997. [HttpPost]
  23998. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  23999. public async Task<IActionResult> CustomersByDiId(CustomersByDiIdDto dto)
  24000. {
  24001. Result groupData = await _customersRep.CustomersByDiId(dto);
  24002. if (groupData.Code != 0)
  24003. {
  24004. return Ok(JsonView(false, groupData.Msg));
  24005. }
  24006. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  24007. }
  24008. /// <summary>
  24009. /// 根据保险费用Id查询保险费用详细
  24010. /// </summary>
  24011. /// <param name="dto"></param>
  24012. /// <returns></returns>
  24013. [HttpPost]
  24014. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24015. public async Task<IActionResult> CustomersById(CustomersByIdDto dto)
  24016. {
  24017. try
  24018. {
  24019. Result groupData = await _customersRep.CustomersById(dto);
  24020. if (groupData.Code != 0)
  24021. {
  24022. return Ok(JsonView(false, groupData.Msg));
  24023. }
  24024. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  24025. }
  24026. catch (Exception ex)
  24027. {
  24028. return Ok(JsonView(false, ex.Message));
  24029. }
  24030. }
  24031. /// <summary>
  24032. /// 保险费用录入页面初始化绑定
  24033. /// </summary>
  24034. /// <param name="dto"></param>
  24035. /// <returns></returns>
  24036. [HttpPost]
  24037. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24038. public async Task<IActionResult> CustomersInitialize(CustomersInitializeDto dto)
  24039. {
  24040. try
  24041. {
  24042. Result groupData = await _customersRep.CustomersInitialize(dto);
  24043. if (groupData.Code != 0)
  24044. {
  24045. return Ok(JsonView(false, groupData.Msg));
  24046. }
  24047. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  24048. }
  24049. catch (Exception ex)
  24050. {
  24051. return Ok(JsonView(false, ex.Message));
  24052. }
  24053. }
  24054. /// <summary>
  24055. /// 保险费用操作(Status:1.新增,2.修改)
  24056. /// </summary>
  24057. /// <param name="dto"></param>
  24058. /// <returns></returns>
  24059. [HttpPost]
  24060. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24061. public async Task<IActionResult> OpCustomers(OpCustomersDto dto)
  24062. {
  24063. Result groupData = await _customersRep.OpCustomers(dto);
  24064. if (groupData.Code != 0)
  24065. {
  24066. return Ok(JsonView(false, groupData.Msg));
  24067. }
  24068. #region 应用推送
  24069. try
  24070. {
  24071. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  24072. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  24073. int dataId = groupData.Data.GetType().GetProperty("dataId").GetValue(groupData.Data, null);
  24074. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  24075. //自动审核
  24076. await _feeAuditRep.FeeAutomaticAudit(4, dto.DiId, dataId);
  24077. //2024-10-21 新增LZ UID
  24078. var userIds = new List<int>() { 21 };
  24079. string title = $"系统通知";
  24080. var diId = dto.DiId;
  24081. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  24082. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  24083. string content = "";
  24084. if (dto.Status == 1) content = $"[新增-保险费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  24085. else if (dto.Status == 2) content = $"[更新-保险费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  24086. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  24087. PageParam_PriceAuditH5 h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "82" };
  24088. await APNsTools.iOS_PushNotifications1("051", "保险费用审核", "", content, true, "ExpenseAuditWebView", h5);
  24089. }
  24090. catch (Exception ex)
  24091. {
  24092. }
  24093. #endregion
  24094. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  24095. }
  24096. /// <summary>
  24097. /// 保险文件上传
  24098. /// </summary>
  24099. /// <param name="file"></param>
  24100. /// <returns></returns>
  24101. [HttpPost]
  24102. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24103. public async Task<IActionResult> UploadCus(IFormFile file)
  24104. {
  24105. try
  24106. {
  24107. if (file != null)
  24108. {
  24109. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  24110. //文件名称
  24111. string projectFileName = file.FileName;
  24112. //上传的文件的路径
  24113. string filePath = "";
  24114. if (!Directory.Exists(fileDir))
  24115. {
  24116. Directory.CreateDirectory(fileDir);
  24117. }
  24118. //上传的文件的路径
  24119. filePath = fileDir + $@"\保险费用文件上传\{projectFileName}";
  24120. using (FileStream fs = System.IO.File.Create(filePath))
  24121. {
  24122. file.CopyTo(fs);
  24123. fs.Flush();
  24124. }
  24125. return Ok(JsonView(true, "上传成功!", projectFileName));
  24126. }
  24127. else
  24128. {
  24129. return Ok(JsonView(false, "上传失败!"));
  24130. }
  24131. }
  24132. catch (Exception ex)
  24133. {
  24134. return Ok(JsonView(false, ex.Message));
  24135. }
  24136. }
  24137. /// <summary>
  24138. /// 保险删除指定文件
  24139. /// </summary>
  24140. /// <param name="dto"></param>
  24141. /// <returns></returns>
  24142. [HttpPost]
  24143. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24144. public async Task<IActionResult> DelFileCus(DelFileDto dto)
  24145. {
  24146. try
  24147. {
  24148. string filePath = "";
  24149. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  24150. // 返回与指定虚拟路径相对应的物理路径即绝对路径
  24151. //int id = 0;
  24152. filePath = fileDir + "/保险费用文件上传/" + dto.fileName;
  24153. // 删除该文件
  24154. try
  24155. {
  24156. System.IO.File.Delete(filePath);
  24157. 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()
  24158. {
  24159. Attachment = "",
  24160. }).ExecuteCommandAsync();
  24161. if (result != 0)
  24162. {
  24163. return Ok(JsonView(true, "成功!"));
  24164. }
  24165. else
  24166. {
  24167. return Ok(JsonView(false, "失败!"));
  24168. }
  24169. }
  24170. catch (Exception)
  24171. {
  24172. 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()
  24173. {
  24174. Attachment = "",
  24175. }).ExecuteCommandAsync();
  24176. if (result != 0)
  24177. {
  24178. return Ok(JsonView(true, "成功!"));
  24179. }
  24180. else
  24181. {
  24182. return Ok(JsonView(false, "失败!"));
  24183. }
  24184. }
  24185. }
  24186. catch (Exception ex)
  24187. {
  24188. return Ok(JsonView(false, "程序错误!"));
  24189. throw;
  24190. }
  24191. }
  24192. /// <summary>
  24193. /// 保险费用操作(删除)
  24194. /// </summary>
  24195. /// <param name="dto"></param>
  24196. /// <returns></returns>
  24197. [HttpPost]
  24198. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24199. public async Task<IActionResult> DelCustomers(DelBaseDto dto)
  24200. {
  24201. try
  24202. {
  24203. var res = await _customersRep.SoftDeleteByIdAsync<Grp_Customers>(dto.Id.ToString(), dto.DeleteUserId);
  24204. if (!res)
  24205. {
  24206. return Ok(JsonView(false, "删除失败"));
  24207. }
  24208. var resultC = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 82).SetColumns(a => new Grp_CreditCardPayment()
  24209. {
  24210. IsDel = 1,
  24211. DeleteUserId = dto.DeleteUserId,
  24212. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  24213. }).ExecuteCommandAsync();
  24214. return Ok(JsonView(true, "删除成功!"));
  24215. }
  24216. catch (Exception ex)
  24217. {
  24218. return Ok(JsonView(false, "程序错误!"));
  24219. throw;
  24220. }
  24221. }
  24222. #endregion
  24223. #region 接团客户名单 PageId 104
  24224. /// <summary>
  24225. /// 接团客户名单
  24226. /// 迁移数据(慎用!)
  24227. /// </summary>
  24228. /// <returns></returns>
  24229. [HttpPost]
  24230. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24231. public async Task<IActionResult> PostTourClientListChange()
  24232. {
  24233. try
  24234. {
  24235. _sqlSugar.ChangeDatabase(DBEnum.OA2014DB);
  24236. //var groupClinetData1
  24237. string sql = string.Format($"Select * From DeleClient Where Isdel = 0");
  24238. var oldOAClientList = await _sqlSugar.SqlQueryable<OA2021_DeleClient>(sql).Where(it => it.Isdel == 0).ToListAsync();
  24239. int updateCount = 0;
  24240. if (oldOAClientList.Count > 0)
  24241. {
  24242. _sqlSugar.ChangeDatabase(DBEnum.OA2023DB);
  24243. _sqlSugar.BeginTran();
  24244. var clientComInfos = _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToList();
  24245. var clientInfos = _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToList();
  24246. foreach (var item in oldOAClientList)
  24247. {
  24248. int comId = 0;
  24249. string format = "yyyy-MM-dd HH:mm:ss";
  24250. string data11 = "1990-01-01 00:00";
  24251. var data1 = IsValidDate(item.OPdate, format);
  24252. if (data1) data11 = item.OPdate;
  24253. //客户公司验证
  24254. if (!string.IsNullOrEmpty(item.Company))
  24255. {
  24256. var clientComInfo = clientComInfos.Where(it => it.CompanyFullName.Equals(item.Company)).FirstOrDefault();
  24257. if (clientComInfo == null) // add
  24258. {
  24259. var addInfo = new Crm_CustomerCompany()
  24260. {
  24261. CompanyAbbreviation = "",
  24262. CompanyFullName = item.Company,
  24263. Address = "",
  24264. PostCodes = "",
  24265. LastedOpUserId = item.OPer,
  24266. LastedOpDt = Convert.ToDateTime(data11),
  24267. CreateUserId = item.OPer,
  24268. CreateTime = Convert.ToDateTime(data11),
  24269. IsDel = 0
  24270. };
  24271. var comId1 = _sqlSugar.Insertable<Crm_CustomerCompany>(addInfo).ExecuteReturnIdentity();
  24272. if (comId1 > 0) comId = comId1;
  24273. }
  24274. else comId = clientComInfo.Id;
  24275. }
  24276. //客户人员验证
  24277. int clientId = 0;
  24278. string name = item.LastName + item.Name;
  24279. if (!string.IsNullOrEmpty(name))
  24280. {
  24281. var clientInfo = clientInfos.Where(it => (it.LastName + it.FirstName).Equals(name)).FirstOrDefault();
  24282. if (clientInfo == null)
  24283. {
  24284. DateTime? dateTime = null;
  24285. var isDt = DateTime.TryParse(item.Birthday, out DateTime birthDayDt);
  24286. if (isDt) dateTime = birthDayDt;
  24287. var addInfo1 = new Crm_DeleClient()
  24288. {
  24289. CrmCompanyId = comId,
  24290. DiId = -1,
  24291. LastName = item.LastName,
  24292. FirstName = item.Name,
  24293. OldName = "",
  24294. Pinyin = item.Pinyin,
  24295. Sex = item.Sex == "男" ? 0 : item.Sex == "女" ? 1 : -1,
  24296. Marriage = 0,
  24297. Phone = item.Phone,
  24298. Job = item.Job,
  24299. BirthDay = dateTime
  24300. };
  24301. var clientId1 = _sqlSugar.Insertable<Crm_DeleClient>(addInfo1).ExecuteReturnIdentity();
  24302. if (clientId1 > 0) clientId = clientId1;
  24303. }
  24304. else clientId = clientInfo.Id;
  24305. }
  24306. if (clientId < 1)
  24307. {
  24308. continue;
  24309. }
  24310. int airType = 0;
  24311. if (item.AirType == "超经舱") airType = 459;
  24312. else if (item.AirType == "公务舱") airType = 458;
  24313. else if (item.AirType == "经济舱") airType = 460;
  24314. else if (item.AirType == "其他") airType = 565;
  24315. else if (item.AirType == "头等舱") airType = 457;
  24316. var _TourClientListEntity = new Grp_TourClientList()
  24317. {
  24318. DiId = item.Diid,
  24319. ClientId = clientId,
  24320. CreateUserId = item.OPer,
  24321. CreateTime = Convert.ToDateTime(data11),
  24322. Remark = item.Remark,
  24323. IsDel = item.Isdel,
  24324. ShippingSpaceTypeId = airType,
  24325. ShippingSpaceSpecialNeeds = item.AirRemark,
  24326. HotelSpecialNeeds = item.RoomType
  24327. };
  24328. var _TourClientList = _sqlSugar.Insertable<Grp_TourClientList>(_TourClientListEntity).ExecuteCommand();
  24329. if (_TourClientList > 0)
  24330. {
  24331. updateCount++;
  24332. }
  24333. }
  24334. _sqlSugar.CommitTran();
  24335. }
  24336. return Ok(JsonView(true, $"更新条数:{updateCount}条"));
  24337. }
  24338. catch (Exception ex)
  24339. {
  24340. _sqlSugar.RollbackTran();
  24341. return Ok(JsonView(false, ex.Message));
  24342. }
  24343. //return Ok(JsonView(true));
  24344. }
  24345. private bool IsValidDate(string dateString, string format)
  24346. {
  24347. return DateTime.TryParseExact(dateString, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateValue);
  24348. }
  24349. /// <summary>
  24350. /// 接团客户名单
  24351. /// 根据团组Id查询List
  24352. /// </summary>
  24353. /// <param name="_dto"></param>
  24354. /// <returns></returns>
  24355. [HttpPost]
  24356. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24357. public async Task<IActionResult> PostTourClientListByDiId(TourClientListByDiIdDto _dto)
  24358. {
  24359. #region 参数验证
  24360. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId"));
  24361. if (_dto.PageId != 104) _dto.PageId = 104; //接团客户名单PageId
  24362. if (_dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId!"));
  24363. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  24364. #region 页面操作权限验证
  24365. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  24366. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  24367. #endregion
  24368. #endregion
  24369. var viewData = await _tourClientListRep._ItemByDiId(_dto.PortType, _dto.DiId);
  24370. if (viewData.Code != 0)
  24371. {
  24372. return Ok(JsonView(false, viewData.Msg));
  24373. }
  24374. return Ok(JsonView(viewData.Data));
  24375. }
  24376. /// <summary>
  24377. /// 接团客户名单
  24378. /// 基础数据 Init
  24379. /// </summary>
  24380. /// <param name="_dto"></param>
  24381. /// <returns></returns>
  24382. [HttpPost]
  24383. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24384. public async Task<IActionResult> PostTourClientListBasicDataInit(TourClientListBasicDataInitDto _dto)
  24385. {
  24386. #region 参数验证
  24387. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  24388. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  24389. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  24390. #region 页面操作权限验证
  24391. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  24392. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  24393. #endregion
  24394. #endregion
  24395. return Ok(await _tourClientListRep._BasicDataInit(_dto.PortType));
  24396. }
  24397. /// <summary>
  24398. /// 接团客户名单
  24399. /// 根据 Id查询 Details
  24400. /// </summary>
  24401. /// <param name="_dto"></param>
  24402. /// <returns></returns>
  24403. [HttpPost]
  24404. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24405. public async Task<IActionResult> PostTourClientListDetails(TourClientListDetailsDto _dto)
  24406. {
  24407. #region 参数验证
  24408. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  24409. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  24410. if (_dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数!"));
  24411. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  24412. #region 页面操作权限验证
  24413. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  24414. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  24415. #endregion
  24416. #endregion
  24417. var viewData = await _tourClientListRep._Details(_dto.PortType, _dto.Id);
  24418. if (viewData.Code != 0)
  24419. {
  24420. return Ok(JsonView(false, viewData.Msg));
  24421. }
  24422. return Ok(JsonView(viewData.Data));
  24423. }
  24424. /// <summary>
  24425. /// 接团客户名单
  24426. /// Add Or Edit
  24427. /// </summary>
  24428. /// <param name="_dto"></param>
  24429. /// <returns></returns>
  24430. [HttpPost]
  24431. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24432. public async Task<IActionResult> PostTourClientListAddOrEdit(TourClientListAddOrEditDto _dto)
  24433. {
  24434. #region 参数验证
  24435. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  24436. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  24437. if (_dto.Id < 0) return Ok(JsonView(false, "请传入有效的Id参数!"));
  24438. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  24439. #region 页面操作权限验证
  24440. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  24441. if (_dto.Id == 0) //添加
  24442. {
  24443. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
  24444. }
  24445. else if (_dto.Id >= 0) //修改
  24446. {
  24447. if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
  24448. }
  24449. #endregion
  24450. #endregion
  24451. var viewData = await _tourClientListRep._AddOrEdit(_dto);
  24452. if (viewData.Code != 0)
  24453. {
  24454. return Ok(JsonView(false, viewData.Msg));
  24455. }
  24456. return Ok(JsonView(true));
  24457. }
  24458. /// <summary>
  24459. /// 接团客户名单
  24460. /// json字符串 AddMultiple(添加多个)
  24461. /// </summary>
  24462. /// <param name="_dto"></param>
  24463. /// <returns></returns>
  24464. [HttpPost]
  24465. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24466. public async Task<IActionResult> PostTourClientListJsonFormatAddMultiple(PostTourClientListJsonFormatAddMultipleDto _dto)
  24467. {
  24468. #region 参数验证
  24469. string jsonLabel = _dto.JsonLabel;
  24470. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  24471. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  24472. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  24473. #region 页面操作权限验证
  24474. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  24475. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
  24476. #endregion
  24477. #endregion
  24478. var request = new TourClientListAddMultipleDto();
  24479. request.DiId = _dto.DiId;
  24480. request.UserId = _dto.UserId;
  24481. if (!CommonFun.IsValidJson(jsonLabel)) return Ok(JsonView(false, "JsonLabel参数不是合法的json格式!"));
  24482. if (string.IsNullOrEmpty(jsonLabel)) return Ok(JsonView(false, "JsonLabel参数值不能为空"));
  24483. List<TourClientListInfoCN> datas = JsonConvert.DeserializeObject<List<TourClientListInfoCN>>(jsonLabel);
  24484. if (!datas.Any()) return Ok(JsonView(false, "JsonLabel参数值不能为空!"));
  24485. var infos = new List<TourClientListInfo>();
  24486. foreach (var data in datas)
  24487. {
  24488. (string lastName, string firstName) = CommonFun.GetLastNameAndFirstName(data.Name);
  24489. string lastNameEn = CommonFun.ConvertToPinyin(lastName),
  24490. firstNameEn = CommonFun.ConvertToPinyin(lastName);
  24491. if (string.IsNullOrEmpty(lastNameEn) || string.IsNullOrEmpty(firstNameEn))
  24492. {
  24493. continue;
  24494. }
  24495. infos.Add(new TourClientListInfo()
  24496. {
  24497. IsAccompany = 1,
  24498. LastName = lastName,
  24499. FirstName = firstName,
  24500. Pinyin = lastNameEn + @"/" + firstNameEn,
  24501. Sex = data.Sex.Equals("男") ? 0 : data.Sex.Equals("女") ? 1 : 2,
  24502. CompanyFullName = data.CompanyFullName,
  24503. Job = data.Job
  24504. });
  24505. }
  24506. if (infos.Any())
  24507. {
  24508. var viewData = await _tourClientListRep._AddMultiple(request);
  24509. if (viewData.Code != 0)
  24510. {
  24511. return Ok(JsonView(false, viewData.Msg));
  24512. }
  24513. return Ok(JsonView(true));
  24514. }
  24515. return Ok(JsonView(false));
  24516. }
  24517. /// <summary>
  24518. /// 接团客户名单
  24519. /// AddMultiple(添加多个)
  24520. /// </summary>
  24521. /// <param name="_dto"></param>
  24522. /// <returns></returns>
  24523. [HttpPost]
  24524. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24525. public async Task<IActionResult> PostTourClientListAddMultiple(TourClientListAddMultipleDto _dto)
  24526. {
  24527. #region 参数验证
  24528. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  24529. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  24530. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  24531. #region 页面操作权限验证
  24532. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  24533. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
  24534. #endregion
  24535. #endregion
  24536. var viewData = await _tourClientListRep._AddMultiple(_dto);
  24537. if (viewData.Code != 0)
  24538. {
  24539. return Ok(JsonView(false, viewData.Msg));
  24540. }
  24541. return Ok(JsonView(true));
  24542. }
  24543. /// <summary>
  24544. /// 接团客户名单
  24545. /// Del
  24546. /// </summary>
  24547. /// <param name="_dto"></param>
  24548. /// <returns></returns>
  24549. [HttpPost]
  24550. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24551. public async Task<IActionResult> PostTourClientListDel(TourClientListDelDto _dto)
  24552. {
  24553. #region 参数验证
  24554. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  24555. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  24556. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  24557. #region 页面操作权限验证
  24558. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  24559. if (pageFunAuthView.DeleteAuth == 0) return Ok(JsonView(false, "您没有删除权限!"));
  24560. #endregion
  24561. #endregion
  24562. var viewData = await _tourClientListRep._Del(_dto.Id, _dto.UserId);
  24563. if (viewData.Code != 0)
  24564. {
  24565. return Ok(JsonView(false, viewData.Msg));
  24566. }
  24567. return Ok(JsonView(true));
  24568. }
  24569. /// <summary>
  24570. /// 接团客户名单
  24571. /// 文件下载 客户名单
  24572. /// </summary>
  24573. /// <param name="_dto"></param>
  24574. /// <returns></returns>
  24575. [HttpPost]
  24576. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24577. public async Task<IActionResult> PostTourClientListDownloadFile(PostTourClientListDownloadFile _dto)
  24578. {
  24579. #region 参数验证
  24580. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  24581. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  24582. if (_dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId参数"));
  24583. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  24584. #region 页面操作权限验证
  24585. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  24586. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  24587. #endregion
  24588. #endregion
  24589. string clientSql = string.Format(@"Select tcl.Id,tcl.DiId,temp.*,tcl.ShippingSpaceTypeId,tcl.ShippingSpaceSpecialNeeds,
  24590. tcl.HotelSpecialNeeds,tcl.MealSpecialNeeds,tcl.Remark
  24591. From Grp_TourClientList tcl
  24592. Left Join
  24593. (Select dc.Id As DcId,dc.LastName,dc.FirstName,dc.Pinyin,dc.Sex,ccom.CompanyFullName,dc.Job,
  24594. cc1.CertNo As IDCardNo,dc.Phone,dc.BirthDay,cc2.PassportType,cc2.CertNo As PassportNo,cc2.Country,
  24595. cc2.Area,cc2.IssueDt,cc2.ExpiryDt
  24596. From Crm_DeleClient dc
  24597. Left Join Crm_CustomerCompany ccom On dc.CrmCompanyId = ccom.Id And ccom.IsDel = 0
  24598. Left Join Crm_CustomerCert cc1 On dc.Id = cc1.DcId And cc1.SdId = 773 And cc1.IsDel = 0
  24599. Left Join Crm_CustomerCert cc2 On dc.Id = cc2.DcId And cc2.SdId = 774 And cc2.IsDel = 0
  24600. Where dc.IsDel = 0) temp
  24601. On temp.DcId =tcl.ClientId
  24602. Where tcl.IsDel = 0 And tcl.DiId = {0}", _dto.DiId);
  24603. List<TourClientListDetailsView> DcList = await _sqlSugar.SqlQueryable<TourClientListDetailsView>(clientSql).ToListAsync();
  24604. if (DcList.Count < 0) return Ok(JsonView(false, "该团未录入客户名单!"));
  24605. //载入模板
  24606. string tempPath = AppSettingsHelper.Get("WordBasePath") + "Template/dwon_团组人员列表模板.doc";
  24607. if (_dto.Language == 1)
  24608. {
  24609. tempPath = AppSettingsHelper.Get("WordBasePath") + "Template/EN_Down_团组人员列表模板.doc";
  24610. }
  24611. //载入模板
  24612. var doc = new Document(tempPath);
  24613. DocumentBuilder builder = new DocumentBuilder(doc);
  24614. //获取word里所有表格
  24615. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  24616. //获取所填表格的序数
  24617. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  24618. var rowStart = tableOne.Rows[0]; //获取第1行
  24619. if (_dto.Language == 0)
  24620. {
  24621. //循环赋值
  24622. for (int i = 0; i < DcList.Count; i++)
  24623. {
  24624. EncryptionProcessor.DecryptProperties(DcList[i]);
  24625. builder.MoveToCell(0, i + 1, 0, 0);
  24626. builder.Write(DcList[i].LastName + DcList[i].FirstName);
  24627. builder.MoveToCell(0, i + 1, 1, 0);
  24628. int sex = DcList[i].Sex;
  24629. string sexStr = string.Empty;
  24630. if (sex == 0) sexStr = "男";
  24631. else if (sex == 1) sexStr = "女";
  24632. else sexStr = "未设置";
  24633. builder.Write(sexStr);
  24634. builder.MoveToCell(0, i + 1, 2, 0);
  24635. string birthDay = DcList[i].BirthDay;
  24636. string birthDayStr = string.Empty;
  24637. if (!string.IsNullOrEmpty(birthDay))
  24638. {
  24639. birthDayStr = Convert.ToDateTime(birthDay).ToString("yyyy-MM-dd");
  24640. }
  24641. builder.Write(birthDayStr);
  24642. builder.MoveToCell(0, i + 1, 3, 0);
  24643. string company = "";
  24644. if (!string.IsNullOrEmpty(DcList[i].CompanyFullName))
  24645. {
  24646. company = DcList[i].CompanyFullName.ToString();
  24647. }
  24648. builder.Write(company);
  24649. builder.MoveToCell(0, i + 1, 4, 0);
  24650. builder.Write(DcList[i].Job);
  24651. }
  24652. }
  24653. else if (_dto.Language == 1)
  24654. {
  24655. List<Res_PositionEnglishComparison> listPEC = _setDataRep.Query<Res_PositionEnglishComparison>(s => s.IsDel == 0).ToList();
  24656. List<Res_CompanyEnglishComparison> listCEC = _setDataRep.Query<Res_CompanyEnglishComparison>(s => s.IsDel == 0).ToList();
  24657. List<string> transArrayStr = new List<string>();
  24658. string transStrRes1 = "";
  24659. var clientEnglishs = new List<ClientEnglishView>();
  24660. for (int i = 0; i < DcList.Count; i++)
  24661. {
  24662. var dc = DcList[i];
  24663. EncryptionProcessor.DecryptProperties(dc);
  24664. if (dc.CompanyFullName.Equals("暂无")) dc.CompanyFullName = "-";
  24665. if (dc.Job.Equals("暂无")) dc.Job = "-";
  24666. string str1 = $"{i}&{dc.CompanyFullName}&{dc.Job}";
  24667. if (DcList.Count - 1 == i) transStrRes1 += str1;
  24668. else transStrRes1 += $"{str1}|";
  24669. clientEnglishs.Add(new()
  24670. {
  24671. Id = dc.Id,
  24672. LastName = dc.LastName,
  24673. FirstName = dc.FirstName,
  24674. Pinyin = dc.Pinyin,
  24675. Sex = dc.Sex,
  24676. CompanyFullName = dc.CompanyFullName,
  24677. Job = dc.Job,
  24678. IDCardNo = dc.IDCardNo,
  24679. BirthDay = dc.BirthDay,
  24680. });
  24681. }
  24682. #region AI转英文
  24683. string jsonValue = JsonConvert.SerializeObject(clientEnglishs);
  24684. string text = @"将此JSON的中文部分全部翻译为英文,然后只给出修改后的JSON数据,不要其他任何文字";
  24685. List<SeedMessages> messages = new List<SeedMessages>()
  24686. {
  24687. new SeedMessages
  24688. {
  24689. Role = KimiRole.user,
  24690. Content = jsonValue + text
  24691. }
  24692. };
  24693. KiMiApiClient client = new KiMiApiClient();
  24694. var kimiApiResult = await client.SeedMessage(messages);
  24695. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  24696. string clients = kimiApiResult_JObject["content"].ToString();
  24697. string startStr = "```json", endStr = "```";
  24698. // 判断并清除开头部分
  24699. if (clients.StartsWith(startStr))
  24700. {
  24701. clients = clients.Remove(0, startStr.Length);
  24702. }
  24703. // 判断并清除结尾部分
  24704. if (clients.EndsWith(endStr))
  24705. {
  24706. clients = clients.Remove(clients.Length - endStr.Length);
  24707. }
  24708. var en_Json = JsonConvert.DeserializeObject<List<ClientEnglishView>>(clients);
  24709. //循环赋值
  24710. for (int i = 0; i < en_Json.Count; i++)
  24711. {
  24712. var dc = en_Json[i];
  24713. var dc1 = DcList.Find(x => x.Id == dc.Id);
  24714. string PYName = dc.FirstName + " " + dc.LastName;
  24715. builder.MoveToCell(0, i + 1, 0, 0);
  24716. builder.Write(PYName);
  24717. string sex = dc.Sex == 0 ? "Male" : dc.Sex == 1 ? "Female" : "";
  24718. builder.MoveToCell(0, i + 1, 1, 0);
  24719. builder.Write(sex);
  24720. DateTime birthDt;
  24721. bool b_birth = DateTime.TryParse(dc.BirthDay, out birthDt);
  24722. string birthday = b_birth ? birthDt.ToString("yyyy-MM-dd") : " ";
  24723. builder.MoveToCell(0, i + 1, 2, 0);
  24724. builder.Write(birthday);
  24725. string company = string.Empty, job = string.Empty;
  24726. company = dc.CompanyFullName;
  24727. job = dc.Job;
  24728. if (dc1 != null && !string.IsNullOrEmpty(dc1.CompanyFullName))
  24729. {
  24730. //查询对照表
  24731. Res_CompanyEnglishComparison tempCec = listCEC.FirstOrDefault(s => s.zhName.Contains(dc1.CompanyFullName.ToString().Trim()));
  24732. if (tempCec != null)
  24733. {
  24734. company = tempCec.enName;
  24735. }
  24736. }
  24737. builder.MoveToCell(0, i + 1, 3, 0);
  24738. builder.Write(company);
  24739. if (dc1 != null && !string.IsNullOrEmpty(dc1.Job))
  24740. {
  24741. //查询对照表
  24742. Res_PositionEnglishComparison tempPec = listPEC.FirstOrDefault(s => s.zhName == dc1.Job.ToString().Trim());
  24743. if (tempPec != null)
  24744. {
  24745. job = tempPec.enName;
  24746. }
  24747. }
  24748. builder.MoveToCell(0, i + 1, 4, 0);
  24749. builder.Write(job);
  24750. }
  24751. #endregion
  24752. #region 旧翻译英文处理
  24753. ////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";
  24754. //string transStrRes = "";
  24755. //if (transStrRes1.Length > 0)
  24756. //{
  24757. // transStrRes = await _juHeApi.GetTextTranslateAsync(transStrRes1);
  24758. //}
  24759. ////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
  24760. ////await _juHeApi.GetTextTranslateAsync(DcList[i].CompanyFullName.ToString().Trim()) ?? "";
  24761. ////List<string> transArray = new List<string> { };
  24762. //List<TranslateInfo> transArray = new List<TranslateInfo>();
  24763. //if (transStrRes.Contains("|"))
  24764. //{
  24765. // string[] transArray1 = transStrRes.Split('|');
  24766. // if (transArray1.Length > 0)
  24767. // {
  24768. // foreach (var item in transArray1)
  24769. // {
  24770. // if (item.Contains("&"))
  24771. // {
  24772. // string[] transArray2 = item.Split('&');
  24773. // int index = 0;
  24774. // string companyName = "", job = "";
  24775. // if (transArray2.Length > 0)
  24776. // {
  24777. // bool success = int.TryParse(transArray2[0].Trim(), out index);
  24778. // if (1 < transArray2.Length) companyName = transArray2[1];
  24779. // if (2 < transArray2.Length) job = transArray2[2];
  24780. // }
  24781. // transArray.Add(new TranslateInfo { Index = index, CompanyName = companyName, Job = job });
  24782. // }
  24783. // }
  24784. // }
  24785. //}
  24786. ////循环赋值
  24787. //for (int i = 0; i < DcList.Count; i++)
  24788. //{
  24789. // string PYName = "";
  24790. // if (DcList[i].Pinyin.Length > 0 && DcList[i].Pinyin.IndexOf('/') > -1)
  24791. // {
  24792. // string PY_Last = DcList[i].Pinyin.Split('/')[0];
  24793. // string PY_First = DcList[i].Pinyin.Split('/')[1];
  24794. // PYName = PY_First + " " + PY_Last;
  24795. // }
  24796. // else
  24797. // {
  24798. // string PY_Last = DcList[i].LastName.GetTotalPingYin().Count > 0 ? DcList[i].LastName.GetTotalPingYin()[0].ToUpper() : "";
  24799. // string PY_First = DcList[i].FirstName.GetTotalPingYin().Count > 0 ? DcList[i].FirstName.GetTotalPingYin()[0].ToUpper() : "";
  24800. // PYName = PY_First + " " + PY_Last;
  24801. // }
  24802. // builder.MoveToCell(0, i + 1, 0, 0);
  24803. // builder.Write(PYName);
  24804. // string sex = DcList[i].Sex == 0 ? "Male" : DcList[i].Sex == 1 ? "Female" : "";
  24805. // builder.MoveToCell(0, i + 1, 1, 0);
  24806. // builder.Write(sex);
  24807. // DateTime birthDt;
  24808. // bool b_birth = DateTime.TryParse(DcList[i].BirthDay, out birthDt);
  24809. // string birthday = b_birth ? birthDt.ToString("yyyy-MM-dd") : " ";
  24810. // builder.MoveToCell(0, i + 1, 2, 0);
  24811. // builder.Write(birthday);
  24812. // string company = string.Empty, job = string.Empty;
  24813. // var dcTransInfo = transArray.FirstOrDefault(s => s.Index == i);
  24814. // if (dcTransInfo != null)
  24815. // {
  24816. // company = dcTransInfo.CompanyName;
  24817. // job = dcTransInfo.Job;
  24818. // }
  24819. // if (!string.IsNullOrEmpty(DcList[i].CompanyFullName))
  24820. // {
  24821. // //查询对照表
  24822. // Res_CompanyEnglishComparison tempCec = listCEC.FirstOrDefault(s => s.zhName.Contains(DcList[i].CompanyFullName.ToString().Trim()));
  24823. // if (tempCec != null)
  24824. // {
  24825. // company = tempCec.enName;
  24826. // }
  24827. // //翻译
  24828. // else
  24829. // {
  24830. // }
  24831. // }
  24832. // builder.MoveToCell(0, i + 1, 3, 0);
  24833. // builder.Write(company);
  24834. // if (!string.IsNullOrEmpty(DcList[i].Job.ToString()))
  24835. // {
  24836. // //查询对照表
  24837. // Res_PositionEnglishComparison tempPec = listPEC.FirstOrDefault(s => s.zhName == DcList[i].Job.ToString().Trim());
  24838. // if (tempPec != null)
  24839. // {
  24840. // job = tempPec.enName;
  24841. // }
  24842. // //翻译
  24843. // else
  24844. // {
  24845. // }
  24846. // }
  24847. // builder.MoveToCell(0, i + 1, 4, 0);
  24848. // builder.Write(job);
  24849. //}
  24850. #endregion
  24851. }
  24852. //删除多余行
  24853. while (tableOne.Rows.Count > DcList.Count + 1)
  24854. {
  24855. tableOne.Rows.RemoveAt(DcList.Count + 1);
  24856. }
  24857. string fileName = "组团人员名单(" + DateTime.Now.ToString("yyyyhhddHHmmss") + ").doc";
  24858. var fileDir = AppSettingsHelper.Get("WordBasePath") + "TourClientList/" + fileName;
  24859. doc.Save(fileDir);
  24860. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/TourClientList/" + fileName;
  24861. return Ok(JsonView(true, "操作成功!", Url));
  24862. }
  24863. private class TranslateInfo
  24864. {
  24865. public int Index { get; set; }
  24866. public string CompanyName { get; set; }
  24867. public string Job { get; set; }
  24868. }
  24869. [HttpPost]
  24870. public async Task<IActionResult> FileReadClient(List<IFormFile> files)
  24871. {
  24872. if (files.Count == 0)
  24873. {
  24874. return Ok(JsonView(false, "文件为空"));
  24875. }
  24876. KiMiApiClient KiMiApi = new KiMiApiClient();
  24877. var seedConter = await KiMiApi.UploadFilesAsync(files);
  24878. if (seedConter.Count == 0)
  24879. {
  24880. return Ok(JsonView(false, "上传结果为空!"));
  24881. }
  24882. var messages = new List<SeedMessages>
  24883. {
  24884. new SeedMessages { Role = KimiRole.system, Content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一切涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。" },
  24885. new SeedMessages { Role = KimiRole.user, Content = "根据文件内容 ,按照“姓、名、姓名拼音、性别、单位、职务、出生日期”的json格式来排列整理(性别和出生日期通过身份证来识别 , 当识别到性别为男时值给0女给1 未识别到性别的情况下值给-1,出生日期按照yyyy-MM-dd来整理(若出生日期没有值则为‘-’),文件存在拼音的情况读取对应的拼音不存在则设置拼音为中文名字全拼),只输出JSON数组数据 从'['开始 到']'结尾 ,不要除JSON数据外的任何文字以及符号" }
  24886. };
  24887. messages.InsertRange(1, seedConter);
  24888. var kimiApiResult = await KiMiApi.SeedMessage(messages);
  24889. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  24890. string clients = kimiApiResult_JObject["content"].ToString();
  24891. string startStr = "```json", endStr = "```";
  24892. // 判断并清除开头部分
  24893. if (clients.StartsWith(startStr))
  24894. {
  24895. clients = clients.Remove(0, startStr.Length);
  24896. }
  24897. // 判断并清除结尾部分
  24898. if (clients.EndsWith(endStr))
  24899. {
  24900. clients = clients.Remove(clients.Length - endStr.Length);
  24901. }
  24902. var clients_JObject = JsonConvert.DeserializeObject<List<JObject>>(clients);
  24903. Dictionary<string, string> clientFieldMap = new Dictionary<string, string>()
  24904. {
  24905. {"姓", "LastName" },
  24906. {"名", "FirstName" },
  24907. {"姓名拼音", "Pinyin" },
  24908. {"性别", "Sex" },
  24909. {"单位", "CompanyFullName" },
  24910. {"职务", "Job" },
  24911. {"出生日期", "Birthday" },
  24912. };
  24913. List<BaiduClientOCRView> crmClients = new List<BaiduClientOCRView>();
  24914. foreach (var item in clients_JObject)
  24915. {
  24916. BaiduClientOCRView cdc = new BaiduClientOCRView();
  24917. foreach (var field in clientFieldMap.Keys)
  24918. {
  24919. if (item.TryGetValue(field, out JToken value))
  24920. {
  24921. var getValue = value.ToString();
  24922. System.Type type = cdc.GetType();
  24923. PropertyInfo propertyInfo = type.GetProperty(clientFieldMap[field]);
  24924. var propertyValue = Convert.ChangeType(getValue, propertyInfo.PropertyType);
  24925. propertyInfo.SetValue(cdc, propertyValue);
  24926. }
  24927. }
  24928. crmClients.Add(cdc);
  24929. }
  24930. return Ok(JsonView(new
  24931. {
  24932. fileCount = files.Count,
  24933. UploadCount = seedConter.Count,
  24934. ApiResult = clients,
  24935. CrmClients = crmClients
  24936. }));
  24937. }
  24938. #endregion
  24939. #region 团组倒推表
  24940. /// <summary>
  24941. /// 倒推表基础数据
  24942. /// Init
  24943. /// </summary>
  24944. /// <returns></returns>
  24945. [HttpPost]
  24946. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24947. public async Task<IActionResult> PostInvertedListInit()
  24948. {
  24949. var viewData = await _invertedListRep.Init();
  24950. if (viewData.Code != 0)
  24951. {
  24952. return Ok(JsonView(false, viewData.Msg));
  24953. }
  24954. return Ok(JsonView(viewData.Data));
  24955. }
  24956. /// <summary>
  24957. /// 倒推表
  24958. /// Info
  24959. /// </summary>
  24960. /// <param name="dto"></param>
  24961. /// <returns></returns>
  24962. [HttpPost]
  24963. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24964. public async Task<IActionResult> PostInvertedListInfo(InvertedListCreateDto dto)
  24965. {
  24966. var viewData = await _invertedListRep.Info(dto.PortType, dto.DiId);
  24967. if (viewData.Code != 0)
  24968. {
  24969. return Ok(JsonView(false, viewData.Msg));
  24970. }
  24971. return Ok(JsonView(viewData.Data));
  24972. }
  24973. /// <summary>
  24974. /// 倒推表
  24975. /// Create
  24976. /// </summary>
  24977. /// <param name="dto"></param>
  24978. /// <returns></returns>
  24979. [HttpPost]
  24980. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24981. public async Task<IActionResult> PostInvertedListCreate(InvertedListCreateDto dto)
  24982. {
  24983. var viewData = await _invertedListRep.Create(dto.PortType, dto.DiId);
  24984. if (viewData.Code != 0)
  24985. {
  24986. return Ok(JsonView(false, viewData.Msg));
  24987. }
  24988. return Ok(JsonView(viewData.Data));
  24989. }
  24990. /// <summary>
  24991. /// 倒推表
  24992. /// Update
  24993. /// </summary>
  24994. /// <param name="dto"></param>
  24995. /// <returns></returns>
  24996. [HttpPost]
  24997. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24998. public async Task<IActionResult> PostInvertedListUpdate(InvertedListUpdateDto dto)
  24999. {
  25000. var viewData = await _invertedListRep.Update(dto);
  25001. if (viewData.Code != 0)
  25002. {
  25003. return Ok(JsonView(false, viewData.Msg));
  25004. }
  25005. return Ok(JsonView(viewData.Data));
  25006. }
  25007. /// <summary>
  25008. /// 倒推表
  25009. /// File Download
  25010. /// </summary>
  25011. /// <param name="dto"></param>
  25012. /// <returns></returns>
  25013. [HttpPost]
  25014. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25015. public async Task<IActionResult> PostInvertedListFileDownload(InvertedListFileDownloadDto dto)
  25016. {
  25017. var info2 = await _invertedListRep.Info(1, dto.DiId);
  25018. if (info2.Code != 0)
  25019. {
  25020. return Ok(JsonView(false, "倒推表数据未生成,请先生成倒退表数据!"));
  25021. }
  25022. var info1 = info2.Data as InvertedListInfoView;
  25023. var info = await _invertedListRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == dto.DiId).FirstAsync();
  25024. string teamName = "";
  25025. if (info != null) teamName = info.TeamName;
  25026. var tempPath = $"{AppSettingsHelper.Get("WordBasePath")}Template/倒退表模板20250121.doc";
  25027. var doc = new Document();
  25028. var builder = new DocumentBuilder(doc);
  25029. #region old insert
  25030. ////载入模板
  25031. //var tempPath = $"{AppSettingsHelper.Get("WordBasePath")}Template/倒退表模板20200617.doc";
  25032. //Document doc = new Document(tempPath);
  25033. //DocumentBuilder builder = new DocumentBuilder(doc);
  25034. //利用键值对存放数据
  25035. //Dictionary<string, string> dic = new Dictionary<string, string>();
  25036. //dic.Add("TeamName", teamName);
  25037. //dic.Add("StartTime", info1.AirportdDropOffDt.ConvertToDatetime()); //开始时间
  25038. //dic.Add("BPtime", info1.ApprovalDataDt.ConvertToDatetime());
  25039. //dic.Add("BPRemark", info1.ApprovalDataRemark);
  25040. //dic.Add("SQtime", info1.ApprovalDt.ConvertToDatetime());
  25041. //dic.Add("SQRemark", info1.ApprovalRemark);
  25042. //dic.Add("CPJtime", info1.IssueApprovalDt.ConvertToDatetime());
  25043. //dic.Add("CPJRemark", info1.IssueApprovalRemark);
  25044. ////dic.Add("HZtime", info1.ApplyPassportDt.ConvertToDatetime());
  25045. ////dic.Add("HZRemark", info1.ApplyPassportRemark);
  25046. //dic.Add("QZtime", info1.VisaInformationDt.ConvertToDatetime());
  25047. //dic.Add("QZRemark", info1.VisaInformationRemark);
  25048. //dic.Add("SQQZtime", info1.SendVisaDt.ConvertToDatetime());
  25049. //dic.Add("SQQZRemark", info1.SendVisaRemark);
  25050. //dic.Add("CQtime", info1.IssueVisaDt.ConvertToDatetime());
  25051. //dic.Add("CQRemark", info1.IssueVisaRemark);
  25052. //dic.Add("XQHtime", info1.PreTripMeetingDt.ConvertToDatetime());
  25053. //dic.Add("XQHRemark", info1.PreTripMeetingRemark);
  25054. //dic.Add("SJtime", info1.AirportdDropOffDt.ConvertToDatetime());
  25055. //dic.Add("SJRemark", info1.AirportdDropOffRemark);
  25056. //#region 填充word模板书签内容
  25057. //foreach (var key in dic.Keys)
  25058. //{
  25059. // builder.MoveToBookmark(key);
  25060. // builder.Write(dic[key]);
  25061. //}
  25062. //#endregion
  25063. #endregion
  25064. #region New Insert
  25065. string titleFont = $"仿宋",
  25066. contentFont = $"仿宋";
  25067. var fontColor = Color.FromArgb(64, 64, 64);
  25068. //设置标题 团组名称
  25069. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  25070. builder.Font.Name = titleFont;
  25071. builder.Font.Color = fontColor;
  25072. builder.Font.Size = 12;
  25073. builder.Font.Bold = true;
  25074. builder.Writeln(teamName);
  25075. //设置副标题 团组出访时间
  25076. builder.Font.Size = 12;
  25077. builder.Writeln("出发时间:" + info1.AirportdDropOffDt.ConvertToDatetime());
  25078. builder.Writeln();
  25079. var backgroundColor = Color.FromArgb(199, 199, 199);
  25080. var table = builder.StartTable();
  25081. builder.InsertCell();
  25082. builder.CellFormat.Shading.BackgroundPatternColor = backgroundColor;
  25083. builder.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.Single;
  25084. builder.CellFormat.Borders.LineWidth = 1;
  25085. builder.CellFormat.Borders.Color = Color.FromArgb(183, 183, 183);
  25086. table.FirstRow.FirstCell.CellFormat.Width = 20; // 单位为百分比
  25087. builder.RowFormat.Height = 40;
  25088. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  25089. builder.Font.Name = contentFont;
  25090. builder.Font.Size = 12;
  25091. builder.Font.Bold = true;
  25092. builder.Font.Color = fontColor;
  25093. builder.Write("时间");
  25094. builder.InsertCell();
  25095. table.FirstRow.FirstCell.CellFormat.Width = 30; // 单位为百分比
  25096. builder.Write("流程");
  25097. builder.InsertCell();
  25098. table.FirstRow.FirstCell.CellFormat.Width = 50; // 单位为百分比
  25099. builder.Write("说明");
  25100. builder.EndRow();
  25101. //报批资料准备
  25102. if (info1.IsSelectedAirportd)
  25103. {
  25104. InvertedListFileDownloadSetRow(builder, contentFont, info1.ApprovalDataDt.ConvertToDatetime(), "报批资料准备", info1.ApprovalDataRemark);
  25105. }
  25106. //报批/提供送签资料
  25107. if (info1.IsSelectedApprovalData)
  25108. {
  25109. InvertedListFileDownloadSetRow(builder, contentFont, info1.ApprovalDt.ConvertToDatetime(), "报批/提供送签资料", info1.ApprovalRemark);
  25110. }
  25111. //出批件护照办理
  25112. if (info1.IsSelectedIssueApproval)
  25113. {
  25114. InvertedListFileDownloadSetRow(builder, contentFont, info1.IssueApprovalDt.ConvertToDatetime(), "出批件\r\n护照办理", info1.IssueApprovalRemark);
  25115. }
  25116. //签证资料准备
  25117. if (info1.IsSelectedVisaInfo)
  25118. {
  25119. InvertedListFileDownloadSetRow(builder, contentFont, info1.VisaInformationDt.ConvertToDatetime(), "签证资料准备", info1.VisaInformationRemark);
  25120. }
  25121. //送签
  25122. if (info1.IsSelectedSendVisa)
  25123. {
  25124. InvertedListFileDownloadSetRow(builder, contentFont, info1.SendVisaDt.ConvertToDatetime(), "送签", info1.SendVisaRemark);
  25125. }
  25126. //出签
  25127. if (info1.IsSelectedIssueVisa)
  25128. {
  25129. InvertedListFileDownloadSetRow(builder, contentFont, info1.IssueVisaDt.ConvertToDatetime(), "出签", info1.IssueVisaRemark);
  25130. }
  25131. //机票
  25132. if (info1.IsSelectedAirTicket)
  25133. {
  25134. if (string.IsNullOrEmpty(info1.AirTicketDt)) info1.AirTicketDt = info1.IssueVisaDt;
  25135. InvertedListFileDownloadSetRow(builder, contentFont, info1.AirTicketDt.ConvertToDatetime(), "机票", info1.AirTicketRemark);
  25136. }
  25137. //酒店
  25138. if (info1.IsSelectedHotel)
  25139. {
  25140. if (string.IsNullOrEmpty(info1.HotelDt)) info1.HotelDt = info1.IssueVisaDt;
  25141. InvertedListFileDownloadSetRow(builder, contentFont, info1.HotelDt.ConvertToDatetime(), "酒店", info1.HotelRemark);
  25142. }
  25143. //开行前会
  25144. if (info1.IsSelectedPreTripMeeting)
  25145. {
  25146. InvertedListFileDownloadSetRow(builder, contentFont, info1.PreTripMeetingDt.ConvertToDatetime(), "开行前会", info1.PreTripMeetingRemark);
  25147. }
  25148. //送机
  25149. if (info1.IsSelectedAirportdDropOff)
  25150. {
  25151. InvertedListFileDownloadSetRow(builder, contentFont, info1.AirportdDropOffDt.ConvertToDatetime(), "送机", info1.AirportdDropOffRemark);
  25152. }
  25153. builder.EndTable();
  25154. //table.PreferredWidth = PreferredWidth.FromPercent(100.00);
  25155. //table.AutoFit(AutoFitBehavior.FixedColumnWidths);
  25156. for (int i = 0; i < table.Rows.Count; i++)
  25157. {
  25158. var row = table.Rows[i];
  25159. //设置宽度
  25160. row.Cells[0].CellFormat.Width = 20.00;
  25161. row.Cells[1].CellFormat.Width = 30.00;
  25162. row.Cells[2].CellFormat.Width = 50.00;
  25163. if (i != 0)
  25164. {
  25165. //边框设置
  25166. InvertedListFileDownloadSetBorders(row.Cells, 0);
  25167. InvertedListFileDownloadSetBorders(row.Cells, 1);
  25168. InvertedListFileDownloadSetBorders(row.Cells, 2);
  25169. }
  25170. }
  25171. #region 页脚插入图片
  25172. // 创建页脚
  25173. Aspose.Words.HeaderFooter footer = new Aspose.Words.HeaderFooter(doc, HeaderFooterType.FooterPrimary);
  25174. doc.FirstSection.HeadersFooters.Add(footer);
  25175. Paragraph para = new Paragraph(doc);
  25176. para.ParagraphFormat.Alignment = ParagraphAlignment.Right;
  25177. footer.AppendChild(para);
  25178. builder.MoveTo(para);
  25179. string imagePath = "./Images/FMGJ_Log.png";
  25180. builder.InsertImage(imagePath);
  25181. #endregion
  25182. #endregion
  25183. var fileDir = AppSettingsHelper.Get("WordBasePath");
  25184. string fileName = $"{teamName}团出行准备流程表{CommonFun.GUID}.doc";
  25185. string filePath = fileDir + $@"InvertedList/{fileName}";
  25186. doc.Save(filePath);
  25187. string Url = $@"{AppSettingsHelper.Get("WordBaseUrl")}Office/Word/InvertedList/{fileName}";
  25188. return Ok(JsonView(true, "操作成功!", Url));
  25189. }
  25190. /// <summary>
  25191. /// 倒推表
  25192. /// File Download
  25193. /// 客户版
  25194. /// </summary>
  25195. /// <param name="dto"></param>
  25196. /// <returns></returns>
  25197. [HttpPost]
  25198. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25199. public async Task<IActionResult> PostInvertedListClientFileDownload(InvertedListFileDownloadDto dto)
  25200. {
  25201. var info2 = await _invertedListRep.Info(1, dto.DiId);
  25202. if (info2.Code != 0)
  25203. {
  25204. return Ok(JsonView(false, "倒推表数据未生成,请先生成倒退表数据!"));
  25205. }
  25206. var info1 = info2.Data as InvertedListInfoView;
  25207. var info = await _invertedListRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == dto.DiId).FirstAsync();
  25208. string teamName = "";
  25209. if (info != null) teamName = info.TeamName;
  25210. var tempPath = $"{AppSettingsHelper.Get("WordBasePath")}Template/倒退表模板20250121.doc";
  25211. var doc = new Document();
  25212. var builder = new DocumentBuilder(doc);
  25213. #region New Insert
  25214. string titleFont = $"仿宋",
  25215. contentFont = $"仿宋";
  25216. var fontColor = Color.FromArgb(64, 64, 64);
  25217. //设置标题 团组名称
  25218. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  25219. builder.Font.Name = titleFont;
  25220. builder.Font.Color = fontColor;
  25221. builder.Font.Size = 12;
  25222. builder.Font.Bold = true;
  25223. builder.Writeln(teamName);
  25224. //设置副标题 团组出访时间
  25225. builder.Font.Size = 12;
  25226. builder.Writeln("出发时间:" + info1.AirportdDropOffDt.ConvertToDatetime());
  25227. builder.Writeln();
  25228. var backgroundColor = Color.FromArgb(199, 199, 199);
  25229. var table = builder.StartTable();
  25230. builder.InsertCell();
  25231. builder.CellFormat.Shading.BackgroundPatternColor = backgroundColor;
  25232. builder.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.Single;
  25233. builder.CellFormat.Borders.LineWidth = 1;
  25234. builder.CellFormat.Borders.Color = Color.FromArgb(183, 183, 183);
  25235. table.FirstRow.FirstCell.CellFormat.Width = 20; // 单位为百分比
  25236. builder.RowFormat.Height = 40;
  25237. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  25238. builder.Font.Name = contentFont;
  25239. builder.Font.Size = 12;
  25240. builder.Font.Bold = true;
  25241. builder.Font.Color = fontColor;
  25242. builder.Write("时间");
  25243. builder.InsertCell();
  25244. table.FirstRow.FirstCell.CellFormat.Width = 30; // 单位为百分比
  25245. builder.Write("流程");
  25246. builder.InsertCell();
  25247. table.FirstRow.FirstCell.CellFormat.Width = 50; // 单位为百分比
  25248. builder.Write("说明");
  25249. builder.EndRow();
  25250. //报批资料准备
  25251. if (info1.IsSelectedAirportd)
  25252. {
  25253. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_ApprovalDataDt.ConvertToDatetime(), "报批资料准备", info1.ApprovalDataRemark);
  25254. }
  25255. //报批/提供送签资料
  25256. if (info1.IsSelectedApprovalData)
  25257. {
  25258. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_ApprovalDt.ConvertToDatetime(), "报批/提供送签资料", info1.ApprovalRemark);
  25259. }
  25260. //出批件护照办理
  25261. if (info1.IsSelectedIssueApproval)
  25262. {
  25263. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_IssueApprovalDt.ConvertToDatetime(), "出批件\r\n护照办理", info1.IssueApprovalRemark);
  25264. }
  25265. //签证资料准备
  25266. if (info1.IsSelectedVisaInfo)
  25267. {
  25268. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_VisaInformationDt.ConvertToDatetime(), "签证资料准备", info1.VisaInformationRemark);
  25269. }
  25270. //送签
  25271. if (info1.IsSelectedSendVisa)
  25272. {
  25273. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_SendVisaDt.ConvertToDatetime(), "送签", info1.SendVisaRemark);
  25274. }
  25275. //出签
  25276. if (info1.IsSelectedIssueVisa)
  25277. {
  25278. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_IssueVisaDt.ConvertToDatetime(), "出签", info1.IssueVisaRemark);
  25279. }
  25280. //机票
  25281. if (info1.IsSelectedAirTicket)
  25282. {
  25283. if (string.IsNullOrEmpty(info1.Client_AirTicketDt)) info1.Client_AirTicketDt = info1.Client_IssueVisaDt;
  25284. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_AirTicketDt.ConvertToDatetime(), "机票", info1.AirTicketRemark);
  25285. }
  25286. //酒店
  25287. if (info1.IsSelectedHotel)
  25288. {
  25289. if (string.IsNullOrEmpty(info1.Client_HotelDt)) info1.Client_HotelDt = info1.Client_IssueVisaDt;
  25290. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_HotelDt.ConvertToDatetime(), "酒店", info1.HotelRemark);
  25291. }
  25292. //开行前会
  25293. if (info1.IsSelectedPreTripMeeting)
  25294. {
  25295. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_PreTripMeetingDt.ConvertToDatetime(), "开行前会", info1.PreTripMeetingRemark);
  25296. }
  25297. //送机
  25298. if (info1.IsSelectedAirportdDropOff)
  25299. {
  25300. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_AirportdDropOffDt.ConvertToDatetime(), "送机", info1.AirportdDropOffRemark);
  25301. }
  25302. builder.EndTable();
  25303. //table.PreferredWidth = PreferredWidth.FromPercent(100.00);
  25304. //table.AutoFit(AutoFitBehavior.FixedColumnWidths);
  25305. for (int i = 0; i < table.Rows.Count; i++)
  25306. {
  25307. var row = table.Rows[i];
  25308. //设置宽度
  25309. row.Cells[0].CellFormat.Width = 20.00;
  25310. row.Cells[1].CellFormat.Width = 30.00;
  25311. row.Cells[2].CellFormat.Width = 50.00;
  25312. if (i != 0)
  25313. {
  25314. //边框设置
  25315. InvertedListFileDownloadSetBorders(row.Cells, 0);
  25316. InvertedListFileDownloadSetBorders(row.Cells, 1);
  25317. InvertedListFileDownloadSetBorders(row.Cells, 2);
  25318. }
  25319. }
  25320. #region 页脚插入图片
  25321. // 创建页脚
  25322. Aspose.Words.HeaderFooter footer = new Aspose.Words.HeaderFooter(doc, HeaderFooterType.FooterPrimary);
  25323. doc.FirstSection.HeadersFooters.Add(footer);
  25324. Paragraph para = new Paragraph(doc);
  25325. para.ParagraphFormat.Alignment = ParagraphAlignment.Right;
  25326. footer.AppendChild(para);
  25327. builder.MoveTo(para);
  25328. string imagePath = "./Images/FMGJ_Log.png";
  25329. builder.InsertImage(imagePath);
  25330. #endregion
  25331. #endregion
  25332. var fileDir = AppSettingsHelper.Get("WordBasePath");
  25333. string fileName = $"{teamName}团出行准备流程表(客户版){CommonFun.GUID}.doc";
  25334. string filePath = fileDir + $@"InvertedList/{fileName}";
  25335. doc.Save(filePath);
  25336. string Url = $@"{AppSettingsHelper.Get("WordBaseUrl")}Office/Word/InvertedList/{fileName}";
  25337. return Ok(JsonView(true, "操作成功!", Url));
  25338. }
  25339. private void InvertedListFileDownloadSetRow(DocumentBuilder builder, string fontName, string dateTime, string content, string reamrk)
  25340. {
  25341. var fontColor = Color.FromArgb(64, 64, 64);
  25342. builder.InsertCell();
  25343. builder.CellFormat.Shading.BackgroundPatternColor = Color.Empty;
  25344. builder.RowFormat.Height = 40;
  25345. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  25346. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  25347. builder.Font.Name = fontName;
  25348. builder.Font.Size = 8;
  25349. builder.Font.Bold = true;
  25350. builder.Font.Color = fontColor;
  25351. builder.Write(dateTime);
  25352. builder.InsertCell();
  25353. builder.Font.Size = 9;
  25354. builder.Font.Bold = true;
  25355. builder.Font.Color = fontColor;
  25356. builder.Write(content);
  25357. builder.InsertCell();
  25358. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  25359. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  25360. builder.Font.Size = 9;
  25361. builder.Font.Bold = false;
  25362. builder.Font.Color = fontColor;
  25363. builder.Write(reamrk);
  25364. builder.EndRow();
  25365. }
  25366. private void InvertedListFileDownloadSetBorders(CellCollection cell, int index)
  25367. {
  25368. cell[index].CellFormat.Borders.Top.LineStyle = Aspose.Words.LineStyle.None;
  25369. cell[index].CellFormat.Borders.Bottom.LineStyle = Aspose.Words.LineStyle.None;
  25370. cell[index].CellFormat.Borders.Left.LineStyle = Aspose.Words.LineStyle.None;
  25371. cell[index].CellFormat.Borders.Right.LineStyle = Aspose.Words.LineStyle.None;
  25372. //cell[index].CellFormat.Borders.Horizontal.LineStyle = Aspose.Words.LineStyle.None;
  25373. //cell[index].CellFormat.Borders.Vertical.LineStyle = Aspose.Words.LineStyle.None;
  25374. }
  25375. #endregion
  25376. #region 会务倒推表
  25377. /// <summary>
  25378. /// 会务倒推表
  25379. /// Init
  25380. /// </summary>
  25381. /// <returns></returns>
  25382. [HttpPost]
  25383. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25384. public async Task<IActionResult> InforRetrogressTableInit()
  25385. {
  25386. var groupData = await _groupRepository.PostShareGroupInfos(1);
  25387. if (groupData.Code == 0) return Ok(JsonView(groupData.Data));
  25388. return Ok(JsonView(false, groupData.Msg));
  25389. }
  25390. /// <summary>
  25391. /// 会务倒推表
  25392. /// ExcelDownload
  25393. /// </summary>
  25394. /// <param name="dto"></param>
  25395. /// <returns></returns>
  25396. [HttpPost]
  25397. [ApiLog("InforRetrogressTable", OperationEnum.Download)]
  25398. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25399. public async Task<IActionResult> InforRetrogressTableFileDownload(InforRetrogressTableFileDownloadDto dto)
  25400. {
  25401. var validator = new InforRetrogressTableFileDownloadDtoValidator();
  25402. var validatorRes = await validator.ValidateAsync(dto);
  25403. if (!validatorRes.IsValid)
  25404. {
  25405. StringBuilder sb = new StringBuilder();
  25406. foreach (var item in validatorRes.Errors)
  25407. {
  25408. sb.AppendLine(item.ErrorMessage);
  25409. }
  25410. return Ok(JsonView(false, sb.ToString()));
  25411. }
  25412. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.GroupId);
  25413. if (groupInfo == null) return Ok(JsonView(false, $"该团组信息未填写!"));
  25414. //时间根据团组出访日期-接团录入日期的天数来判断用哪个模板
  25415. var days = groupInfo.VisitDate.Subtract(groupInfo.CreateTime).Days;
  25416. #region Excel
  25417. var tempPath = AppSettingsHelper.Get("ExcelTempPath");
  25418. var servicePath = AppSettingsHelper.Get("GrpFileBaseUrl");
  25419. var savePath = AppSettingsHelper.Get("ExcelBasePath") + "InforRetrogressTable/";
  25420. var ftpPath = AppSettingsHelper.Get("ExcelFtpPath") + "InforRetrogressTable/";
  25421. var fileNamePrefix = string.Empty;
  25422. if (days >= 30)
  25423. {
  25424. tempPath += $"会务工作倒推进度表(30天).xlsx";
  25425. fileNamePrefix = $"{groupInfo.TeamName}_会务工作倒推进度表(30天)";
  25426. }
  25427. else if (days < 30 && days > 7)
  25428. {
  25429. tempPath += $"会务工作倒推进度表(15天).xlsx";
  25430. fileNamePrefix = $"{groupInfo.TeamName}_会务工作倒推进度表(15天)";
  25431. }
  25432. else if (days <= 7)
  25433. {
  25434. tempPath += $"会务工作倒推进度表(7天).xlsx";
  25435. fileNamePrefix = $"{groupInfo.TeamName}_会务工作倒推进度表(7天)";
  25436. }
  25437. var fileName = $"{fileNamePrefix}{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx";
  25438. fileName = CommonFun.ValidFileName(fileName);
  25439. //载入模板
  25440. WorkbookDesigner designer = new WorkbookDesigner();
  25441. designer.Workbook = new Workbook(tempPath);
  25442. designer.Process();
  25443. if (!Directory.Exists(savePath))
  25444. {
  25445. Directory.CreateDirectory(savePath);
  25446. }
  25447. string serverPath = $"{savePath}{fileName}";
  25448. designer.Workbook.Save(serverPath);
  25449. string rst = $"{servicePath}{ftpPath}{fileName}";
  25450. #endregion
  25451. return Ok(JsonView(new { url = rst }));
  25452. }
  25453. #endregion
  25454. #region 三公签证费用(签证费、代办费)
  25455. /// <summary>
  25456. /// 三公签证费用(签证费、代办费)
  25457. /// List
  25458. /// </summary>
  25459. /// <returns></returns>
  25460. [HttpPost]
  25461. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25462. public async Task<IActionResult> PostVisaFeeList(VisaFeeListDto _dto)
  25463. {
  25464. return Ok(await _visaFeeInfoRep.List(_dto.PortType, _dto.DiId));
  25465. }
  25466. /// <summary>
  25467. /// 三公签证费用(签证费、代办费)
  25468. /// Add Or Update
  25469. /// </summary>
  25470. /// <returns></returns>
  25471. [HttpPost]
  25472. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25473. public async Task<IActionResult> PostVisaFeeAddAndUpdate(VisaFeeAddAndUpdateDto _dto)
  25474. {
  25475. var _view = await _visaFeeInfoRep.Update(_dto);
  25476. if (_view.Code != 0)
  25477. {
  25478. return Ok(JsonView(false, _view.Msg));
  25479. }
  25480. return Ok(JsonView(true, _view.Msg));
  25481. }
  25482. #endregion
  25483. #region 酒店询价
  25484. /// <summary>
  25485. /// 酒店询价
  25486. /// Init
  25487. /// </summary>
  25488. /// <returns></returns>
  25489. [HttpPost]
  25490. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25491. public async Task<IActionResult> PostHotelInquiryInit()
  25492. {
  25493. var res = await _hotelInquiryRep._Init();
  25494. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  25495. return Ok(JsonView(true, res.Msg, res.Data));
  25496. }
  25497. /// <summary>
  25498. /// 酒店询价
  25499. /// page Item
  25500. /// </summary>
  25501. /// <param name="_dto"></param>
  25502. /// <returns></returns>
  25503. [HttpPost]
  25504. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25505. public async Task<IActionResult> PostHotelInquiryPageItem(HotelInquiryPageItemDto _dto)
  25506. {
  25507. var res = await _hotelInquiryRep._PageItem(_dto.PageIndex, _dto.PageSize, _dto.PortType, _dto.DiId);
  25508. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  25509. var view = res.Data as PageDataViewBase;
  25510. return Ok(JsonView(true, res.Msg, view.Data, view.Total));
  25511. }
  25512. /// <summary>
  25513. /// 酒店询价
  25514. /// info
  25515. /// </summary>
  25516. /// <param name="_dto"></param>
  25517. /// <returns></returns>
  25518. [HttpPost]
  25519. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25520. public async Task<IActionResult> PostHotelInquiryInfo(HotelInquiryInfoDto _dto)
  25521. {
  25522. var res = await _hotelInquiryRep._Info(_dto.PortType, _dto.Id);
  25523. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  25524. return Ok(JsonView(true, res.Msg, res.Data));
  25525. }
  25526. /// <summary>
  25527. /// 酒店询价
  25528. /// Add Or Edit
  25529. /// </summary>
  25530. /// <param name="_dto"></param>
  25531. /// <returns></returns>
  25532. [HttpPost]
  25533. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25534. public async Task<IActionResult> PostHotelInquiryAddOrEdit(HotelInquiryAddOrEditDto _dto)
  25535. {
  25536. var res = await _hotelInquiryRep._AddOrEdit(_dto);
  25537. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  25538. return Ok(JsonView(true, res.Msg, res.Data));
  25539. }
  25540. /// <summary>
  25541. /// 酒店询价
  25542. /// Del
  25543. /// </summary>
  25544. /// <param name="_dto"></param>
  25545. /// <returns></returns>
  25546. [HttpPost]
  25547. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25548. public async Task<IActionResult> PostHotelInquiryDel(HotelInquiryDelDto _dto)
  25549. {
  25550. var res = await _hotelInquiryRep._Del(_dto.Id, _dto.DeleteUserId);
  25551. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  25552. return Ok(JsonView(true, res.Msg, res.Data));
  25553. }
  25554. #endregion
  25555. #region 下载匹配op行程单
  25556. /// <summary>
  25557. /// 匹配op行程单
  25558. /// Init
  25559. /// </summary>
  25560. /// <param name="dto">团组列表请求dto</param>
  25561. /// <returns></returns>
  25562. [HttpPost]
  25563. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25564. public async Task<IActionResult> PostMateOpGroupInit(MateOpGroupInitDto dto)
  25565. {
  25566. Stopwatch stopwatch = Stopwatch.StartNew(); // 创建并启动Stopwatch
  25567. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  25568. bool isDepStatus = await GeneralMethod.IsMarketingStaff(dto.CurrUserId);
  25569. List<Grp_DelegationInfo> groupInfos = new List<Grp_DelegationInfo>();
  25570. groupInfos = _sqlSugar.Queryable<Grp_DelegationInfo>()
  25571. .Where(it => it.IsDel == 0)
  25572. .WhereIF(isDepStatus, it => it.JietuanOperator == dto.CurrUserId)
  25573. .OrderByDescending(it => it.VisitStartDate)
  25574. .ToList();
  25575. if (groupInfos.Count < 1) return Ok(JsonView(false, "暂无和你相关的团组信息!"));
  25576. var country = groupInfos.Select(it => it.VisitCountry).ToList();
  25577. var diids = groupInfos.Select(it => it.Id).ToList();
  25578. List<string> countrys = new List<string>();
  25579. foreach (var item in country)
  25580. {
  25581. var data = _groupRepository.FormartTeamName(item);
  25582. var dataArray = _groupRepository.GroupSplitCountry(data);
  25583. if (dataArray.Count > 0) countrys.AddRange(dataArray);
  25584. }
  25585. countrys = countrys.Where(it => !string.IsNullOrEmpty(it)).Distinct().ToList();
  25586. List<string> areaArray = new List<string>(); //GetGroupCityLine
  25587. var areaItem = GeneralMethod.GetGroupCityLineItem(diids, "-");
  25588. foreach (var item in areaItem)
  25589. {
  25590. string areaStr = item.Value;
  25591. if (!string.IsNullOrEmpty(areaStr))
  25592. {
  25593. string[] str1 = areaStr.Split("-");
  25594. if (str1.Length > 0)
  25595. {
  25596. areaArray.AddRange(str1);
  25597. }
  25598. }
  25599. }
  25600. if (areaArray.Count > 0) areaArray = areaArray.Distinct().ToList();
  25601. var cityDatas = _sqlSugar.Queryable<Sys_Cities>()
  25602. .Where(it => it.IsDel == 0 && areaArray.Contains(it.Name_CN))
  25603. .Select(it => new { id = it.Id, parentId = it.CountriesId, name = it.Name_CN })
  25604. .ToList();
  25605. List<int> countriesIds = cityDatas.Select(it => it.parentId).ToList();
  25606. var countriesDatas = _sqlSugar.Queryable<Sys_Countries>()
  25607. .Where(it => countriesIds.Contains(it.Id))
  25608. .Select(it => new { it.Id, Name = it.Name_CN })
  25609. .ToList();
  25610. var teamNames = groupInfos.Where(it => !string.IsNullOrEmpty(it.TeamName))
  25611. .Select(it => it.TeamName).ToList();
  25612. stopwatch.Stop();
  25613. return Ok(JsonView(true, $"操作成功,耗时{stopwatch.ElapsedMilliseconds} ms", new { teamNames, countriesDatas, citiesDatas = cityDatas }));
  25614. }
  25615. ///// <summary>
  25616. ///// 匹配op行程单
  25617. ///// Init 查询区域数据
  25618. ///// </summary>
  25619. ///// <param name="dto">团组列表请求dto</param>
  25620. ///// <returns></returns>
  25621. //[HttpPost]
  25622. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25623. //public async Task<IActionResult> PostMateOpGroupCountryChangeData(MateOpGroupCountryChangeDataDto dto)
  25624. //{
  25625. // Stopwatch stopwatch = Stopwatch.StartNew(); // 创建并启动Stopwatch
  25626. // List<Sys_Cities> cityDatas = new List<Sys_Cities>();
  25627. // string countriesDataStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("CityDatas");//string 取
  25628. // if (string.IsNullOrEmpty(countriesDataStr))
  25629. // {
  25630. // cityDatas = await _sqlSugar.Queryable<Sys_Cities>().Where(it => it.IsDel == 0).ToListAsync();
  25631. // TimeSpan ts = DateTime.Now.AddHours(2).TimeOfDay; //设置redis 过期时间 2
  25632. // await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>("CountriesDatas", JsonConvert.SerializeObject(cityDatas), ts);//string 存
  25633. // }
  25634. // else
  25635. // {
  25636. // cityDatas = JsonConvert.DeserializeObject<List<Sys_Cities>>(countriesDataStr);
  25637. // }
  25638. // var provinceData = cityDatas.Where(it => it.CountriesId == dto.CountriesId && it.Level == 1).ToList();
  25639. // var citiesData = cityDatas.Where(it => it.CountriesId == dto.CountriesId && it.Level == 2).ToList();
  25640. // var countiesData = cityDatas.Where(it => it.CountriesId == dto.CountriesId && it.Level == 3).ToList();
  25641. // List<dynamic> childList = new List<dynamic>();
  25642. // int parentId = dto.CountriesId;
  25643. // if (provinceData.Count > 1)
  25644. // {
  25645. // foreach (var item1 in provinceData)
  25646. // {
  25647. // List<dynamic> childList1 = new List<dynamic>();
  25648. // var citiesData1 = citiesData.Where(it => it.ParentId == item1.Id).ToList();
  25649. // foreach (var item2 in citiesData1)
  25650. // {
  25651. // List<dynamic> childList2 = new List<dynamic>();
  25652. // var countiesData1 = countiesData.Where(it => it.ParentId == item2.Id).ToList();
  25653. // foreach (var item3 in countiesData1)
  25654. // {
  25655. // childList2.Add(new
  25656. // {
  25657. // id = item3.Id,
  25658. // parentId = item2.Id,
  25659. // level = "district",
  25660. // name = item3.Name_CN,
  25661. // });
  25662. // }
  25663. // childList1.Add(new
  25664. // {
  25665. // id = item2.Id,
  25666. // parentId = item1.Id,
  25667. // level = "city",
  25668. // name = item2.Name_CN,
  25669. // childList = childList2
  25670. // });
  25671. // }
  25672. // childList.Add(new
  25673. // {
  25674. // id = item1.Id,
  25675. // parentId = parentId,
  25676. // level = "province",
  25677. // name = item1.Name_CN,
  25678. // childList = childList1
  25679. // });
  25680. // }
  25681. // //城市
  25682. // var citiesData2 = citiesData.Where(it => it.ParentId == 0).ToList();
  25683. // foreach (var item2 in citiesData2)
  25684. // {
  25685. // List<dynamic> childList22 = new List<dynamic>();
  25686. // var countiesData1 = countiesData.Where(it => it.ParentId == item2.Id).ToList();
  25687. // foreach (var item3 in countiesData1)
  25688. // {
  25689. // childList22.Add(new
  25690. // {
  25691. // id = item3.Id,
  25692. // parentId = item2.Id,
  25693. // level = "district",
  25694. // name = item3.Name_CN,
  25695. // });
  25696. // }
  25697. // childList.Add(new
  25698. // {
  25699. // id = item2.Id,
  25700. // parentId = parentId,
  25701. // level = "city",
  25702. // name = item2.Name_CN,
  25703. // childList = childList22
  25704. // });
  25705. // }
  25706. // }
  25707. // else
  25708. // {
  25709. // foreach (var item2 in citiesData)
  25710. // {
  25711. // string cname = item2.Name_CN;
  25712. // List<dynamic> childList1 = new List<dynamic>();
  25713. // var countiesData1 = countiesData.Where(it => it.ParentId == item2.Id).ToList();
  25714. // foreach (var item3 in countiesData1)
  25715. // {
  25716. // childList1.Add(new
  25717. // {
  25718. // Id = item3.Id,
  25719. // parentId = item2.Id,
  25720. // level = "district",
  25721. // name = item3.Name_CN
  25722. // });
  25723. // }
  25724. // childList.Add(new
  25725. // {
  25726. // id = item2.Id,
  25727. // parentId = parentId,
  25728. // level = "city",
  25729. // name = item2.Name_CN,
  25730. // childList = childList1
  25731. // });
  25732. // }
  25733. // }
  25734. // stopwatch.Stop();
  25735. // return Ok(JsonView(true, $"操作成功,耗时{stopwatch.ElapsedMilliseconds} ms", childList));
  25736. //}
  25737. /// <summary>
  25738. /// 匹配op行程单
  25739. /// 接团信息列表 Page
  25740. /// </summary>
  25741. /// <param name="dto">团组列表请求dto</param>
  25742. /// <returns></returns>
  25743. [HttpPost]
  25744. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25745. public async Task<IActionResult> PostMateOpGroupPageList(MateOpGroupPageListDto dto)
  25746. {
  25747. var swatch = new Stopwatch();
  25748. swatch.Start();
  25749. #region 参数验证
  25750. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  25751. if (dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  25752. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  25753. #region 页面操作权限验证
  25754. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  25755. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  25756. #endregion
  25757. #endregion
  25758. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) // web/Android
  25759. {
  25760. var _view = await GeneralMethod.MateOpGroupPageListRedis();
  25761. //string sqlWhere = "";
  25762. if (!string.IsNullOrEmpty(dto.Country))
  25763. {
  25764. _view = _view.Where(x => !string.IsNullOrEmpty(x.VisitCountry) && x.VisitCountry.Contains(dto.Country)).ToList();
  25765. }
  25766. if (!string.IsNullOrEmpty(dto.Area))
  25767. {
  25768. _view = _view.Where(x => !string.IsNullOrEmpty(x.RouteCity) && x.RouteCity.Contains(dto.Area)).ToList();
  25769. }
  25770. if (!string.IsNullOrEmpty(dto.TeamName))
  25771. {
  25772. _view = _view.Where(x => !string.IsNullOrEmpty(x.TeamName) && x.TeamName.Contains(dto.TeamName)).ToList();
  25773. }
  25774. int startIndex = (dto.PageIndex - 1) * dto.PageSize; // 计算开始的索引
  25775. int endIndex = startIndex + dto.PageSize - 1; // 计算结束的索引
  25776. var _view1 = _view.Skip(startIndex).Take(endIndex).ToList();
  25777. swatch.Stop();
  25778. return Ok(JsonView(true, $"查询成功!耗时 {swatch.ElapsedMilliseconds} ms", _view1, _view.Count));
  25779. }
  25780. else
  25781. {
  25782. return Ok(JsonView(false, "查询失败"));
  25783. }
  25784. }
  25785. /// <summary>
  25786. /// 匹配op行程单
  25787. /// 行程单下载
  25788. /// </summary>
  25789. /// <param name="dto">团组列表请求dto</param>
  25790. /// <returns></returns>
  25791. [HttpPost]
  25792. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25793. public async Task<IActionResult> PostMateOpGroupDownload(MateOpGroupDownloadDto dto)
  25794. {
  25795. #region 参数验证
  25796. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  25797. if (dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  25798. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  25799. #region 页面操作权限验证
  25800. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  25801. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限"));
  25802. #endregion
  25803. #endregion
  25804. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) // web/Android
  25805. {
  25806. var res = ExportTravel(new ExportTravelDto() { Diid = dto.diId });
  25807. return Ok(res.GetType().GetProperty("Value").GetValue(res, null));
  25808. }
  25809. else
  25810. {
  25811. return Ok(JsonView(false, "下载失败!"));
  25812. }
  25813. }
  25814. #endregion
  25815. #region 国家信息 数据 注释
  25816. //[HttpPost]
  25817. //public async Task<IActionResult> LoadCitiesInitData(List<int> dto)
  25818. //{
  25819. // List<Grp_GroupsTaskAssignment> infos = new List<Grp_GroupsTaskAssignment>();
  25820. // foreach (var item in dto)
  25821. // {
  25822. // infos.Add(new Grp_GroupsTaskAssignment()
  25823. // {
  25824. // DIId = item,
  25825. // CTId = 82,
  25826. // UId = 248,
  25827. // IsEnable = 1,
  25828. // CreateUserId = 233,
  25829. // CreateTime = DateTime.Now,
  25830. // IsDel = 0
  25831. // });
  25832. // infos.Add(new Grp_GroupsTaskAssignment()
  25833. // {
  25834. // DIId = item,
  25835. // CTId = 82,
  25836. // UId = 286,
  25837. // IsEnable = 1,
  25838. // CreateUserId = 233,
  25839. // CreateTime = DateTime.Now,
  25840. // IsDel = 0
  25841. // });
  25842. // }
  25843. // int add = _sqlSugar.Insertable<Grp_GroupsTaskAssignment>(infos).ExecuteCommand();
  25844. // return Ok("操作成功");
  25845. //}
  25846. //public class paramJsonDto
  25847. //{
  25848. // public List<CountriesInfo> str { get; set; }
  25849. //}
  25850. //[HttpPost]
  25851. //public async Task<IActionResult> LoadCitiesInitData(paramJsonDto dto)
  25852. //{
  25853. // //List<CountriesInfo> infos = new List<CountriesInfo>();
  25854. // //infos = JsonConvert.DeserializeObject<List<CountriesInfo>>(dto.str);
  25855. // List<Sys_Cities> cities = new List<Sys_Cities>();
  25856. // List<Sys_Cities> districts = new List<Sys_Cities>();
  25857. // var counties = _sqlSugar.Queryable<Sys_Countries>().Where(it => it.IsDel == 0).ToList();
  25858. // _sqlSugar.BeginTran();
  25859. // int countitiesIndex = 0;
  25860. // foreach (var item in dto.str)
  25861. // {
  25862. // dynamic data = item.c;
  25863. // int countriesId = counties.Find(it => it.Name_CN.Equals(item.cn))?.Id ?? 0;
  25864. // if (data != null)
  25865. // {
  25866. // countitiesIndex++;
  25867. // foreach (var item1 in data)
  25868. // {
  25869. // string cnname = item1.cn;
  25870. // string enname = item1.en;
  25871. // Sys_Cities provinceInfo = new Sys_Cities()
  25872. // {
  25873. // CountriesId = countriesId,
  25874. // Name_CN = cnname,
  25875. // Name_EN = enname,
  25876. // ParentId = 0,
  25877. // IsCapital = 1,
  25878. // CreateUserId = 208,
  25879. // CreateTime = DateTime.Now,
  25880. // IsDel = 0
  25881. // };
  25882. // if (item1.lv == "province") //省份
  25883. // {
  25884. // provinceInfo.Level = 1;
  25885. // int provinceId = 0;
  25886. // var provinceInfo1 = _sqlSugar.Queryable<Sys_Cities>().Where(it => it.CountriesId == countriesId && it.Level == 1 && it.Name_CN.Equals(cnname)).First();
  25887. // if (provinceInfo1 != null) provinceId = provinceInfo1.Id;
  25888. // else provinceId = _sqlSugar.Insertable<Sys_Cities>(provinceInfo).ExecuteReturnIdentity();
  25889. // var data1 = item1.c;
  25890. // foreach (var item2 in data1)
  25891. // {
  25892. // if (item2.lv == "city")
  25893. // {
  25894. // string citycnname = item2.cn;
  25895. // string cityenname = item2.en;
  25896. // Sys_Cities cityInfo = new Sys_Cities()
  25897. // {
  25898. // CountriesId = countriesId,
  25899. // ParentId = provinceId,
  25900. // Level = 2,
  25901. // Name_CN = citycnname,
  25902. // Name_EN = cityenname,
  25903. // IsCapital = 1,
  25904. // CreateUserId = 208,
  25905. // CreateTime = DateTime.Now,
  25906. // IsDel = 0
  25907. // };
  25908. // if (item2.c != null)
  25909. // {
  25910. // int cityId = 0;
  25911. // var citiesInfo = _sqlSugar.Queryable<Sys_Cities>().Where(it => it.CountriesId == countriesId && it.Level == 2 && it.Name_CN.Equals(citycnname)).First();
  25912. // if (citiesInfo != null) cityId = citiesInfo.Id;
  25913. // else cityId = _sqlSugar.Insertable<Sys_Cities>(cityInfo).ExecuteReturnIdentity();
  25914. // foreach (var item3 in item2.c)
  25915. // {
  25916. // if (item3.lv == "district")
  25917. // {
  25918. // var districtInfo = new Sys_Cities()
  25919. // {
  25920. // CountriesId = countriesId,
  25921. // Name_CN = item3.cn,
  25922. // Name_EN = item3.en,
  25923. // Level = 3,
  25924. // ParentId = cityId,
  25925. // IsCapital = 1,
  25926. // CreateUserId = 208,
  25927. // CreateTime = DateTime.Now,
  25928. // IsDel = 0
  25929. // };
  25930. // //if (districts.Find(it => it.CountriesId == countriesId && it.ParentId == cityId && it.Name_CN.Equals(districtInfo.Name_CN)) == null)
  25931. // //{
  25932. // districts.Add(districtInfo);
  25933. // //}
  25934. // }
  25935. // }
  25936. // }
  25937. // else
  25938. // {
  25939. // //if (cities.Find(it => it.CountriesId == countriesId && it.ParentId == provinceId && it.Name_CN.Equals(citycnname)) == null)
  25940. // //{
  25941. // cities.Add(cityInfo);
  25942. // //}
  25943. // }
  25944. // }
  25945. // }
  25946. // }
  25947. // else if (item1.lv == "city")//城市
  25948. // {
  25949. // provinceInfo.Level = 2;
  25950. // if (item1.c != null)
  25951. // {
  25952. // int cityId = 0;
  25953. // var citiesInfo = _sqlSugar.Queryable<Sys_Cities>().Where(it => it.CountriesId == countriesId && it.Level == 1 && it.Name_CN.Equals(provinceInfo.Name_CN)).First();
  25954. // if (citiesInfo != null) cityId = citiesInfo.Id;
  25955. // else cityId = _sqlSugar.Insertable<Sys_Cities>(provinceInfo).ExecuteReturnIdentity();
  25956. // foreach (var item3 in item1.c)
  25957. // {
  25958. // if (item3.lv == "district")
  25959. // {
  25960. // var districtInfo = new Sys_Cities()
  25961. // {
  25962. // CountriesId = countriesId,
  25963. // Name_CN = item3.cn,
  25964. // Name_EN = item3.en,
  25965. // Level = 3,
  25966. // ParentId = cityId,
  25967. // IsCapital = 1,
  25968. // CreateUserId = 208,
  25969. // CreateTime = DateTime.Now,
  25970. // IsDel = 0
  25971. // };
  25972. // //if (districts.Find(it => it.CountriesId == countriesId && it.ParentId == cityId && it.Name_CN.Equals(districtInfo.Name_CN)) == null)
  25973. // //{
  25974. // districts.Add(districtInfo);
  25975. // //}
  25976. // }
  25977. // }
  25978. // }
  25979. // else
  25980. // {
  25981. // //if (cities.Find(it => it.CountriesId == countriesId && it.Name_CN.Equals(provinceInfo.Name_CN)) == null)
  25982. // //{
  25983. // cities.Add(provinceInfo);
  25984. // //}
  25985. // }
  25986. // }
  25987. // }
  25988. // }
  25989. // }
  25990. // var procinceDatas = _sqlSugar.Queryable<Sys_Cities>().ToList();
  25991. // cities = cities.Distinct().ToList();
  25992. // districts = districts.Distinct().ToList();
  25993. // var citiesDatas = cities.Where(it => it.Level == 2).ToList();
  25994. // //var districtDatas = cities.Where(it => it.Level == 3).ToList();
  25995. // cities.AddRange(districts);
  25996. // var citiesAdd = _sqlSugar.Insertable<Sys_Cities>(cities).ExecuteReturnIdentity();
  25997. // //_sqlSugar.RollbackTran();
  25998. // _sqlSugar.CommitTran();
  25999. // return Ok(JsonView(false, "操作成功!"));
  26000. //}
  26001. //[HttpPost]
  26002. //public async Task<IActionResult> LoadCitiesInitInfo(CounrtiesDto dto)
  26003. //{
  26004. // List<CountitiesInfo> infos = dto.MyProperty;
  26005. // List<Sys_Cities> cityInfos = new List<Sys_Cities>();
  26006. // _sqlSugar.BeginTran();
  26007. // var countities = _sqlSugar.Queryable<Sys_Countries>().Where(it => it.IsDel == 0).ToList();
  26008. // var citities = _sqlSugar.Queryable<Sys_Cities>().Where(it => it.IsDel == 0 && it.Level == 2).ToList();
  26009. // foreach (var item in infos)
  26010. // {
  26011. // var countryInfo = countities.Where(it => it.ThreeCode.Equals(item.country_code3)).FirstOrDefault();
  26012. // if (countryInfo != null)
  26013. // {
  26014. // var cityInfo = citities.Where(it => it.CountriesId == countryInfo.Id).ToList();
  26015. // var cityInfo1 = cityInfo.Where(it => item.capital_name_chinese.Contains(it.Name_CN)).FirstOrDefault();
  26016. // if (cityInfo1 != null)
  26017. // {
  26018. // cityInfo1.IsCapital = 0;
  26019. // cityInfos.Add(cityInfo1);
  26020. // }
  26021. // }
  26022. // }
  26023. // var update = _sqlSugar.Updateable<Sys_Cities>(cityInfos)
  26024. // .UpdateColumns(it => it.IsCapital)
  26025. // .WhereColumns(it => it.Id)
  26026. // .ExecuteCommand();
  26027. // //_sqlSugar.RollbackTran();
  26028. // _sqlSugar.CommitTran();
  26029. // return Ok(JsonView(false, "操作成功!"));
  26030. //}
  26031. //public class CounrtiesDto
  26032. //{
  26033. // public List<CountitiesInfo> MyProperty { get; set; }
  26034. //}
  26035. //public class CountitiesInfo
  26036. //{
  26037. // /// <summary>
  26038. // /// 圣约翰
  26039. // /// </summary>
  26040. // public string capital_name_chinese { get; set; }
  26041. // /// <summary>
  26042. // ///
  26043. // /// </summary>
  26044. // public string capital_name { get; set; }
  26045. // /// <summary>
  26046. // ///
  26047. // /// </summary>
  26048. // public string country_type { get; set; }
  26049. // /// <summary>
  26050. // /// 安提瓜和巴布达
  26051. // /// </summary>
  26052. // public string country_name_chinese { get; set; }
  26053. // /// <summary>
  26054. // /// 安提瓜和巴布达
  26055. // /// </summary>
  26056. // public string country_name_chinese_short { get; set; }
  26057. // /// <summary>
  26058. // /// 安提瓜和巴布达
  26059. // /// </summary>
  26060. // public string country_name_chinese_UN { get; set; }
  26061. // /// <summary>
  26062. // ///
  26063. // /// </summary>
  26064. // public string country_name_english_abbreviation { get; set; }
  26065. // /// <summary>
  26066. // ///
  26067. // /// </summary>
  26068. // public string country_name_english_formal { get; set; }
  26069. // /// <summary>
  26070. // ///
  26071. // /// </summary>
  26072. // public string country_name_english_UN { get; set; }
  26073. // /// <summary>
  26074. // ///
  26075. // /// </summary>
  26076. // public string continent_name { get; set; }
  26077. // /// <summary>
  26078. // ///
  26079. // /// </summary>
  26080. // public string subregion_name { get; set; }
  26081. // /// <summary>
  26082. // ///
  26083. // /// </summary>
  26084. // public string country_code2 { get; set; }
  26085. // /// <summary>
  26086. // ///
  26087. // /// </summary>
  26088. // public string country_code3 { get; set; }
  26089. // /// <summary>
  26090. // ///
  26091. // /// </summary>
  26092. // public string phone_code { get; set; }
  26093. //}
  26094. //public class CountriesInfo : BasicInfo
  26095. //{
  26096. // public List<CitiesInfo> c { get; set; }
  26097. //}
  26098. //public class CitiesInfo : BasicInfo
  26099. //{
  26100. // public List<AreaInfo> c { get; set; }
  26101. //}
  26102. //public class AreaInfo : BasicInfo
  26103. //{
  26104. // public List<AreaInfo> c { get; set; }
  26105. //}
  26106. //public class BasicInfo
  26107. //{
  26108. // public string code { get; set; }
  26109. // public string cn { get; set; }
  26110. // public string lv { get; set; }
  26111. // public string en { get; set; }
  26112. //}
  26113. #endregion
  26114. #region 查看邀请方
  26115. /// <summary>
  26116. /// 查看邀请方
  26117. /// 邀请方信息 Init
  26118. /// </summary>
  26119. /// <param name="dto"></param>
  26120. /// <returns></returns>
  26121. [HttpPost]
  26122. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26123. public async Task<IActionResult> PostGroupLinkInvitingUnitNameInit(GroupLinkInvitingUnitNameInitDto dto)
  26124. {
  26125. string sqlWhere = string.Empty;
  26126. if (!string.IsNullOrEmpty(dto.Search))
  26127. {
  26128. sqlWhere = string.Format($@" And UnitName Like '%{dto.Search}%'");
  26129. }
  26130. string sql = string.Format($@"Select
  26131. ROW_NUMBER() Over(Order By Id desc) As Row_Number,
  26132. Id,
  26133. UnitName
  26134. From Res_InvitationOfficialActivityData
  26135. Where IsDel = 0
  26136. And (UnitName != '' Or UnitName != null) {sqlWhere}");
  26137. RefAsync<int> total = 0;
  26138. var _views = await _sqlSugar.SqlQueryable<GroupLinkInvitingUnitNameInitView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  26139. return Ok(JsonView(true, MsgTips.Succeed, _views, total));
  26140. }
  26141. /// <summary>
  26142. /// 查看邀请方
  26143. /// 国家信息 Init
  26144. /// </summary>
  26145. /// <param name="dto"></param>
  26146. /// <returns></returns>
  26147. [HttpPost]
  26148. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26149. public async Task<IActionResult> PostGroupLinkInvitingCountryInit(GroupLinkInvitingUnitNameInitDto dto)
  26150. {
  26151. var groupInfos = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).OrderByDescending(it => it.CreateUserId).ToListAsync();
  26152. var country = groupInfos.Select(it => it.VisitCountry).ToList();
  26153. var diids = groupInfos.Select(it => it.Id).ToList();
  26154. List<string> countrys = new List<string>();
  26155. foreach (var item in country)
  26156. {
  26157. var data = _groupRepository.FormartTeamName(item);
  26158. var dataArray = _groupRepository.GroupSplitCountry(data);
  26159. if (dataArray.Count > 0) countrys.AddRange(dataArray);
  26160. }
  26161. countrys = countrys.Distinct().ToList();
  26162. for (int i = 0; i < countrys.Count; i++)
  26163. {
  26164. string item = countrys[i];
  26165. if (string.IsNullOrEmpty(item) || item.Contains("-"))
  26166. {
  26167. countrys.Remove(item);
  26168. i--;
  26169. }
  26170. }
  26171. RefAsync<int> total = 0;
  26172. var countyDatas = await _sqlSugar.Queryable<Sys_Countries>()
  26173. .Where(it => countrys.Contains(it.Name_CN))
  26174. .WhereIF(!string.IsNullOrEmpty(dto.Search), it => it.Name_CN.Contains(dto.Search))
  26175. .Select(it => new { id = it.Id, name = it.Name_CN })
  26176. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  26177. return Ok(JsonView(true, MsgTips.Succeed, countyDatas, total));
  26178. }
  26179. /// <summary>
  26180. /// 查看邀请方
  26181. /// 城市信息 Init
  26182. /// </summary>
  26183. /// <param name="dto"></param>
  26184. /// <returns></returns>
  26185. [HttpPost]
  26186. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26187. public async Task<IActionResult> PostGroupLinkInvitingCityInit(GroupLinkInvitingCityInitDto dto)
  26188. {
  26189. if (dto.CountiesId < 1) return Ok(JsonView(false, "请传入有效的国家Id"));
  26190. RefAsync<int> total = 0;
  26191. var countyDatas = await _sqlSugar.Queryable<Sys_Cities>()
  26192. .Where(it => it.CountriesId == dto.CountiesId)
  26193. .WhereIF(!string.IsNullOrEmpty(dto.Search), it => it.Name_CN.Contains(dto.Search))
  26194. .OrderBy(it => new { IsCapital = SqlFunc.Asc(it.IsCapital), Id = SqlFunc.Asc(it.Id) })
  26195. .Select(it => new { id = it.Id, name = it.Name_CN })
  26196. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  26197. return Ok(JsonView(true, MsgTips.Succeed, countyDatas, total));
  26198. }
  26199. /// <summary>
  26200. /// 查看邀请方
  26201. /// 团组名称 Init
  26202. /// </summary>
  26203. /// <param name="dto"></param>
  26204. /// <returns></returns>
  26205. [HttpPost]
  26206. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26207. public async Task<IActionResult> PostGroupLinkInvitingGroupInit(GroupLinkInvitingDto dto)
  26208. {
  26209. var watch = new Stopwatch();
  26210. watch.Start();
  26211. RefAsync<int> total = 0;
  26212. var countyDatas = await _sqlSugar.Queryable<Res_OfficialActivities>()
  26213. .InnerJoin<Grp_DelegationInfo>((oa, di) => oa.DiId == di.Id)
  26214. .Where((oa, di) => oa.IsDel == 0)
  26215. .WhereIF(!string.IsNullOrEmpty(dto.Search), (oa, di) => di.TeamName.Contains(dto.Search))
  26216. .OrderBy((oa, di) => new { id = SqlFunc.Desc(di.Id) })
  26217. .Select((oa, di) => new { id = di.Id, name = di.TeamName })
  26218. .Distinct()
  26219. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  26220. watch.Stop();
  26221. return Ok(JsonView(true, $"{MsgTips.Succeed},耗时 {watch.ElapsedMilliseconds} ms", countyDatas, total));
  26222. }
  26223. /// <summary>
  26224. /// 查看邀请方
  26225. /// 团组 & 邀请方信息
  26226. /// </summary>
  26227. /// <param name="dto"></param>
  26228. /// <returns></returns>
  26229. [HttpPost]
  26230. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26231. public async Task<IActionResult> PostGroupLinkInvitingPageList(GroupLinkInvitingPageListDto dto)
  26232. {
  26233. var watch = new Stopwatch();
  26234. watch.Start();
  26235. RefAsync<int> total = 0;
  26236. var infos = await _sqlSugar.Queryable<GroupLinkInvitingPageListView>()
  26237. .AS("Grp_DelegationInfo")
  26238. .Includes(x => x.InvitingInfos)
  26239. .Where(x => x.IsDel == 0 && x.InvitingInfos.Any(z => z.IsDel == 0))
  26240. .WhereIF(!string.IsNullOrEmpty(dto.Counrty), x => x.VisitCountry.Contains(dto.Counrty))
  26241. .WhereIF(!string.IsNullOrEmpty(dto.Area), x => x.InvitingInfos.Any(z => z.Area.Contains(dto.Area))) //
  26242. .WhereIF(!string.IsNullOrEmpty(dto.TeamName), x => x.TeamName.Contains(dto.TeamName)) //
  26243. .WhereIF(!string.IsNullOrEmpty(dto.UnitName), x => x.InvitingInfos.Any(z => z.Client.Contains(dto.UnitName)))
  26244. .OrderBy(x => new { JietuanTime = SqlFunc.Desc(x.VisitStartDate) })
  26245. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  26246. var userDatas = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToList();
  26247. var setDatas = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0).ToList();
  26248. infos.ForEach(x =>
  26249. {
  26250. x.TeamDid = setDatas.Find(y => int.Parse(x.TeamDid) == y.Id)?.Name ?? "-";
  26251. x.JietuanOperator = userDatas.Find(y => int.Parse(x.JietuanOperator) == y.Id)?.CnName ?? "-";
  26252. x.TeamLevSId = setDatas.Find(y => int.Parse(x.TeamLevSId) == y.Id)?.Name ?? "-";
  26253. x.InvitingInfos = x.InvitingInfos.Where(it => it.IsDel == 0).ToList();
  26254. });
  26255. watch.Stop();
  26256. return Ok(JsonView(true, $"{MsgTips.Succeed},耗时 {watch.ElapsedMilliseconds} ms", infos, total));
  26257. }
  26258. #endregion
  26259. #region 报批行程
  26260. /// <summary>
  26261. /// 报批行程初始化
  26262. /// </summary>
  26263. /// <param name="dto"></param>
  26264. /// <returns></returns>
  26265. [HttpPost]
  26266. public IActionResult ApprovalJourneyInit(ApprovalJourneyDto dto)
  26267. {
  26268. const int chiNumber = 5;
  26269. var jw = JsonView(false);
  26270. var groupList = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0).OrderByDescending(x => x.VisitStartDate).ToList();
  26271. var group = groupList.First();
  26272. var diid = dto.Diid == -1 ? group?.Id : dto.Diid;
  26273. group = groupList.First(x => x.Id == diid);
  26274. var blackCodeList = _sqlSugar.Queryable<Air_TicketBlackCode>()
  26275. .Where(x => x.DiId == diid && x.IsDel == 0)
  26276. .ToArray();
  26277. var count = 1;
  26278. foreach (var item in blackCodeList)
  26279. {
  26280. if (string.IsNullOrWhiteSpace(item.Title))
  26281. {
  26282. item.Title = "未设置名称数据" + count;
  26283. }
  26284. count++;
  26285. }
  26286. ;
  26287. if (group == null)
  26288. {
  26289. jw.Msg = "暂无团组!";
  26290. return Ok(jw);
  26291. }
  26292. var data = new
  26293. {
  26294. groupList = groupList.Select(x => new
  26295. {
  26296. x.TeamName,
  26297. x.Id
  26298. }),
  26299. content = new ArrayList(),
  26300. groupInfo = new
  26301. {
  26302. group.VisitDays,
  26303. group.TourCode,
  26304. group.VisitPNumber,
  26305. group.TeamName,
  26306. group.Id,
  26307. visitStartDate = group.VisitStartDate.ToString("yyyy-MM-dd"),
  26308. visitEndDate = group.VisitEndDate.ToString("yyyy-MM-dd"),
  26309. group.ClientUnit
  26310. },
  26311. blackCodeList = blackCodeList.Select(x => new
  26312. {
  26313. x.Title,
  26314. x.Id
  26315. }),
  26316. FileTempList = new ArrayList()
  26317. {
  26318. new { Index = 1,FileName = "旧模板" },
  26319. new { Index = 2,FileName = "省外办" },
  26320. new { Index = 3,FileName = "市外办" },
  26321. }
  26322. };
  26323. var resultArr = new ArrayList();
  26324. var content = _sqlSugar.Queryable<Grp_ApprovalTravel>().Where(x => x.Diid == diid && x.IsDel == 0).ToList();
  26325. #region 默认不生成行程
  26326. //if (content.Count == 0)
  26327. //{
  26328. // var stay = "-";
  26329. // var cityPath = "-";
  26330. // var blackCodeList = _sqlSugar.Queryable<Air_TicketBlackCode>()
  26331. // .Where(x => x.DiId == diid && x.IsDel == 0)
  26332. // .ToList();
  26333. // //添加城市路径以及住宿地
  26334. // //黑屏代码数据
  26335. // DataTable dtBlack = GeneralMethod.GetTableByBlackCodeById(blackCodeList.FirstOrDefault());
  26336. // if (dtBlack.Rows.Count == 0 || string.IsNullOrWhiteSpace(dtBlack.Rows[0][1].ToString()))
  26337. // {
  26338. // jw = JsonView(true, "黑屏代码有误!", data);
  26339. // return Ok(jw);
  26340. // }
  26341. // data = data with
  26342. // {
  26343. // blackCodeList = new ArrayList(blackCodeList.Select(x => new
  26344. // {
  26345. // x.Title,
  26346. // x.Id,
  26347. // }).ToArray())
  26348. // };
  26349. // foreach (DataRow row in dtBlack.Rows)
  26350. // {
  26351. // if (!string.IsNullOrWhiteSpace(row["Error"].ToString()))
  26352. // {
  26353. // jw = JsonView(true, "黑屏代码有误!" + row["Error"].ToString(), data);
  26354. // return Ok(jw);
  26355. // }
  26356. // }
  26357. // //黑屏代码获取时间区间
  26358. // var timeArr = GeneralMethod.GetTimeListByDataTable(dtBlack);
  26359. // string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  26360. // _sqlSugar.BeginTran();
  26361. // for (int i = 0; i < timeArr.Count; i++)
  26362. // {
  26363. // stay = "-";
  26364. // cityPath = "-";
  26365. // DateTime NewData = DateTime.Parse(timeArr[i]);
  26366. // string week = Day[Convert.ToInt32(NewData.DayOfWeek.ToString("d"))].ToString();
  26367. // Grp_ApprovalTravel appro = new Grp_ApprovalTravel();
  26368. // var tbSelect = dtBlack.Select(string.Format("Day = '{0}'", NewData.ToString("yyyy-MM-dd")));
  26369. // if (tbSelect.Length > 0)
  26370. // {
  26371. // List<string> threeCodeStr = new List<string>();
  26372. // foreach (var item in tbSelect)
  26373. // {
  26374. // var threeCode = item["Three"].ToString() ?? "";
  26375. // if (threeCode.Length == 6)
  26376. // {
  26377. // var start = threeCode.Substring(0, 3);
  26378. // var end = threeCode.Substring(3, 3);
  26379. // if (threeCodeStr.Count == 0)
  26380. // {
  26381. // threeCodeStr.Add(start);
  26382. // threeCodeStr.Add(end);
  26383. // }
  26384. // else
  26385. // {
  26386. // if (threeCodeStr[threeCodeStr.Count - 1] == start)
  26387. // {
  26388. // threeCodeStr.Add(end);
  26389. // }
  26390. // else
  26391. // {
  26392. // threeCodeStr.Add(start);
  26393. // threeCodeStr.Add(end);
  26394. // }
  26395. // }
  26396. // }
  26397. // }
  26398. // var threeCodeList = _threeCodeRepository.QueryThreeCodeArray(threeCodeStr);
  26399. // var last = threeCodeStr.Last();
  26400. // foreach (var item in threeCodeStr)
  26401. // {
  26402. // cityPath += (threeCodeList.Keys.Contains(item) ? threeCodeList[item].City : "【未知三字码】") + "-";
  26403. // if (item.Equals(last))
  26404. // {
  26405. // stay = threeCodeList.Keys.Contains(item) ? threeCodeList[item].City : "【未知三字码】";
  26406. // }
  26407. // }
  26408. // cityPath = cityPath.Trim('-');
  26409. // }
  26410. // appro.Date = "第" + intToString(i + 1) + "天 " + NewData.Month + "月" + NewData.Day + "日(" + week + ") " + cityPath + " 宿:" + stay;
  26411. // appro.Diid = diid ?? -1;
  26412. // var thisId = _sqlSugar.Insertable<Grp_ApprovalTravel>(appro).ExecuteReturnIdentity();
  26413. // appro.Id = thisId;
  26414. // appro.CreateUserId = dto.UserId;
  26415. // appro.CreateTime = DateTime.Now;
  26416. // content.Add(appro);
  26417. // }
  26418. // _sqlSugar.CommitTran();
  26419. //}
  26420. #endregion
  26421. foreach (var x in content)
  26422. {
  26423. var chiList = _sqlSugar.Queryable<Grp_ApprovalTravelDetails>().Where(x1 => x1.ParentId == x.Id && x1.IsDel == 0).ToList();
  26424. if (chiList.Count < chiNumber)
  26425. {
  26426. for (int i = chiList.Count; i < chiNumber; i++)
  26427. {
  26428. chiList.Add(new Grp_ApprovalTravelDetails());
  26429. }
  26430. }
  26431. resultArr.Add(new
  26432. {
  26433. x.Id,
  26434. x.Date,
  26435. x.Diid,
  26436. chiList = chiList.Select(x1 => new
  26437. {
  26438. timeInterval = string.IsNullOrWhiteSpace(x1.Time) ? new string[1] : x1.Time.Split('-'),
  26439. x1.Details,
  26440. x1.ParentId,
  26441. x1.Id
  26442. })
  26443. });
  26444. }
  26445. data = data with
  26446. {
  26447. content = resultArr,
  26448. };
  26449. jw = JsonView(true, "获取成功!", data);
  26450. return Ok(jw);
  26451. }
  26452. /// <summary>
  26453. /// 报批行程删除
  26454. /// </summary>
  26455. /// <param name="dto"></param>
  26456. /// <returns></returns>
  26457. [HttpPost]
  26458. public IActionResult DeleteApprovalJourney(DeleteApprovalJourney dto)
  26459. {
  26460. var jw = JsonView(false);
  26461. var group = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  26462. if (group == null)
  26463. {
  26464. jw.Msg = "团组参数有误!";
  26465. return Ok(jw);
  26466. }
  26467. try
  26468. {
  26469. _sqlSugar.BeginTran();
  26470. var arr = _sqlSugar.Queryable<Grp_ApprovalTravel>().Where(x => x.Diid == dto.Diid && x.IsDel == 0).Select(x => x.Id).ToList();
  26471. _ = _sqlSugar.Updateable<Grp_ApprovalTravelDetails>().SetColumns(x => new Grp_ApprovalTravelDetails
  26472. {
  26473. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  26474. DeleteUserId = dto.uesrId,
  26475. IsDel = 1
  26476. }).Where(x => arr.Contains(x.ParentId) && x.IsDel == 0).ExecuteCommand();
  26477. _ = _sqlSugar.Updateable<Grp_ApprovalTravel>().SetColumns(x => new Grp_ApprovalTravel
  26478. {
  26479. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  26480. DeleteUserId = dto.uesrId,
  26481. IsDel = 1
  26482. }).Where(x => arr.Contains(x.Id)).ExecuteCommand();
  26483. _sqlSugar.CommitTran();
  26484. jw = JsonView(true, "删除成功");
  26485. }
  26486. catch (Exception ex)
  26487. {
  26488. jw = JsonView(false, ex.Message);
  26489. }
  26490. return Ok(jw);
  26491. }
  26492. /// <summary>
  26493. /// 报批行程保存
  26494. /// </summary>
  26495. /// <param name="dto"></param>
  26496. /// <returns></returns>
  26497. [HttpPost]
  26498. public IActionResult SaveApprovalJourney(SaveApprovalJourney dto)
  26499. {
  26500. var jw = JsonView(false);
  26501. var Find = dto.Arr.Find(x => x.id == 0);
  26502. if (Find != null)
  26503. {
  26504. jw.Msg = "生成的ID为0!";
  26505. return Ok(jw);
  26506. }
  26507. foreach (var item in dto.Arr)
  26508. {
  26509. foreach (var chi in item.chiList)
  26510. {
  26511. if (chi.parentId == 0)
  26512. {
  26513. chi.parentId = item.id;
  26514. }
  26515. }
  26516. }
  26517. var chiArr = dto.Arr.SelectMany(x => x.chiList).ToList();
  26518. _sqlSugar.BeginTran();
  26519. if (chiArr.Where(x => x.id == 0).Count() == chiArr.Count)
  26520. {
  26521. var parentIds = dto.Arr.Select(x => x.id).ToList();
  26522. _sqlSugar.Updateable<Grp_ApprovalTravelDetails>().Where(x => parentIds.Contains(x.ParentId) && x.IsDel == 0).SetColumns(x => new Grp_ApprovalTravelDetails
  26523. {
  26524. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  26525. DeleteUserId = dto.UserId,
  26526. IsDel = 1
  26527. }).ExecuteCommand();
  26528. }
  26529. try
  26530. {
  26531. _ = _sqlSugar.Insertable<Grp_ApprovalTravelDetails>(chiArr.Where(x => x.id == 0).Select(x => new Grp_ApprovalTravelDetails
  26532. {
  26533. CreateTime = DateTime.Now,
  26534. CreateUserId = dto.UserId,
  26535. Details = x.details,
  26536. ParentId = x.parentId,
  26537. Time = x.timeInterval.Where(x => !string.IsNullOrWhiteSpace(x)).Count() > 1 ? x.timeInterval[0] + "-" + x.timeInterval[1] : "",
  26538. Remark = "",
  26539. IsDel = 0
  26540. }).ToList()).ExecuteCommand();
  26541. _ = _sqlSugar.Updateable<Grp_ApprovalTravelDetails>(chiArr.Where(x => x.id != 0).Select(x => new Grp_ApprovalTravelDetails
  26542. {
  26543. Id = x.id,
  26544. Details = x.details,
  26545. ParentId = x.parentId,
  26546. Time = x.timeInterval.Where(x => !string.IsNullOrWhiteSpace(x)).Count() > 1 ? x.timeInterval[0] + "-" + x.timeInterval[1] : "",
  26547. }).ToList()).UpdateColumns(x => new Grp_ApprovalTravelDetails
  26548. {
  26549. Details = x.Details,
  26550. ParentId = x.ParentId,
  26551. Time = x.Time
  26552. }).ExecuteCommand();
  26553. _ = _sqlSugar.Updateable<Grp_ApprovalTravel>(dto.Arr.Where(x => x.id != 0).Select(x => new Grp_ApprovalTravel
  26554. {
  26555. Id = x.id,
  26556. Date = x.date,
  26557. }).ToList()).UpdateColumns(x => new Grp_ApprovalTravel
  26558. {
  26559. Date = x.Date
  26560. }).ExecuteCommand();
  26561. _sqlSugar.CommitTran();
  26562. jw = JsonView(true, "保存成功!");
  26563. }
  26564. catch (Exception ex)
  26565. {
  26566. _sqlSugar.RollbackTran();
  26567. jw = JsonView(false, "保存失败!" + ex.Message);
  26568. }
  26569. return Ok(jw);
  26570. }
  26571. /// <summary>
  26572. /// 报批行程生成
  26573. /// </summary>
  26574. /// <param name="dto"></param>
  26575. /// <returns></returns>
  26576. [HttpPost]
  26577. public IActionResult CreateApprovalJourney(CreateApprovalJourneyDto dto)
  26578. {
  26579. var jw = JsonView(false);
  26580. var group = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  26581. if (group == null)
  26582. {
  26583. jw.Msg = "暂无该团组!";
  26584. return Ok(jw);
  26585. }
  26586. var blackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().First(x => x.Id == dto.BlackCodeId && x.IsDel == 0);
  26587. //黑屏代码数据
  26588. DataTable dtBlack = GeneralMethod.GetTableByBlackCodeBySingle(blackCode);
  26589. if (dtBlack.Rows.Count == 0 || string.IsNullOrWhiteSpace(dtBlack.Rows[0][1].ToString()))
  26590. {
  26591. jw.Msg = "黑屏代码有误!";
  26592. return Ok(jw);
  26593. }
  26594. foreach (DataRow row in dtBlack.Rows)
  26595. {
  26596. if (!string.IsNullOrWhiteSpace(row["Error"].ToString()))
  26597. {
  26598. jw.Msg = "黑屏代码有误!" + row["Error"].ToString();
  26599. return Ok(jw);
  26600. }
  26601. }
  26602. //var officialActivitiesArr = _sqlSugar.Queryable<Res_OfficialActivities>().Where(x => x.DiId == dto.Diid && x.IsDel == 0).ToList();
  26603. var resultArr = new ArrayList();
  26604. //if (officialActivitiesArr.Count == 0)
  26605. //{
  26606. // jw.Msg = "暂无公务出访信息!";
  26607. // return Ok(jw);
  26608. //}
  26609. try
  26610. {
  26611. _sqlSugar.BeginTran();
  26612. DeleteApprovalJourney(new
  26613. Domain.Dtos.Groups.DeleteApprovalJourney
  26614. {
  26615. Diid = dto.Diid,
  26616. uesrId = dto.Userid
  26617. });
  26618. var stay = "-";
  26619. var cityPath = "-";
  26620. var arriveCountry = string.Empty;
  26621. //添加城市路径以及住宿地
  26622. //黑屏代码获取时间区间
  26623. var timeArr = GeneralMethod.GetTimeListByDataTable(dtBlack);
  26624. var empty = "【未收入该三字码!请机票同事录入】";
  26625. string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  26626. #region 配置公务活动时间
  26627. List<Tuple<int, string, string>> Times = new List<Tuple<int, string, string>>();
  26628. Times.Add(new Tuple<int, string, string>(9, "9:00", "10:30"));
  26629. Times.Add(new Tuple<int, string, string>(11, "11:00", "12:00"));
  26630. Times.Add(new Tuple<int, string, string>(14, "14:00", "15:30"));
  26631. Times.Add(new Tuple<int, string, string>(16, "16:00", "17:00"));
  26632. List<Tuple<DateTime, List<string>>> fallTimesCheckCountry = new List<Tuple<DateTime, List<string>>>()
  26633. {
  26634. 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" }),
  26635. 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"}),
  26636. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,11,30,0), new List<string>{"14:00-15:30","16:00-17:00"}),
  26637. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,13,30,0), new List<string>{"16:30-17:30"}),
  26638. };
  26639. List<Tuple<DateTime, List<string>>> fallTimesNotCheckCountry = new List<Tuple<DateTime, List<string>>>()
  26640. {
  26641. 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" }),
  26642. 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"}),
  26643. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,11,30,0), new List<string>{"14:00-15:30","16:00-17:00"}),
  26644. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,14,30,0), new List<string>{"16:30-17:30"}),
  26645. };
  26646. List<Tuple<DateTime, List<string>>> takeoffTimes = new List<Tuple<DateTime, List<string>>>()
  26647. {
  26648. 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" }),
  26649. 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"}),
  26650. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,14,00,0), new List<string>{"9:00-10:30", "11:00-12:00",}),
  26651. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,12,00,0), new List<string>{"09:00-10:00"}),
  26652. };
  26653. #endregion
  26654. var nextDayNum = 0;
  26655. for (int i = 0; i < timeArr.Count; i++)
  26656. {
  26657. stay = "-";
  26658. cityPath = "-";
  26659. var chiarr = new List<Grp_ApprovalTravelDetails>();
  26660. DateTime NewData = DateTime.Parse(timeArr[i]);
  26661. //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();
  26662. var tbSelect = dtBlack.Select(string.Format("Day = '{0}'", NewData.ToString("yyyy-MM-dd")));
  26663. if (nextDayNum > 0)
  26664. {
  26665. nextDayNum--;
  26666. }
  26667. if (tbSelect.Length > 0)
  26668. {
  26669. List<string> threeCodeStr = new List<string>();
  26670. bool isTrade = false;
  26671. string trip = string.Empty;
  26672. foreach (var item in tbSelect)
  26673. {
  26674. if (nextDayNum == 0)
  26675. {
  26676. nextDayNum = Convert.ToInt32(item["Sign"]);
  26677. }
  26678. var airStartTime = item["StartTime"].ToString() ?? "0000";
  26679. var airEndTime = item["EndTime"].ToString() ?? "0000";
  26680. var takeOffTime = DateTime.Parse(timeArr[i]);
  26681. var fallToTime = DateTime.Parse(timeArr[i]);
  26682. takeOffTime = takeOffTime.AddHours(int.Parse(airStartTime.Substring(0, 2)));
  26683. takeOffTime = takeOffTime.AddMinutes(int.Parse(airStartTime.Substring(2, 2)));
  26684. fallToTime = fallToTime.AddHours(int.Parse(airEndTime.Substring(0, 2)));
  26685. fallToTime = fallToTime.AddMinutes(int.Parse(airEndTime.Substring(2, 2)));
  26686. if (nextDayNum > 0)
  26687. {
  26688. fallToTime = fallToTime.AddDays(nextDayNum);
  26689. }
  26690. trip = string.Empty;
  26691. var start = string.Empty;
  26692. var end = string.Empty;
  26693. var threeCode = item["Three"].ToString() ?? "";
  26694. if (threeCode.Length == 6)
  26695. {
  26696. start = threeCode.Substring(0, 3);
  26697. end = threeCode.Substring(3, 3);
  26698. if (threeCodeStr.Count == 0)
  26699. {
  26700. threeCodeStr.Add(start);
  26701. threeCodeStr.Add(end);
  26702. }
  26703. else
  26704. {
  26705. if (threeCodeStr[threeCodeStr.Count - 1] == start)
  26706. {
  26707. threeCodeStr.Add(end);
  26708. }
  26709. else
  26710. {
  26711. threeCodeStr.Add(start);
  26712. threeCodeStr.Add(end);
  26713. }
  26714. }
  26715. }
  26716. //处理机票信息
  26717. var start_Object = _sqlSugar.Queryable<Res_ThreeCode>().First(x => x.Three.ToUpper() == start.ToUpper());
  26718. var end_Object = _sqlSugar.Queryable<Res_ThreeCode>().First(x => x.Three.ToUpper() == end.ToUpper());
  26719. if (start_Object == null)
  26720. {
  26721. start_Object = new Res_ThreeCode()
  26722. {
  26723. AirPort = empty,
  26724. AirPort_En = empty,
  26725. City = empty,
  26726. Country = empty,
  26727. Four = empty,
  26728. Three = empty,
  26729. };
  26730. }
  26731. if (end_Object == null)
  26732. {
  26733. end_Object = new Res_ThreeCode()
  26734. {
  26735. AirPort = empty,
  26736. AirPort_En = empty,
  26737. City = empty,
  26738. Country = empty,
  26739. Four = empty,
  26740. Three = empty,
  26741. };
  26742. }
  26743. //机型判断
  26744. string airModel = item["AirModel"].ToString();
  26745. airModel = GeneralMethod.GetLonger(airModel!.Substring(0, 1)) + airModel;
  26746. string flightTime = item["FlightTime"].ToString();
  26747. flightTime = ParseBlackTime(flightTime);
  26748. //航班号
  26749. string flightcode = item["Fliagtcode"].ToString();
  26750. var aircompany = _sqlSugar.Queryable<Res_AirCompany>().First(x => x.ShortCode.ToUpper() == flightcode!.Substring(0, 2).ToUpper() && x.IsDel == 0);
  26751. var hsEmpty = "【此航司" + flightcode!.Substring(0, 2).ToUpper() + "未收录,请机票同事录入】";
  26752. if (aircompany == null)
  26753. {
  26754. aircompany = new Res_AirCompany
  26755. {
  26756. CnName = hsEmpty,
  26757. EnName = hsEmpty,
  26758. ShortCode = hsEmpty,
  26759. };
  26760. }
  26761. //航班前公务安排
  26762. if (tbSelect.First().Equals(item) && i != 0)
  26763. {
  26764. foreach (var takeoff in takeoffTimes)
  26765. {
  26766. var takeoffItem1 = NewData.AddHours(takeoff.Item1.Hour).AddMinutes(takeoff.Item1.Minute);
  26767. if (DateTime.Compare(takeOffTime, takeoffItem1) > 0)
  26768. {
  26769. foreach (var addTime in takeoff.Item2)
  26770. {
  26771. chiarr.Add(new Grp_ApprovalTravelDetails
  26772. {
  26773. Time = addTime,
  26774. CreateTime = DateTime.Now,
  26775. CreateUserId = dto.Userid,
  26776. ParentId = 0,
  26777. Details = "公务活动"
  26778. });
  26779. }
  26780. break;
  26781. }
  26782. }
  26783. }
  26784. //从成都天府国际机场搭乘四川航空公司3U3961飞往东京
  26785. //trip += $"从{start_Object.AirPort}搭乘{aircompany.CnName}{flightcode}飞往{end_Object.City}。\r\n({start_Object.AirPort}/{end_Object.AirPort} 机型:{airModel} 飞行时间{flightTime});\r\n";
  26786. //乘坐四川航空3U3901次航班由成都飞往加德满都,3小时25分钟
  26787. trip += $"乘坐{aircompany.CnName}{flightcode}次航班由{start_Object.City}飞往{end_Object.City},{flightTime}";
  26788. isTrade = Convert.ToBoolean(item["isTransitShipment"]);
  26789. if (isTrade)
  26790. {
  26791. //trip += $"抵达{end_Object.AirPort}{item["EndBuilding"].ToString().Trim()}航站楼(中转 行李直达)\r\n";
  26792. trip += "(转机不出机场)。";
  26793. }
  26794. //else
  26795. //{
  26796. // trip += "\r\n"; //$"抵达{end_Object.AirPort}{item["EndBuilding"].ToString().Trim()}航站楼,办理入境手续,之后前往提取行李\r\n";
  26797. //}
  26798. chiarr.Add(new Grp_ApprovalTravelDetails
  26799. {
  26800. Time = takeOffTime.ToString("HH:mm") + "-" + fallToTime.ToString("HH:mm"),
  26801. CreateTime = DateTime.Now,
  26802. CreateUserId = dto.Userid,
  26803. ParentId = 0,
  26804. Details = trip
  26805. });
  26806. //最后一条到达的时间安排公务
  26807. if (tbSelect.Last().Equals(item) && i != timeArr.Count - 1)
  26808. {
  26809. bool isCheckCountry = false;
  26810. if (end_Object.Country != arriveCountry)
  26811. {
  26812. arriveCountry = end_Object.Country;
  26813. isCheckCountry = true;
  26814. }
  26815. if (nextDayNum == 0)
  26816. {
  26817. //需要入境的情况
  26818. if (isCheckCountry)
  26819. {
  26820. foreach (var fallTime in fallTimesCheckCountry)
  26821. {
  26822. var fallTimeItem1 = NewData.AddHours(fallTime.Item1.Hour).AddMinutes(fallTime.Item1.Minute);
  26823. if (DateTime.Compare(fallToTime, fallTimeItem1) < 0)
  26824. {
  26825. foreach (var addTime in fallTime.Item2)
  26826. {
  26827. chiarr.Add(new Grp_ApprovalTravelDetails
  26828. {
  26829. Time = addTime,
  26830. CreateTime = DateTime.Now,
  26831. CreateUserId = dto.Userid,
  26832. ParentId = 0,
  26833. Details = "公务活动"
  26834. });
  26835. }
  26836. break;
  26837. }
  26838. }
  26839. }
  26840. else
  26841. {
  26842. foreach (var fallTime in fallTimesNotCheckCountry)
  26843. {
  26844. var fallTimeItem1 = NewData.AddHours(fallTime.Item1.Hour).AddMinutes(fallTime.Item1.Minute);
  26845. if (DateTime.Compare(fallToTime, fallTimeItem1) < 0)
  26846. {
  26847. foreach (var addTime in fallTime.Item2)
  26848. {
  26849. chiarr.Add(new Grp_ApprovalTravelDetails
  26850. {
  26851. Time = addTime,
  26852. CreateTime = DateTime.Now,
  26853. CreateUserId = dto.Userid,
  26854. ParentId = 0,
  26855. Details = "公务活动"
  26856. });
  26857. }
  26858. break;
  26859. }
  26860. }
  26861. }
  26862. }
  26863. }
  26864. }
  26865. //添加乘车语句
  26866. //chiarr.Add(new Grp_ApprovalTravelDetails
  26867. //{
  26868. // Time = (fallToTime.AddHours(2.5).ToString("HH:mm") + "-" + fallToTime.AddHours(3).ToString("HH:mm")),
  26869. // CreateTime = DateTime.Now,
  26870. // CreateUserId = dto.Userid,
  26871. // ParentId = 0,
  26872. // Details = "乘车前往市区(约xx公里,大约需要xx分钟)"
  26873. //});
  26874. //if (i != timeArr.Count - 1)
  26875. //{
  26876. // fallToTime = fallToTime.AddHours(2.5);
  26877. // foreach (var item in Times)
  26878. // {
  26879. // //排列公务时间
  26880. // if (fallToTime.Hour < item.Item1)
  26881. // {
  26882. // chiarr.Add(new Grp_ApprovalTravelDetails
  26883. // {
  26884. // Time = $"{item.Item2} - {item.Item3}",
  26885. // CreateTime = DateTime.Now,
  26886. // CreateUserId = dto.Userid,
  26887. // ParentId = 0,
  26888. // Details = "公务活动"
  26889. // });
  26890. // }
  26891. // }
  26892. //}
  26893. var threeCodeList = _threeCodeRepository.QueryThreeCodeArray(threeCodeStr);
  26894. var last = threeCodeStr.Last();
  26895. foreach (var item in threeCodeStr)
  26896. {
  26897. cityPath += (threeCodeList.Keys.Contains(item) ? threeCodeList[item].City : "【未知三字码】") + "-";
  26898. if (item.Equals(last))
  26899. {
  26900. stay = threeCodeList.Keys.Contains(item) ? threeCodeList[item].City : "【未知三字码】";
  26901. }
  26902. }
  26903. cityPath = cityPath.Trim('-');
  26904. }
  26905. else
  26906. {
  26907. foreach (var item in Times)
  26908. {
  26909. chiarr.Add(new Grp_ApprovalTravelDetails
  26910. {
  26911. Time = $"{item.Item2} - {item.Item3}",
  26912. CreateTime = DateTime.Now,
  26913. CreateUserId = dto.Userid,
  26914. ParentId = 0,
  26915. Details = "公务活动"
  26916. });
  26917. }
  26918. }
  26919. string week = Day[Convert.ToInt32(NewData.DayOfWeek.ToString("d"))].ToString();
  26920. Grp_ApprovalTravel appro = new Grp_ApprovalTravel();
  26921. appro.Date = NewData.Month + "月" + NewData.Day + "日(" + week + ")" + "第" + intToString(i + 1) + "天 ";
  26922. appro.Diid = dto.Diid;
  26923. appro.CreateUserId = dto.Userid;
  26924. appro.CreateTime = DateTime.Now;
  26925. var thisId = _sqlSugar.Insertable<Grp_ApprovalTravel>(appro).ExecuteReturnIdentity();
  26926. appro.Id = thisId;
  26927. //foreach (var item in gwinfo)
  26928. //{
  26929. // Grp_ApprovalTravelDetails chi = new Grp_ApprovalTravelDetails();
  26930. // chi.Details = "拜访" + item.Client;
  26931. // if (!string.IsNullOrWhiteSpace(item.ReqSample))
  26932. // {
  26933. // chi.Details += "," + item.ReqSample;
  26934. // }
  26935. // chi.ParentId = thisId;
  26936. // chi.Time = item.Time;
  26937. // chiarr.Add(chi);
  26938. //}
  26939. if (chiarr.Count < 6)
  26940. {
  26941. for (int j = chiarr.Count; j < 6; j++)
  26942. {
  26943. chiarr.Add(new
  26944. Grp_ApprovalTravelDetails());
  26945. }
  26946. }
  26947. resultArr.Add(new
  26948. {
  26949. appro.Id,
  26950. appro.Date,
  26951. appro.Diid,
  26952. chiList = chiarr.Select(x1 => new
  26953. {
  26954. timeInterval = string.IsNullOrWhiteSpace(x1.Time) ? new string[1] : x1.Time.Split('-'),
  26955. x1.Details,
  26956. x1.ParentId,
  26957. x1.Id
  26958. })
  26959. });
  26960. }
  26961. _sqlSugar.CommitTran();
  26962. jw = JsonView(true, "生成成功!", resultArr);
  26963. }
  26964. catch (Exception ex)
  26965. {
  26966. jw.Code = 400;
  26967. jw.Msg = "生成失败!" + ex.Message;
  26968. }
  26969. return Ok(jw);
  26970. }
  26971. /// <summary>
  26972. /// 报批行程word导出
  26973. /// </summary>
  26974. /// <param name="dto"></param>
  26975. /// <returns></returns>
  26976. [HttpPost]
  26977. public IActionResult ExportApprovalJourneyWord(ExportApprovalJourneyWord dto)
  26978. {
  26979. var jw = JsonView(false);
  26980. var group = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  26981. if (group == null)
  26982. {
  26983. jw.Msg = "暂无该团组!";
  26984. return Ok(jw);
  26985. }
  26986. //模板路径
  26987. string tempPath = AppSettingsHelper.Get("WordBasePath") + "Template/";
  26988. var fileName = string.Empty;
  26989. string titleFont = string.Empty, timeFont = string.Empty, contentFont = string.Empty;
  26990. bool bold = false;
  26991. if (dto.FileIndex == 1)
  26992. {
  26993. fileName = "公务行程导出模板.docx"; //"C:\\Server\\File\\OA2023\\Office\\Word\\Template/公务行程导出模板.docx"
  26994. }
  26995. else if (dto.FileIndex == 2)
  26996. {
  26997. fileName = "省外办-报批.docx";
  26998. bold = false;
  26999. titleFont = "方正黑体简体";
  27000. timeFont = "Times New Roman";
  27001. contentFont = "方正仿宋_GBK";
  27002. }
  27003. else if (dto.FileIndex == 3)
  27004. {
  27005. fileName = "市外办-报批.docx";
  27006. titleFont = "方正黑体简体";
  27007. timeFont = "Times New Roman";
  27008. contentFont = "方正仿宋简体";
  27009. }
  27010. tempPath = tempPath + fileName;
  27011. //载入模板
  27012. Document doc = new Document(tempPath);
  27013. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  27014. //获取所填表格的序数
  27015. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  27016. Aspose.Words.Tables.Row titleRowClone = null;
  27017. Aspose.Words.Tables.Row CenterRowClone = null;
  27018. int index = 0;
  27019. int indexChi = 0;
  27020. int SetIndex = 0;
  27021. var ApprovalTravelArr = _sqlSugar.Queryable<Grp_ApprovalTravel>().Where(x => x.IsDel == 0 && x.Diid == dto.Diid).ToList();
  27022. //获取数据,放到datatable
  27023. foreach (var item in ApprovalTravelArr)
  27024. {
  27025. if (index > 0)
  27026. {
  27027. titleRowClone = (Aspose.Words.Tables.Row)tableOne.Rows[0].Clone(true);
  27028. tableOne.AppendChild(titleRowClone);
  27029. }
  27030. var textTime = item.Date;
  27031. var ChiRep = _sqlSugar.Queryable<Grp_ApprovalTravelDetails>().Where(x => x.IsDel == 0 && x.ParentId == item.Id).ToList();
  27032. SetCells(tableOne, doc, SetIndex, 0, textTime, titleFont, bold);
  27033. SetIndex++;
  27034. if (ChiRep.Count > 0)
  27035. {
  27036. foreach (var itemChi in ChiRep)
  27037. {
  27038. var txtTime = itemChi.Time;
  27039. var txtDetail = itemChi.Details;
  27040. if (string.IsNullOrEmpty(txtTime) && string.IsNullOrEmpty(txtDetail))
  27041. {
  27042. //SetCells(tableOne, doc, SetIndex, 0, "", timeFont, bold);
  27043. //SetCells(tableOne, doc, SetIndex, 1, "", contentFont, bold);
  27044. //indexChi++;
  27045. //SetIndex++;
  27046. break;
  27047. }
  27048. if (indexChi > 0)
  27049. {
  27050. CenterRowClone = (Aspose.Words.Tables.Row)tableOne.Rows[1].Clone(true);
  27051. tableOne.AppendChild(CenterRowClone);
  27052. }
  27053. SetCells(tableOne, doc, SetIndex, 0, txtTime, timeFont, bold);
  27054. SetCells(tableOne, doc, SetIndex, 1, txtDetail, contentFont, bold);
  27055. indexChi++;
  27056. SetIndex++;
  27057. }
  27058. }
  27059. //else
  27060. //{
  27061. // if (indexChi > 0)
  27062. // {
  27063. // CenterRowClone = (Aspose.Words.Tables.Row)tableOne.Rows[1].Clone(true);
  27064. // tableOne.AppendChild(CenterRowClone);
  27065. // }
  27066. // SetCells(tableOne, doc, SetIndex, 0, "",timeFont, bold);
  27067. // SetCells(tableOne, doc, SetIndex, 1, "", contentFont, bold);
  27068. // indexChi++;
  27069. // SetIndex++;
  27070. //}
  27071. index++;
  27072. }
  27073. string strFileName = "/Travel/ExportApprovalJourneyWord/" + group.TeamName + fileName;
  27074. doc.Save(AppSettingsHelper.Get("WordBasePath") + strFileName, Aspose.Words.SaveFormat.Docx); //"C:\\Server\\File\\OA2023\\Office\\Word" + strFileName
  27075. jw.Data = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + strFileName; //"C:\\Server\\File\\OA2023\\Office\\Word" + strFileName
  27076. jw.Code = 200;
  27077. jw.Msg = "";
  27078. return Ok(jw);
  27079. }
  27080. private string ParseBlackTime(string time)
  27081. {
  27082. // 匹配可能只有分钟的情况
  27083. string pattern = @"(?:(\d+)H)?(?:(\d+)M)?";
  27084. System.Text.RegularExpressions.Match match = Regex.Match(time, pattern);
  27085. if (match.Success)
  27086. {
  27087. string hours = match.Groups[1].Value;
  27088. string minutes = match.Groups[2].Value;
  27089. // 如果小时部分为空,则只显示分钟
  27090. if (string.IsNullOrEmpty(hours))
  27091. {
  27092. return $"{minutes}分钟";
  27093. }
  27094. // 如果分钟部分为空,则只显示小时
  27095. else if (string.IsNullOrEmpty(minutes))
  27096. {
  27097. return $"{hours}小时";
  27098. }
  27099. // 否则显示完整格式
  27100. else
  27101. {
  27102. return $"{hours}小时{minutes}分钟";
  27103. }
  27104. }
  27105. else
  27106. {
  27107. return "未知时长";
  27108. }
  27109. }
  27110. private string intToString(int numberVal)
  27111. {
  27112. string numberval = numberVal.ToString();
  27113. Dictionary<char, string> Number = new Dictionary<char, string>();
  27114. Number.Add('1', "一");
  27115. Number.Add('2', "二");
  27116. Number.Add('3', "三");
  27117. Number.Add('4', "四");
  27118. Number.Add('5', "五");
  27119. Number.Add('6', "六");
  27120. Number.Add('7', "七");
  27121. Number.Add('8', "八");
  27122. Number.Add('9', "九");
  27123. string stringNumberVal = string.Empty;
  27124. for (int i = 0; i < numberval.Length; i++)
  27125. {
  27126. if (i == 0)
  27127. {
  27128. stringNumberVal += Number[numberval[i]];
  27129. }
  27130. else if (i >= 1)
  27131. {
  27132. if (numberval[i] == '0')
  27133. {
  27134. stringNumberVal = "十";
  27135. }
  27136. else
  27137. {
  27138. stringNumberVal += "十" + Number[numberval[i]];
  27139. }
  27140. }
  27141. }
  27142. return stringNumberVal;
  27143. }
  27144. private void SetCells(Aspose.Words.Tables.Table table, Document doc, int rows, int cells, string val, string font, bool bold)
  27145. {
  27146. //获取table中的某个单元格,从0开始
  27147. Cell lshCell = table.Rows[rows].Cells[cells];
  27148. //将单元格中段落移除
  27149. foreach (Paragraph item in lshCell.Paragraphs)
  27150. {
  27151. lshCell.Paragraphs.Remove(item);
  27152. }
  27153. if (val.Contains("\r\n"))
  27154. {
  27155. var spArr = val.Split("\r\n").Where(x => !string.IsNullOrWhiteSpace(x));
  27156. foreach (var item in spArr)
  27157. {
  27158. //新建一个段落
  27159. Paragraph p = new Paragraph(doc);
  27160. var r = new Run(doc, item);
  27161. //设置字体
  27162. if (!string.IsNullOrEmpty(font))
  27163. {
  27164. r.Font.Name = font;
  27165. }
  27166. r.Font.Bold = bold;
  27167. //把设置的值赋给之前新建的段落
  27168. p.AppendChild(r);
  27169. //将此段落加到单元格内
  27170. lshCell.AppendChild(p);
  27171. }
  27172. }
  27173. else
  27174. {
  27175. //新建一个段落
  27176. Paragraph p = new Paragraph(doc);
  27177. var r = new Run(doc, val);
  27178. //设置字体
  27179. if (!string.IsNullOrEmpty(font))
  27180. {
  27181. r.Font.Name = font;
  27182. }
  27183. r.Font.Bold = bold;
  27184. //把设置的值赋给之前新建的段落
  27185. p.AppendChild(r);
  27186. //将此段落加到单元格内
  27187. lshCell.AppendChild(p);
  27188. }
  27189. }
  27190. /// <summary>
  27191. /// 报批行程AI续写
  27192. /// </summary>
  27193. /// <returns></returns>
  27194. [HttpPost]
  27195. public async Task<IActionResult> ApprovalJourneyAiWrite(ApprovalJourneyAiWriteDto dto)
  27196. {
  27197. var jw = JsonView(false);
  27198. if (dto.ClientPurpose.IsNullOrWhiteSpace() || dto.ClientName.IsNullOrWhiteSpace())
  27199. {
  27200. jw.Msg = "参数有误!";
  27201. return Ok(jw);
  27202. }
  27203. KiMiApiClient kiMi = new KiMiApiClient();
  27204. List<SeedMessages> messages = new List<SeedMessages>() {
  27205. new SeedMessages
  27206. {
  27207. Role = KimiRole.system,
  27208. Content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。"
  27209. },
  27210. new SeedMessages
  27211. {
  27212. Role = KimiRole.user,
  27213. Content = $@"参考这个模板格式来编写一份{dto.ClientName}拜访{dto.ClientPurpose},结合{dto.ClientName}的业务,描述拜访目的,字数在200字内(直接给出拜访目的,不输出其他内容)"
  27214. }
  27215. };
  27216. var kimi_result = await kiMi.SeedMessageByFullConterObject(messages);
  27217. string data = kimi_result.Choices[0]?.Message.Content;
  27218. if (string.IsNullOrWhiteSpace(data))
  27219. {
  27220. jw.Data = "Ai续写失败!";
  27221. }
  27222. else
  27223. {
  27224. jw = JsonView(true, "success!", data);
  27225. }
  27226. return Ok(jw);
  27227. }
  27228. #endregion
  27229. #region 团组接待意见调查
  27230. /// <summary>
  27231. /// 团组接待意见调查 - 信息管理
  27232. /// 基础数据(团组)
  27233. /// </summary>
  27234. /// <returns></returns>
  27235. [HttpGet]
  27236. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27237. public async Task<IActionResult> OpinionaireInit()
  27238. {
  27239. var groupData = await _groupRepository.Query(x => x.IsDel == 0)
  27240. .Select(x => new
  27241. {
  27242. x.Id,
  27243. GroupName = $"[{x.VisitDate.ToString("yyyy-MM-dd")}]{x.TeamName}"
  27244. })
  27245. .OrderByDescending(x => x.Id)
  27246. .ToListAsync();
  27247. return Ok(JsonView(groupData, groupData.Count));
  27248. }
  27249. /// <summary>
  27250. /// 团组接待意见调查 - 信息管理
  27251. /// 列表
  27252. /// </summary>
  27253. /// <param name="groupId"></param>
  27254. /// <returns></returns>
  27255. [HttpGet("{groupId}")]
  27256. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27257. public async Task<IActionResult> OpinionaireManageList(int groupId)
  27258. {
  27259. if (groupId < 1) Ok(JsonView(false, "请传入有效的diId"));
  27260. var data = await _opinionaireRep.Query(x => x.DiId == groupId)
  27261. .Select(x => new
  27262. {
  27263. x.Id,
  27264. x.TourGuideName,
  27265. x.CityName,
  27266. CreateUserName = SqlFunc.Subqueryable<Sys_Users>().Where(x1 => x.CreateUserId == x1.Id).Select(x1 => x1.CnName),
  27267. x.CreateTime
  27268. })
  27269. .OrderBy(x => x.Id)
  27270. .ToListAsync();
  27271. return Ok(JsonView(data));
  27272. }
  27273. /// <summary>
  27274. /// 团组接待意见调查 - 信息管理
  27275. /// 保存
  27276. /// </summary>
  27277. /// <param name="dto"></param>
  27278. /// <returns></returns>
  27279. [HttpPost]
  27280. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27281. public async Task<IActionResult> OpinionaireManageSave(OpinionaireManageSaveDto dto)
  27282. {
  27283. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  27284. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  27285. if (dto.DiId < 1) Ok(JsonView(false, "请传入有效的diId"));
  27286. if (dto.Items.Length < 1) Ok(JsonView(false, "请传入需要保存的信息"));
  27287. var addData = _mapper.Map<List<Grp_Opinionaire>>(dto.Items.Where(x => x.Id == 0).ToList());
  27288. var updData = _mapper.Map<List<Grp_Opinionaire>>(dto.Items.Where(x => x.Id > 0).ToList());
  27289. _opinionaireRep.BeginTran();
  27290. if (addData != null && addData.Count > 0)
  27291. {
  27292. foreach (var item in addData)
  27293. {
  27294. item.CreateUserId = currUserInfo.UserId;
  27295. item.DiId = dto.DiId;
  27296. }
  27297. var add = await _opinionaireRep._sqlSugar.Insertable(addData).ExecuteCommandAsync();
  27298. }
  27299. if (updData != null && updData.Count > 0)
  27300. {
  27301. var upd = await _opinionaireRep._sqlSugar
  27302. .Updateable(updData)
  27303. .UpdateColumns(x => new { x.CityName, x.TourGuideName })
  27304. .WhereColumns(x => new { x.Id })
  27305. .ExecuteCommandAsync();
  27306. }
  27307. _opinionaireRep.CommitTran();
  27308. return Ok(JsonView("操作成功!"));
  27309. }
  27310. /// <summary>
  27311. /// 团组接待意见调查 - 信息管理
  27312. /// 删除
  27313. /// </summary>
  27314. /// <param name="id"></param>
  27315. /// <returns></returns>
  27316. [HttpDelete("{id}")]
  27317. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27318. public async Task<IActionResult> OpinionaireManageDel(int id)
  27319. {
  27320. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  27321. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  27322. if (id < 1) Ok(JsonView(false, "请传入有效的id"));
  27323. var del = await _opinionaireRep.SoftDeleteAsync(x => x.Id == id, currUserInfo.UserId);
  27324. if (!del) return Ok(JsonView("操作失败!"));
  27325. return Ok(JsonView("操作成功!"));
  27326. }
  27327. /// <summary>
  27328. /// 团组接待意见调查 - 用户
  27329. /// 列表
  27330. /// </summary>
  27331. /// <param name="diId"></param>
  27332. /// <returns></returns>
  27333. [HttpGet("{diId}")]
  27334. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27335. public async Task<IActionResult> OpinionaireUserList(int diId)
  27336. {
  27337. if (diId < 1) Ok(JsonView(false, "请传入有效的diId"));
  27338. var sql = string.Format(@"
  27339. SELECT
  27340. o.Id,
  27341. o.DiId,
  27342. di.TeamName AS 'GroupName',
  27343. di.VisitPNumber AS 'PeopleNumber',
  27344. di.ClientName AS 'LeadGroup',
  27345. di.VisitCountry AS 'Travel',
  27346. di.VisitDays AS 'Days',
  27347. o.CityName,
  27348. o.TourGuideName,
  27349. o.Catering,
  27350. o.CateringReason,
  27351. o.Stay,
  27352. o.StayReason,
  27353. o.[Route],
  27354. o.RouteReason,
  27355. o.OfficialActivity,
  27356. o.OfficialActivityReason,
  27357. o.TourGuide,
  27358. o.TourGuideReason,
  27359. o.[Translate],
  27360. o.TranslateReason,
  27361. o.Trip,
  27362. o.TripReason,
  27363. o.ESFileName,
  27364. o.SignatureDate,
  27365. o.Remark
  27366. FROM
  27367. Grp_Opinionaire o
  27368. LEFT JOIN Grp_DelegationInfo di ON o.DiId = di.Id
  27369. WHERE
  27370. o.IsDel = 0
  27371. AND o.DiId = {0}
  27372. ORDER BY
  27373. o.Id ASC", diId);
  27374. var data = await _sqlSugar.SqlQueryable<OpinionaireUserListView>(sql).ToListAsync();
  27375. if (data.Count < 1) return Ok(JsonView(false, "暂无数据"));
  27376. return Ok(JsonView(data));
  27377. }
  27378. /// <summary>
  27379. /// 团组接待意见调查 - 用户
  27380. /// 保存
  27381. /// </summary>
  27382. /// <param name="dto"></param>
  27383. /// <returns></returns>
  27384. [HttpPost]
  27385. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27386. public async Task<IActionResult> OpinionaireUserSave([FromForm] OpinionaireUserSaveInfo[] dto)
  27387. {
  27388. if (dto.Length < 1) Ok(JsonView(false, "请传入有效的参数"));
  27389. foreach (var item in dto)
  27390. {
  27391. if (string.IsNullOrEmpty(item.Catering)) Ok(JsonView(false, "请选择餐饮评分!"));
  27392. if (string.IsNullOrEmpty(item.Stay)) Ok(JsonView(false, "请选择住宿评分!"));
  27393. if (string.IsNullOrEmpty(item.Route)) Ok(JsonView(false, "请选择行程评分!"));
  27394. if (string.IsNullOrEmpty(item.OfficialActivity)) Ok(JsonView(false, "请选择公务活动评分!"));
  27395. if (string.IsNullOrEmpty(item.Translate)) Ok(JsonView(false, "请选择翻译评分!"));
  27396. if (string.IsNullOrEmpty(item.Trip)) Ok(JsonView(false, "请选择行程评分!"));
  27397. if (string.IsNullOrEmpty(item.SignatureDate)) Ok(JsonView(false, "请填写签名日期!"));
  27398. if (item.File.Length < 1) Ok(JsonView(false, "请上传签名图片!"));
  27399. }
  27400. var filePathBase = $"{AppSettingsHelper.Get("GrpFileBasePath")}OpinionaireElectronicSignature";
  27401. if (!Directory.Exists(filePathBase))
  27402. {
  27403. Directory.CreateDirectory(filePathBase);
  27404. }
  27405. #region 上传文件
  27406. var filePaths = new List<string>();
  27407. foreach (var item in dto)
  27408. {
  27409. var file = item.File;
  27410. // 将文件保存到指定位置
  27411. var filePath = Path.Combine(filePathBase, file.FileName);
  27412. using (var stream = new FileStream(filePath, FileMode.Create))
  27413. {
  27414. await file.CopyToAsync(stream);
  27415. }
  27416. //验证文件是否上传成功
  27417. if (!System.IO.File.Exists(filePath))
  27418. {
  27419. foreach (var filePathStr in filePaths)
  27420. {
  27421. System.IO.File.Delete(filePathStr);
  27422. }
  27423. return Ok(JsonView(false, "文件上传失败!"));
  27424. }
  27425. item.ESFileName = file.FileName;
  27426. }
  27427. #endregion
  27428. var infos = _mapper.Map<List<Grp_Opinionaire>>(dto);
  27429. var upd = await _sqlSugar.Updateable<Grp_Opinionaire>(infos)
  27430. .UpdateColumns(x => new
  27431. {
  27432. x.Catering,
  27433. x.CateringReason,
  27434. x.Stay,
  27435. x.StayReason,
  27436. x.Route,
  27437. x.RouteReason,
  27438. x.OfficialActivity,
  27439. x.OfficialActivityReason,
  27440. x.TourGuide,
  27441. x.TourGuideReason,
  27442. x.Translate,
  27443. x.TranslateReason,
  27444. x.Trip,
  27445. x.TripReason,
  27446. x.ESFileName,
  27447. x.SignatureDate,
  27448. x.Remark
  27449. })
  27450. .WhereColumns(x => new { x.Id })
  27451. .ExecuteCommandAsync();
  27452. if (upd < 1)
  27453. {
  27454. foreach (var filePathStr in filePaths)
  27455. {
  27456. System.IO.File.Delete(filePathStr);
  27457. }
  27458. return Ok(JsonView(false));
  27459. }
  27460. return Ok(JsonView(true));
  27461. }
  27462. #endregion
  27463. #region 团组餐厅相关信息
  27464. /// <summary>
  27465. /// 团组相关餐厅信息
  27466. /// 基础数据(团组)
  27467. /// </summary>
  27468. /// <returns></returns>
  27469. [HttpGet]
  27470. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27471. public async Task<IActionResult> RestaurantInit()
  27472. {
  27473. return Ok(await _restaurantRep.InitAsync());
  27474. }
  27475. /// <summary>
  27476. /// 团组相关餐厅信息
  27477. /// Item
  27478. /// </summary>
  27479. /// <param name="dto"></param>
  27480. /// <returns></returns>
  27481. [HttpPost]
  27482. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27483. public async Task<IActionResult> RestaurantItem(RestaurantItemDto dto)
  27484. {
  27485. int portType = dto.PortType,
  27486. groupId = dto.GroupId;
  27487. if (!SharingStaticData.PortTypes.Contains(portType)) return Ok(JsonView(false, MsgTips.Port));
  27488. if (groupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  27489. return Ok(await _restaurantRep.ItemAsync(portType, groupId));
  27490. }
  27491. /// <summary>
  27492. /// 团组相关餐厅信息
  27493. /// List
  27494. /// </summary>
  27495. /// <param name="dto"></param>
  27496. /// <returns></returns>
  27497. [HttpPost]
  27498. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27499. public async Task<IActionResult> RestaurantList(RestaurantItemDto dto)
  27500. {
  27501. int portType = dto.PortType,
  27502. groupId = dto.GroupId;
  27503. if (!SharingStaticData.PortTypes.Contains(portType)) return Ok(JsonView(false, MsgTips.Port));
  27504. if (groupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  27505. var sql = string.Format(@" SELECT
  27506. ri.Id,
  27507. ri.GroupId,
  27508. ri.Date,
  27509. ri.StartTime,
  27510. ri.EndTime,
  27511. CASE WHEN ri.Type = 1 THEN '早餐'
  27512. WHEN ri.Type = 2 THEN '午餐'
  27513. WHEN ri.Type = 3 THEN '晚餐'
  27514. ELSE '其他'
  27515. END AS 'Type',
  27516. ri.Name,
  27517. ri.Address,
  27518. ri.Tel,
  27519. ri.Remark,
  27520. ri.CreateTime,
  27521. u.CnName AS CreateUserName
  27522. FROM
  27523. Grp_RestaurantInfo ri
  27524. LEFT JOIN Sys_Users u ON ri.CreateUserId = u.Id
  27525. WHERE
  27526. ri.IsDel = 0
  27527. AND ri.GroupId = {0}
  27528. ORDER BY
  27529. ri.Date ASC
  27530. ", groupId);
  27531. var infos = await _sqlSugar.SqlQueryable<RestaurantItemView>(sql).ToListAsync();
  27532. if (!infos.Any()) Ok(JsonView(false, "数据未填写!"));
  27533. return Ok(JsonView(infos));
  27534. }
  27535. /// <summary>
  27536. /// 团组相关餐厅信息
  27537. /// Info
  27538. /// </summary>
  27539. /// <param name="dto"></param>
  27540. /// <returns></returns>
  27541. [HttpPost]
  27542. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27543. public async Task<IActionResult> RestaurantInfo(RestaurantInfoDto dto)
  27544. {
  27545. int portType = dto.PortType,
  27546. id = dto.Id;
  27547. if (!SharingStaticData.PortTypes.Contains(portType)) return Ok(JsonView(false, MsgTips.Port));
  27548. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  27549. return Ok(await _restaurantRep.InfoAsync(portType, id));
  27550. }
  27551. /// <summary>
  27552. /// 团组相关餐厅信息
  27553. /// Op
  27554. /// </summary>
  27555. /// <param name="dto"></param>
  27556. /// <returns></returns>
  27557. [HttpPost]
  27558. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27559. public async Task<IActionResult> RestaurantOp(RestaurantOpDto dto)
  27560. {
  27561. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  27562. if (dto.GroupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  27563. if (string.IsNullOrEmpty(dto.Name)) return Ok(JsonView(false, "餐厅名称为空!"));
  27564. return Ok(await _restaurantRep.OpAsync(dto));
  27565. }
  27566. /// <summary>
  27567. /// 团组相关餐厅信息
  27568. /// Del
  27569. /// </summary>
  27570. /// <param name="dto"></param>
  27571. /// <returns></returns>
  27572. [HttpPost]
  27573. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27574. public async Task<IActionResult> RestaurantDel(RestaurantDelDto dto)
  27575. {
  27576. int userId = dto.DeleteUserId;
  27577. var id = dto.Id;
  27578. if (userId < 1) return Ok(JsonView(false, MsgTips.UserId));
  27579. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  27580. return Ok(await _restaurantRep.DelAsync(dto));
  27581. }
  27582. #endregion
  27583. #region 团组会务成本
  27584. /// <summary>
  27585. /// 团组会务成本数据初始化
  27586. /// </summary>
  27587. /// <returns></returns>
  27588. [HttpPost]
  27589. public async Task<IActionResult> ConferenceAffairsInIt(ConferenceAffairsInItDto Dto)
  27590. {
  27591. var expr = _sqlSugar.Queryable<Grp_DelegationInfo>()
  27592. .OrderByDescending(x => x.CreateTime)
  27593. .Where(x => x.IsDel == 0)
  27594. .Select<DelegationEasyView>();
  27595. DelegationEasyView di = Dto.GroupId == 0 ?
  27596. expr.First() :
  27597. expr.First(x => x.Id == Dto.GroupId);
  27598. if (di == null)
  27599. {
  27600. return Ok(JsonView(false, "团组信息不存在!"));
  27601. }
  27602. var typeData = await _sqlSugar.Queryable<Sys_SetData>()
  27603. .Where(x => x.IsDel == 0 && x.STid == 21)
  27604. .Select(x => new { x.Id, Text = x.Name })
  27605. .ToListAsync();
  27606. var hwids = _sqlSugar.Queryable<Sys_SetData>()
  27607. .Where(x => x.IsDel == 0 && x.STid == 10 && x.Name.Contains("会务活动"))
  27608. .Select(x => x.Id)
  27609. .ToList();
  27610. //仅检索会务团组
  27611. var groupList = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  27612. .Where(x => x.IsDel == 0 && hwids.Contains(x.TeamDid))
  27613. .OrderByDescending(x => x.VisitDate)
  27614. .Select(x => new { x.Id, x.TeamName })
  27615. .ToListAsync();
  27616. var currenyList = await GeneralMethod.PostGroupTeamRateByDiIdAndCTableId(1, di.Id, 98);
  27617. var userList = await _sqlSugar.Queryable<Sys_Users>()
  27618. .Where(x => x.IsDel == 0)
  27619. .Select(x => new { x.Id, x.CnName })
  27620. .ToListAsync();
  27621. var units = await _sqlSugar.Queryable<Sys_SetData>()
  27622. .Where(x => x.IsDel == 0 && x.STid == 119)
  27623. .Select(x => new { x.Id, Text = x.Name })
  27624. .ToListAsync();
  27625. var FileType = new[]
  27626. {
  27627. new { Id = 0 , Name = "成本下载" },
  27628. new { Id = 1 , Name = "报价下载" },
  27629. new { Id = 2 , Name = "总表下载" },
  27630. };
  27631. var GM = new List<int>();
  27632. var permissionControlDB = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == 1448)?.Remark;
  27633. try
  27634. {
  27635. GM = JsonConvert.DeserializeObject<List<int>>(permissionControlDB);
  27636. }
  27637. catch (Exception ex)
  27638. {
  27639. GM = new List<int>() { 21 };
  27640. }
  27641. var isReview = Dto.UserId == 21;
  27642. var isGM = GM.Contains(Dto.UserId);
  27643. var ConferenceAffairsCost = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
  27644. .Where(x => x.IsDel == 0)
  27645. .Select<ConferenceAffairsCostView>()
  27646. .First(x => x.Diid == di.Id);
  27647. if (ConferenceAffairsCost == null)
  27648. {
  27649. ConferenceAffairsCost = new ConferenceAffairsCostView();
  27650. ConferenceAffairsCost.Diid = di.Id;
  27651. }
  27652. #region 权限校验
  27653. var ids = _sqlSugar.Queryable<Grp_ConferenceAffairsCostControl>()
  27654. .Where(x => x.Diid == di.Id && x.IsDel == 0)
  27655. .Select(x => x.UserId)
  27656. .Distinct()
  27657. .ToList();
  27658. if (!ids.Contains(Dto.UserId) && !isGM)
  27659. {
  27660. return Ok(JsonView(201, "暂无权限!", new
  27661. {
  27662. typeData,
  27663. groupList,
  27664. currenyList,
  27665. isGM,
  27666. userList,
  27667. units,
  27668. isReview,
  27669. operatorUser = ids,
  27670. di,
  27671. FileType
  27672. }));
  27673. }
  27674. #endregion
  27675. var ConferenceAffairsCostChi = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  27676. .Where(x => x.IsDel == 0 && x.Diid == di.Id)
  27677. .Select<ConferenceAffairsCostChildView>()
  27678. .OrderBy(x => x.Index)
  27679. .ToList();
  27680. for (int i = 1; i <= ConferenceAffairsCostChi.Count; i++)
  27681. {
  27682. ConferenceAffairsCostChi[i - 1].Index = i;
  27683. }
  27684. var backData = new
  27685. {
  27686. ConferenceAffairsCost,
  27687. ConferenceAffairsCostChi,
  27688. typeData,
  27689. groupList,
  27690. currenyList,
  27691. isGM,
  27692. userList,
  27693. units,
  27694. isReview,
  27695. operatorUser = ids,
  27696. di,
  27697. FileType
  27698. };
  27699. return Ok(JsonView(true, "SUCCESS", backData));
  27700. }
  27701. /// <summary>
  27702. /// 会务成本保存
  27703. /// </summary>
  27704. /// <returns></returns>
  27705. [HttpPost]
  27706. public async Task<IActionResult> ConferenceAffairsSave(ConferenceAffairsSaveDto Dto)
  27707. {
  27708. _sqlSugar.BeginTran();
  27709. var data = _mapper.Map<Grp_ConferenceAffairsCost>(Dto.ConferenceAffairsCost);
  27710. var childResult = new
  27711. {
  27712. success = 0,
  27713. error = 0
  27714. };
  27715. try
  27716. {
  27717. if (data.Id == 0)
  27718. {
  27719. _sqlSugar.Updateable<Grp_ConferenceAffairsCost>()
  27720. .Where(x => x.Diid == Dto.GroupId)
  27721. .SetColumns(x => new Grp_ConferenceAffairsCost
  27722. {
  27723. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  27724. DeleteUserId = Dto.UserId
  27725. })
  27726. .ExecuteCommand();
  27727. data.Diid = Dto.GroupId;
  27728. data.CreateTime = DateTime.Now;
  27729. data.CreateUserId = Dto.UserId;
  27730. data.Id = _sqlSugar.Insertable<Grp_ConferenceAffairsCost>(data)
  27731. .ExecuteReturnIdentity();
  27732. }
  27733. else
  27734. {
  27735. _sqlSugar.Updateable<Grp_ConferenceAffairsCost>(data)
  27736. .ExecuteCommand();
  27737. data.Id = data.Id;
  27738. }
  27739. if (Dto.ConferenceAffairsCostChild.Any())
  27740. {
  27741. var datas = _mapper.Map<List<Grp_ConferenceAffairsCostChild>>(Dto.ConferenceAffairsCostChild);
  27742. var insertArr = datas.Where(x => x.Id == 0).ToList();
  27743. var updateArr = datas.Where(x => x.Id != 0 && x.ReviewStatus != 1).ToList();
  27744. var notUpdateArr = datas.Where(x => x.Id != 0 && x.ReviewStatus == 1).ToList();
  27745. insertArr.ForEach(x => { x.Diid = Dto.GroupId; x.ConferenceAffairsCostId = data.Id; });
  27746. var inrsetCount = insertArr.Any() ? _sqlSugar.Insertable<Grp_ConferenceAffairsCostChild>(insertArr).ExecuteCommand() : 0;
  27747. var updateCount = updateArr.Any() ? _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>(updateArr)
  27748. .IgnoreColumns(x => new { x.ConferenceAffairsCostId })
  27749. .ExecuteCommand() : 0;
  27750. childResult = childResult with
  27751. {
  27752. error = notUpdateArr.Count(),
  27753. success = inrsetCount + updateCount
  27754. };
  27755. }
  27756. _sqlSugar.CommitTran();
  27757. }
  27758. catch (Exception ex)
  27759. {
  27760. _sqlSugar.RollbackTran();
  27761. return Ok(JsonView(false, "失败!" + ex.Message));
  27762. }
  27763. return Ok(JsonView(true, "操作成功!", childResult));
  27764. }
  27765. [HttpPost]
  27766. public async Task<IActionResult> ConferenceAffairsAudit(ConferenceAffairsAuditDto Dto)
  27767. {
  27768. var count = 0;
  27769. if (Dto.ConferenceAffairsCostChildids.Any())
  27770. {
  27771. count = _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>().
  27772. Where(x => Dto.ConferenceAffairsCostChildids.Contains(x.Id)).
  27773. SetColumns(x => new Grp_ConferenceAffairsCostChild
  27774. {
  27775. ReviewStatus = Dto.ReviewStatus
  27776. }).
  27777. ExecuteCommand();
  27778. }
  27779. return Ok(JsonView(true, "操作成功!", count));
  27780. }
  27781. /// <summary>
  27782. /// 会务成本所有数据清除
  27783. /// </summary>
  27784. /// <param name="Dto"></param>
  27785. /// <returns></returns>
  27786. [HttpPost]
  27787. public async Task<IActionResult> ConferenceAffairsDelete(ConferenceAffairsDeleteDto Dto)
  27788. {
  27789. if (Dto.GroupId < 1) return Ok(JsonView(false, "请传入有效的Id"));
  27790. if (Dto.UserId < 1) return Ok(JsonView(false, "请传入有效的用户Id"));
  27791. _sqlSugar.BeginTran();
  27792. try
  27793. {
  27794. var delCount = _sqlSugar.Updateable<Grp_ConferenceAffairsCost>()
  27795. .Where(x => x.Diid == Dto.GroupId)
  27796. .SetColumns(x => new Grp_ConferenceAffairsCost
  27797. {
  27798. IsDel = 1,
  27799. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  27800. DeleteUserId = Dto.UserId
  27801. })
  27802. .ExecuteCommand();
  27803. if (delCount > 0)
  27804. {
  27805. _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>()
  27806. .Where(x => x.Diid == Dto.GroupId)
  27807. .SetColumns(x => new Grp_ConferenceAffairsCostChild
  27808. {
  27809. IsDel = 1,
  27810. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  27811. DeleteUserId = Dto.UserId
  27812. })
  27813. .ExecuteCommand();
  27814. _sqlSugar.Updateable<Grp_ConferenceAffairsCostControl>()
  27815. .Where(x => x.Diid == Dto.GroupId && x.IsDel == 0)
  27816. .SetColumns(x => new Grp_ConferenceAffairsCostControl
  27817. {
  27818. IsDel = 1,
  27819. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  27820. DeleteUserId = Dto.UserId
  27821. })
  27822. .ExecuteCommand();
  27823. }
  27824. _sqlSugar.CommitTran();
  27825. }
  27826. catch (Exception ex)
  27827. {
  27828. _sqlSugar.RollbackTran();
  27829. return Ok(JsonView(false, "操作失败!" + ex.Message));
  27830. }
  27831. return Ok(JsonView(true, "操作成功!"));
  27832. }
  27833. /// <summary>
  27834. /// 子项数据删除
  27835. /// </summary>
  27836. /// <param name="Dto"></param>
  27837. /// <returns></returns>
  27838. [HttpPost]
  27839. public async Task<IActionResult> ConferenceAffairSinglesDelete(ConferenceAffairsDeleteSingleDto Dto)
  27840. {
  27841. var isAudit = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>().Where(x => x.IsDel == 0 && Dto.ids.Contains(x.Id))
  27842. .Any(x => x.ReviewStatus == 1);
  27843. if (isAudit) return Ok(JsonView(false, "包含已审核数据无法删除!"));
  27844. var count = _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>()
  27845. .Where(x => Dto.ids.Contains(x.Id) && x.IsDel == 0)
  27846. .SetColumns(x => new Grp_ConferenceAffairsCostChild
  27847. {
  27848. IsDel = 1,
  27849. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  27850. DeleteUserId = Dto.UserId
  27851. })
  27852. .ExecuteCommand();
  27853. return Ok(JsonView(true, "SUCCESS!", count));
  27854. }
  27855. /// <summary>
  27856. /// 会务成本权限分配
  27857. /// </summary>
  27858. /// <param name="Dto"></param>
  27859. /// <returns></returns>
  27860. [HttpPost]
  27861. public async Task<IActionResult> PermissionSetting(PermissionSettingDto Dto)
  27862. {
  27863. _sqlSugar.BeginTran();
  27864. var count = 0;
  27865. try
  27866. {
  27867. _sqlSugar.Updateable<Grp_ConferenceAffairsCostControl>()
  27868. .Where(x => x.Diid == Dto.GroupId && x.IsDel == 0)
  27869. .SetColumns(x => new Grp_ConferenceAffairsCostControl
  27870. {
  27871. IsDel = 1,
  27872. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  27873. DeleteUserId = Dto.CreateUserId
  27874. })
  27875. .ExecuteCommand();
  27876. count = _sqlSugar.Insertable<Grp_ConferenceAffairsCostControl>(Dto.UserIds.Select(x => new Grp_ConferenceAffairsCostControl
  27877. {
  27878. CreateTime = DateTime.Now,
  27879. CreateUserId = Dto.CreateUserId,
  27880. UserId = x,
  27881. Diid = Dto.GroupId,
  27882. }).ToList()).ExecuteCommand();
  27883. _sqlSugar.CommitTran();
  27884. }
  27885. catch (Exception ex)
  27886. {
  27887. _sqlSugar.RollbackTran();
  27888. return Ok(JsonView(false, "操作失败!" + ex.Message));
  27889. }
  27890. return Ok(JsonView(true, "操作成功!", count));
  27891. }
  27892. /// <summary>
  27893. /// 团组会务成本文件下载
  27894. /// </summary>
  27895. /// <returns></returns>
  27896. [HttpPost]
  27897. public async Task<IActionResult> ConferenceAffairsFileDown(ConferenceAffairsFileDownDto Dto)
  27898. {
  27899. var FileType = new[]
  27900. {
  27901. new { Id = 0 , Name = "成本下载" },
  27902. new { Id = 1 , Name = "报价下载" },
  27903. new { Id = 2 , Name = "总表下载" },
  27904. };
  27905. if (Dto.GroupId < 1) return Ok(JsonView(false, "请传入有效的Id"));
  27906. if (Dto.FileTypeId < 0 || Dto.FileTypeId > 2) return Ok(JsonView(false, "请传入有效的文件类型"));
  27907. var di = _sqlSugar.Queryable<Grp_DelegationInfo>()
  27908. .Where(x => x.IsDel == 0 && x.Id == Dto.GroupId)
  27909. .Select<DelegationEasyView>()
  27910. .First();
  27911. var main = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
  27912. .First(x => x.Diid == Dto.GroupId && x.IsDel == 0);
  27913. if (main == null)
  27914. {
  27915. return Ok(JsonView(false, "团组会务成本信息不存在!"));
  27916. }
  27917. JsonView jw = JsonView(false);
  27918. //总表下载
  27919. var loadPath = $"{AppSettingsHelper.Get("ExcelBasePath")}ConferenceAffairs/template/";
  27920. var outputPath = $"{AppSettingsHelper.Get("ExcelBasePath")}ConferenceAffairs/output/total/";
  27921. var networkPath = outputPath.Replace(AppSettingsHelper.Get("ExcelBasePath"), AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath"));
  27922. var field = string.Empty;
  27923. var fileTypeName = string.Empty;
  27924. field = @$"
  27925. a.[Index],a.PriceName,a.CostPrice,a.Count,a.Coefficient,a.BaoJiaPrice,a.AddedValue,a.Details,a.Remark,a.Rate,
  27926. b.Name as PriceTypeStr ,
  27927. c.Name as CurrencyStr ,
  27928. d.Name as UnitStr ,
  27929. case a.ReviewStatus
  27930. WHEN 1 THEN '已通过'
  27931. WHEN 0 THEN '未审核'
  27932. WHEN -1 THEN '未通过'
  27933. ELSE '未审核'
  27934. END AS ReviewStatusStr
  27935. ";
  27936. if (Dto.FileTypeId == 0)
  27937. {
  27938. fileTypeName = "会务成本成本表";
  27939. loadPath += $"{fileTypeName}.xlsx";
  27940. outputPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  27941. networkPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  27942. }
  27943. else if (Dto.FileTypeId == 1)
  27944. {
  27945. fileTypeName = "会务成本报价表";
  27946. loadPath += $"{fileTypeName}.xlsx";
  27947. outputPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  27948. networkPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  27949. }
  27950. else if (Dto.FileTypeId == 2)
  27951. {
  27952. fileTypeName = "会务成本总表";
  27953. loadPath += $"{fileTypeName}.xlsx";
  27954. outputPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  27955. networkPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  27956. }
  27957. var chiExcelContent = _sqlSugar.SqlQueryable<ConferenceAffairsExcelContent>(@$"
  27958. SELECT
  27959. {field}
  27960. FROM Grp_ConferenceAffairsCostChild a
  27961. LEFT JOIN Sys_SetData b on b.IsDel = 0 AND b.Id = a.PriceType
  27962. LEFT JOIN Sys_SetData c on c.IsDel = 0 AND c.Id = a.Currency
  27963. LEFT JOIN Sys_SetData d on d.IsDel = 0 AND d.Id = a.Unit
  27964. WHERE a.isdel = 0
  27965. AND a.Diid = {main.Diid}
  27966. AND a.ConferenceAffairsCostId = {main.Id}
  27967. ").ToList();
  27968. var currLists = chiExcelContent.Select(x => new CurrList
  27969. {
  27970. CurrName = x.CurrencyStr,
  27971. CurrRate = x.Rate
  27972. })
  27973. .Distinct()
  27974. .ToList();
  27975. var designer = new WorkbookDesigner
  27976. {
  27977. Workbook = new Workbook(loadPath)
  27978. };
  27979. var MostCurr = _sqlSugar.Queryable<Sys_SetData>().First(x => x.IsDel == 0 && x.Id == main.MostCurr);
  27980. MostCurr ??= new Sys_SetData { Name = "暂无!" };
  27981. designer.SetDataSource("TeamName", di.TeamName);
  27982. designer.SetDataSource("City", main.City);
  27983. designer.SetDataSource("AllCost", main.CostAll);
  27984. designer.SetDataSource("AllBaoJia", main.BaoJiaAll);
  27985. designer.SetDataSource("Curr", MostCurr.Name);
  27986. designer.SetDataSource("Curr1", MostCurr.Name);
  27987. DataTable dt = CommonFun.GetDataTableFromIList<ConferenceAffairsExcelContent>(chiExcelContent);
  27988. dt.TableName = "TB";
  27989. designer.SetDataSource(dt);
  27990. DataTable dt1 = CommonFun.GetDataTableFromIList<CurrList>(currLists);
  27991. dt1.TableName = "currTb";
  27992. designer.SetDataSource(dt1);
  27993. designer.Process();
  27994. designer.Workbook.Save(outputPath);
  27995. jw = JsonView(true, "操作成功!", new
  27996. {
  27997. FileName = $"{di.TeamName}_{fileTypeName}.xlsx",
  27998. FilePath = networkPath
  27999. });
  28000. return Ok(jw);
  28001. }
  28002. [HttpPost]
  28003. public async Task<IActionResult> QueryConferenceAffairsChild(QueryConferenceAffairsChildDto Dto)
  28004. {
  28005. return Ok(JsonView(true, "SUCCESS", _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>().Where(x => x.IsDel == 0 && x.Diid == Dto.GroupId)
  28006. .Select(x => x.PriceName).ToList()));
  28007. }
  28008. #endregion
  28009. #region 会务流程
  28010. /// <summary>
  28011. /// 会务流程 - 团组列表
  28012. /// </summary>
  28013. /// <returns>团组基本信息、团组列表和会务基本信息列表</returns>
  28014. [HttpGet]
  28015. public async Task<IActionResult> ConferenceProceduresGroupNames()
  28016. {
  28017. var conferenceTypeIds = new List<int>() {
  28018. 302, // 成都-会务活动
  28019. 691 // 四川-会务活动
  28020. };
  28021. var groupList = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  28022. .Where(x => x.IsDel == 0)
  28023. .Where(x => conferenceTypeIds.Contains(x.TeamDid))
  28024. .OrderByDescending(x => x.VisitDate)
  28025. .Select(x => new
  28026. {
  28027. x.Id,
  28028. x.TeamName,
  28029. HasChildData = SqlFunc.Subqueryable<Grp_ConferenceProcedures>()
  28030. .Where(child => child.DiId == x.Id) // 替换关联条件
  28031. .Any() // 判断子表是否存在数据
  28032. })
  28033. .ToListAsync();
  28034. return Ok(JsonView(true, "SUCCESS", groupList));
  28035. }
  28036. /// <summary>
  28037. /// 会务流程 - 数据初始化
  28038. /// </summary>
  28039. /// <param name="dto"></param>
  28040. /// <returns>团组基本信息、团组列表和会务基本信息列表</returns>
  28041. [HttpPost]
  28042. public async Task<IActionResult> ConferenceProceduresInit(ConferenceProceduresInitDto dto)
  28043. {
  28044. try
  28045. {
  28046. var conferenceTypeIds = new List<int>() {
  28047. 302, // 成都-会务活动
  28048. 691 // 四川-会务活动
  28049. };
  28050. Grp_DelegationInfo targetGroup = null;
  28051. targetGroup = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  28052. .Where(x => x.Id == dto.GroupId && x.IsDel == 0)
  28053. .FirstAsync();
  28054. if (targetGroup == null)
  28055. {
  28056. targetGroup = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  28057. .Where(x => x.IsDel == 0)
  28058. .Where(x => conferenceTypeIds.Contains(x.TeamDid))
  28059. .OrderByDescending(x => x.VisitDate)
  28060. .FirstAsync();
  28061. }
  28062. if (targetGroup == null)
  28063. {
  28064. return Ok(JsonView(false, "未找到任何团组信息"));
  28065. }
  28066. var groupList = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  28067. .Where(x => x.IsDel == 0)
  28068. .Where(x => conferenceTypeIds.Contains(x.TeamDid))
  28069. .OrderByDescending(x => x.VisitDate)
  28070. .Select(x => new
  28071. {
  28072. x.Id,
  28073. x.TeamName,
  28074. HasChildData = SqlFunc.Subqueryable<Grp_ConferenceProcedures>()
  28075. .Where(child => child.DiId == x.Id)
  28076. .Any() // 判断子表是否存在数据
  28077. })
  28078. .ToListAsync();
  28079. var conferenceProceduresList = await _sqlSugar.Queryable<Grp_ConferenceProcedures>()
  28080. .Where(x => x.DiId == targetGroup.Id && x.IsDel == 0)
  28081. .Select(x => new { x.Id, x.Title, x.DataDetails, x.Details, x.Remark })
  28082. .ToListAsync();
  28083. if (!conferenceProceduresList.Any())
  28084. {
  28085. conferenceProceduresList = await _sqlSugar.Queryable<Grp_ConferenceProcedures>()
  28086. .Where(x => x.DiId == -1 && x.IsDel == 0)
  28087. .Select(x => new { x.Id, x.Title, x.DataDetails, x.Details, x.Remark })
  28088. .ToListAsync();
  28089. }
  28090. var conferenceProceduresGroupByTitle = conferenceProceduresList
  28091. .GroupBy(x => x.Title)
  28092. .Select(x => new
  28093. {
  28094. title = x.Key,
  28095. itmes = x.Select(y => new
  28096. {
  28097. y.Id,
  28098. y.DataDetails,
  28099. y.Details,
  28100. y.Remark
  28101. }).ToList()
  28102. })
  28103. .ToList();
  28104. var response = new
  28105. {
  28106. GroupInfo = new
  28107. {
  28108. targetGroup.Id,
  28109. targetGroup.TeamName,
  28110. targetGroup.VisitDate,
  28111. targetGroup.VisitDays,
  28112. targetGroup.VisitPNumber,
  28113. targetGroup.VisitCountry,
  28114. targetGroup.VisitStartDate,
  28115. targetGroup.VisitEndDate,
  28116. targetGroup.ClientName,
  28117. targetGroup.ClientUnit
  28118. },
  28119. GroupList = groupList,
  28120. ConferenceProceduresList = conferenceProceduresList,
  28121. conferenceProceduresGroupByTitle = conferenceProceduresGroupByTitle
  28122. };
  28123. return Ok(JsonView(true, "SUCCESS", response));
  28124. }
  28125. catch (Exception ex)
  28126. {
  28127. _logger.LogError(ex, "数据初始化失败");
  28128. return Ok(JsonView(false, $"ERROR:{ex.Message}"));
  28129. }
  28130. }
  28131. /// <summary>
  28132. /// 会务流程 - 保存
  28133. /// </summary>
  28134. /// <param name="dto"></param>
  28135. /// <returns></returns>
  28136. [HttpPost]
  28137. public async Task<IActionResult> ConferenceProceduresSave(ConferenceProceduresSaveDto dto)
  28138. {
  28139. _sqlSugar.BeginTran();
  28140. try
  28141. {
  28142. //删除旧数据
  28143. _sqlSugar.Updateable<Grp_ConferenceProcedures>()
  28144. .Where(x => x.DiId == dto.GroupId && x.IsDel == 0)
  28145. .SetColumns(x => new Grp_ConferenceProcedures
  28146. {
  28147. IsDel = 1,
  28148. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  28149. DeleteUserId = dto.UserId
  28150. })
  28151. .ExecuteCommand();
  28152. //添加新数据
  28153. var newData = new List<Grp_ConferenceProcedures>();
  28154. foreach (var item in dto.ConferenceProceduresSaveItem)
  28155. {
  28156. foreach (var item2 in item.itmes)
  28157. {
  28158. newData.Add(new Grp_ConferenceProcedures
  28159. {
  28160. DiId = dto.GroupId,
  28161. Title = item.title,
  28162. DataDetails = item2.DataDetails,
  28163. Details = item2.details,
  28164. Remark = item2.Remark,
  28165. CreateTime = DateTime.Now,
  28166. CreateUserId = dto.UserId
  28167. });
  28168. }
  28169. }
  28170. _sqlSugar.Insertable(newData).ExecuteCommand();
  28171. _sqlSugar.CommitTran();
  28172. }
  28173. catch (Exception ex)
  28174. {
  28175. _sqlSugar.RollbackTran();
  28176. return Ok(JsonView(false, $"ERROR:{ex.Message}"));
  28177. }
  28178. return Ok(JsonView(true, "SUCCESS"));
  28179. }
  28180. [HttpPost]
  28181. public async Task<IActionResult> ConferenceProceduresFileDown(ConferenceProceduresFileDownDto dto)
  28182. {
  28183. var jw = JsonView(false, "团组信息不存在");
  28184. jw.Data = string.Empty;
  28185. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  28186. .Where(x => x.Id == dto.GroupId && x.IsDel == 0)
  28187. .FirstAsync();
  28188. if (groupInfo == null)
  28189. {
  28190. return Ok(jw);
  28191. }
  28192. var conferenceProceduresList = await _sqlSugar.Queryable<Grp_ConferenceProcedures>()
  28193. .Where(x => x.DiId == dto.GroupId && x.IsDel == 0)
  28194. .ToListAsync();
  28195. if (!conferenceProceduresList.Any())
  28196. {
  28197. jw.Msg = "会务流程信息不存在";
  28198. return Ok(jw);
  28199. }
  28200. var filePath = $"{AppSettingsHelper.Get("ExcelBasePath")}Template/会务流程.xlsx";
  28201. if (!System.IO.File.Exists(filePath))
  28202. {
  28203. jw.Msg = "模板文件不存在";
  28204. return Ok(jw);
  28205. }
  28206. var designer = new WorkbookDesigner();
  28207. designer.Workbook = new Workbook(filePath);
  28208. designer.SetDataSource("TB", conferenceProceduresList);
  28209. designer.Process();
  28210. var sheet = designer.Workbook.Worksheets[0];
  28211. var cells = sheet.Cells;
  28212. int col = 0; // 第一列
  28213. int startRow = 2; // 若第0行为表头,则从第1行开始;无表头请改为0
  28214. int endRow = cells.MaxDataRow;
  28215. if (endRow >= startRow)
  28216. {
  28217. int mergeStart = startRow;
  28218. string prev = cells[mergeStart, col].StringValue?.Trim() ?? string.Empty;
  28219. for (int r = startRow + 1; r <= endRow; r++)
  28220. {
  28221. string cur = cells[r, col].StringValue?.Trim() ?? string.Empty;
  28222. if (!string.Equals(cur, prev, StringComparison.Ordinal))
  28223. {
  28224. int count = r - mergeStart;
  28225. if (count > 1)
  28226. cells.Merge(mergeStart, col, count, 1);
  28227. mergeStart = r;
  28228. prev = cur;
  28229. }
  28230. }
  28231. int tailCount = endRow - mergeStart + 1;
  28232. if (tailCount > 1)
  28233. cells.Merge(mergeStart, col, tailCount, 1);
  28234. }
  28235. // byte[] bytes = null;
  28236. // using (MemoryStream stream = new MemoryStream())
  28237. // {
  28238. // designer.Workbook.Save(stream, Aspose.Cells.SaveFormat.Xlsx);
  28239. // bytes = stream.ToArray();
  28240. // }
  28241. // return File(bytes, "application/excel", $"{groupInfo.TeamName}_会务流程.xlsx");
  28242. string savePath = $"{AppSettingsHelper.Get("ExcelBasePath")}ConferenceProcedures";
  28243. if (!System.IO.Directory.Exists(savePath))
  28244. {
  28245. System.IO.Directory.CreateDirectory(savePath);
  28246. }
  28247. designer.Workbook.Save($"{savePath}/{groupInfo.TeamName}_会务流程.xlsx");
  28248. string rst = savePath.replace(AppSettingsHelper.Get("ExcelBasePath"),
  28249. AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath"));
  28250. return Ok(JsonView(true, "SUCCESS", $"{rst}/{groupInfo.TeamName}_会务流程.xlsx"));
  28251. }
  28252. #endregion
  28253. #region 团组签证流程
  28254. /// <summary>
  28255. /// 团组签证流程 - 团组列表(分页)
  28256. /// </summary>
  28257. /// <returns></returns>
  28258. [HttpPost]
  28259. public async Task<IActionResult> VisaProcessGroupNames(VisaProcessGroupNamesDto dto)
  28260. {
  28261. int currUserId = dto.CurrUserId <= 0 ? 1 : dto.CurrUserId;
  28262. string groupName = dto.GroupName.Trim();
  28263. int pageIndex = dto.PageIndex <= 0 ? 1 : dto.PageIndex;
  28264. int pageSize = dto.PageSize <= 0 ? 10 : dto.PageSize;
  28265. int portType = dto.PortType;
  28266. RefAsync<int> total = 0;
  28267. var query = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>()
  28268. .InnerJoin<Grp_DelegationInfo>((x, y) => x.DIId == y.Id)
  28269. .InnerJoin<Grp_VisaProcessSteps>((x, y, z) => x.DIId == z.GroupId)
  28270. .Where((x, y, z) => x.IsDel == 0 && x.CTId == 80 && x.UId == currUserId && z.IsDel == 0);
  28271. //构建单字模糊查询
  28272. if (!string.IsNullOrEmpty(groupName))
  28273. {
  28274. var characters = groupName.ToCharArray();
  28275. foreach (var character in characters)
  28276. {
  28277. var charString = character.ToString();
  28278. query = query.Where((x, y) =>
  28279. SqlFunc.Contains(y.TeamName, charString));
  28280. }
  28281. }
  28282. var groups = await query
  28283. .OrderByDescending((x, y) => y.VisitDate)
  28284. .Select((x, y) => new
  28285. {
  28286. y.Id,
  28287. GroupName = y.TeamName,
  28288. y.VisitDate,
  28289. // 加入子查询统计子表条数
  28290. CompletedCount = SqlFunc.Subqueryable<Grp_VisaProcessSteps>()
  28291. .Where(sub => sub.GroupId == y.Id && sub.IsCompleted && sub.IsDel == 0)
  28292. .Count()
  28293. })
  28294. .Distinct()
  28295. .ToPageListAsync(pageIndex, pageSize, total);
  28296. var msg = "SUCCESS";
  28297. if (total <= 0) msg = "暂无可操作的团组,请联系经理分配团组!";
  28298. var groups1 = groups.Select(x => new
  28299. {
  28300. x.Id,
  28301. x.GroupName,
  28302. x.CompletedCount
  28303. }).ToList();
  28304. return Ok(JsonView(true, msg, groups1, total));
  28305. }
  28306. /// <summary>
  28307. /// 团组签证流程 - 详情
  28308. /// </summary>
  28309. /// <returns></returns>
  28310. [HttpPost]
  28311. public async Task<IActionResult> VisaProcessInfoByGroupId(VisaProcessInfoByGroupIdDto dto)
  28312. {
  28313. var res = await _visaProcessRep.Info(dto);
  28314. if (res.Code != 200) return Ok(JsonView(false, res.Msg));
  28315. return Ok(JsonView(true, res.Msg, res.Data));
  28316. }
  28317. /// <summary>
  28318. /// 团组签证流程 - 流程创建测试
  28319. /// </summary>
  28320. /// <returns></returns>
  28321. [HttpPost]
  28322. public async Task<IActionResult> VisaProcessAdd(int groupId, int currUserId)
  28323. {
  28324. return Ok(await _visaProcessRep.Create(currUserId, groupId));
  28325. }
  28326. /// <summary>
  28327. /// 团组签证流程 - 流程Top4Init 测试
  28328. /// </summary>
  28329. /// <returns></returns>
  28330. [HttpPost]
  28331. public async Task<IActionResult> VisaProcessTop4StepInit(int groupId, int currUserId)
  28332. {
  28333. return Ok(await _visaProcessRep.UpdateBatchTop4Step(groupId, currUserId));
  28334. }
  28335. /// <summary>
  28336. /// 团组签证流程 - 设置状态 完成/未完成
  28337. /// </summary>
  28338. /// <returns></returns>
  28339. [HttpPost]
  28340. public async Task<IActionResult> VisaProcessSetCompleted(VisaProcessSetCompletedDto dto)
  28341. {
  28342. //参数验证
  28343. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.Id == dto.StepId && x.IsDel == 0).AnyAsync();
  28344. if (!stepValid) return Ok(JsonView(false, "签证流程ID无效。"));
  28345. var userValid = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == dto.CurrUserId && x.IsDel == 0).AnyAsync();
  28346. if (!userValid) return Ok(JsonView(false, "用户ID无效。"));
  28347. var res = await _visaProcessRep.SetCompleted(dto.StepId, dto.CurrUserId, dto.IsCompleted);
  28348. if (res.Code != 200) return Ok(JsonView(false, res.Msg));
  28349. return Ok(JsonView(true, res.Msg));
  28350. }
  28351. /// <summary>
  28352. /// 团组签证流程 - 修改各步骤内容
  28353. /// </summary>
  28354. /// <returns></returns>
  28355. [HttpPost]
  28356. public async Task<IActionResult> VisaProcessSetContent(VisaProcessSetContent dto)
  28357. {
  28358. //参数验证
  28359. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.Id == dto.StepId && x.IsDel == 0).FirstAsync();
  28360. if (stepValid == null) return Ok(JsonView(false, "签证流程ID无效。"));
  28361. var userValid = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == dto.CurrUserId && x.IsDel == 0).AnyAsync();
  28362. if (!userValid) return Ok(JsonView(false, "用户ID无效。"));
  28363. if (dto.StepContents == null && dto.StepContents.Count < 1)
  28364. {
  28365. return Ok(JsonView(false, "步骤内容无效。"));
  28366. }
  28367. //各步骤值处理
  28368. object stepVal;
  28369. if (stepValid.Step == 7) stepVal = dto.StepContents;
  28370. else stepVal = dto.StepContents[0].ToString();
  28371. var stepInfo = new Grp_VisaProcessSteps
  28372. {
  28373. Id = dto.StepId,
  28374. DataType = stepValid.DataType,
  28375. TypedValue = stepVal,
  28376. LastUpdateUserId = dto.CurrUserId
  28377. };
  28378. var res = await _visaProcessRep.Update(stepInfo);
  28379. if (res.Code != 200) return Ok(JsonView(false, res.Msg));
  28380. return Ok(JsonView(true, res.Msg));
  28381. }
  28382. /// <summary>
  28383. /// 团组签证流程 - 上传文件
  28384. /// </summary>
  28385. /// <returns></returns>
  28386. [HttpPost]
  28387. public async Task<IActionResult> VisaProcessUploadFiles([FromForm] VisaProcessUploadFilesDto dto)
  28388. {
  28389. //参数验证
  28390. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.Id == dto.StepId && x.IsDel == 0).FirstAsync();
  28391. if (stepValid == null) return Ok(JsonView(false, "签证流程ID无效。"));
  28392. var before = stepValid;
  28393. var userValid = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == dto.CurrUserId && x.IsDel == 0).AnyAsync();
  28394. if (!userValid) return Ok(JsonView(false, "用户ID无效。"));
  28395. //验证文件是否存在
  28396. if (dto.Files == null || dto.Files.Count < 1) return Ok(JsonView(false, "请选择文件。"));
  28397. //验证该步骤是否可以上传文件
  28398. var uploadSteps = new List<int>() {
  28399. 5, //实际出签时间
  28400. 6, //是否需要开出境证明
  28401. 7, //是否需要办理电子入境卡手续
  28402. };
  28403. if (!uploadSteps.Contains(stepValid.Step))
  28404. {
  28405. return Ok(JsonView(false, $"该步骤不可上传附件。可上传附件步骤({string.Join("、", uploadSteps)})"));
  28406. }
  28407. //验证根目录
  28408. string rootRrl = AppSettingsHelper.Get("OfficeBaseUrl");
  28409. string rootPath = AppSettingsHelper.Get("OfficeTempBasePath");
  28410. if (!System.IO.Directory.Exists(rootPath))
  28411. {
  28412. System.IO.Directory.CreateDirectory(rootPath);
  28413. }
  28414. //验证签证流程上传文件夹 //按照团组名称存储文件夹 GrpFile/VisaProcessFiles/
  28415. var groupName = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  28416. .Where(x => x.IsDel == 0 && x.Id == stepValid.GroupId)
  28417. .Select(x => $"{x.TeamName}({x.Id})")
  28418. .FirstAsync();
  28419. //创建团组文件夹
  28420. var groupPath = rootPath + "GrpFile/VisaProcessFiles/" + groupName;
  28421. if (!System.IO.Directory.Exists(groupPath))
  28422. {
  28423. System.IO.Directory.CreateDirectory(groupPath);
  28424. }
  28425. List<string> filePaths = new List<string>();
  28426. //保存文件
  28427. foreach (var file in dto.Files)
  28428. {
  28429. // 生成存储文件名
  28430. var fileName = CommonFun.GenerateStoredFileName($"Step{stepValid.Step}.{file.FileName.Split(".")[1]}");
  28431. var filePath = Path.Combine(groupPath, fileName);
  28432. // 保存文件到磁盘
  28433. using (var stream = new FileStream(filePath, FileMode.Create))
  28434. {
  28435. await file.CopyToAsync(stream);
  28436. }
  28437. filePaths.Add($"GrpFile/VisaProcessFiles/{groupName}/{fileName}");
  28438. }
  28439. //数据库存储
  28440. stepValid.TypedFileNameValue = filePaths;
  28441. stepValid.LastUpdateUserId = dto.CurrUserId;
  28442. stepValid.LastUpdateTime = DateTime.Now;
  28443. var res = await _sqlSugar.Updateable(stepValid)
  28444. .UpdateColumns(it => new { it.TypedFileNameValue, it.LastUpdateUserId, it.LastUpdateTime })
  28445. .Where(s => s.Id == dto.StepId && s.IsDel == 0)
  28446. .ExecuteCommandAsync();
  28447. if (res < 1) Ok(JsonView(false, "文件上传失败。"));
  28448. //记录上传文件
  28449. await _visaProcessRep.LogOperationAsync(before, stepValid, "Upload", dto.CurrUserId);
  28450. return Ok(JsonView(true));
  28451. }
  28452. /// <summary>
  28453. /// 团组签证流程 - step 7 资料下载
  28454. /// </summary>
  28455. /// <returns></returns>
  28456. [HttpGet]
  28457. public async Task<IActionResult> VisaProcessDownload(int groupId, int currUserId)
  28458. {
  28459. var userValid = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == currUserId && x.IsDel == 0).AnyAsync();
  28460. if (!userValid) return Ok(JsonView(false, "用户ID无效。"));
  28461. //验证根目录
  28462. string rootRrl = AppSettingsHelper.Get("OfficeBaseUrl");
  28463. string rootPath = AppSettingsHelper.Get("OfficeTempBasePath");
  28464. if (!System.IO.Directory.Exists(rootPath))
  28465. {
  28466. System.IO.Directory.CreateDirectory(rootPath);
  28467. }
  28468. //验证签证流程上传文件夹 //按照团组名称存储文件夹 GrpFile/VisaProcessFiles/
  28469. var groupName = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  28470. .Where(x => x.IsDel == 0 && x.Id == groupId)
  28471. .Select(x => $"{x.TeamName}({x.Id})")
  28472. .FirstAsync();
  28473. //创建团组文件夹
  28474. var timestamp = DateTime.Now.ToString("yyyyMMddHHmmss");
  28475. var randomStr = Guid.NewGuid().ToString("N").Substring(0, 8);
  28476. var dirName = $"{groupName}_相关资料_{timestamp}";
  28477. var sourceDirectoryPath = $"{rootPath}/GrpFile/VisaProcessFiles/{groupName}";
  28478. var path = $"{rootPath}/GrpFile/VisaProcessFiles/{groupName}/{dirName}";
  28479. if (!System.IO.Directory.Exists(path))
  28480. {
  28481. System.IO.Directory.CreateDirectory(path);
  28482. }
  28483. //验证接团客户名单
  28484. string sql = string.Format(@"
  28485. SELECT
  28486. tcl.Id,
  28487. tcl.DiId,
  28488. tcl.IsAccompany,
  28489. temp.*,
  28490. u.CnName AS Operator,
  28491. tcl.CreateTime AS OperatingTime,
  28492. ssd.name AS ShippingSpaceType
  28493. FROM
  28494. Grp_TourClientList tcl
  28495. LEFT JOIN (
  28496. SELECT
  28497. dc.Id AS DcId,
  28498. dc.LastName,
  28499. dc.FirstName,
  28500. ccom.CompanyFullName,
  28501. dc.Job,
  28502. cc.CertNo AS IDCardNo,
  28503. dc.Sex,
  28504. dc.BirthDay
  28505. FROM
  28506. Crm_DeleClient dc
  28507. LEFT JOIN Crm_CustomerCompany ccom ON dc.CrmCompanyId = ccom.Id
  28508. AND ccom.IsDel = 0
  28509. LEFT JOIN Crm_CustomerCert cc ON dc.Id = cc.DcId
  28510. AND cc.SdId = 773
  28511. AND cc.IsDel = 0
  28512. WHERE
  28513. dc.IsDel = 0
  28514. ) temp ON temp.DcId = tcl.ClientId
  28515. LEFT JOIN Sys_Users u ON tcl.CreateUserId = u.Id
  28516. LEFT JOIN sys_setdata ssd ON ssd.isdel = 0 AND ssd.id = tcl.ShippingSpaceTypeid
  28517. WHERE
  28518. tcl.IsDel = 0
  28519. AND tcl.DiId = {0}", groupId);
  28520. var groupClientList = await _sqlSugar.SqlQueryable<TourClientInfosView>(sql).ToListAsync();
  28521. //解密
  28522. foreach (var item in groupClientList)
  28523. {
  28524. EncryptionProcessor.DecryptProperties(item);
  28525. }
  28526. if (groupClientList == null || groupClientList.Count < 1)
  28527. {
  28528. return Ok(JsonView(false, $"团组客户名单未录入客户信息,不可生成相关资料。"));
  28529. }
  28530. #region 生成文件
  28531. //酒店信息
  28532. var hotelInfos = await _sqlSugar.Queryable<Grp_HotelReservations>()
  28533. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  28534. .OrderBy(x => x.CheckInDate)
  28535. .ToListAsync();
  28536. //航班信息
  28537. var airInfos = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  28538. .Where(x => x.IsDel == 0 && x.DIId == groupId)
  28539. .OrderBy(x => x.FlightsDate)
  28540. .ToListAsync();
  28541. foreach (var clientInfo in groupClientList)
  28542. {
  28543. var clientId = clientInfo.DcId;
  28544. var guestName = $"{clientInfo.LastName}{clientInfo.FirstName}";
  28545. #region 个人信息资料
  28546. #endregion
  28547. #region 机票航班信息
  28548. var clientAirInfos = airInfos.Where(x => x.ClientName.Contains(clientId.ToString())).ToList();
  28549. if (clientAirInfos != null && clientAirInfos.Count > 0)
  28550. {
  28551. //创建表格
  28552. Document airDoc = new Document();
  28553. DocumentBuilder airBuilder = new DocumentBuilder(airDoc);
  28554. GeneralMethod.SetupDocumentStyles(airBuilder);
  28555. GeneralMethod.AddTitle(airBuilder, $"{guestName} - 机票信息");
  28556. GeneralMethod.AddAirInfoSections(airBuilder, clientAirInfos, "机票航班信息");
  28557. var airRandomStr = Guid.NewGuid().ToString("N").Substring(0, 8);
  28558. var airFileName = $"{guestName}_机票信息_{airRandomStr}.docx";
  28559. airDoc.Save($"{path}/{airFileName}");
  28560. }
  28561. #endregion
  28562. #region 酒店信息
  28563. var clientHotelInfos = hotelInfos.Where(x => x.GuestName.Contains(clientId.ToString())).ToList();
  28564. if (clientHotelInfos != null && clientHotelInfos.Count > 0)
  28565. {
  28566. //创建表格
  28567. Document hotelDoc = new Document();
  28568. DocumentBuilder HotelBuilder = new DocumentBuilder(hotelDoc);
  28569. GeneralMethod.SetupDocumentStyles(HotelBuilder);
  28570. GeneralMethod.AddTitle(HotelBuilder, $"{guestName} - 酒店信息");
  28571. GeneralMethod.AddHotelInfoSections(HotelBuilder, clientHotelInfos, "酒店信息");
  28572. var hotelRandomStr = Guid.NewGuid().ToString("N").Substring(0, 8);
  28573. var hotelFileName = $"{guestName}_酒店信息_{hotelRandomStr}.docx";
  28574. hotelDoc.Save($"{path}/{hotelFileName}");
  28575. }
  28576. #endregion
  28577. }
  28578. #endregion
  28579. //打包文件夹
  28580. var sourceDirectory = $"{sourceDirectoryPath}/{dirName}";
  28581. var zipFilePath = $"{sourceDirectoryPath}/{dirName}.zip";
  28582. if (System.IO.File.Exists(zipFilePath))
  28583. {
  28584. System.IO.File.Delete(zipFilePath);
  28585. }
  28586. ZipFile.CreateFromDirectory(sourceDirectory, zipFilePath, CompressionLevel.Fastest, false);
  28587. // 等待并验证
  28588. await Task.Delay(100); // 给系统时间完成文件操作
  28589. if (System.IO.File.Exists(zipFilePath))
  28590. {
  28591. var fileInfo = new FileInfo(zipFilePath);
  28592. var url = $"{rootRrl}Office/GrpFile/VisaProcessFiles/{groupName}/{dirName}.zip";
  28593. //记录下载日志
  28594. await _visaProcessRep.LogOperationAsync(null, null, "Download", currUserId);
  28595. return Ok(JsonView(StatusCodes.Status200OK, "操作成功!", url));
  28596. }
  28597. return Ok(JsonView(false));
  28598. }
  28599. /// <summary>
  28600. /// 团组签证流程 - 根据步骤记录ID获取该步骤的所有操作日志
  28601. /// </summary>
  28602. /// <returns></returns>
  28603. [HttpGet]
  28604. public async Task<IActionResult> VisaProcessLogByStepId(int stepId)
  28605. {
  28606. //参数验证
  28607. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.Id == stepId && x.IsDel == 0).FirstAsync();
  28608. if (stepValid == null) return Ok(JsonView(false, "签证流程ID无效。"));
  28609. var logs = await _visaProcessRep.GetStepLogsAsync(stepId);
  28610. return Ok(JsonView(logs));
  28611. }
  28612. /// <summary>
  28613. /// 团组签证流程 - 根据团组ID获取该团组下所有步骤的操作日志
  28614. /// </summary>
  28615. /// <returns></returns>
  28616. [HttpGet]
  28617. public async Task<IActionResult> VisaProcessLogByGroupId(int groupId)
  28618. {
  28619. //参数验证
  28620. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.GroupId == groupId && x.IsDel == 0).FirstAsync();
  28621. if (stepValid == null) return Ok(JsonView(false, "团组ID无效。"));
  28622. var logs = await _visaProcessRep.GetGroupStepLogsAsync(groupId);
  28623. return Ok(JsonView(logs));
  28624. }
  28625. #endregion
  28626. #region 团组总览进程
  28627. /// <summary>
  28628. /// 团组总览进程 - 流程创建测试
  28629. /// </summary>
  28630. /// <returns></returns>
  28631. [HttpGet]
  28632. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28633. public async Task<IActionResult> GroupProcessInitTest(int groupId, int currUserId)
  28634. {
  28635. return Ok(await _processOverviewRep.ProcessInitAsync(groupId, currUserId));
  28636. }
  28637. /// <summary>
  28638. /// 团组总览进程 - 团组名称集合
  28639. /// </summary>
  28640. /// <returns></returns>
  28641. [HttpGet()]
  28642. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28643. public async Task<IActionResult> GroupProcessGroupNames()
  28644. {
  28645. var groupNames = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  28646. .Where(x => x.IsDel == 0)
  28647. .OrderByDescending(x => x.VisitDate)
  28648. .Select(x => new
  28649. {
  28650. x.Id,
  28651. GroupName = x.TeamName,
  28652. HasProcess = SqlFunc.Subqueryable<Grp_ProcessOverview>()
  28653. .Where(po => po.GroupId == x.Id && po.IsDel == 0)
  28654. .Any()
  28655. })
  28656. .ToListAsync();
  28657. return Ok(JsonView(groupNames));
  28658. }
  28659. /// <summary>
  28660. /// 团组总览进程 - 流程详情
  28661. /// </summary>
  28662. /// <returns></returns>
  28663. [HttpGet]
  28664. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28665. public async Task<IActionResult> GroupProcessDetails(int groupId)
  28666. {
  28667. var res = await _processOverviewRep.ProcessesDetailsAsync(groupId);
  28668. if (res.Code == StatusCodes.Status200OK)
  28669. {
  28670. return Ok(JsonView(res.Data));
  28671. }
  28672. return Ok(JsonView(false, res.Msg));
  28673. }
  28674. /// <summary>
  28675. /// 团组总览进程 - 更新节点状态
  28676. /// </summary>
  28677. /// <returns></returns>
  28678. [HttpPost]
  28679. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28680. public async Task<IActionResult> GroupProcessUpdateNodeStatus(GroupProcessUpdateNodeStatusDto dto)
  28681. {
  28682. var res = await _processOverviewRep.UpdateNodeStatusSimpleAsync(dto.NodeId, dto.CurrUserId);
  28683. if (res.Code == StatusCodes.Status200OK)
  28684. {
  28685. return Ok(JsonView(res.Data));
  28686. }
  28687. return Ok(JsonView(false, res.Msg));
  28688. }
  28689. /// <summary>
  28690. /// 团组总览进程 - 更新签证节点信息
  28691. /// </summary>
  28692. /// <returns></returns>
  28693. [HttpPost]
  28694. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28695. public async Task<IActionResult> GroupProcessUpdateVisaNodeDetails(GroupProcessUpdateVisaNodeDetailsDto dto)
  28696. {
  28697. //验证签证信息
  28698. if (dto.VisaSubNodes.Count < 1) return Ok(JsonView(false, "请传入有效的签证节点信息。"));
  28699. var res = await _processOverviewRep.UpdateVisaNodeDetailsAsync(dto);
  28700. if (res.Code == StatusCodes.Status200OK)
  28701. {
  28702. return Ok(JsonView(res.Data));
  28703. }
  28704. return Ok(JsonView(false, res.Msg));
  28705. }
  28706. /// <summary>
  28707. /// 团组总览进程 - 设置实际完成时间
  28708. /// </summary>
  28709. /// <returns></returns>
  28710. [HttpPost]
  28711. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28712. public async Task<IActionResult> GroupProcessSetActualDone(GroupProcessSetActualDoneDto dto)
  28713. {
  28714. //验证签证信息
  28715. var res = await _processOverviewRep.SetActualDoneAsync(dto);
  28716. if (res.Code == StatusCodes.Status200OK)
  28717. {
  28718. return Ok(JsonView(res.Data));
  28719. }
  28720. return Ok(JsonView(false, res.Msg));
  28721. }
  28722. #endregion
  28723. #region 团组会务总览进程
  28724. /// <summary>
  28725. /// 团组会务总览进程 - 流程创建测试
  28726. /// </summary>
  28727. /// <returns></returns>
  28728. [HttpGet]
  28729. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28730. public async Task<IActionResult> ConfProcessInitTest(int groupId, int currUserId)
  28731. {
  28732. return Ok(await _processOverviewRep.ProcessInitAsync(groupId, currUserId));
  28733. }
  28734. /// <summary>
  28735. /// 团组会务总览进程 - 基础信息集合(团组名称、参与人信息)
  28736. /// </summary>
  28737. /// <returns></returns>
  28738. [HttpGet]
  28739. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28740. public async Task<IActionResult> ConfProcessGroupNames()
  28741. {
  28742. var groupTypes = new List<int>() {
  28743. 302, // 成都-会务活动
  28744. 691, // 四川-会务活动
  28745. 762, // 四川-赛事项目收入
  28746. 1047 // 成都-赛事项目收入
  28747. };
  28748. var groupNames = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  28749. .Where(x => x.IsDel == 0 && groupTypes.Contains(x.TeamDid))
  28750. .OrderByDescending(x => x.VisitDate)
  28751. .Select(x => new
  28752. {
  28753. x.Id,
  28754. GroupName = x.TeamName,
  28755. HasProcess = SqlFunc.Subqueryable<Grp_ConfProcessOverview>()
  28756. .Where(po => po.GroupId == x.Id && po.IsDel == 0)
  28757. .Any()
  28758. })
  28759. .ToListAsync();
  28760. var participators = await _sqlSugar.Queryable<Sys_Users>()
  28761. .Where(x => x.IsDel == 0 && x.DepId == 5)
  28762. .Select(x => new ParticipatorInfo()
  28763. {
  28764. UserId = x.Id,
  28765. UserName = x.CnName
  28766. })
  28767. .ToListAsync();
  28768. var view = new { groupNames, participators };
  28769. return Ok(JsonView(view));
  28770. }
  28771. /// <summary>
  28772. /// 团组会务总览进程 - 获取节点模板信息
  28773. /// </summary>
  28774. /// <returns></returns>
  28775. [HttpGet]
  28776. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28777. public async Task<IActionResult> ConfProcessNodeTempInfos(int groupId, int currUserId)
  28778. {
  28779. var nodeTemps1 = await _processOverviewRep.DefaultConfProcessTemps(groupId, currUserId);
  28780. var nodeTemps = nodeTemps1.Select(x => new
  28781. {
  28782. TempId = x.ProcessOrder,
  28783. TempName = $"情况{x.ProcessOrder}",
  28784. //TempNodes = x.Nodes
  28785. }).ToList();
  28786. return Ok(JsonView(nodeTemps));
  28787. }
  28788. /// <summary>
  28789. /// 团组会务总览进程 - 更新节点模板
  28790. /// </summary>
  28791. /// <param name="groupId">团组Id</param>
  28792. /// <param name="nodeTempId">节点模板Id</param>
  28793. /// <param name="currUserId">当前用户Id</param>
  28794. /// <returns></returns>
  28795. [HttpGet]
  28796. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28797. public async Task<IActionResult> ConfProcessChangeNodeTempSave(int groupId, int nodeTempId, int currUserId)
  28798. {
  28799. var res = await _processOverviewRep.ConfProcessChangeNodeTempSaveAsync(groupId, nodeTempId, currUserId);
  28800. if (res.Code == StatusCodes.Status200OK)
  28801. {
  28802. return Ok(JsonView(res.Data));
  28803. }
  28804. return Ok(JsonView(false, res.Msg));
  28805. }
  28806. /// <summary>
  28807. /// 团组会务总览进程 - 流程详情
  28808. /// </summary>
  28809. /// <param name="groupId">团组Id</param>
  28810. /// <param name="currUserId">当前userId</param>
  28811. /// <returns></returns>
  28812. [HttpGet]
  28813. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28814. public async Task<IActionResult> ConfProcessDetails(int groupId, int currUserId)
  28815. {
  28816. var res = await _processOverviewRep.ConfProcessesDetailsAsync(groupId, currUserId);
  28817. if (res.Code == StatusCodes.Status200OK)
  28818. {
  28819. return Ok(JsonView(res.Data));
  28820. }
  28821. return Ok(JsonView(false, res.Msg));
  28822. }
  28823. /// <summary>
  28824. /// 团组会务总览进程 - 更新节点状态
  28825. /// </summary>
  28826. /// <returns></returns>
  28827. [HttpPost]
  28828. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28829. public async Task<IActionResult> ConfProcessUpdateNodeStatus(GroupProcessUpdateNodeStatusDto dto)
  28830. {
  28831. var res = await _processOverviewRep.UpdateConfNodeStatusAsync(dto.NodeId, dto.CurrUserId);
  28832. if (res.Code == StatusCodes.Status200OK)
  28833. {
  28834. return Ok(JsonView(res.Data));
  28835. }
  28836. return Ok(JsonView(false, res.Msg));
  28837. }
  28838. /// <summary>
  28839. /// 团组会务总览进程 - 设置实际完成时间及其他信息
  28840. /// </summary>
  28841. /// <returns></returns>
  28842. [HttpPost]
  28843. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  28844. public async Task<IActionResult> ConfProcessSetActualDone(ConfProcessSetActualDoneDto dto)
  28845. {
  28846. var res = await _processOverviewRep.SetNodeInfoAsync(dto);
  28847. if (res.Code == StatusCodes.Status200OK)
  28848. {
  28849. return Ok(JsonView(res.Data));
  28850. }
  28851. return Ok(JsonView(false, res.Msg));
  28852. }
  28853. #endregion
  28854. }
  28855. }